mirror of https://github.com/apache/jclouds.git
updated sandbox services so that they compile
This commit is contained in:
parent
36e6ca787d
commit
ba12d4add5
|
@ -31,23 +31,26 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.collect.Memoized;
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.callables.RunScriptOnNode;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
|
import org.jclouds.compute.internal.PersistNodeCredentials;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
|
||||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.scriptbuilder.functions.InitAdminAccess;
|
||||||
import org.libvirt.Connect;
|
import org.libvirt.Connect;
|
||||||
import org.libvirt.StorageVol;
|
import org.libvirt.StorageVol;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
@ -72,22 +75,23 @@ public class LibvirtComputeService extends BaseComputeService {
|
||||||
@Memoized Supplier<Set<? extends Image>> images,
|
@Memoized Supplier<Set<? extends Image>> images,
|
||||||
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
|
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||||
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
|
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
|
Provider<TemplateOptions> templateOptionsProvider,
|
||||||
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
|
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
|
||||||
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
|
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
|
||||||
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended,
|
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, Timeouts timeouts,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Connect client) {
|
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
|
||||||
|
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Connect client) {
|
||||||
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getNodeMetadataStrategy,
|
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getNodeMetadataStrategy,
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
|
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
|
||||||
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
||||||
nodeSuspended, initScriptRunnerFactory, timeouts, executor);
|
nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials,
|
||||||
|
timeouts, executor);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class LibvirtComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Properties getRestProperties() {
|
protected Properties setupRestProperties() {
|
||||||
Properties restProperties = new Properties();
|
Properties restProperties = new Properties();
|
||||||
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
|
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
|
||||||
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
|
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
|
||||||
|
|
|
@ -176,7 +176,6 @@ public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
|
||||||
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
|
||||||
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,41 +20,37 @@ package org.jclouds.nirvanix.sdn.filters;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
|
|
||||||
import org.jclouds.concurrent.MoreExecutors;
|
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
|
||||||
import org.jclouds.date.DateService;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
|
||||||
import org.jclouds.logging.Logger.LoggerFactory;
|
import org.jclouds.nirvanix.sdn.SDNClient;
|
||||||
import org.jclouds.nirvanix.sdn.SDNPropertiesBuilder;
|
|
||||||
import org.jclouds.nirvanix.sdn.SessionToken;
|
import org.jclouds.nirvanix.sdn.SessionToken;
|
||||||
|
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
|
||||||
|
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
||||||
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
import org.jclouds.rest.RestClientTest;
|
||||||
|
import org.jclouds.rest.RestContextFactory;
|
||||||
|
import org.jclouds.rest.RestContextSpec;
|
||||||
import org.jclouds.rest.annotations.EndpointParam;
|
import org.jclouds.rest.annotations.EndpointParam;
|
||||||
import org.jclouds.rest.config.RestModule;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Guice;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "sdn.AddSessionTokenToRequestTest")
|
@Test(groups = "unit", testName = "AddSessionTokenToRequestTest")
|
||||||
public class AddSessionTokenToRequestTest {
|
public class AddSessionTokenToRequestTest extends RestClientTest<SDNAsyncClient> {
|
||||||
|
|
||||||
private Injector injector;
|
|
||||||
private AddSessionTokenToRequest filter;
|
|
||||||
|
|
||||||
private static interface TestService {
|
private static interface TestService {
|
||||||
@POST
|
@POST
|
||||||
|
@ -65,15 +61,15 @@ public class AddSessionTokenToRequestTest {
|
||||||
public Object[][] dataProvider() throws SecurityException, NoSuchMethodException {
|
public Object[][] dataProvider() throws SecurityException, NoSuchMethodException {
|
||||||
|
|
||||||
RestAnnotationProcessor<TestService> factory = injector.getInstance(Key
|
RestAnnotationProcessor<TestService> factory = injector.getInstance(Key
|
||||||
.get(new TypeLiteral<RestAnnotationProcessor<TestService>>() {
|
.get(new TypeLiteral<RestAnnotationProcessor<TestService>>() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Method method = TestService.class.getMethod("foo", URI.class);
|
Method method = TestService.class.getMethod("foo", URI.class);
|
||||||
return new Object[][] { { factory.createRequest(method, new Object[] { URI.create("https://host:443") }) },
|
return new Object[][] { { factory.createRequest(method, new Object[] { URI.create("https://host:443") }) },
|
||||||
{ factory.createRequest(method, new Object[] { URI.create("https://host/path") }) },
|
{ factory.createRequest(method, new Object[] { URI.create("https://host/path") }) },
|
||||||
{ factory.createRequest(method, new Object[] { URI.create("https://host/?query") })
|
{ factory.createRequest(method, new Object[] { URI.create("https://host/?query") })
|
||||||
|
|
||||||
} };
|
} };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "dataProvider")
|
@Test(dataProvider = "dataProvider")
|
||||||
|
@ -82,7 +78,7 @@ public class AddSessionTokenToRequestTest {
|
||||||
String query = request.getEndpoint().getQuery();
|
String query = request.getEndpoint().getQuery();
|
||||||
request = filter.filter(request);
|
request = filter.filter(request);
|
||||||
assertEquals(request.getEndpoint().getQuery(), query == null ? "sessionToken=" + token : query + "&sessionToken="
|
assertEquals(request.getEndpoint().getQuery(), query == null ? "sessionToken=" + token : query + "&sessionToken="
|
||||||
+ token);
|
+ token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,34 +89,44 @@ public class AddSessionTokenToRequestTest {
|
||||||
assert token.equals(filter.getSessionToken());
|
assert token.equals(filter.getSessionToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* before class, as we need to ensure that the filter is threadsafe.
|
protected void checkFilters(HttpRequest request) {
|
||||||
*
|
}
|
||||||
*/
|
|
||||||
|
private AddSessionTokenToRequest filter;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
protected void createFilter() {
|
@Override
|
||||||
injector = Guice.createInjector(new RestModule(), new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(),
|
protected void setupFactory() throws IOException {
|
||||||
MoreExecutors.sameThreadExecutor()), new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() {
|
super.setupFactory();
|
||||||
|
|
||||||
protected void configure() {
|
|
||||||
bind(DateService.class);
|
|
||||||
Names.bindProperties(this.binder(),
|
|
||||||
new SDNPropertiesBuilder(new Properties()).credentials("appkey/appname/username", "password").build());
|
|
||||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
|
||||||
public Logger getLogger(String category) {
|
|
||||||
return Logger.NULL;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@SessionToken
|
|
||||||
@Provides
|
|
||||||
String authTokenProvider() {
|
|
||||||
return System.currentTimeMillis() + "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
filter = injector.getInstance(AddSessionTokenToRequest.class);
|
filter = injector.getInstance(AddSessionTokenToRequest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Module createModule() {
|
||||||
|
return new TestSDNRestClientModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresHttp
|
||||||
|
@ConfiguresRestClient
|
||||||
|
static class TestSDNRestClientModule extends SDNRestClientModule {
|
||||||
|
@Override
|
||||||
|
public void configure() {
|
||||||
|
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
||||||
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
|
||||||
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
|
||||||
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RestContextSpec<SDNClient, SDNAsyncClient> createContextSpec() {
|
||||||
|
return new RestContextFactory().createContextSpec("sdn", "user", "password", new Properties());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -18,99 +18,113 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.nirvanix.sdn.filters;
|
package org.jclouds.nirvanix.sdn.filters;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.easymock.classextension.EasyMock.createMock;
|
|
||||||
import static org.easymock.classextension.EasyMock.replay;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
|
|
||||||
import org.jclouds.concurrent.MoreExecutors;
|
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
|
||||||
import org.jclouds.logging.Logger.LoggerFactory;
|
import org.jclouds.nirvanix.sdn.SDNClient;
|
||||||
import org.jclouds.nirvanix.sdn.SDNPropertiesBuilder;
|
import org.jclouds.nirvanix.sdn.SessionToken;
|
||||||
import org.jclouds.nirvanix.sdn.config.SDNAuthRestClientModule;
|
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
|
||||||
|
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
||||||
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
import org.jclouds.rest.RestClientTest;
|
||||||
|
import org.jclouds.rest.RestContextFactory;
|
||||||
|
import org.jclouds.rest.RestContextSpec;
|
||||||
import org.jclouds.rest.annotations.EndpointParam;
|
import org.jclouds.rest.annotations.EndpointParam;
|
||||||
import org.jclouds.rest.config.RestModule;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
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.common.base.Throwables;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
@Test(groups = "unit", sequential = true, testName = "sdn.InsertUserContextIntoPathTest")
|
@Test(groups = "unit", singleThreaded = true, testName = "sdn.InsertUserContextIntoPathTest")
|
||||||
// sequential as easymock isn't threadsafe
|
// sequential as easymock isn't threadsafe
|
||||||
public class InsertUserContextIntoPathTest {
|
public class InsertUserContextIntoPathTest extends RestClientTest<TestService> {
|
||||||
|
|
||||||
private Injector injector;
|
|
||||||
private InsertUserContextIntoPath filter;
|
|
||||||
private RestAnnotationProcessor<TestService> factory;
|
|
||||||
private Method method;
|
private Method method;
|
||||||
|
|
||||||
private static interface TestService {
|
|
||||||
@POST
|
|
||||||
public void foo(@EndpointParam URI endpoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testRequestInvalid() {
|
public void testRequestInvalid() {
|
||||||
HttpRequest request = factory.createRequest(method, URI.create("https://host/path"));
|
HttpRequest request = processor.createRequest(method, URI.create("https://host/path"));
|
||||||
request = filter.filter(request);
|
request = filter.filter(request);
|
||||||
request = filter.filter(request);
|
request = filter.filter(request);
|
||||||
assertEquals(request.getEndpoint().getPath(), "/token/appname/username/path");
|
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
|
||||||
assertEquals(request.getEndpoint().getHost(), "host");
|
assertEquals(request.getEndpoint().getHost(), "host");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRequestNoSession() {
|
public void testRequestNoSession() {
|
||||||
HttpRequest request = factory.createRequest(method, URI.create("https://host/path"));
|
HttpRequest request = processor.createRequest(method, URI.create("https://host/path"));
|
||||||
request = filter.filter(request);
|
request = filter.filter(request);
|
||||||
assertEquals(request.getEndpoint().getPath(), "/token/appname/username/path");
|
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
|
||||||
assertEquals(request.getEndpoint().getHost(), "host");
|
assertEquals(request.getEndpoint().getHost(), "host");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRequestAlreadyHasSession() {
|
public void testRequestAlreadyHasSession() {
|
||||||
HttpRequest request = factory.createRequest(method, URI.create("https://host/token/appname/username/path"));
|
HttpRequest request = processor.createRequest(method, URI.create("https://host/sessiontoken/appname/username/path"));
|
||||||
request = filter.filter(request);
|
request = filter.filter(request);
|
||||||
assertEquals(request.getEndpoint().getPath(), "/token/appname/username/path");
|
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
|
||||||
assertEquals(request.getEndpoint().getHost(), "host");
|
assertEquals(request.getEndpoint().getHost(), "host");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private InsertUserContextIntoPath filter;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
protected void createFilter() throws SecurityException, NoSuchMethodException {
|
@Override
|
||||||
injector = Guice.createInjector(new RestModule(), new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(),
|
protected void setupFactory() throws IOException {
|
||||||
MoreExecutors.sameThreadExecutor()), new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() {
|
super.setupFactory();
|
||||||
|
|
||||||
protected void configure() {
|
|
||||||
install(new SDNAuthRestClientModule());
|
|
||||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
|
||||||
public Logger getLogger(String category) {
|
|
||||||
return Logger.NULL;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
AddSessionTokenToRequest sessionManager = createMock(AddSessionTokenToRequest.class);
|
|
||||||
expect(sessionManager.getSessionToken()).andReturn("token").anyTimes();
|
|
||||||
replay(sessionManager);
|
|
||||||
bind(AddSessionTokenToRequest.class).toInstance(sessionManager);
|
|
||||||
Names.bindProperties(this.binder(),
|
|
||||||
new SDNPropertiesBuilder(new Properties()).credentials("appkey/appname/username", "password").build());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
filter = injector.getInstance(InsertUserContextIntoPath.class);
|
filter = injector.getInstance(InsertUserContextIntoPath.class);
|
||||||
factory = injector.getInstance(Key.get(new TypeLiteral<RestAnnotationProcessor<TestService>>() {
|
try {
|
||||||
}));
|
method = TestService.class.getMethod("foo", URI.class);
|
||||||
method = TestService.class.getMethod("foo", URI.class);
|
} catch (Exception e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TypeLiteral<RestAnnotationProcessor<TestService>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<TestService>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Module createModule() {
|
||||||
|
return new TestSDNRestClientModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresHttp
|
||||||
|
@ConfiguresRestClient
|
||||||
|
static class TestSDNRestClientModule extends SDNRestClientModule {
|
||||||
|
@Override
|
||||||
|
public void configure() {
|
||||||
|
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
||||||
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
|
||||||
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
|
||||||
|
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RestContextSpec<SDNClient, SDNAsyncClient> createContextSpec() {
|
||||||
|
return new RestContextFactory().createContextSpec("sdn", "user", "password", new Properties());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkFilters(HttpRequest request) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TestService {
|
||||||
|
@POST
|
||||||
|
public void foo(@EndpointParam URI endpoint);
|
||||||
}
|
}
|
|
@ -24,7 +24,10 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.json.Json;
|
||||||
import org.jclouds.rimuhosting.miro.data.CreateOptions;
|
import org.jclouds.rimuhosting.miro.data.CreateOptions;
|
||||||
import org.jclouds.rimuhosting.miro.data.NewServerData;
|
import org.jclouds.rimuhosting.miro.data.NewServerData;
|
||||||
import org.jclouds.rimuhosting.miro.domain.MetaData;
|
import org.jclouds.rimuhosting.miro.domain.MetaData;
|
||||||
|
@ -33,6 +36,10 @@ import org.jclouds.rimuhosting.miro.domain.MetaData;
|
||||||
* @author Ivan Meredith
|
* @author Ivan Meredith
|
||||||
*/
|
*/
|
||||||
public class CreateServerOptions extends RimuHostingJsonBinder {
|
public class CreateServerOptions extends RimuHostingJsonBinder {
|
||||||
|
@Inject
|
||||||
|
public CreateServerOptions(Json jsonBinder) {
|
||||||
|
super(jsonBinder);
|
||||||
|
}
|
||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
private List<MetaData> metaData = new ArrayList<MetaData>();
|
private List<MetaData> metaData = new ArrayList<MetaData>();
|
||||||
|
|
|
@ -21,7 +21,10 @@ package org.jclouds.rimuhosting.miro.binder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.json.Json;
|
||||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,6 +35,11 @@ import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
* @author Ivan Meredith
|
* @author Ivan Meredith
|
||||||
*/
|
*/
|
||||||
public class RimuHostingJsonBinder extends BindToJsonPayload {
|
public class RimuHostingJsonBinder extends BindToJsonPayload {
|
||||||
|
@Inject
|
||||||
|
public RimuHostingJsonBinder(Json jsonBinder) {
|
||||||
|
super(jsonBinder);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
|
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
|
||||||
return bindToRequest(request, (Object) postParams);
|
return bindToRequest(request, (Object) postParams);
|
||||||
|
|
|
@ -20,7 +20,10 @@ package org.jclouds.rimuhosting.miro.binder;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.json.Json;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
@ -32,6 +35,11 @@ import com.google.common.collect.ImmutableMap;
|
||||||
* @author Ivan Meredith
|
* @author Ivan Meredith
|
||||||
*/
|
*/
|
||||||
public class RimuHostingRebootJsonBinder extends RimuHostingJsonBinder {
|
public class RimuHostingRebootJsonBinder extends RimuHostingJsonBinder {
|
||||||
|
@Inject
|
||||||
|
public RimuHostingRebootJsonBinder(Json jsonBinder) {
|
||||||
|
super(jsonBinder);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
|
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
|
||||||
return super.bindToRequest(request, (Object) ImmutableMap.of("running_state", "RESTARTING"));
|
return super.bindToRequest(request, (Object) ImmutableMap.of("running_state", "RESTARTING"));
|
||||||
|
|
Loading…
Reference in New Issue