Merge pull request #484 from aplowe/catalogclient

Issue 830: vCloud 1.5 - Improving CatalogClientLiveTest
This commit is contained in:
Adrian Cole 2012-03-20 10:49:24 -07:00
commit 2359ee9ec5
6 changed files with 187 additions and 153 deletions

View File

@ -29,6 +29,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser;
@ -36,6 +37,7 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToXMLPayload;
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.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
@ -125,4 +127,12 @@ public interface AdminCatalogAsyncClient extends CatalogAsyncClient {
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Void> publishCatalog(@EndpointParam URI catalogRef,
@BinderParam(BindToXMLPayload.class) PublishCatalogParams params);
/**
* @return synchronous access to {@link Metadata.Writable} features
*/
@Override
@Delegate
MetadataAsyncClient.Writable getMetadataClient();
}

View File

@ -23,7 +23,9 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
@ -112,4 +114,11 @@ public interface AdminCatalogClient extends CatalogClient {
//TODO: lot of work to pass in a single boolean, would like to polymorphically include something like:
//void publishCatalog(URI catalogRef)
/**
* @return synchronous access to {@link Metadata.Writable} features
*/
@Override
@Delegate
MetadataClient.Writeable getMetadataClient();
}

View File

@ -38,7 +38,7 @@ import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.CatalogType;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncClient.Writable;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
@ -102,8 +102,14 @@ public interface CatalogAsyncClient {
ListenableFuture<Void> deleteCatalogItem(@EndpointParam URI catalogItemUri);
/**
* @return asynchronous access to {@link Writable} features
* @return asynchronous access to {@link Metadata.Readable} features
*/
@Delegate
MetadataAsyncClient.Writable getMetadataClient();
MetadataAsyncClient.Readable getMetadataClient();
/**
* @return asynchronous access to {@link Metadata.Writeable} features for CatalogItems
*/
@Delegate
MetadataAsyncClient.Writable getCatalogItemMetadataClient();
}

View File

@ -99,8 +99,15 @@ public interface CatalogClient {
void deleteCatalogItem(URI catalogItemRef);
/**
* @return synchronous access to {@link Metadata.Writeable} features
* @return synchronous access to {@link Metadata.Readable} features
*/
@Delegate
MetadataClient.Writeable getMetadataClient();
MetadataClient.Readable getMetadataClient();
/**
* @return synchronous access to {@link Metadata.Writeable} features for CatalogItems
*/
@Delegate
MetadataClient.Writeable getCatalogItemMetadataClient();
}

View File

@ -295,7 +295,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT
Task expected = mergeMetadataTask();
assertEquals(client.getCatalogClient().getMetadataClient().mergeMetadata(catalogItemURI, metadata), expected);
assertEquals(client.getCatalogClient().getCatalogItemMetadataClient().mergeMetadata(catalogItemURI, metadata), expected);
}
@Test
@ -348,7 +348,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT
Task expected = setMetadataValueTask();
assertEquals(client.getCatalogClient().getMetadataClient().setMetadata(catalogItemURI, "KEY", value), expected);
assertEquals(client.getCatalogClient().getCatalogItemMetadataClient().setMetadata(catalogItemURI, "KEY", value), expected);
}
@Test
@ -373,7 +373,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT
Task expected = deleteMetadataEntryTask();
assertEquals(client.getCatalogClient().getMetadataClient().deleteMetadataEntry(catalogItemURI, "KEY"), expected);
assertEquals(client.getCatalogClient().getCatalogItemMetadataClient().deleteMetadataEntry(catalogItemURI, "KEY"), expected);
}
@SuppressWarnings("unchecked")

View File

