Issue 112: formatting and pulled shareable code into core

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2241 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-09 17:44:00 +00:00
parent 68edff3895
commit 7602f1b7b8
28 changed files with 78 additions and 74 deletions

View File

@ -21,16 +21,16 @@
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
package org.jclouds.rest.domain;
import java.net.URI;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.jclouds.rest.domain.internal.LinkImpl;
import com.google.inject.ImplementedBy;
/**
* Location of a vCloud resource
* Location of a Rest resource
*
* @author Adrian Cole
*

View File

@ -21,14 +21,14 @@
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
package org.jclouds.rest.domain.internal;
import java.net.URI;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.rest.domain.Link;
/**
* Location of a vCloud resource
* Location of a Rest resource
*
* @author Adrian Cole
*

View File

@ -21,13 +21,13 @@
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.util;
package org.jclouds.rest.util;
import java.net.URI;
import java.util.Map;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.xml.sax.Attributes;
/**

View File

@ -4,7 +4,7 @@
$Revision$
$Date$
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
====================================================================
Licensed to the Apache Software Foundation (ASF) under one
@ -34,7 +34,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-vcloud-core</artifactId>
<artifactId>jclouds-vcloud</artifactId>
<name>jclouds vcloud Components Core</name>
<packaging>jar</packaging>
<description>jclouds Core components to access vcloud</description>

View File

@ -51,7 +51,6 @@ public interface VCloudClient {
@XMLResponseParser(CatalogHandler.class)
Future<Catalog> getCatalog();
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@Consumes(VDC_XML)

View File

@ -29,18 +29,18 @@ import java.util.concurrent.ExecutorService;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.vcloud.config.BaseVCloudContextModule;
import org.jclouds.vcloud.config.BaseVCloudRestClientModule;
import org.jclouds.vcloud.config.VCloudContextModule;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Creates {@link VCloudContext} or {@link Injector} instances based on the most commonly requested
* arguments.
* Creates {@link RestContext} for {@link VCloudClient} instances based on the most commonly
* requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
@ -49,11 +49,12 @@ import com.google.inject.TypeLiteral;
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see CloudFilesContext
* @see RestContext
* @see VCloudClient
*/
public class BaseVCloudContextBuilder extends RestContextBuilder<VCloudClient> {
public class VCloudContextBuilder extends RestContextBuilder<VCloudClient> {
public BaseVCloudContextBuilder(Properties props) {
public VCloudContextBuilder(Properties props) {
super(new TypeLiteral<VCloudClient>() {
}, props);
}
@ -61,22 +62,22 @@ public class BaseVCloudContextBuilder extends RestContextBuilder<VCloudClient> {
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new VCloudDiscoveryRestClientModule());
modules.add(new BaseVCloudRestClientModule());
modules.add(new VCloudRestClientModule());
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new BaseVCloudContextModule());
modules.add(new VCloudContextModule());
}
@Override
public BaseVCloudContextBuilder withExecutorService(ExecutorService service) {
return (BaseVCloudContextBuilder) super.withExecutorService(service);
public VCloudContextBuilder withExecutorService(ExecutorService service) {
return (VCloudContextBuilder) super.withExecutorService(service);
}
@Override
public BaseVCloudContextBuilder withModules(Module... modules) {
return (BaseVCloudContextBuilder) super.withModules(modules);
public VCloudContextBuilder withModules(Module... modules) {
return (VCloudContextBuilder) super.withModules(modules);
}
}

View File

@ -34,7 +34,7 @@ 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.vcloud.domain.Link;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;

View File

@ -41,7 +41,7 @@ import com.google.inject.Provides;
/**
* @author Adrian Cole
*/
public class BaseVCloudContextModule extends AbstractModule {
public class VCloudContextModule extends AbstractModule {
@Override
protected void configure() {
}

View File

@ -45,7 +45,7 @@ import com.google.inject.Provides;
*/
@RequiresHttp
@ConfiguresRestClient
public class BaseVCloudRestClientModule extends AbstractModule {
public class VCloudRestClientModule extends AbstractModule {
@Override
protected void configure() {

View File

@ -25,6 +25,7 @@ package org.jclouds.vcloud.domain;
import java.util.Map;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import com.google.inject.ImplementedBy;

View File

@ -25,6 +25,7 @@ package org.jclouds.vcloud.domain;
import java.util.Map;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;

View File

@ -29,8 +29,9 @@ import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Link;
/**
* Locations of resources in vCloud

View File

@ -26,7 +26,8 @@ package org.jclouds.vcloud.domain.internal;
import java.net.URI;
import java.util.Map;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.TasksList;

View File

@ -38,9 +38,9 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.VCloudLogin.VCloudSession;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.xml.OrgListHandler;

View File

@ -23,16 +23,16 @@
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.util.Utils.putLink;
import static org.jclouds.rest.util.Utils.putLink;
import java.net.URI;
import java.util.Map;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

View File

@ -23,20 +23,20 @@
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.rest.util.Utils.newLink;
import static org.jclouds.rest.util.Utils.putLink;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import static org.jclouds.vcloud.util.Utils.newLink;
import static org.jclouds.vcloud.util.Utils.putLink;
import java.net.URI;
import java.util.Map;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

View File

@ -23,13 +23,13 @@
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.rest.util.Utils.putLink;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.util.Utils.putLink;
import java.util.Map;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.rest.domain.Link;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

View File

@ -69,7 +69,7 @@ System.err.println(response);
"jclouds.test.endpoint");
account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
connection = new BaseVCloudContextBuilder(new VCloudPropertiesBuilder(URI.create(endpoint),
connection = new VCloudContextBuilder(new VCloudPropertiesBuilder(URI.create(endpoint),
account, key).build()).withModules(new Log4JLoggingModule()).buildContext().getApi();
}

View File

@ -38,8 +38,8 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.config.BaseVCloudContextModule;
import org.jclouds.vcloud.config.BaseVCloudRestClientModule;
import org.jclouds.vcloud.config.VCloudContextModule;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.endpoints.Org;
import org.testng.annotations.Test;
@ -50,12 +50,12 @@ import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of modules configured in BaseVCloudContextBuilder
* Tests behavior of modules configured in VCloudContextBuilder
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.BaseVCloudContextBuilderTest")
public class BaseVCloudContextBuilderTest {
@Test(groups = "unit", testName = "vcloud.VCloudContextBuilderTest")
public class VCloudContextBuilderTest {
VCloudClient connection = createMock(VCloudClient.class);
@ConfiguresRestClient
@ -86,10 +86,9 @@ public class BaseVCloudContextBuilderTest {
assertEquals(context.getEndPoint(), URI.create("http://org"));
}
public BaseVCloudContextBuilder builder() {
return new BaseVCloudContextBuilder(new VCloudPropertiesBuilder(URI
.create("http://localhost"), "id", "secret").build())
.withModules(new StubClientModule());
public VCloudContextBuilder builder() {
return new VCloudContextBuilder(new VCloudPropertiesBuilder(URI.create("http://localhost"),
"id", "secret").build()).withModules(new StubClientModule());
}
public void testBuildInjector() {
@ -102,18 +101,18 @@ public class BaseVCloudContextBuilderTest {
protected void testAddContextModule() {
List<Module> modules = new ArrayList<Module>();
BaseVCloudContextBuilder builder = builder();
VCloudContextBuilder builder = builder();
builder.addContextModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), BaseVCloudContextModule.class);
assertEquals(modules.get(0).getClass(), VCloudContextModule.class);
}
protected void addClientModule() {
List<Module> modules = new ArrayList<Module>();
BaseVCloudContextBuilder builder = builder();
VCloudContextBuilder builder = builder();
builder.addClientModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), BaseVCloudRestClientModule.class);
assertEquals(modules.get(0).getClass(), VCloudRestClientModule.class);
}
}

View File

@ -68,6 +68,7 @@ public class VCloudDiscoveryLiveTest {
"jclouds.test.endpoint");
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
private final class VCloudDiscoveryContextModule extends AbstractModule {
@SuppressWarnings( { "unused" })

View File

@ -69,8 +69,8 @@ public class VCloudLoginLiveTest {
@SuppressWarnings( { "unused" })
@Provides
@Singleton
RestContext<VCloudLogin> provideContext(Closer closer, VCloudLogin api,
@VCloud URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
RestContext<VCloudLogin> provideContext(Closer closer, VCloudLogin api, @VCloud URI endPoint,
@Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
return new RestContextImpl<VCloudLogin>(closer, api, endPoint, account);
}
@ -110,8 +110,8 @@ public class VCloudLoginLiveTest {
@Override
protected void addClientModule(List<Module> modules) {
properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(
endpoint, "endpoint").toString());
properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint,
"endpoint").toString());
properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user"));
properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key"));
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4");

View File

@ -38,10 +38,10 @@ 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.rest.domain.Link;
import org.jclouds.util.Jsr330;
import org.jclouds.vcloud.VCloudLogin;
import org.jclouds.vcloud.VCloudLogin.VCloudSession;
import org.jclouds.vcloud.domain.Link;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;

View File

@ -31,9 +31,9 @@ import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudLogin.VCloudSession;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

View File

@ -30,8 +30,8 @@ import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

View File

@ -32,9 +32,9 @@ import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -63,8 +63,8 @@ public class OrgHandlerTest extends BaseHandlerTest {
assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
assertEquals(result.getType(), ORG_XML);
assertEquals(result.getCatalog(), new LinkImpl("Miami Environment 1 Catalog", CATALOG_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")));
assertEquals(result.getCatalog(), new LinkImpl("Miami Environment 1 Catalog", CATALOG_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")));
assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new LinkImpl(
"Miami Environment 1", VCloudMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))));

View File

@ -30,9 +30,9 @@ import java.net.URI;
import java.util.Map;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Link;
import org.jclouds.vcloud.domain.internal.LinkImpl;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;