Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kun.tang committed Sep 29, 2024
1 parent 5c02573 commit 3a8145b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@AutoValue
public abstract class StageFlowNode {

public abstract int id();
public abstract String name();

public abstract String status();
Expand All @@ -38,8 +39,8 @@ public abstract class StageFlowNode {
StageFlowNode() {
}

@SerializedNames({ "name", "status", "startTimeMillis", "durationTimeMillis", "parentNodes" })
public static StageFlowNode create(String name, String status, long startTimeMillis, long durationTimeMillis, List<Long> parentNodes) {
return new AutoValue_StageFlowNode(name, status, startTimeMillis, durationTimeMillis, parentNodes);
@SerializedNames({ "id","name", "status", "startTimeMillis", "durationTimeMillis", "parentNodes" })
public static StageFlowNode create(int id,String name, String status, long startTimeMillis, long durationTimeMillis, List<Long> parentNodes) {
return new AutoValue_StageFlowNode(id,name, status, startTimeMillis, durationTimeMillis, parentNodes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public void testCreateJob() {
assertTrue(success.value());
}

@Test
public void testCreateFolder(){
RequestStatus success = api().createFolder(null,"DevTestFolder");
assertTrue(success.value());
}

// The next 3 tests must run one after the other as they use the same Job
@Test
public void testStopFreeStyleBuild() throws InterruptedException {
Expand Down Expand Up @@ -192,6 +198,20 @@ public void testGetJobInfo() {
assertTrue(output.builds().isEmpty());
}

@Test(dependsOnMethods = "testCreateJob")
public void testCheckJobNameExisted() {
JobExisted output = api().checkJobName(null,"DevTest");
assertNotNull(output);
assertTrue(output.existed());
}

@Test(dependsOnMethods = "testCreateJob")
public void testCheckJobNameNotExisted() {
JobExisted output = api().checkJobName(null,"DevTest1");
assertNotNull(output);
assertFalse(output.existed());
}

@Test(dependsOnMethods = "testGetJobInfo")
public void testLastBuildNumberOnJobWithNoBuilds() {
Integer output = api().lastBuildNumber(null, "DevTest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import javax.ws.rs.core.MediaType;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -115,9 +116,52 @@ public void testGetJobInfoNotFound() throws Exception {
}
}

public void testGetBuildInfo() throws Exception {
public void testCheckJobNameExisted() throws Exception {
MockWebServer server = mockWebServer();
String body = payloadFromResource("/checkJobNameExisted.txt");
server.enqueue(new MockResponse().setBody(body).setResponseCode(200));
JenkinsApi jenkinsApi = api(server.url("/").url());
JobsApi api = jenkinsApi.jobsApi();
try {
JobExisted output = api.checkJobName(null,"DevTest");
assertTrue(output.existed());
} finally {
jenkinsApi.close();
server.shutdown();
}
}

public void testCheckJobNameNotExisted() throws Exception {
MockWebServer server = mockWebServer();
String body = payloadFromResource("/checkJobNameNotExisted.txt");
server.enqueue(new MockResponse().setBody(body).setResponseCode(200));
JenkinsApi jenkinsApi = api(server.url("/").url());
JobsApi api = jenkinsApi.jobsApi();
try {
JobExisted output = api.checkJobName(null,"DevTest1");
assertFalse(output.existed());
} finally {
jenkinsApi.close();
server.shutdown();
}
}

public void testCheckJobNameNotFound() throws Exception {
MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setResponseCode(404));
JenkinsApi jenkinsApi = api(server.url("/").url());
JobsApi api = jenkinsApi.jobsApi();
try {
JobExisted output = api.checkJobName(null,"DevTest1");
assertNull(output);
} finally {
jenkinsApi.close();
server.shutdown();
}
}

public void testGetBuildInfo() throws Exception {
MockWebServer server = mockWebServer();
String body = payloadFromResource("/build-info.json");
server.enqueue(new MockResponse().setBody(body).setResponseCode(200));
JenkinsApi jenkinsApi = api(server.url("/").url());
Expand Down Expand Up @@ -174,6 +218,21 @@ public void testCreateJob() throws Exception {
server.shutdown();
}
}
public void testCreateFolder() throws Exception {
MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setResponseCode(200));
JenkinsApi jenkinsApi = api(server.url("/").url());
JobsApi api = jenkinsApi.jobsApi();
try {
RequestStatus success = api.createFolder(null, "DevTestFolder");
assertNotNull(success);
assertTrue(success.value());
assertTrue(success.errors().isEmpty());
} finally {
jenkinsApi.close();
server.shutdown();
}
}

public void testCreateJobInFolder() throws Exception {
MockWebServer server = mockWebServer();
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/checkJobNameExisted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="error">A job already exists with the name ‘DevTest’</div>
1 change: 1 addition & 0 deletions src/test/resources/checkJobNameNotExisted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div/>

0 comments on commit 3a8145b

Please sign in to comment.