@ -18,34 +18,26 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static com.google.common.base.Predicates.and;
import static com.google.common.collect.Iterables.find;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MUST_EXIST_FMT;
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;
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;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.*;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.CatalogType;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.*;
import org.jclouds.vcloud.director.v1_5.domain.Error;
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.Task;
import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
@ -62,103 +54,142 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/*
* Convenience references to API clients.
*/
private CatalogClient catalogClient;
private QueryClient queryClient;
/*
* Shared state between dependant tests.
*/
private AdminCatalog adminCatalog;
private Media media;
private CatalogItem catalogItem;
private Reference catalogRef;
private Reference catalogItemRef;
private Reference newCatalogItemRef;
private CatalogType catalog;
private CatalogItem catalogItem;
private CatalogItem newCatalogItem;
private Metadata catalogMetadata;
@Override
@BeforeClass(inheritGroups = true)
public void setupRequiredClients() {
protected void setupRequiredClients() throws Exception {
// TODO why do I need a guard clause here?
if (adminCatalog != null) return;
catalogClient = context.getApi().getCatalogClient();
queryClient = context.getApi().getQueryClient();
Reference orgRef = Iterables.getFirst(context.getApi().getOrgClient().getOrgList().getOrgs(), null).toAdminReference(endpoint);
AdminCatalog newCatalog = AdminCatalog.builder()
.name("Test Catalog " + random.nextInt())
.description("created by CatalogClientLiveTest")
.build();
AdminCatalogClient adminCatalogClient = context.getApi().getAdminCatalogClient();
adminCatalog = adminCatalogClient.createCatalog(orgRef.getHref(), newCatalog);
catalogRef = find(adminCatalog.getLinks(), and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG)));
Metadata newMetadata = Metadata.builder()
.entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.build();
Task mergeCatalogMetadata = adminCatalogClient.getMetadataClient().mergeMetadata(adminCatalog.getHref(), newMetadata);
checkTask(mergeCatalogMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogMetadata), String.format(TASK_COMPLETE_TIMELY, "setupRequiredClients"));
}
private Metadata catalogItemMetadata;
@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) {
context.getApi().getAdminCatalogClient().deleteCatalog(adminCatalog.getHref());
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");
}
}
}
@Test(testName = "GET /catalog/{id}")
public void testGetCatalog() {
// TODO use property from default property set
CatalogReferences catalogReferences = queryClient.catalogReferencesQuery(String.format("name==%s", catalogName));
assertEquals(Iterables.size(catalogReferences.getReferences()), 1, String.format(MUST_EXIST_FMT, catalogName, "Catalog"));
catalogRef = Iterables.getOnlyElement(catalogReferences.getReferences());
catalog = catalogClient.getCatalog(catalogRef.getHref());
CatalogType catalog = catalogClient.getCatalog(catalogRef.getHref());
assertNotNull(catalog);
// Double check it's pointing at the correct catalog
assertEquals(catalog.getHref(), catalogRef.getHref());
}
@Test(testName = "GET /catalogItem/{id}", dependsOnMethods = { "testGetCatalog" })
@Test(testName = "GET /catalogItem/{id}", dependsOnMethods = "testAddCatalogItem")
public void testGetCatalogItem() {
assertFalse(Iterables.isEmpty(catalog.getCatalogItems().getCatalogItems()));
catalogItemRef = Iterables.get(catalog.getCatalogItems().getCatalogItems(), 0);
catalogItem = catalogClient.getCatalogItem(catalogItemRef.getHref());
CatalogItem catalogItem = catalogClient.getCatalogItem(this.catalogItem.getHref());
checkCatalogItem(catalogItem);
assertEquals(catalogItem.getEntity().getHref(), this.catalogItem.getEntity().getHref());
}
// 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 = { "testGetCatalog" })
@Test(testName = "POST /catalog/{id}/catalogItems")
public void testAddCatalogItem() {
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Vdc vdc = context.getApi().getVdcClient().getVdc(vdcURI);
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA)
.name("Test media 1")
.size(iso.length)
.imageType(Media.ImageType.ISO)
.description("Test media generated by testCreateMedia()")
.build();
media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
Checks.checkMediaFor(VCloudDirectorMediaType.MEDIA, media);
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())
.type(VCloudDirectorMediaType.CATALOG_ITEM)
.entity(Reference.builder().href(media.getHref()).build())
.build();
newCatalogItem = catalogClient.addCatalogItem(catalogRef.getHref(), editedCatalogItem);
checkCatalogItem(newCatalogItem);
assertEquals(newCatalogItem.getName(), "newitem");
catalogItem = catalogClient.addCatalogItem(catalogRef.getHref(), editedCatalogItem);
checkCatalogItem(catalogItem);
assertEquals(catalogItem.getName(), "newitem");
assertEquals(catalogItem.getDescription(), "New Item");
}
@Test(testName = "PUT /catalogItem/{id}", dependsOnMethods = { "testAddCatalogItem" })
@Test(testName = "PUT /catalogItem/{id}", dependsOnMethods = "testAddCatalogItem")
public void testUpdateCatalogItem() {
CatalogType catalog = catalogClient.getCatalog(catalogRef.getHref());
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.getHref(), updatedCatalogItem);
checkCatalogItem(newCatalogItem);
assertEquals(newCatalogItem.getName(), "UPDATEDNAME");
catalogItem = catalogClient.updateCatalogItem(catalogItem.getHref(), updatedCatalogItem);
checkCatalogItem(catalogItem);
assertEquals(catalogItem.getName(), "UPDATEDNAME");
}
@Test(testName = "DELETE /catalogItem/{id}", dependsOnMethods = { "testAddCatalogItem" })
// Note this runs after all the metadata tests
@Test(testName = "DELETE /catalogItem/{id}", dependsOnMethods = "testDeleteCatalogItemMetadataValue")
public void testDeleteCatalogItem() {
catalogClient.deleteCatalogItem(newCatalogItemRef.getHref());
catalogClient.deleteCatalogItem(catalogItem.getHref());
try {
catalogClient.getCatalogItem(newCatalogItemRef.getHref());
catalogClient.getCatalogItem(catalogItem.getHref());
fail("The CatalogItem should have been deleted");
} catch (VCloudDirectorException vcde) {
checkError(vcde.getError());
// XXX
assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The majorErrorCode should be 403 since the item has been deleted");
} finally {
catalogItem = null;
}
}
// 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" })
@Test(testName = "GET /catalog/{id}/metadata")
public void testGetCatalogMetadata() {
catalogMetadata = catalogClient.getMetadataClient().getMetadata(catalogRef.getHref());
Metadata catalogMetadata = catalogClient.getMetadataClient().getMetadata(catalogRef.getHref());
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" })
@Test(testName = "GET /catalog/{id}/metadata/{key}")
public void testGetCatalogMetadataValue() {
Metadata catalogMetadata = catalogClient.getMetadataClient().getMetadata(catalogRef.getHref());
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), new Predicate<MetadataEntry>() {
@Override
public boolean apply(MetadataEntry input) {
@ -171,80 +202,69 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
checkMetadataValue(metadataValue);
}
@Test(testName = "GET /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItem" })
@Test(testName = "GET /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
public void testGetCatalogItemMetadata() {
resetCatalogItemMetadata(catalogItemRef.getHref());
catalogItemMetadata = catalogClient.getMetadataClient().getMetadata(catalogItemRef.getHref());
assertEquals(catalogItemMetadata.getMetadataEntries().size(), 1, String.format(MUST_EXIST_FMT, "MetadataEntry", "CatalogItem"));
Metadata catalogItemMetadata = catalogClient.getCatalogItemMetadataClient().getMetadata(catalogItem.getHref());
checkMetadata(catalogItemMetadata);
}
@Test(testName = "POST /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItemMetadata" })
@Test(testName = "POST /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
public void testMergeCatalogItemMetadata() {
Metadata newMetadata = Metadata.builder()
.entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.entry(MetadataEntry.builder().entry("VEGIMITE", "VALUE").build())
.build();
Task mergeCatalogItemMetadata = catalogClient.getMetadataClient().mergeMetadata(catalogItemRef.getHref(), newMetadata);
Metadata before = catalogClient.getCatalogItemMetadataClient().getMetadata(catalogItem.getHref());
Task mergeCatalogItemMetadata = catalogClient.getCatalogItemMetadataClient().mergeMetadata(catalogItem.getHref(), newMetadata);
checkTask(mergeCatalogItemMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadataClient().getMetadata(catalogItem.getHref());
Metadata mergedCatalogItemMetadata = catalogClient.getMetadataClient().getMetadata(catalogItemRef.getHref());
// XXX
assertEquals(mergedCatalogItemMetadata.getMetadataEntries().size(), catalogItemMetadata.getMetadataEntries().size() + 1,
"Should have added another MetadataEntry to the CatalogItem");
assertTrue(mergedCatalogItemMetadata.getMetadataEntries().size() > before.getMetadataEntries().size(),
"Should have added at least one other MetadataEntry to the CatalogItem");
MetadataValue keyMetadataValue = catalogClient.getMetadataClient().getMetadataValue(catalogItemRef.getHref(), "KEY");
// XXX
MetadataValue keyMetadataValue = catalogClient.getCatalogItemMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY");
assertEquals(keyMetadataValue.getValue(), "MARMALADE", "The Value of the MetadataValue for KEY should have changed");
checkMetadataValue(keyMetadataValue);
MetadataValue newKeyMetadataValue = catalogClient.getMetadataClient().getMetadataValue(catalogItemRef.getHref(), "VEGIMITE");
// XXX
MetadataValue newKeyMetadataValue = catalogClient.getCatalogItemMetadataClient().getMetadataValue(catalogItem.getHref(), "VEGIMITE");
assertEquals(newKeyMetadataValue.getValue(), "VALUE", "The Value of the MetadataValue for NEW_KEY should have been set");
checkMetadataValue(newKeyMetadataValue);
}
// TODO escalate
// 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 = { "testGetCatalogItemMetadata" })
@Test(testName = "GET /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testSetCatalogItemMetadataValue")
public void testGetCatalogItemMetadataValue() {
MetadataEntry existingMetadataEntry = Iterables.find(catalogItemMetadata.getMetadataEntries(), new Predicate<MetadataEntry>() {
@Override
public boolean apply(MetadataEntry input) {
return input.getKey().equals("KEY");
}
});
MetadataValue metadataValue = catalogClient.getMetadataClient().getMetadataValue(catalogItemRef.getHref(), "KEY");
assertEquals(existingMetadataEntry.getValue(), metadataValue.getValue());
MetadataValue metadataValue = catalogClient.getCatalogItemMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY");
checkMetadataValue(metadataValue);
}
@Test(testName = "PUT /catalog/{id}/metadata/{key}", dependsOnMethods = { "testGetCatalogItemMetadataValue" })
@Test(testName = "PUT /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testMergeCatalogItemMetadata")
public void testSetCatalogItemMetadataValue() {
MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build();
Task setCatalogItemMetadataValue = catalogClient.getMetadataClient().setMetadata(catalogItemRef.getHref(), "KEY", newMetadataValue);
Task setCatalogItemMetadataValue = catalogClient.getCatalogItemMetadataClient().setMetadata(catalogItem.getHref(), "KEY", newMetadataValue);
checkTask(setCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue"));
MetadataValue updatedMetadataValue = catalogClient.getMetadataClient().getMetadataValue(catalogItemRef.getHref(), "KEY");
MetadataValue updatedMetadataValue = catalogClient.getCatalogItemMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY");
assertEquals(updatedMetadataValue.getValue(), newMetadataValue.getValue(),
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", newMetadataValue.getValue(), updatedMetadataValue.getValue()));
checkMetadataValue(updatedMetadataValue);
}
@Test(testName = "DELETE /catalog/{id}/metadata/{key}", dependsOnMethods = { "testSetCatalogItemMetadataValue" })
@Test(testName = "DELETE /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testGetCatalogItemMetadataValue")
public void testDeleteCatalogItemMetadataValue() {
Task deleteCatalogItemMetadataValue = catalogClient.getMetadataClient().deleteMetadataEntry(catalogItemRef.getHref(), "KEY");
Task deleteCatalogItemMetadataValue = catalogClient.getCatalogItemMetadataClient().deleteMetadataEntry(catalogItem.getHref(), "KEY");
checkTask(deleteCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue"));
try {
catalogClient.getMetadataClient().getMetadataValue(catalogItemRef.getHref(), "KEY");
catalogClient.getMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY");
fail("The CatalogItem MetadataValue for KEY should have been deleted");
} catch (VCloudDirectorException vcde) {
Error error = vcde.getError();
@ -254,22 +274,4 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
String.format(CORRECT_VALUE_OBJECT_FMT, "MajorErrorCode", "Error", "403",Integer.toString(majorErrorCode)));
}
}
private void deleteAllCatalogItemMetadata(URI catalogItemURI) {
Metadata currentMetadata = catalogClient.getMetadataClient().getMetadata(catalogItemURI);
for (MetadataEntry currentMetadataEntry : currentMetadata.getMetadataEntries()) {
retryTaskSuccess.apply(catalogClient.getMetadataClient().deleteMetadataEntry(catalogItemURI, currentMetadataEntry.getKey()));
}
Metadata emptyMetadata = catalogClient.getMetadataClient().getMetadata(catalogItemURI);
assertTrue(emptyMetadata.getMetadataEntries().isEmpty(), "The catalogItem Metadata should be empty");
}
private void resetCatalogItemMetadata(URI catalogItemURI) {
deleteAllCatalogItemMetadata(catalogItemURI);
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "VALUE").build()).build();
Task mergeCatalogItemMetadata = catalogClient.getMetadataClient().mergeMetadata(catalogItemURI, newMetadata);
checkTask(mergeCatalogItemMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
}
}