diff --git a/apis/chef/src/main/java/org/jclouds/chef/domain/CookbookVersion.java b/apis/chef/src/main/java/org/jclouds/chef/domain/CookbookVersion.java index df9bd822ec..01abb646fd 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/domain/CookbookVersion.java +++ b/apis/chef/src/main/java/org/jclouds/chef/domain/CookbookVersion.java @@ -38,7 +38,7 @@ public class CookbookVersion { public static class Builder { private String cookbookName; private ImmutableSet.Builder definitions = ImmutableSet.builder(); - private ImmutableSet.Builder attributes = ImmutableSet.builder(); + private ImmutableSet.Builder attributes = ImmutableSet.builder(); private ImmutableSet.Builder files = ImmutableSet.builder(); private Metadata metadata = Metadata.builder().build(); private ImmutableSet.Builder providers = ImmutableSet.builder(); @@ -69,12 +69,12 @@ public class CookbookVersion { return this; } - public Builder attribute(Attribute attribute) { + public Builder attribute(Resource attribute) { this.attributes.add(checkNotNull(attribute, "attribute")); return this; } - public Builder attributes(Iterable attributes) { + public Builder attributes(Iterable attributes) { this.attributes.addAll(checkNotNull(attributes, "attributes")); return this; } @@ -168,7 +168,7 @@ public class CookbookVersion { private final String name; private final Set definitions; - private final Set attributes; + private final Set attributes; private final Set files; private final Metadata metadata; private final Set providers; @@ -190,7 +190,7 @@ public class CookbookVersion { @ConstructorProperties({ "name", "definitions", "attributes", "files", "metadata", "providers", "cookbook_name", "resources", "templates", "libraries", "version", "recipes", "root_files" }) - protected CookbookVersion(String name, @Nullable Set definitions, @Nullable Set attributes, + protected CookbookVersion(String name, @Nullable Set definitions, @Nullable Set attributes, @Nullable Set files, Metadata metadata, @Nullable Set providers, String cookbookName, @Nullable Set resources, @Nullable Set templates, @Nullable Set libraries, String version, @Nullable Set recipes, @Nullable Set rootFiles) { @@ -217,7 +217,7 @@ public class CookbookVersion { return definitions; } - public Set getAttributes() { + public Set getAttributes() { return attributes; } diff --git a/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java index a477be0363..42a5cc21d3 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java @@ -30,6 +30,7 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.Collections; import java.util.List; @@ -85,6 +86,30 @@ public abstract class BaseChefApiLiveTest extends BaseChefLiv public void testCreateNewCookbook() throws Exception { // Define the file you want in the cookbook File file = new File(System.getProperty("user.dir"), "pom.xml"); + FilePayload content = uploadAndGetFilePayload(file); + + // Create the metadata of the cookbook + Metadata metadata = Metadata.builder() // + .name(PREFIX) // + .version("0.0.0") // + .description("Jclouds test uploaded cookbook") // + .maintainer("jclouds") // + .maintainerEmail("someone@jclouds.org") // + .license("Apache 2.0") // + .build(); + + // Create a new cookbook + CookbookVersion cookbook = CookbookVersion.builder(PREFIX, "0.0.0") // + .metadata(metadata) // + .rootFile(Resource.builder().fromPayload(content).build()) // + .attribute(Resource.builder().fromPayload(content).name("default.rb").build()) + .build(); + + // upload the cookbook to the remote server + api.updateCookbook(PREFIX, "0.0.0", cookbook); + } + + private FilePayload uploadAndGetFilePayload(File file) throws IOException { FilePayload content = Payloads.newFilePayload(file); content.getContentMetadata().setContentType("application/x-binary"); @@ -111,25 +136,7 @@ public abstract class BaseChefApiLiveTest extends BaseChefLiv api.commitSandbox(site.getSandboxId(), false); fail("Could not upload content"); } - - // Create the metadata of the cookbook - Metadata metadata = Metadata.builder() // - .name(PREFIX) // - .version("0.0.0") // - .description("Jclouds test uploaded cookbook") // - .maintainer("jclouds") // - .maintainerEmail("someone@jclouds.org") // - .license("Apache 2.0") // - .build(); - - // Create a new cookbook - CookbookVersion cookbook = CookbookVersion.builder(PREFIX, "0.0.0") // - .metadata(metadata) // - .rootFile(Resource.builder().fromPayload(content).build()) // - .build(); - - // upload the cookbook to the remote server - api.updateCookbook(PREFIX, "0.0.0", cookbook); + return content; } public void testListCookbooks() throws Exception { @@ -158,9 +165,9 @@ public abstract class BaseChefApiLiveTest extends BaseChefLiv Iterable cookbooks = chefService.listCookbookVersions(); for (CookbookVersion cookbook : cookbooks) { for (Resource resource : ImmutableList. builder().addAll(cookbook.getDefinitions()) - .addAll(cookbook.getFiles()).addAll(cookbook.getLibraries()).addAll(cookbook.getSuppliers()) - .addAll(cookbook.getRecipes()).addAll(cookbook.getResources()).addAll(cookbook.getRootFiles()) - .addAll(cookbook.getTemplates()).build()) { + .addAll(cookbook.getFiles()).addAll(cookbook.getLibraries()).addAll(cookbook.getSuppliers()) + .addAll(cookbook.getRecipes()).addAll(cookbook.getResources()).addAll(cookbook.getRootFiles()) + .addAll(cookbook.getTemplates()).addAll(cookbook.getAttributes()).build()) { InputStream stream = api.getResourceContents(resource); assertNotNull(stream, "Resource contents are null for resource: " + resource.getName());