Merge pull request #557 from grkvlt/vcloud-fixes

Issue 830: vCloud test fixes
This commit is contained in:
Adrian Cole 2012-04-11 15:25:44 -07:00
commit 70d179b3c7
49 changed files with 362 additions and 308 deletions

View File

@ -23,7 +23,6 @@ import static org.jclouds.dmtf.DMTFConstants.OVF_NS;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
@ -33,7 +32,6 @@ import com.google.common.base.Objects;
* @author Adrian Cole
* @author Adam Lowe
*/
@XmlType(name = "OperatingSystemSection_Type")
public class OperatingSystemSection extends SectionType {
public static Builder<?> builder() {

View File

@ -25,7 +25,6 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import org.jclouds.dmtf.cim.ResourceAllocationSettingData;
import org.jclouds.dmtf.cim.VirtualSystemSettingData;
@ -46,7 +45,6 @@ import com.google.common.collect.Sets;
* @author Adam Lowe
* @author grkvlt@apache.org
*/
@XmlType(name = "VirtualHardwareSection_Type")
public class VirtualHardwareSection extends SectionType {
public static Builder<?> builder() {

View File

@ -95,6 +95,7 @@ public class Link extends Reference {
@XmlEnumValue("remove") REMOVE("remove"),
@XmlEnumValue("screen:acquireTicket") SCREEN_ACQUIRE_TICKET("screen:acquireTicket"),
@XmlEnumValue("screen:thumbnail") SCREEN_THUMBNAIL("screen:thumbnail"),
@XmlEnumValue("syncSyslogSettings") SYNC_SYSLOG_SETTINGS("syncSyslogSettings"),
@XmlEnumValue("task:cancel") TASK_CANCEL("task:cancel"),
@XmlEnumValue("blockingTask") BLOCKING_TASK("blockingTask"),
@XmlEnumValue("taskOwner") TASK_OWNER("taskOwner"),
@ -121,7 +122,7 @@ public class Link extends Reference {
NEXT_PAGE, OVA, OVF, POWER_OFF, POWER_ON, REBOOT, RESET, SHUTDOWN,
SUSPEND, PREVIOUS_PAGE, PUBLISH, RECOMPOSE, RECONNECT, REGISTER,
REJECT, RELOCATE, REMOVE, REPAIR, SCREEN_ACQUIRE_TICKET,
SCREEN_THUMBNAIL, TASK_CANCEL, BLOCKING_TASK, TASK_OWNER,
SCREEN_THUMBNAIL, SYNC_SYSLOG_SETTINGS, TASK_CANCEL, BLOCKING_TASK, TASK_OWNER,
TASK_PARAMS, TASK_REQUEST, UNDEPLOY, UNLOCK, UNREGISTER, UP,
UPDATE_PROGRESS, UPGRADE, UPLOAD_ALTERNATE, UPLOAD_DEFAULT,
UPLOAD_DEFAULT);

View File

@ -20,6 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.dmtf.DMTFConstants.OVF_NS;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_VMW_NS;
@ -30,6 +31,7 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
@ -43,7 +45,8 @@ import com.google.common.collect.Sets;
* @author Adam Lowe
* @author grkvlt@apache.org
*/
@XmlRootElement(name = "OperatingSystemSection")
@XmlRootElement(name = "OperatingSystemSection", namespace = OVF_NS)
@XmlType(name = "OperatingSystemSection_Type")
@XmlSeeAlso({ org.jclouds.dmtf.ovf.OperatingSystemSection.class })
public class OperatingSystemSection extends org.jclouds.dmtf.ovf.OperatingSystemSection {

View File

@ -20,6 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.dmtf.DMTFConstants.OVF_NS;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS;
import java.net.URI;
@ -30,6 +31,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
@ -41,7 +43,8 @@ import com.google.common.collect.Sets;
*
* @author grkvlt@apache.org
*/
@XmlRootElement(name = "VirtualHardwareSection", namespace = VCLOUD_1_5_NS)
@XmlRootElement(name = "VirtualHardwareSection", namespace = OVF_NS)
@XmlType(name = "VirtualHardwareSection_Type")
@XmlSeeAlso({ org.jclouds.dmtf.ovf.VirtualHardwareSection.class })
public class VirtualHardwareSection extends org.jclouds.dmtf.ovf.VirtualHardwareSection {

View File

@ -204,7 +204,7 @@ public interface VAppTemplateAsyncClient {
* @see VAppTemplateClient#getNetworkConnectionSection(URI)
*/
@GET
@Consumes(NETWORK_CONFIG_SECTION)
@Consumes(NETWORK_CONNECTION_SECTION)
@Path("/networkConnectionSection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)

View File

@ -55,11 +55,12 @@ public class VCloudDirectorErrorHandler implements HttpErrorHandler {
: String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine());
Exception exception = new HttpResponseException(command, response, message);
// Try to create a VCloudDirectorException from XML payload
if (response.getPayload().getContentMetadata().getContentType().startsWith(VCloudDirectorMediaType.ERROR)) {
// Try to create a VCloudDirectorException from XML payload, if it exists
if (response.getPayload() != null && response.getPayload().getContentMetadata().getContentType().startsWith(VCloudDirectorMediaType.ERROR)) {
try {
Error error = JAXB.unmarshal(InputSuppliers.of(data).getInput(), Error.class);
exception = new VCloudDirectorException(error);
message = error.getMessage();
} catch (Exception e) {
Throwables.propagate(e);
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.vcloud.director.v1_5.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
@ -34,7 +36,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* Test a {@link Task} to see if it has succeeded.
* Test a {@link Task} status is in a particular set of {@link Task.Status statuses}.
*
* @author grkvlt@apache.org
*/
@ -61,6 +63,7 @@ public class TaskStatusEquals implements Predicate<Task> {
/** @see Predicate#apply(Object) */
@Override
public boolean apply(Task task) {
checkNotNull(task, "task");
logger.trace("looking for status on task %s", task);
// TODO shouldn't we see if it's already done before getting it from API server?

View File

@ -18,6 +18,10 @@
*/
package org.jclouds.vcloud.director.v1_5.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.EnumSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -30,7 +34,7 @@ import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import com.google.common.base.Predicate;
/**
* Test a {@link Task} to see if it has succeeded.
* Test a {@link Task} to see if it has {@link Task.Status#SUCCESS succeeded}.
*
* @author grkvlt@apache.org
*/
@ -50,21 +54,19 @@ public class TaskSuccess implements Predicate<Task> {
/** @see Predicate#apply(Object) */
@Override
public boolean apply(Task task) {
logger.trace("looking for status on task %s", task);
checkNotNull(task, "task");
logger.trace("looking for status on task %s", task.getOperationName());
// TODO shouldn't we see if it's already done before getting it from API server?
task = taskClient.getTask(task.getHref());
// 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))
logger.trace("%s: looking for status %s: currently: %s", task.getOperationName(), Task.Status.SUCCESS, task.getStatus());
if (EnumSet.of(Task.Status.ERROR, Task.Status.CANCELED, Task.Status.ABORTED).contains(task.getStatus())) {
throw new VCloudDirectorException(task);
if (task.getStatus().equals(Task.Status.CANCELED))
throw new VCloudDirectorException(task);
if (task.getStatus().equals(Task.Status.ABORTED))
throw new VCloudDirectorException(task);
return task.getStatus().equals(Task.Status.SUCCESS);
} else return task.getStatus().equals(Task.Status.SUCCESS);
}
@Override

View File

@ -0,0 +1,114 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.net.URI;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of {@link AdminCatalogClient}.
*
* @author danikov
*/
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "HttpClientLiveTest")
public class HttpClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private JAXBParser parser = new JAXBParser("true");
private SessionWithToken sessionWithToken;
@Override
protected void setupRequiredClients() throws Exception {
setupCredentials();
}
@Test(description = "POST /login")
public void testPostLogin() throws IOException {
testLoginWithMethod("POST");
}
@Test(description = "GET /login")
public void testGetLogin() throws IOException {
testLoginWithMethod("GET");
}
private void testLoginWithMethod(final String method) throws IOException {
String user = identity.substring(0, identity.lastIndexOf('@'));
String org = identity.substring(identity.lastIndexOf('@') + 1);
String password = credential;
String authHeader = "Basic " + CryptoStreams.base64(String.format("%s@%s:%s", checkNotNull(user), checkNotNull(org), checkNotNull(password)).getBytes("UTF-8"));
HttpResponse response = context.getUtils().getHttpClient().invoke(HttpRequest.builder()
.method(method)
.endpoint(URI.create(endpoint + "/login"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Authorization", authHeader)
.put("Accept", "*/*")
.build())
.build());
sessionWithToken = SessionWithToken.builder().session(session).token(response.getFirstHeaderOrNull("x-vcloud-authorization")).build();
assertEquals(sessionWithToken.getSession().getUser(), user);
assertEquals(sessionWithToken.getSession().getOrg(), org);
assertTrue(sessionWithToken.getSession().getLinks().size() > 0);
assertNotNull(sessionWithToken.getToken());
OrgList orgList = parser.fromXML(Strings2.toStringAndClose(response.getPayload().getInput()), OrgList.class);
assertTrue(orgList.getOrgs().size() > 0, "must have orgs");
context.getApi().getOrgClient().getOrg(Iterables.getLast(orgList.getOrgs()).getHref());
}
@Test(description = "GET /schema/{schemaFileName}", dependsOnMethods = { "testPostLogin", "testGetLogin" })
public void testGetSchema() throws IOException {
String schemafileName = "master.xsd";
HttpResponse response = context.getUtils().getHttpClient().invoke(HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/v1.5/schema/" + schemafileName))
.headers(ImmutableMultimap.<String, String>builder()
.put("x-vcloud-authorization", sessionWithToken.getToken())
.put("Accept", "*/*")
.build())
.build());
String schema = Strings2.toStringAndClose(response.getPayload().getInput());
// TODO: asserting something about the schema
}
}

View File

@ -1,136 +0,0 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.net.URI;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of {@link AdminCatalogClient}.
*
* @author danikov
*/
@Test(groups = {"live", "user", "nonClient"}, singleThreaded = true, testName = "NonClientOperationsLiveTest")
public class NonClientOperationsLiveTest extends BaseVCloudDirectorClientLiveTest
{
private JAXBParser parser = new JAXBParser("true");
private SessionWithToken sessionWithToken;
@Override
protected void setupRequiredClients() throws Exception
{
setupCredentials();
}
@Test(testName = "POST /login")
public void testPostLogin() throws IOException
{
testLoginWithMethod("POST");
}
@Test(testName = "GET /login")
public void testGetLogin() throws IOException
{
testLoginWithMethod("GET");
}
private void testLoginWithMethod(final String method) throws IOException
{
String user = identity.substring(0, identity.lastIndexOf('@'));
String org = identity.substring(identity.lastIndexOf('@') + 1);
String password = credential;
String authHeader =
"Basic "
+ CryptoStreams.base64(String.format("%s@%s:%s", checkNotNull(user),
checkNotNull(org), checkNotNull(password)).getBytes("UTF-8"));
HttpResponse response =
context
.getUtils()
.getHttpClient()
.invoke(
HttpRequest
.builder()
.method(method)
.endpoint(URI.create(endpoint + "/login"))
.headers(ImmutableMultimap.of("Authorization", authHeader, "Accept", "*/*"))
.build());
sessionWithToken =
SessionWithToken.builder().session(session)
.token(response.getFirstHeaderOrNull("x-vcloud-authorization")).build();
assertEquals(sessionWithToken.getSession().getUser(), user);
assertEquals(sessionWithToken.getSession().getOrg(), org);
assertTrue(sessionWithToken.getSession().getLinks().size() > 0);
assertNotNull(sessionWithToken.getToken());
OrgList orgList =
parser.fromXML(Strings2.toStringAndClose(response.getPayload().getInput()),
OrgList.class);
assertTrue(orgList.getOrgs().size() > 0, "must have orgs");
context.getApi().getOrgClient().getOrg(Iterables.getLast(orgList.getOrgs()).getHref());
}
@Test(testName = "GET /schema/{schemaFileName}", dependsOnMethods = {"testPostLogin",
"testGetLogin"})
public void testGetSchema() throws IOException
{
String schemafileName = "master.xsd";
HttpResponse response =
context
.getUtils()
.getHttpClient()
.invoke(
HttpRequest
.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/v1.5/schema/" + schemafileName))
.headers(
ImmutableMultimap.of("x-vcloud-authorization",
sessionWithToken.getToken(), "Accept", "*/*")).build());
String schema = Strings2.toStringAndClose(response.getPayload().getInput());
// TODO: asserting something about the schema
}
}

View File

@ -51,6 +51,8 @@ public class VCloudDirectorLiveTestConstants {
public static final String OBJ_FIELD_GTE_1 = "ERR-108: %s field %s must be greater than to equal to 0 (%d)";
public static final String OBJ_FIELD_GTE = "ERR-108: %s field %s must be greater than to equal to %d (%d)";
public static final String GETTER_RETURNS_SAME_OBJ = "ERR-109: %s should return the same %s as %s (%s, %s)";
public static final String OBJ_FIELD_UPDATABLE = "ERR-110: %s field %s should be updatable";
@ -89,6 +91,12 @@ public class VCloudDirectorLiveTestConstants {
public static final String MATCHES_STRING_FMT = "ERR-127: The %s field must match the pattern \"%s\" (%s)";
public static final String OBJ_FIELD_LIST_EMPTY = "ERR-128: %s %s must be empty (%d members)";
public static final String OBJ_FIELD_LIST_SIZE_EQ = "ERR-129: %s %s must have %d members (%d members)";
public static final String OBJ_FIELD_LIST_SIZE_GE = "ERR-130: %s %s must have at least %d members (%d members)";
/* Error codes from 300 to 399 reflect entities and their links and relationship errors. */
public static final String ENTITY_NON_NULL = "ERR-301: The %s entity must not be null";

View File

@ -582,6 +582,8 @@ public class Checks {
}
public static void checkVmPendingQuestion(VmPendingQuestion question) {
assertNotNull(question, String.format(NOT_NULL_OBJ_FMT, "VmPendingQuestion"));
// Check required fields
assertNotNull(question.getQuestion(), String.format(OBJ_FIELD_REQ, "VmPendingQuestion", "Question"));
assertNotNull(question.getQuestionId(), String.format(OBJ_FIELD_REQ, "VmPendingQuestion", "QuestionId"));
@ -727,7 +729,7 @@ public class Checks {
// NOTE transport cannot be checked
if (hardware.getItems() != null) {
for (ResourceAllocationSettingData item : hardware.getItems()) {
checkResourceAllocationSettingData((RasdItem) item);
checkResourceAllocationSettingData(item);
}
}
@ -758,7 +760,7 @@ public class Checks {
// assertNotNull(virtualSystem.getVirtualSystemType(), String.format(OBJ_FIELD_REQ, "VirtualSystemSettingData", "virtualSystemType"));
}
public static void checkResourceAllocationSettingData(RasdItem item) {
public static void checkResourceAllocationSettingData(ResourceAllocationSettingData item) {
// TODO
}

View File

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

View File

@ -25,7 +25,6 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkCatalogItem;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkError;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkTask;
@ -35,9 +34,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
@ -64,7 +61,7 @@ import com.google.common.collect.Iterables;
*
* @author grkvlt@apache.org
*/
@Test(groups = { "live", "user", "catalog" }, singleThreaded = true, testName = "CatalogClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "CatalogClientLiveTest")
public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/*
@ -112,22 +109,29 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@AfterClass(alwaysRun = true)
public void tearDown() {
if (catalogItem != null)
catalogClient.deleteCatalogItem(catalogItem.getHref());
if (media != null)
context.getApi().getMediaClient().deleteMedia(media.getHref());
if (adminCatalog != null) {
adminContext.getApi().getCatalogClient().deleteCatalog(adminCatalog.getHref());
if (catalogItem != null) {
try {
catalogClient.getCatalog(catalogRef.getHref());
fail("The Catalog should have been deleted");
} catch (VCloudDirectorException vcde) {
checkError(vcde.getError());
assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The majorErrorCode should be 403 since the item has been deleted");
catalogClient.deleteCatalogItem(catalogItem.getHref());
} catch (Exception e) {
logger.warn(e, "Error when deleting catalog item '%s'", catalogItem.getName());
}
}
if (media != null) {
try {
Task delete = context.getApi().getMediaClient().deleteMedia(media.getHref());
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting media '%s'", media.getName());
}
}
if (adminContext != null && adminCatalog != null) {
try {
adminContext.getApi().getCatalogClient().deleteCatalog(adminCatalog.getHref());
} catch (Exception e) {
logger.warn(e, "Error when deleting catalog '%s'", adminCatalog.getName());
}
}
// TODO wait for tasks
}
@Test(description = "GET /catalog/{id}")

View File

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

View File

@ -32,6 +32,8 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_LIST_SIZE_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_LIST_SIZE_GE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
@ -42,18 +44,15 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Set;
import org.jclouds.io.Payloads;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.CloneMediaParams;
import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.vcloud.director.v1_5.domain.File;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Media;
@ -65,10 +64,12 @@ import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@ -77,7 +78,7 @@ import com.google.common.collect.Iterables;
*
* @author danikov
*/
@Test(groups = { "live", "user", "media" }, singleThreaded = true, testName = "MediaClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "MediaClientLiveTest")
public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String MEDIA = "media";
@ -108,10 +109,20 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@AfterClass(alwaysRun = true)
protected void tidyUp() {
if (media != null) {
assertTaskSucceeds(mediaClient.deleteMedia(media.getHref()));
try {
Task delete = mediaClient.deleteMedia(media.getHref());
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting media '%s': %s", media.getName());
}
}
if (oldMedia != null) {
assertTaskSucceeds(mediaClient.deleteMedia(oldMedia.getHref()));
try {
Task delete = mediaClient.deleteMedia(oldMedia.getHref());
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting media '%s': %s", oldMedia.getName());
}
}
}
@ -137,29 +148,27 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkMediaFor(MEDIA, media);
assertNotNull(media.getFiles(), String.format(OBJ_FIELD_REQ, MEDIA, "files"));
assertTrue(media.getFiles().size() == 1, String.format(OBJ_FIELD_EQ, MEDIA, "files.size()", "1",
media.getFiles().size()));
assertTrue(media.getFiles().size() == 1, String.format(OBJ_FIELD_LIST_SIZE_EQ, MEDIA, "files", 1, media.getFiles().size()));
File uploadFile = getFirst(media.getFiles(), null);
assertNotNull(uploadFile, String.format(OBJ_FIELD_REQ, MEDIA, "files.first"));
assertEquals(uploadFile.getSize(), new Long(iso.length));
assertTrue(equal(uploadFile.getSize(), sourceMedia.getSize()), String.format(OBJ_FIELD_EQ, MEDIA, "uploadFile.size()",
sourceMedia.getSize(), uploadFile.getSize()));
assertEquals(uploadFile.getSize().longValue(), sourceMedia.getSize(),
String.format(OBJ_FIELD_EQ, MEDIA, "uploadFile.size()", sourceMedia.getSize(), uploadFile.getSize()));
Set<Link> links = uploadFile.getLinks();
assertNotNull(links, String.format(OBJ_FIELD_REQ, MEDIA, "uploadFile.links"));
assertTrue(links.size() == 1, String.format(OBJ_FIELD_EQ, MEDIA, "uploadfile.links.size()", "1",
links.size()));
Link uploadLink = getFirst(links, null);
assertTrue(equal(uploadLink.getRel(), Link.Rel.UPLOAD_DEFAULT), String.format(OBJ_FIELD_REQ, MEDIA, "uploadFile.links.first"));
assertTrue(links.size() >= 1, String.format(OBJ_FIELD_LIST_SIZE_GE, MEDIA, "uploadfile.links", 1, links.size()));
assertTrue(Iterables.all(links, Predicates.or(LinkPredicates.relEquals(Link.Rel.UPLOAD_DEFAULT), LinkPredicates.relEquals(Link.Rel.UPLOAD_ALTERNATE))),
String.format(OBJ_FIELD_REQ, MEDIA, "uploadFile.links.first"));
Link uploadLink = Iterables.find(links, LinkPredicates.relEquals(Link.Rel.UPLOAD_DEFAULT));
context.getApi().getUploadClient().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
media = mediaClient.getMedia(media.getHref());
if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), "running");
assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = mediaClient.getMedia(media.getHref());
}

View File

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

View File

@ -36,6 +36,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Network;
import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@ -48,7 +49,7 @@ import com.google.common.collect.Iterables;
*
* @author danikov
*/
@Test(groups = { "live", "user", "network" }, singleThreaded = true, testName = "NetworkClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "NetworkClientLiveTest")
public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String NETWORK = "network";
@ -67,10 +68,14 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@AfterClass(alwaysRun = true)
public void cleanUp() throws Exception {
public void cleanUp() {
if (metadataSet) {
adminContext.getApi().getNetworkClient().getMetadataClient()
.deleteMetadataEntry(toAdminUri(networkURI), "key");
try {
Task delete = adminContext.getApi().getNetworkClient().getMetadataClient().deleteMetadataEntry(toAdminUri(networkURI), "key");
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting metadata");
}
}
}

View File

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

View File

@ -40,6 +40,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Org;
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@ -52,7 +53,7 @@ import com.google.common.collect.Iterables;
*
* @author grkvlt@apache.org
*/
@Test(groups = { "live", "user", "org" }, singleThreaded = true, testName = "OrgClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "OrgClientLiveTest")
public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/*
@ -73,11 +74,17 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@AfterClass(alwaysRun = true)
public void cleanUp() throws Exception {
if (adminMembersSet) {
adminContext.getApi().getOrgClient().getMetadataClient()
.deleteMetadataEntry(toAdminUri(orgURI), "KEY");
adminContext.getApi().getCatalogClient()
.deleteCatalog(catalogRef);
try {
Task delete = adminContext.getApi().getOrgClient().getMetadataClient().deleteMetadataEntry(toAdminUri(orgURI), "KEY");
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry");
}
try {
adminContext.getApi().getCatalogClient().deleteCatalog(catalogRef);
} catch (Exception e) {
logger.warn(e, "Error when deleting catalog'%s': %s", catalogRef);
}
}
}

View File

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

View File

@ -61,7 +61,7 @@ import com.google.common.collect.Iterables;
*
* @author grkvlt@apache.org
*/
@Test(groups = { "live", "user", "query" }, singleThreaded = true, testName = "QueryClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "QueryClientLiveTest")
public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/*
@ -76,9 +76,7 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@AfterClass(alwaysRun = true)
public void cleanUp() throws Exception {
if (vApp != null) {
cleanUpVApp(vApp);
}
if (vApp != null) cleanUpVApp(vApp);
}
@Override

View File

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

View File

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

View File

@ -27,7 +27,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "live", "user", "upload" }, singleThreaded = true, testName = "UploadClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "UploadClientLiveTest")
public class UploadClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String UPLOAD = "upload";

View File

@ -64,7 +64,7 @@ import com.google.common.collect.Multimaps;
*
* @author grkvlt@apache.org
*/
@Test(groups = { "unit", "user", "vapp" }, singleThreaded = true, testName = "VAppClientExpectTest")
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "VAppClientExpectTest")
public class VAppClientExpectTest extends VCloudDirectorAdminClientExpectTest {
private String vAppId = "vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be";

View File

@ -129,51 +129,51 @@ import com.google.common.collect.Sets;
*
* @author grkvlt@apache.org
*/
@Test(groups = { "live", "user", "vapp" }, singleThreaded = true, testName = "VAppClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "VAppClientLiveTest")
public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
private MetadataValue metadataValue;
private String key;
private URI mediaURI;
private URI testUserURI;
private boolean mediaCreated = false;
private boolean testUserCreated = false;
@Override
@BeforeClass(alwaysRun = true)
protected void setupRequiredClients() {
super.setupRequiredClients();
@BeforeClass(alwaysRun = true, dependsOnMethods = { "setupRequiredClients" })
protected void setupRequiredEntities() {
Set<Link> links = vdcClient.getVdc(vdcURI).getLinks();
Predicate<Link> addMediaLink = and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA));
if (contains(links, addMediaLink)) {
Link addMedia = find(links, addMediaLink);
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
if (mediaURI == null) {
Predicate<Link> addMediaLink = and(relEquals(Link.Rel.ADD), typeEquals(VCloudDirectorMediaType.MEDIA));
Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA)
.name("Test media "+random.nextInt())
.size(iso.length)
.imageType(Media.ImageType.ISO)
.description("Test media generated by vAppClientLiveTest")
.build();
Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
if (contains(links, addMediaLink)) {
Link addMedia = find(links, addMediaLink);
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Link uploadLink = getFirst(getFirst(media.getFiles(), null).getLinks(), null);
context.getApi().getUploadClient().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA)
.name("Test media "+random.nextInt())
.size(iso.length)
.imageType(Media.ImageType.ISO)
.description("Test media generated by vAppClientLiveTest")
.build();
Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
media = context.getApi().getMediaClient().getMedia(media.getHref());
Link uploadLink = getFirst(getFirst(media.getFiles(), null).getLinks(), null);
context.getApi().getUploadClient().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = context.getApi().getMediaClient().getMedia(media.getHref());
}
mediaURI = media.getHref();
} else {
mediaURI = super.mediaURI;
if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = context.getApi().getMediaClient().getMedia(media.getHref());
}
mediaURI = media.getHref();
mediaCreated = true;
}
}
if (adminContext != null) {
@ -187,8 +187,20 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Override
@AfterClass(alwaysRun = true)
public void cleanUp() {
if (adminContext != null && mediaURI != null) {
assertTaskDoneEventually(context.getApi().getMediaClient().deleteMedia(mediaURI));
if (adminContext != null && mediaCreated && mediaURI != null) {
try {
Task delete = context.getApi().getMediaClient().deleteMedia(mediaURI);
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn("Error when deleting media: %s", e.getMessage());
}
}
if (adminContext != null && testUserCreated && testUserURI != null) {
try {
adminContext.getApi().getUserClient().deleteUser(testUserURI);
} catch (Exception e) {
logger.warn("Error when deleting user: %s", e.getMessage());
}
}
}

View File

@ -77,7 +77,7 @@ import com.google.common.collect.ImmutableSet;
*
* @author Adam Lowe
*/
@Test(groups = { "unit", "user", "vapptemplate" }, testName = "VAppTemplateClientExpectTest")
@Test(groups = { "unit", "user" }, testName = "VAppTemplateClientExpectTest")
public class VAppTemplateClientExpectTest extends VCloudDirectorAdminClientExpectTest {
public VAppTemplateClientExpectTest() {

View File

@ -84,7 +84,7 @@ import com.google.common.collect.Iterables;
*
* @author Aled Sage
*/
@Test(groups = { "live", "user", "vapptemplate" }, singleThreaded = true, testName = "VAppTemplateClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "VAppTemplateClientLiveTest")
public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
private String key;
@ -93,7 +93,12 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
@AfterClass(alwaysRun = true)
protected void tidyUp() {
if (key != null) {
assertTaskSucceeds(vAppTemplateClient.getMetadataClient().deleteMetadataEntry(vAppTemplateURI, key));
try {
Task delete = vAppTemplateClient.getMetadataClient().deleteMetadataEntry(vAppTemplateURI, key);
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry '%s'", key);
}
}
}

View File

@ -56,7 +56,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "unit", "user", "vdc" }, singleThreaded = true, testName = "VdcClientExpectTest")
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "VdcClientExpectTest")
public class VdcClientExpectTest extends VCloudDirectorAdminClientExpectTest {
private URI vdcURI;

View File

@ -66,7 +66,7 @@ import com.google.common.collect.Iterables;
*
* @author danikov
*/
@Test(groups = { "live", "user", "vdc" }, singleThreaded = true, testName = "VdcClientLiveTest")
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "VdcClientLiveTest")
public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String VDC = "vdc";
@ -118,8 +118,12 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
if (metadataSet) {
adminContext.getApi().getVdcClient().getMetadataClient()
.deleteMetadataEntry(toAdminUri(vdcURI), "key");
try {
Task delete = adminContext.getApi().getVdcClient().getMetadataClient().deleteMetadataEntry(toAdminUri(vdcURI), "key");
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error deleting metadata entry");
}
}
}

View File

@ -40,7 +40,7 @@ import com.google.common.collect.ImmutableSet;
*
* @author grkvlt@apache.org
*/
@Test(groups = { "unit", "admin", "catalog" }, singleThreaded = true, testName = "CatalogClientExpectTest")
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "CatalogClientExpectTest")
public class AdminCatalogClientExpectTest extends VCloudDirectorAdminClientExpectTest {
private Reference catalogRef = Reference.builder()

View File

@ -54,7 +54,7 @@ import com.google.common.collect.Iterables;
*
* @author danikov
*/
@Test(groups = { "live", "admin", "catalog" }, singleThreaded = true, testName = "CatalogClientLiveTest")
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "CatalogClientLiveTest")
public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String CATALOG = "admin catalog";
@ -83,13 +83,10 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
@AfterClass(alwaysRun = true)
protected void tidyUp() {
if (catalog != null) {
catalogClient.deleteCatalog(catalog.getHref());
try { //TODO: predicate to retry for a short while?
catalogClient.getCatalog(catalog.getHref());
fail("The Catalog should have been deleted");
} catch (VCloudDirectorException vcde) {
checkError(vcde.getError());
assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The majorErrorCode should be 403 since the item has been deleted");
try {
catalogClient.deleteCatalog(catalog.getHref());
} catch (Exception e) {
logger.warn(e, "Error deleting admin catalog '%s'", catalog.getName());
}
}
}

View File

@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableSet;
*
* @author danikov
*/
@Test(groups = { "unit", "admin", "network"}, singleThreaded = true, testName = "AdminNetworkClientExpectTest")
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "AdminNetworkClientExpectTest")
public class AdminNetworkClientExpectTest extends VCloudDirectorAdminClientExpectTest {
Reference networkRef = Reference.builder()

View File

@ -51,7 +51,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "live", "admin", "network" }, singleThreaded = true, testName = "AdminNetworkLiveTest")
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "AdminNetworkLiveTest")
public class AdminNetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String NETWORK = "AdminNetwork";

View File

@ -43,7 +43,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "unit", "user", "org"}, singleThreaded = true, testName = "AdminOrgClientExpectTest")
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "AdminOrgClientExpectTest")
public class AdminOrgClientExpectTest extends VCloudDirectorAdminClientExpectTest {
private Reference orgRef = Reference.builder()

View File

@ -47,7 +47,7 @@ import com.google.common.collect.Iterables;
*
* @author danikov
*/
@Test(groups = { "live", "admin", "org" }, singleThreaded = true, testName = "AdminOrgClientLiveTest")
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "AdminOrgClientLiveTest")
public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String ORG = "admin org";

View File

@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableMultimap;
*
* @author Aled Sage
*/
@Test(groups = { "unit", "admin", "query" }, singleThreaded = true, testName = "AdminQueryClientExpectTest")
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "AdminQueryClientExpectTest")
public class AdminQueryClientExpectTest extends VCloudDirectorAdminClientExpectTest {
// TODO Write expect tests for all other admin-query operations

View File

@ -40,7 +40,7 @@ import org.testng.annotations.Test;
*
* @author Aled Sage
*/
@Test(groups = { "live", "admin", "query" }, singleThreaded = true, testName = "AdminQueryClientLiveTest")
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "AdminQueryClientLiveTest")
public class AdminQueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/*

View File

@ -35,7 +35,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "unit", "admin", "vdc" }, singleThreaded = true, testName = "AdminVdcClientExpectTest")
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "AdminVdcClientExpectTest")
public class AdminVdcClientExpectTest extends VCloudDirectorAdminClientExpectTest {
private Reference vdcRef = Reference.builder()

View File

@ -45,7 +45,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "live", "admin", "vdc" }, singleThreaded = true, testName = "AdminVdcClientLiveTest")
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "AdminVdcClientLiveTest")
public class AdminVdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String VDC = "admin vdc";
@ -75,7 +75,7 @@ public class AdminVdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
if (metadataKey != null) {
try {
Task task = metadataClient.deleteMetadataEntry(adminVdcUri, metadataKey);
assertTaskSucceeds(task);
taskDoneEventually(task);
} catch (VCloudDirectorException e) {
logger.warn(e, "Error deleting metadata-value (perhaps it doesn't exist?); continuing...");
}

View File

@ -34,7 +34,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "unit", "admin", "group"}, singleThreaded = true, testName = "GroupClientExpectTest")
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "GroupClientExpectTest")
public class GroupClientExpectTest extends VCloudDirectorAdminClientExpectTest {
private Reference groupRef = Reference.builder()

View File

@ -38,7 +38,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "live", "admin", "group" }, singleThreaded = true, testName = "GroupClientLiveTest")
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "GroupClientLiveTest")
public class GroupClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String GROUP = "admin group";

View File

@ -37,7 +37,7 @@ import org.testng.annotations.Test;
*
* @author danikov
*/
@Test(groups = { "unit", "admin", "adminUser"}, singleThreaded = true, testName = "UserClientExpectTest")
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "UserClientExpectTest")
public class UserClientExpectTest extends VCloudDirectorAdminClientExpectTest {
private Reference orgRef = Reference.builder()

View File

@ -30,7 +30,6 @@ import static org.testng.AssertJUnit.assertFalse;
import java.net.URI;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
@ -49,7 +48,7 @@ import com.google.common.collect.Iterables;
*
* @author danikov
*/
@Test(groups = { "live", "admin", "adminUser" }, singleThreaded = true, testName = "UserClientLiveTest")
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "UserClientLiveTest")
public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public static final String USER = "admin user";
@ -77,8 +76,8 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
if (user != null) {
try {
userClient.deleteUser(user.getHref());
} catch (VCloudDirectorException e) {
// ignore; user probably already deleted
} catch (Exception e) {
logger.warn(e, "Error deleting user '%s'", user.getName());
}
}
}
@ -90,16 +89,14 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
checkUser(newUser);
}
@Test(description = "GET /admin/user/{id}",
dependsOnMethods = { "testCreateUser" })
@Test(description = "GET /admin/user/{id}", dependsOnMethods = { "testCreateUser" })
public void testGetUser() {
user = userClient.getUser(user.getHref());
checkUser(user);
}
@Test(description = "PUT /admin/user/{id}",
dependsOnMethods = { "testGetUser" })
@Test(description = "PUT /admin/user/{id}", dependsOnMethods = { "testGetUser" })
public void testUpdateUser() {
User oldUser = user.toBuilder().build();
User newUser = user.toBuilder()
@ -177,11 +174,13 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
assertTrue(settings.isAccountLockoutEnabled());
for (int i=0; i<settings.getInvalidLoginsBeforeLockout()+1; i++) {
for (int i = 0; i < settings.getInvalidLoginsBeforeLockout() + 1; i++) {
try {
sessionClient.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), orgRef.getName(), "wrongpassword!");
fail("Managed to login using the wrong password!");
} catch(AuthorizationException ex) {
} catch (AuthorizationException e) {
} catch (Exception e) {
fail("Expected AuthorizationException", e);
}
}
@ -191,7 +190,9 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
try {
sessionClient.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), orgRef.getName(), "newPassword");
fail("Managed to login to locked account!");
} catch(AuthorizationException ex) {
} catch (AuthorizationException e) {
} catch (Exception e) {
fail("Expected AuthorizationException", e);
}
userClient.unlockUser(user.getHref());

View File

@ -303,21 +303,31 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
assertTrue(retryTaskSuccessLong.apply(task), String.format(TASK_COMPLETE_TIMELY, task));
}
protected void assertTaskStatusEventually(Task task, Task.Status running, ImmutableSet<Task.Status> immutableSet) {
protected boolean taskStatusEventually(Task task, Task.Status running, ImmutableSet<Task.Status> immutableSet) {
TaskClient taskClient = context.getApi().getTaskClient();
TaskStatusEquals predicate = new TaskStatusEquals(taskClient, running, immutableSet);
RetryablePredicate<Task> retryablePredicate = new RetryablePredicate<Task>(predicate, TASK_TIMEOUT_SECONDS * 1000L);
assertTrue(retryablePredicate.apply(task), "Task must enter status "+running);
return retryablePredicate.apply(task);
}
protected void assertTaskDoneEventually(Task task) {
protected void assertTaskStatusEventually(Task task, Task.Status running, ImmutableSet<Task.Status> immutableSet) {
assertTrue(taskStatusEventually(task, running, immutableSet),
String.format("Task '%s' must reach status %s", task.getOperationName(), running));
}
protected boolean taskDoneEventually(Task task) {
TaskClient taskClient = context.getApi().getTaskClient();
TaskStatusEquals predicate = new TaskStatusEquals(
taskClient,
ImmutableSet.of(Task.Status.ABORTED, Task.Status.CANCELED, Task.Status.ERROR, Task.Status.SUCCESS),
Collections.<Task.Status>emptySet());
RetryablePredicate<Task> retryablePredicate = new RetryablePredicate<Task>(predicate, LONG_TASK_TIMEOUT_SECONDS * 1000L);
assertTrue(retryablePredicate.apply(task), "Task must be done");
return retryablePredicate.apply(task);
}
protected void assertTaskDoneEventually(Task task) {
assertTrue(taskDoneEventually(task),
String.format("Task '%s' must complete", task.getOperationName()));
}
/**
@ -407,10 +417,13 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
protected void cleanUpVAppTemplate(VAppTemplate vAppTemplate) {
VAppTemplateClient vappTemplateClient = context.getApi().getVAppTemplateClient();
Task task = vappTemplateClient.deleteVappTemplate(vAppTemplate.getHref());
assertTaskSucceeds(task);
}
try {
Task task = vappTemplateClient.deleteVappTemplate(vAppTemplate.getHref());
taskDoneEventually(task);
} catch (Exception e) {
logger.warn(e, "Error deleting template '%s'", vAppTemplate.getName());
}
}
protected void cleanUpVApp(VApp vApp) {
cleanUpVApp(vApp.getHref());
@ -434,7 +447,9 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
// Otherwise, get error on delete "entity is busy completing an operation.
if (vApp.getTasks() != null) {
for (Task task : vApp.getTasks()) {
assertTaskDoneEventually(task);
if (!taskDoneEventually(task)) {
logger.warn("Task '%s' did not complete", task.getOperationName());
}
}
}
@ -442,7 +457,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
if (vApp.getStatus().equals(Status.POWERED_ON.getValue())) {
try {
Task shutdownTask = vAppClient.shutdown(vAppURI);
retryTaskSuccess.apply(shutdownTask);
taskDoneEventually(shutdownTask);
} catch (Exception e) {
// keep going; cleanup as much as possible
logger.warn(e, "Continuing cleanup after error shutting down VApp %s", vApp.getName());
@ -454,7 +469,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
try {
UndeployVAppParams params = UndeployVAppParams.builder().build();
Task undeployTask = vAppClient.undeploy(vAppURI, params);
retryTaskSuccess.apply(undeployTask);
taskDoneEventually(undeployTask);
} catch (Exception e) {
// keep going; cleanup as much as possible
logger.warn(e, "Continuing cleanup after error undeploying VApp %s", vApp.getName());
@ -463,7 +478,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
try {
Task task = vAppClient.deleteVApp(vAppURI);
assertTaskSucceeds(task);
taskDoneEventually(task);
vAppNames.remove(vApp.getName());
logger.info("Deleted VApp %s", vApp.getName());
} catch (Exception e) {

View File

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

View File

@ -48,7 +48,7 @@ import com.google.inject.Module;
* @author Adrian Cole
*/
@Listeners(FormatApiResultsListener.class)
@Test(groups = { "live", "user", "login" }, testName = "SessionClientLiveTest")
@Test(groups = { "live", "user" }, testName = "SessionClientLiveTest")
public class SessionClientLiveTest extends BaseVersionedServiceLiveTest {
public SessionClientLiveTest() {
provider = "vcloud-director";
@ -73,7 +73,7 @@ public class SessionClientLiveTest extends BaseVersionedServiceLiveTest {
private SessionClient client;
private SessionWithToken sessionWithToken;
@Test(testName = "POST /sessions")
@Test(description = "POST /sessions")
public void testLogin() {
String user = identity.substring(0, identity.lastIndexOf('@'));
String org = identity.substring(identity.lastIndexOf('@') + 1);
@ -86,13 +86,13 @@ public class SessionClientLiveTest extends BaseVersionedServiceLiveTest {
assertNotNull(sessionWithToken.getToken());
}
@Test(testName = "GET /session", dependsOnMethods = "testLogin")
@Test(description = "GET /session", dependsOnMethods = "testLogin")
public void testGetSession() {
assertEquals(client.getSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken()),
sessionWithToken.getSession());
}
@Test(testName = "DELETE /session", dependsOnMethods = "testGetSession")
@Test(description = "DELETE /session", dependsOnMethods = "testGetSession")
public void testLogout() {
client.logoutSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken());
}