Updated Branches:
  refs/heads/master 7eddead37 -> a76209f09

JCLOUDS-272: Migrate list roles, cookbooks and databags tests from ChefApiTest 
to ChefApiExpectTest.


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/a76209f0
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/tree/a76209f0
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/diff/a76209f0

Branch: refs/heads/master
Commit: a76209f091fb855b54063e68e435ee2bf7e87236
Parents: 7eddead
Author: Noorul Islam K M <[email protected]>
Authored: Sun Oct 13 11:48:28 2013 +0530
Committer: Ignasi Barrera <[email protected]>
Committed: Tue Oct 15 23:09:23 2013 +0200

----------------------------------------------------------------------
 .../org/jclouds/chef/ChefApiExpectTest.java     | 57 ++++++++++++++++++++
 .../test/java/org/jclouds/chef/ChefApiTest.java | 51 ------------------
 core/src/test/resources/data_list.json          |  4 ++
 core/src/test/resources/roles_list.json         |  4 ++
 4 files changed, 65 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/a76209f0/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java 
b/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
index 90e99da..4417f0d 100644
--- a/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
+++ b/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
@@ -133,6 +133,25 @@ public class ChefApiExpectTest extends 
BaseChefApiExpectTest<ChefApi> {
       assertTrue(nodes.isEmpty(), String.format("Expected nodes to be empty 
but was: %s", nodes));
    }
 
+   public void testListCookbooksReturnsValidSet() {
+      ChefApi api = requestSendsResponse(
+            signed(getHttpRequestBuilder("GET", "/cookbooks").build()),
+            HttpResponse.builder().statusCode(200)
+                  
.payload(payloadFromResourceWithContentType("/env_cookbooks.json", 
MediaType.APPLICATION_JSON)) //
+                  .build());
+      Set<String> cookbooks = api.listCookbooks();
+      assertEquals(cookbooks.size(), 2);
+      assertTrue(cookbooks.contains("apache2"), String.format("Expected 
cookbooks to contain 'apache2' but was: %s", cookbooks));
+   }
+
+   public void testListCookbooksReturnsEmptySetOn404() {
+      ChefApi api = requestSendsResponse(
+            signed(getHttpRequestBuilder("GET", "/cookbooks").build()),
+            HttpResponse.builder().statusCode(404).build());
+      Set<String> cookbooks = api.listCookbooks();
+      assertTrue(cookbooks.isEmpty(), String.format("Expected cookbooks to be 
empty but was: %s", cookbooks));
+   }
+
    public void testListCookbooksInEnvironmentReturnsValidSet() {
       ChefApi api = requestSendsResponse(
             signed(getHttpRequestBuilder("GET", 
"/environments/dev/cookbooks").build()),
@@ -203,6 +222,44 @@ public class ChefApiExpectTest extends 
BaseChefApiExpectTest<ChefApi> {
       assertTrue(result.isEmpty(), String.format("Expected search result to be 
empty but was: %s", result));
    }
 
+   public void testListRolesReturnsValidSet() {
+      ChefApi api = requestSendsResponse(
+            signed(getHttpRequestBuilder("GET", "/roles").build()),
+            HttpResponse.builder().statusCode(200)
+                  
.payload(payloadFromResourceWithContentType("/roles_list.json", 
MediaType.APPLICATION_JSON)) //
+                  .build());
+      Set<String> roles = api.listRoles();
+      assertEquals(roles.size(), 2);
+      assertTrue(roles.contains("webserver"), String.format("Expected roles to 
contain 'websever' but was: %s", roles));
+   }
+
+   public void testListRolesReturnsEmptySetOn404() {
+      ChefApi api = requestSendsResponse(
+            signed(getHttpRequestBuilder("GET", "/roles").build()),
+            HttpResponse.builder().statusCode(404).build());
+      Set<String> roles = api.listRoles();
+      assertTrue(roles.isEmpty(), String.format("Expected roles to be empty 
but was: %s", roles));
+   }
+
+   public void testListDatabagsReturnsValidSet() {
+      ChefApi api = requestSendsResponse(
+            signed(getHttpRequestBuilder("GET", "/data").build()),
+            HttpResponse.builder().statusCode(200)
+                  
.payload(payloadFromResourceWithContentType("/data_list.json", 
MediaType.APPLICATION_JSON)) //
+                  .build());
+      Set<String> databags = api.listDatabags();
+      assertEquals(databags.size(), 2);
+      assertTrue(databags.contains("applications"), String.format("Expected 
databags to contain 'applications' but was: %s", databags));
+   }
+
+   public void testListDatabagsReturnsEmptySetOn404() {
+      ChefApi api = requestSendsResponse(
+            signed(getHttpRequestBuilder("GET", "/data").build()),
+            HttpResponse.builder().statusCode(404).build());
+      Set<String> databags = api.listDatabags();
+      assertTrue(databags.isEmpty(), String.format("Expected databags to be 
empty but was: %s", databags));
+   }
+
    @Override
    protected Module createModule() {
       return new TestChefRestClientModule();

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/a76209f0/core/src/test/java/org/jclouds/chef/ChefApiTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/jclouds/chef/ChefApiTest.java 
b/core/src/test/java/org/jclouds/chef/ChefApiTest.java
index 05eca4b..28df35f 100644
--- a/core/src/test/java/org/jclouds/chef/ChefApiTest.java
+++ b/core/src/test/java/org/jclouds/chef/ChefApiTest.java
@@ -192,23 +192,6 @@ public class ChefApiTest extends BaseAsyncApiTest<ChefApi> 
{
 
    }
 
-   public void testListCookbooks() throws SecurityException, 
NoSuchMethodException, IOException {
-      Invokable<?, ?> method = method(ChefApi.class, "listCookbooks");
-      GeneratedHttpRequest httpRequest = 
processor.apply(Invocation.create(method, ImmutableList.of()));
-
-      assertRequestLineEquals(httpRequest, "GET 
http://localhost:4000/cookbooks 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, 
ParseCookbookDefinitionCheckingChefVersion.class);
-      assertSaxResponseParserClassEquals(method, null);
-      assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
-      checkFilters(httpRequest);
-
-   }
-
    public void testListVersionsOfCookbook() throws SecurityException, 
NoSuchMethodException, IOException {
       Invokable<?, ?> method = method(ChefApi.class, "listVersionsOfCookbook", 
String.class);
       GeneratedHttpRequest httpRequest = processor
@@ -414,23 +397,6 @@ public class ChefApiTest extends BaseAsyncApiTest<ChefApi> 
{
 
    }
 
-   public void testListRoles() throws SecurityException, 
NoSuchMethodException, IOException {
-      Invokable<?, ?> method = method(ChefApi.class, "listRoles");
-      GeneratedHttpRequest httpRequest = 
processor.apply(Invocation.create(method, ImmutableList.of()));
-
-      assertRequestLineEquals(httpRequest, "GET http://localhost:4000/roles 
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 testDeleteDatabag() throws SecurityException, 
NoSuchMethodException, IOException {
       Invokable<?, ?> method = method(ChefApi.class, "deleteDatabag", 
String.class);
       GeneratedHttpRequest httpRequest = processor
@@ -465,23 +431,6 @@ public class ChefApiTest extends BaseAsyncApiTest<ChefApi> 
{
 
    }
 
-   public void testListDatabags() throws SecurityException, 
NoSuchMethodException, IOException {
-      Invokable<?, ?> method = method(ChefApi.class, "listDatabags");
-      GeneratedHttpRequest httpRequest = 
processor.apply(Invocation.create(method, ImmutableList.of()));
-
-      assertRequestLineEquals(httpRequest, "GET http://localhost:4000/data 
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 testDeleteDatabagItem() throws SecurityException, 
NoSuchMethodException, IOException {
       Invokable<?, ?> method = method(ChefApi.class, "deleteDatabagItem", 
String.class, String.class);
       GeneratedHttpRequest httpRequest = 
processor.apply(Invocation.create(method,

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/a76209f0/core/src/test/resources/data_list.json
----------------------------------------------------------------------
diff --git a/core/src/test/resources/data_list.json 
b/core/src/test/resources/data_list.json
new file mode 100644
index 0000000..de9205d
--- /dev/null
+++ b/core/src/test/resources/data_list.json
@@ -0,0 +1,4 @@
+{
+    "users": "http://localhost:4000/data/users";,
+    "applications": "http://localhost:4000/data/applications";
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/a76209f0/core/src/test/resources/roles_list.json
----------------------------------------------------------------------
diff --git a/core/src/test/resources/roles_list.json 
b/core/src/test/resources/roles_list.json
new file mode 100644
index 0000000..1f75bc1
--- /dev/null
+++ b/core/src/test/resources/roles_list.json
@@ -0,0 +1,4 @@
+{
+    "webserver": "http://localhost:4000/roles/webserver";,
+    "smtpserver": "http://localhost:4000/roles/smtpserver";
+}

Reply via email to