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

Commit

Permalink
Fixed cookbook upload tests
Browse files Browse the repository at this point in the history
There was an issue when commiting the sandbox after uploading its
contents. We were sending the is_complete flag as a String when the Chef
Server expected a boolean flag. Fixing the binder fixed the live test.
  • Loading branch information
Ignasi Barrera committed Jul 3, 2012
1 parent bbeec9b commit d09640e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class BindIsCompletedToJsonPayload extends BindToStringPayload {


@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload ) { public <R extends HttpRequest> R bindToRequest(R request, Object payload ) {
super.bindToRequest(request, String.format("{\"is_completed\":\"%s\"}", payload)); super.bindToRequest(request, String.format("{\"is_completed\":%s}", payload));
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON);
return request; return request;
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testCommitSandbox() throws SecurityException, NoSuchMethodException,
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1"); "PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncClient.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncClient.VERSION + "-test\n");
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}", "application/json", false); assertPayloadEquals(httpRequest, "{\"is_completed\":true}", "application/json", false);


assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ public void testCreateNewCookbook() throws Exception {
} }


// create a new cookbook // create a new cookbook
CookbookVersion cookbook = new CookbookVersion("test3", "0.0.0"); CookbookVersion cookbook = new CookbookVersion(PREFIX, "0.0.0");
cookbook.getRootFiles().add(new Resource(content)); cookbook.getRootFiles().add(new Resource(content));


// upload the cookbook to the remote server // upload the cookbook to the remote server
chefClient.updateCookbook("test3", "0.0.0", cookbook); chefClient.updateCookbook(PREFIX, "0.0.0", cookbook);
} }


@Test(dependsOnMethods = "testCreateClient") @Test(dependsOnMethods = "testCreateClient")
Expand Down Expand Up @@ -168,22 +168,13 @@ public void testListCookbooks() throws Exception {


@Test(dependsOnMethods = "testCreateNewCookbook") @Test(dependsOnMethods = "testCreateNewCookbook")
public void testUpdateCookbook() throws Exception { public void testUpdateCookbook() throws Exception {
for (String cookbook : chefClient.listCookbooks()) CookbookVersion cookbook = chefClient.getCookbook(PREFIX, "0.0.0");
for (String version : chefClient.getVersionsOfCookbook(cookbook)) { assertNotNull(chefClient.updateCookbook(PREFIX, "0.0.0", cookbook));
CookbookVersion cook = chefClient.getCookbook(cookbook, version);
chefClient.updateCookbook(cookbook, version, cook);
}
} }


@Test(dependsOnMethods = {"testCreateNewCookbook", "testUpdateCookbook"}, enabled = false) @Test(dependsOnMethods = {"testCreateNewCookbook", "testUpdateCookbook"})
public void testCreateCookbook() throws Exception { public void testDeleteCookbook() throws Exception {
for (String cookbook : chefClient.listCookbooks()) assertNotNull(chefClient.deleteCookbook(PREFIX, "0.0.0"));
for (String version : chefClient.getVersionsOfCookbook(cookbook)) {
CookbookVersion cook = chefClient.getCookbook(cookbook, version);
chefClient.deleteCookbook(cookbook, version);
assert chefClient.getCookbook(cookbook, version) == null : cookbook + version;
chefClient.updateCookbook(cookbook, version, cook);
}
} }


@Test(expectedExceptions = AuthorizationException.class) @Test(expectedExceptions = AuthorizationException.class)
Expand Down

0 comments on commit d09640e

Please sign in to comment.