mirror of https://github.com/apache/jclouds.git
JCLOUDS-82: Use unwrapApi from View and remove custom method in ChefContext
This commit is contained in:
parent
474f7fffad
commit
543dc025c4
|
@ -36,9 +36,4 @@ public interface ChefContext extends View, Closeable {
|
||||||
*/
|
*/
|
||||||
ChefService getChefService();
|
ChefService getChefService();
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides access to the underlying Chef api.
|
|
||||||
*/
|
|
||||||
<A extends ChefApi> A getApi(Class<A> apiClass);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,11 +46,9 @@ public class CookbookVersion {
|
||||||
private Set<Resource> rootFiles = Sets.newLinkedHashSet();
|
private Set<Resource> rootFiles = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@SerializedName("json_class")
|
@SerializedName("json_class")
|
||||||
private String _jsonClass = "Chef::CookbookVersion";
|
private String _jsonClass = "Chef::CookbookVersion";
|
||||||
@SerializedName("chef_type")
|
@SerializedName("chef_type")
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private String _chefType = "cookbook_version";
|
private String _chefType = "cookbook_version";
|
||||||
|
|
||||||
public CookbookVersion(String cookbookName, String version) {
|
public CookbookVersion(String cookbookName, String version) {
|
||||||
|
|
|
@ -33,10 +33,8 @@ public class Environment {
|
||||||
@SerializedName("cookbook_versions")
|
@SerializedName("cookbook_versions")
|
||||||
private Map<String, String> cookbookVersions = Maps.newLinkedHashMap();
|
private Map<String, String> cookbookVersions = Maps.newLinkedHashMap();
|
||||||
// internal
|
// internal
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@SerializedName("json_class")
|
@SerializedName("json_class")
|
||||||
private String _jsonClass = "Chef::Environment";
|
private String _jsonClass = "Chef::Environment";
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@SerializedName("chef_type")
|
@SerializedName("chef_type")
|
||||||
private String _chefType = "environment";
|
private String _chefType = "environment";
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,9 @@ public class Sandbox {
|
||||||
private String guid;
|
private String guid;
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@SerializedName("json_class")
|
@SerializedName("json_class")
|
||||||
private String _jsonClass = "Chef::Sandbox";
|
private String _jsonClass = "Chef::Sandbox";
|
||||||
@SerializedName("chef_type")
|
@SerializedName("chef_type")
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private String _chefType = "sandbox";
|
private String _chefType = "sandbox";
|
||||||
|
|
||||||
public Sandbox(String rev, boolean isCompleted, Date createTime, Iterable<String> checksums, String name, String guid) {
|
public Sandbox(String rev, boolean isCompleted, Date createTime, Iterable<String> checksums, String name, String guid) {
|
||||||
|
|
|
@ -24,14 +24,11 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Context;
|
import org.jclouds.Context;
|
||||||
import org.jclouds.chef.ChefApi;
|
|
||||||
import org.jclouds.chef.ChefContext;
|
import org.jclouds.chef.ChefContext;
|
||||||
import org.jclouds.chef.ChefService;
|
import org.jclouds.chef.ChefService;
|
||||||
import org.jclouds.internal.BaseView;
|
import org.jclouds.internal.BaseView;
|
||||||
import org.jclouds.location.Provider;
|
import org.jclouds.location.Provider;
|
||||||
import org.jclouds.rest.ApiContext;
|
|
||||||
|
|
||||||
import com.google.common.reflect.TypeParameter;
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,15 +51,6 @@ public class ChefContextImpl extends BaseView implements ChefContext {
|
||||||
return chefService;
|
return chefService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <A extends ChefApi> A getApi(Class<A> apiClass) {
|
|
||||||
TypeToken<ApiContext<A>> contextToken = new TypeToken<ApiContext<A>>(delegate().getClass()) {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
}.where(new TypeParameter<A>() {
|
|
||||||
}, TypeToken.of(apiClass));
|
|
||||||
return unwrap(contextToken).getApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
delegate().close();
|
delegate().close();
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.internal;
|
|
||||||
|
|
||||||
import static com.google.common.base.Throwables.propagate;
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.jclouds.ContextBuilder;
|
|
||||||
import org.jclouds.chef.ChefApi;
|
|
||||||
import org.jclouds.chef.ChefApiMetadata;
|
|
||||||
import org.jclouds.chef.ChefContext;
|
|
||||||
import org.jclouds.chef.filters.SignedHeaderAuthTest;
|
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
|
||||||
import org.jclouds.rest.internal.BaseRestApiTest.MockModule;
|
|
||||||
import org.testng.annotations.AfterClass;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the access to the underlying API from the context.
|
|
||||||
*
|
|
||||||
* @author Ignasi Barrera
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "ChefContextTest")
|
|
||||||
public class ChefContextTest {
|
|
||||||
|
|
||||||
private ChefContext context;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public void setup() {
|
|
||||||
context = ContextBuilder.newBuilder(new ChefApiMetadata())
|
|
||||||
.credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY)
|
|
||||||
.modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())) //
|
|
||||||
.buildView(ChefContext.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCanAccessChefApi() {
|
|
||||||
ChefApi api = context.getApi(ChefApi.class);
|
|
||||||
assertNotNull(api);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public void tearDown() {
|
|
||||||
try {
|
|
||||||
context.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue