Skip to content
This repository has been archived by the owner on Feb 4, 2019. It is now read-only.

Commit

Permalink
JCLOUDS-272: Migrate list roles, cookbooks and databags tests from Ch…
Browse files Browse the repository at this point in the history
…efApiTest to ChefApiExpectTest.
  • Loading branch information
noorul authored and nacx committed Oct 15, 2013
1 parent 7eddead commit a76209f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 51 deletions.
57 changes: 57 additions & 0 deletions core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java
Expand Up @@ -133,6 +133,25 @@ public void testListNodesInEnvironmentReturnsEmptySetOn404() {
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()),
Expand Down Expand Up @@ -203,6 +222,44 @@ public void testSearchRolesWithOptionsReturnsEmptyResult() {
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();
Expand Down
51 changes: 0 additions & 51 deletions core/src/test/java/org/jclouds/chef/ChefApiTest.java
Expand Up @@ -192,23 +192,6 @@ public void testUpdateCookbook() throws SecurityException, NoSuchMethodException

}

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
Expand Down Expand Up @@ -414,23 +397,6 @@ public void testUpdateRole() throws SecurityException, NoSuchMethodException, IO

}

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
Expand Down Expand Up @@ -465,23 +431,6 @@ public void testCreateDatabag() throws SecurityException, NoSuchMethodException,

}

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,
Expand Down
4 changes: 4 additions & 0 deletions core/src/test/resources/data_list.json
@@ -0,0 +1,4 @@
{
"users": "http://localhost:4000/data/users",
"applications": "http://localhost:4000/data/applications"
}
4 changes: 4 additions & 0 deletions core/src/test/resources/roles_list.json
@@ -0,0 +1,4 @@
{
"webserver": "http://localhost:4000/roles/webserver",
"smtpserver": "http://localhost:4000/roles/smtpserver"
}

0 comments on commit a76209f

Please sign in to comment.