updated archetype to use new async model

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2297 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-17 06:33:59 +00:00
parent 09adeebe3d
commit f2410e5889
9 changed files with 102 additions and 43 deletions

View File

@ -0,0 +1,59 @@
#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};
import java.util.SortedSet;
import java.util.concurrent.Future;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import ${package}.domain.Status;
import ${package}.functions.ParseStatusesFromJsonResponse;
/**
* Provides asynchronous access to ${clientName} via their REST API.
* <p/>
*
* @see ${clientName}Client
* @see <a href="TODO: insert URL of client documentation" />
* @author ${author}
*/
@Endpoint(${clientName}.class)
@RequestFilters(BasicAuthentication.class)
public interface ${clientName}AsyncClient {
@GET
@ResponseParser(ParseStatusesFromJsonResponse.class)
@Path("/statuses/mentions.json")
Future<SortedSet<Status>> getMyMentions();
}

View File

@ -27,32 +27,22 @@
package ${package};
import java.util.SortedSet;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.concurrent.Timeout;
import ${package}.domain.Status;
import ${package}.functions.ParseStatusesFromJsonResponse;
/**
* Provides access to ${clientName} via their REST API.
* Provides synchronous access to ${clientName}.
* <p/>
*
* @see <a href="*/<-- (remove '*/') TODO: insert URL of client documentation" />
* @see ${clientName}AsyncClient
* @see <a href="TODO: insert URL of client documentation" />
* @author ${author}
*/
@Endpoint(${clientName}.class)
@RequestFilters(BasicAuthentication.class)
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)
public interface ${clientName}Client {
@GET
@ResponseParser(ParseStatusesFromJsonResponse.class)
@Path("/statuses/mentions.json")
Future<SortedSet<Status>> getMyMentions();
SortedSet<Status> getMyMentions();
}

View File

