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:33 UTC

[07/50] [abbrv] git commit: JCLOUDS-272: Migrate unit tests from ChefApiTest to ChefApiExpectTest.

JCLOUDS-272: Migrate unit tests from ChefApiTest to ChefApiExpectTest.


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/58784cc4
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/58784cc4
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/58784cc4

Branch: refs/heads/master
Commit: 58784cc492c519afb460987daa8f4e2931035636
Parents: 174531e
Author: Noorul Islam K M <no...@noorul.com>
Authored: Mon Sep 9 11:13:11 2013 +0530
Committer: Ignasi Barrera <na...@apache.org>
Committed: Mon Sep 16 15:06:24 2013 +0200

----------------------------------------------------------------------
 .../org/jclouds/chef/ChefApiExpectTest.java     | 78 +++++++++++++++++---
 .../test/java/org/jclouds/chef/ChefApiTest.java | 34 ---------
 apis/chef/src/test/resources/clients_list.json  |  5 ++
 .../src/test/resources/environment_nodes.json   |  5 --
 apis/chef/src/test/resources/nodes_list.json    |  5 ++
 5 files changed, 77 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/58784cc4/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 f19b2ef..7706609 100644
--- a/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
+++ b/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
@@ -44,7 +44,63 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
      provider = "chef";
    }
 
-   public void testListEnvironmentRecipesReturns2xx() {
+   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());
+      Set<String> nodes = api.listClients();
+      assertEquals(nodes.size(), 3);
+      assertTrue(nodes.contains("adam"), String.format("Expected nodes to contain 'adam' but was: %s", nodes));
+   }
+
+   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()), //
+            HttpResponse.builder().statusCode(404)
+                  .build());
+      Set<String> clients = api.listClients();
+      assertTrue(clients.isEmpty(), String.format("Expected clients to be empty but was: %s", clients));
+   }
+
+   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()), //
+            HttpResponse.builder().statusCode(200)
+                  .payload(payloadFromResourceWithContentType("/nodes_list.json", MediaType.APPLICATION_JSON)) //
+                  .build());
+      Set<String> nodes = api.listNodes();
+      assertEquals(nodes.size(), 3);
+      assertTrue(nodes.contains("blah"), String.format("Expected nodes to contain 'blah' but was: %s", nodes));
+   }
+
+   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());
+      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") //
@@ -56,10 +112,10 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
                   .build());
       Set<String> recipes = api.listRecipesInEnvironment("dev");
       assertEquals(recipes.size(), 3);
-      assertTrue(recipes.contains("apache2"));
+      assertTrue(recipes.contains("apache2"), String.format("Expected recipes to contain 'apache2' but was: %s", recipes));
    }
 
