Issue 1031:update maven archetype

This commit is contained in:
Adrian Cole 2012-07-25 00:33:18 -07:00
parent 8179713655
commit 17172a7d17
29 changed files with 1411 additions and 419 deletions

View File

@ -36,7 +36,7 @@
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.0-alpha-4</version>
<version>2.2</version>
<extensions>true</extensions>
</plugin>
<plugin>
@ -50,7 +50,7 @@
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.0-alpha-4</version>
<version>2.2</version>
</extension>
</extensions>
</build>

View File

@ -2,10 +2,10 @@
<archetype-descriptor name="jclouds-rest-client-archetype">
<requiredProperties>
<requiredProperty key="groupId">
<defaultValue>org.jclouds</defaultValue>
<defaultValue>org.jclouds.labs</defaultValue>
</requiredProperty>
<requiredProperty key="package" >
<defaultValue>${groupId}.${artifactId}</defaultValue>
<defaultValue>org.jclouds.${artifactId}</defaultValue>
</requiredProperty>
<requiredProperty key="author">
<defaultValue>Adrian Cole</defaultValue>
@ -23,6 +23,9 @@
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
@ -32,7 +35,8 @@
<fileSet encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.json</include>
<include>logback.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">

View File

@ -5,4 +5,4 @@ properties:
* test.${lcaseProviderName}.credential
Note that this module is intentionally incomplete. You should global replace and create your own client from this example. Make sure that you use tests propertly. For
example, the test ending in *AsyncClientTest will help ensure that your annotations parse in the way you expect.
example, tests ending in *ExpectTest will help ensure that your annotations parse in the way you expect.

View File

