Large squashed commit with various changes:

- Setup new test properties for catalog names and various ids as injectable
- Make retryable TaskSuccess predicate injectable
- Mark test classes as "user"
- Various tidyup and code fixes as and when required
This commit is contained in:
Andrew Donald Kennedy 2012-02-21 16:07:31 +00:00
parent 29f26df137
commit 34459605fc
25 changed files with 175 additions and 164 deletions

View File

@ -29,7 +29,6 @@ import com.google.common.base.Splitter;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
*
* @author Jason King * @author Jason King
*/ */
public abstract class BaseVersionedServiceLiveTest extends BaseRestClientLiveTest { public abstract class BaseVersionedServiceLiveTest extends BaseRestClientLiveTest {
@ -48,16 +47,18 @@ public abstract class BaseVersionedServiceLiveTest extends BaseRestClientLiveTes
overrides.setProperty(provider + ".image.login-user", loginUser); overrides.setProperty(provider + ".image.login-user", loginUser);
if (authenticateSudo != null) if (authenticateSudo != null)
overrides.setProperty(provider + ".image.authenticate-sudo", authenticateSudo); overrides.setProperty(provider + ".image.authenticate-sudo", authenticateSudo);
return overrides; return overrides;
} }
@Override
@BeforeClass @BeforeClass
protected void setupCredentials() { protected void setupCredentials() {
super.setupCredentials(); super.setupCredentials();
imageId = System.getProperty("test." + provider + ".image-id"); imageId = System.getProperty("test." + provider + ".image-id");
loginUser = System.getProperty("test." + provider + ".image.login-user"); loginUser = System.getProperty("test." + provider + ".image.login-user");
authenticateSudo = System.getProperty("test." + provider + ".image.authenticate-sudo"); authenticateSudo = System.getProperty("test." + provider + ".image.authenticate-sudo");
if (loginUser != null){ if (loginUser != null){
Iterable<String> userPass = Splitter.on(':').split(loginUser); Iterable<String> userPass = Splitter.on(':').split(loginUser);
Builder loginCredentialsBuilder = LoginCredentials.builder(); Builder loginCredentialsBuilder = LoginCredentials.builder();

View File

@ -40,7 +40,6 @@ public abstract class BaseRestClientLiveTest {
protected String apiVersion; protected String apiVersion;
protected String buildVersion; protected String buildVersion;
protected Properties setupRestProperties() { protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties"); return RestContextFactory.getPropertiesFromResource("/rest.properties");
} }

View File

@ -42,6 +42,11 @@
<test.vcloud-director.image-id></test.vcloud-director.image-id> <test.vcloud-director.image-id></test.vcloud-director.image-id>
<test.vcloud-director.image.login-user></test.vcloud-director.image.login-user> <test.vcloud-director.image.login-user></test.vcloud-director.image.login-user>
<test.vcloud-director.image.authenticate-sudo></test.vcloud-director.image.authenticate-sudo> <test.vcloud-director.image.authenticate-sudo></test.vcloud-director.image.authenticate-sudo>
<test.vcloud-director.catalog-name>Public</test.vcloud-director.catalog-name>
<test.vcloud-director.media-id></test.vcloud-director.media-id>
<test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id>
<test.vcloud-director.network-id></test.vcloud-director.network-id>
<test.vcloud-director.vdc-d></test.vcloud-director.vdc-d>
</properties> </properties>
<dependencies> <dependencies>
@ -109,6 +114,11 @@
<test.vcloud-director.image-id>${test.vcloud-director.image-id}</test.vcloud-director.image-id> <test.vcloud-director.image-id>${test.vcloud-director.image-id}</test.vcloud-director.image-id>
<test.vcloud-director.image.login-user>${test.vcloud-director.image.login-user}</test.vcloud-director.image.login-user> <test.vcloud-director.image.login-user>${test.vcloud-director.image.login-user}</test.vcloud-director.image.login-user>
<test.vcloud-director.image.authenticate-sudo>${test.vcloud-director.image.authenticate-sudo}</test.vcloud-director.image.authenticate-sudo> <test.vcloud-director.image.authenticate-sudo>${test.vcloud-director.image.authenticate-sudo}</test.vcloud-director.image.authenticate-sudo>
<test.vcloud-director.catalog-name>${test.vcloud-director.catalog-name}</test.vcloud-director.catalog-name>
<test.vcloud-director.media-id>${test.vcloud-director.media-id}</test.vcloud-director.media-id>
<test.vcloud-director.vapptemplate-id>${test.vcloud-director.vapptemplate-id}</test.vcloud-director.vapptemplate-id>
<test.vcloud-director.network-id>${test.vcloud-director.network-id}</test.vcloud-director.network-id>
<test.vcloud-director.vdc-id>${test.vcloud-director.vdc-id}</test.vcloud-director.vdc-id>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.vcloud.director.v1_5; package org.jclouds.vcloud.director.v1_5;
/** /**
* Constants used by VCloudDirector clients * Constants used by VCloudDirector clients
* *
@ -29,35 +30,36 @@ public class VCloudDirectorConstants {
public static final String VCLOUD_1_5_NS = "http://www.vmware.com/vcloud/v1.5"; public static final String VCLOUD_1_5_NS = "http://www.vmware.com/vcloud/v1.5";
/** The property used to configure the timeout for task completion. */ /** The property used to configure the timeout for task completion. */
public static final String PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete"; public static final String PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete";
public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema"; public static final String PROPERTY_VCLOUD_DIRECTOR_VERSION_SCHEMA = "jclouds.vcloud-director.version.schema";
/** Name of the default org that your vApp will join, if an org isn't explicitly specified. */ /** Name of the default org that your vApp will join, if an org isn't explicitly specified. */
public static final String PROPERTY_VCLOUD_DEFAULT_ORG = "jclouds.vcloud.defaults.org"; public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_ORG = "jclouds.vcloud-director.defaults.org";
/** Name of the default catalog to query, if it isn't explicitly specified. */ /** Name of the default catalog to query, if it isn't explicitly specified. */
public static final String PROPERTY_VCLOUD_DEFAULT_CATALOG = "jclouds.vcloud.defaults.catalog"; public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_CATALOG = "jclouds.vcloud-director.defaults.catalog";
/** Name of the VDC that your vApp will join, if a vDC isn't explicitly specified. */ /** Name of the VDC that your vApp will join, if a vDC isn't explicitly specified. */
public static final String PROPERTY_VCLOUD_DEFAULT_VDC = "jclouds.vcloud.defaults.vdc"; public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_VDC = "jclouds.vcloud-director.defaults.vdc";
/** Name of the default network, in the default VDC that your vApp will join. */ /** Name of the default network, in the default VDC that your vApp will join. */
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network"; public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_NETWORK = "jclouds.vcloud-director.defaults.network";
/** TODO javadoc */ /** TODO javadoc */
// public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode"; // public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud-director.defaults.fencemode";
/** TODO javadoc */ /** TODO javadoc */
public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns"; public static final String PROPERTY_VCLOUD_DIRECTOR_XML_NAMESPACE = "jclouds.vcloud-director.xml.ns";
/** TODO javadoc */ /** TODO javadoc */
public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema"; public static final String PROPERTY_VCLOUD_DIRECTOR_XML_SCHEMA = "jclouds.vcloud-director.xml.schema";
// TODO put these somewhere else, maybe core?
/** TODO javadoc */ /** TODO javadoc */
public static final String PROPERTY_VCLOUD_DNS_NAME_LEN_MIN = "jclouds.dns_name_length_min"; public static final String PROPERTY_DNS_NAME_LEN_MIN = "jclouds.dns_name_length_min";
/** TODO javadoc */ /** TODO javadoc */
public static final String PROPERTY_VCLOUD_DNS_NAME_LEN_MAX = "jclouds.dns_name_length_max"; public static final String PROPERTY_NS_NAME_LEN_MAX = "jclouds.dns_name_length_max";
} }

View File

@ -33,30 +33,29 @@ import org.jclouds.PropertiesBuilder;
public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder { public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { public Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api"); properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api");
properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(30 * 60)); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(30 * 60));
properties.setProperty(PROPERTY_API_VERSION, "1.5"); properties.setProperty(PROPERTY_API_VERSION, "1.5");
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_NAMESPACE,
String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA)); String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_DIRECTOR_VERSION_SCHEMA));
properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(8 * 60)); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(8 * 60));
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, PROPERTY_ENDPOINT + "/v1.5/schema/master.xsd"); properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_SCHEMA, PROPERTY_ENDPOINT + "/v1.5/schema/master.xsd");
properties.setProperty(PROPERTY_VCLOUD_DNS_NAME_LEN_MIN, "1");
properties.setProperty(PROPERTY_VCLOUD_DNS_NAME_LEN_MAX, "80");
// TODO integrate these with the {@link ComputeTimeouts} instead of having a single timeout for everything. // TODO integrate these with the {@link ComputeTimeouts} instead of having a single timeout for everything.
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l));
properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(300)); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(300));
properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l));
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_CATALOG, "Public");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_VDC, "FIXME");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "FIXME");
return properties; return properties;
} }
public VCloudDirectorPropertiesBuilder() {
super();
}
public VCloudDirectorPropertiesBuilder(Properties properties) { public VCloudDirectorPropertiesBuilder(Properties properties) {
super(properties); super(properties);
} }

