Merge pull request #516 from grkvlt/vcloud

Issue 830: Add new entity operation to QueryClient
This commit is contained in:
Adrian Cole 2012-03-23 12:07:06 -07:00
commit cb370ab26d
14 changed files with 164 additions and 244 deletions

View File

@ -38,6 +38,8 @@ public class VCloudDirectorMediaType {
public static final String ANY_IMAGE = "image/*";
public static final String TEXT_XML = "text/xml";
/** The default {@literal Accept} header for the vCloud API. */
public static final String APPLICATION_XML_1_5 = "application/*+xml;version=1.5";
@ -190,10 +192,10 @@ public class VCloudDirectorMediaType {
public static final String VAPP_NETWORK = "application/vnd.vmware.vcloud.vAppNetwork+xml";
public static final String ADMIN_VDC = "application/vnd.vmware.admin.vdc+xml";
public static final String TEXT_XML = "text/xml";
public static final String NETWORK_POOL = "application/vnd.vmware.admin.networkPool+xml";
public static final String ENTITY = "application/vnd.vmware.vcloud.entity+xml";
/**
* All acceptable media types.
@ -218,7 +220,7 @@ public class VCloudDirectorMediaType {
ADMIN_ORG_NETWORK, USER, ROLE, DEPLOY_VAPP_PARAMS, RECOMPOSE_VAPP_PARAMS,
RELOCATE_VM_PARAMS, UNDEPLOY_VAPP_PARAMS, ADMIN_VDC, MEDIA_PARAMS,
RUNTIME_INFO_SECTION, SCREEN_TICKET, VAPP_NETWORK,
TEXT_XML, ADMIN_VDC, NETWORK_POOL, ADMIN_ORG
TEXT_XML, ADMIN_VDC, NETWORK_POOL, ADMIN_ORG, ENTITY
);
// NOTE These lists must be updated whenever a new media type constant is added.

View File

@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlSeeAlso;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
@XmlSeeAlso( {OrgNetwork.class, ExternalNetwork.class} )
@XmlSeeAlso({ OrgNetwork.class, ExternalNetwork.class })
public abstract class Network extends EntityType {
public static final class FenceMode {

View File

@ -21,6 +21,7 @@ package org.jclouds.vcloud.director.v1_5.features;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import org.jclouds.rest.annotations.ExceptionParser;
@ -28,6 +29,7 @@ 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.Entity;
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;
@ -45,6 +47,16 @@ import com.google.common.util.concurrent.ListenableFuture;
@SkipEncoding({ '=' })
public interface QueryAsyncClient {
/**
* @see QueryClient#entity(String)
*/
@GET
@Path("/entity/{id}")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Entity> entity(@PathParam("id") String id);
/**
* REST API General queries handler.
*/

View File

@ -21,14 +21,9 @@ 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.Entity;
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.QueryResultRecordType;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.domain.query.VAppReferences;
@ -41,6 +36,15 @@ import org.jclouds.vcloud.director.v1_5.domain.query.VAppReferences;
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface QueryClient {
/**
* Redirects to the URL of an entity with the given VCD ID.
*
* <pre>
* GET /entity/{id}
* </pre>
*/
Entity entity(String id);
// TODO Add a typed object for filter syntax, or at least a fluent builder
/**

View File

@ -59,13 +59,13 @@ public class LinkPredicates {
* @see ReferenceTypePredicates#nameEquals
*/
public static Predicate<Link> nameEquals(String name) {
return ReferenceTypePredicates.nameEquals(name);
return ReferencePredicates.nameEquals(name);
}
/**
* @see ReferenceTypePredicates#typeEquals
*/
public static Predicate<Link> typeEquals(String type) {
return ReferenceTypePredicates.typeEquals(type);
return ReferencePredicates.typeEquals(type);
}
}

View File

@ -20,27 +20,23 @@ package org.jclouds.vcloud.director.v1_5.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* Predicates handy when working with Reference Types
* Predicates for working with {@link Reference} collections.
*
* @author Adrian Cole
*/
public class ReferencePredicates {
/**
* matches references of the given name
* Matches {@link Reference}s with the given name.
*
* @param <T>
* type of the Reference, ex. {@link Link}
* @param name
* ex. {@code context.getApi().getCurrentSession().getOrg()}
* @param T type of the reference, for example {@link Link}
* @param name value of the name attribute of the referenced object
* @return predicate that will match references of the given name
*/
public static <T extends Reference> Predicate<T> nameEquals(final String name) {
@ -60,12 +56,58 @@ public class ReferencePredicates {
}
/**
* matches references of the given type
* Matches {@link Reference}s with names starting with the given prefix.
*
* @param <T>
* type of the Reference, ex. {@link Link}
* @param type
* ex. {@link VCloudDirectorMediaType#CATALOG}
* @param T type of the reference, for example {@link Link}
* @param name prefix of the name attribute of the referenced object
* @return predicate that will match references with names starting with the given prefix
*/
public static <T extends Reference> Predicate<T> nameStartsWith(final String prefix) {
checkNotNull(prefix, "prefix must be defined");
return new Predicate<T>() {
@Override
public boolean apply(T reference) {
String name = reference.getName();
return name != null && name.startsWith(prefix);
}
@Override
public String toString() {
return "nameStartsWith(" + prefix + ")";
}
};
}
/**
* Matches {@link Reference}s with names in the given collection.
*
* @param T type of the reference, for example {@link Link}
* @param names collection of values for the name attribute of the referenced object
* @return predicate that will match references with names starting with the given prefix
*/
public static <T extends Reference> Predicate<T> nameIn(final Iterable<String> names) {
checkNotNull(names, "names must be defined");
return new Predicate<T>() {
@Override
public boolean apply(T reference) {
String name = reference.getName();
return Iterables.contains(names, name);
}
@Override
public String toString() {
return "nameIn(" + Iterables.toString(names) + ")";
}
};
}
/**
* Matches {@link Reference}s of the given type.
*
* @param T type of the reference, for example {@link Link}
* @param type the media type string of the referenced object, for example {@link VCloudDirectorMediaType#CATALOG}
* @return predicate that will match references of the given type
* @see VCloudDirectorMediaType
*/

View File

@ -1,129 +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.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* Predicates for working with {@link Reference} collections.
*
* @author Adrian Cole
*/
public class ReferenceTypePredicates {
/**
* Matches {@link Reference}s with the given name.
*
* @param T type of the reference, for example {@link Link}
* @param name value of the name attribute of the referenced object
* @return predicate that will match references of the given name
*/
public static <T extends Reference> Predicate<T> nameEquals(final String name) {
checkNotNull(name, "name must be defined");
return new Predicate<T>() {
@Override
public boolean apply(T reference) {
return name.equals(reference.getName());
}
@Override
public String toString() {
return "nameEquals(" + name + ")";
}
};
}
/**
* Matches {@link Reference}s with names starting with the given prefix.
*
* @param T type of the reference, for example {@link Link}
* @param name prefix of the name attribute of the referenced object
* @return predicate that will match references with names starting with the given prefix
*/
public static <T extends Reference> Predicate<T> nameStartsWith(final String prefix) {
checkNotNull(prefix, "prefix must be defined");
return new Predicate<T>() {
@Override
public boolean apply(T reference) {
String name = reference.getName();
return name != null && name.startsWith(prefix);
}
@Override
public String toString() {
return "nameStartsWith(" + prefix + ")";
}
};
}
/**
* Matches {@link Reference}s with names in the given collection.
*
* @param T type of the reference, for example {@link Link}
* @param names collection of values for the name attribute of the referenced object
* @return predicate that will match references with names starting with the given prefix
*/
public static <T extends Reference> Predicate<T> nameIn(final Iterable<String> names) {
checkNotNull(names, "names must be defined");
return new Predicate<T>() {
@Override
public boolean apply(T reference) {
String name = reference.getName();
return Iterables.contains(names, name);
}
@Override
public String toString() {
return "nameIn(" + Iterables.toString(names) + ")";
}
};
}
/**
* Matches {@link Reference}s of the given type.
*
* @param T type of the reference, for example {@link Link}
* @param type the media type string of the referenced object, for example {@link VCloudDirectorMediaType#CATALOG}
* @return predicate that will match references of the given type
* @see VCloudDirectorMediaType
*/
public static <T extends Reference> Predicate<T> typeEquals(final String type) {
checkNotNull(type, "type must be defined");
return new Predicate<T>() {
@Override
public boolean apply(T reference) {
return type.equals(reference.getType());
}
@Override
public String toString() {
return "typeEquals(" + type + ")";
}
};
}
}

View File

@ -51,7 +51,7 @@ import org.jclouds.vcloud.director.v1_5.domain.cim.CimUnsignedInt;
import org.jclouds.vcloud.director.v1_5.domain.cim.CimUnsignedLong;
import org.jclouds.vcloud.director.v1_5.domain.cim.ResourceAllocationSettingData;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
@ -186,8 +186,8 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
Iterable<Reference> vApps = Iterables.filter(
vdc.getResourceEntities(),
Predicates.and(
ReferenceTypePredicates.<Reference>typeEquals(VCloudDirectorMediaType.VAPP),
ReferenceTypePredicates.<Reference>nameIn(vAppNames)
ReferencePredicates.<Reference>typeEquals(VCloudDirectorMediaType.VAPP),
ReferencePredicates.<Reference>nameIn(vAppNames)
)
);

View File

@ -18,7 +18,9 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_EQUAL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkEntityType;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@ -32,6 +34,8 @@ import java.util.List;
import java.util.Set;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.ResourceType;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.VApp;
@ -45,6 +49,7 @@ import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultVAppRecord;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultVAppTemplateRecord;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultVMRecord;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -84,6 +89,24 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest {
vAppClient = context.getApi().getVAppClient();
}
@Test(testName = "GET /entity/{id}")
public void testEntity() {
// Get a VAppTemplate to look up as an entity
VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
// Method under test
Entity entity = queryClient.entity(vAppTemplate.getId());
// Check returned entity
checkEntityType(entity);
// Retrieve and check template using entity link
Link link = Iterables.find(entity.getLinks(), ReferencePredicates.<Link>typeEquals(VCloudDirectorMediaType.VAPP_TEMPLATE));
VAppTemplate retrieved = vAppTemplateClient.getVAppTemplate(link.getHref());
assertEquals(retrieved, vAppTemplate, String.format(ENTITY_EQUAL, "VAppTemplate"));
}
@Test(testName = "GET /query")
public void testQuery() {
VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);

View File

@ -529,7 +529,10 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
public void testModifyLeaseSettingsSection() {
// Copy existing section
LeaseSettingsSection oldSection = vAppClient.getLeaseSettingsSection(vApp.getHref());
LeaseSettingsSection newSection = oldSection.toBuilder().build();
Integer twoHours = (int) TimeUnit.SECONDS.convert(2L, TimeUnit.HOURS);
LeaseSettingsSection newSection = oldSection.toBuilder()
.deploymentLeaseInSeconds(twoHours)
.build();
// The method under test
Task modifyLeaseSettingsSection = vAppClient.modifyLeaseSettingsSection(vApp.getHref(), newSection);
@ -542,13 +545,13 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
checkLeaseSettingsSection(modified);
// Check the date fields
if (modified.getDeploymentLeaseExpiration() != null) {
if (modified.getDeploymentLeaseExpiration() != null && newSection.getDeploymentLeaseExpiration() != null) {
assertTrue(modified.getDeploymentLeaseExpiration().after(newSection.getDeploymentLeaseExpiration()),
String.format("The new deploymentLeaseExpiration timestamp must be later than the original: %s > %s",
dateService.iso8601DateFormat(modified.getDeploymentLeaseExpiration()),
dateService.iso8601DateFormat(newSection.getDeploymentLeaseExpiration())));
}
if (modified.getStorageLeaseExpiration() != null) {
if (modified.getStorageLeaseExpiration() != null && newSection.getStorageLeaseExpiration() != null) {
assertTrue(modified.getStorageLeaseExpiration().after(newSection.getStorageLeaseExpiration()),
String.format("The new storageLeaseExpiration timestamp must be later than the original: %s > %s",
dateService.iso8601DateFormat(modified.getStorageLeaseExpiration()),
@ -566,6 +569,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
.build();
// Check the section was modified correctly
assertEquals(modified.getDeploymentLeaseInSeconds(), twoHours,
String.format(OBJ_FIELD_EQ, "LeaseSettingsSection", "DeploymentLeaseInSeconds", Integer.toString(twoHours), modified.getDeploymentLeaseInSeconds().toString()));
assertEquals(modified, newSection, String.format(ENTITY_EQUAL, "LeaseSettingsSection"));
}
@ -819,7 +824,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
checkRuntimeInfoSection(section);
}
// FIXME If still failing, consider escalating?
// FIXME If still failing, consider escalating?
@Test(testName = "GET /vApp/{id}/screen", dependsOnMethods = { "testDeployVApp" })
public void testGetScreenImage() {
// Power on VApp

View File

@ -318,9 +318,9 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vAppTemplate/{id}/leaseSettingsSection")
public void testEditLeaseSettingsSection() throws Exception {
int deploymentLeaseInSeconds = random.nextInt(10000)+1;
// Note: use smallish number for storageLeaseInSeconds; it seems to be capped at 5184000?
// NOTE use smallish number for storageLeaseInSeconds; it seems to be capped at 5184000?
int storageLeaseInSeconds = random.nextInt(10000)+1;
LeaseSettingsSection leaseSettingSection = LeaseSettingsSection.builder()
.info("my info")
.storageLeaseInSeconds(storageLeaseInSeconds)
@ -331,8 +331,8 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
retryTaskSuccess.apply(task);
LeaseSettingsSection newLeaseSettingsSection = vAppTemplateClient.getVappTemplateLeaseSettingsSection(vAppTemplateURI);
assertEquals(newLeaseSettingsSection.getStorageLeaseInSeconds(), (Integer)storageLeaseInSeconds);
assertEquals(newLeaseSettingsSection.getDeploymentLeaseInSeconds(), (Integer)deploymentLeaseInSeconds);
assertEquals(newLeaseSettingsSection.getStorageLeaseInSeconds(), (Integer) storageLeaseInSeconds);
assertEquals(newLeaseSettingsSection.getDeploymentLeaseInSeconds(), (Integer) deploymentLeaseInSeconds);
}
@Test(testName = "PUT /vAppTemplate/{id}/networkConfigSection")

View File

@ -50,6 +50,7 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.InstantiateVAppTemplateParams;
import org.jclouds.vcloud.director.v1_5.domain.InstantiationParams;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Network;
import org.jclouds.vcloud.director.v1_5.domain.NetworkConfigSection;
import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.Org;
@ -66,11 +67,10 @@ import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import org.jclouds.vcloud.director.v1_5.features.VAppClient;
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient;
import org.jclouds.vcloud.director.v1_5.features.VdcClient;
import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
import org.jclouds.vcloud.director.v1_5.predicates.TaskStatusEquals;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@ -126,10 +126,10 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
provider = "vcloud-director";
}
protected static DateService dateService;
protected DateService dateService;
@BeforeGroups(alwaysRun = true)
protected static void setupDateService() {
@BeforeClass(alwaysRun = true)
protected void setupDateService() {
dateService = Guice.createInjector().getInstance(DateService.class);
assertNotNull(dateService);
}
@ -187,28 +187,20 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
if (Iterables.any(Lists.newArrayList(vAppTemplateURI, networkURI, vdcURI), Predicates.isNull())) {
Org thisOrg = context.getApi().getOrgClient().getOrg(
Iterables.find(context.getApi().getOrgClient().getOrgList().getOrgs(),
ReferenceTypePredicates.<Reference> nameEquals(session.getOrg())).getHref());
//TODO: can we create new objects via (admin) operations instead of looking things up?
//TODO: lookup mediaURI, userURI
// FIXME: lookup vAppTemplate
// if (vAppTemplateURI == null)
// vAppTemplateURI = Iterables.find(context.getApi().getQueryClient().vAppTemplatesReferenceQueryAll(),
// ReferenceTypePredicates.<Link> typeEquals(VCloudDirectorMediaType.VDC)).getHref();
ReferencePredicates.<Reference> nameEquals(session.getOrg())).getHref());
if (vdcURI == null)
vdcURI = Iterables.find(thisOrg.getLinks(),
ReferenceTypePredicates.<Link> typeEquals(VCloudDirectorMediaType.VDC)).getHref();
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.VDC)).getHref();
if (networkURI == null)
networkURI = Iterables.find(thisOrg.getLinks(),
ReferenceTypePredicates.<Link> typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref();
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref();
// FIXME the URI should be opaque
if (Strings.isNullOrEmpty(catalogId)) {
String uri = Iterables.find(thisOrg.getLinks(),
ReferenceTypePredicates.<Link> typeEquals(VCloudDirectorMediaType.CATALOG)).getHref().toASCIIString();
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.CATALOG)).getHref().toASCIIString();
catalogId = Iterables.getLast(Splitter.on('/').split(uri));
}
}
@ -331,7 +323,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
// Build the configuration object
NetworkConfiguration networkConfiguration = NetworkConfiguration.builder()
.parentNetwork(parentNetwork.get())
.fenceMode("bridged")
.fenceMode(Network.FenceMode.ISOLATED)
.build();
return networkConfiguration;

View File

@ -18,14 +18,18 @@
*/
package org.jclouds.vcloud.director.v1_5.predicates;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ReferencePredicatesTest")
@ -35,21 +39,41 @@ public class ReferencePredicatesTest {
@Test
public void testNameEqualsWhenEqual() {
assert ReferencePredicates.<Reference> nameEquals("image").apply(ref);
assertTrue(ReferencePredicates.<Reference> nameEquals("image").apply(ref));
}
@Test
public void testNameEqualsWhenNotEqual() {
assert !ReferencePredicates.<Reference> nameEquals("foo").apply(ref);
assertFalse(ReferencePredicates.<Reference> nameEquals("foo").apply(ref));
}
@Test
public void testNameStartsWithWhenStartsWith() {
assertTrue(ReferencePredicates.<Reference> nameStartsWith("i").apply(ref));
}
@Test
public void testNameStartsWithWhenNotStartsWith() {
assertFalse(ReferencePredicates.<Reference> nameStartsWith("f").apply(ref));
}
@Test
public void testNameInWhenIn() {
assertTrue(ReferencePredicates.<Reference> nameIn(ImmutableSet.of("one", "two", "image")).apply(ref));
}
@Test
public void testNameInWhenNotIn() {
assertFalse(ReferencePredicates.<Reference> nameIn(ImmutableSet.of("one", "two", "foo")).apply(ref));
}
@Test
public void testTypeEqualsWhenEqual() {
assert ReferencePredicates.<Reference> typeEquals(VCloudDirectorMediaType.CATALOG_ITEM).apply(ref);
assertTrue(ReferencePredicates.<Reference> typeEquals(VCloudDirectorMediaType.CATALOG_ITEM).apply(ref));
}
@Test
public void testTypeEqualsWhenNotEqual() {
assert !ReferencePredicates.<Reference> typeEquals("foo").apply(ref);
assertFalse(ReferencePredicates.<Reference> typeEquals("foo").apply(ref));
}
}

View File

@ -1,55 +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.predicates;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ReferenceTypePredicatesTest")
public class ReferenceTypePredicatesTest {
Reference ref = Reference.builder().type("application/vnd.vmware.vcloud.catalogItem+xml").name("image").href(
URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/67a469a1-aafe-4b5b-bb31-a6202ad8961f")).build();
@Test
public void testNameEqualsWhenEqual() {
assert ReferenceTypePredicates.<Reference> nameEquals("image").apply(ref);
}
@Test
public void testNameEqualsWhenNotEqual() {
assert !ReferenceTypePredicates.<Reference> nameEquals("foo").apply(ref);
}
@Test
public void testTypeEqualsWhenEqual() {
assert ReferenceTypePredicates.<Reference> typeEquals(VCloudDirectorMediaType.CATALOG_ITEM).apply(ref);
}
@Test
public void testTypeEqualsWhenNotEqual() {
assert !ReferenceTypePredicates.<Reference> typeEquals("foo").apply(ref);
}
}