From 543dc025c443a0b06fb0e77d8efe437736c2b1c1 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Mon, 27 May 2013 09:48:26 +0200 Subject: [PATCH] JCLOUDS-82: Use unwrapApi from View and remove custom method in ChefContext --- .../java/org/jclouds/chef/ChefContext.java | 5 -- .../jclouds/chef/domain/CookbookVersion.java | 2 - .../org/jclouds/chef/domain/Environment.java | 2 - .../java/org/jclouds/chef/domain/Sandbox.java | 2 - .../chef/internal/ChefContextImpl.java | 12 ---- .../chef/internal/ChefContextTest.java | 69 ------------------- 6 files changed, 92 deletions(-) delete mode 100644 apis/chef/src/test/java/org/jclouds/chef/internal/ChefContextTest.java diff --git a/apis/chef/src/main/java/org/jclouds/chef/ChefContext.java b/apis/chef/src/main/java/org/jclouds/chef/ChefContext.java index f1ffb3b70c..a3d9d987b6 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/ChefContext.java +++ b/apis/chef/src/main/java/org/jclouds/chef/ChefContext.java @@ -36,9 +36,4 @@ public interface ChefContext extends View, Closeable { */ ChefService getChefService(); - /** - * Provides access to the underlying Chef api. - */ - A getApi(Class apiClass); - } 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 04ef11f40d..9251bd13fb 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 @@ -46,11 +46,9 @@ public class CookbookVersion { private Set rootFiles = Sets.newLinkedHashSet(); // internal - @SuppressWarnings("unused") @SerializedName("json_class") private String _jsonClass = "Chef::CookbookVersion"; @SerializedName("chef_type") - @SuppressWarnings("unused") private String _chefType = "cookbook_version"; public CookbookVersion(String cookbookName, String version) { diff --git a/apis/chef/src/main/java/org/jclouds/chef/domain/Environment.java b/apis/chef/src/main/java/org/jclouds/chef/domain/Environment.java index 7d3e24ab88..d96caa7863 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/domain/Environment.java +++ b/apis/chef/src/main/java/org/jclouds/chef/domain/Environment.java @@ -33,10 +33,8 @@ public class Environment { @SerializedName("cookbook_versions") private Map cookbookVersions = Maps.newLinkedHashMap(); // internal - @SuppressWarnings("unused") @SerializedName("json_class") private String _jsonClass = "Chef::Environment"; - @SuppressWarnings("unused") @SerializedName("chef_type") private String _chefType = "environment"; diff --git a/apis/chef/src/main/java/org/jclouds/chef/domain/Sandbox.java b/apis/chef/src/main/java/org/jclouds/chef/domain/Sandbox.java index 87c6aa4b22..2a2de287a3 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/domain/Sandbox.java +++ b/apis/chef/src/main/java/org/jclouds/chef/domain/Sandbox.java @@ -41,11 +41,9 @@ public class Sandbox { private String guid; // internal - @SuppressWarnings("unused") @SerializedName("json_class") private String _jsonClass = "Chef::Sandbox"; @SerializedName("chef_type") - @SuppressWarnings("unused") private String _chefType = "sandbox"; public Sandbox(String rev, boolean isCompleted, Date createTime, Iterable checksums, String name, String guid) { diff --git a/apis/chef/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java b/apis/chef/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java index baa9786b2f..e641e70f73 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java +++ b/apis/chef/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java @@ -24,14 +24,11 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.Context; -import org.jclouds.chef.ChefApi; import org.jclouds.chef.ChefContext; import org.jclouds.chef.ChefService; import org.jclouds.internal.BaseView; import org.jclouds.location.Provider; -import org.jclouds.rest.ApiContext; -import com.google.common.reflect.TypeParameter; import com.google.common.reflect.TypeToken; /** @@ -54,15 +51,6 @@ public class ChefContextImpl extends BaseView implements ChefContext { return chefService; } - @Override - public A getApi(Class apiClass) { - TypeToken> contextToken = new TypeToken>(delegate().getClass()) { - private static final long serialVersionUID = 1L; - }.where(new TypeParameter() { - }, TypeToken.of(apiClass)); - return unwrap(contextToken).getApi(); - } - @Override public void close() throws IOException { delegate().close(); diff --git a/apis/chef/src/test/java/org/jclouds/chef/internal/ChefContextTest.java b/apis/chef/src/test/java/org/jclouds/chef/internal/ChefContextTest.java deleted file mode 100644 index f07cf0226f..0000000000 --- a/apis/chef/src/test/java/org/jclouds/chef/internal/ChefContextTest.java +++ /dev/null @@ -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. 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); - } - } -}