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 {
@SuppressWarnings("unused")
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory().createContext(
provider, identity, credential).getProviderSpecificContext();
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory(setupRestProperties())
.createContext(provider, identity, credential).getProviderSpecificContext();
}
@Override
@ -64,8 +64,8 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getId());
System.out.println(allData.getHardware());
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory().createContext(
provider, identity, credential).getProviderSpecificContext();
RestContext<VCloudClient, VCloudAsyncClient> tmContext = new ComputeServiceContextFactory(
setupRestProperties()).createContext(provider, identity, credential).getProviderSpecificContext();
VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, 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.rest.AuthorizationException;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
@ -95,13 +96,13 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType resource : response.getAvailableNetworks().values()) {
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
try{
OrgNetwork item = connection.getNetwork(resource.getHref());
assertNotNull(item);
} catch (AuthorizationException e){
try {
OrgNetwork item = connection.getNetwork(resource.getHref());
assertNotNull(item);
} catch (AuthorizationException e) {
}
}
}
}
}
}
}
@ -206,11 +207,15 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
return overrides;
}
protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider,
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
connection = context.getApi();

View File

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

View File

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

View File

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