-   public void testListEnvironmentRecipesReturns404() {
+   public void testListRecipesInEnvironmentReturns404() {
       ChefApi api = requestSendsResponse(
             signed(HttpRequest.builder() //
                   .method("GET") //
@@ -68,11 +124,11 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
                   .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
             HttpResponse.builder().statusCode(404)
                   .build());
-
-      assertTrue(api.listRecipesInEnvironment("dev").isEmpty());
+      Set<String> recipes = api.listRecipesInEnvironment("dev");
+      assertTrue(recipes.isEmpty(), String.format("Expected recipes to be empty but was: %s", recipes));
    }
 
-   public void testListEnvironmentNodesReturns2xx() {
+   public void testListNodesInEnvironmentReturns2xx() {
       ChefApi api = requestSendsResponse(
             signed(HttpRequest.builder() //
                   .method("GET") //
@@ -80,14 +136,14 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
                   .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) //
                   .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
             HttpResponse.builder().statusCode(200)
-                  .payload(payloadFromResourceWithContentType("/environment_nodes.json", MediaType.APPLICATION_JSON)) //
+                  .payload(payloadFromResourceWithContentType("/nodes_list.json", MediaType.APPLICATION_JSON)) //
                   .build());
       Set<String> nodes = api.listNodesInEnvironment("dev");
       assertEquals(nodes.size(), 3);
-      assertTrue(nodes.contains("blah"));
+      assertTrue(nodes.contains("blah"), String.format("Expected nodes to contain 'blah' but was: %s", nodes));
    }
 
-   public void testListEnvironmentNodesReturns404() {
+   public void testListNodesInEnvironmentReturns404() {
       ChefApi api = requestSendsResponse(
             signed(HttpRequest.builder() //
                   .method("GET") //
@@ -96,8 +152,8 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
                   .addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
             HttpResponse.builder().statusCode(404)
                   .build());
-
-      assertTrue(api.listNodesInEnvironment("dev").isEmpty());
+      Set<String> nodes = api.listNodesInEnvironment("dev");
+      assertTrue(nodes.isEmpty(), String.format("Expected nodes to be empty but was: %s", nodes));
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/jclouds/blob/58784cc4/apis/chef/src/test/java/org/jclouds/chef/ChefApiTest.java
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/java/org/jclouds/chef/ChefApiTest.java b/apis/chef/src/test/java/org/jclouds/chef/ChefApiTest.java
index 5ca105d..e6e2c66 100644
--- a/apis/chef/src/test/java/org/jclouds/chef/ChefApiTest.java
+++ b/apis/chef/src/test/java/org/jclouds/chef/ChefApiTest.java
@@ -279,23 +279,6 @@ public class ChefApiTest extends BaseAsyncApiTest<ChefApi> {
 
    }
 
-   public void testListClients() throws SecurityException, NoSuchMethodException, IOException {
-      Invokable<?, ?> method = method(ChefApi.class, "listClients");
-      GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
-
-      assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
-      assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefApiMetadata.DEFAULT_API_VERSION
-            + "-test\n");
-      assertPayloadEquals(httpRequest, null, null, false);
-
-      assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
-      assertSaxResponseParserClassEquals(method, null);
-      assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
-      checkFilters(httpRequest);
-
-   }
-
    public void testGenerateKeyForClient() throws SecurityException, NoSuchMethodException, IOException {
       Invokable<?, ?> method = method(ChefApi.class, "generateKeyForClient", String.class);
       GeneratedHttpRequest httpRequest = processor
@@ -375,23 +358,6 @@ public class ChefApiTest extends BaseAsyncApiTest<ChefApi> {
 
    }
 
-   public void testListNodes() throws SecurityException, NoSuchMethodException, IOException {
-      Invokable<?, ?> method = method(ChefApi.class, "listNodes");
-      GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
-
-      assertRequestLineEquals(httpRequest, "GET http://localhost:4000/nodes HTTP/1.1");
-      assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefApiMetadata.DEFAULT_API_VERSION
-            + "-test\n");
-      assertPayloadEquals(httpRequest, null, null, false);
-
-      assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
-      assertSaxResponseParserClassEquals(method, null);
-      assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
-      checkFilters(httpRequest);
-
-   }
-
    public void testDeleteRole() throws SecurityException, NoSuchMethodException, IOException {
       Invokable<?, ?> method = method(ChefApi.class, "deleteRole", String.class);
       GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("role")));

http://git-wip-us.apache.org/repos/asf/jclouds/blob/58784cc4/apis/chef/src/test/resources/clients_list.json
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/resources/clients_list.json b/apis/chef/src/test/resources/clients_list.json
new file mode 100644
index 0000000..000110b
--- /dev/null
+++ b/apis/chef/src/test/resources/clients_list.json
@@ -0,0 +1,5 @@
+{
+  "chef-webui": "http://localhost:4000/clients/chef-webui",
+  "chef-validator": "http://localhost:4000/clients/chef-validator",
+  "adam": "http://localhost:4000/clients/adam"
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/58784cc4/apis/chef/src/test/resources/environment_nodes.json
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/resources/environment_nodes.json b/apis/chef/src/test/resources/environment_nodes.json
deleted file mode 100644
index 92ef95a..0000000
--- a/apis/chef/src/test/resources/environment_nodes.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "blah": "https://api.opscode.com/org/directory/nodes/blah",
-  "boxer": "https://api.opscode.com/org/directory/nodes/boxer",
-  "blarrrrgh": "https://api.opscode.com/org/directory/nodes/blarrrrgh"
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/58784cc4/apis/chef/src/test/resources/nodes_list.json
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/resources/nodes_list.json b/apis/chef/src/test/resources/nodes_list.json
new file mode 100644
index 0000000..92ef95a
--- /dev/null
+++ b/apis/chef/src/test/resources/nodes_list.json
@@ -0,0 +1,5 @@
+{
+  "blah": "https://api.opscode.com/org/directory/nodes/blah",
+  "boxer": "https://api.opscode.com/org/directory/nodes/boxer",
+  "blarrrrgh": "https://api.opscode.com/org/directory/nodes/blarrrrgh"
+}