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

View File

@ -40,7 +40,6 @@ public abstract class BaseRestClientLiveTest {
protected String apiVersion;
protected String buildVersion;
protected Properties setupRestProperties() {
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.login-user></test.vcloud-director.image.login-user>
<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>
<dependencies>
@ -109,6 +114,11 @@
<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.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>
</configuration>
</execution>

View File

@ -18,9 +18,10 @@
*/
package org.jclouds.vcloud.director.v1_5;
/**
* Constants used by VCloudDirector clients
*
*
* @author grkvlt@apache.org
*/
public class VCloudDirectorConstants {
@ -29,35 +30,36 @@ public class VCloudDirectorConstants {
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. */
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. */
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. */
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. */
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. */
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 */
// 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 */
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 */
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 */
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 */
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 {
@Override
protected Properties defaultProperties() {
public Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api");
properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(30 * 60));
properties.setProperty(PROPERTY_API_VERSION, "1.5");
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE,
String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA));
properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_NAMESPACE,
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_VCLOUD_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");
properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_SCHEMA, PROPERTY_ENDPOINT + "/v1.5/schema/master.xsd");
// 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_VCLOUD_DEFAULT_CATALOG, "Public");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_VDC, "FIXME");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "FIXME");
properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l));
return properties;
}
public VCloudDirectorPropertiesBuilder() {
super();
}
public VCloudDirectorPropertiesBuilder(Properties 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 org.jclouds.rest.config.BinderUtils.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
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.ServerError;
import org.jclouds.location.Provider;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
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.login.SessionAsyncClient;
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.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
@ -100,10 +95,13 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
@Override
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(), OrgClient.class, OrgAsyncClient.class);
bindClientAndAsyncClient(binder(), TaskClient.class, TaskAsyncClient.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(InvalidateSessionAndRetryOn401AndLogoutOnClose.class);
super.configure();
}

View File

@ -18,28 +18,21 @@
*/
package org.jclouds.vcloud.director.v1_5.predicates;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Singleton;
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.domain.Task;
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
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
*/
@ -47,35 +40,31 @@ import com.google.inject.Inject;
public class TaskSuccess implements Predicate<URI> {
private final TaskClient taskClient;
private final RetryablePredicate<URI> retry;
private final Predicate<URI> checkSuccess = new Predicate<URI>() {
@Override
public boolean apply(URI taskUri) {
logger.trace("looking for status on task %s", taskUri);
Task task = taskClient.getTask(taskUri);
// perhaps task isn't available, yet
if (task == null) return false;
logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus());
if (task.getStatus().equals(Task.Status.ERROR))
throw new VCloudDirectorException(task);
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);
public TaskSuccess(TaskClient taskClient) {
this.taskClient = taskClient;
}
/** @see Predicate#apply(Object) */
@Override
public boolean apply(URI input) {
return retry.apply(input);
public boolean apply(URI taskUri) {
logger.trace("looking for status on task %s", taskUri);
Task task = taskClient.getTask(taskUri);
// perhaps task isn't available, yet
if (task == null) return false;
logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus());
if (task.getStatus().equals(Task.Status.ERROR))
throw new VCloudDirectorException(task);
return task.getStatus().equals(Task.Status.SUCCESS);
}
@Override
public String toString() {
return "checkTaskSuccess()";
}
}

View File

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

View File