@ -4,119 +4,120 @@ $symbol_dollar = '$' )
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to jclouds, Inc. (jclouds) under one or more
contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. jclouds 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
Licensed to jclouds, Inc. (jclouds) under one or more
contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. jclouds 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
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.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<groupId>${groupId}</groupId>
<artifactId>jclouds-${artifactId}</artifactId>
<name>jclouds ${providerName} core</name>
<description>jclouds components to access ${providerName}</description>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<name>jclouds ${providerName} core</name>
<description>jclouds components to access ${providerName}</description>
<scm>
<connection>scm:git:git@github.com:jclouds/jclouds.git</connection>
<developerConnection>scm:git:git@github.com:jclouds/jclouds.git</developerConnection>
<url>http://github.com/jclouds/jclouds/tree/master/${lcaseProviderName}</url>
</scm>
<scm>
<connection>scm:git:git@github.com:jclouds/jclouds.git</connection>
<developerConnection>scm:git:git@github.com:jclouds/jclouds.git</developerConnection>
<url>http://github.com/jclouds/jclouds/tree/master/labs/${lcaseProviderName}</url>
</scm>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<test.${lcaseProviderName}.identity>${providerIdentity}</test.${lcaseProviderName}.identity>
<test.${lcaseProviderName}.credential>${providerCredential}</test.${lcaseProviderName}.credential>
<test.${lcaseProviderName}.api-version>${providerApiVersion}</test.${lcaseProviderName}.api-version>
<test.${lcaseProviderName}.build-version></test.${lcaseProviderName}.build-version>
<test.${lcaseProviderName}.endpoint>${providerEndpoint}</test.${lcaseProviderName}.endpoint>
</properties>
<dependencies>
<dependency>
<groupId>${symbol_dollar}{project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${symbol_dollar}{project.version}</version>
</dependency>
<dependency>
<groupId>${symbol_dollar}{project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${symbol_dollar}{project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${symbol_dollar}{project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test.${lcaseProviderName}.identity>\$\{test.${lcaseProviderName}.identity\}</test.${lcaseProviderName}.identity>
<test.${lcaseProviderName}.credential>\$\{test.${lcaseProviderName}.credential\}</test.${lcaseProviderName}.credential>
<test.${lcaseProviderName}.endpoint>\$\{test.${lcaseProviderName}.endpoint\}</test.${lcaseProviderName}.endpoint>
<test.${lcaseProviderName}.api-version>\$\{test.${lcaseProviderName}.api-version\}</test.${lcaseProviderName}.api-version>
<test.${lcaseProviderName}.build-version>\$\{test.${lcaseProviderName}.build-version\}</test.${lcaseProviderName}.build-version>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<jclouds.version>1.5.0-SNAPSHOT</jclouds.version>
<test.${lcaseProviderName}.identity>${providerIdentity}</test.${lcaseProviderName}.identity>
<test.${lcaseProviderName}.credential>${providerCredential}</test.${lcaseProviderName}.credential>
<test.${lcaseProviderName}.api-version>${providerApiVersion}</test.${lcaseProviderName}.api-version>
<test.${lcaseProviderName}.build-version></test.${lcaseProviderName}.build-version>
<test.${lcaseProviderName}.endpoint>${providerEndpoint}</test.${lcaseProviderName}.endpoint>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${symbol_dollar}{jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${symbol_dollar}{jclouds.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${symbol_dollar}{jclouds.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test.${lcaseProviderName}.identity>\$\{test.${lcaseProviderName}.identity\}</test.${lcaseProviderName}.identity>
<test.${lcaseProviderName}.credential>\$\{test.${lcaseProviderName}.credential\}</test.${lcaseProviderName}.credential>
<test.${lcaseProviderName}.endpoint>\$\{test.${lcaseProviderName}.endpoint\}</test.${lcaseProviderName}.endpoint>
<test.${lcaseProviderName}.api-version>\$\{test.${lcaseProviderName}.api-version\}</test.${lcaseProviderName}.api-version>
<test.${lcaseProviderName}.build-version>\$\{test.${lcaseProviderName}.build-version\}</test.${lcaseProviderName}.build-version>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,47 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import ${package}.features.KeyApi;
import org.jclouds.rest.annotations.Delegate;
/**
* Provides synchronous access to ${providerName}.
* <p/>
*
* @see ${providerName}AsyncApi
* @see <a href="TODO: docs!">api doc</a>
* @author ${author}
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface ${providerName}Api {
/**
* Provides synchronous access to Key features.
*/
@Delegate
KeyApi getKeyApi();
}

View File

@ -0,0 +1,98 @@
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import ${package}.config.${providerName}RestClientModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for ${providerName} ${providerApiVersion} API
*
* @author ${author}
*/
public class ${providerName}ApiMetadata extends BaseRestApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = 6725672099385580694L;
public static final TypeToken<RestContext<${providerName}Api, ${providerName}AsyncApi>> CONTEXT_TOKEN = new TypeToken<RestContext<${providerName}Api, ${providerName}AsyncApi>>() {
private static final long serialVersionUID = -5070937833892503232L;
};
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}
public ${providerName}ApiMetadata() {
this(new Builder());
}
protected ${providerName}ApiMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
// TODO: add any custom properties here
return properties;
}
public static class Builder extends BaseRestApiMetadata.Builder {
protected Builder() {
super(${providerName}Api.class, ${providerName}AsyncApi.class);
id("${lcaseProviderName}")
.name("${providerName} API")
.identityName("${providerIdentity}")
.credentialName("${providerCredential}")
.documentation(URI.create("TODO"))
.version("${providerApiVersion}")
.defaultEndpoint("${providerEndpoint}")
.defaultProperties(${providerName}ApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>> of(${providerName}RestClientModule.class));
}
@Override
public ${providerName}ApiMetadata build() {
return new ${providerName}ApiMetadata(this);
}
@Override
public Builder fromApiMetadata(ApiMetadata in) {
super.fromApiMetadata(in);
return this;
}
}
}

View File

@ -0,0 +1,43 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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 ${package}.features.KeyAsyncApi;
import org.jclouds.rest.annotations.Delegate;
/**
* Provides asynchronous access to ${providerName} via their REST API.
* <p/>
*
* @see ${providerName}Api
* @see <a href="TODO: docs!">api doc</a>
* @author ${author}
*/
public interface ${providerName}AsyncApi {
/**
* Provides asynchronous access to Key features.
*/
@Delegate
KeyAsyncApi getKeyApi();
}

View File

@ -0,0 +1,70 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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 java.util.Map;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import ${package}.${providerName}AsyncApi;
import ${package}.${providerName}Api;
import ${package}.features.KeyAsyncApi;
import ${package}.features.KeyApi;
import ${package}.handlers.${providerName}ErrorHandler;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap;
/**
* Configures the ${providerName} connection.
*
* @author ${author}
*/
@ConfiguresRestClient
public class ${providerName}RestClientModule extends RestClientModule<${providerName}Api, ${providerName}AsyncApi> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(KeyApi.class, KeyAsyncApi.class)
.build();
public ${providerName}RestClientModule() {
super(DELEGATE_MAP);
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(${providerName}ErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(${providerName}ErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(${providerName}ErrorHandler.class);
}
}

View File

@ -0,0 +1,151 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Date;
import com.google.common.base.Objects;
import com.google.common.collect.ComparisonChain;
/**
* Example
*
* @author ${author}
* @see <a href="TODO!">api doc</a>
*/
public class Key implements Comparable<Key> {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromKey(this);
}
public static class Builder {
private String name;
private String key;
private Date created = new Date();
/**
* @see Key#getName()
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see Key#get()
*/
public Builder key(String key) {
this.key = key;
return this;
}
/**
* @see Key#getCreated()
*/
public Builder created(Date created) {
this.created = created;
return this;
}
public Key build() {
return new Key(name, key, created);
}
public Builder fromKey(Key in) {
return name(in.getName()).key(in.get()).created(in.getCreated());
}
}
protected final String name;
protected final String key;
// don't include created in the http request
transient protected final Date created;
@ConstructorProperties({ "name", "key", "created" })
public Key(String name, String key, Date created) {
this.name = checkNotNull(name, "name");
this.key = checkNotNull(key, "key: OpenSSH formatted public key of key(%s)", name);
this.created = checkNotNull(created, "created date of key(%s)", name);
}
/**
* Name for this key
*/
public String getName() {
return name;
}
/**
* OpenSSH formatted public key
*/
public String get() {
return key;
}
/**
* Date the key was created
*/
public Date getCreated() {
return created;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Key) {
Key that = Key.class.cast(object);
return Objects.equal(name, that.name);
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hashCode(name);
}
@Override
public String toString() {
return Objects.toStringHelper("").omitNullValues()
.add("name", name)
.add("key", key)
.add("created", created).toString();
}
@Override
public int compareTo(Key that) {
return ComparisonChain.start()
.compare(this.name, that.name)
.compare(this.created, that.created).result();
}
}

View File

@ -0,0 +1,60 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.features;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import ${package}.domain.Key;
/**
* Description here
*
* @author ${author}
* @see KeyAsyncApi
* @see <a href="TODO!">api doc</a>
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface KeyApi {
/**
* Lists all public keys we have on record for the specified account.
*/
Set<Key> list();
/**
* Retrieves an individual key record.
*/
Key get(String name);
/**
* Uploads a new OpenSSH key to SmartDataCenter for use in SSH and HTTP
* signing.
*/
Key create(Key key);
/**
* Deletes an SSH key by name.
*/
void delete(String name);
}

View File

@ -0,0 +1,92 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.features;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.filters.BasicAuthentication;
import ${package}.domain.Key;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @author ${author}
* @see KeyApi
* @see <a href="TODO!">api doc</a>
*/
@SkipEncoding({ '/', '=' })
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
@RequestFilters(BasicAuthentication.class)
public interface KeyAsyncApi {
/**
* @see KeyApi#list
*/
@GET
@Path("/my/keys")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Key>> list();
/**
* @see KeyApi#get
*/
@GET
@Path("/my/keys/{name}")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Key> get(@PathParam("name") String name);
/**
* @see KeyApi#create
*/
@POST
@Path("/my/keys")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Key> create(@BinderParam(BindToJsonPayload.class) Key key);
/**
* @see KeyApi#delete
*/
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("/my/keys/{name}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> delete(@PathParam("name") String name);
}

View File

@ -0,0 +1,70 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.handlers;
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
import javax.inject.Singleton;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
/**
* This will parse and set an appropriate exception on the command object.
*
* @author ${author}
*
*/
@Singleton
public class ${providerName}ErrorHandler implements HttpErrorHandler {
public void handleError(HttpCommand command, HttpResponse response) {
// it is important to always read fully and close streams
byte[] data = closeClientButKeepContentStream(response);
String message = data != null ? new String(data) : null;
Exception exception = message != null ? new HttpResponseException(command, response, message)
: new HttpResponseException(command, response);
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
response.getStatusLine());
switch (response.getStatusCode()) {
case 400:
break;
case 401:
case 403:
exception = new AuthorizationException(message, exception);
break;
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
exception = new ResourceNotFoundException(message, exception);
}
break;
case 409:
exception = new IllegalStateException(message, exception);
break;
}
command.setException(exception);
}
}

View File

@ -0,0 +1,45 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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 org.jclouds.View;
import org.jclouds.apis.internal.BaseApiMetadataTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
/**
* Tests that ${providerName}ApiMetadata is properly registered in ServiceLoader
*
* <pre>
* META-INF/services/org.jclouds.apis.ApiMetadata
* </pre>
*
* @author ${author}
*/
@Test(groups = "unit", testName = "${providerName}ApiMetadataTest")
public class ${providerName}ApiMetadataTest extends BaseApiMetadataTest {
public ${providerName}ApiMetadataTest() {
super(new ${providerName}ApiMetadata(), ImmutableSet.<TypeToken<? extends View>> of());
}
}

View File

@ -1,133 +0,0 @@
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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 static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.rest.internal.BaseAsyncClientTest;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import ${package}.${providerName}AsyncClient;
import ${package}.${providerName}Client;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.inject.TypeLiteral;
/**
* Tests annotation parsing of {@code ${providerName}AsyncClient}
*
* @author ${author}
*/
@Test(groups = "unit", testName = "${lcaseProviderName}.${providerName}AsyncClientTest")
public class ${providerName}AsyncClientTest extends BaseAsyncClientTest<${providerName}AsyncClient> {
public void testList() throws SecurityException, NoSuchMethodException, IOException {
Method method = ${providerName}AsyncClient.class.getMethod("list");
GeneratedHttpRequest<${providerName}AsyncClient> request = processor.createRequest(method);
assertRequestLineEquals(request, "GET ${providerEndpoint}/items HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: text/plain\n");
assertPayloadEquals(request, null, null, false);
// now make sure request filters apply by replaying
Iterables.getOnlyElement(request.getFilters()).filter(request);
Iterables.getOnlyElement(request.getFilters()).filter(request);
assertRequestLineEquals(request, "GET ${providerEndpoint}/items HTTP/1.1");
// for example, using basic authentication, we should get "only one" header
assertNonPayloadHeadersEqual(request, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReturnStringIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGet() throws SecurityException, NoSuchMethodException, IOException {
Method method = ${providerName}AsyncClient.class.getMethod("get", long.class);
GeneratedHttpRequest<${providerName}AsyncClient> request = processor.createRequest(method, 1);
assertRequestLineEquals(request, "GET ${providerEndpoint}/items/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: text/plain\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReturnStringIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testDelete() throws SecurityException, NoSuchMethodException, IOException {
Method method = ${providerName}AsyncClient.class.getMethod("delete", long.class);
GeneratedHttpRequest<${providerName}AsyncClient> request = processor.createRequest(
method, 1);
assertRequestLineEquals(request, "DELETE ${providerEndpoint}/items/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(request);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<${providerName}AsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<${providerName}AsyncClient>>() {
};
}
@Override
public ContextSpec<${providerName}Client, ${providerName}AsyncClient> createContextSpec() {
return contextSpec("${lcaseProviderName}", "${providerEndpoint}", "${providerApiVersion}", "identity", "credential", ${providerName}Client.class,
${providerName}AsyncClient.class);
}
}

View File

@ -1,83 +0,0 @@
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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 static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContext;
import static org.testng.Assert.assertNotNull;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code ${providerName}Client}
*
* @author ${author}
*/
@Test(groups = "live", testName = "${lcaseProviderName}.${providerName}ClientLiveTest")
public class ${providerName}ClientLiveTest {
protected RestContext<${providerName}Client, ${providerName}AsyncClient> context;
protected String provider = "${lcaseProviderName}";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiVersion;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test.${lcaseProviderName}.identity"), "test.${lcaseProviderName}.identity");
credential = checkNotNull(System.getProperty("test.${lcaseProviderName}.credential"), "test.${lcaseProviderName}.credential");
endpoint = checkNotNull(System.getProperty("test.${lcaseProviderName}.endpoint"), "test.${lcaseProviderName}.endpoint");
apiVersion = checkNotNull(System.getProperty("test.${lcaseProviderName}.api-version"), "test.${lcaseProviderName}.api-version");
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
context = createContext(contextSpec(provider, endpoint, apiVersion, identity, credential,
${providerName}Client.class, ${providerName}AsyncClient.class), ImmutableSet.<Module> of(new Log4JLoggingModule()));
}
@Test
public void testList() throws Exception {
String response = context.getApi().list();
assertNotNull(response);
}
@Test
public void testGet() throws Exception {
String response = context.getApi().get(1l);
assertNotNull(response);
}
/*
* TODO: add tests for ${providerName} interface methods
*/
}

View File

@ -0,0 +1,86 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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
*
* Unles 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 expres or implied. See the License for the
* specific language governing permisions and limitations
* under the License.
*/
package ${package}.features;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import ${package}.${providerName}Api;
import ${package}.internal.Base${providerName}ApiExpectTest;
import ${package}.parse.ParseKeyListTest;
import ${package}.parse.ParseKeyTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author ${author}
*/
@Test(groups = "unit", testName = "KeyApiExpectTest")
public class KeyApiExpectTest extends Base${providerName}ApiExpectTest {
public HttpRequest list = HttpRequest.builder().method("GET")
.endpoint("${providerEndpoint}/my/keys")
.addHeader("X-Api-Version", "${providerApiVersion}")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
public HttpResponse listResponse = HttpResponse.builder().statusCode(200).payload(
payloadFromResource("/key_list.json")).build();
public void testListKeysWhenResponseIs2xx() {
${providerName}Api apiWhenKeysExists = requestSendsResponse(list, listResponse);
assertEquals(apiWhenKeysExists.getKeyApi().list(), new ParseKeyListTest().expected());
}
public void testListKeysWhenResponseIs404() {
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
${providerName}Api listWhenNone = requestSendsResponse(list, listResponse);
assertEquals(listWhenNone.getKeyApi().list(), ImmutableSet.of());
}
public void testCreateKeyWhenResponseIs202() throws Exception {
HttpRequest create = HttpRequest.builder()
.method("POST")
.endpoint("${providerEndpoint}/my/keys")
.addHeader("X-Api-Version", "${providerApiVersion}")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.payload(
payloadFromStringWithContentType(
"{\"name\":\"rsa\",\"key\":\"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0A5Pf5Cq...\"}",
"application/json")).build();
HttpResponse createResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted")
.payload(payloadFromResourceWithContentType("/key.json", "application/json; charset=UTF-8"))
.build();
${providerName}Api apiWithNewKey = requestSendsResponse(create, createResponse);
assertEquals(apiWithNewKey.getKeyApi().create(new ParseKeyTest().expected())
.toString(), new ParseKeyTest().expected().toString());
}
}

View File

@ -0,0 +1,90 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.features;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.crypto.SshKeys;
import ${package}.domain.Key;
import ${package}.features.KeyApi;
import ${package}.internal.Base${providerName}ApiLiveTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/**
* @author ${author}
*/
@Test(groups = "live", singleThreaded = true, testName = "KeyApiLiveTest")
public class KeyApiLiveTest extends Base${providerName}ApiLiveTest {
@Test
public void testListAndGetKeys() throws Exception {
KeyApi api = context.getApi().getKeyApi();
Set<Key> response = api.list();
assert null != response;
for (Key key : response) {
Key newDetails = api.get(key.getName());
assertEquals(newDetails.getName(), key.getName());
assertEquals(newDetails.get(), key.get());
assertEquals(newDetails.getCreated(), key.getCreated());
}
}
private String keyText;
private String fingerprint;
@BeforeTest
public void initKeys() {
keyText = SshKeys.generate().get("public");
fingerprint = SshKeys.fingerprintPublicKey(keyText);
}
public void testCreateKey() {
KeyApi api = context.getApi().getKeyApi();
Key newKey = api.create(Key.builder().name(fingerprint).key(keyText).build());
assertEquals(newKey.getName(), fingerprint);
assertEquals(newKey.get(), keyText);
newKey = api.get(fingerprint);
assertEquals(newKey.getName(), fingerprint);
assertEquals(newKey.get(), keyText);
}
@Test(dependsOnMethods = "testCreateKey", expectedExceptions = IllegalStateException.class)
public void testDuplicateKey() {
KeyApi api = context.getApi().getKeyApi();
api.create(Key.builder().name(fingerprint).key(keyText).build());
}
@Test(dependsOnMethods = "testDuplicateKey")
public void testDestroyKey() {
final KeyApi api = context.getApi().getKeyApi();
api.delete(fingerprint);
// not that eventhough the key is destroyed it is visible via GET for at
// least 45 seconds. This may be a cache issue on the server
}
}

View File

@ -0,0 +1,100 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.handlers;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reportMatcher;
import static org.easymock.EasyMock.verify;
import java.net.URI;
import org.easymock.IArgumentMatcher;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
/**
*
* @author ${author}
*/
@Test(groups = "unit", testName = "${providerName}ErrorHandlerTest")
public class ${providerName}ErrorHandlerTest {
@Test
public void test409MakesIllegalStateException() {
assertCodeMakes(
"POST",
URI.create("${providerEndpoint}"),
409,
"HTTP/1.1 409 Conflict",
"\"{\"code\":\"InvalidState\",\"message\":\"An incompatible transition has already been queued for this resource\"}\"",
IllegalStateException.class);
}
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
Class<? extends Exception> expected) {
assertCodeMakes(method, uri, statusCode, message, "application/json", content, expected);
}
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
String content, Class<? extends Exception> expected) {
${providerName}ErrorHandler function = new ${providerName}ErrorHandler();
HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
response.getPayload().getContentMetadata().setContentType(contentType);
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
command.setException(classEq(expected));
replay(command);
function.handleError(command, response);
verify(command);
}
public static Exception classEq(final Class<? extends Exception> in) {
reportMatcher(new IArgumentMatcher() {
@Override
public void appendTo(StringBuffer buffer) {
buffer.append("classEq(");
buffer.append(in);
buffer.append(")");
}
@Override
public boolean matches(Object arg) {
return arg.getClass() == in;
}
});
return null;
}
}

