From f05e68869d23665ca9c5964403a51d3800a9dae4 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 1 Jun 2010 14:09:01 -0700 Subject: [PATCH] fixed basic archetype --- .../__providerName__ContextModuleTest.java | 71 ++++----- .../META-INF/maven/archetype-metadata.xml | 5 +- .../main/java/__clientName__AsyncClient.java | 50 ++++--- .../src/main/java/__clientName__Client.java | 13 +- .../java/__clientName__ContextBuilder.java | 8 +- .../java/__clientName__ContextFactory.java | 4 +- .../java/__clientName__PropertiesBuilder.java | 22 +-- .../config/__clientName__ContextModule.java | 10 +- .../java/__clientName__AsyncClientTest.java | 82 +++++++---- .../java/__clientName__ClientLiveTest.java | 33 ++--- .../__clientName__ContextModuleTest.java | 139 ------------------ 11 files changed, 151 insertions(+), 286 deletions(-) delete mode 100644 archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java diff --git a/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java b/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java index d1d5403b44..127e81a27b 100644 --- a/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java +++ b/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java @@ -23,64 +23,55 @@ package ${package}.config; import static org.testng.Assert.assertEquals; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; +import javax.ws.rs.core.UriBuilder; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +import org.jboss.resteasy.specimpl.UriBuilderImpl; +import org.jclouds.${providerName}PropertiesBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.http.functions.config.ParserModule.CDateAdapter; import org.jclouds.http.functions.config.ParserModule.DateAdapter; +import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; -import ${package}.reference.${providerName}Constants; import org.jclouds.util.Jsr330; -import org.jclouds.Constants; import org.testng.annotations.Test; import com.google.inject.Guice; import com.google.inject.Injector; + /** * @author ${author} */ @Test(groups = "unit", testName = "${lcaseProviderName}.${providerName}ContextModule") public class ${providerName}ContextModuleTest { - - Injector createInjector() { - return Guice.createInjector(new ${providerName}RestClientModule(), new ${providerName}ContextModule() { - @Override - protected void configure() { - bindConstant().annotatedWith(Jsr330.named(${providerName}Constants.PROPERTY_${ucaseProviderName}_USER)).to( - "user"); - bindConstant().annotatedWith(Jsr330.named(${providerName}Constants.PROPERTY_${ucaseProviderName}_KEY)) - .to("password"); - bindConstant().annotatedWith(Jsr330.named(${providerName}Constants.PROPERTY_${ucaseProviderName}_ENDPOINT)) - .to("http://localhost"); - bindConstant().annotatedWith(Jsr330.named(${providerName}Constants.PROPERTY_${ucaseProviderName}_SESSIONINTERVAL)) - .to("30"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)) - .to("0"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_CONNECTION_TIMEOUT)) - .to("30"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_SO_TIMEOUT)) - .to("10"); - bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - super.configure(); - } - }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), - new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); - } + + Injector createInjector() { + return Guice.createInjector(new ${providerName}RestClientModule(), new ${providerName}ContextModule("${artifactId}") { + @Override + protected void configure() { + Jsr330.bindProperties(this.binder(), new ${providerName}PropertiesBuilder("user", "pass") + .build()); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + bind(UriBuilder.class).to(UriBuilderImpl.class); + super.configure(); + } + }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), + new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); + } @Test void testServerErrorHandler() { @@ -89,12 +80,6 @@ public class ${providerName}ContextModuleTest { "TODO: insert expected error handler class"); } - @Test - void testDateTimeAdapter() { - assertEquals(this.createInjector().getInstance(DateAdapter.class).getClass(), - ${providerName}ContextModule.DateSecondsAdapter.class); - } - @Test void testClientErrorHandler() { DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); diff --git a/archetypes/json-client-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/archetypes/json-client-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index f4b96e1b14..baaea65b4f 100644 --- a/archetypes/json-client-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/archetypes/json-client-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -23,7 +23,10 @@ org.jclouds - + + + ${groupId}.${artifactId} + Adrian Cole diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__AsyncClient.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__AsyncClient.java index d79c648524..12afba9f76 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__AsyncClient.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__AsyncClient.java @@ -1,27 +1,9 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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. - * ==================================================================== - */ #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -44,9 +26,17 @@ */ package ${package}; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; /** * Provides asynchronous access to ${clientName} via their REST API. @@ -59,7 +49,23 @@ import org.jclouds.rest.annotations.RequestFilters; @Endpoint(${clientName}.class) @RequestFilters(BasicAuthentication.class) public interface ${clientName}AsyncClient { - /* - * TODO: define interface methods for ${clientName} - */ + /* + * TODO: define interface methods for ${clientName} + */ + + /** + * @see ${clientName}AsyncClient#list() + */ + @GET + @Path("/item") + ListenableFuture list(); + + /** + * @see ${clientName}AsyncClient#get(String) + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("/item/{itemId}") + ListenableFuture get(@PathParam("itemId") long id); + } diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__Client.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__Client.java index 9f24ccff70..c72ed15ab8 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__Client.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__Client.java @@ -58,7 +58,14 @@ import org.jclouds.concurrent.Timeout; */ @Timeout(duration = 4, timeUnit = TimeUnit.SECONDS) public interface ${clientName}Client { - /* - * TODO: define interface methods for ${clientName} - */ + /* + * Note all these delegate to methods in ${clientName}AsyncClient with a specified or inherited timeout. + * The singatures should match those of ${clientName}AsyncClient, except the returnvals should not be + * wrapped in a ListenableFuture + */ + + String list(); + + String get(long id); + } diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextBuilder.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextBuilder.java index 17e6ba08cd..344ba4e9a8 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextBuilder.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextBuilder.java @@ -64,8 +64,8 @@ import com.google.inject.TypeLiteral; */ public class ${clientName}ContextBuilder extends RestContextBuilder<${clientName}AsyncClient, ${clientName}Client> { - public ${clientName}ContextBuilder(Properties props) { - super(new TypeLiteral<${clientName}AsyncClient>() { + public ${clientName}ContextBuilder(String providerName, Properties props) { + super(providerName, new TypeLiteral<${clientName}AsyncClient>() { }, new TypeLiteral<${clientName}Client>() { }, props); checkNotNull(properties.getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_USER)); @@ -77,8 +77,8 @@ public class ${clientName}ContextBuilder extends RestContextBuilder<${clientName } @Override - protected void addContextModule(List modules) { - modules.add(new ${clientName}ContextModule()); + protected void addContextModule(String providerName, List modules) { + modules.add(new ${clientName}ContextModule(providerName)); } } diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextFactory.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextFactory.java index efdb9dc61d..9a3b79f030 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextFactory.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__ContextFactory.java @@ -71,12 +71,12 @@ public class ${clientName}ContextFactory { public static RestContext<${clientName}AsyncClient, ${clientName}Client> createContext(String user, String password, Module... modules) { - return new ${clientName}ContextBuilder(new ${clientName}PropertiesBuilder(user, password).build()) + return new ${clientName}ContextBuilder("${artifactId}", new ${clientName}PropertiesBuilder(user, password).build()) .withModules(modules).buildContext(); } public static RestContext<${clientName}AsyncClient, ${clientName}Client> createContext(Properties properties, Module... modules) { - return new ${clientName}ContextBuilder(new ${clientName}PropertiesBuilder(properties).build()) + return new ${clientName}ContextBuilder("${artifactId}", new ${clientName}PropertiesBuilder(properties).build()) .withModules(modules).buildContext(); } diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__PropertiesBuilder.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__PropertiesBuilder.java index 87d01e6268..52b06ff3ae 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__PropertiesBuilder.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/__clientName__PropertiesBuilder.java @@ -1,28 +1,10 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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. - * ==================================================================== - */ #set( $ucaseClientName = ${clientName.toUpperCase()} ) #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -53,6 +35,8 @@ import static ${package}.reference.${clientName}Constants.PROPERTY_${ucaseClient import java.net.URI; import java.util.Properties; +import org.jclouds.PropertiesBuilder; + /** * Builds properties used in ${clientName} Clients * diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/config/__clientName__ContextModule.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/config/__clientName__ContextModule.java index fccef43caf..c7796c5eda 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/config/__clientName__ContextModule.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/main/java/config/__clientName__ContextModule.java @@ -47,8 +47,6 @@ import java.net.URI; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.http.functions.config.ParserModule.CDateAdapter; -import org.jclouds.http.functions.config.ParserModule.DateAdapter; import org.jclouds.lifecycle.Closer; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; @@ -66,9 +64,15 @@ import com.google.inject.Provides; * @author ${author} */ public class ${clientName}ContextModule extends AbstractModule { + + public ${clientName}ContextModule(String providerName) { + // providerName ignored right now + } + @Override protected void configure() { - bind(DateAdapter.class).to(CDateAdapter.class); + // example of how to customize bindings + // bind(DateAdapter.class).to(CDateAdapter.class); } @Provides diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__AsyncClientTest.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__AsyncClientTest.java index ba27c1c540..aec26deda5 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__AsyncClientTest.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__AsyncClientTest.java @@ -1,28 +1,10 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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. - * ==================================================================== - */ #set( $lcaseClientName = ${clientName.toLowerCase()} ) #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -45,24 +27,30 @@ */ package ${package}; + import static org.testng.Assert.assertEquals; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.net.URI; +import java.util.Properties; import javax.inject.Singleton; +import org.jclouds.encryption.EncryptionService; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.encryption.EncryptionService; +import org.jclouds.util.Jsr330; import org.testng.annotations.Test; +import com.google.common.collect.Iterables; import com.google.inject.AbstractModule; import com.google.inject.Module; import com.google.inject.Provides; @@ -76,25 +64,55 @@ import com.google.inject.TypeLiteral; @Test(groups = "unit", testName = "${lcaseClientName}.${clientName}AsyncClientTest") public class ${clientName}AsyncClientTest extends RestClientTest<${clientName}AsyncClient> { - public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException { - Method method = ${clientName}AsyncClient.class.getMethod("TODO: insert test method name"); - GeneratedHttpRequest<${clientName}AsyncClient> httpMethod = processor.createRequest(method); - assertRequestLineEquals(httpMethod, "TODO: insert expected request"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + public void testList() throws SecurityException, NoSuchMethodException, IOException { + Method method = ${clientName}AsyncClient.class.getMethod("list"); + GeneratedHttpRequest<${clientName}AsyncClient> httpRequest = processor.createRequest(method); - assertResponseParserClassEquals(method, httpMethod, "TODO: insert expected response class"); + assertRequestLineEquals(httpRequest, "GET ${clientEndpoint}/item HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + + // now make sure request filters apply by replaying + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, "GET ${clientEndpoint}/item HTTP/1.1"); + // for example, using basic authentication, we should get "only one" header + assertHeadersEqual(httpRequest, "Authorization: Basic Zm9vOmJhcg==\n"); + assertPayloadEquals(httpRequest, null); + + // TODO: insert expected response class, which probably extends ParseJson + assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(httpRequest); + + } + + public void testGet() throws SecurityException, NoSuchMethodException, IOException { + Method method = ${clientName}AsyncClient.class.getMethod("get", long.class); + GeneratedHttpRequest<${clientName}AsyncClient> httpRequest = processor.createRequest(method, 1); + + assertRequestLineEquals(httpRequest, "GET ${clientEndpoint}/item/1 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + + // TODO: insert expected response class, which probably extends ParseJson + assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class); + assertSaxResponseParserClassEquals(method, null); + // note that get methods should convert 404's to null + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } @Override - protected void checkFilters(GeneratedHttpRequest<${clientName}AsyncClient> httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + protected void checkFilters(GeneratedHttpRequest<${clientName}AsyncClient> httpRequest) { + assertEquals(httpRequest.getFilters().size(), 1); + assertEquals(httpRequest.getFilters().get(0).getClass(), BasicAuthentication.class); } @Override @@ -108,6 +126,8 @@ public class ${clientName}AsyncClientTest extends RestClientTest<${clientName}As return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), new ${clientName}PropertiesBuilder( + new Properties()).build()); bind(URI.class).annotatedWith(${clientName}.class).toInstance( URI.create("${clientEndpoint}")); bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__ClientLiveTest.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__ClientLiveTest.java index afc158c710..c14555db74 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__ClientLiveTest.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/__clientName__ClientLiveTest.java @@ -1,28 +1,10 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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. - * ==================================================================== - */ #set( $lcaseClientName = ${clientName.toLowerCase()} ) #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -46,6 +28,7 @@ package ${package}; import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertNotNull; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.testng.annotations.BeforeGroups; @@ -70,6 +53,18 @@ public class ${clientName}ClientLiveTest { .getApi(); } + @Test + public void testList() throws Exception { + String response = connection.list(); + assertNotNull(response); + } + + @Test + public void testGet() throws Exception { + String response = connection.get(1l); + assertNotNull(response); + } + /* * TODO: add tests for ${clientName} interface methods */ diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java deleted file mode 100644 index 24012ae58e..0000000000 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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. - * ==================================================================== - */ -#set( $lcaseClientName = ${clientName.toLowerCase()} ) -#set( $ucaseClientName = ${clientName.toUpperCase()} ) -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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 ${package}.config; - -import static org.testng.Assert.assertEquals; -import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; - -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.http.HttpRetryHandler; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.http.functions.config.ParserModule; -import org.jclouds.http.functions.config.ParserModule.CDateAdapter; -import org.jclouds.http.functions.config.ParserModule.DateAdapter; -import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; -import org.jclouds.http.handlers.DelegatingErrorHandler; -import org.jclouds.http.handlers.DelegatingRetryHandler; -import org.jclouds.http.handlers.RedirectionRetryHandler; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import ${package}.reference.${clientName}Constants; -import org.jclouds.util.Jsr330; -import org.jclouds.Constants; -import org.testng.annotations.Test; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * @author ${author} - */ -@Test(groups = "unit", testName = "${lcaseClientName}.${clientName}ContextModule") -public class ${clientName}ContextModuleTest { - - Injector createInjector() { - return Guice.createInjector(new ${clientName}RestClientModule(), new ${clientName}ContextModule() { - @Override - protected void configure() { - bindConstant().annotatedWith(Jsr330.named(${clientName}Constants.PROPERTY_${ucaseClientName}_USER)).to( - "user"); - bindConstant().annotatedWith(Jsr330.named(${clientName}Constants.PROPERTY_${ucaseClientName}_PASSWORD)) - .to("password"); - bindConstant().annotatedWith(Jsr330.named(${clientName}Constants.PROPERTY_${ucaseClientName}_ENDPOINT)) - .to("http://localhost"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)) - .to("0"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); - bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - super.configure(); - } - }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), - new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); - } - - @Test - void testServerErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getServerErrorHandler().getClass(), - CloseContentAndSetExceptionErrorHandler.class); - } - - @Test - void testDateTimeAdapter() { - assertEquals(this.createInjector().getInstance(DateAdapter.class).getClass(), - CDateAdapter.class); - } - - @Test - void testClientErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getClientErrorHandler().getClass(), - CloseContentAndSetExceptionErrorHandler.class); - } - - @Test - void testClientRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY); - } - - @Test - void testRedirectionRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class); - } - -} \ No newline at end of file