From a1ff6f3b59dab670ea8d0a35fdc81c09e31dda61 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 24 Apr 2012 21:53:32 -0700 Subject: [PATCH] easier param when job xml is already a string --- .../jenkins/v1/features/JobAsyncClient.java | 11 +++++++- .../jenkins/v1/features/JobClient.java | 2 ++ .../v1/features/JobClientExpectTest.java | 26 ++++++++++++------- .../v1/features/JobClientLiveTest.java | 4 +-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobAsyncClient.java b/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobAsyncClient.java index 4406138358..4e1deb3356 100644 --- a/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobAsyncClient.java +++ b/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobAsyncClient.java @@ -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 createFromXML(@QueryParam("name") String displayName, Payload xml); + /** + * @see JobClient#createFromXML(String, String) + */ + @POST + @Path("/createItem") + @Produces(MediaType.TEXT_XML) + ListenableFuture createFromXML(@QueryParam("name") String displayName, @BinderParam(BindToStringPayload.class) String xml); /** * @see JobClient#getJobView diff --git a/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobClient.java b/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobClient.java index 066f665d70..61568fdeb6 100644 --- a/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobClient.java +++ b/labs/jenkins/src/main/java/org/jclouds/jenkins/v1/features/JobClient.java @@ -41,6 +41,8 @@ public interface JobClient { */ void createFromXML(String displayName, Payload xml); + void createFromXML(String displayName, String xml); + void delete(String displayName); } diff --git a/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientExpectTest.java b/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientExpectTest.java index 9e4e8136db..d13e789aa4 100644 --- a/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientExpectTest.java +++ b/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientExpectTest.java @@ -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. 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. 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() { diff --git a/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientLiveTest.java b/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientLiveTest.java index 559ca177bb..0bff311ca8 100644 --- a/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientLiveTest.java +++ b/labs/jenkins/src/test/java/org/jclouds/jenkins/v1/features/JobClientLiveTest.java @@ -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")