Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions src/test/java/school/redrover/api/FreestyleProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.restassured.response.Response;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
import school.redrover.api.dto.project.ProjectResponse;
import school.redrover.api.testdata.ProjectType;
import school.redrover.common.APIBaseTest;
import school.redrover.api.testdata.ProjectDataProvider;
Expand All @@ -15,31 +17,51 @@ public class FreestyleProjectTest extends APIBaseTest {

@Test(dataProvider = "projectNameList", dataProviderClass = ProjectDataProvider.class)
public void testCreateWithValidName(String projectName) {
Response createProjectResponse = createProjectWithXML(projectName,
Response response = createProjectWithXML(projectName,
getPayload("create-empty-freestyle-project.xml"));
Response getProjectResponse = getProjectByName(projectName);

String actualProjectName = getProjectResponse.jsonPath().getString("name");
Assert.assertEquals(response.getStatusCode(), 200);
}

@Test
public void testGetProjectByName() {
SoftAssert softAssert = new SoftAssert();
createProjectWithXML(PROJECT_NAME, getPayload("create-empty-freestyle-project.xml"));

Response response = getProjectByName(PROJECT_NAME);

softAssert.assertEquals(createProjectResponse.getStatusCode(), 200);
ProjectResponse projectResponse = response.as(ProjectResponse.class);

softAssert.assertEquals(actualProjectName, projectName);
softAssert.assertEquals(getProjectResponse.getStatusCode(), 200);
softAssert.assertTrue(getProjectResponse.time() <= 1500);
softAssert.assertEquals(response.getStatusCode(), 200);
softAssert.assertTrue(response.time() <= 1500);
softAssert.assertEquals(projectResponse.name(), PROJECT_NAME);
softAssert.assertEquals(projectResponse.fullName(), PROJECT_NAME);
softAssert.assertEquals(projectResponse.fullDisplayName(), PROJECT_NAME);
softAssert.assertEquals(projectResponse.displayName(), PROJECT_NAME);
softAssert.assertEquals(projectResponse.className(), ProjectType.FREESTYLE_PROJECT.mode());
softAssert.assertTrue(projectResponse.url().endsWith(PROJECT_NAME + "/"));
softAssert.assertAll();
}

@Test(dataProvider = "renameProjectNameList", dataProviderClass = ProjectDataProvider.class)
public void testRenameProject(String oldName, String newName) {
SoftAssert softAssert = new SoftAssert();
createProjectWithXML(oldName, getPayload("create-empty-freestyle-project.xml"));

renameProject(oldName, newName);

Response getProjectResponse = getProjectByName(newName);
Response response = getProjectByName(newName);

ProjectResponse projectResponse = response.as(ProjectResponse.class);

String actualProjectName = getProjectResponse.jsonPath().getString("name");
softAssert.assertEquals(actualProjectName, newName);
softAssert.assertEquals(getProjectResponse.statusCode(), 200);
softAssert.assertTrue(getProjectResponse.time() <= 1500);
softAssert.assertEquals(response.statusCode(), 200);
softAssert.assertTrue(response.time() <= 1500);
softAssert.assertEquals(projectResponse.name(), newName);
softAssert.assertEquals(projectResponse.fullName(), newName);
softAssert.assertEquals(projectResponse.fullDisplayName(), newName);
softAssert.assertEquals(projectResponse.displayName(), newName);
softAssert.assertTrue(projectResponse.url().endsWith(newName + "/"));
softAssert.assertAll();
}

@Test
Expand All @@ -49,18 +71,20 @@ public void testDeleteProject() {
deleteProject(PROJECT_NAME);

Response afterDeletedResponse = getProjectByName(PROJECT_NAME);
Assert.assertEquals(afterDeletedResponse.statusCode(), 404, "Not found");
Assert.assertEquals(afterDeletedResponse.statusCode(), 404);
}

@Test(dataProvider = "providerUnsafeCharacters", dataProviderClass = ProjectDataProvider.class)
public void testCreateWithUnsafeCharacter(String unsafeCharacter) {
SoftAssert softAssert = new SoftAssert();
Response response = createProject(unsafeCharacter, ProjectType.FREESTYLE_PROJECT);

softAssert.assertEquals(response.statusCode(), 400);
softAssert.assertTrue(response.time() <= 1500);
softAssert.assertEquals(
response.getHeaders().getValue("X-Error"),
"%s is an unsafe character".formatted(unsafeCharacter));
softAssert.assertAll();
}

}
41 changes: 41 additions & 0 deletions src/test/java/school/redrover/api/dto/project/ProjectResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package school.redrover.api.dto.project;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public record ProjectResponse(
@JsonProperty("_class")
String className,
List<Object> actions,
String description,
String displayName,
String displayNameOrNull,
String fullDisplayName,
String fullName,
String name,
String url,
boolean buildable,
List<Object> builds,
String color,
Object firstBuild,
List<Object> healthReport,
boolean keepDependencies,
Object lastBuild,
Object lastCompletedBuild,
Object lastFailedBuild,
Object lastStableBuild,
Object lastSuccessfulBuild,
Object lastUnstableBuild,
Object lastUnsuccessfulBuild,
int nextBuildNumber,
List<Object> property,
boolean concurrentBuild,
boolean inQueue,
Object queueItem,
boolean resumeBlocked,
boolean disabled
) {
}
4 changes: 0 additions & 4 deletions src/test/java/school/redrover/common/APIBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.asserts.SoftAssert;
import school.redrover.common.logging.Log;
import school.redrover.common.logging.RestAssuredLogFilter;

Expand All @@ -17,7 +16,6 @@ public abstract class APIBaseTest {
protected String apiToken;
protected String tokenUuid;
protected String userName = ProjectUtils.getUserName();
protected SoftAssert softAssert;

@BeforeClass
protected void setUpApi() {
Expand All @@ -34,13 +32,11 @@ protected void beforeMethod(Method method) {
Log.info("Clear data");
Log.info("Run %s.%s", this.getClass().getName(), method.getName());
JenkinsUtils.clearData();
softAssert = new SoftAssert();
}

@AfterClass
protected void tearDownApi() {
Log.info("Delete API token");
JenkinsUtils.deleteApiTokenByUuid(jenkinsUrl, tokenUuid, apiToken);
softAssert.assertAll();
}
}