You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2014/10/10 15:13:40 UTC
[14/50] [abbrv] git commit: Make listCookbooksInEnvironment return an
empty set on 404
Make listCookbooksInEnvironment return an empty set on 404
Added tests to validate above.
Also factored out some duplicate code in test.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/0e4d32b9
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/0e4d32b9
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/0e4d32b9
Branch: refs/heads/master
Commit: 0e4d32b98ec0373b679eba2301e827968f6e7590
Parents: ce1cba6
Author: Noorul Islam K M <no...@noorul.com>
Authored: Thu Sep 19 17:16:30 2013 +0530
Committer: Ignasi Barrera <na...@apache.org>
Committed: Thu Sep 19 15:48:05 2013 +0200
----------------------------------------------------------------------
.../src/main/java/org/jclouds/chef/ChefApi.java | 11 +--
.../org/jclouds/chef/ChefApiExpectTest.java | 93 ++++++++------------
2 files changed, 45 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/0e4d32b9/apis/chef/src/main/java/org/jclouds/chef/ChefApi.java
----------------------------------------------------------------------
diff --git a/apis/chef/src/main/java/org/jclouds/chef/ChefApi.java b/apis/chef/src/main/java/org/jclouds/chef/ChefApi.java
index b8b4513..5601022 100644
--- a/apis/chef/src/main/java/org/jclouds/chef/ChefApi.java
+++ b/apis/chef/src/main/java/org/jclouds/chef/ChefApi.java
@@ -192,7 +192,7 @@ public interface ChefApi extends Closeable {
*
* @param environmentname The name of the environment to get the cookbooks
* from.
- * @return The definitions of the cookbooks (URL and versions) available in
+ * @return The definitions of the cookbooks (name, URL and versions) available in
* the given environment.
*/
@SinceApiVersion("0.10.0")
@@ -200,17 +200,18 @@ public interface ChefApi extends Closeable {
@GET
@ResponseParser(ParseCookbookDefinitionListFromJsonv10.class)
@Path("/environments/{environmentname}/cookbooks")
- @Fallback(NullOnNotFoundOr404.class)
+ @Fallback(EmptySetOnNotFoundOr404.class)
Set<CookbookDefinition> listCookbooksInEnvironment(@PathParam("environmentname") String environmentName);
/**
* Lists the cookbooks that are available in the given environment, limiting
* the number of versions returned for each cookbook.
*
- * @param environmentname The name of the environment.
+ * @param environmentname The name of the environment to get the cookbooks
+ * from.
* @param numversions The number of cookbook versions to include in the
* response, where n is the number of cookbook versions.
- * @return The definitions of the cookbooks (URL and versions) available in
+ * @return The definitions of the cookbooks (name, URL and versions) available in
* the given environment.
*/
@SinceApiVersion("0.10.0")
@@ -218,7 +219,7 @@ public interface ChefApi extends Closeable {
@GET
@ResponseParser(ParseCookbookDefinitionListFromJsonv10.class)
@Path("/environments/{environmentname}/cookbooks?num_versions={numversions}")
- @Fallback(NullOnNotFoundOr404.class)
+ @Fallback(EmptySetOnNotFoundOr404.class)
Set<CookbookDefinition> listCookbooksInEnvironment(@PathParam("environmentname") String environmentName,
@PathParam("numversions") String numVersions);
http://git-wip-us.apache.org/repos/asf/jclouds/blob/0e4d32b9/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java b/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
index 65344ef..634c5da 100644
--- a/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
+++ b/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
@@ -45,16 +45,20 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
provider = "chef";
}
+ private HttpRequest.Builder getHttpRequestBuilder(String method, String endPoint) {
+ return HttpRequest.builder() //
+ .method(method) //
+ .endpoint("http://localhost:4000" + endPoint) //
+ .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
+ .addHeader("Accept", MediaType.APPLICATION_JSON);
+ }
+
public void testListClientsReturns2xx() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/clients") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
- HttpResponse.builder().statusCode(200)
- .payload(payloadFromResourceWithContentType("/clients_list.json", MediaType.APPLICATION_JSON)) //
- .build());
+ signed(getHttpRequestBuilder("GET", "/clients").build()),
+ HttpResponse.builder().statusCode(200) //
+ .payload(payloadFromResourceWithContentType("/clients_list.json", MediaType.APPLICATION_JSON)) //
+ .build());
Set<String> nodes = api.listClients();
assertEquals(nodes.size(), 3);
assertTrue(nodes.contains("adam"), String.format("Expected nodes to contain 'adam' but was: %s", nodes));
@@ -62,11 +66,7 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
public void testListClientsReturns404() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/clients") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
+ signed(getHttpRequestBuilder("GET", "/clients").build()),
HttpResponse.builder().statusCode(404)
.build());
Set<String> clients = api.listClients();
@@ -75,11 +75,7 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
public void testListNodesReturns2xx() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/nodes") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
+ signed(getHttpRequestBuilder("GET", "/nodes").build()),
HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/nodes_list.json", MediaType.APPLICATION_JSON)) //
.build());
@@ -90,24 +86,15 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
public void testListNodesReturns404() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/nodes") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
- HttpResponse.builder().statusCode(404)
- .build());
+ signed(getHttpRequestBuilder("GET", "/nodes").build()),
+ HttpResponse.builder().statusCode(404).build());
Set<String> nodes = api.listNodes();
assertTrue(nodes.isEmpty(), String.format("Expected nodes to be empty but was: %s", nodes));
}
public void testListRecipesInEnvironmentReturns2xx() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/environments/dev/recipes") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
+ signed(getHttpRequestBuilder("GET", "/environments/dev/recipes").build()),
HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/environment_recipes.json", MediaType.APPLICATION_JSON)) //
.build());
@@ -118,24 +105,15 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
public void testListRecipesInEnvironmentReturns404() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/environments/dev/recipes") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
- HttpResponse.builder().statusCode(404)
- .build());
+ signed(getHttpRequestBuilder("GET", "/environments/dev/recipes").build()),
+ HttpResponse.builder().statusCode(404).build());
Set<String> recipes = api.listRecipesInEnvironment("dev");
assertTrue(recipes.isEmpty(), String.format("Expected recipes to be empty but was: %s", recipes));
}
public void testListNodesInEnvironmentReturns2xx() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/environments/dev/nodes") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
+ signed(getHttpRequestBuilder("GET", "/environments/dev/nodes").build()),
HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/nodes_list.json", MediaType.APPLICATION_JSON)) //
.build());
@@ -146,24 +124,15 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
public void testListNodesInEnvironmentReturns404() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/environments/dev/nodes") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
- HttpResponse.builder().statusCode(404)
- .build());
+ signed(getHttpRequestBuilder("GET", "/environments/dev/nodes").build()),
+ HttpResponse.builder().statusCode(404).build());
Set<String> nodes = api.listNodesInEnvironment("dev");
assertTrue(nodes.isEmpty(), String.format("Expected nodes to be empty but was: %s", nodes));
}
public void testListCookbooksInEnvironmentReturnsValidSet() {
ChefApi api = requestSendsResponse(
- signed(HttpRequest.builder() //
- .method("GET") //
- .endpoint("http://localhost:4000/environments/dev/cookbooks") //
- .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
- .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
+ signed(getHttpRequestBuilder("GET", "/environments/dev/cookbooks").build()),
HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/env_cookbooks.json", MediaType.APPLICATION_JSON)) //
.build());
@@ -171,6 +140,22 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
assertEquals(cookbooks.size(), 2);
}
+ public void testListCookbooksInEnvironmentReturnsEmptySetOn404() {
+ ChefApi api = requestSendsResponse(
+ signed(getHttpRequestBuilder("GET", "/environments/dev/cookbooks").build()),
+ HttpResponse.builder().statusCode(404).build());
+ Set<CookbookDefinition> cookbooks = api.listCookbooksInEnvironment("dev");
+ assertTrue(cookbooks.isEmpty(), String.format("Expected cookbooks to be empty but was: %s", cookbooks));
+ }
+
+ public void testListCookbooksInEnvironmentWithNumVersionReturnsEmptySetOn404() {
+ ChefApi api = requestSendsResponse(
+ signed(getHttpRequestBuilder("GET", "/environments/dev/cookbooks").addQueryParam("num_versions", "2").build()),
+ HttpResponse.builder().statusCode(404).build());
+ Set<CookbookDefinition> cookbooks = api.listCookbooksInEnvironment("dev", "2");
+ assertTrue(cookbooks.isEmpty(), String.format("Expected cookbooks to be empty but was: %s", cookbooks));
+ }
+
@Override
protected Module createModule() {
return new TestChefRestClientModule();