mirror of https://github.com/apache/jclouds.git
Issue 95: multiple endpoints per interface
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1922 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
66c1b593b9
commit
58b075562f
|
@ -62,6 +62,7 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
||||||
import org.jclouds.http.functions.ParseETagHeader;
|
import org.jclouds.http.functions.ParseETagHeader;
|
||||||
import org.jclouds.http.functions.ReturnFalseOn404;
|
import org.jclouds.http.functions.ReturnFalseOn404;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.EntityParam;
|
import org.jclouds.rest.EntityParam;
|
||||||
import org.jclouds.rest.ExceptionParser;
|
import org.jclouds.rest.ExceptionParser;
|
||||||
import org.jclouds.rest.Headers;
|
import org.jclouds.rest.Headers;
|
||||||
|
@ -90,6 +91,7 @@ import com.google.inject.internal.Nullable;
|
||||||
@VirtualHost
|
@VirtualHost
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
@RequestFilters(RequestAuthorizeSignature.class)
|
@RequestFilters(RequestAuthorizeSignature.class)
|
||||||
|
@Endpoint(S3.class)
|
||||||
public interface S3BlobStore extends BlobStore<BucketMetadata, ObjectMetadata, S3Object> {
|
public interface S3BlobStore extends BlobStore<BucketMetadata, ObjectMetadata, S3Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,8 +75,8 @@ public class RestS3ConnectionModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected S3BlobStore provideS3Connection(@S3 URI uri, RestClientFactory factory) {
|
protected S3BlobStore provideS3Connection(RestClientFactory factory) {
|
||||||
return factory.create(uri, S3BlobStore.class);
|
return factory.create(S3BlobStore.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bindErrorHandlers() {
|
protected void bindErrorHandlers() {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.AzureBlob;
|
||||||
import org.jclouds.azure.storage.blob.domain.Blob;
|
import org.jclouds.azure.storage.blob.domain.Blob;
|
||||||
import org.jclouds.azure.storage.blob.domain.BlobMetadata;
|
import org.jclouds.azure.storage.blob.domain.BlobMetadata;
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
||||||
|
@ -57,6 +58,7 @@ import org.jclouds.http.functions.ParseETagHeader;
|
||||||
import org.jclouds.http.functions.ReturnFalseOn404;
|
import org.jclouds.http.functions.ReturnFalseOn404;
|
||||||
import org.jclouds.http.functions.ReturnTrueOn404;
|
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.EntityParam;
|
import org.jclouds.rest.EntityParam;
|
||||||
import org.jclouds.rest.ExceptionParser;
|
import org.jclouds.rest.ExceptionParser;
|
||||||
import org.jclouds.rest.Headers;
|
import org.jclouds.rest.Headers;
|
||||||
|
@ -79,6 +81,7 @@ import org.jclouds.rest.XMLResponseParser;
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
@RequestFilters(SharedKeyAuthentication.class)
|
@RequestFilters(SharedKeyAuthentication.class)
|
||||||
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17")
|
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17")
|
||||||
|
@Endpoint(AzureBlob.class)
|
||||||
public interface AzureBlobStore extends BlobStore<ContainerMetadata, BlobMetadata, Blob> {
|
public interface AzureBlobStore extends BlobStore<ContainerMetadata, BlobMetadata, Blob> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.net.URI;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlob;
|
import org.jclouds.azure.storage.AzureBlob;
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobStore;
|
import org.jclouds.azure.storage.blob.AzureBlobStore;
|
||||||
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
|
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
|
||||||
import org.jclouds.azure.storage.config.RestAzureStorageConnectionModule;
|
import org.jclouds.azure.storage.config.RestAzureStorageConnectionModule;
|
||||||
|
@ -62,8 +62,8 @@ public class RestAzureBlobStoreModule extends RestAzureStorageConnectionModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected AzureBlobStore provideAzureBlobStore(@AzureBlob URI uri, RestClientFactory factory) {
|
protected AzureBlobStore provideAzureBlobStore(RestClientFactory factory) {
|
||||||
return factory.create(uri, AzureBlobStore.class);
|
return factory.create(AzureBlobStore.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,7 +30,7 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlob;
|
import org.jclouds.azure.storage.AzureBlob;
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobContext;
|
import org.jclouds.azure.storage.blob.AzureBlobContext;
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobStore;
|
import org.jclouds.azure.storage.blob.AzureBlobStore;
|
||||||
import org.jclouds.azure.storage.blob.domain.Blob;
|
import org.jclouds.azure.storage.blob.domain.Blob;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Collections;
|
||||||
|
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.AzureBlob;
|
||||||
import org.jclouds.azure.storage.blob.functions.ReturnTrueIfContainerAlreadyExists;
|
import org.jclouds.azure.storage.blob.functions.ReturnTrueIfContainerAlreadyExists;
|
||||||
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
||||||
import org.jclouds.azure.storage.options.CreateOptions;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
|
@ -63,13 +64,12 @@ import com.google.inject.Guice;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "cloudservers.AzureBlobStoreTest")
|
@Test(groups = "unit", testName = "cloudservers.AzureBlobStoreTest")
|
||||||
public class AzureBlobStoreTest {
|
public class AzureBlobStoreTest {
|
||||||
|
|
||||||
JaxrsAnnotationProcessor.Factory factory;
|
JaxrsAnnotationProcessor.Factory factory;
|
||||||
|
|
||||||
public void testListContainers() throws SecurityException, NoSuchMethodException {
|
public void testListContainers() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("listContainers");
|
Method method = AzureBlobStore.class.getMethod("listContainers");
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list");
|
||||||
|
@ -84,9 +84,9 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testListContainersOptions() throws SecurityException, NoSuchMethodException {
|
public void testListContainersOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("listContainers", ListOptions.class);
|
Method method = AzureBlobStore.class.getMethod("listContainers", ListOptions.class);
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { maxResults(
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { maxResults(1).marker(
|
||||||
1).marker("marker").prefix("prefix") });
|
"marker").prefix("prefix") });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
||||||
assert httpMethod.getEndpoint().getQuery().contains("comp=list");
|
assert httpMethod.getEndpoint().getQuery().contains("comp=list");
|
||||||
|
@ -104,9 +104,8 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testCreateContainer() throws SecurityException, NoSuchMethodException {
|
public void testCreateContainer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("createContainer", String.class);
|
Method method = AzureBlobStore.class.getMethod("createContainer", String.class);
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container" });
|
||||||
new Object[] { "container" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
||||||
|
@ -123,9 +122,8 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
|
public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("deleteContainer", String.class);
|
Method method = AzureBlobStore.class.getMethod("deleteContainer", String.class);
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container" });
|
||||||
new Object[] { "container" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
||||||
|
@ -142,9 +140,9 @@ public class AzureBlobStoreTest {
|
||||||
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException {
|
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("createContainer", String.class,
|
Method method = AzureBlobStore.class.getMethod("createContainer", String.class,
|
||||||
CreateContainerOptions.class);
|
CreateContainerOptions.class);
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container",
|
||||||
"container", withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
||||||
|
@ -164,8 +162,8 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException {
|
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("createRootContainer");
|
Method method = AzureBlobStore.class.getMethod("createRootContainer");
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
||||||
|
@ -182,8 +180,8 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException {
|
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("deleteRootContainer");
|
Method method = AzureBlobStore.class.getMethod("deleteRootContainer");
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
||||||
|
@ -199,9 +197,9 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException {
|
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("createRootContainer", CreateOptions.class);
|
Method method = AzureBlobStore.class.getMethod("createRootContainer", CreateOptions.class);
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withPublicAcl()
|
||||||
new Object[] { withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
.withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
|
||||||
|
@ -221,9 +219,8 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testListBlobs() throws SecurityException, NoSuchMethodException {
|
public void testListBlobs() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("listBlobs", String.class);
|
Method method = AzureBlobStore.class.getMethod("listBlobs", String.class);
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container" });
|
||||||
new Object[] { "container" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list");
|
||||||
|
@ -238,8 +235,8 @@ public class AzureBlobStoreTest {
|
||||||
|
|
||||||
public void testListRootBlobs() throws SecurityException, NoSuchMethodException {
|
public void testListRootBlobs() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobStore.class.getMethod("listBlobs");
|
Method method = AzureBlobStore.class.getMethod("listBlobs");
|
||||||
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list");
|
||||||
|
@ -260,7 +257,8 @@ public class AzureBlobStoreTest {
|
||||||
new AbstractModule() {
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).toInstance(URI.create("http://blob.core.windows.net"));
|
bind(URI.class).annotatedWith(AzureBlob.class).toInstance(
|
||||||
|
URI.create("http://myaccount.blob.core.windows.net"));
|
||||||
bindConstant().annotatedWith(
|
bindConstant().annotatedWith(
|
||||||
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT))
|
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT))
|
||||||
.to("myaccount");
|
.to("myaccount");
|
||||||
|
@ -268,11 +266,9 @@ public class AzureBlobStoreTest {
|
||||||
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
|
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
|
||||||
HttpUtils.toBase64String("key".getBytes()));
|
HttpUtils.toBase64String("key".getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
||||||
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
||||||
JaxrsAnnotationProcessor.Factory.class);
|
JaxrsAnnotationProcessor.Factory.class);
|
||||||
processor = factory.create(AzureBlobStore.class);
|
processor = factory.create(AzureBlobStore.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ package org.jclouds.azure.storage.blob.config;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.AzureBlob;
|
import org.jclouds.azure.storage.AzureBlob;
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobStore;
|
import org.jclouds.azure.storage.blob.AzureBlobStore;
|
||||||
import org.jclouds.azure.storage.blob.internal.StubAzureBlobStore;
|
import org.jclouds.azure.storage.blob.internal.StubAzureBlobStore;
|
||||||
import org.jclouds.cloud.ConfiguresCloudConnection;
|
import org.jclouds.cloud.ConfiguresCloudConnection;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jclouds.azure.storage.blob;
|
package org.jclouds.azure.storage;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jclouds.azure.storage.queue;
|
package org.jclouds.azure.storage;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.jclouds.azure.storage;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Related to a resource of type Azure Table
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
|
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
|
@Qualifier
|
||||||
|
public @interface AzureTable {
|
||||||
|
|
||||||
|
}
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.filters;
|
package org.jclouds.azure.storage.filters;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -30,22 +31,24 @@ import java.net.URI;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.AzureBlob;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.QueryParams;
|
import org.jclouds.rest.QueryParams;
|
||||||
import org.jclouds.rest.RequestFilters;
|
import org.jclouds.rest.RequestFilters;
|
||||||
import org.jclouds.rest.RestClientFactory;
|
import org.jclouds.rest.RestClientFactory;
|
||||||
import org.jclouds.rest.config.JaxrsModule;
|
import org.jclouds.rest.config.JaxrsModule;
|
||||||
|
import org.jclouds.util.Jsr330;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import org.jclouds.util.Jsr330;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
||||||
|
@ -56,6 +59,7 @@ import org.jclouds.util.Jsr330;
|
||||||
public class SharedKeyAuthenticationLiveTest {
|
public class SharedKeyAuthenticationLiveTest {
|
||||||
|
|
||||||
@RequestFilters(SharedKeyAuthentication.class)
|
@RequestFilters(SharedKeyAuthentication.class)
|
||||||
|
@Endpoint(AzureBlob.class)
|
||||||
public interface IntegrationTestClient {
|
public interface IntegrationTestClient {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
@ -77,13 +81,15 @@ public class SharedKeyAuthenticationLiveTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
final String account = System.getProperty("jclouds.test.user");
|
final String account = checkNotNull(System.getProperty("jclouds.test.user"),
|
||||||
final String key = System.getProperty("jclouds.test.key");
|
"jclouds.test.user");
|
||||||
|
final String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||||
|
uri = "http://" + account + ".blob.core.windows.net";
|
||||||
injector = Guice.createInjector(new AbstractModule() {
|
injector = Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
bind(URI.class).annotatedWith(AzureBlob.class).toInstance(URI.create(uri));
|
||||||
bindConstant().annotatedWith(
|
bindConstant().annotatedWith(
|
||||||
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT)).to(account);
|
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT)).to(account);
|
||||||
bindConstant().annotatedWith(
|
bindConstant().annotatedWith(
|
||||||
|
@ -93,7 +99,6 @@ public class SharedKeyAuthenticationLiveTest {
|
||||||
}, new JaxrsModule(), new Log4JLoggingModule(), new ExecutorServiceModule(
|
}, new JaxrsModule(), new Log4JLoggingModule(), new ExecutorServiceModule(
|
||||||
new WithinThreadExecutorService()), new JavaUrlHttpCommandExecutorServiceModule());
|
new WithinThreadExecutorService()), new JavaUrlHttpCommandExecutorServiceModule());
|
||||||
RestClientFactory factory = injector.getInstance(RestClientFactory.class);
|
RestClientFactory factory = injector.getInstance(RestClientFactory.class);
|
||||||
uri = "http://" + account + ".blob.core.windows.net";
|
client = factory.create(IntegrationTestClient.class);
|
||||||
client = factory.create(URI.create(uri), IntegrationTestClient.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.AzureQueue;
|
||||||
import org.jclouds.azure.storage.domain.BoundedList;
|
import org.jclouds.azure.storage.domain.BoundedList;
|
||||||
import org.jclouds.azure.storage.filters.SharedKeyAuthentication;
|
import org.jclouds.azure.storage.filters.SharedKeyAuthentication;
|
||||||
import org.jclouds.azure.storage.options.CreateOptions;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
|
@ -39,6 +40,7 @@ import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
||||||
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
|
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.Headers;
|
import org.jclouds.rest.Headers;
|
||||||
import org.jclouds.rest.QueryParams;
|
import org.jclouds.rest.QueryParams;
|
||||||
import org.jclouds.rest.RequestFilters;
|
import org.jclouds.rest.RequestFilters;
|
||||||
|
@ -67,6 +69,7 @@ import org.jclouds.rest.XMLResponseParser;
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
@RequestFilters(SharedKeyAuthentication.class)
|
@RequestFilters(SharedKeyAuthentication.class)
|
||||||
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17")
|
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17")
|
||||||
|
@Endpoint(AzureQueue.class)
|
||||||
public interface AzureQueueConnection {
|
public interface AzureQueueConnection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,8 +28,8 @@ import java.net.URI;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.AzureQueue;
|
||||||
import org.jclouds.azure.storage.config.RestAzureStorageConnectionModule;
|
import org.jclouds.azure.storage.config.RestAzureStorageConnectionModule;
|
||||||
import org.jclouds.azure.storage.queue.AzureQueue;
|
|
||||||
import org.jclouds.azure.storage.queue.AzureQueueConnection;
|
import org.jclouds.azure.storage.queue.AzureQueueConnection;
|
||||||
import org.jclouds.azure.storage.queue.reference.AzureQueueConstants;
|
import org.jclouds.azure.storage.queue.reference.AzureQueueConstants;
|
||||||
import org.jclouds.cloud.ConfiguresCloudConnection;
|
import org.jclouds.cloud.ConfiguresCloudConnection;
|
||||||
|
@ -57,9 +57,8 @@ public class RestAzureQueueConnectionModule extends RestAzureStorageConnectionMo
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected AzureQueueConnection provideAzureStorageConnection(@AzureQueue URI uri,
|
protected AzureQueueConnection provideAzureStorageConnection(RestClientFactory factory) {
|
||||||
RestClientFactory factory) {
|
return factory.create(AzureQueueConnection.class);
|
||||||
return factory.create(uri, AzureQueueConnection.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,7 +30,7 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.queue.AzureQueue;
|
import org.jclouds.azure.storage.AzureQueue;
|
||||||
import org.jclouds.azure.storage.queue.AzureQueueConnection;
|
import org.jclouds.azure.storage.queue.AzureQueueConnection;
|
||||||
import org.jclouds.azure.storage.queue.AzureQueueContext;
|
import org.jclouds.azure.storage.queue.AzureQueueContext;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Collections;
|
||||||
|
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.AzureQueue;
|
||||||
import org.jclouds.azure.storage.options.CreateOptions;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
|
@ -60,9 +61,7 @@ import com.google.inject.Guice;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "cloudservers.AzureQueueConnectionTest")
|
@Test(groups = "unit", testName = "cloudservers.AzureQueueConnectionTest")
|
||||||
public class AzureQueueConnectionTest {
|
public class AzureQueueConnectionTest {
|
||||||
|
|
||||||
JaxrsAnnotationProcessor.Factory factory;
|
JaxrsAnnotationProcessor.Factory factory;
|
||||||
|
|
||||||
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}
|
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}
|
||||||
.getClass();
|
.getClass();
|
||||||
private static final Class<? extends CreateOptions[]> createOptionsVarargsClass = new CreateOptions[] {}
|
private static final Class<? extends CreateOptions[]> createOptionsVarargsClass = new CreateOptions[] {}
|
||||||
|
@ -70,8 +69,8 @@ public class AzureQueueConnectionTest {
|
||||||
|
|
||||||
public void testListQueues() throws SecurityException, NoSuchMethodException {
|
public void testListQueues() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureQueueConnection.class.getMethod("listQueues", listOptionsVarargsClass);
|
Method method = AzureQueueConnection.class.getMethod("listQueues", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list");
|
||||||
|
@ -86,9 +85,9 @@ public class AzureQueueConnectionTest {
|
||||||
|
|
||||||
public void testListQueuesOptions() throws SecurityException, NoSuchMethodException {
|
public void testListQueuesOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureQueueConnection.class.getMethod("listQueues", listOptionsVarargsClass);
|
Method method = AzureQueueConnection.class.getMethod("listQueues", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { maxResults(
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { maxResults(1).marker(
|
||||||
1).marker("marker").prefix("prefix") });
|
"marker").prefix("prefix") });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/");
|
||||||
assert httpMethod.getEndpoint().getQuery().contains("comp=list");
|
assert httpMethod.getEndpoint().getQuery().contains("comp=list");
|
||||||
|
@ -107,8 +106,8 @@ public class AzureQueueConnectionTest {
|
||||||
public void testCreateQueue() throws SecurityException, NoSuchMethodException {
|
public void testCreateQueue() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureQueueConnection.class.getMethod("createQueue", String.class,
|
Method method = AzureQueueConnection.class.getMethod("createQueue", String.class,
|
||||||
createOptionsVarargsClass);
|
createOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "queue" });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "queue" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=queue");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=queue");
|
||||||
|
@ -124,8 +123,8 @@ public class AzureQueueConnectionTest {
|
||||||
|
|
||||||
public void testDeleteQueue() throws SecurityException, NoSuchMethodException {
|
public void testDeleteQueue() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureQueueConnection.class.getMethod("deleteQueue", String.class);
|
Method method = AzureQueueConnection.class.getMethod("deleteQueue", String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "queue" });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "queue" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=queue");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=queue");
|
||||||
|
@ -141,8 +140,8 @@ public class AzureQueueConnectionTest {
|
||||||
public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException {
|
public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureQueueConnection.class.getMethod("createQueue", String.class,
|
Method method = AzureQueueConnection.class.getMethod("createQueue", String.class,
|
||||||
createOptionsVarargsClass);
|
createOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "queue",
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "queue",
|
||||||
withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
|
||||||
|
@ -166,7 +165,8 @@ public class AzureQueueConnectionTest {
|
||||||
new AbstractModule() {
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
|
bind(URI.class).annotatedWith(AzureQueue.class).toInstance(
|
||||||
|
URI.create("http://localhost:8080"));
|
||||||
bindConstant().annotatedWith(
|
bindConstant().annotatedWith(
|
||||||
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT))
|
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT))
|
||||||
.to("user");
|
.to("user");
|
||||||
|
@ -174,11 +174,9 @@ public class AzureQueueConnectionTest {
|
||||||
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
|
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
|
||||||
HttpUtils.toBase64String("key".getBytes()));
|
HttpUtils.toBase64String("key".getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
||||||
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
||||||
JaxrsAnnotationProcessor.Factory.class);
|
JaxrsAnnotationProcessor.Factory.class);
|
||||||
processor = factory.create(AzureQueueConnection.class);
|
processor = factory.create(AzureQueueConnection.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,19 +21,23 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rest;
|
||||||
|
|
||||||
import org.jclouds.cloud.CloudContext;
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.ElementType.TYPE;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an authenticated context to Cloud Files CDN.
|
* Designates that this Resource expects virtual host style requests
|
||||||
*
|
|
||||||
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
|
||||||
* @see CloudFilesCDNConnection
|
|
||||||
* @see CloudContext
|
|
||||||
* @author James Murty
|
|
||||||
*
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public interface CloudFilesCDNContext extends CloudContext<CloudFilesCDNConnection> {
|
@Target( { TYPE, METHOD })
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface Endpoint {
|
||||||
|
Class<? extends Annotation> value();
|
||||||
}
|
}
|
|
@ -40,6 +40,9 @@ import java.util.Map.Entry;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
@ -65,14 +68,11 @@ import com.google.common.collect.MapMaker;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import javax.inject.Inject;
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import javax.inject.Singleton;
|
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
import com.google.inject.internal.Lists;
|
import com.google.inject.internal.Lists;
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of JaxrsUtil
|
* Tests behavior of JaxrsUtil
|
||||||
|
@ -260,7 +260,9 @@ public class JaxrsAnnotationProcessor {
|
||||||
|
|
||||||
private HttpRequestOptionsBinder optionsBinder;
|
private HttpRequestOptionsBinder optionsBinder;
|
||||||
|
|
||||||
public HttpRequest createRequest(URI endpoint, Method method, Object[] args) {
|
public HttpRequest createRequest(Method method, Object[] args) {
|
||||||
|
URI endpoint = getEndpointFor(method);
|
||||||
|
|
||||||
String httpMethod = getHttpMethodOrConstantOrThrowException(method);
|
String httpMethod = getHttpMethodOrConstantOrThrowException(method);
|
||||||
|
|
||||||
UriBuilder builder = addHostPrefixIfPresent(endpoint, method, args);
|
UriBuilder builder = addHostPrefixIfPresent(endpoint, method, args);
|
||||||
|
@ -664,4 +666,17 @@ public class JaxrsAnnotationProcessor {
|
||||||
}
|
}
|
||||||
return postParams;
|
return postParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URI getEndpointFor(Method method) {
|
||||||
|
Endpoint endpoint;
|
||||||
|
if (method.isAnnotationPresent(Endpoint.class)) {
|
||||||
|
endpoint = method.getAnnotation(Endpoint.class);
|
||||||
|
} else if (declaring.isAnnotationPresent(Endpoint.class)) {
|
||||||
|
endpoint = declaring.getAnnotation(Endpoint.class);
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"There must be an @Endpoint annotation on type or method: " + method);
|
||||||
|
}
|
||||||
|
return injector.getInstance(Key.get(URI.class, endpoint.value()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,11 @@
|
||||||
package org.jclouds.rest;
|
package org.jclouds.rest;
|
||||||
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.rest.RestClientProxy.RestClientProxyFactory;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.rest.RestClientProxy.RestClientProxyFactory;
|
||||||
|
|
||||||
public class RestClientFactory {
|
public class RestClientFactory {
|
||||||
private final RestClientProxyFactory proxyFactory;
|
private final RestClientProxyFactory proxyFactory;
|
||||||
|
|
||||||
|
@ -39,9 +38,9 @@ public class RestClientFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T create(URI endPoint, Class<T> clazz) {
|
public <T> T create(Class<T> clazz) {
|
||||||
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz },
|
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz },
|
||||||
proxyFactory.create(endPoint, clazz));
|
proxyFactory.create(clazz));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,12 @@ package org.jclouds.rest;
|
||||||
*/
|
*/
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.concurrent.FutureExceptionParser;
|
import org.jclouds.concurrent.FutureExceptionParser;
|
||||||
import org.jclouds.http.HttpConstants;
|
import org.jclouds.http.HttpConstants;
|
||||||
|
@ -44,14 +45,11 @@ import org.jclouds.http.TransformingHttpCommand;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import javax.inject.Inject;
|
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
public class RestClientProxy implements InvocationHandler {
|
public class RestClientProxy implements InvocationHandler {
|
||||||
private final JaxrsAnnotationProcessor util;
|
private final JaxrsAnnotationProcessor util;
|
||||||
private final Class<?> declaring;
|
private final Class<?> declaring;
|
||||||
private final URI endPoint;
|
|
||||||
private final TransformingHttpCommand.Factory commandFactory;
|
private final TransformingHttpCommand.Factory commandFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,16 +63,14 @@ public class RestClientProxy implements InvocationHandler {
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
public static interface RestClientProxyFactory {
|
public static interface RestClientProxyFactory {
|
||||||
RestClientProxy create(URI endPoint, Class<?> clazz);
|
RestClientProxy create(Class<?> clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestClientProxy(JaxrsAnnotationProcessor.Factory utilFactory,
|
public RestClientProxy(JaxrsAnnotationProcessor.Factory utilFactory,
|
||||||
TransformingHttpCommand.Factory factory, @Assisted URI endPoint,
|
TransformingHttpCommand.Factory factory, @Assisted Class<?> declaring) {
|
||||||
@Assisted Class<?> declaring) {
|
|
||||||
this.util = utilFactory.create(declaring);
|
this.util = utilFactory.create(declaring);
|
||||||
this.declaring = declaring;
|
this.declaring = declaring;
|
||||||
this.endPoint = endPoint;
|
|
||||||
this.commandFactory = factory;
|
this.commandFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +83,7 @@ public class RestClientProxy implements InvocationHandler {
|
||||||
} else if (util.getDelegateOrNull(method) != null) {
|
} else if (util.getDelegateOrNull(method) != null) {
|
||||||
method = util.getDelegateOrNull(method);
|
method = util.getDelegateOrNull(method);
|
||||||
logger.trace("%s - converting method to request", method);
|
logger.trace("%s - converting method to request", method);
|
||||||
HttpRequest request = util.createRequest(endPoint, method, args);
|
HttpRequest request = util.createRequest(method, args);
|
||||||
logger.trace("%s - converted method to request %s", method, request);
|
logger.trace("%s - converted method to request %s", method, request);
|
||||||
|
|
||||||
Function<HttpResponse, ?> transformer = util.createResponseParser(method);
|
Function<HttpResponse, ?> transformer = util.createResponseParser(method);
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.cloud.CloudContextBuilder;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
||||||
import org.jclouds.rest.RestClientFactory;
|
import org.jclouds.rest.RestClientFactory;
|
||||||
|
import org.jclouds.rest.JaxrsAnnotationProcessorTest.Localhost;
|
||||||
import org.jclouds.rest.config.JaxrsModule;
|
import org.jclouds.rest.config.JaxrsModule;
|
||||||
import org.jclouds.util.Jsr330;
|
import org.jclouds.util.Jsr330;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
@ -145,13 +146,14 @@ public abstract class BaseJettyTest {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
Jsr330.bindProperties(binder(), properties);
|
Jsr330.bindProperties(binder(), properties);
|
||||||
|
bind(URI.class).annotatedWith(Localhost.class).toInstance(
|
||||||
|
URI.create("http://localhost:" + testPort));
|
||||||
}
|
}
|
||||||
}, new JDKLoggingModule(), new JaxrsModule(), createClientModule());
|
}, new JDKLoggingModule(), new JaxrsModule(), createClientModule());
|
||||||
CloudContextBuilder.addExecutorServiceIfNotPresent(modules);
|
CloudContextBuilder.addExecutorServiceIfNotPresent(modules);
|
||||||
injector = Guice.createInjector(modules);
|
injector = Guice.createInjector(modules);
|
||||||
RestClientFactory factory = injector.getInstance(RestClientFactory.class);
|
RestClientFactory factory = injector.getInstance(RestClientFactory.class);
|
||||||
client = factory.create(URI.create("http://localhost:" + testPort),
|
client = factory.create(IntegrationTestClient.class);
|
||||||
IntegrationTestClient.class);
|
|
||||||
closer = injector.getInstance(Closer.class);
|
closer = injector.getInstance(Closer.class);
|
||||||
assert client != null;
|
assert client != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,14 @@ import javax.ws.rs.PathParam;
|
||||||
import org.jclouds.http.binders.JsonBinder;
|
import org.jclouds.http.binders.JsonBinder;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.options.HttpRequestOptions;
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.EntityParam;
|
import org.jclouds.rest.EntityParam;
|
||||||
import org.jclouds.rest.ExceptionParser;
|
import org.jclouds.rest.ExceptionParser;
|
||||||
import org.jclouds.rest.MapBinder;
|
import org.jclouds.rest.MapBinder;
|
||||||
import org.jclouds.rest.MapEntityParam;
|
import org.jclouds.rest.MapEntityParam;
|
||||||
import org.jclouds.rest.RequestFilters;
|
import org.jclouds.rest.RequestFilters;
|
||||||
import org.jclouds.rest.XMLResponseParser;
|
import org.jclouds.rest.XMLResponseParser;
|
||||||
|
import org.jclouds.rest.JaxrsAnnotationProcessorTest.Localhost;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ import com.google.common.base.Function;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public interface IntegrationTestClient {
|
public interface IntegrationTestClient {
|
||||||
|
|
||||||
@HEAD
|
@HEAD
|
||||||
|
|
|
@ -40,6 +40,7 @@ import java.util.Map;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Qualifier;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
@ -63,6 +64,7 @@ import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.http.options.HttpRequestOptions;
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
import org.jclouds.rest.config.JaxrsModule;
|
import org.jclouds.rest.config.JaxrsModule;
|
||||||
import org.jclouds.util.DateService;
|
import org.jclouds.util.DateService;
|
||||||
|
import org.jclouds.util.Jsr330;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.mortbay.jetty.HttpHeaders;
|
import org.mortbay.jetty.HttpHeaders;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
@ -74,7 +76,6 @@ import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import org.jclouds.util.Jsr330;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
||||||
|
@ -83,14 +84,26 @@ import org.jclouds.util.Jsr330;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "jaxrs.JaxrsUtilTest")
|
@Test(groups = "unit", testName = "jaxrs.JaxrsUtilTest")
|
||||||
public class JaxrsAnnotationProcessorTest {
|
public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
@Target( { ElementType.METHOD })
|
@Target( { ElementType.METHOD })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@javax.ws.rs.HttpMethod("FOO")
|
@javax.ws.rs.HttpMethod("FOO")
|
||||||
public @interface FOO {
|
public @interface FOO {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
|
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
|
@Qualifier
|
||||||
|
public @interface Localhost {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
|
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
|
@Qualifier
|
||||||
|
public @interface Localhost2 {
|
||||||
|
}
|
||||||
|
|
||||||
@QueryParams(keys = "x-ms-version", values = "2009-07-17")
|
@QueryParams(keys = "x-ms-version", values = "2009-07-17")
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestQuery {
|
public class TestQuery {
|
||||||
@FOO
|
@FOO
|
||||||
@QueryParams(keys = "x-ms-rubbish", values = "bin")
|
@QueryParams(keys = "x-ms-rubbish", values = "bin")
|
||||||
|
@ -105,8 +118,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testQuery() throws SecurityException, NoSuchMethodException {
|
public void testQuery() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestQuery.class.getMethod("foo");
|
Method method = TestQuery.class.getMethod("foo");
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(endpoint, method,
|
|
||||||
new Object[] {});
|
new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
||||||
|
@ -116,8 +128,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testQuery2() throws SecurityException, NoSuchMethodException {
|
public void testQuery2() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestQuery.class.getMethod("foo2");
|
Method method = TestQuery.class.getMethod("foo2");
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(endpoint, method,
|
|
||||||
new Object[] {});
|
new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
||||||
|
@ -126,6 +137,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(httpMethod.getMethod(), "FOO");
|
assertEquals(httpMethod.getMethod(), "FOO");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestCustomMethod {
|
public class TestCustomMethod {
|
||||||
@FOO
|
@FOO
|
||||||
public void foo() {
|
public void foo() {
|
||||||
|
@ -134,9 +146,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testCustomMethod() throws SecurityException, NoSuchMethodException {
|
public void testCustomMethod() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestCustomMethod.class.getMethod("foo");
|
Method method = TestCustomMethod.class.getMethod("foo");
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestCustomMethod.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestCustomMethod.class).createRequest(endpoint,
|
new Object[] {});
|
||||||
method, new Object[] {});
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
||||||
assertEquals(httpMethod.getMethod(), "FOO");
|
assertEquals(httpMethod.getMethod(), "FOO");
|
||||||
|
@ -146,23 +157,42 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
public void foo();
|
public void foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestOverridden implements Parent {
|
public class TestOverridden implements Parent {
|
||||||
@POST
|
@POST
|
||||||
public void foo() {
|
public void foo() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverriddenMethod() throws SecurityException, NoSuchMethodException {
|
public void testOverriddenMethod() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestOverridden.class.getMethod("foo");
|
Method method = TestOverridden.class.getMethod("foo");
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestOverridden.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestOverridden.class).createRequest(endpoint, method,
|
|
||||||
new Object[] {});
|
new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
||||||
assertEquals(httpMethod.getMethod(), "POST");
|
assertEquals(httpMethod.getMethod(), "POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
|
public class TestOverriddenEndpoint implements Parent {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Endpoint(Localhost2.class)
|
||||||
|
public void foo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException {
|
||||||
|
Method method = TestOverriddenEndpoint.class.getMethod("foo");
|
||||||
|
HttpRequest httpMethod = factory.create(TestOverriddenEndpoint.class).createRequest(method,
|
||||||
|
new Object[] {});
|
||||||
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
|
assertEquals(httpMethod.getEndpoint().getPort(), 8081);
|
||||||
|
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
||||||
|
assertEquals(httpMethod.getMethod(), "POST");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestPost {
|
public class TestPost {
|
||||||
@POST
|
@POST
|
||||||
public void post(@EntityParam String content) {
|
public void post(@EntityParam String content) {
|
||||||
|
@ -183,13 +213,11 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
@MapBinder(JsonBinder.class)
|
@MapBinder(JsonBinder.class)
|
||||||
public void postWithMethodBinder(@PathParam("foo") @MapEntityParam("fooble") String path) {
|
public void postWithMethodBinder(@PathParam("foo") @MapEntityParam("fooble") String path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreatePostRequest() throws SecurityException, NoSuchMethodException {
|
public void testCreatePostRequest() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestPost.class.getMethod("post", String.class);
|
Method method = TestPost.class.getMethod("post", String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "data" });
|
new Object[] { "data" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
||||||
|
@ -204,8 +232,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException {
|
public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestPost.class.getMethod("postAsJson", String.class);
|
Method method = TestPost.class.getMethod("postAsJson", String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "data" });
|
new Object[] { "data" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
assertEquals(httpMethod.getEndpoint().getPath(), "");
|
||||||
|
@ -220,10 +247,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException {
|
public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestPost.class.getMethod("postWithPath", String.class, MapEntityBinder.class);
|
Method method = TestPost.class.getMethod("postWithPath", String.class, MapEntityBinder.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "data", new MapEntityBinder() {
|
new Object[] { "data", new MapEntityBinder() {
|
||||||
|
|
||||||
public void addEntityToRequest(Map<String, String> postParams, HttpRequest request) {
|
public void addEntityToRequest(Map<String, String> postParams, HttpRequest request) {
|
||||||
request.setEntity(postParams.get("fooble"));
|
request.setEntity(postParams.get("fooble"));
|
||||||
}
|
}
|
||||||
|
@ -231,7 +256,6 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
public void addEntityToRequest(Object toBind, HttpRequest request) {
|
public void addEntityToRequest(Object toBind, HttpRequest request) {
|
||||||
throw new RuntimeException("this shouldn't be used in POST");
|
throw new RuntimeException("this shouldn't be used in POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
} });
|
} });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
|
||||||
|
@ -242,8 +266,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException {
|
public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestPost.class.getMethod("postWithMethodBinder", String.class);
|
Method method = TestPost.class.getMethod("postWithMethodBinder", String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "data", });
|
new Object[] { "data", });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
|
||||||
|
@ -257,20 +280,18 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(httpMethod.getEntity(), expected);
|
assertEquals(httpMethod.getEntity(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestPut {
|
public class TestPut {
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{foo}")
|
@Path("{foo}")
|
||||||
@MapBinder(JsonBinder.class)
|
@MapBinder(JsonBinder.class)
|
||||||
public void putWithMethodBinder(@PathParam("foo") @MapEntityParam("fooble") String path) {
|
public void putWithMethodBinder(@PathParam("foo") @MapEntityParam("fooble") String path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException {
|
public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestPut.class.getMethod("putWithMethodBinder", String.class);
|
Method method = TestPut.class.getMethod("putWithMethodBinder", String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestPut.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestPut.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "data", });
|
new Object[] { "data", });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
|
||||||
|
@ -285,57 +306,49 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestRequestFilter1 implements HttpRequestFilter {
|
static class TestRequestFilter1 implements HttpRequestFilter {
|
||||||
|
|
||||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestRequestFilter2 implements HttpRequestFilter {
|
static class TestRequestFilter2 implements HttpRequestFilter {
|
||||||
|
|
||||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestFilters(TestRequestFilter1.class)
|
@RequestFilters(TestRequestFilter1.class)
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
static class TestRequestFilter {
|
static class TestRequestFilter {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RequestFilters(TestRequestFilter2.class)
|
@RequestFilters(TestRequestFilter2.class)
|
||||||
public void get() {
|
public void get() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestFilter() throws SecurityException, NoSuchMethodException {
|
public void testRequestFilter() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestRequestFilter.class.getMethod("get");
|
Method method = TestRequestFilter.class.getMethod("get");
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequestFilter.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequestFilter.class).createRequest(endpoint,
|
new Object[] {});
|
||||||
method, new Object[] {});
|
|
||||||
assertEquals(httpMethod.getFilters().size(), 2);
|
assertEquals(httpMethod.getFilters().size(), 2);
|
||||||
assertEquals(httpMethod.getFilters().get(0).getClass(), TestRequestFilter1.class);
|
assertEquals(httpMethod.getFilters().get(0).getClass(), TestRequestFilter1.class);
|
||||||
assertEquals(httpMethod.getFilters().get(1).getClass(), TestRequestFilter2.class);
|
assertEquals(httpMethod.getFilters().get(1).getClass(), TestRequestFilter2.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestEncoding {
|
public class TestEncoding {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{path1}/{path2}")
|
@Path("{path1}/{path2}")
|
||||||
public void twoPaths(@PathParam("path1") String path, @PathParam("path2") String path2) {
|
public void twoPaths(@PathParam("path1") String path, @PathParam("path2") String path2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSkipEncoding() throws SecurityException, NoSuchMethodException {
|
public void testSkipEncoding() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
|
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", "localhost" });
|
new Object[] { "1", "localhost" });
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1/localhost");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1/localhost");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
|
@ -345,8 +358,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEncodingPath() throws SecurityException, NoSuchMethodException {
|
public void testEncodingPath() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
|
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "/", "localhost" });
|
new Object[] { "/", "localhost" });
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "///localhost");
|
assertEquals(httpMethod.getEndpoint().getPath(), "///localhost");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
|
@ -355,8 +367,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
@Path("/v1/{account}")
|
@Path("/v1/{account}")
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public interface TestConstantPathParam {
|
public interface TestConstantPathParam {
|
||||||
|
|
||||||
@Named("testaccount")
|
@Named("testaccount")
|
||||||
@PathParam("account")
|
@PathParam("account")
|
||||||
void setUsername();
|
void setUsername();
|
||||||
|
@ -364,22 +376,20 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
@GET
|
@GET
|
||||||
@Path("{path1}/{path2}")
|
@Path("{path1}/{path2}")
|
||||||
public void twoPaths(@PathParam("path1") String path, @PathParam("path2") String path2);
|
public void twoPaths(@PathParam("path1") String path, @PathParam("path2") String path2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstantPathParam() throws SecurityException, NoSuchMethodException {
|
public void testConstantPathParam() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
|
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestConstantPathParam.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestConstantPathParam.class).createRequest(endpoint,
|
new Object[] { "1", "localhost" });
|
||||||
method, new Object[] { "1", "localhost" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/v1/ralphie/1/localhost");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/v1/ralphie/1/localhost");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestPath {
|
public class TestPath {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{path}")
|
@Path("{path}")
|
||||||
public void onePath(@PathParam("path") String path) {
|
public void onePath(@PathParam("path") String path) {
|
||||||
|
@ -404,15 +414,13 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class FirstCharacter implements Function<Object, String> {
|
static class FirstCharacter implements Function<Object, String> {
|
||||||
|
|
||||||
public String apply(Object from) {
|
public String apply(Object from) {
|
||||||
return from.toString().substring(0, 1);
|
return from.toString().substring(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestHeader {
|
public class TestHeader {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Headers(keys = "x-amz-copy-source", values = "/{bucket}")
|
@Headers(keys = "x-amz-copy-source", values = "/{bucket}")
|
||||||
public void oneHeader(@PathParam("bucket") String path) {
|
public void oneHeader(@PathParam("bucket") String path) {
|
||||||
|
@ -448,8 +456,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Headers(keys = "x-amz-copy-source", values = "/{bucket}")
|
@Headers(keys = "x-amz-copy-source", values = "/{bucket}")
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestClassHeader {
|
public class TestClassHeader {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public void oneHeader(@PathParam("bucket") String path) {
|
public void oneHeader(@PathParam("bucket") String path) {
|
||||||
}
|
}
|
||||||
|
@ -500,8 +508,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
|
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestTransformers {
|
public class TestTransformers {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public void noTransformer() {
|
public void noTransformer() {
|
||||||
}
|
}
|
||||||
|
@ -510,7 +518,6 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
@ResponseParser(ReturnStringIf200.class)
|
@ResponseParser(ReturnStringIf200.class)
|
||||||
public void oneTransformer() {
|
public void oneTransformer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
|
@ -530,8 +537,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(transformer, ReturnStringIf200.class);
|
assertEquals(transformer, ReturnStringIf200.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestRequest {
|
public class TestRequest {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@VirtualHost
|
@VirtualHost
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
|
@ -597,8 +604,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
|
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
|
||||||
HttpRequestOptions[] optionsHolder = new HttpRequestOptions[] {};
|
HttpRequestOptions[] optionsHolder = new HttpRequestOptions[] {};
|
||||||
Method method = TestRequest.class.getMethod("get", String.class, optionsHolder.getClass());
|
Method method = TestRequest.class.getMethod("get", String.class, optionsHolder.getClass());
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", options });
|
new Object[] { "1", options });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -614,10 +620,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
NoSuchMethodException {
|
NoSuchMethodException {
|
||||||
DateTime date = new DateTime();
|
DateTime date = new DateTime();
|
||||||
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
|
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
|
||||||
|
|
||||||
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
|
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", options });
|
new Object[] { "1", options });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -629,8 +633,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
.singletonList(dateService.rfc822DateFormat(date)));
|
.singletonList(dateService.rfc822DateFormat(date)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class PrefixOptions extends BaseHttpRequestOptions {
|
public class PrefixOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
public PrefixOptions withPrefix(String prefix) {
|
public PrefixOptions withPrefix(String prefix) {
|
||||||
queryParameters.put("prefix", checkNotNull(prefix, "prefix"));
|
queryParameters.put("prefix", checkNotNull(prefix, "prefix"));
|
||||||
return this;
|
return this;
|
||||||
|
@ -640,10 +644,8 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
public void testCreateGetOptionsThatProducesQuery() throws SecurityException,
|
public void testCreateGetOptionsThatProducesQuery() throws SecurityException,
|
||||||
NoSuchMethodException {
|
NoSuchMethodException {
|
||||||
PrefixOptions options = new PrefixOptions().withPrefix("1");
|
PrefixOptions options = new PrefixOptions().withPrefix("1");
|
||||||
|
|
||||||
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
|
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", options });
|
new Object[] { "1", options });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -652,13 +654,11 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
||||||
.singletonList("localhost"));
|
.singletonList("localhost"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateGetQuery() throws SecurityException, NoSuchMethodException {
|
public void testCreateGetQuery() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestRequest.class.getMethod("getQuery", String.class);
|
Method method = TestRequest.class.getMethod("getQuery", String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1" });
|
new Object[] { "1" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -669,8 +669,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException {
|
public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestRequest.class.getMethod("getQueryNull", String.class);
|
Method method = TestRequest.class.getMethod("getQueryNull", String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1" });
|
new Object[] { "1" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -679,6 +678,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class EntityOptions extends BaseHttpRequestOptions {
|
public class EntityOptions extends BaseHttpRequestOptions {
|
||||||
@Override
|
@Override
|
||||||
public String buildStringEntity() {
|
public String buildStringEntity() {
|
||||||
|
@ -689,11 +689,9 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
public void testCreateGetOptionsThatProducesEntity() throws SecurityException,
|
public void testCreateGetOptionsThatProducesEntity() throws SecurityException,
|
||||||
NoSuchMethodException {
|
NoSuchMethodException {
|
||||||
EntityOptions options = new EntityOptions();
|
EntityOptions options = new EntityOptions();
|
||||||
|
|
||||||
Method method = TestRequest.class.getMethod("putOptions", String.class,
|
Method method = TestRequest.class.getMethod("putOptions", String.class,
|
||||||
HttpRequestOptions.class);
|
HttpRequestOptions.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", options });
|
new Object[] { "1", options });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -706,7 +704,6 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
.singletonList("application/unknown"));
|
.singletonList("application/unknown"));
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
|
||||||
.singletonList("foo".getBytes().length + ""));
|
.singletonList("foo".getBytes().length + ""));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "strings")
|
@DataProvider(name = "strings")
|
||||||
|
@ -718,8 +715,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method method = TestRequest.class.getMethod("get", String.class, String.class);
|
Method method = TestRequest.class.getMethod("get", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { key, "localhost" });
|
new Object[] { key, "localhost" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20");
|
String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20");
|
||||||
|
@ -729,13 +725,11 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
||||||
.singletonList("localhost"));
|
.singletonList("localhost"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreatePutRequest() throws SecurityException, NoSuchMethodException {
|
public void testCreatePutRequest() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestRequest.class.getMethod("put", String.class, String.class);
|
Method method = TestRequest.class.getMethod("put", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "111", "data" });
|
new Object[] { "111", "data" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -750,8 +744,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
public void testCreatePutHeader() throws SecurityException, NoSuchMethodException {
|
public void testCreatePutHeader() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestRequest.class.getMethod("putHeader", String.class, String.class);
|
Method method = TestRequest.class.getMethod("putHeader", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", "data" });
|
new Object[] { "1", "data" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
|
@ -765,34 +758,31 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assertEquals(httpMethod.getEntity(), "data");
|
assertEquals(httpMethod.getEntity(), "data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestVirtualHostMethod {
|
public class TestVirtualHostMethod {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
@VirtualHost
|
@VirtualHost
|
||||||
public Future<String> get(@PathParam("id") String id, String foo) {
|
public Future<String> get(@PathParam("id") String id, String foo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
|
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestVirtualHostMethod.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestVirtualHostMethod.class).createRequest(endpoint,
|
new Object[] { "1", "localhost" });
|
||||||
method, new Object[] { "1", "localhost" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
||||||
.singletonList("localhost"));
|
.singletonList("localhost"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestVirtualHost {
|
public class TestVirtualHost {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
@VirtualHost
|
@VirtualHost
|
||||||
|
@ -816,37 +806,32 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testVirtualHost() throws SecurityException, NoSuchMethodException {
|
public void testVirtualHost() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHost.class.getMethod("get", String.class, String.class);
|
Method method = TestVirtualHost.class.getMethod("get", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(endpoint,
|
new Object[] { "1", "localhost" });
|
||||||
method, new Object[] { "1", "localhost" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
|
||||||
.singletonList("localhost"));
|
.singletonList("localhost"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostPrefix() throws SecurityException, NoSuchMethodException {
|
public void testHostPrefix() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHost.class.getMethod("getPrefix", String.class, String.class);
|
Method method = TestVirtualHost.class.getMethod("getPrefix", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(endpoint,
|
new Object[] { "1", "holy" });
|
||||||
method, new Object[] { "1", "holy" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "holylocalhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "holylocalhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostPrefixDot() throws SecurityException, NoSuchMethodException {
|
public void testHostPrefixDot() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
|
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(endpoint,
|
new Object[] { "1", "holy" });
|
||||||
method, new Object[] { "1", "holy" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "holy.localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "holy.localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
|
@ -856,22 +841,17 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testHostPrefixDotEmpty() throws SecurityException, NoSuchMethodException {
|
public void testHostPrefixDotEmpty() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
|
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
factory.create(TestVirtualHost.class).createRequest(method, new Object[] { "1", "" });
|
||||||
factory.create(TestVirtualHost.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", "" });
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testHostPrefixDotNull() throws SecurityException, NoSuchMethodException {
|
public void testHostPrefixDotNull() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
|
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
factory.create(TestVirtualHost.class).createRequest(method, new Object[] { "1", null });
|
||||||
factory.create(TestVirtualHost.class).createRequest(endpoint, method,
|
|
||||||
new Object[] { "1", null });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestHeaders {
|
public class TestHeaders {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public void oneHeader(@HeaderParam("header") String header) {
|
public void oneHeader(@HeaderParam("header") String header) {
|
||||||
}
|
}
|
||||||
|
@ -931,6 +911,7 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
assert values.contains("egg");
|
assert values.contains("egg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Endpoint(Localhost.class)
|
||||||
public class TestEntity {
|
public class TestEntity {
|
||||||
@PUT
|
@PUT
|
||||||
public void put(@EntityParam String content) {
|
public void put(@EntityParam String content) {
|
||||||
|
@ -944,7 +925,6 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
@PUT
|
@PUT
|
||||||
public void twoEntities(@EntityParam String entity1, @EntityParam String entity2) {
|
public void twoEntities(@EntityParam String entity1, @EntityParam String entity2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -964,7 +944,6 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
public void putWithPath() throws SecurityException, NoSuchMethodException {
|
public void putWithPath() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestEntity.class.getMethod("putWithPath", String.class, String.class);
|
Method method = TestEntity.class.getMethod("putWithPath", String.class, String.class);
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.PUT, URI.create("http://localhost:8080"));
|
HttpRequest request = new HttpRequest(HttpMethod.PUT, URI.create("http://localhost:8080"));
|
||||||
|
|
||||||
factory.create(TestEntity.class).buildEntityIfPostOrPutRequest(method,
|
factory.create(TestEntity.class).buildEntityIfPostOrPutRequest(method,
|
||||||
new Object[] { "rabble", "test" }, request);
|
new Object[] { "rabble", "test" }, request);
|
||||||
assertEquals(request.getEntity(), "test");
|
assertEquals(request.getEntity(), "test");
|
||||||
|
@ -987,11 +966,15 @@ public class JaxrsAnnotationProcessorTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
factory = Guice.createInjector(new AbstractModule() {
|
factory = Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bindConstant().annotatedWith(Jsr330.named("testaccount")).to("ralphie");
|
bindConstant().annotatedWith(Jsr330.named("testaccount")).to("ralphie");
|
||||||
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
|
bind(URI.class).annotatedWith(Localhost.class).toInstance(
|
||||||
|
URI.create("http://localhost:8080"));
|
||||||
|
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
|
||||||
|
URI.create("http://localhost:8081"));
|
||||||
}
|
}
|
||||||
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
||||||
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.concurrent.Future;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.HEAD;
|
import javax.ws.rs.HEAD;
|
||||||
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
@ -41,23 +42,34 @@ import org.jclouds.blobstore.binders.UserMetadataBinder;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.BlobKey;
|
import org.jclouds.blobstore.functions.BlobKey;
|
||||||
|
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
|
||||||
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
||||||
import org.jclouds.http.functions.ParseETagHeader;
|
import org.jclouds.http.functions.ParseETagHeader;
|
||||||
import org.jclouds.http.functions.ReturnFalseOn404;
|
import org.jclouds.http.functions.ReturnFalseOn404;
|
||||||
import org.jclouds.http.functions.ReturnTrueOn404;
|
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
import org.jclouds.rackspace.CloudFiles;
|
||||||
|
import org.jclouds.rackspace.CloudFilesCDN;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
|
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseAccountMetadataResponseFromHeaders;
|
import org.jclouds.rackspace.cloudfiles.functions.ParseAccountMetadataResponseFromHeaders;
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseBlobMetadataListFromJsonResponse;
|
import org.jclouds.rackspace.cloudfiles.functions.ParseBlobMetadataListFromJsonResponse;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.functions.ParseCdnUriFromHeaders;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataListFromGsonResponse;
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerListFromJsonResponse;
|
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerListFromJsonResponse;
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseObjectFromHeadersAndHttpContent;
|
import org.jclouds.rackspace.cloudfiles.functions.ParseObjectFromHeadersAndHttpContent;
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseObjectMetadataFromHeaders;
|
import org.jclouds.rackspace.cloudfiles.functions.ParseObjectMetadataFromHeaders;
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ReturnTrueOn404FalseOn409;
|
import org.jclouds.rackspace.cloudfiles.functions.ReturnTrueOn404FalseOn409;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
|
||||||
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
|
||||||
import org.jclouds.rackspace.filters.AuthenticateRequest;
|
import org.jclouds.rackspace.filters.AuthenticateRequest;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.EntityParam;
|
import org.jclouds.rest.EntityParam;
|
||||||
import org.jclouds.rest.ExceptionParser;
|
import org.jclouds.rest.ExceptionParser;
|
||||||
|
import org.jclouds.rest.Headers;
|
||||||
import org.jclouds.rest.ParamParser;
|
import org.jclouds.rest.ParamParser;
|
||||||
import org.jclouds.rest.QueryParams;
|
import org.jclouds.rest.QueryParams;
|
||||||
import org.jclouds.rest.RequestFilters;
|
import org.jclouds.rest.RequestFilters;
|
||||||
|
@ -77,6 +89,7 @@ import com.google.common.collect.Multimap;
|
||||||
*/
|
*/
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
@RequestFilters(AuthenticateRequest.class)
|
@RequestFilters(AuthenticateRequest.class)
|
||||||
|
@Endpoint(CloudFiles.class)
|
||||||
public interface CloudFilesBlobStore extends
|
public interface CloudFilesBlobStore extends
|
||||||
BlobStore<ContainerMetadata, BlobMetadata, Blob<BlobMetadata>> {
|
BlobStore<ContainerMetadata, BlobMetadata, Blob<BlobMetadata>> {
|
||||||
@GET
|
@GET
|
||||||
|
@ -155,4 +168,48 @@ public interface CloudFilesBlobStore extends
|
||||||
@PathParam("key") String key,
|
@PathParam("key") String key,
|
||||||
@EntityParam(UserMetadataBinder.class) Multimap<String, String> userMetadata);
|
@EntityParam(UserMetadataBinder.class) Multimap<String, String> userMetadata);
|
||||||
|
|
||||||
|
// / cdn functionality below
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseContainerCDNMetadataListFromGsonResponse.class)
|
||||||
|
@QueryParams(keys = "format", values = "json")
|
||||||
|
@Path("/")
|
||||||
|
@Endpoint(CloudFilesCDN.class)
|
||||||
|
List<ContainerCDNMetadata> listCDNContainers(ListCdnContainerOptions... options);
|
||||||
|
|
||||||
|
// TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it
|
||||||
|
// here.
|
||||||
|
@HEAD
|
||||||
|
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
|
||||||
|
@ExceptionParser(ThrowContainerNotFoundOn404.class)
|
||||||
|
@Path("{container}")
|
||||||
|
@Endpoint(CloudFilesCDN.class)
|
||||||
|
ContainerCDNMetadata getCDNMetadata(@PathParam("container") String container);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("{container}")
|
||||||
|
@ResponseParser(ParseCdnUriFromHeaders.class)
|
||||||
|
@Endpoint(CloudFilesCDN.class)
|
||||||
|
String enableCDN(@PathParam("container") String container,
|
||||||
|
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("{container}")
|
||||||
|
@ResponseParser(ParseCdnUriFromHeaders.class)
|
||||||
|
@Endpoint(CloudFilesCDN.class)
|
||||||
|
String enableCDN(@PathParam("container") String container);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("{container}")
|
||||||
|
@ResponseParser(ParseCdnUriFromHeaders.class)
|
||||||
|
@Endpoint(CloudFilesCDN.class)
|
||||||
|
String updateCDN(@PathParam("container") String container,
|
||||||
|
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("{container}")
|
||||||
|
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "False")
|
||||||
|
@Endpoint(CloudFilesCDN.class)
|
||||||
|
boolean disableCDN(@PathParam("container") String container);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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 org.jclouds.rackspace.cloudfiles;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.HEAD;
|
|
||||||
import javax.ws.rs.HeaderParam;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseCdnUriFromHeaders;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataListFromGsonResponse;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
|
|
||||||
import org.jclouds.rackspace.filters.AuthenticateRequest;
|
|
||||||
import org.jclouds.rest.ExceptionParser;
|
|
||||||
import org.jclouds.rest.Headers;
|
|
||||||
import org.jclouds.rest.QueryParams;
|
|
||||||
import org.jclouds.rest.RequestFilters;
|
|
||||||
import org.jclouds.rest.ResponseParser;
|
|
||||||
import org.jclouds.rest.SkipEncoding;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides access to the Cloud Files service's CDN offering via their REST API.
|
|
||||||
*
|
|
||||||
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
|
||||||
* @author James Murty
|
|
||||||
*/
|
|
||||||
@SkipEncoding('/')
|
|
||||||
@RequestFilters(AuthenticateRequest.class)
|
|
||||||
public interface CloudFilesCDNConnection {
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@ResponseParser(ParseContainerCDNMetadataListFromGsonResponse.class)
|
|
||||||
@QueryParams(keys = "format", values = "json")
|
|
||||||
@Path("/")
|
|
||||||
List<ContainerCDNMetadata> listCDNContainers(ListCdnContainerOptions... options);
|
|
||||||
|
|
||||||
// TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it
|
|
||||||
// here.
|
|
||||||
@HEAD
|
|
||||||
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
|
|
||||||
@ExceptionParser(ThrowContainerNotFoundOn404.class)
|
|
||||||
@Path("{container}")
|
|
||||||
ContainerCDNMetadata getCDNMetadata(@PathParam("container") String container);
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("{container}")
|
|
||||||
@ResponseParser(ParseCdnUriFromHeaders.class)
|
|
||||||
String enableCDN(@PathParam("container") String container,
|
|
||||||
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("{container}")
|
|
||||||
@ResponseParser(ParseCdnUriFromHeaders.class)
|
|
||||||
String enableCDN(@PathParam("container") String container);
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("{container}")
|
|
||||||
@ResponseParser(ParseCdnUriFromHeaders.class)
|
|
||||||
String updateCDN(@PathParam("container") String container,
|
|
||||||
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("{container}")
|
|
||||||
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "False")
|
|
||||||
boolean disableCDN(@PathParam("container") String container);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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 org.jclouds.rackspace.cloudfiles;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
|
||||||
import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
|
||||||
import org.jclouds.rackspace.RackspaceContextBuilder;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.config.RestCloudFilesCDNConnectionModule;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates {@link CloudFilesCDNContext} or {@link Injector} 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/>
|
|
||||||
* <p/>
|
|
||||||
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
|
|
||||||
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
|
|
||||||
*
|
|
||||||
* @author James Murty
|
|
||||||
* @see CloudFilesCDNContext, CloudFilesCDNContextBuilder
|
|
||||||
*/
|
|
||||||
public class CloudFilesCDNContextBuilder extends RackspaceContextBuilder<CloudFilesCDNContext> {
|
|
||||||
|
|
||||||
public CloudFilesCDNContextBuilder(Properties props) {
|
|
||||||
super(props);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CloudFilesCDNContextBuilder newBuilder(String id, String secret) {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
CloudFilesCDNContextBuilder builder = new CloudFilesCDNContextBuilder(properties);
|
|
||||||
builder.authenticate(id, secret);
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addApiModule(List<Module> modules) {
|
|
||||||
super.addApiModule(modules);
|
|
||||||
modules.add(new RestCloudFilesCDNConnectionModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addContextModule(List<Module> modules) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CloudFilesCDNContext buildContext() {
|
|
||||||
return buildInjector().getInstance(CloudFilesCDNContext.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
|
||||||
import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
|
||||||
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates {@link CloudFilesCDNContext} 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/>
|
|
||||||
* <p/>
|
|
||||||
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
|
|
||||||
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole, Andrew Newdigate
|
|
||||||
* @see CloudFilesCDNContext
|
|
||||||
*/
|
|
||||||
public class CloudFilesCDNContextFactory {
|
|
||||||
|
|
||||||
public static CloudFilesCDNContext createCloudFilesCDNContext(String user, String key,
|
|
||||||
Module... modules) {
|
|
||||||
return CloudFilesCDNContextBuilder.newBuilder(user, key).withModules(modules).buildContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CloudFilesCDNContext createCloudFilesCDNContext(URI endpoint, String user,
|
|
||||||
String key, Module... modules) {
|
|
||||||
return CloudFilesCDNContextBuilder.newBuilder(user, key).withEndpoint(endpoint).withModules(
|
|
||||||
modules).buildContext();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -23,17 +23,15 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles.config;
|
package org.jclouds.rackspace.cloudfiles.config;
|
||||||
|
|
||||||
import java.net.URI;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.cloud.ConfiguresCloudConnection;
|
import org.jclouds.cloud.ConfiguresCloudConnection;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rackspace.Storage;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
|
||||||
import org.jclouds.rest.RestClientFactory;
|
import org.jclouds.rest.RestClientFactory;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the Cloud Files connection, including logging and http transport.
|
* Configures the Cloud Files connection, including logging and http transport.
|
||||||
|
@ -50,9 +48,8 @@ public class RestCloudFilesBlobStoreModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected CloudFilesBlobStore provideConnection(@Storage URI authenticationUri,
|
protected CloudFilesBlobStore provideConnection(RestClientFactory factory) {
|
||||||
RestClientFactory factory) {
|
return factory.create(CloudFilesBlobStore.class);
|
||||||
return factory.create(authenticationUri, CloudFilesBlobStore.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,63 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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 org.jclouds.rackspace.cloudfiles.config;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.cloud.ConfiguresCloudConnection;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.rackspace.CDN;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNConnection;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNContext;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesCDNContext;
|
|
||||||
import org.jclouds.rest.RestClientFactory;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the Cloud Files CDN connection, including logging and http transport.
|
|
||||||
* This class supplies the CDN-specific URI required for the CDN operations in the
|
|
||||||
* Cloud Files service.
|
|
||||||
*
|
|
||||||
* @author James Murty
|
|
||||||
*/
|
|
||||||
@ConfiguresCloudConnection
|
|
||||||
@RequiresHttp
|
|
||||||
public class RestCloudFilesCDNConnectionModule extends AbstractModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(CloudFilesCDNContext.class).to(GuiceCloudFilesCDNContext.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected CloudFilesCDNConnection provideCDNConnection(@CDN URI cdnUri,
|
|
||||||
RestClientFactory factory) {
|
|
||||||
return factory.create(cdnUri, CloudFilesCDNConnection.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,92 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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 org.jclouds.rackspace.cloudfiles.internal;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.jclouds.lifecycle.Closer;
|
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
import org.jclouds.rackspace.Authentication;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNConnection;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNContext;
|
|
||||||
import org.jclouds.rackspace.reference.RackspaceConstants;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses a Guice Injector to configure the objects served by CloudFilesCDNContext methods.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
* @see Injector
|
|
||||||
*/
|
|
||||||
public class GuiceCloudFilesCDNContext implements CloudFilesCDNContext {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private Logger logger = Logger.NULL;
|
|
||||||
private final Injector injector;
|
|
||||||
private final Closer closer;
|
|
||||||
private final URI endPoint;
|
|
||||||
private final String account;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private GuiceCloudFilesCDNContext(Injector injector, Closer closer,
|
|
||||||
@Authentication URI endPoint,
|
|
||||||
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
|
|
||||||
this.injector = injector;
|
|
||||||
this.closer = closer;
|
|
||||||
this.endPoint = endPoint;
|
|
||||||
this.account = account;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @see Closer
|
|
||||||
*/
|
|
||||||
public void close() {
|
|
||||||
try {
|
|
||||||
closer.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error(e, "error closing content");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccount() {
|
|
||||||
return account;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CloudFilesCDNConnection getApi() {
|
|
||||||
return injector.getInstance(CloudFilesCDNConnection.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getEndPoint() {
|
|
||||||
return endPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -34,6 +34,7 @@ import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||||
|
@ -42,11 +43,14 @@ import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
|
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
|
||||||
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
@ -70,6 +74,99 @@ public class CloudFilesBlobStoreLiveTest {
|
||||||
new Log4JLoggingModule()).getApi();
|
new Log4JLoggingModule()).getApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCDNOperations() throws Exception {
|
||||||
|
final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour
|
||||||
|
|
||||||
|
// Create two new containers for testing
|
||||||
|
final String containerNameWithCDN = bucketPrefix + ".testCDNOperationsContainerWithCDN";
|
||||||
|
final String containerNameWithoutCDN = bucketPrefix + ".testCDNOperationsContainerWithoutCDN";
|
||||||
|
assertTrue(connection.createContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
|
||||||
|
assertTrue(connection.createContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
ContainerCDNMetadata cdnMetadata = null;
|
||||||
|
|
||||||
|
// Enable CDN with PUT for one container
|
||||||
|
final String cdnUri = connection.enableCDN(containerNameWithCDN);
|
||||||
|
assertTrue(cdnUri != null);
|
||||||
|
assertTrue(cdnUri.startsWith("http://"));
|
||||||
|
|
||||||
|
// Confirm CDN is enabled via HEAD request and has default TTL
|
||||||
|
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
|
||||||
|
assertTrue(cdnMetadata.isCdnEnabled());
|
||||||
|
assertEquals(cdnMetadata.getCdnUri(), cdnUri);
|
||||||
|
final long initialTTL = cdnMetadata.getTtl();
|
||||||
|
|
||||||
|
try {
|
||||||
|
cdnMetadata = connection.getCDNMetadata(containerNameWithoutCDN);
|
||||||
|
assert false : "should not exist";
|
||||||
|
} catch (ContainerNotFoundException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
cdnMetadata = connection.getCDNMetadata("DoesNotExist");
|
||||||
|
assert false : "should not exist";
|
||||||
|
} catch (ContainerNotFoundException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// List CDN metadata for containers, and ensure all CDN info is available for enabled
|
||||||
|
// container
|
||||||
|
List<ContainerCDNMetadata> cdnMetadataList = connection.listCDNContainers();
|
||||||
|
assertTrue(cdnMetadataList.size() >= 1);
|
||||||
|
assertTrue(Iterables.any(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
|
||||||
|
public boolean apply(ContainerCDNMetadata cdnMetadata) {
|
||||||
|
return (cdnMetadata.getName().equals(containerNameWithCDN)
|
||||||
|
&& cdnMetadata.isCdnEnabled() && cdnMetadata.getTtl() == initialTTL && cdnMetadata
|
||||||
|
.getCdnUri().equals(cdnUri));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Test listing with options
|
||||||
|
cdnMetadataList = connection.listCDNContainers(ListCdnContainerOptions.Builder.enabledOnly());
|
||||||
|
assertTrue(Iterables.all(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
|
||||||
|
public boolean apply(ContainerCDNMetadata cdnMetadata) {
|
||||||
|
return cdnMetadata.isCdnEnabled();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
cdnMetadataList = connection.listCDNContainers(ListCdnContainerOptions.Builder.afterMarker(
|
||||||
|
containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1)).maxResults(1));
|
||||||
|
assertEquals(cdnMetadataList.size(), 1);
|
||||||
|
assertEquals(cdnMetadataList.get(0).getName(), containerNameWithCDN);
|
||||||
|
|
||||||
|
// Enable CDN with PUT for the same container, this time with a custom TTL
|
||||||
|
long ttl = 4000;
|
||||||
|
connection.enableCDN(containerNameWithCDN, ttl);
|
||||||
|
|
||||||
|
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
|
||||||
|
assertTrue(cdnMetadata.isCdnEnabled());
|
||||||
|
assertEquals(cdnMetadata.getTtl(), ttl);
|
||||||
|
|
||||||
|
// Check POST by updating TTL settings
|
||||||
|
ttl = minimumTTL;
|
||||||
|
connection.updateCDN(containerNameWithCDN, minimumTTL);
|
||||||
|
|
||||||
|
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
|
||||||
|
assertTrue(cdnMetadata.isCdnEnabled());
|
||||||
|
assertEquals(cdnMetadata.getTtl(), minimumTTL);
|
||||||
|
|
||||||
|
// Confirm that minimum allowed value for TTL is 3600, lower values are ignored.
|
||||||
|
connection.updateCDN(containerNameWithCDN, 3599L);
|
||||||
|
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
|
||||||
|
assertEquals(cdnMetadata.getTtl(), minimumTTL); // Note that TTL is 3600 here, not 3599
|
||||||
|
|
||||||
|
// Disable CDN with POST
|
||||||
|
assertTrue(connection.disableCDN(containerNameWithCDN));
|
||||||
|
|
||||||
|
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
|
||||||
|
assertEquals(cdnMetadata.isCdnEnabled(), false);
|
||||||
|
|
||||||
|
// Delete test containers
|
||||||
|
assertTrue(connection.deleteContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
|
||||||
|
assertTrue(connection.deleteContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListOwnedContainers() throws Exception {
|
public void testListOwnedContainers() throws Exception {
|
||||||
List<ContainerMetadata> response = connection.listContainers();
|
List<ContainerMetadata> response = connection.listContainers();
|
||||||
|
|
|
@ -1,159 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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 org.jclouds.rackspace.cloudfiles;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
|
|
||||||
import org.testng.annotations.BeforeGroups;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code JaxrsAnnotationProcessor} for Cloud Files CDN service.
|
|
||||||
*
|
|
||||||
* @author James Murty
|
|
||||||
*/
|
|
||||||
@Test(groups = "live", testName = "cloudfiles.CloudFilesAuthenticationLiveTest")
|
|
||||||
public class CloudFilesCDNConnectionLiveTest {
|
|
||||||
|
|
||||||
private String bucketPrefix = System.getProperty("user.name") + "-cfcdnint";
|
|
||||||
CloudFilesCDNConnection cdnConnection;
|
|
||||||
CloudFilesBlobStore filesConnection;
|
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
|
||||||
public void setupConnection() {
|
|
||||||
String account = System.getProperty("jclouds.test.user");
|
|
||||||
String key = System.getProperty("jclouds.test.key");
|
|
||||||
|
|
||||||
cdnConnection = CloudFilesCDNContextFactory.createCloudFilesCDNContext(account, key,
|
|
||||||
new Log4JLoggingModule()).getApi();
|
|
||||||
filesConnection = CloudFilesContextFactory.createCloudFilesContext(account, key,
|
|
||||||
new Log4JLoggingModule()).getApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCDNOperations() throws Exception {
|
|
||||||
final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour
|
|
||||||
|
|
||||||
// Create two new containers for testing
|
|
||||||
final String containerNameWithCDN = bucketPrefix + ".testCDNOperationsContainerWithCDN";
|
|
||||||
final String containerNameWithoutCDN = bucketPrefix + ".testCDNOperationsContainerWithoutCDN";
|
|
||||||
assertTrue(filesConnection.createContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
|
|
||||||
assertTrue(filesConnection.createContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
|
|
||||||
|
|
||||||
ContainerCDNMetadata cdnMetadata = null;
|
|
||||||
|
|
||||||
// Enable CDN with PUT for one container
|
|
||||||
final String cdnUri = cdnConnection.enableCDN(containerNameWithCDN);
|
|
||||||
assertTrue(cdnUri != null);
|
|
||||||
assertTrue(cdnUri.startsWith("http://"));
|
|
||||||
|
|
||||||
// Confirm CDN is enabled via HEAD request and has default TTL
|
|
||||||
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
|
|
||||||
assertTrue(cdnMetadata.isCdnEnabled());
|
|
||||||
assertEquals(cdnMetadata.getCdnUri(), cdnUri);
|
|
||||||
final long initialTTL = cdnMetadata.getTtl();
|
|
||||||
|
|
||||||
try {
|
|
||||||
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithoutCDN);
|
|
||||||
assert false : "should not exist";
|
|
||||||
} catch (ContainerNotFoundException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
cdnMetadata = cdnConnection.getCDNMetadata("DoesNotExist");
|
|
||||||
assert false : "should not exist";
|
|
||||||
} catch (ContainerNotFoundException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// List CDN metadata for containers, and ensure all CDN info is available for enabled
|
|
||||||
// container
|
|
||||||
List<ContainerCDNMetadata> cdnMetadataList = cdnConnection.listCDNContainers();
|
|
||||||
assertTrue(cdnMetadataList.size() >= 1);
|
|
||||||
assertTrue(Iterables.any(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
|
|
||||||
public boolean apply(ContainerCDNMetadata cdnMetadata) {
|
|
||||||
return (cdnMetadata.getName().equals(containerNameWithCDN)
|
|
||||||
&& cdnMetadata.isCdnEnabled() && cdnMetadata.getTtl() == initialTTL && cdnMetadata
|
|
||||||
.getCdnUri().equals(cdnUri));
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Test listing with options
|
|
||||||
cdnMetadataList = cdnConnection.listCDNContainers(ListCdnContainerOptions.Builder
|
|
||||||
.enabledOnly());
|
|
||||||
assertTrue(Iterables.all(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
|
|
||||||
public boolean apply(ContainerCDNMetadata cdnMetadata) {
|
|
||||||
return cdnMetadata.isCdnEnabled();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
cdnMetadataList = cdnConnection.listCDNContainers(ListCdnContainerOptions.Builder
|
|
||||||
.afterMarker(containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1))
|
|
||||||
.maxResults(1));
|
|
||||||
assertEquals(cdnMetadataList.size(), 1);
|
|
||||||
assertEquals(cdnMetadataList.get(0).getName(), containerNameWithCDN);
|
|
||||||
|
|
||||||
// Enable CDN with PUT for the same container, this time with a custom TTL
|
|
||||||
long ttl = 4000;
|
|
||||||
cdnConnection.enableCDN(containerNameWithCDN, ttl);
|
|
||||||
|
|
||||||
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
|
|
||||||
assertTrue(cdnMetadata.isCdnEnabled());
|
|
||||||
assertEquals(cdnMetadata.getTtl(), ttl);
|
|
||||||
|
|
||||||
// Check POST by updating TTL settings
|
|
||||||
ttl = minimumTTL;
|
|
||||||
cdnConnection.updateCDN(containerNameWithCDN, minimumTTL);
|
|
||||||
|
|
||||||
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
|
|
||||||
assertTrue(cdnMetadata.isCdnEnabled());
|
|
||||||
assertEquals(cdnMetadata.getTtl(), minimumTTL);
|
|
||||||
|
|
||||||
// Confirm that minimum allowed value for TTL is 3600, lower values are ignored.
|
|
||||||
cdnConnection.updateCDN(containerNameWithCDN, 3599L);
|
|
||||||
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
|
|
||||||
assertEquals(cdnMetadata.getTtl(), minimumTTL); // Note that TTL is 3600 here, not 3599
|
|
||||||
|
|
||||||
// Disable CDN with POST
|
|
||||||
assertTrue(cdnConnection.disableCDN(containerNameWithCDN));
|
|
||||||
|
|
||||||
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
|
|
||||||
assertEquals(cdnMetadata.isCdnEnabled(), false);
|
|
||||||
|
|
||||||
// Delete test containers
|
|
||||||
assertTrue(filesConnection.deleteContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
|
|
||||||
assertTrue(filesConnection.deleteContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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 org.jclouds.rackspace.cloudfiles;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.cloud.CloudContext;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.config.RestCloudFilesCDNConnectionModule;
|
|
||||||
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesCDNContext;
|
|
||||||
import org.jclouds.rackspace.config.RestRackspaceAuthenticationModule;
|
|
||||||
import org.jclouds.rackspace.reference.RackspaceConstants;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of modules configured in CloudFilesCDNContextBuilder
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "cloudfiles.CloudFilesCDNContextBuilderTest")
|
|
||||||
public class CloudFilesCDNContextBuilderTest {
|
|
||||||
|
|
||||||
public void testNewBuilder() {
|
|
||||||
CloudFilesCDNContextBuilder builder = CloudFilesCDNContextBuilder.newBuilder("id", "secret");
|
|
||||||
assertEquals(builder.getProperties().getProperty(
|
|
||||||
RackspaceConstants.PROPERTY_RACKSPACE_ENDPOINT), "https://api.mosso.com");
|
|
||||||
assertEquals(builder.getProperties().getProperty(RackspaceConstants.PROPERTY_RACKSPACE_USER),
|
|
||||||
"id");
|
|
||||||
assertEquals(builder.getProperties().getProperty(RackspaceConstants.PROPERTY_RACKSPACE_KEY),
|
|
||||||
"secret");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildContext() {
|
|
||||||
CloudContext<CloudFilesCDNConnection> context = CloudFilesCDNContextBuilder.newBuilder("id",
|
|
||||||
"secret").buildContext();
|
|
||||||
assertEquals(context.getClass(), GuiceCloudFilesCDNContext.class);
|
|
||||||
assertEquals(context.getAccount(), "id");
|
|
||||||
assertEquals(context.getEndPoint(), URI.create("https://api.mosso.com"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBuildInjector() {
|
|
||||||
Injector i = CloudFilesCDNContextBuilder.newBuilder("id", "secret").buildInjector();
|
|
||||||
assert i.getInstance(CloudFilesCDNContext.class) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void testAddContextModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
CloudFilesCDNContextBuilder builder = CloudFilesCDNContextBuilder.newBuilder("id", "secret");
|
|
||||||
builder.addContextModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), RestRackspaceAuthenticationModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addConnectionModule() {
|
|
||||||
List<Module> modules = new ArrayList<Module>();
|
|
||||||
CloudFilesCDNContextBuilder builder = CloudFilesCDNContextBuilder.newBuilder("id", "secret");
|
|
||||||
builder.addApiModule(modules);
|
|
||||||
assertEquals(modules.size(), 1);
|
|
||||||
assertEquals(modules.get(0).getClass(), RestCloudFilesCDNConnectionModule.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -32,7 +32,9 @@ import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.integration.internal.StubBlobStore;
|
import org.jclouds.blobstore.integration.internal.StubBlobStore;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
|
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
||||||
|
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
|
||||||
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
@ -85,4 +87,28 @@ public class StubCloudFilesBlobStore extends
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean disableCDN(String container) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String enableCDN(String container, Long ttl) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String enableCDN(String container) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContainerCDNMetadata getCDNMetadata(String container) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ContainerCDNMetadata> listCDNContainers(ListCdnContainerOptions... options) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String updateCDN(String container, Long ttl) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
import org.jclouds.http.functions.ReturnFalseOn404;
|
import org.jclouds.http.functions.ReturnFalseOn404;
|
||||||
|
import org.jclouds.rackspace.CloudServers;
|
||||||
import org.jclouds.rackspace.cloudservers.binders.BackupScheduleBinder;
|
import org.jclouds.rackspace.cloudservers.binders.BackupScheduleBinder;
|
||||||
import org.jclouds.rackspace.cloudservers.binders.ChangeAdminPassBinder;
|
import org.jclouds.rackspace.cloudservers.binders.ChangeAdminPassBinder;
|
||||||
import org.jclouds.rackspace.cloudservers.binders.ChangeServerNameBinder;
|
import org.jclouds.rackspace.cloudservers.binders.ChangeServerNameBinder;
|
||||||
|
@ -73,6 +74,7 @@ import org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions;
|
||||||
import org.jclouds.rackspace.cloudservers.options.ListOptions;
|
import org.jclouds.rackspace.cloudservers.options.ListOptions;
|
||||||
import org.jclouds.rackspace.cloudservers.options.RebuildServerOptions;
|
import org.jclouds.rackspace.cloudservers.options.RebuildServerOptions;
|
||||||
import org.jclouds.rackspace.filters.AuthenticateRequest;
|
import org.jclouds.rackspace.filters.AuthenticateRequest;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.EntityParam;
|
import org.jclouds.rest.EntityParam;
|
||||||
import org.jclouds.rest.ExceptionParser;
|
import org.jclouds.rest.ExceptionParser;
|
||||||
import org.jclouds.rest.MapBinder;
|
import org.jclouds.rest.MapBinder;
|
||||||
|
@ -94,6 +96,7 @@ import org.jclouds.rest.SkipEncoding;
|
||||||
*/
|
*/
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
@RequestFilters(AuthenticateRequest.class)
|
@RequestFilters(AuthenticateRequest.class)
|
||||||
|
@Endpoint(CloudServers.class)
|
||||||
public interface CloudServersConnection {
|
public interface CloudServersConnection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,11 +23,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rackspace.cloudservers.config;
|
package org.jclouds.rackspace.cloudservers.config;
|
||||||
|
|
||||||
import java.net.URI;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.cloud.ConfiguresCloudConnection;
|
import org.jclouds.cloud.ConfiguresCloudConnection;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rackspace.Server;
|
|
||||||
import org.jclouds.rackspace.cloudservers.CloudServersConnection;
|
import org.jclouds.rackspace.cloudservers.CloudServersConnection;
|
||||||
import org.jclouds.rackspace.cloudservers.CloudServersContext;
|
import org.jclouds.rackspace.cloudservers.CloudServersContext;
|
||||||
import org.jclouds.rackspace.cloudservers.internal.GuiceCloudServersContext;
|
import org.jclouds.rackspace.cloudservers.internal.GuiceCloudServersContext;
|
||||||
|
@ -35,7 +34,6 @@ import org.jclouds.rest.RestClientFactory;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the Cloud Servers connection, including logging and http transport.
|
* Configures the Cloud Servers connection, including logging and http transport.
|
||||||
|
@ -53,9 +51,8 @@ public class RestCloudServersConnectionModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected CloudServersConnection provideConnection(@Server URI authenticationUri,
|
protected CloudServersConnection provideConnection(RestClientFactory factory) {
|
||||||
RestClientFactory factory) {
|
return factory.create(CloudServersConnection.class);
|
||||||
return factory.create(authenticationUri, CloudServersConnection.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -46,9 +46,9 @@ public class Server {
|
||||||
private Integer flavorId;
|
private Integer flavorId;
|
||||||
private String hostId;
|
private String hostId;
|
||||||
private Integer imageId;
|
private Integer imageId;
|
||||||
|
private Integer sharedIpGroupId;
|
||||||
|
|
||||||
private Integer progress;
|
private Integer progress;
|
||||||
private Integer sharedIpGroupId;
|
|
||||||
private ServerStatus status;
|
private ServerStatus status;
|
||||||
|
|
||||||
public Server() {
|
public Server() {
|
||||||
|
@ -163,9 +163,7 @@ public class Server {
|
||||||
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
|
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
|
||||||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
||||||
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||||
result = prime * result + ((progress == null) ? 0 : progress.hashCode());
|
|
||||||
result = prime * result + ((sharedIpGroupId == null) ? 0 : sharedIpGroupId.hashCode());
|
result = prime * result + ((sharedIpGroupId == null) ? 0 : sharedIpGroupId.hashCode());
|
||||||
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,21 +213,11 @@ public class Server {
|
||||||
return false;
|
return false;
|
||||||
} else if (!getName().equals(other.getName()))
|
} else if (!getName().equals(other.getName()))
|
||||||
return false;
|
return false;
|
||||||
if (progress == null) {
|
|
||||||
if (other.progress != null)
|
|
||||||
return false;
|
|
||||||
} else if (!progress.equals(other.progress))
|
|
||||||
return false;
|
|
||||||
if (sharedIpGroupId == null) {
|
if (sharedIpGroupId == null) {
|
||||||
if (other.sharedIpGroupId != null)
|
if (other.sharedIpGroupId != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!sharedIpGroupId.equals(other.sharedIpGroupId))
|
} else if (!sharedIpGroupId.equals(other.sharedIpGroupId))
|
||||||
return false;
|
return false;
|
||||||
if (status == null) {
|
|
||||||
if (other.status != null)
|
|
||||||
return false;
|
|
||||||
} else if (!status.equals(other.status))
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class CreateSharedIpGroupOptions extends JsonBinder {
|
||||||
Integer serverId;
|
Integer serverId;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private class SharedIpGroupRequest {
|
private static class SharedIpGroupRequest {
|
||||||
final String name;
|
final String name;
|
||||||
Integer server;
|
Integer server;
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,8 @@ import com.google.inject.Injector;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", sequential = true, testName = "cloudservers.CloudServersConnectionLiveTest")
|
// disabled [Web Hosting #129069
|
||||||
|
@Test(groups = "live", enabled = false, sequential = true, testName = "cloudservers.CloudServersConnectionLiveTest")
|
||||||
public class CloudServersConnectionLiveTest {
|
public class CloudServersConnectionLiveTest {
|
||||||
|
|
||||||
protected CloudServersConnection connection;
|
protected CloudServersConnection connection;
|
||||||
|
@ -475,7 +476,8 @@ public class CloudServersConnectionLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServerIp")
|
// [Web Hosting #129069
|
||||||
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp")
|
||||||
public void testUnshare() throws Exception {
|
public void testUnshare() throws Exception {
|
||||||
connection.unshareIp(ip, serverId2);
|
connection.unshareIp(ip, serverId2);
|
||||||
blockUntilServerActive(serverId2);
|
blockUntilServerActive(serverId2);
|
||||||
|
@ -496,7 +498,8 @@ public class CloudServersConnectionLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testUnshare")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp")
|
||||||
|
// "testUnshare")
|
||||||
public void testShareConfig() throws Exception {
|
public void testShareConfig() throws Exception {
|
||||||
connection.shareIp(ip, serverId2, sharedIpGroupId, true);
|
connection.shareIp(ip, serverId2, sharedIpGroupId, true);
|
||||||
blockUntilServerActive(serverId2);
|
blockUntilServerActive(serverId2);
|
||||||
|
@ -506,7 +509,7 @@ public class CloudServersConnectionLiveTest {
|
||||||
testUnshare();
|
testUnshare();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testShareConfig")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareConfig")
|
||||||
public void testShareNoConfig() throws Exception {
|
public void testShareNoConfig() throws Exception {
|
||||||
connection.shareIp(ip, serverId2, sharedIpGroupId, false);
|
connection.shareIp(ip, serverId2, sharedIpGroupId, false);
|
||||||
blockUntilServerActive(serverId2);
|
blockUntilServerActive(serverId2);
|
||||||
|
@ -516,7 +519,7 @@ public class CloudServersConnectionLiveTest {
|
||||||
testUnshare();
|
testUnshare();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testShareNoConfig")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig")
|
||||||
public void testBackup() throws Exception {
|
public void testBackup() throws Exception {
|
||||||
assertEquals(new BackupSchedule(), connection.listBackupSchedule(serverId));
|
assertEquals(new BackupSchedule(), connection.listBackupSchedule(serverId));
|
||||||
BackupSchedule dailyWeekly = new BackupSchedule();
|
BackupSchedule dailyWeekly = new BackupSchedule();
|
||||||
|
@ -529,7 +532,7 @@ public class CloudServersConnectionLiveTest {
|
||||||
assertEquals(connection.listBackupSchedule(serverId).isEnabled(), false);
|
assertEquals(connection.listBackupSchedule(serverId).isEnabled(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testBackup")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup")
|
||||||
public void testCreateImage() throws Exception {
|
public void testCreateImage() throws Exception {
|
||||||
Image image = connection.createImageFromServer("hoofie", serverId);
|
Image image = connection.createImageFromServer("hoofie", serverId);
|
||||||
assertEquals("hoofie", image.getName());
|
assertEquals("hoofie", image.getName());
|
||||||
|
@ -538,7 +541,7 @@ public class CloudServersConnectionLiveTest {
|
||||||
blockUntilImageActive(imageId);
|
blockUntilImageActive(imageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateImage")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage")
|
||||||
public void testRebuildServer() throws Exception {
|
public void testRebuildServer() throws Exception {
|
||||||
assertTrue(connection.rebuildServer(serverId, withImage(imageId)));
|
assertTrue(connection.rebuildServer(serverId, withImage(imageId)));
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
|
@ -546,19 +549,19 @@ public class CloudServersConnectionLiveTest {
|
||||||
// assertEquals(new Integer(imageId), connection.getServer(serverId).getImageId());
|
// assertEquals(new Integer(imageId), connection.getServer(serverId).getImageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
||||||
public void testRebootHard() throws Exception {
|
public void testRebootHard() throws Exception {
|
||||||
assertTrue(connection.rebootServer(serverId, RebootType.HARD));
|
assertTrue(connection.rebootServer(serverId, RebootType.HARD));
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebootHard")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard")
|
||||||
public void testRebootSoft() throws Exception {
|
public void testRebootSoft() throws Exception {
|
||||||
assertTrue(connection.rebootServer(serverId, RebootType.SOFT));
|
assertTrue(connection.rebootServer(serverId, RebootType.SOFT));
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||||
public void testRevertResize() throws Exception {
|
public void testRevertResize() throws Exception {
|
||||||
assertTrue(connection.resizeServer(serverId, 2));
|
assertTrue(connection.resizeServer(serverId, 2));
|
||||||
blockUntilServerVerifyResize(serverId);
|
blockUntilServerVerifyResize(serverId);
|
||||||
|
@ -567,7 +570,7 @@ public class CloudServersConnectionLiveTest {
|
||||||
assertEquals(new Integer(1), connection.getServer(serverId).getFlavorId());
|
assertEquals(new Integer(1), connection.getServer(serverId).getFlavorId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||||
public void testConfirmResize() throws Exception {
|
public void testConfirmResize() throws Exception {
|
||||||
assertTrue(connection.resizeServer(serverId2, 2));
|
assertTrue(connection.resizeServer(serverId2, 2));
|
||||||
blockUntilServerVerifyResize(serverId2);
|
blockUntilServerVerifyResize(serverId2);
|
||||||
|
@ -577,7 +580,7 @@ public class CloudServersConnectionLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be last!. do not rely on positional order.
|
// must be last!. do not rely on positional order.
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize",
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize",
|
||||||
"testConfirmResize" })
|
"testConfirmResize" })
|
||||||
void deleteServers() {
|
void deleteServers() {
|
||||||
if (serverId > 0) {
|
if (serverId > 0) {
|
||||||
|
@ -592,7 +595,7 @@ public class CloudServersConnectionLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "deleteServers" })
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "deleteServers" })
|
||||||
void testDeleteSharedIpGroup() {
|
void testDeleteSharedIpGroup() {
|
||||||
if (sharedIpGroupId > 0) {
|
if (sharedIpGroupId > 0) {
|
||||||
connection.deleteSharedIpGroup(sharedIpGroupId);
|
connection.deleteSharedIpGroup(sharedIpGroupId);
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
import org.jclouds.http.functions.ReturnFalseOn404;
|
import org.jclouds.http.functions.ReturnFalseOn404;
|
||||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||||
import org.jclouds.rackspace.Authentication;
|
import org.jclouds.rackspace.Authentication;
|
||||||
|
import org.jclouds.rackspace.CloudServers;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.BackupSchedule;
|
import org.jclouds.rackspace.cloudservers.domain.BackupSchedule;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.DailyBackup;
|
import org.jclouds.rackspace.cloudservers.domain.DailyBackup;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.RebootType;
|
import org.jclouds.rackspace.cloudservers.domain.RebootType;
|
||||||
|
@ -91,21 +92,17 @@ import com.google.inject.Provides;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "cloudservers.CloudServersConnectionTest")
|
@Test(groups = "unit", testName = "cloudservers.CloudServersConnectionTest")
|
||||||
public class CloudServersConnectionTest {
|
public class CloudServersConnectionTest {
|
||||||
|
|
||||||
JaxrsAnnotationProcessor.Factory factory;
|
JaxrsAnnotationProcessor.Factory factory;
|
||||||
|
|
||||||
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}
|
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}
|
||||||
.getClass();
|
.getClass();
|
||||||
|
|
||||||
private static final Class<? extends CreateServerOptions[]> createServerOptionsVarargsClass = new CreateServerOptions[] {}
|
private static final Class<? extends CreateServerOptions[]> createServerOptionsVarargsClass = new CreateServerOptions[] {}
|
||||||
.getClass();
|
.getClass();
|
||||||
|
|
||||||
public void testCreateServer() throws SecurityException, NoSuchMethodException {
|
public void testCreateServer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
||||||
int.class, int.class, createServerOptionsVarargsClass);
|
int.class, int.class, createServerOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1 });
|
||||||
2, 1 });
|
|
||||||
assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod
|
assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod
|
||||||
.getEntity());
|
.getEntity());
|
||||||
validateCreateServer(method, httpMethod);
|
validateCreateServer(method, httpMethod);
|
||||||
|
@ -114,9 +111,9 @@ public class CloudServersConnectionTest {
|
||||||
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
|
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
||||||
int.class, int.class, createServerOptionsVarargsClass);
|
int.class, int.class, createServerOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1,
|
||||||
2, 1, withSharedIpGroup(2) });
|
withSharedIpGroup(2) });
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
|
@ -126,9 +123,9 @@ public class CloudServersConnectionTest {
|
||||||
public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException {
|
public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
||||||
int.class, int.class, createServerOptionsVarargsClass);
|
int.class, int.class, createServerOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1,
|
||||||
2, 1, new CreateServerOptions[] { withFile("/etc/jclouds", "foo".getBytes()) } });
|
new CreateServerOptions[] { withFile("/etc/jclouds", "foo".getBytes()) } });
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
|
@ -138,9 +135,9 @@ public class CloudServersConnectionTest {
|
||||||
public void testCreateServerWithMetadata() throws SecurityException, NoSuchMethodException {
|
public void testCreateServerWithMetadata() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
||||||
int.class, int.class, createServerOptionsVarargsClass);
|
int.class, int.class, createServerOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1,
|
||||||
2, 1, withMetadata(ImmutableMap.of("foo", "bar")) });
|
withMetadata(ImmutableMap.of("foo", "bar")) });
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
|
@ -151,8 +148,8 @@ public class CloudServersConnectionTest {
|
||||||
NoSuchMethodException, UnknownHostException {
|
NoSuchMethodException, UnknownHostException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
|
||||||
int.class, int.class, createServerOptionsVarargsClass);
|
int.class, int.class, createServerOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
|
||||||
"ralphie",
|
"ralphie",
|
||||||
2,
|
2,
|
||||||
1,
|
1,
|
||||||
|
@ -184,8 +181,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testListServers() throws SecurityException, NoSuchMethodException {
|
public void testListServers() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class
|
Method method = CloudServersConnection.class
|
||||||
.getMethod("listServers", listOptionsVarargsClass);
|
.getMethod("listServers", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -201,9 +198,9 @@ public class CloudServersConnectionTest {
|
||||||
public void testListServersOptions() throws SecurityException, NoSuchMethodException {
|
public void testListServersOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class
|
Method method = CloudServersConnection.class
|
||||||
.getMethod("listServers", listOptionsVarargsClass);
|
.getMethod("listServers", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
|
||||||
new Object[] { changesSince(now).maxResults(1).startAt(2) });
|
.maxResults(1).startAt(2) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
||||||
|
@ -218,9 +215,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testListServersDetail() throws SecurityException, NoSuchMethodException {
|
public void testListServersDetail() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class
|
Method method = CloudServersConnection.class
|
||||||
.getMethod("listServers", listOptionsVarargsClass);
|
.getMethod("listServers", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
|
||||||
new Object[] { withDetails() });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/detail");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/detail");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -233,8 +229,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testGetServer() throws SecurityException, NoSuchMethodException {
|
public void testGetServer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("getServer", int.class);
|
Method method = CloudServersConnection.class.getMethod("getServer", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -249,8 +245,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testListFlavors() throws SecurityException, NoSuchMethodException {
|
public void testListFlavors() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class
|
Method method = CloudServersConnection.class
|
||||||
.getMethod("listFlavors", listOptionsVarargsClass);
|
.getMethod("listFlavors", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -264,9 +260,9 @@ public class CloudServersConnectionTest {
|
||||||
public void testListFlavorsOptions() throws SecurityException, NoSuchMethodException {
|
public void testListFlavorsOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class
|
Method method = CloudServersConnection.class
|
||||||
.getMethod("listFlavors", listOptionsVarargsClass);
|
.getMethod("listFlavors", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
|
||||||
new Object[] { changesSince(now).maxResults(1).startAt(2) });
|
.maxResults(1).startAt(2) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
||||||
|
@ -281,9 +277,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testListFlavorsDetail() throws SecurityException, NoSuchMethodException {
|
public void testListFlavorsDetail() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class
|
Method method = CloudServersConnection.class
|
||||||
.getMethod("listFlavors", listOptionsVarargsClass);
|
.getMethod("listFlavors", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
|
||||||
new Object[] { withDetails() });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -297,9 +292,9 @@ public class CloudServersConnectionTest {
|
||||||
public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException {
|
public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class
|
Method method = CloudServersConnection.class
|
||||||
.getMethod("listFlavors", listOptionsVarargsClass);
|
.getMethod("listFlavors", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails()
|
||||||
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
|
.changesSince(now).maxResults(1).startAt(2) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
||||||
|
@ -313,8 +308,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testGetFlavor() throws SecurityException, NoSuchMethodException {
|
public void testGetFlavor() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("getFlavor", int.class);
|
Method method = CloudServersConnection.class.getMethod("getFlavor", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/2");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -328,8 +323,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListImages() throws SecurityException, NoSuchMethodException {
|
public void testListImages() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -342,9 +337,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListImagesDetail() throws SecurityException, NoSuchMethodException {
|
public void testListImagesDetail() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
|
||||||
new Object[] { withDetails() });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -357,9 +351,9 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListImagesOptions() throws SecurityException, NoSuchMethodException {
|
public void testListImagesOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
|
||||||
new Object[] { changesSince(now).maxResults(1).startAt(2) });
|
.maxResults(1).startAt(2) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
||||||
|
@ -373,9 +367,9 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListImagesDetailOptions() throws SecurityException, NoSuchMethodException {
|
public void testListImagesDetailOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails()
|
||||||
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
|
.changesSince(now).maxResults(1).startAt(2) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
||||||
|
@ -389,8 +383,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testGetImage() throws SecurityException, NoSuchMethodException {
|
public void testGetImage() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("getImage", int.class);
|
Method method = CloudServersConnection.class.getMethod("getImage", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/images/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/images/2");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -404,8 +398,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testDeleteServer() throws SecurityException, NoSuchMethodException {
|
public void testDeleteServer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("deleteServer", int.class);
|
Method method = CloudServersConnection.class.getMethod("deleteServer", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
|
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
|
||||||
|
@ -419,8 +413,8 @@ public class CloudServersConnectionTest {
|
||||||
UnknownHostException {
|
UnknownHostException {
|
||||||
Method method = CloudServersConnection.class.getMethod("shareIp", InetAddress.class,
|
Method method = CloudServersConnection.class.getMethod("shareIp", InetAddress.class,
|
||||||
int.class, int.class, boolean.class);
|
int.class, int.class, boolean.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
|
||||||
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
|
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
||||||
|
@ -440,8 +434,8 @@ public class CloudServersConnectionTest {
|
||||||
UnknownHostException {
|
UnknownHostException {
|
||||||
Method method = CloudServersConnection.class.getMethod("shareIp", InetAddress.class,
|
Method method = CloudServersConnection.class.getMethod("shareIp", InetAddress.class,
|
||||||
int.class, int.class, boolean.class);
|
int.class, int.class, boolean.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
|
||||||
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, true });
|
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, true });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
||||||
|
@ -462,8 +456,8 @@ public class CloudServersConnectionTest {
|
||||||
UnknownHostException {
|
UnknownHostException {
|
||||||
Method method = CloudServersConnection.class.getMethod("unshareIp", InetAddress.class,
|
Method method = CloudServersConnection.class.getMethod("unshareIp", InetAddress.class,
|
||||||
int.class);
|
int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
|
||||||
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
|
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
|
||||||
|
@ -477,8 +471,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testReplaceBackupSchedule() throws SecurityException, NoSuchMethodException {
|
public void testReplaceBackupSchedule() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("replaceBackupSchedule", int.class,
|
Method method = CloudServersConnection.class.getMethod("replaceBackupSchedule", int.class,
|
||||||
BackupSchedule.class);
|
BackupSchedule.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2,
|
||||||
new BackupSchedule(WeeklyBackup.MONDAY, DailyBackup.H_0800_1000, true) });
|
new BackupSchedule(WeeklyBackup.MONDAY, DailyBackup.H_0800_1000, true) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
|
||||||
|
@ -498,8 +492,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testDeleteBackupSchedule() throws SecurityException, NoSuchMethodException {
|
public void testDeleteBackupSchedule() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("deleteBackupSchedule", int.class);
|
Method method = CloudServersConnection.class.getMethod("deleteBackupSchedule", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
|
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
|
||||||
|
@ -512,8 +506,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testChangeAdminPass() throws SecurityException, NoSuchMethodException {
|
public void testChangeAdminPass() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("changeAdminPass", int.class,
|
Method method = CloudServersConnection.class.getMethod("changeAdminPass", int.class,
|
||||||
String.class);
|
String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2, "foo" });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, "foo" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
|
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
|
||||||
|
@ -531,8 +525,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testChangeServerName() throws SecurityException, NoSuchMethodException {
|
public void testChangeServerName() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("renameServer", int.class,
|
Method method = CloudServersConnection.class.getMethod("renameServer", int.class,
|
||||||
String.class);
|
String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2, "foo" });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, "foo" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
|
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
|
||||||
|
@ -550,8 +544,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testListSharedIpGroups() throws SecurityException, NoSuchMethodException {
|
public void testListSharedIpGroups() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
||||||
listOptionsVarargsClass);
|
listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -565,9 +559,9 @@ public class CloudServersConnectionTest {
|
||||||
public void testListSharedIpGroupsOptions() throws SecurityException, NoSuchMethodException {
|
public void testListSharedIpGroupsOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
||||||
listOptionsVarargsClass);
|
listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
|
||||||
new Object[] { changesSince(now).maxResults(1).startAt(2) });
|
.maxResults(1).startAt(2) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
||||||
|
@ -582,9 +576,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testListSharedIpGroupsDetail() throws SecurityException, NoSuchMethodException {
|
public void testListSharedIpGroupsDetail() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
||||||
listOptionsVarargsClass);
|
listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
|
||||||
new Object[] { withDetails() });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -599,9 +592,9 @@ public class CloudServersConnectionTest {
|
||||||
NoSuchMethodException {
|
NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
|
||||||
listOptionsVarargsClass);
|
listOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails()
|
||||||
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
|
.changesSince(now).maxResults(1).startAt(2) });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
|
||||||
|
@ -615,8 +608,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testGetSharedIpGroup() throws SecurityException, NoSuchMethodException {
|
public void testGetSharedIpGroup() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("getSharedIpGroup", int.class);
|
Method method = CloudServersConnection.class.getMethod("getSharedIpGroup", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -634,9 +627,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testCreateSharedIpGroup() throws SecurityException, NoSuchMethodException {
|
public void testCreateSharedIpGroup() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
|
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
|
||||||
createSharedIpGroupOptionsVarargsClass);
|
createSharedIpGroupOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie" });
|
||||||
.createRequest(endpoint, method, new Object[] { "ralphie" });
|
|
||||||
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", httpMethod.getEntity());
|
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", httpMethod.getEntity());
|
||||||
validateCreateSharedIpGroup(method, httpMethod);
|
validateCreateSharedIpGroup(method, httpMethod);
|
||||||
}
|
}
|
||||||
|
@ -644,8 +636,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testCreateSharedIpGroupWithIpGroup() throws SecurityException, NoSuchMethodException {
|
public void testCreateSharedIpGroupWithIpGroup() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
|
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
|
||||||
createSharedIpGroupOptionsVarargsClass);
|
createSharedIpGroupOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie",
|
||||||
withServer(2) });
|
withServer(2) });
|
||||||
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}", httpMethod
|
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}", httpMethod
|
||||||
.getEntity());
|
.getEntity());
|
||||||
|
@ -671,8 +663,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testDeleteSharedIpGroup() throws SecurityException, NoSuchMethodException {
|
public void testDeleteSharedIpGroup() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("deleteSharedIpGroup", int.class);
|
Method method = CloudServersConnection.class.getMethod("deleteSharedIpGroup", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
|
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
|
||||||
|
@ -684,8 +676,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListAddresses() throws SecurityException, NoSuchMethodException {
|
public void testListAddresses() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listAddresses", int.class);
|
Method method = CloudServersConnection.class.getMethod("listAddresses", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -697,8 +689,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListPublicAddresses() throws SecurityException, NoSuchMethodException {
|
public void testListPublicAddresses() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listPublicAddresses", int.class);
|
Method method = CloudServersConnection.class.getMethod("listPublicAddresses", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -710,8 +702,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListPrivateAddresses() throws SecurityException, NoSuchMethodException {
|
public void testListPrivateAddresses() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listPrivateAddresses", int.class);
|
Method method = CloudServersConnection.class.getMethod("listPrivateAddresses", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/private");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/private");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -723,8 +715,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testListBackupSchedule() throws SecurityException, NoSuchMethodException {
|
public void testListBackupSchedule() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("listBackupSchedule", int.class);
|
Method method = CloudServersConnection.class.getMethod("listBackupSchedule", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -737,9 +729,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testCreateImageWithIpGroup() throws SecurityException, NoSuchMethodException {
|
public void testCreateImageWithIpGroup() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("createImageFromServer", String.class,
|
Method method = CloudServersConnection.class.getMethod("createImageFromServer", String.class,
|
||||||
int.class);
|
int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2 });
|
||||||
2 });
|
|
||||||
assertEquals("{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", httpMethod.getEntity());
|
assertEquals("{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", httpMethod.getEntity());
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
|
||||||
|
@ -762,8 +753,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testRebuildServer() throws SecurityException, NoSuchMethodException {
|
public void testRebuildServer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("rebuildServer", int.class,
|
Method method = CloudServersConnection.class.getMethod("rebuildServer", int.class,
|
||||||
rebuildServerOptionsVarargsClass);
|
rebuildServerOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 3 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 3 });
|
||||||
assertEquals("{\"rebuild\":{}}", httpMethod.getEntity());
|
assertEquals("{\"rebuild\":{}}", httpMethod.getEntity());
|
||||||
validateRebuildServer(method, httpMethod);
|
validateRebuildServer(method, httpMethod);
|
||||||
}
|
}
|
||||||
|
@ -771,9 +762,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testRebuildServerWithImage() throws SecurityException, NoSuchMethodException {
|
public void testRebuildServerWithImage() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("rebuildServer", int.class,
|
Method method = CloudServersConnection.class.getMethod("rebuildServer", int.class,
|
||||||
rebuildServerOptionsVarargsClass);
|
rebuildServerOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 3,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 3, withImage(2) });
|
||||||
withImage(2) });
|
|
||||||
assertEquals("{\"rebuild\":{\"imageId\":2}}", httpMethod.getEntity());
|
assertEquals("{\"rebuild\":{\"imageId\":2}}", httpMethod.getEntity());
|
||||||
validateRebuildServer(method, httpMethod);
|
validateRebuildServer(method, httpMethod);
|
||||||
}
|
}
|
||||||
|
@ -798,9 +788,8 @@ public class CloudServersConnectionTest {
|
||||||
public void testReboot() throws SecurityException, NoSuchMethodException {
|
public void testReboot() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("rebootServer", int.class,
|
Method method = CloudServersConnection.class.getMethod("rebootServer", int.class,
|
||||||
RebootType.class);
|
RebootType.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2,
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, RebootType.HARD });
|
||||||
RebootType.HARD });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
||||||
|
@ -817,8 +806,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testResize() throws SecurityException, NoSuchMethodException {
|
public void testResize() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("resizeServer", int.class, int.class);
|
Method method = CloudServersConnection.class.getMethod("resizeServer", int.class, int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2, 3 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, 3 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
||||||
|
@ -835,8 +824,8 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testConfirmResize() throws SecurityException, NoSuchMethodException {
|
public void testConfirmResize() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("confirmResizeServer", int.class);
|
Method method = CloudServersConnection.class.getMethod("confirmResizeServer", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
||||||
|
@ -853,8 +842,7 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
public void testRevertResize() throws SecurityException, NoSuchMethodException {
|
public void testRevertResize() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = CloudServersConnection.class.getMethod("revertResizeServer", int.class);
|
Method method = CloudServersConnection.class.getMethod("revertResizeServer", int.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
|
||||||
|
@ -873,10 +861,12 @@ public class CloudServersConnectionTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
factory = Guice.createInjector(new AbstractModule() {
|
factory = Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
|
bind(URI.class).annotatedWith(CloudServers.class).toInstance(
|
||||||
|
URI.create("http://localhost:8080"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -890,5 +880,4 @@ public class CloudServersConnectionTest {
|
||||||
JaxrsAnnotationProcessor.Factory.class);
|
JaxrsAnnotationProcessor.Factory.class);
|
||||||
processor = factory.create(CloudServersConnection.class);
|
processor = factory.create(CloudServersConnection.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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 org.jclouds.rackspace.cloudservers.domain;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code CreateImageBinder}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "cloudservers.CreateImageBinderTest")
|
||||||
|
public class ServerTest {
|
||||||
|
public void testStatusDoesntAffectEquals() {
|
||||||
|
Server server1 = new Server(1, "hello");
|
||||||
|
server1.setStatus(ServerStatus.ACTIVE);
|
||||||
|
Server server2 = new Server(1, "hello");
|
||||||
|
server2.setStatus(ServerStatus.BUILD);
|
||||||
|
assertEquals(server1, server2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testProgressDoesntAffectEquals() {
|
||||||
|
Server server1 = new Server(1, "hello");
|
||||||
|
server1.setProgress(1);
|
||||||
|
Server server2 = new Server(1, "hello");
|
||||||
|
server2.setProgress(2);
|
||||||
|
assertEquals(server1, server2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ import javax.inject.Qualifier;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
@Qualifier
|
@Qualifier
|
||||||
public @interface Authentication {
|
public @interface Authentication {
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ import javax.inject.Qualifier;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
@Qualifier
|
@Qualifier
|
||||||
public @interface Storage {
|
public @interface CloudFiles {
|
||||||
|
|
||||||
}
|
}
|
|
@ -38,8 +38,8 @@ import javax.inject.Qualifier;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
@Qualifier
|
@Qualifier
|
||||||
public @interface CDN {
|
public @interface CloudFilesCDN {
|
||||||
|
|
||||||
}
|
}
|
|
@ -38,8 +38,8 @@ import javax.inject.Qualifier;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
@Qualifier
|
@Qualifier
|
||||||
public @interface Server {
|
public @interface CloudServers {
|
||||||
|
|
||||||
}
|
}
|
|
@ -31,6 +31,7 @@ import javax.ws.rs.Path;
|
||||||
|
|
||||||
import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders;
|
import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders;
|
||||||
import org.jclouds.rackspace.reference.RackspaceHeaders;
|
import org.jclouds.rackspace.reference.RackspaceHeaders;
|
||||||
|
import org.jclouds.rest.Endpoint;
|
||||||
import org.jclouds.rest.ResponseParser;
|
import org.jclouds.rest.ResponseParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,17 +41,17 @@ import org.jclouds.rest.ResponseParser;
|
||||||
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@Endpoint(Authentication.class)
|
||||||
public interface RackspaceAuthentication {
|
public interface RackspaceAuthentication {
|
||||||
|
|
||||||
public interface AuthenticationResponse {
|
public interface AuthenticationResponse {
|
||||||
@Storage
|
@CloudFiles
|
||||||
URI getStorageUrl();
|
URI getStorageUrl();
|
||||||
|
|
||||||
@CDN
|
@CloudFilesCDN
|
||||||
URI getCDNManagementUrl();
|
URI getCDNManagementUrl();
|
||||||
|
|
||||||
@Server
|
@CloudServers
|
||||||
URI getServerManagementUrl();
|
URI getServerManagementUrl();
|
||||||
|
|
||||||
@Authentication
|
@Authentication
|
||||||
|
|
|
@ -34,10 +34,10 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rackspace.Authentication;
|
import org.jclouds.rackspace.Authentication;
|
||||||
import org.jclouds.rackspace.CDN;
|
import org.jclouds.rackspace.CloudFilesCDN;
|
||||||
import org.jclouds.rackspace.RackspaceAuthentication;
|
import org.jclouds.rackspace.RackspaceAuthentication;
|
||||||
import org.jclouds.rackspace.Server;
|
import org.jclouds.rackspace.CloudServers;
|
||||||
import org.jclouds.rackspace.Storage;
|
import org.jclouds.rackspace.CloudFiles;
|
||||||
import org.jclouds.rackspace.RackspaceAuthentication.AuthenticationResponse;
|
import org.jclouds.rackspace.RackspaceAuthentication.AuthenticationResponse;
|
||||||
import org.jclouds.rest.RestClientFactory;
|
import org.jclouds.rest.RestClientFactory;
|
||||||
import org.jclouds.rest.config.JaxrsModule;
|
import org.jclouds.rest.config.JaxrsModule;
|
||||||
|
@ -69,39 +69,35 @@ public class RestRackspaceAuthenticationModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected AuthenticationResponse provideAuthenticationResponse(
|
protected AuthenticationResponse provideAuthenticationResponse(RestClientFactory factory,
|
||||||
@Authentication URI authenticationUri, RestClientFactory factory,
|
|
||||||
@Named(PROPERTY_RACKSPACE_USER) String user, @Named(PROPERTY_RACKSPACE_KEY) String key) {
|
@Named(PROPERTY_RACKSPACE_USER) String user, @Named(PROPERTY_RACKSPACE_KEY) String key) {
|
||||||
return factory.create(authenticationUri, RackspaceAuthentication.class).authenticate(user,
|
return factory.create(RackspaceAuthentication.class).authenticate(user, key);
|
||||||
key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Authentication
|
@Authentication
|
||||||
protected String provideAuthenticationToken(@Authentication URI authenticationUri,
|
protected String provideAuthenticationToken(RestClientFactory factory,
|
||||||
RestClientFactory factory, @Named(PROPERTY_RACKSPACE_USER) String user,
|
@Named(PROPERTY_RACKSPACE_USER) String user, @Named(PROPERTY_RACKSPACE_KEY) String key) {
|
||||||
@Named(PROPERTY_RACKSPACE_KEY) String key) {
|
return factory.create(RackspaceAuthentication.class).authenticate(user, key).getAuthToken();
|
||||||
return factory.create(authenticationUri, RackspaceAuthentication.class).authenticate(user,
|
|
||||||
key).getAuthToken();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Storage
|
@CloudFiles
|
||||||
protected URI provideStorageUrl(AuthenticationResponse response) {
|
protected URI provideStorageUrl(AuthenticationResponse response) {
|
||||||
return response.getStorageUrl();
|
return response.getStorageUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Server
|
@CloudServers
|
||||||
protected URI provideServerUrl(AuthenticationResponse response) {
|
protected URI provideServerUrl(AuthenticationResponse response) {
|
||||||
return response.getServerManagementUrl();
|
return response.getServerManagementUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@CDN
|
@CloudFilesCDN
|
||||||
protected URI provideCDNUrl(AuthenticationResponse response) {
|
protected URI provideCDNUrl(AuthenticationResponse response) {
|
||||||
return response.getCDNManagementUrl();
|
return response.getCDNManagementUrl();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ import static org.testng.Assert.fail;
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
import java.lang.reflect.UndeclaredThrowableException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
|
@ -44,7 +46,7 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import javax.inject.Singleton;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
||||||
|
@ -54,8 +56,8 @@ import javax.inject.Singleton;
|
||||||
@Test(groups = "live", testName = "rackspace.RackspaceAuthenticationLiveTest")
|
@Test(groups = "live", testName = "rackspace.RackspaceAuthenticationLiveTest")
|
||||||
public class RackspaceAuthenticationLiveTest {
|
public class RackspaceAuthenticationLiveTest {
|
||||||
|
|
||||||
String account = System.getProperty("jclouds.test.user");
|
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||||
String key = System.getProperty("jclouds.test.key");
|
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||||
|
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
|
|
||||||
|
@ -89,6 +91,8 @@ public class RackspaceAuthenticationLiveTest {
|
||||||
new AbstractModule() {
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
bind(URI.class).annotatedWith(Authentication.class).toInstance(
|
||||||
|
URI.create("https://api.mosso.com"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -96,8 +100,7 @@ public class RackspaceAuthenticationLiveTest {
|
||||||
@Singleton
|
@Singleton
|
||||||
protected RackspaceAuthentication provideCloudFilesAuthentication(
|
protected RackspaceAuthentication provideCloudFilesAuthentication(
|
||||||
RestClientFactory factory) {
|
RestClientFactory factory) {
|
||||||
return factory.create(URI.create("https://api.mosso.com"),
|
return factory.create(RackspaceAuthentication.class);
|
||||||
RackspaceAuthentication.class);
|
|
||||||
}
|
}
|
||||||
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
||||||
new JavaUrlHttpCommandExecutorServiceModule());
|
new JavaUrlHttpCommandExecutorServiceModule());
|
||||||
|
|
|
@ -58,9 +58,8 @@ public class RackspaceAuthenticationTest {
|
||||||
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
|
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = RackspaceAuthentication.class.getMethod("authenticate", String.class,
|
Method method = RackspaceAuthentication.class.getMethod("authenticate", String.class,
|
||||||
String.class);
|
String.class);
|
||||||
URI endpoint = URI.create("http://localhost");
|
HttpRequest httpMethod = factory.create(RackspaceAuthentication.class).createRequest(method,
|
||||||
HttpRequest httpMethod = factory.create(RackspaceAuthentication.class).createRequest(
|
new Object[] { "foo", "bar" });
|
||||||
endpoint, method, new Object[] { "foo", "bar" });
|
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/auth");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/auth");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
|
@ -77,10 +76,12 @@ public class RackspaceAuthenticationTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
factory = Guice.createInjector(new AbstractModule() {
|
factory = Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
|
bind(URI.class).annotatedWith(Authentication.class).toInstance(
|
||||||
|
URI.create("http://localhost:8080"));
|
||||||
}
|
}
|
||||||
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
|
||||||
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
|
||||||
|
|
Loading…
Reference in New Issue