View File

@ -0,0 +1,31 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.internal;
import ${package}.${providerName}Api;
/**
* @author ${author}
*/
public class Base${providerName}ApiExpectTest extends Base${providerName}ExpectTest<${providerName}Api> {
}

View File

@ -0,0 +1,49 @@
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.internal;
import org.jclouds.apis.BaseContextLiveTest;
import ${package}.${providerName}ApiMetadata;
import ${package}.${providerName}AsyncApi;
import ${package}.${providerName}Api;
import org.jclouds.rest.RestContext;
import com.google.common.reflect.TypeToken;
/**
* @author ${author}
*/
public class Base${providerName}ApiLiveTest extends BaseContextLiveTest<RestContext<${providerName}Api, ${providerName}AsyncApi>> {
public Base${providerName}ApiLiveTest() {
provider = "${lcaseProviderName}";
}
@Override
protected TypeToken<RestContext<${providerName}Api, ${providerName}AsyncApi>> contextType() {
return ${providerName}ApiMetadata.CONTEXT_TOKEN;
}
}

View File

@ -0,0 +1,40 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.internal;
import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import ${package}.${providerName}AsyncApi;
import com.google.common.base.Function;
import com.google.inject.Module;
/**
* @author ${author}
*/
public class Base${providerName}AsyncApiExpectTest extends Base${providerName}ExpectTest<${providerName}AsyncApi> {
public ${providerName}AsyncApi createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return createInjector(fn, module, props).getInstance(${providerName}AsyncApi.class);
}
}