@ -44,10 +44,11 @@ import com.google.inject.TypeLiteral;
*
* @author ${author}
*/
public class ${clientName}ContextBuilder extends RestContextBuilder<${clientName}Client> {
public class ${clientName}ContextBuilder extends RestContextBuilder<${clientName}AsyncClient, ${clientName}Client> {
public ${clientName}ContextBuilder(Properties props) {
super(new TypeLiteral<${clientName}Client>() {
super(new TypeLiteral<${clientName}AsyncClient>() {
}, new TypeLiteral<${clientName}Client>() {
}, props);
checkNotNull(properties.getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_USER));
checkNotNull(properties.getProperty(${clientName}Constants.PROPERTY_${ucaseClientName}_PASSWORD));

View File

@ -47,16 +47,17 @@ import com.google.inject.Module;
* @author ${author}
* @see RestContext
* @see ${clientName}Client
* @see ${clientName}AsyncClient
*/
public class ${clientName}ContextFactory {
public static RestContext<${clientName}Client> createContext(String user, String password,
public static RestContext<${clientName}AsyncClient, ${clientName}Client> createContext(String user, String password,
Module... modules) {
return new ${clientName}ContextBuilder(new ${clientName}PropertiesBuilder(user, password).build())
.withModules(modules).buildContext();
}
public static RestContext<${clientName}Client> createContext(Properties properties, Module... modules) {
public static RestContext<${clientName}AsyncClient, ${clientName}Client> createContext(Properties properties, Module... modules) {
return new ${clientName}ContextBuilder(new ${clientName}PropertiesBuilder(properties).build())
.withModules(modules).buildContext();
}

View File

@ -35,6 +35,7 @@ import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import ${package}.${clientName};
import ${package}.${clientName}AsyncClient;
import ${package}.${clientName}Client;
import ${package}.reference.${clientName}Constants;
@ -54,9 +55,9 @@ public class ${clientName}ContextModule extends AbstractModule {
@Provides
@Singleton
RestContext<${clientName}Client> provideContext(Closer closer, ${clientName}Client defaultApi,
@${clientName} URI endPoint, @Named(${clientName}Constants.PROPERTY_${ucaseClientName}_USER) String account) {
return new RestContextImpl<${clientName}Client>(closer, defaultApi, endPoint, account);
RestContext<${clientName}AsyncClient, ${clientName}Client> provideContext(Closer closer, ${clientName}AsyncClient asyncApi,
${clientName}Client syncApi, @${clientName} URI endPoint, @Named(${clientName}Constants.PROPERTY_${ucaseClientName}_USER) String account) {
return new RestContextImpl<${clientName}AsyncClient, ${clientName}Client>(closer, asyncApi, syncApi, endPoint, account);
}
}

View File

@ -30,12 +30,15 @@ import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import ${package}.${clientName};
import ${package}.${clientName}Client;
import ${package}.${clientName}AsyncClient;
import ${package}.reference.${clientName}Constants;
import com.google.inject.AbstractModule;
@ -67,8 +70,15 @@ public class ${clientName}RestClientModule extends AbstractModule {
@Provides
@Singleton
protected ${clientName}Client provideClient(RestClientFactory factory) {
return factory.create(${clientName}Client.class);
protected ${clientName}AsyncClient provideClient(RestClientFactory factory) {
return factory.create(${clientName}AsyncClient.class);
}
@Provides
@Singleton
public ${clientName}Client provideClient(${clientName}AsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(${clientName}Client.class, client);
}
@Provides

View File

@ -51,18 +51,18 @@ import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ${clientName}Client}
* Tests annotation parsing of {@code ${clientName}AsyncClient}
*
* @author ${author}
*/
@Test(groups = "unit", testName = "${lcaseClientName}.${clientName}ClientTest")
public class ${clientName}ClientTest extends RestClientTest<${clientName}Client> {
@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}Client.class.getMethod(""<-- (remove '"') TODO: insert test method name");
GeneratedHttpRequest<${clientName}Client> httpMethod = processor.createRequest(method);
Method method = ${clientName}AsyncClient.class.getMethod("TODO: insert test method name");
GeneratedHttpRequest<${clientName}AsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, ""<-- (remove '"') TODO: insert expected request");
assertRequestLineEquals(httpMethod, "TODO: insert expected request");
assertHeadersEqual(httpMethod, "");
assertEntityEquals(httpMethod, null);
@ -74,14 +74,14 @@ public class ${clientName}ClientTest extends RestClientTest<${clientName}Client>
}
@Override
protected void checkFilters(GeneratedHttpRequest<${clientName}Client> httpMethod) {
protected void checkFilters(GeneratedHttpRequest<${clientName}AsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<${clientName}Client>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<${clientName}Client>>() {
protected TypeLiteral<RestAnnotationProcessor<${clientName}AsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<${clientName}AsyncClient>>() {
};
}

View File

@ -30,9 +30,6 @@ package ${package};
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.SortedSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import ${package}.domain.Status;
@ -50,7 +47,7 @@ public class ${clientName}ClientLiveTest {
private ${clientName}Client connection;
@BeforeGroups(groups = { "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException {
public void setupClient() {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
@ -59,8 +56,8 @@ public class ${clientName}ClientLiveTest {
}
@Test
public void testGetMyMentions() throws Exception {
SortedSet<Status> response = connection.getMyMentions().get(1, TimeUnit.SECONDS);
public void testGetMyMentions() {
SortedSet<Status> response = connection.getMyMentions();
assert (response.size() > 0);
}

View File

@ -65,7 +65,7 @@ public class ${clientName}ContextBuilderTest {
}
public void testBuildContext() {
RestContext<${clientName}Client> context = newBuilder().buildContext();
RestContext<${clientName}AsyncClient, ${clientName}Client> context = newBuilder().buildContext();
assertEquals(context.getClass(), RestContextImpl.class);
assertEquals(context.getAccount(), "user");
assertEquals(context.getEndPoint(), URI.create("${clientEndpoint}"));
@ -73,7 +73,7 @@ public class ${clientName}ContextBuilderTest {
public void testBuildInjector() {
Injector i = newBuilder().buildInjector();
assert i.getInstance(Key.get(new TypeLiteral<RestContext<${clientName}Client>>() {
assert i.getInstance(Key.get(new TypeLiteral<RestContext<${clientName}AsyncClient, ${clientName}Client>>() {
})) != null; // TODO: test all things taken from context
assert i.getInstance(BasicAuthentication.class) != null;
}