mirror of https://github.com/apache/jclouds.git
fixed basic archetype
This commit is contained in:
parent
9fbc3068f2
commit
f05e68869d
|
@ -23,24 +23,32 @@ 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}
|
||||
*/
|
||||
|
@ -48,34 +56,17 @@ import com.google.inject.Injector;
|
|||
public class ${providerName}ContextModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
return Guice.createInjector(new ${providerName}RestClientModule(), new ${providerName}ContextModule() {
|
||||
return Guice.createInjector(new ${providerName}RestClientModule(), new ${providerName}ContextModule("${artifactId}") {
|
||||
@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");
|
||||
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(),
|
||||
|
@ -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);
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
<requiredProperty key="groupId">
|
||||
<defaultValue>org.jclouds</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="package" >
|
||||
<defaultValue>${groupId}.${artifactId}</defaultValue>
|
||||
</requiredProperty>
|
||||
<requiredProperty key="author">
|
||||
<defaultValue>Adrian Cole</defaultValue>
|
||||
</requiredProperty>
|
||||
|
|
|
@ -1,27 +1,9 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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.
|
||||
|
@ -62,4 +52,20 @@ public interface ${clientName}AsyncClient {
|
|||
/*
|
||||
* TODO: define interface methods for ${clientName}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see ${clientName}AsyncClient#list()
|
||||
*/
|
||||
@GET
|
||||
@Path("/item")
|
||||
ListenableFuture<String> list();
|
||||
|
||||
/**
|
||||
* @see ${clientName}AsyncClient#get(String)
|
||||
*/
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/item/{itemId}")
|
||||
ListenableFuture<String> get(@PathParam("itemId") long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,13 @@ 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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Module> modules) {
|
||||
modules.add(new ${clientName}ContextModule());
|
||||
protected void addContextModule(String providerName, List<Module> modules) {
|
||||
modules.add(new ${clientName}ContextModule(providerName));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,28 +1,10 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,28 +1,10 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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() {
|
||||
|
|
|
@ -1,28 +1,10 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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
|
||||
*/
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue