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.Reference;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
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.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.features.admin.AdminCatalogApi;
|
||||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
|
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
|
@ -74,44 +73,29 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
private AdminCatalog adminCatalog;
|
private AdminCatalog adminCatalog;
|
||||||
private Media media;
|
private Media media;
|
||||||
private CatalogItem catalogItem;
|
private CatalogItem catalogItem;
|
||||||
|
private boolean createdByTest = false;
|
||||||
|
private AdminCatalogApi adminCatalogApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupRequiredApis() {
|
protected void setupRequiredApis() {
|
||||||
// TODO why do I need a guard clause here?
|
|
||||||
if (adminCatalog != null)
|
|
||||||
return;
|
|
||||||
catalogApi = context.getApi().getCatalogApi();
|
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 "))
|
AdminCatalog newCatalog = AdminCatalog.builder().name(name("Test Catalog "))
|
||||||
.description("created by CatalogApiLiveTest").build();
|
.description("created by CatalogApiLiveTest").build();
|
||||||
|
|
||||||
AdminCatalogApi adminCatalogApi = adminContext.getApi().getCatalogApi();
|
|
||||||
adminCatalog = adminCatalogApi.addCatalogToOrg(newCatalog, org.getId());
|
adminCatalog = adminCatalogApi.addCatalogToOrg(newCatalog, org.getId());
|
||||||
catalogUrn = catalogApi.get(
|
catalogUrn = catalogApi.get(
|
||||||
find(adminCatalog.getLinks(),
|
find(adminCatalog.getLinks(),
|
||||||
and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG))).getHref()).getId();
|
and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG))).getHref()).getId();
|
||||||
|
|
||||||
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
|
createdByTest = true;
|
||||||
.build();
|
|
||||||
|
|
||||||
Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi(adminCatalog.getId()).merge(newMetadata);
|
|
||||||
checkTask(mergeCatalogMetadata);
|
|
||||||
assertTrue(retryTaskSuccess.apply(mergeCatalogMetadata),
|
|
||||||
String.format(TASK_COMPLETE_TIMELY, "setupRequiredApis"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass(alwaysRun = true)
|
@AfterClass(alwaysRun = true)
|
||||||
public void tearDown() {
|
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) {
|
if (media != null) {
|
||||||
try {
|
try {
|
||||||
Task remove = context.getApi().getMediaApi().remove(media.getId());
|
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());
|
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) {
|
if (adminContext != null && adminCatalog != null) {
|
||||||
try {
|
try {
|
||||||
adminContext.getApi().getCatalogApi().remove(adminCatalog.getId());
|
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());
|
logger.warn(e, "Error when deleting catalog '%s'", adminCatalog.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO wait for tasks
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "GET /catalog/{id}")
|
@Test(description = "GET /catalog/{id}")
|
||||||
|
@ -151,7 +143,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
Vdc vdc = lazyGetVdc();
|
Vdc vdc = lazyGetVdc();
|
||||||
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
|
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();
|
.imageType(Media.ImageType.ISO).description("Test media generated by testAddMedia()").build();
|
||||||
media = context.getApi().getMediaApi().add(addMedia.getHref(), sourceMedia);
|
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
|
// Note this runs after all the metadata tests
|
||||||
@Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testRemoveCatalogItemMetadataValue")
|
@Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testRemoveCatalogItemMetadataValue")
|
||||||
public void testRemoveCatalogItem() {
|
public void testRemoveCatalogItem() {
|
||||||
|
removeMediaAttachedToCatalogItem(catalogItem);
|
||||||
catalogApi.removeItem(catalogItem.getId());
|
catalogApi.removeItem(catalogItem.getId());
|
||||||
catalogItem = catalogApi.getItem(catalogItem.getId());
|
catalogItem = catalogApi.getItem(catalogItem.getId());
|
||||||
assertNull(catalogItem);
|
assertNull(catalogItem);
|
||||||
|
@ -190,6 +183,13 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
|
|
||||||
@Test(description = "GET /catalog/{id}/metadata/{key}")
|
@Test(description = "GET /catalog/{id}/metadata/{key}")
|
||||||
public void testGetCatalogMetadataValue() {
|
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();
|
Metadata catalogMetadata = catalogApi.getMetadataApi(catalogUrn).get();
|
||||||
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(),
|
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(),
|
||||||
new Predicate<MetadataEntry>() {
|
new Predicate<MetadataEntry>() {
|
||||||
|
@ -198,7 +198,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
return input.getKey().equals("KEY");
|
return input.getKey().equals("KEY");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
MetadataValue metadataValue = catalogApi.getMetadataApi(catalogApi.get(existingMetadataEntry.getHref()).getId())
|
MetadataValue metadataValue = catalogApi.getMetadataApi(catalogUrn)
|
||||||
.getValue("KEY");
|
.getValue("KEY");
|
||||||
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), String.format(CORRECT_VALUE_OBJECT_FMT,
|
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), String.format(CORRECT_VALUE_OBJECT_FMT,
|
||||||
"Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
|
"Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
|
||||||
|
@ -270,4 +270,19 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
MetadataValue removed = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("KEY");
|
MetadataValue removed = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("KEY");
|
||||||
assertNull(removed);
|
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.InstantiateVAppTemplateParams;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiationParams;
|
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.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.domain.section.NetworkConfigSection;
|
||||||
import org.jclouds.vcloud.director.v1_5.features.TaskApi;
|
import org.jclouds.vcloud.director.v1_5.features.TaskApi;
|
||||||
import org.jclouds.vcloud.director.v1_5.features.VAppApi;
|
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"));
|
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
|
org = context
|
||||||
.getApi()
|
.getApi()
|
||||||
.getOrgApi()
|
.getOrgApi()
|
||||||
|
@ -267,7 +276,6 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
|
||||||
vAppTemplateUrn = vAppTemplate.getId();
|
vAppTemplateUrn = vAppTemplate.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (networkUrn == null) {
|
if (networkUrn == null) {
|
||||||
|
|
Loading…
Reference in New Issue