View File

@ -19,7 +19,6 @@ package org.jclouds.vcloud.director.v1_5.config;
import static com.google.common.base.Throwables.*; import static com.google.common.base.Throwables.*;
import static org.jclouds.rest.config.BinderUtils.*; import static org.jclouds.rest.config.BinderUtils.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
@ -36,7 +35,6 @@ import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.location.Provider; import org.jclouds.location.Provider;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
@ -61,17 +59,14 @@ import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401A
import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler; import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler;
import org.jclouds.vcloud.director.v1_5.login.SessionAsyncClient; import org.jclouds.vcloud.director.v1_5.login.SessionAsyncClient;
import org.jclouds.vcloud.director.v1_5.login.SessionClient; import org.jclouds.vcloud.director.v1_5.login.SessionClient;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.name.Named; import com.google.inject.name.Named;
@ -100,10 +95,13 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
@Override @Override
protected void configure() { protected void configure() {
// session client is used directly for filters and retry handlers, so let's bind it explicitly // Bind clients that are used directly in Functions, Predicates and other circumstances
bindClientAndAsyncClient(binder(), SessionClient.class, SessionAsyncClient.class); bindClientAndAsyncClient(binder(), SessionClient.class, SessionAsyncClient.class);
bindClientAndAsyncClient(binder(), OrgClient.class, OrgAsyncClient.class); bindClientAndAsyncClient(binder(), OrgClient.class, OrgAsyncClient.class);
bindClientAndAsyncClient(binder(), TaskClient.class, TaskAsyncClient.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(InvalidateSessionAndRetryOn401AndLogoutOnClose.class); bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(InvalidateSessionAndRetryOn401AndLogoutOnClose.class);
super.configure(); super.configure();
} }

View File

@ -18,28 +18,21 @@
*/ */
package org.jclouds.vcloud.director.v1_5.predicates; package org.jclouds.vcloud.director.v1_5.predicates;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI; import java.net.URI;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.inject.Inject;
/** /**
* Keeps testing {@link Task} to see if it has succeeded before a time limit has elapsed. * Test a {@link Task} to see if it has succeeded.
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@ -47,8 +40,16 @@ import com.google.inject.Inject;
public class TaskSuccess implements Predicate<URI> { public class TaskSuccess implements Predicate<URI> {
private final TaskClient taskClient; private final TaskClient taskClient;
private final RetryablePredicate<URI> retry;
private final Predicate<URI> checkSuccess = new Predicate<URI>() { @Resource
protected Logger logger = Logger.NULL;
@Inject
public TaskSuccess(TaskClient taskClient) {
this.taskClient = taskClient;
}
/** @see Predicate#apply(Object) */
@Override @Override
public boolean apply(URI taskUri) { public boolean apply(URI taskUri) {
logger.trace("looking for status on task %s", taskUri); logger.trace("looking for status on task %s", taskUri);
@ -61,21 +62,9 @@ public class TaskSuccess implements Predicate<URI> {
throw new VCloudDirectorException(task); throw new VCloudDirectorException(task);
return task.getStatus().equals(Task.Status.SUCCESS); return task.getStatus().equals(Task.Status.SUCCESS);
} }
};
@Resource
protected Logger logger = Logger.NULL;
@Inject
public TaskSuccess(RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long maxWait) {
this.taskClient = context.getApi().getTaskClient();
this.retry = new RetryablePredicate<URI>(checkSuccess, maxWait);
}
/** @see Predicate#apply(Object) */
@Override @Override
public boolean apply(URI input) { public String toString() {
return retry.apply(input); return "checkTaskSuccess()";
} }
} }