@ -181,7 +181,8 @@ public class Checks {
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.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
*/
@Test(groups = "unit", singleThreaded = true, testName = "CatalogClientExpectTest")
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogClientExpectTest")
public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test

View File

@ -45,7 +45,7 @@ import com.google.common.collect.Iterables;
*
* @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 {
/*
@ -178,7 +178,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata);
checkTask(mergeCatalogItemMetadata);
assertTrue(successTester.apply(mergeCatalogItemMetadata.getHref()),
assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata.getHref()),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef);

View File

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

View File

@ -69,10 +69,9 @@ import com.google.common.collect.Iterables;
*
* @author danikov
*/
@Test(groups = { "live", "apitests", "User" }, testName = "MediaClientLiveTest")
@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "MediaClientLiveTest")
public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String MEDIA = "media";
public static Predicate<URI> taskTester;
/*
* Convenience references to API clients.
@ -99,7 +98,6 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.id(mediaId)
.build();
mediaClient = context.getApi().getMediaClient();
taskTester = new RetryablePredicate<URI>(new TaskSuccess(context), 10, 1, TimeUnit.SECONDS);
mediaClient.setMetadata(mediaRef, "key", MetadataValue.builder().value("value").build());
}
@ -127,11 +125,11 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
assertTrue(size >= 0, String.format(OBJ_FIELD_GTE_0, MEDIA, "size", size));
}
@Test(testName = "GET /media/{id}/owner",
@Test(testName = "GET /media/{id}/owner",
dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" })
public void testWhenResponseIs2xxLoginReturnsValidMediaOwner() {
Owner directOwner = mediaClient.getOwner(mediaRef);
assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ,
assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ,
"getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString()));
// parent type
@ -142,7 +140,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkReferenceType(directOwner.getUser());
}
@Test(testName = "PUT /media/{id}",
@Test(testName = "PUT /media/{id}",
dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" })
public void testWhenResponseIs2xxLoginReturnsValidNetwork() {
String oldName = media.getName();
@ -154,11 +152,11 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task updateMedia = mediaClient.updateMedia(mediaRef, media);
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);
assertTrue(equal(media.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, MEDIA, "name"));
assertTrue(equal(media.getDescription(), newDescription),
assertTrue(equal(media.getDescription(), newDescription),
String.format(OBJ_FIELD_UPDATABLE, MEDIA, "description"));
//TODO negative tests?
@ -171,16 +169,16 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
updateMedia = mediaClient.updateMedia(mediaRef, media);
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);
}
@Test(testName = "GET /media/{id}/metadata",
@Test(testName = "GET /media/{id}/metadata",
dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" })
public void testWhenResponseIs2xxLoginReturnsValidMetadata() {
metadata = mediaClient.getMetadata(mediaRef);
// required for testing
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "metadata.entries"));
// parent type
@ -188,9 +186,9 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
for (MetadataEntry entry : metadata.getMetadataEntries()) {
// required elements and attributes
assertNotNull(entry.getKey(),
assertNotNull(entry.getKey(),
String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", metadataValue, "key"));
assertNotNull(entry.getValue(),
assertNotNull(entry.getValue(),
String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", metadataValue, "value"));
// parent type
@ -198,7 +196,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
}
@Test(testName = "POST /media/{id}/metadata",
@Test(testName = "POST /media/{id}/metadata",
dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMetadata" })
public void testWhenResponseIs2xxLoginMergedMetadata() {
// test new
@ -209,7 +207,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata);
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);
checkMetadataContainsEntries(metadata, inputEntries);
@ -223,7 +221,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata);
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);
checkMetadataContainsEntries(metadata, inputEntries);
@ -240,14 +238,14 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
if (!found) {
String.format(OBJ_FIELD_CONTAINS, MEDIA, "metadata",
Iterables.toString(metadata.getMetadataEntries()),
String.format(OBJ_FIELD_CONTAINS, MEDIA, "metadata",
Iterables.toString(metadata.getMetadataEntries()),
Iterables.toString(entries));
}
}
}
@Test(testName = "GET /media/{id}/metadata/{key}",
@Test(testName = "GET /media/{id}/metadata/{key}",
dependsOnMethods = { "testWhenResponseIs2xxLoginMergedMetadata" })
public void testWhenResponseIs2xxLoginReturnsValidMetadataValue() {
metadataValue = mediaClient.getMetadataValue(mediaRef, "key");
@ -257,14 +255,14 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
// Check required elements and attributes
String value = metadataValue.getValue();
assertNotNull(value,
String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry",
assertNotNull(value,
String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry",
metadataValue.toString(), metadataEntryValue.toString()));
assertEquals(value, metadataEntryValue,
assertEquals(value, metadataEntryValue,
String.format(OBJ_FIELD_EQ, MEDIA, "metadataEntry.value", metadataEntryValue, value));
}
@Test(testName = "PUT /media/{id}/metadata/{key}",
@Test(testName = "PUT /media/{id}/metadata/{key}",
dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMetadataValue" })
public void testWhenResponseIs2xxLoginUpdatesMetadataEntry() {
metadataEntryValue = "newValue";
@ -272,7 +270,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Task setMetadataEntry = mediaClient.setMetadata(mediaRef, "key", newValue);
Checks.checkTask(setMetadataEntry);
assertTrue(taskTester.apply(setMetadataEntry.getHref()),
assertTrue(retryTaskSuccess.apply(setMetadataEntry.getHref()),
String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry"));
metadataValue = mediaClient.getMetadataValue(mediaRef, "key");
@ -280,12 +278,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
testWhenResponseIs2xxLoginReturnsValidMetadataValue();
}
@Test(testName = "DELETE /media/{id}/metadata/{key}",
@Test(testName = "DELETE /media/{id}/metadata/{key}",
dependsOnMethods = { "testWhenResponseIs2xxLoginUpdatesMetadataEntry" } )
public void testWhenResponseIs2xxLoginDeletesMetadataEntry() {
Task deleteMetadataEntry = mediaClient.deleteMetadataEntry(mediaRef, "testKey");
Checks.checkTask(deleteMetadataEntry);
assertTrue(taskTester.apply(deleteMetadataEntry.getHref()),
assertTrue(retryTaskSuccess.apply(deleteMetadataEntry.getHref()),
String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry"));
Error expected = Error.builder()
@ -305,8 +303,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
if (metadataValue != null) { // guard against NPE on the .toStrings
assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA,
"Metadata", metadataValue.toString(),
assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA,
"Metadata", metadataValue.toString(),
"metadataEntry", metadataValue.toString()));
}
@ -314,18 +312,18 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
testWhenResponseIs2xxLoginReturnsValidMetadata();
testWhenResponseIs2xxLoginReturnsValidMedia();
}
@Test(testName = "DELETE /media/{id}",
@Test(testName = "DELETE /media/{id}",
dependsOnMethods = { "testWhenResponseIs2xxLoginDeletesMetadataEntry" } )
public void testWhenResponseIs2xxLoginDeletesMedia() {
Task deleteMedia = mediaClient.deleteMedia(mediaRef);
Checks.checkTask(deleteMedia);
assertTrue(taskTester.apply(deleteMedia.getHref()),
assertTrue(retryTaskSuccess.apply(deleteMedia.getHref()),
String.format(TASK_COMPLETE_TIMELY, "deleteMedia"));
Error expected = Error.builder()
.message(String.format(
"No access to entity \"(com.vmware.vcloud.entity.media:%s)\".",
"No access to entity \"(com.vmware.vcloud.entity.media:%s)\".",
mediaRef.getId()))
.majorErrorCode(403)
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")

View File

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

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.*;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.*;
import java.net.URI;
@ -37,7 +38,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest")
@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "NetworkClientLiveTest")
public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/*
@ -51,27 +52,24 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
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}")
public void testWhenResponseIs2xxLoginReturnsValidNetwork() {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/"+networkId)).build();
.href(URI.create(endpoint + "/network/" + networkId)).build();
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() {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/NOTAUUID")).build();
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)
.minorErrorCode("BAD_REQUEST")
.build();
@ -85,29 +83,8 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
fail("Should have thrown a VCloudDirectorException");
}
}
@Test(testName = "GET /network/{catalog_id}", enabled=false)
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}")
@Test(testName = "GET /network/{id} - fake")
public void testWhenResponseIs403ForFakeNetworkId() {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build();
@ -133,11 +110,12 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/"+networkId)).build();
Metadata expected = context.getApi().getNetworkClient().getMetadata(networkRef);
// assert metadata is valid
// assert has metadata in order to support subsequent test
// assign metadata key (todo- ordering)
Metadata metadata = context.getApi().getNetworkClient().getMetadata(networkRef);
checkMetadata(metadata);
// TODO assert has metadata in order to support subsequent test
// TODO assign metadata key (todo- ordering)
}
String metadataKey = "key";
@ -148,9 +126,8 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Reference networkRef = Reference.builder()
.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
*/
@Test(groups = "unit", singleThreaded = true, testName = "OrgClientExpectTest")
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "OrgClientExpectTest")
public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,12 +18,14 @@
*/
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.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
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.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Module;
/**
* Tests behavior of {@code VCloudDirectorClient}
* Tests behavior of {@link VCloudDirectorClient}
*
* @author Adrian Cole
* @author grkvlt@apache.org
*/
@Test(groups = "live")
public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest {
@ -48,8 +54,41 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe
provider = "vcloud-director";
}
@Inject
protected TaskSuccess successTester;
protected String catalogName;
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;
@ -57,14 +96,16 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe
public void setupContext() {
setupCredentials();
Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, identity, credential,
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() {
if (context != null)
context.close();
}
}

View File

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

View File

@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap;
* @author Adrian Cole
*/
@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)
public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionClient> {
public static final String user = "adrian@jclouds.org";

View File

@ -18,17 +18,14 @@
*/
package org.jclouds.vcloud.director.v1_5.login;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.jclouds.rest.RestContextFactory.*;
import static org.testng.Assert.*;
import java.net.URI;
import java.util.Properties;
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.RestContextSpec;
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);
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
client = context.utils().injector().getInstance(SessionClient.class);