mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 15:08:28 +00:00
added get job
This commit is contained in:
parent
5ee2cf6748
commit
a03565003f
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.jenkins.v1.features;
|
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.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
@ -25,12 +27,14 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
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.filters.BasicAuthenticationUnlessAnonymous;
|
||||||
import org.jclouds.jenkins.v1.functions.ReturnVoidOn302Or404;
|
import org.jclouds.jenkins.v1.functions.ReturnVoidOn302Or404;
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
@ -51,7 +55,16 @@ public interface JobAsyncClient {
|
|||||||
@Path("/createItem")
|
@Path("/createItem")
|
||||||
@Produces(MediaType.TEXT_XML)
|
@Produces(MediaType.TEXT_XML)
|
||||||
ListenableFuture<Void> createFromXML(@QueryParam("name") String displayName, @BinderParam(BindToStringPayload.class) String 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
|
* @see JobClient#delete
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +21,7 @@ package org.jclouds.jenkins.v1.features;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.jenkins.v1.domain.JobDetails;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Job Services
|
* Job Services
|
||||||
@ -40,6 +41,8 @@ public interface JobClient {
|
|||||||
*/
|
*/
|
||||||
void createFromXML(String displayName, String xml);
|
void createFromXML(String displayName, String xml);
|
||||||
|
|
||||||
|
JobDetails get(String displayName);
|
||||||
|
|
||||||
void delete(String displayName);
|
void delete(String displayName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.jenkins.v1.features;
|
package org.jclouds.jenkins.v1.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
@ -25,6 +28,7 @@ import org.jclouds.http.HttpRequest;
|
|||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.jenkins.v1.JenkinsClient;
|
import org.jclouds.jenkins.v1.JenkinsClient;
|
||||||
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientExpectTest;
|
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientExpectTest;
|
||||||
|
import org.jclouds.jenkins.v1.parse.ParseJobDetailsTest;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -83,4 +87,32 @@ public class JobClientExpectTest extends BaseJenkinsClientExpectTest {
|
|||||||
|
|
||||||
deleteJobWhenDeleted.getJobClient().delete("blagoo");
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.jenkins.v1.features;
|
package org.jclouds.jenkins.v1.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jclouds.jenkins.v1.domain.JobDetails;
|
||||||
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientLiveTest;
|
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientLiveTest;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
@ -38,6 +42,13 @@ public class JobClientLiveTest extends BaseJenkinsClientLiveTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateJob")
|
@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() {
|
public void testDeleteJob() {
|
||||||
getClient().delete("blagoo");
|
getClient().delete("blagoo");
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user