View File

@ -35,7 +35,5 @@ public class VCloudDirectorClientExpectTest extends BaseVCloudDirectorRestClient
VCloudDirectorClient clientWhenSessionsExist = requestSendsResponse(loginRequest, sessionResponse); VCloudDirectorClient clientWhenSessionsExist = requestSendsResponse(loginRequest, sessionResponse);
assertEquals(clientWhenSessionsExist.getCurrentSession(), SessionClientExpectTest.SESSION); assertEquals(clientWhenSessionsExist.getCurrentSession(), SessionClientExpectTest.SESSION);
} }
} }

View File

@ -181,7 +181,8 @@ public class Checks {
checkResourceType(metadata); checkResourceType(metadata);
} }
public static void checkMetadataEntry(MetadataEntry metadataEntry) {+ // Check required fields public static void checkMetadataEntry(MetadataEntry metadataEntry) {
// Check required fields
assertNotNull(metadataEntry.getKey(), String.format(NOT_NULL_OBJECT_FMT, "Key", "MetadataEntry")); assertNotNull(metadataEntry.getKey(), String.format(NOT_NULL_OBJECT_FMT, "Key", "MetadataEntry"));
assertNotNull(metadataEntry.getValue(), String.format(NOT_NULL_OBJECT_FMT, "Value", "MetadataEntry")); assertNotNull(metadataEntry.getValue(), String.format(NOT_NULL_OBJECT_FMT, "Value", "MetadataEntry"));

View File

@ -46,7 +46,7 @@ import com.google.common.collect.ImmutableSet;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = "unit", singleThreaded = true, testName = "CatalogClientExpectTest") @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogClientExpectTest")
public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test @Test

