Query and catalog expect and live testing along with Checks and other cliemt and domain object fixes

This commit is contained in:
Andrew Donald Kennedy 2012-02-17 01:40:29 +00:00
parent 97f4d09778
commit 973ef7e167
18 changed files with 470 additions and 66 deletions

View File

@ -6,8 +6,7 @@ import java.net.URI;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "catalogReference")
@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "CatalogReference")
public class CatalogReference extends ReferenceType<CatalogReference> {
@SuppressWarnings("unchecked")
@ -91,7 +90,7 @@ public class CatalogReference extends ReferenceType<CatalogReference> {
return true;
if (o == null || getClass() != o.getClass())
return false;
Reference that = Reference.class.cast(o);
CatalogReference that = CatalogReference.class.cast(o);
return super.equals(that);
}
}

View File

@ -85,11 +85,11 @@ public class Reference extends ReferenceType<Reference> {
}
@Override
protected Builder fromReferenceType(ReferenceType<Reference> in) {
public Builder fromReferenceType(ReferenceType<Reference> in) {
return Builder.class.cast(super.fromReferenceType(in));
}
protected Builder fromReference(Reference in) {
public Builder fromReference(Reference in) {
return fromReferenceType(in);
}
}

View File

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
@ -69,6 +70,24 @@ public class CatalogReferences extends QueryResultReferences<CatalogReference> {
return queryResultReferences;
}
/**
* @see QueryResultReferences#getReferences()
*/
@Override
public Builder references(List<CatalogReference> references) {
this.references = references;
return this;
}
/**
* @see QueryResultReferences#getReferences()
*/
@Override
public Builder reference(CatalogReference reference) {
this.references.add(reference);
return this;
}
/**
* @see Container#getName()
*/
@ -96,6 +115,15 @@ public class CatalogReferences extends QueryResultReferences<CatalogReference> {
return this;
}
/**
* @see Container#getTotal()
*/
@Override
public Builder total(Long total) {
this.total = total;
return this;
}
/**
* @see ResourceType#getHref()
*/
@ -134,11 +162,11 @@ public class CatalogReferences extends QueryResultReferences<CatalogReference> {
@Override
public Builder fromQueryResultReferences(QueryResultReferences<CatalogReference> in) {
return Builder.class.cast(super.fromContainerType(in));
return Builder.class.cast(super.fromQueryResultReferences(in));
}
public Builder fromCatalogReferences(CatalogReferences in) {
return Builder.class.cast(fromQueryResultReferences(in).references(in.getReferences()));
return fromQueryResultReferences(in);
}
}

View File

@ -26,6 +26,7 @@ import java.net.URI;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.ResourceType;

View File

@ -52,10 +52,7 @@ import com.google.common.collect.Sets;
* @author grkvlt@apache.org
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({
QueryResultCatalogRecord.class,
QueryResultNetworkRecord.class,
})
@XmlSeeAlso({ QueryResultCatalogRecord.class, QueryResultNetworkRecord.class })
public class QueryResultRecordType<T extends QueryResultRecordType<T>> {
public static <T extends QueryResultRecordType<T>> Builder<T> builder() {

View File

@ -21,15 +21,16 @@ package org.jclouds.vcloud.director.v1_5.domain.query;
import static com.google.common.base.Objects.*;
import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.CatalogReference;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
@ -120,6 +121,15 @@ public class QueryResultReferences<T extends ReferenceType<T>> extends Container
return this;
}
/**
* @see Container#getTotal()
*/
@Override
public Builder<T> total(Long total) {
this.total = total;
return this;
}
/**
* @see ResourceType#getHref()
*/
@ -174,7 +184,10 @@ public class QueryResultReferences<T extends ReferenceType<T>> extends Container
super(href);
}
@XmlElementRef(name = "Reference", namespace = VCLOUD_1_5_NS)
// NOTE add other types as they are used. probably not the best way to do this.
@XmlElementRefs({
@XmlElementRef(type = CatalogReference.class)
})
protected List<T> references;
/**

View File

@ -19,15 +19,17 @@
package org.jclouds.vcloud.director.v1_5.features;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryList;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
@ -39,11 +41,27 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author grkvlt@apache.org
*/
@RequestFilters(AddVCloudAuthorizationToRequest.class)
@SkipEncoding({ '=' })
@SuppressWarnings("rawtypes")
public interface QueryAsyncClient {
/**
* REST API General queries handler.
*/
@GET
@Path("/query")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<QueryList> queryList();
@GET
@Path("/query")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<QueryResultRecords> queryAll(@QueryParam("type") String type);
@GET
@Path("/query")
@Consumes
@ -62,6 +80,13 @@ public interface QueryAsyncClient {
/**
* Retrieves a list of Catalogs by using REST API general QueryHandler.
*/
@GET
@Path("/catalogs/query")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<QueryResultRecords> catalogsQueryAll();
@GET
@Path("/catalogs/query")
@Consumes
@ -75,13 +100,20 @@ public interface QueryAsyncClient {
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<QueryResultRecords> catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize,
@QueryParam("format") String format, @QueryParam("filter") String filter);
@QueryParam("filter") String filter);
@GET
@Path("/catalogs/query")
@Consumes
@DefaultValue("references")
@QueryParam("format")
@QueryParams(keys = { "format" }, values = { "references" })
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<CatalogReferences> catalogReferencesQueryAll();
@GET
@Path("/catalogs/query")
@Consumes
@QueryParams(keys = { "format" }, values = { "references" })
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<CatalogReferences> catalogReferencesQuery(@QueryParam("filter") String filter);
@ -89,8 +121,7 @@ public interface QueryAsyncClient {
@GET
@Path("/catalogs/query")
@Consumes
@DefaultValue("references")
@QueryParam("format")
@QueryParams(keys = { "format" }, values = { "references" })
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<CatalogReferences> catalogReferencesQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize,

View File

@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryList;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
/**
@ -40,6 +41,10 @@ public interface QueryClient {
* GET /query
* </pre>
*/
QueryList queryList();
QueryResultRecords queryAll(String type);
QueryResultRecords query(String type, String filter);
QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter);
@ -55,9 +60,13 @@ public interface QueryClient {
* GET /catalogs/query
* </pre>
*/
QueryResultRecords catalogsQueryAll();
QueryResultRecords catalogsQuery(String filter);
QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String format, String filter);
QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String filter);
CatalogReferences catalogReferencesQueryAll();
CatalogReferences catalogReferencesQuery(String filter);

View File

@ -1,4 +1,4 @@
/**
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -121,9 +121,9 @@ public class Checks {
public static void checkLink(Link link) {
// Check required fields
assertNotNull(link.getRel(), "The Rel attribute of a Link must be set");
assertTrue(Link.Rel.ALL.contains(link.getRel()),
String.format("The Rel attribute (%s) of a Link must be one of the allowed list - %s",
link.getRel(), Iterables.toString(Link.Rel.ALL)));
// XXX choose one
assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link must be from the allowed list: %s", Iterables.toString(Link.Rel.ALL)));
assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link cannot be '%s'", link.getRel()));
// Check parent type
checkReferenceType(link);
@ -132,9 +132,9 @@ public class Checks {
public static void checkTask(Task task) {
// Check required fields
assertNotNull(task.getStatus(), "The Status attribute of a Task must be set");
assertTrue(Task.Status.ALL.contains(task.getStatus().toString()),
String.format("The Status of a Task (%s) must be one of the allowed list - %s",
task.getStatus().toString(), Iterables.toString(Task.Status.ALL)));
// XXX choose one
assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task must be from the allowed list: %s", Iterables.toString(Task.Status.ALL)));
assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task cannot be '%s'", task.getStatus()));
// Check optional fields
// NOTE operation cannot be checked
@ -174,6 +174,24 @@ public class Checks {
checkEntityType(file);
}
public static void checkMetadata(Metadata metadata) {
Set<MetadataEntry> metadataEntries = metadata.getMetadataEntries();
if (metadataEntries != null && !metadataEntries.isEmpty()) {
for (MetadataEntry metadataEntry : metadataEntries) checkMetadataEntry(metadataEntry);
}
// Check parent type
checkResourceType(metadata);
}
public static void checkMetadataEntry(MetadataEntry metadataEntry) {+ // Check required fields
assertNotNull(metadataEntry.getKey(), "The Key attribute of a MetadataEntry must be set");
assertNotNull(metadataEntry.getValue(), "The Value attribute of a MetadataEntry must be set");
// Check parent type
checkResourceType(metadataEntry);
}
public static void checkProgress(Integer progress) {
assertTrue(progress >= 0 && progress <= 100, "The Progress attribute must be between 0 and 100");
}
@ -188,6 +206,27 @@ public class Checks {
// NOTE stackTrace cannot be checked
}
public static void checkCatalog(Catalog catalog) {
// Check optional elements/attributes
Entity owner = catalog.getOwner();
if (owner != null) checkEntityType(owner);
CatalogItems catalogItems = catalog.getCatalogItems();
if (catalogItems != null) {
for (Reference catalogItemReference : catalogItems.getCatalogItems()) {
checkReferenceType(catalogItemReference);
}
}
// NOTE isPublished cannot be checked
// Check parent type
checkEntityType(catalog);
}
public static void checkCatalogItem(CatalogItem catalogItem) {
// Check parent type
checkEntityType(catalogItem);
}
public static void checkImageType(String imageType) {
assertTrue(Media.ImageType.ALL.contains(imageType),
"The Image type of a Media must be one of the allowed list");

View File

@ -18,18 +18,26 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkTask;
import static org.testng.Assert.assertFalse;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.*;
import static org.testng.Assert.*;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
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.Reference;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TasksList;
import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
/**
@ -40,23 +48,146 @@ import com.google.common.collect.Iterables;
@Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest")
public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private static final String CATALOG_NAME = "QunyingTestCatalog"; // TODO add as test configuration property
/*
* Convenience references to API clients.
*/
private final CatalogClient catalogClient = context.getApi().getCatalogClient();
private final QueryClient queryClient = context.getApi().getQueryClient();
private CatalogClient catalogClient;
private QueryClient queryClient;
/*
* Shared state between dependant tests.
*/
private Reference catalogRef;
private ReferenceType<?> catalogRef;
private ReferenceType<?> catalogItemRef;
private ReferenceType<?> newCatalogItemRef;
private Catalog catalog;
private CatalogItem catalogItem;
private CatalogItem newCatalogItem;
private Metadata catalogMetadata;
@BeforeGroups(groups = { "live" })
public void setupClients() {
catalogClient = context.getApi().getCatalogClient();
queryClient = context.getApi().getQueryClient();
}
@Test(testName = "GET /catalog/{id}")
public void testGetTaskList() {
catalogRef = null;
public void testGetCatalog() {
CatalogReferences catalogReferences = queryClient.catalogReferencesQuery(String.format("name==%s", CATALOG_NAME));
assertEquals(Iterables.size(catalogReferences.getReferences()), 1, String.format("The %s Catalog must exist", CATALOG_NAME));
catalogRef = Iterables.getOnlyElement(catalogReferences.getReferences());
catalog = catalogClient.getCatalog(catalogRef);
}
@Test(testName = "GET /catalogItem/{id}", dependsOnMethods = { "testGetCatalog" })
public void testGetCatalogItem() {
assertFalse(Iterables.isEmpty(catalog.getCatalogItems().getCatalogItems()));
catalogItemRef = Iterables.get(catalog.getCatalogItems().getCatalogItems(), 0);
catalogItem = catalogClient.getCatalogItem(catalogItemRef);
checkCatalogItem(catalogItem);
}
// NOTE for this test to work, we need to be able to upload a new vAppTemplate to a vDC first
// NOTE we could do this with a test environment property -Dtest.vcloud-director.vappTemplateId=vapptemplate-abcd
@Test(testName = "POST /catalog/{id}/catalogItems", dependsOnMethods = { "testGetCatalogItem" }, enabled = false)
public void testAddCatalogItem() {
CatalogItem editedCatalogItem = CatalogItem.builder()
.name("newitem")
.description("New Item")
// XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The VCD entity image already exists.
// .entity(Reference.builder().href(catalogItem.getEntity().getHref()).build())
// XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The VCD entity ubuntu10 already exists.
// .entity(Reference.builder().href(URI.create(endpoint + "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")).build())
.build();
newCatalogItem = catalogClient.addCatalogItem(catalogRef, editedCatalogItem);
checkCatalogItem(newCatalogItem);
assertEquals(newCatalogItem.getName(), "newitem");
}
@Test(testName = "PUT /catalogItem/{id}", dependsOnMethods = { "testAddCatalogItem" }, enabled = false)
public void testUpdateCatalogItem() {
Catalog catalog = catalogClient.getCatalog(catalogRef);
newCatalogItemRef = Iterables.find(catalog.getCatalogItems().getCatalogItems(), new Predicate<Reference>() {
@Override
public boolean apply(Reference input) {
return input.getHref().equals(newCatalogItem.getHref());
}
});
CatalogItem updatedCatalogItem = CatalogItem.builder().fromCatalogItem(catalogItem).name("UPDATEDNAME").build();
newCatalogItem = catalogClient.updateCatalogItem(catalogRef, updatedCatalogItem);
checkCatalogItem(newCatalogItem);
assertEquals(newCatalogItem.getName(), "UPDATEDNAME");
}
@Test(testName = "DELETE /catalogItem/{id}", dependsOnMethods = { "testUpdateCatalogItem" }, enabled = false)
public void testDeleteCatalogItem() {
catalogClient.deleteCatalogItem(newCatalogItemRef);
try {
catalogClient.getCatalogItem(newCatalogItemRef);
fail("The CatalogItem 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");
}
}
// NOTE for this test to work, we need to be able to create metadata on a Catalog, specifically { "KEY", "VALUE" }
@Test(testName = "GET /catalog/{id}/metadata", dependsOnMethods = { "testGetCatalog" }, enabled = false)
public void testGetCatalogMetadata() {
catalogMetadata = catalogClient.getCatalogMetadata(catalogRef);
checkMetadata(catalogMetadata);
}
// NOTE for this test to work, we need to be able to create metadata on a Catalog, specifically { "KEY", "VALUE" }
@Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testGetCatalogMetadata" }, enabled = false)
public void testGetCatalogMetadataEntry() {
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), new Predicate<MetadataEntry>() {
@Override
public boolean apply(MetadataEntry input) {
return input.getKey().equals("KEY");
}
});
MetadataEntry metadataEntry = catalogClient.getCatalogMetadataEntry(catalogRef, "KEY");
assertEquals(existingMetadataEntry.getValue(), metadataEntry.getValue());
checkMetadataEntry(metadataEntry);
}
@Test(testName = "POST /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItem" })
public void testMergeCatalogItemMetadata() {
Metadata newMetadata = Metadata.builder()
.entry(MetadataEntry.builder().entry("KEY", "VALUE").build())
.build();
Task task = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata);
// TODO wait until task no longer running...
}
@Test(testName = "GET /catalogItem/{id}/metadata", dependsOnMethods = { "testMergeCatalogItemMetadata" })
public void testGetCatalogItemMetadata() {
Metadata metadata = catalogClient.getCatalogItemMetadata(catalogItemRef);
}
// XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The access to the resource metadata_item with id KEY is forbidden
@Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }, enabled = false)
public void testGetCatalogItemMetadataEntry() {
MetadataEntry metadataEntry = catalogClient.getCatalogItemMetadataEntry(catalogItemRef, "KEY");
}
@Test(testName = "PUT /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" })
public void testSetCatalogItemMetadataEntry() {
MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build();
Task task = catalogClient.setCatalogItemMetadataEntry(catalogItemRef, "KEY", newMetadataValue);
// TODO wait until task no longer running...
}
@Test(testName = "DELETE /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" })
public void testDeleteCatalogItemMetadataEntry() {
Task task = catalogClient.deleteCatalogItemMetadataEntry(catalogItemRef, "KEY");
// TODO wait until task no longer running...
}
}

