added get job

This commit is contained in:
Adrian Cole 2012-04-24 23:36:06 -07:00
parent 5ee2cf6748
commit a03565003f
5 changed files with 110 additions and 1 deletions

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.jenkins.v1.features;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@ -25,12 +27,14 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.jenkins.v1.domain.JobDetails;
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 org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -51,7 +55,16 @@ public interface JobAsyncClient {
@Path("/createItem")
@Produces(MediaType.TEXT_XML)
ListenableFuture<Void> createFromXML(@QueryParam("name") String displayName, @BinderParam(BindToStringPayload.class) String xml);
/**
* @see JobClient#get
*/
@GET
@Path("/job/{displayName}/api/json")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<JobDetails> get(@PathParam("displayName") String displayName);
/**
* @see JobClient#delete
*/

View File

@ -21,6 +21,7 @@ package org.jclouds.jenkins.v1.features;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.jenkins.v1.domain.JobDetails;
/**
* Job Services
@ -40,6 +41,8 @@ public interface JobClient {
*/
void createFromXML(String displayName, String xml);
JobDetails get(String displayName);
void delete(String displayName);
}

View File

@ -18,6 +18,9 @@
*/
package org.jclouds.jenkins.v1.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import java.io.IOException;
import java.net.URI;
@ -25,6 +28,7 @@ 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.jenkins.v1.parse.ParseJobDetailsTest;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
@ -83,4 +87,32 @@ public class JobClientExpectTest extends BaseJenkinsClientExpectTest {
deleteJobWhenDeleted.getJobClient().delete("blagoo");
}
HttpRequest getJob = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/job/ddd/api/json"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.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"));
}
}

View File

@ -18,8 +18,12 @@
*/
package org.jclouds.jenkins.v1.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import org.jclouds.jenkins.v1.domain.JobDetails;
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientLiveTest;
import org.jclouds.util.Strings2;
import org.testng.annotations.AfterClass;
@ -38,6 +42,13 @@ public class JobClientLiveTest extends BaseJenkinsClientLiveTest {
}
@Test(dependsOnMethods = "testCreateJob")
public void testGetJob() throws IOException {
JobDetails job = getClient().get("blagoo");
assertNotNull(job);
assertEquals(job.getName(), "blagoo");
}
@Test(dependsOnMethods = "testGetJob")
public void testDeleteJob() {
getClient().delete("blagoo");
}

View File

@ -0,0 +1,50 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.jenkins.v1.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.jenkins.v1.domain.JobDetails;
import org.jclouds.json.BaseItemParserTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ParseJobDetailsTest")
public class ParseJobDetailsTest extends BaseItemParserTest<JobDetails> {
@Override
public String resource() {
return "/job.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public JobDetails expected() {
return JobDetails.builder()
.name("ddd")
.url(URI.create("http://localhost:8080/job/ddd/"))
.color("grey").build();
}
}