View File

@ -45,7 +45,7 @@ import com.google.common.collect.Iterables;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest", singleThreaded = true) @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "CatalogClientLiveTest")
public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/* /*
@ -178,7 +178,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata);
checkTask(mergeCatalogItemMetadata); checkTask(mergeCatalogItemMetadata);
assertTrue(successTester.apply(mergeCatalogItemMetadata.getHref()), assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata.getHref()),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef);

View File

@ -43,7 +43,7 @@ import org.testng.annotations.Test;
* *
* @author danikov * @author danikov
*/ */
@Test(groups = "unit", singleThreaded = true, testName = "NetworkClientExpectTest") @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "NetworkClientExpectTest")
public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test @Test

View File

@ -69,10 +69,9 @@ import com.google.common.collect.Iterables;
* *
* @author danikov * @author danikov
*/ */
@Test(groups = { "live", "apitests", "User" }, testName = "MediaClientLiveTest") @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "MediaClientLiveTest")
public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String MEDIA = "media"; public static final String MEDIA = "media";
public static Predicate<URI> taskTester;
/* /*
* Convenience references to API clients. * Convenience references to API clients.
@ -99,7 +98,6 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.id(mediaId) .id(mediaId)
.build(); .build();
mediaClient = context.getApi().getMediaClient(); mediaClient = context.getApi().getMediaClient();
taskTester = new RetryablePredicate<URI>(new TaskSuccess(context), 10, 1, TimeUnit.SECONDS);
mediaClient.setMetadata(mediaRef, "key", MetadataValue.builder().value("value").build()); mediaClient.setMetadata(mediaRef, "key", MetadataValue.builder().value("value").build());
} }
@ -154,7 +152,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task updateMedia = mediaClient.updateMedia(mediaRef, media); Task updateMedia = mediaClient.updateMedia(mediaRef, media);
Checks.checkTask(updateMedia); Checks.checkTask(updateMedia);
assertTrue(taskTester.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia")); assertTrue(retryTaskSuccess.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia"));
media = mediaClient.getMedia(mediaRef); media = mediaClient.getMedia(mediaRef);
assertTrue(equal(media.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, MEDIA, "name")); assertTrue(equal(media.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, MEDIA, "name"));
@ -171,7 +169,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
updateMedia = mediaClient.updateMedia(mediaRef, media); updateMedia = mediaClient.updateMedia(mediaRef, media);
Checks.checkTask(updateMedia); Checks.checkTask(updateMedia);
assertTrue(taskTester.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia")); assertTrue(retryTaskSuccess.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia"));
media = mediaClient.getMedia(mediaRef); media = mediaClient.getMedia(mediaRef);
} }
@ -209,7 +207,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata); Task mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata);
Checks.checkTask(mergeMetadata); Checks.checkTask(mergeMetadata);
assertTrue(taskTester.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)")); assertTrue(retryTaskSuccess.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)"));
metadata = mediaClient.getMetadata(mediaRef); metadata = mediaClient.getMetadata(mediaRef);
checkMetadataContainsEntries(metadata, inputEntries); checkMetadataContainsEntries(metadata, inputEntries);
@ -223,7 +221,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata); mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata);
Checks.checkTask(mergeMetadata); Checks.checkTask(mergeMetadata);
assertTrue(taskTester.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(modify)")); assertTrue(retryTaskSuccess.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(modify)"));
metadata = mediaClient.getMetadata(mediaRef); metadata = mediaClient.getMetadata(mediaRef);
checkMetadataContainsEntries(metadata, inputEntries); checkMetadataContainsEntries(metadata, inputEntries);
@ -272,7 +270,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task setMetadataEntry = mediaClient.setMetadata(mediaRef, "key", newValue); Task setMetadataEntry = mediaClient.setMetadata(mediaRef, "key", newValue);
Checks.checkTask(setMetadataEntry); Checks.checkTask(setMetadataEntry);
assertTrue(taskTester.apply(setMetadataEntry.getHref()), assertTrue(retryTaskSuccess.apply(setMetadataEntry.getHref()),
String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry")); String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry"));
metadataValue = mediaClient.getMetadataValue(mediaRef, "key"); metadataValue = mediaClient.getMetadataValue(mediaRef, "key");
@ -285,7 +283,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testWhenResponseIs2xxLoginDeletesMetadataEntry() { public void testWhenResponseIs2xxLoginDeletesMetadataEntry() {
Task deleteMetadataEntry = mediaClient.deleteMetadataEntry(mediaRef, "testKey"); Task deleteMetadataEntry = mediaClient.deleteMetadataEntry(mediaRef, "testKey");
Checks.checkTask(deleteMetadataEntry); Checks.checkTask(deleteMetadataEntry);
assertTrue(taskTester.apply(deleteMetadataEntry.getHref()), assertTrue(retryTaskSuccess.apply(deleteMetadataEntry.getHref()),
String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry")); String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry"));
Error expected = Error.builder() Error expected = Error.builder()
@ -320,7 +318,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task deleteMedia = mediaClient.deleteMedia(mediaRef); Task deleteMedia = mediaClient.deleteMedia(mediaRef);
Checks.checkTask(deleteMedia); Checks.checkTask(deleteMedia);
assertTrue(taskTester.apply(deleteMedia.getHref()), assertTrue(retryTaskSuccess.apply(deleteMedia.getHref()),
String.format(TASK_COMPLETE_TIMELY, "deleteMedia")); String.format(TASK_COMPLETE_TIMELY, "deleteMedia"));
Error expected = Error.builder() Error expected = Error.builder()

View File

@ -48,7 +48,7 @@ import com.google.common.collect.ImmutableSet;
* *
* @author danikov * @author danikov
*/ */
@Test(groups = "unit", singleThreaded = true, testName = "NetworkClientExpectTest") @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "NetworkClientExpectTest")
public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test @Test

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.*; import static org.testng.Assert.*;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.*;
import java.net.URI; import java.net.URI;
@ -37,7 +38,7 @@ import org.testng.annotations.Test;
* *
* @author danikov * @author danikov
*/ */
@Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest") @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "NetworkClientLiveTest")
public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/* /*
@ -51,10 +52,6 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
networkClient = context.getApi().getNetworkClient(); networkClient = context.getApi().getNetworkClient();
} }
// @Before populate
String networkId = "55a677cf-ab3f-48ae-b880-fab90421980c";
String catalogId = "9e08c2f6-077a-42ce-bece-d5332e2ebb5c";
@Test(testName = "GET /network/{id}") @Test(testName = "GET /network/{id}")
public void testWhenResponseIs2xxLoginReturnsValidNetwork() { public void testWhenResponseIs2xxLoginReturnsValidNetwork() {
Reference networkRef = Reference.builder() Reference networkRef = Reference.builder()
@ -62,16 +59,17 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
OrgNetwork network = networkClient.getNetwork(networkRef); OrgNetwork network = networkClient.getNetwork(networkRef);
//TODO assert network is valid // TODO change to checkOrgNetwork(...)
checkEntityType(network);
} }
@Test(testName = "GET /network/NOTAUUID", enabled=false) @Test(testName = "GET /network/{id} - invalid")
public void testWhenResponseIs400ForInvalidNetworkId() { public void testWhenResponseIs400ForInvalidNetworkId() {
Reference networkRef = Reference.builder() Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/NOTAUUID")).build(); .href(URI.create(endpoint + "/network/NOTAUUID")).build();
Error expected = Error.builder() Error expected = Error.builder()
.message("validation error : EntityRef has incorrect type, expected type is com.vmware.vcloud.entity.network.") .message("validation error on field 'id': String value has invalid format or length")
.majorErrorCode(400) .majorErrorCode(400)
.minorErrorCode("BAD_REQUEST") .minorErrorCode("BAD_REQUEST")
.build(); .build();
@ -86,28 +84,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
} }
} }
@Test(testName = "GET /network/{catalog_id}", enabled=false) @Test(testName = "GET /network/{id} - fake")
public void testWhenResponseIs403ForCatalogIdUsedAsNetworkId() {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network"+catalogId)).build();
Error expected = Error.builder()
.message("This operation is denied.")
.majorErrorCode(403)
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build();
try {
networkClient.getNetwork(networkRef);
fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
}
@Test(testName = "GET /network/{fake_id}")
public void testWhenResponseIs403ForFakeNetworkId() { public void testWhenResponseIs403ForFakeNetworkId() {
Reference networkRef = Reference.builder() Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build(); .href(URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build();
@ -133,11 +110,12 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Reference networkRef = Reference.builder() Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/"+networkId)).build(); .href(URI.create(endpoint + "/network/"+networkId)).build();
Metadata expected = context.getApi().getNetworkClient().getMetadata(networkRef); Metadata metadata = context.getApi().getNetworkClient().getMetadata(networkRef);
// assert metadata is valid checkMetadata(metadata);
// assert has metadata in order to support subsequent test
// assign metadata key (todo- ordering) // TODO assert has metadata in order to support subsequent test
// TODO assign metadata key (todo- ordering)
} }
String metadataKey = "key"; String metadataKey = "key";
@ -148,9 +126,8 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Reference networkRef = Reference.builder() Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/"+networkId)).build(); .href(URI.create(endpoint + "/network/"+networkId)).build();
MetadataEntry expected = networkClient.getMetadataEntry(networkRef, metadataKey); MetadataEntry metadataEntry = networkClient.getMetadataEntry(networkRef, metadataKey);
// assert metadataEntry is valid checkMetadataEntry(metadataEntry);
} }
} }

View File

@ -44,7 +44,7 @@ import com.google.common.collect.Iterables;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", singleThreaded = true, testName = "OrgClientExpectTest") @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "OrgClientExpectTest")
public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test @Test

View File

@ -39,7 +39,7 @@ import com.google.common.collect.Iterables;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = { "live", "apitests" }, testName = "OrgClientLiveTest") @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "OrgClientLiveTest")
public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/* /*

View File

@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = "unit", singleThreaded = true, testName = "QueryClientExpectTest") @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "QueryClientExpectTest")
public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test @Test

View File

@ -32,7 +32,7 @@ import org.testng.annotations.Test;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = { "live", "apitests" }, testName = "QueryClientLiveTest") @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "QueryClientLiveTest")
public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/* /*

View File

@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = "unit", singleThreaded = true, testName = "TaskClientExpectTest") @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "TaskClientExpectTest")
public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test @Test

View File

@ -39,7 +39,7 @@ import com.google.common.collect.Iterables;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@Test(groups = { "live", "apitests" }, testName = "TaskClientLiveTest") @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "TaskClientLiveTest")
public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest { public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/* /*

View File

@ -18,12 +18,14 @@
*/ */
package org.jclouds.vcloud.director.v1_5.internal; package org.jclouds.vcloud.director.v1_5.internal;
import java.util.Properties; import static org.testng.Assert.*;
import javax.inject.Inject; import java.net.URI;
import java.util.Properties;
import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
@ -33,13 +35,17 @@ import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
* Tests behavior of {@code VCloudDirectorClient} * Tests behavior of {@link VCloudDirectorClient}
* *
* @author Adrian Cole * @author Adrian Cole
* @author grkvlt@apache.org
*/ */
@Test(groups = "live") @Test(groups = "live")
public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest {
@ -48,8 +54,41 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe
provider = "vcloud-director"; provider = "vcloud-director";
} }
@Inject protected String catalogName;
protected TaskSuccess successTester; protected String mediaId;
protected String vAppTemplateId;
protected String networkId;
protected String vDCId;
@Override
protected Properties setupProperties() {
Properties overrides= super.setupProperties();
if (catalogName != null)
overrides.setProperty(provider + ".catalog-name", catalogName);
if (mediaId != null)
overrides.setProperty(provider + ".media-id", mediaId);
if (vAppTemplateId != null)
overrides.setProperty(provider + ".vapptemplate-id", vAppTemplateId);
if (networkId != null)
overrides.setProperty(provider + ".network-id", networkId);
if (vDCId != null)
overrides.setProperty(provider + ".vcd-id", vDCId);
return overrides;
}
public Predicate<URI> retryTaskSuccess;
@Override
@BeforeClass(groups = { "live" })
protected void setupCredentials() {
super.setupCredentials();
catalogName = System.getProperty("test." + provider + ".catalog-name");
mediaId = System.getProperty("test." + provider + ".media-id");
vAppTemplateId = System.getProperty("test." + provider + ".vapptemplate-id");
networkId = System.getProperty("test." + provider + ".network-id");
vDCId = System.getProperty("test." + provider + ".vdc-id");
}
protected RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context; protected RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context;
@ -57,14 +96,16 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe
public void setupContext() { public void setupContext() {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, identity, credential, context = new RestContextFactory().createContext(provider, identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides);
// successTester = new TaskSuccess(context, 1000L); // NOTE is this required?
TaskSuccess taskSuccess = context.utils().injector().getInstance(TaskSuccess.class);
retryTaskSuccess = new RetryablePredicate<URI>(taskSuccess, 1000L);
} }
protected void tearDown() { protected void tearDown() {
if (context != null) if (context != null)
context.close(); context.close();
} }
} }