View File

@ -18,8 +18,7 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import static org.testng.Assert.*;
import java.net.URI;
@ -30,15 +29,27 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code NetworkClient}
* Tests behavior of {@link NetworkClient}
*
* @author danikov
*/
@Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest")
public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/*
* Convenience references to API clients.
*/
private NetworkClient networkClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
networkClient = context.getApi().getNetworkClient();
}
// @Before populate
String networkId = "55a677cf-ab3f-48ae-b880-fab90421980c";
@ -49,7 +60,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/"+networkId)).build();
OrgNetwork network = context.getApi().getNetworkClient().getNetwork(networkRef);
OrgNetwork network = networkClient.getNetwork(networkRef);
//TODO assert network is valid
}
@ -66,7 +77,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.build();
try {
context.getApi().getNetworkClient().getNetwork(networkRef);
networkClient.getNetwork(networkRef);
fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
@ -87,7 +98,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.build();
try {
context.getApi().getNetworkClient().getNetwork(networkRef);
networkClient.getNetwork(networkRef);
fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
@ -108,7 +119,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.build();
try {
context.getApi().getNetworkClient().getNetwork(networkRef);
networkClient.getNetwork(networkRef);
fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
@ -137,7 +148,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint + "/network/"+networkId)).build();
MetadataEntry expected = context.getApi().getNetworkClient().getMetadataEntry(networkRef, metadataKey);
MetadataEntry expected = networkClient.getMetadataEntry(networkRef, metadataKey);
// assert metadataEntry is valid
}

