allowed overriding of rest.properties during testing

This commit is contained in:
Adrian Cole 2011-03-05 16:50:48 -05:00
parent ad0acb56fa
commit 7eef59db02
5 changed files with 27 additions and 17 deletions

View File

@ -52,8 +52,8 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory().createContext( RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory(setupRestProperties())
provider, identity, credential).getProviderSpecificContext(); .createContext(provider, identity, credential).getProviderSpecificContext();
} }
@Override @Override
@ -64,8 +64,8 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getId()); NodeMetadata allData = client.getNodeMetadata(node.getId());
System.out.println(allData.getHardware()); System.out.println(allData.getHardware());
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory().createContext( RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory(
provider, identity, credential).getProviderSpecificContext(); setupRestProperties()).createContext(provider, identity, credential).getProviderSpecificContext();
VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName()); VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName());
assertEquals(vApp.getName(), allData.getName()); assertEquals(vApp.getName(), allData.getName());
} }

View File

@ -30,6 +30,7 @@ import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
@ -95,13 +96,13 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
VDC response = connection.getVDC(vdc.getHref()); VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType resource : response.getAvailableNetworks().values()) { for (ReferenceType resource : response.getAvailableNetworks().values()) {
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
try{ try {
OrgNetwork item = connection.getNetwork(resource.getHref()); OrgNetwork item = connection.getNetwork(resource.getHref());
assertNotNull(item); assertNotNull(item);
} catch (AuthorizationException e){ } catch (AuthorizationException e) {
} }
} }
} }
} }
} }
@ -206,11 +207,15 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
return overrides; return overrides;
} }
protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
}
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider, context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
connection = context.getApi(); connection = context.getApi();

View File

@ -161,12 +161,12 @@ public abstract class BaseComputeServiceLiveTest {
if (context != null) if (context != null)
context.close(); context.close();
Properties props = setupProperties(); Properties props = setupProperties();
context = new ComputeServiceContextFactory(getRestProperties()).createContext(provider, ImmutableSet.of( context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, ImmutableSet.of(
new Log4JLoggingModule(), getSshModule()), props); new Log4JLoggingModule(), getSshModule()), props);
client = context.getComputeService(); client = context.getComputeService();
} }
protected Properties getRestProperties() { protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties"); return RestContextFactory.getPropertiesFromResource("/rest.properties");
} }
@ -182,7 +182,7 @@ public abstract class BaseComputeServiceLiveTest {
public void testCorrectAuthException() throws Exception { public void testCorrectAuthException() throws Exception {
ComputeServiceContext context = null; ComputeServiceContext context = null;
try { try {
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, "MOMMA", "MIA", ImmutableSet
.<Module> of(new Log4JLoggingModule())); .<Module> of(new Log4JLoggingModule()));
context.getComputeService().listNodes(); context.getComputeService().listNodes();
} catch (AuthorizationException e) { } catch (AuthorizationException e) {

View File

@ -44,6 +44,7 @@ import org.jclouds.domain.LocationScope;
import org.jclouds.json.Json; import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule; import org.jclouds.json.config.GsonModule;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContextFactory;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@ -91,10 +92,14 @@ public abstract class BaseTemplateBuilderLiveTest {
return overrides; return overrides;
} }
protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
}
@BeforeClass @BeforeClass
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
setupCredentials(); setupCredentials();
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), setupProperties()); .<Module> of(new Log4JLoggingModule()), setupProperties());
} }

View File

@ -24,7 +24,7 @@ public class ServerManagerComputeServiceLiveTest extends BaseComputeServiceLiveT
} }
@Override @Override
protected Properties getRestProperties() { protected Properties setupRestProperties() {
Properties restProperties = new Properties(); Properties restProperties = new Properties();
restProperties.setProperty("servermanager.contextbuilder", restProperties.setProperty("servermanager.contextbuilder",
ServerManagerComputeServiceContextBuilder.class.getName()); ServerManagerComputeServiceContextBuilder.class.getName());