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

This commit is contained in:
Noorul Islam K M 2013-09-09 11:13:11 +05:30 committed by Ignasi Barrera
parent 39d83e7d17
commit 7c4cf02c16
4 changed files with 72 additions and 45 deletions

View File

@ -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

View File

@ -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")));

View File

@ -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"
}