Updated Branches: refs/heads/master eecfbf016 -> 3bc628f9e
Removed redundant binders Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/commit/3bc628f9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/tree/3bc628f9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/diff/3bc628f9 Branch: refs/heads/master Commit: 3bc628f9ea62a4a5e91bb9c60e51a2f5a9756500 Parents: eecfbf0 Author: Ignasi Barrera <[email protected]> Authored: Tue Sep 3 10:29:27 2013 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Wed Sep 4 10:44:32 2013 +0200 ---------------------------------------------------------------------- .../src/main/java/org/jclouds/chef/ChefApi.java | 10 ++-- .../binders/BindClientnameToJsonPayload.java | 40 --------------- .../binders/BindIsCompletedToJsonPayload.java | 40 --------------- .../chef/binders/BindNameToJsonPayload.java | 40 --------------- .../enterprisechef/EnterpriseChefApi.java | 4 +- .../binders/BindGroupNameToJsonPayload.java | 42 ---------------- .../binders/BindGroupNameToJsonPayloadTest.java | 52 -------------------- 7 files changed, 6 insertions(+), 222 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/3bc628f9/core/src/main/java/org/jclouds/chef/ChefApi.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/ChefApi.java b/core/src/main/java/org/jclouds/chef/ChefApi.java index e319ea7..fb5366f 100644 --- a/core/src/main/java/org/jclouds/chef/ChefApi.java +++ b/core/src/main/java/org/jclouds/chef/ChefApi.java @@ -40,8 +40,6 @@ import org.jclouds.Fallbacks.VoidOnNotFoundOr404; import org.jclouds.chef.binders.BindChecksumsToJsonPayload; import org.jclouds.chef.binders.BindCreateClientOptionsToJsonPayload; import org.jclouds.chef.binders.BindGenerateKeyForClientToJsonPayload; -import org.jclouds.chef.binders.BindIsCompletedToJsonPayload; -import org.jclouds.chef.binders.BindNameToJsonPayload; import org.jclouds.chef.binders.DatabagItemId; import org.jclouds.chef.binders.EnvironmentName; import org.jclouds.chef.binders.NodeName; @@ -85,6 +83,7 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SinceApiVersion; import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.annotations.WrapWith; import org.jclouds.rest.binders.BindToJsonPayload; /** @@ -137,8 +136,7 @@ public interface ChefApi extends Closeable { @Named("sandbox:commit") @PUT @Path("/sandboxes/{id}") - Sandbox commitSandbox(@PathParam("id") String id, - @BinderParam(BindIsCompletedToJsonPayload.class) boolean isCompleted); + Sandbox commitSandbox(@PathParam("id") String id, @WrapWith("is_completed") boolean isCompleted); /** * @return a list of all the cookbook names @@ -503,7 +501,7 @@ public interface ChefApi extends Closeable { @Named("databag:create") @POST @Path("/data") - void createDatabag(@BinderParam(BindNameToJsonPayload.class) String databagName); + void createDatabag(@WrapWith("name") String databagName); /** * Delete a data bag, including its items @@ -779,7 +777,7 @@ public interface ChefApi extends Closeable { @Named("content:get") @GET @Fallback(NullOnNotFoundOr404.class) - @SkipEncoding({'+', ' ', '/', '=', ':', ';'}) + @SkipEncoding({ '+', ' ', '/', '=', ':', ';' }) InputStream getResourceContents(@EndpointParam(parser = UriForResource.class) Resource resource); /** http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/3bc628f9/core/src/main/java/org/jclouds/chef/binders/BindClientnameToJsonPayload.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/binders/BindClientnameToJsonPayload.java b/core/src/main/java/org/jclouds/chef/binders/BindClientnameToJsonPayload.java deleted file mode 100644 index 3f6dd97..0000000 --- a/core/src/main/java/org/jclouds/chef/binders/BindClientnameToJsonPayload.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.chef.binders; - -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.binders.BindToStringPayload; - -/** - * - * @author Adrian Cole - * - */ -@Singleton -public class BindClientnameToJsonPayload extends BindToStringPayload { - - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object payload) { - super.bindToRequest(request, String.format("{\"clientname\":\"%s\"}", payload)); - request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); - return request; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/3bc628f9/core/src/main/java/org/jclouds/chef/binders/BindIsCompletedToJsonPayload.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/binders/BindIsCompletedToJsonPayload.java b/core/src/main/java/org/jclouds/chef/binders/BindIsCompletedToJsonPayload.java deleted file mode 100644 index 105178e..0000000 --- a/core/src/main/java/org/jclouds/chef/binders/BindIsCompletedToJsonPayload.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.chef.binders; - -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.binders.BindToStringPayload; - -/** - * - * @author Adrian Cole - * - */ -@Singleton -public class BindIsCompletedToJsonPayload extends BindToStringPayload { - - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object payload) { - super.bindToRequest(request, String.format("{\"is_completed\":%s}", payload)); - request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); - return request; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/3bc628f9/core/src/main/java/org/jclouds/chef/binders/BindNameToJsonPayload.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/binders/BindNameToJsonPayload.java b/core/src/main/java/org/jclouds/chef/binders/BindNameToJsonPayload.java deleted file mode 100644 index 02fabef..0000000 --- a/core/src/main/java/org/jclouds/chef/binders/BindNameToJsonPayload.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.chef.binders; - -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.binders.BindToStringPayload; - -/** - * - * @author Adrian Cole - * - */ -@Singleton -public class BindNameToJsonPayload extends BindToStringPayload { - - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object payload) { - super.bindToRequest(request, String.format("{\"name\":\"%s\"}", payload)); - request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); - return request; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/3bc628f9/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java ---------------------------------------------------------------------- diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java index 0e0b2a6..33f85c6 100644 --- a/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java @@ -33,7 +33,6 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.chef.ChefApi; import org.jclouds.chef.filters.SignedHeaderAuth; import org.jclouds.chef.functions.ParseKeySetFromJson; -import org.jclouds.enterprisechef.binders.BindGroupNameToJsonPayload; import org.jclouds.enterprisechef.binders.BindGroupToUpdateRequestJsonPayload; import org.jclouds.enterprisechef.binders.GroupName; import org.jclouds.enterprisechef.domain.Group; @@ -44,6 +43,7 @@ import org.jclouds.rest.annotations.Headers; import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.WrapWith; /** * Provides synchronous access to the Enterprise Chef Api. @@ -98,7 +98,7 @@ public interface EnterpriseChefApi extends ChefApi @Named("group:create") @POST @Path("/groups") - void createGroup(@BinderParam(BindGroupNameToJsonPayload.class) String name); + void createGroup(@WrapWith("groupname") String name); /** * Updates a group. http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/3bc628f9/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java ---------------------------------------------------------------------- diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java b/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java deleted file mode 100644 index 47f1a9a..0000000 --- a/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.enterprisechef.binders; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.binders.BindToStringPayload; - -/** - * Binds the name of a group to the json payload. - * - * @author Ignasi Barrera - */ -@Singleton -public class BindGroupNameToJsonPayload extends BindToStringPayload { - - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object payload) { - super.bindToRequest(request, String.format("{\"groupname\":\"%s\"}", checkNotNull(payload, "payload"))); - request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); - return request; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/3bc628f9/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java ---------------------------------------------------------------------- diff --git a/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java b/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java deleted file mode 100644 index 4cb399f..0000000 --- a/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.enterprisechef.binders; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.enterprisechef.binders.BindGroupNameToJsonPayload; -import org.jclouds.http.HttpRequest; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link BindGroupNameToJsonPayload} class. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "BindGroupNameToJsonPayloadTest") -public class BindGroupNameToJsonPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindGroupNameToJsonPayload binder = new BindGroupNameToJsonPayload(); - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - public void testBindString() throws IOException { - BindGroupNameToJsonPayload binder = new BindGroupNameToJsonPayload(); - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - HttpRequest newRequest = binder.bindToRequest(request, "foo"); - - String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput()); - assertEquals(payload, "{\"groupname\":\"foo\"}"); - } -}
