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.
Expand Up @@ -34,7 +34,7 @@ public class BindIsCompletedToJsonPayload extends BindToStringPayload {

@Override
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);
return request;
}
Expand Down
Expand Up @@ -86,7 +86,7 @@ public void testCommitSandbox() throws SecurityException, NoSuchMethodException,
assertRequestLineEquals(httpRequest,
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
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);
assertSaxResponseParserClassEquals(method, null);
Expand Down
Expand Up @@ -130,11 +130,11 @@ public void testCreateNewCookbook() throws Exception {
}

// 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));

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

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

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

@Test(dependsOnMethods = {"testCreateNewCookbook", "testUpdateCookbook"}, enabled = false)
public void testCreateCookbook() throws Exception {
for (String cookbook : chefClient.listCookbooks())
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(dependsOnMethods = {"testCreateNewCookbook", "testUpdateCookbook"})
public void testDeleteCookbook() throws Exception {
assertNotNull(chefClient.deleteCookbook(PREFIX, "0.0.0"));
}

@Test(expectedExceptions = AuthorizationException.class)
Expand Down

0 comments on commit d09640e

Please sign in to comment.