easier param when job xml is already a string

This commit is contained in:
Adrian Cole 2012-04-24 21:53:32 -07:00
parent d83ce9c154
commit a1ff6f3b59
4 changed files with 30 additions and 13 deletions

View File

@ -28,8 +28,10 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.io.Payload;
import org.jclouds.jenkins.v1.filters.BasicAuthenticationUnlessAnonymous;
import org.jclouds.jenkins.v1.functions.ReturnVoidOn302Or404;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.common.util.concurrent.ListenableFuture;
@ -44,13 +46,20 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface JobAsyncClient {
/**
* @see JobClient#createFromXML
* @see JobClient#createFromXML(String, Payload)
*/
@POST
@Path("/createItem")
@Produces(MediaType.TEXT_XML)
ListenableFuture<Void> createFromXML(@QueryParam("name") String displayName, Payload xml);
/**
* @see JobClient#createFromXML(String, String)
*/
@POST
@Path("/createItem")
@Produces(MediaType.TEXT_XML)
ListenableFuture<Void> createFromXML(@QueryParam("name") String displayName, @BinderParam(BindToStringPayload.class) String xml);
/**
* @see JobClient#getJobView

View File

@ -41,6 +41,8 @@ public interface JobClient {
*/
void createFromXML(String displayName, Payload xml);
void createFromXML(String displayName, String xml);
void delete(String displayName);
}

View File

@ -18,12 +18,14 @@
*/
package org.jclouds.jenkins.v1.features;
import java.io.IOException;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.jenkins.v1.JenkinsClient;
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientExpectTest;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
@ -34,21 +36,27 @@ import com.google.common.collect.ImmutableMultimap;
*/
@Test(groups = "unit", testName = "JobClientExpectTest")
public class JobClientExpectTest extends BaseJenkinsClientExpectTest {
HttpRequest createJob = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("http://localhost:8080/createItem?name=blagoo"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(payloadFromResourceWithContentType("/sample_job.xml", "text/xml"))
.build();
public void testCreateJobWhenResponseIs2xx() {
HttpRequest createJob = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("http://localhost:8080/createItem?name=blagoo"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(payloadFromResourceWithContentType("/sample_job.xml", "text/xml"))
.build();
HttpResponse createJobResponse = HttpResponse.builder().statusCode(200).build();
HttpResponse createJobResponse = HttpResponse.builder().statusCode(200).build();
public void testCreateJobPayloadWhenResponseIs2xx() {
JenkinsClient createJobWhenCreated = requestSendsResponse(createJob, createJobResponse);
createJobWhenCreated.getJobClient().createFromXML("blagoo", payloadFromResource("/sample_job.xml"));
}
public void testCreateJobStringWhenResponseIs2xx() throws IOException {
JenkinsClient createJobWhenCreated = requestSendsResponse(createJob, createJobResponse);
createJobWhenCreated.getJobClient().createFromXML("blagoo", Strings2.toStringAndClose(getClass().getResourceAsStream("/sample_job.xml")));
}
public void testDeleteJobWhenResponseIs2xx() {

View File

@ -20,7 +20,6 @@ package org.jclouds.jenkins.v1.features;
import java.io.IOException;
import org.jclouds.io.Payloads;
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientLiveTest;
import org.jclouds.util.Strings2;
import org.testng.annotations.AfterClass;
@ -35,8 +34,7 @@ public class JobClientLiveTest extends BaseJenkinsClientLiveTest {
public void testCreateJob() throws IOException {
getClient().delete("blagoo");
getClient().createFromXML("blagoo",
Payloads.newPayload(Strings2.toStringAndClose(getClass().getResourceAsStream("/sample_job.xml"))));
getClient().createFromXML("blagoo", Strings2.toStringAndClose(getClass().getResourceAsStream("/sample_job.xml")));
}
@Test(dependsOnMethods = "testCreateJob")