Merge pull request #599 from andreaturli/master

jenkins api: added buildWithParameters with Mulpmaps.for(map)
This commit is contained in:
Ivan Meredith 2012-05-02 02:06:30 -07:00
commit 33503970bb
5 changed files with 138 additions and 1 deletions

View File

@ -0,0 +1,58 @@
/**
* 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.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.utils.ModifyRequest.addQueryParams;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import com.google.common.collect.Multimaps;
/**
* Binds the map to parameters.
*
* @author Andrea Turli
*/
public class BindMapToOptionalParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindMapToOptionalParams(Provider<UriBuilder> builder) {
this.builder = checkNotNull(builder, "builder");
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Maps!");
Map<String, String> map = (Map<String, String>) input;
request = addQueryParams(request, Multimaps.forMap(map), builder.get());
return request;
}
}

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.jenkins.v1.features; package org.jclouds.jenkins.v1.features;
import java.util.Map;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
@ -25,14 +27,19 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.jclouds.jenkins.v1.binders.BindMapToOptionalParams;
import org.jclouds.jenkins.v1.domain.JobDetails; 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.BindMapToMatrixParams;
import org.jclouds.rest.binders.BindMapToStringPayload;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -81,6 +88,15 @@ public interface JobAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Void> build(@PathParam("displayName") String displayName); ListenableFuture<Void> build(@PathParam("displayName") String displayName);
/**
* @see JobClient#buildJobWithParameters
*/
@POST
@Path("/job/{displayName}/buildWithParameters")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Void> buildWithParameters(@PathParam("displayName") String displayName,
@BinderParam(BindMapToOptionalParams.class) Map<String, String> parameters);
/** /**
* @see JobClient#fetchConfigXML * @see JobClient#fetchConfigXML
*/ */

View File

@ -18,8 +18,12 @@
*/ */
package org.jclouds.jenkins.v1.features; package org.jclouds.jenkins.v1.features;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.ws.rs.core.UriInfo;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.jenkins.v1.domain.JobDetails; import org.jclouds.jenkins.v1.domain.JobDetails;
@ -55,6 +59,8 @@ public interface JobClient {
*/ */
void build(String displayName); void build(String displayName);
void buildWithParameters(String displayName, Map<String, String> parameters);
String fetchConfigXML(String displayName); String fetchConfigXML(String displayName);
} }

View File

@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import org.jclouds.jenkins.v1.domain.JobDetails; import org.jclouds.jenkins.v1.domain.JobDetails;
import org.jclouds.jenkins.v1.internal.BaseJenkinsClientLiveTest; import org.jclouds.jenkins.v1.internal.BaseJenkinsClientLiveTest;
@ -29,6 +30,8 @@ import org.jclouds.util.Strings2;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -66,11 +69,28 @@ public class JobClientLiveTest extends BaseJenkinsClientLiveTest {
getClient().delete("blagoo"); getClient().delete("blagoo");
} }
@Test(dependsOnMethods = "testDeleteJob")
public void testCreateJobWithParameters() throws IOException {
getClient().delete("jobWithParameters");
getClient().createFromXML("jobWithParameters", Strings2.toStringAndClose(getClass().getResourceAsStream("/sample_job_with_parameters.xml")));
}
@Test(dependsOnMethods = "testCreateJobWithParameters")
public void testBuildJobWithParameters() throws IOException {
Map<String, String> parameters = ImmutableMap.of("name", "test1", "password", "secret");
getClient().buildWithParameters("jobWithParameters", parameters);
}
@Test(dependsOnMethods = "testBuildJob")
public void testDeleteJobWithParameters() {
getClient().delete("jobWithParameters");
}
@AfterClass(groups = { "integration", "live" }) @AfterClass(groups = { "integration", "live" })
@Override @Override
protected void tearDownContext() { protected void tearDownContext() {
getClient().delete("blagoo"); getClient().delete("blagoo");
getClient().delete("blagooCopy"); getClient().delete("jobWithParameters");
super.tearDownContext(); super.tearDownContext();
} }

View File

@ -0,0 +1,37 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions />
<description />
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>name</name>
<description />
<defaultValue />
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>password</name>
<description />
<defaultValue />
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.scm.NullSCM" />
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false
</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers class="vector" />
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>echo hello</command>
</hudson.tasks.Shell>
</builders>
<publishers />
<buildWrappers />
</project>