View File

@ -29,6 +29,7 @@ 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.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
@ -45,7 +46,12 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
* Convenience references to API clients.
*/
private final OrgClient orgClient = context.getApi().getOrgClient();
private OrgClient orgClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
orgClient = context.getApi().getOrgClient();
}
/*
* Shared state between dependant tests.

View File

@ -26,7 +26,9 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.CatalogReference;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultCatalogRecord;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
@ -43,10 +45,10 @@ import com.google.common.collect.ImmutableMultimap;
public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test
public void testQueryCatalogNoParam() {
public void testQueryAllCatalogs() {
HttpRequest queryRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/catalogs/query?filter="))
.endpoint(URI.create(endpoint + "/catalogs/query"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
@ -115,7 +117,71 @@ public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTes
.build())
.build();
assertEquals(client.getQueryClient().catalogsQuery(""), expected);
assertEquals(client.getQueryClient().catalogsQueryAll(), expected);
}
@Test
public void testQueryAllCatalogReferences() {
HttpRequest queryRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/catalogs/query?format=references"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse queryResponse= HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/query/allCatalogReferences.xml", VCloudDirectorMediaType.QUERY_RESULT_RECORDS + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, queryRequest, queryResponse);
CatalogReferences expected = CatalogReferences.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=references"))
.type("application/vnd.vmware.vcloud.query.references+xml")
.name("catalog")
.page(1)
.pageSize(25)
.total(4L)
.link(Link.builder()
.rel("alternate")
.type("application/vnd.vmware.vcloud.query.records+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=records"))
.build())
.link(Link.builder()
.rel("alternate")
.type("application/vnd.vmware.vcloud.query.idrecords+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=idrecords"))
.build())
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("QunyingTestCatalog")
.id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build())
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Public")
.id("urn:vcloud:catalog:9e08c2f6-077a-42ce-bece-d5332e2ebb5c")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.build())
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("dantest")
.id("urn:vcloud:catalog:b542aff4-9f97-4f51-a126-4330fbf62f02")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/b542aff4-9f97-4f51-a126-4330fbf62f02"))
.build())
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("test")
.id("urn:vcloud:catalog:b7289d54-4ca4-497f-9a93-2d4afc97e3da")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/b7289d54-4ca4-497f-9a93-2d4afc97e3da"))
.build())
.build();
assertEquals(client.getQueryClient().catalogReferencesQueryAll(), expected);
}
}

View File

@ -18,23 +18,18 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.*;
import static org.testng.Assert.*;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
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.domain.TasksList;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of {@link QueryClient}.
*
@ -47,8 +42,14 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
* Convenience references to API clients.
*/
private final CatalogClient catalogClient = context.getApi().getCatalogClient();
private final QueryClient queryClient = context.getApi().getQueryClient();
private CatalogClient catalogClient;
private QueryClient queryClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
catalogClient = context.getApi().getCatalogClient();
queryClient = context.getApi().getQueryClient();
}
/*
* Shared state between dependant tests.

View File

@ -18,7 +18,6 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.*;
import static org.testng.Assert.*;
@ -29,6 +28,7 @@ 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.TasksList;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
@ -45,8 +45,14 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest {
* Convenience references to API clients.
*/
private final OrgClient orgClient = context.getApi().getOrgClient();
private final TaskClient taskClient = context.getApi().getTaskClient();
private OrgClient orgClient;
private TaskClient taskClient;
@BeforeGroups(groups = { "live" })
public void setupClients() {
orgClient = context.getApi().getOrgClient();
taskClient = context.getApi().getTaskClient();
}
/*
* Shared state between dependant tests.

View File

@ -62,4 +62,3 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<CatalogReferences xmlns="http://www.vmware.com/vcloud/v1.5" total="4" pageSize="25" page="1" name="catalog" type="application/vnd.vmware.vcloud.query.references+xml" href="https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&amp;pageSize=25&amp;format=references" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="alternate" type="application/vnd.vmware.vcloud.query.records+xml" href="https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&amp;pageSize=25&amp;format=records"/>
<Link rel="alternate" type="application/vnd.vmware.vcloud.query.idrecords+xml" href="https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&amp;pageSize=25&amp;format=idrecords"/>
<CatalogReference type="application/vnd.vmware.vcloud.catalog+xml" name="QunyingTestCatalog" id="urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<CatalogReference type="application/vnd.vmware.vcloud.catalog+xml" name="Public" id="urn:vcloud:catalog:9e08c2f6-077a-42ce-bece-d5332e2ebb5c" href="https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"/>
<CatalogReference type="application/vnd.vmware.vcloud.catalog+xml" name="dantest" id="urn:vcloud:catalog:b542aff4-9f97-4f51-a126-4330fbf62f02" href="https://vcloudbeta.bluelock.com/api/catalog/b542aff4-9f97-4f51-a126-4330fbf62f02"/>
<CatalogReference type="application/vnd.vmware.vcloud.catalog+xml" name="test" id="urn:vcloud:catalog:b7289d54-4ca4-497f-9a93-2d4afc97e3da" href="https://vcloudbeta.bluelock.com/api/catalog/b7289d54-4ca4-497f-9a93-2d4afc97e3da"/>
</CatalogReferences>

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<QueryList xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.vcloud.query.queryList+xml" href="https://vcloudbeta.bluelock.com/api/query" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="organization" href="https://vcloudbeta.bluelock.com/api/query?type=organization&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="organization" href="https://vcloudbeta.bluelock.com/api/query?type=organization&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="organization" href="https://vcloudbeta.bluelock.com/api/query?type=organization&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="orgVdc" href="https://vcloudbeta.bluelock.com/api/query?type=orgVdc&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="orgVdc" href="https://vcloudbeta.bluelock.com/api/query?type=orgVdc&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="orgVdc" href="https://vcloudbeta.bluelock.com/api/query?type=orgVdc&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="media" href="https://vcloudbeta.bluelock.com/api/query?type=media&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="media" href="https://vcloudbeta.bluelock.com/api/query?type=media&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="media" href="https://vcloudbeta.bluelock.com/api/query?type=media&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="vAppTemplate" href="https://vcloudbeta.bluelock.com/api/query?type=vAppTemplate&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="vAppTemplate" href="https://vcloudbeta.bluelock.com/api/query?type=vAppTemplate&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="vAppTemplate" href="https://vcloudbeta.bluelock.com/api/query?type=vAppTemplate&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="vApp" href="https://vcloudbeta.bluelock.com/api/query?type=vApp&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="vApp" href="https://vcloudbeta.bluelock.com/api/query?type=vApp&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="vApp" href="https://vcloudbeta.bluelock.com/api/query?type=vApp&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="vm" href="https://vcloudbeta.bluelock.com/api/query?type=vm&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="vm" href="https://vcloudbeta.bluelock.com/api/query?type=vm&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="vm" href="https://vcloudbeta.bluelock.com/api/query?type=vm&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="orgNetwork" href="https://vcloudbeta.bluelock.com/api/query?type=orgNetwork&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="orgNetwork" href="https://vcloudbeta.bluelock.com/api/query?type=orgNetwork&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="orgNetwork" href="https://vcloudbeta.bluelock.com/api/query?type=orgNetwork&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="vAppNetwork" href="https://vcloudbeta.bluelock.com/api/query?type=vAppNetwork&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="vAppNetwork" href="https://vcloudbeta.bluelock.com/api/query?type=vAppNetwork&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="vAppNetwork" href="https://vcloudbeta.bluelock.com/api/query?type=vAppNetwork&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="catalog" href="https://vcloudbeta.bluelock.com/api/query?type=catalog&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="catalog" href="https://vcloudbeta.bluelock.com/api/query?type=catalog&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="catalog" href="https://vcloudbeta.bluelock.com/api/query?type=catalog&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="group" href="https://vcloudbeta.bluelock.com/api/query?type=group&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="group" href="https://vcloudbeta.bluelock.com/api/query?type=group&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="group" href="https://vcloudbeta.bluelock.com/api/query?type=group&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="user" href="https://vcloudbeta.bluelock.com/api/query?type=user&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="user" href="https://vcloudbeta.bluelock.com/api/query?type=user&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="user" href="https://vcloudbeta.bluelock.com/api/query?type=user&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="strandedUser" href="https://vcloudbeta.bluelock.com/api/query?type=strandedUser&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="strandedUser" href="https://vcloudbeta.bluelock.com/api/query?type=strandedUser&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="strandedUser" href="https://vcloudbeta.bluelock.com/api/query?type=strandedUser&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="role" href="https://vcloudbeta.bluelock.com/api/query?type=role&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="role" href="https://vcloudbeta.bluelock.com/api/query?type=role&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="role" href="https://vcloudbeta.bluelock.com/api/query?type=role&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="allocatedExternalAddress" href="https://vcloudbeta.bluelock.com/api/query?type=allocatedExternalAddress&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="allocatedExternalAddress" href="https://vcloudbeta.bluelock.com/api/query?type=allocatedExternalAddress&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="event" href="https://vcloudbeta.bluelock.com/api/query?type=event&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="event" href="https://vcloudbeta.bluelock.com/api/query?type=event&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="right" href="https://vcloudbeta.bluelock.com/api/query?type=right&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="right" href="https://vcloudbeta.bluelock.com/api/query?type=right&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="right" href="https://vcloudbeta.bluelock.com/api/query?type=right&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="vAppOrgNetworkRelation" href="https://vcloudbeta.bluelock.com/api/query?type=vAppOrgNetworkRelation&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="vAppOrgNetworkRelation" href="https://vcloudbeta.bluelock.com/api/query?type=vAppOrgNetworkRelation&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="vAppOrgNetworkRelation" href="https://vcloudbeta.bluelock.com/api/query?type=vAppOrgNetworkRelation&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="catalogItem" href="https://vcloudbeta.bluelock.com/api/query?type=catalogItem&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="catalogItem" href="https://vcloudbeta.bluelock.com/api/query?type=catalogItem&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="catalogItem" href="https://vcloudbeta.bluelock.com/api/query?type=catalogItem&amp;format=idrecords"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.references+xml" name="task" href="https://vcloudbeta.bluelock.com/api/query?type=task&amp;format=references"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.records+xml" name="task" href="https://vcloudbeta.bluelock.com/api/query?type=task&amp;format=records"/>
<Link rel="down" type="application/vnd.vmware.vcloud.query.idrecords+xml" name="task" href="https://vcloudbeta.bluelock.com/api/query?type=task&amp;format=idrecords"/>
</QueryList>