mirror of https://github.com/apache/jclouds.git
JCLOUDS-256: Add missing API to list environment recipes
This commit is contained in:
parent
5d6ed8144b
commit
b5809e9d07
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -372,6 +372,11 @@ public class TransientChefApi implements ChefApi {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> listEnvironmentRecipes(String environmentname) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
closer.close();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
"ant",
|
||||
"apache2",
|
||||
"apache2::mod_auth_openid"
|
||||
]
|
||||
|
Loading…
Reference in New Issue