View File

@ -0,0 +1,35 @@
#set( $lcaseProviderName = ${providerName.toLowerCase()} )
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.internal;
import org.jclouds.rest.internal.BaseRestApiExpectTest;
/**
* @author ${author}
*/
public class Base${providerName}ExpectTest<T> extends BaseRestApiExpectTest<T> {
public Base${providerName}ExpectTest() {
provider = "${lcaseProviderName}";
}
}

View File

@ -0,0 +1,70 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.parse;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import ${package}.domain.Key;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author ${author}
*/
@Test(groups = "unit", testName = "ParseKeyListTest")
public class ParseKeyListTest extends BaseSetParserTest<Key> {
@Override
public String resource() {
return "/key_list.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Set<Key> expected() {
return ImmutableSet.of(
Key.builder()
.name("rsa")
.key("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0A5Pf5Cq...")
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-04-13T22:14:46+00:00"))
.build()
);
}
protected Injector injector() {
return Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
}
}

View File

@ -0,0 +1,65 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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}.parse;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import ${package}.domain.Key;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author ${author}
*/
@Test(groups = "unit", testName = "ParseKeyTest")
public class ParseKeyTest extends BaseItemParserTest<Key> {
@Override
public String resource() {
return "/key.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Key expected() {
return Key.builder()
.name("rsa")
.key("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0A5Pf5Cq...")
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-04-13T22:14:46+00:00"))
.build();
}
protected Injector injector() {
return Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
}
}

View File

@ -0,0 +1,5 @@
{
"name": "rsa",
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0A5Pf5Cq...",
"created": "2011-04-13T22:14:46+00:00"
}

View File

@ -0,0 +1,7 @@
[
{
"name": "rsa",
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0A5Pf5Cq...",
"created": "2011-04-13T22:14:46+00:00"
}
]

View File

@ -1,90 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache Log4j
website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message${symbol_escape}n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message${symbol_escape}n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
%m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message${symbol_escape}n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message${symbol_escape}n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
%m%n"/>
-->
</layout>
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category><!--
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
--><!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<configuration scan="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="WIREFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-wire.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<root>
<level value="warn" />
</root>
<logger name="org.jclouds">
<level value="DEBUG" />
<appender-ref ref="FILE" />
</logger>
<logger name="jclouds.wire">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
<logger name="jclouds.headers">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
</configuration>