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:45 UTC
[19/50] [abbrv] git commit: JCLOUDS-272: Migrate list roles,
cookbooks and databags tests from ChefApiTest to ChefApiExpectTest.
JCLOUDS-272: Migrate list roles, cookbooks and databags 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/b2c44b4a
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/b2c44b4a
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/b2c44b4a
Branch: refs/heads/master
Commit: b2c44b4a537e3c0c201155d0782662af31099a98
Parents: 2b3bcaf
Author: Noorul Islam K M <no...@noorul.com>
Authored: Sun Oct 13 11:48:28 2013 +0530
Committer: Ignasi Barrera <na...@apache.org>
Committed: Tue Oct 15 23:09:23 2013 +0200
----------------------------------------------------------------------
.../org/jclouds/chef/ChefApiExpectTest.java | 57 ++++++++++++++++++++
.../test/java/org/jclouds/chef/ChefApiTest.java | 51 ------------------
apis/chef/src/test/resources/data_list.json | 4 ++
apis/chef/src/test/resources/roles_list.json | 4 ++
4 files changed, 65 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/b2c44b4a/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 90e99da..4417f0d 100644
--- a/apis/chef/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
+++ b/apis/chef/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/jclouds/blob/b2c44b4a/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 05eca4b..28df35f 100644
--- a/apis/chef/src/test/java/org/jclouds/chef/ChefApiTest.java
+++ b/apis/chef/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/jclouds/blob/b2c44b4a/apis/chef/src/test/resources/data_list.json
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/resources/data_list.json b/apis/chef/src/test/resources/data_list.json
new file mode 100644
index 0000000..de9205d
--- /dev/null
+++ b/apis/chef/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/jclouds/blob/b2c44b4a/apis/chef/src/test/resources/roles_list.json
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/resources/roles_list.json b/apis/chef/src/test/resources/roles_list.json
new file mode 100644
index 0000000..1f75bc1
--- /dev/null
+++ b/apis/chef/src/test/resources/roles_list.json
@@ -0,0 +1,4 @@
+{
+ "webserver": "http://localhost:4000/roles/webserver",
+ "smtpserver": "http://localhost:4000/roles/smtpserver"
+}