vmsQuery(@QueryParam("filter") String filter);
}
diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java
index e6e29931d4..7d8d907379 100644
--- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java
+++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java
@@ -21,6 +21,11 @@ package org.jclouds.vcloud.director.v1_5.features;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
+import org.jclouds.vcloud.director.v1_5.domain.Catalog;
+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.VApp;
+import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
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;
@@ -102,6 +107,20 @@ public interface QueryClient {
/** @see #catalogReferencesQueryAll() */
CatalogReferences catalogReferencesQuery(Integer page, Integer pageSize, String filter);
+ /**
+ * Retrieves a list of {@link VAppTemplate}s by using REST API general QueryHandler.
+ *
+ *
+ * GET /vAppTemplates/query
+ *
+ *
+ * @see #queryAll(String)
+ */
+ QueryResultRecords vAppTemplatesQueryAll();
+
+ /** @see #queryAll() */
+ QueryResultRecords vAppTemplatesQuery(String filter);
+
/**
* Retrieves a list of {@link VApp}s by using REST API general QueryHandler.
*
@@ -119,6 +138,20 @@ public interface QueryClient {
/** @see #queryAll() */
QueryResultRecords vAppsQuery(Integer page, Integer pageSize, String filter);
+ /**
+ * Retrieves a list of {@link Vm}s by using REST API general QueryHandler.
+ *
+ *
+ * GET /vms/query
+ *
+ *
+ * @see #queryAll(String)
+ */
+ QueryResultRecords vmsQueryAll();
+
+ /** @see #queryAll() */
+ QueryResultRecords vmsQuery(String filter);
+
/**
* Retrieves a list of {@link VAppReference}s by using REST API general QueryHandler.
*
diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java
index 551fe66683..64c07737f1 100644
--- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java
+++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java
@@ -19,9 +19,21 @@
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
+import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences;
+import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeClass;
@@ -39,32 +51,80 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
* Convenience references to API clients.
*/
- private CatalogClient catalogClient;
private QueryClient queryClient;
+ private VAppTemplateClient vappTemplateClient;
@Override
@BeforeClass(inheritGroups = true)
public void setupRequiredClients() {
- catalogClient = context.getApi().getCatalogClient();
queryClient = context.getApi().getQueryClient();
+ vappTemplateClient = context.getApi().getVAppTemplateClient();
}
- /*
- * Shared state between dependant tests.
- */
-
- private QueryResultRecords catalogRecords;
- private CatalogReferences catalogReferences;
-
@Test(testName = "GET /catalogs/query")
public void testQueryAllCatalogs() {
- catalogRecords = queryClient.catalogsQueryAll();
+ QueryResultRecords catalogRecords = queryClient.catalogsQueryAll();
assertFalse(catalogRecords.getRecords().isEmpty(), String.format(NOT_EMPTY_OBJECT_FMT, "CatalogRecord", "QueryResultRecords"));
}
@Test(testName = "GET /catalogs/query?format=references", dependsOnMethods = { "testQueryAllCatalogs" })
public void testQueryAllCatalogReferences() {
- catalogReferences = queryClient.catalogReferencesQueryAll();
+ CatalogReferences catalogReferences = queryClient.catalogReferencesQueryAll();
assertFalse(catalogReferences.getReferences().isEmpty(), String.format(NOT_EMPTY_OBJECT_FMT, "CatalogReference", "CatalogReferences"));
}
-}
\ No newline at end of file
+
+ @Test(testName = "GET /vAppTemplates/query")
+ public void testQueryAllVAppTemplates() {
+ QueryResultRecords queryResult = queryClient.vAppTemplatesQueryAll();
+ Set hrefs = toHrefs(queryResult);
+
+ assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VAPP_TEMPLATE, null));
+ assertTrue(hrefs.contains(vAppTemplateURI), "VAppTemplates query result should include vAppTemplate "+vAppTemplateURI+"; but only has "+hrefs);
+ }
+
+ @Test(testName = "GET /vAppTemplates/query?filter)")
+ public void testQueryVAppTemplates() {
+ VAppTemplate vAppTemplate = vappTemplateClient.getVAppTemplate(vAppTemplateURI);
+ QueryResultRecords queryResult = queryClient.vAppTemplatesQuery(String.format("name==%s", vAppTemplate.getName()));
+ Set hrefs = toHrefs(queryResult);
+
+ assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VAPP_TEMPLATE, null));
+ assertEquals(hrefs, Collections.singleton(vAppTemplateURI), "VAppTemplates query result should have found vAppTemplate "+vAppTemplateURI);
+ }
+
+ @Test(testName = "GET /vApps/query")
+ public void testQueryAllVApps() {
+ // TODO instantiate a vApp, so can assert it's included
+
+ QueryResultRecords queryResult = queryClient.vAppsQueryAll();
+ Set hrefs = toHrefs(queryResult);
+
+ assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VAPP, null));
+ //assertTrue(hrefs.contains(vappUri), "VApp query result should include vapp "+vappUri+"; but only has "+hrefs);
+ }
+
+ @Test(testName = "GET /vms/query")
+ public void testQueryAllVms() {
+ // TODO instantiate a vApp + vms, so can assert it's included
+
+ QueryResultRecords queryResult = queryClient.vmsQueryAll();
+ Set hrefs = toHrefs(queryResult);
+
+ assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VM, null));
+ //assertTrue(hrefs.contains(vappUri), "VApp query result should include vapp "+vappUri+"; but only has "+hrefs);
+ }
+
+ private void assertRecordTypes(QueryResultRecords queryResult, Collection validTypes) {
+ for (QueryResultRecordType record : queryResult.getRecords()) {
+ assertTrue(validTypes.contains(record.getType()), "invalid type for query result record, "+record.getType()+"; valid types are "+validTypes);
+ }
+ }
+
+ private Set toHrefs(QueryResultRecords queryResult) {
+ Set hrefs = new LinkedHashSet();
+ for (QueryResultRecordType record : queryResult.getRecords()) {
+ hrefs.add(record.getHref());
+ }
+ return hrefs;
+ }
+}