Updated Branches: refs/heads/master 3f2a196f2 -> eecfbf016
JCLOUDS-256: Add missing API to list environment recipes Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/commit/83f4081a Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/tree/83f4081a Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/diff/83f4081a Branch: refs/heads/master Commit: 83f4081a02fda257f9209cb1b697fcd1242c9dce Parents: 3f2a196 Author: Noorul Islam K M <[email protected]> Authored: Tue Sep 3 16:21:33 2013 +0530 Committer: Ignasi Barrera <[email protected]> Committed: Wed Sep 4 10:39:31 2013 +0200 ---------------------------------------------------------------------- .../src/main/java/org/jclouds/chef/ChefApi.java | 15 ++++ .../org/jclouds/chef/test/TransientChefApi.java | 5 ++ .../org/jclouds/chef/ChefApiExpectTest.java | 95 ++++++++++++++++++++ .../chef/internal/BaseChefApiLiveTest.java | 6 ++ .../src/test/resources/environment_recipes.json | 6 ++ 5 files changed, 127 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/83f4081a/core/src/main/java/org/jclouds/chef/ChefApi.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/ChefApi.java b/core/src/main/java/org/jclouds/chef/ChefApi.java index faa189c..9dd1df4 100644 --- a/core/src/main/java/org/jclouds/chef/ChefApi.java +++ b/core/src/main/java/org/jclouds/chef/ChefApi.java @@ -923,4 +923,19 @@ public interface ChefApi extends Closeable { @Path("/environments/{environmentname}/cookbooks/{cookbookname}?num_versions={numversions}") CookbookDefinition getEnvironmentCookbook(@PathParam("environmentname") String environmentname, @PathParam("cookbookname") String cookbookname, @PathParam("numversions") String numversions); + + /** + * @return List of environment recipes. + * @throws AuthorizationException + * <p/> + * "401 Unauthorized" if you are not a recognized user. + * <p/> + * "403 Forbidden" if you do not have rights to list environment recipes. + */ + @SinceApiVersion("0.10.0") + @Named("environment:recipelist") + @GET + @Path("/environments/{environmentname}/recipes") + @Fallback(EmptySetOnNotFoundOr404.class) + Set<String> listEnvironmentRecipes(@PathParam("environmentname") String environmentname); } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/83f4081a/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java b/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java index 908ae2f..90919b7 100644 --- a/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java +++ b/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java @@ -373,6 +373,11 @@ public class TransientChefApi implements ChefApi { } @Override + public Set<String> listEnvironmentRecipes(String environmentname) { + throw new UnsupportedOperationException(); + } + + @Override public void close() throws IOException { closer.close(); } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/83f4081a/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java b/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java new file mode 100644 index 0000000..fd34e2c --- /dev/null +++ b/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.chef; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.chef.BaseChefApiExpectTest; +import org.jclouds.chef.ChefApi; +import org.jclouds.date.TimeStamp; +import org.jclouds.chef.config.ChefHttpApiModule; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rest.ConfiguresRestClient; +import org.testng.annotations.Test; + +import com.google.common.base.Supplier; +import com.google.inject.Module; + +/** + * Expect tests for the {@link ChefApi} class. + * + * @author Noorul Islam K M + */ +@Test(groups = "unit", testName = "ChefApiExpectTest") +public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> { + public ChefApiExpectTest() { + provider = "chef"; + } + + public void testListEnvironmentRecipesReturns2xx() { + ChefApi api = requestSendsResponse( + signed(HttpRequest.builder() // + .method("GET") // + .endpoint("http://localhost:4000/environments/dev/recipes") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // + HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/environment_recipes.json", MediaType.APPLICATION_JSON)) // + .build()); + Set<String> recipes = api.listEnvironmentRecipes("dev"); + assertEquals(recipes.size(), 3); + assertTrue(recipes.contains("apache2")); + } + + public void testListEnvironmentRecipesReturns404() { + ChefApi api = requestSendsResponse( + signed(HttpRequest.builder() // + .method("GET") // + .endpoint("http://localhost:4000/environments/dev/recipes") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // + HttpResponse.builder().statusCode(404) + .build()); + + assertTrue(api.listEnvironmentRecipes("dev").isEmpty()); + } + + @Override + protected Module createModule() { + return new TestChefRestClientModule(); + } + + @ConfiguresRestClient + static class TestChefRestClientModule extends ChefHttpApiModule { + @Override + protected String provideTimeStamp(@TimeStamp Supplier<String> cache) { + return "timestamp"; + } + } + + @Override + protected ChefApiMetadata createApiMetadata() { + return new ChefApiMetadata(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/83f4081a/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java b/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java index 529df68..7256323 100644 --- a/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java +++ b/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java @@ -464,6 +464,12 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv assertTrue(waitForIndex.apply(options)); } + @Test(dependsOnMethods = "testCreateEnvironment") + public void testListEnvironmentRecipes() { + Set<String> recipeList = api.listEnvironmentRecipes(PREFIX); + assertTrue(!recipeList.isEmpty()); + } + @AfterClass(groups = { "live", "integration" }) @Override public void tearDown() { http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/83f4081a/core/src/test/resources/environment_recipes.json ---------------------------------------------------------------------- diff --git a/core/src/test/resources/environment_recipes.json b/core/src/test/resources/environment_recipes.json new file mode 100644 index 0000000..cca3a11 --- /dev/null +++ b/core/src/test/resources/environment_recipes.json @@ -0,0 +1,6 @@ +[ + "ant", + "apache2", + "apache2::mod_auth_openid" +] +
