mirror of https://github.com/apache/jclouds.git
Merge pull request #796 from andreaturli/vmware-test-tool
issue 830: fixed CatalogApiLiveTest
This commit is contained in:
commit
728d69727f
|
@ -46,7 +46,6 @@ 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.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
|
||||
import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogApi;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
|
||||
import org.testng.annotations.AfterClass;
|
||||
|
@ -74,44 +73,29 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
private AdminCatalog adminCatalog;
|
||||
private Media media;
|
||||
private CatalogItem catalogItem;
|
||||
private boolean createdByTest = false;
|
||||
private AdminCatalogApi adminCatalogApi;
|
||||
|
||||
@Override
|
||||
protected void setupRequiredApis() {
|
||||
// TODO why do I need a guard clause here?
|
||||
if (adminCatalog != null)
|
||||
return;
|
||||
catalogApi = context.getApi().getCatalogApi();
|
||||
Org org = context.getApi().getOrgApi().get(Iterables.get(context.getApi().getOrgApi().list(), 0).getHref());
|
||||
adminCatalogApi = adminContext.getApi().getCatalogApi();
|
||||
|
||||
if (adminContext != null) {
|
||||
if(catalogUrn == null) {
|
||||
AdminCatalog newCatalog = AdminCatalog.builder().name(name("Test Catalog "))
|
||||
.description("created by CatalogApiLiveTest").build();
|
||||
|
||||
AdminCatalogApi adminCatalogApi = adminContext.getApi().getCatalogApi();
|
||||
adminCatalog = adminCatalogApi.addCatalogToOrg(newCatalog, org.getId());
|
||||
catalogUrn = catalogApi.get(
|
||||
find(adminCatalog.getLinks(),
|
||||
and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG))).getHref()).getId();
|
||||
|
||||
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
|
||||
.build();
|
||||
|
||||
Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi(adminCatalog.getId()).merge(newMetadata);
|
||||
checkTask(mergeCatalogMetadata);
|
||||
assertTrue(retryTaskSuccess.apply(mergeCatalogMetadata),
|
||||
String.format(TASK_COMPLETE_TIMELY, "setupRequiredApis"));
|
||||
createdByTest = true;
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void tearDown() {
|
||||
if (catalogItem != null) {
|
||||
try {
|
||||
catalogApi.removeItem(catalogItem.getId());
|
||||
} catch (Exception e) {
|
||||
logger.warn(e, "Error when deleting catalog item '%s'", catalogItem.getName());
|
||||
}
|
||||
}
|
||||
if (media != null) {
|
||||
try {
|
||||
Task remove = context.getApi().getMediaApi().remove(media.getId());
|
||||
|
@ -120,6 +104,14 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
logger.warn(e, "Error when deleting media '%s'", media.getName());
|
||||
}
|
||||
}
|
||||
if(createdByTest) {
|
||||
if (catalogItem != null) {
|
||||
try {
|
||||
catalogApi.removeItem(catalogItem.getId());
|
||||
} catch (Exception e) {
|
||||
logger.warn(e, "Error when deleting catalog item '%s'", catalogItem.getName());
|
||||
}
|
||||
}
|
||||
if (adminContext != null && adminCatalog != null) {
|
||||
try {
|
||||
adminContext.getApi().getCatalogApi().remove(adminCatalog.getId());
|
||||
|
@ -127,7 +119,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
logger.warn(e, "Error when deleting catalog '%s'", adminCatalog.getName());
|
||||
}
|
||||
}
|
||||
// TODO wait for tasks
|
||||
}
|
||||
}
|
||||
|
||||
@Test(description = "GET /catalog/{id}")
|
||||
|
@ -151,7 +143,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
Vdc vdc = lazyGetVdc();
|
||||
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)
|
||||
Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name(name("TestMedia-")).size(iso.length)
|
||||
.imageType(Media.ImageType.ISO).description("Test media generated by testAddMedia()").build();
|
||||
media = context.getApi().getMediaApi().add(addMedia.getHref(), sourceMedia);
|
||||
|
||||
|
@ -177,6 +169,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
// Note this runs after all the metadata tests
|
||||
@Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testRemoveCatalogItemMetadataValue")
|
||||
public void testRemoveCatalogItem() {
|
||||
removeMediaAttachedToCatalogItem(catalogItem);
|
||||
catalogApi.removeItem(catalogItem.getId());
|
||||
catalogItem = catalogApi.getItem(catalogItem.getId());
|
||||
assertNull(catalogItem);
|
||||
|
@ -190,6 +183,13 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
|
||||
@Test(description = "GET /catalog/{id}/metadata/{key}")
|
||||
public void testGetCatalogMetadataValue() {
|
||||
|
||||
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
|
||||
.build();
|
||||
|
||||
Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi(catalogUrn).merge(newMetadata);
|
||||
assertTaskSucceedsLong(mergeCatalogMetadata);
|
||||
|
||||
Metadata catalogMetadata = catalogApi.getMetadataApi(catalogUrn).get();
|
||||
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(),
|
||||
new Predicate<MetadataEntry>() {
|
||||
|
@ -198,7 +198,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
return input.getKey().equals("KEY");
|
||||
}
|
||||
});
|
||||
MetadataValue metadataValue = catalogApi.getMetadataApi(catalogApi.get(existingMetadataEntry.getHref()).getId())
|
||||
MetadataValue metadataValue = catalogApi.getMetadataApi(catalogUrn)
|
||||
.getValue("KEY");
|
||||
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), String.format(CORRECT_VALUE_OBJECT_FMT,
|
||||
"Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
|
||||
|
@ -270,4 +270,19 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
|||
MetadataValue removed = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("KEY");
|
||||
assertNull(removed);
|
||||
}
|
||||
|
||||
|
||||
private void removeMediaAttachedToCatalogItem(CatalogItem catalogItem) {
|
||||
if (media != null) {
|
||||
if (catalogItem.getEntity().getHref().equals(media.getHref())) {
|
||||
try {
|
||||
Task remove = context.getApi().getMediaApi().remove(media.getId());
|
||||
taskDoneEventually(remove);
|
||||
media = null;
|
||||
} catch (Exception e) {
|
||||
logger.warn(e, "Error when deleting media '%s'", media.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,8 @@ import org.jclouds.vcloud.director.v1_5.domain.org.Org;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiateVAppTemplateParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiationParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
|
||||
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.section.NetworkConfigSection;
|
||||
import org.jclouds.vcloud.director.v1_5.features.TaskApi;
|
||||
import org.jclouds.vcloud.director.v1_5.features.VAppApi;
|
||||
|
@ -246,6 +248,13 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
|
|||
|
||||
userUrn = emptyToNull(System.getProperty("test." + provider + ".user-id"));
|
||||
|
||||
// QueryResultRecords queryResult = adminContext.getApi().getQueryApi().usersQueryAll();
|
||||
// for (QueryResultRecordType recordType : queryResult.getRecords()) {
|
||||
// User user = adminContext.getApi().getUserApi().get(recordType.getHref());
|
||||
// System.out.println(user.getName());
|
||||
// System.out.println(user.getId());
|
||||
// }
|
||||
|
||||
org = context
|
||||
.getApi()
|
||||
.getOrgApi()
|
||||
|
@ -267,7 +276,6 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
|
|||
vAppTemplateUrn = vAppTemplate.getId();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (networkUrn == null) {
|
||||
|
|
Loading…
Reference in New Issue