View File

@ -18,8 +18,8 @@
*/ */
package org.jclouds.vcloud.director.v1_5.internal; package org.jclouds.vcloud.director.v1_5.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.*;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.*;
import java.net.URI; import java.net.URI;
@ -29,6 +29,7 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.BaseRestClientExpectTest;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;

View File

@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "SessionClientExpectTest") @Test(groups = "unit", testName = "SessionClientExpectTest")
// only needed as SessionClient is not(Link.builder().registered in(Link.builder().rest.properties // only needed as SessionClient is not registered in rest.properties
@RegisterContext(sync = SessionClient.class, async = SessionAsyncClient.class) @RegisterContext(sync = SessionClient.class, async = SessionAsyncClient.class)
public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionClient> { public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionClient> {
public static final String user = "adrian@jclouds.org"; public static final String user = "adrian@jclouds.org";

View File

@ -18,17 +18,14 @@
*/ */
package org.jclouds.vcloud.director.v1_5.login; package org.jclouds.vcloud.director.v1_5.login;
import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.jclouds.rest.RestContextFactory.*;
import static org.jclouds.rest.RestContextFactory.createContextBuilder; import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
@ -61,7 +58,7 @@ public class SessionClientLiveTest extends BaseVersionedServiceLiveTest {
apiVersion, buildVersion, "", identity, credential, SessionClient.class, SessionAsyncClient.class); apiVersion, buildVersion, "", identity, credential, SessionClient.class, SessionAsyncClient.class);
context = createContextBuilder(contextSpec, overrides).withModules( context = createContextBuilder(contextSpec, overrides).withModules(
ImmutableSet.<Module> of(new SLF4JLoggingModule())).buildContext(); ImmutableSet.<Module> of(new Log4JLoggingModule())).buildContext();
// session client isn't typically exposed to the user, as it is implicit // session client isn't typically exposed to the user, as it is implicit
client = context.utils().injector().getInstance(SessionClient.class); client = context.utils().injector().getInstance(SessionClient.class);