mirror of https://github.com/apache/jclouds.git
jenkins lab: added build command to JobClient + Tests
This commit is contained in:
parent
a03565003f
commit
9069ad7136
|
@ -73,4 +73,20 @@ public interface JobAsyncClient {
|
|||
@ExceptionParser(ReturnVoidOn302Or404.class)
|
||||
ListenableFuture<Void> delete(@PathParam("displayName") String displayName);
|
||||
|
||||
/**
|
||||
* @see JobClient#buildJob
|
||||
*/
|
||||
@POST
|
||||
@Path("/job/{displayName}/build")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> build(@PathParam("displayName") String displayName);
|
||||
|
||||
/**
|
||||
* @see JobClient#fetchConfigXML
|
||||
*/
|
||||
@GET
|
||||
@Path("/job/{displayName}/config.xml")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<String> fetchConfigXML(@PathParam("displayName") String displayName);
|
||||
|
||||
}
|
||||
|
|
|
@ -45,4 +45,16 @@ public interface JobClient {
|
|||
|
||||
void delete(String displayName);
|
||||
|
||||
/**
|
||||
* Build a job via API
|
||||
*
|
||||
* If security is enabled, provide username/password of an account with build permission in the request.
|
||||
* Another alternative (but deprecated) is to configure the 'Trigger builds remotely' section in the job configuration.
|
||||
*
|
||||
* @param displayName
|
||||
*/
|
||||
void build(String displayName);
|
||||
|
||||
String fetchConfigXML(String displayName);
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ import com.google.common.collect.ImmutableMultimap;
|
|||
@Test(groups = "unit", testName = "JobClientExpectTest")
|
||||
public class JobClientExpectTest extends BaseJenkinsClientExpectTest {
|
||||
|
||||
|
||||
public void testCreateJobStringWhenResponseIs2xx() throws IOException {
|
||||
HttpRequest createJob = HttpRequest.builder()
|
||||
.method("POST")
|
||||
|
@ -97,22 +96,57 @@ public class JobClientExpectTest extends BaseJenkinsClientExpectTest {
|
|||
.build();
|
||||
|
||||
public void testGetJobWhenResponseIs2xx() {
|
||||
|
||||
HttpResponse getJobResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/job.json")).build();
|
||||
|
||||
JenkinsClient clientWhenJobExists = requestSendsResponse(getJob, getJobResponse);
|
||||
|
||||
assertEquals(clientWhenJobExists.getJobClient().get("ddd").toString(),
|
||||
new ParseJobDetailsTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testGetJobWhenResponseIs404() {
|
||||
|
||||
HttpResponse getJobResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
JenkinsClient getJobWhenGetd = requestSendsResponse(getJob, getJobResponse);
|
||||
|
||||
assertNull(getJobWhenGetd.getJobClient().get("ddd"));
|
||||
}
|
||||
|
||||
HttpRequest buildJob = HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("http://localhost:8080/job/ddd/build"))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build();
|
||||
|
||||
public void testBuildJobWhenResponseIs2xx() {
|
||||
HttpResponse buildJobResponse = HttpResponse.builder().statusCode(200).build();
|
||||
JenkinsClient clientWhenJobExists = requestSendsResponse(buildJob, buildJobResponse);
|
||||
clientWhenJobExists.getJobClient().build("ddd");
|
||||
}
|
||||
|
||||
public void testBuildJobWhenResponseIs404() {
|
||||
HttpResponse getJobResponse = HttpResponse.builder().statusCode(404).build();
|
||||
JenkinsClient getJobWhenGetd = requestSendsResponse(buildJob, getJobResponse);
|
||||
getJobWhenGetd.getJobClient().build("ddd");
|
||||
}
|
||||
|
||||
HttpRequest fetchConfig = HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("http://localhost:8080/job/ddd/config.xml"))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build();
|
||||
|
||||
public void testFetchConfigXMLWhenResponseIs2xx() {
|
||||
HttpResponse fetchConfigResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/sample_job.xml", "text/xml")).build();
|
||||
JenkinsClient clientWhenJobExists = requestSendsResponse(fetchConfig, fetchConfigResponse);
|
||||
String configXML = clientWhenJobExists.getJobClient().fetchConfigXML("ddd");
|
||||
//TODO enable this assertion
|
||||
//assertEquals(configXML, Strings2.toStringAndClose(getClass().getResourceAsStream("/sample_job.xml")));
|
||||
}
|
||||
|
||||
public void testFetchConfigXMLWhenResponseIs404() {
|
||||
HttpResponse fetchConfigResponse = HttpResponse.builder().statusCode(404).build();
|
||||
JenkinsClient getJobWhenGetd = requestSendsResponse(fetchConfig, fetchConfigResponse);
|
||||
getJobWhenGetd.getJobClient().fetchConfigXML("ddd");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,14 @@ public class JobClientLiveTest extends BaseJenkinsClientLiveTest {
|
|||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateJob")
|
||||
public void testFetchConfigXML() throws IOException {
|
||||
String configXML = getClient().fetchConfigXML("blagoo");
|
||||
assertNotNull(configXML);
|
||||
//TODO enable this assertion
|
||||
//assertEquals(configXML, Strings2.toStringAndClose(getClass().getResourceAsStream("/sample_job.xml")));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testFetchConfigXML")
|
||||
public void testGetJob() throws IOException {
|
||||
JobDetails job = getClient().get("blagoo");
|
||||
assertNotNull(job);
|
||||
|
@ -49,6 +57,11 @@ public class JobClientLiveTest extends BaseJenkinsClientLiveTest {
|
|||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetJob")
|
||||
public void testBuildJob() throws IOException {
|
||||
getClient().build("blagoo");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testBuildJob")
|
||||
public void testDeleteJob() {
|
||||
getClient().delete("blagoo");
|
||||
}
|
||||
|
@ -57,6 +70,7 @@ public class JobClientLiveTest extends BaseJenkinsClientLiveTest {
|
|||
@Override
|
||||
protected void tearDownContext() {
|
||||
getClient().delete("blagoo");
|
||||
getClient().delete("blagooCopy");
|
||||
super.tearDownContext();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue