mirror of https://github.com/apache/jclouds.git
fix NPE and test ordering
This commit is contained in:
parent
33128f8d8b
commit
3295c1fdc7
|
@ -41,6 +41,7 @@ import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams;
|
||||||
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.User;
|
import org.jclouds.vcloud.director.v1_5.domain.User;
|
||||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@BeforeClass(inheritGroups = true)
|
@BeforeClass(inheritGroups = true)
|
||||||
public void setupRequiredClients() {
|
protected void setupRequiredClients() {
|
||||||
catalogClient = context.getApi().getAdminCatalogClient();
|
catalogClient = context.getApi().getAdminCatalogClient();
|
||||||
orgRef = Iterables.getFirst(context.getApi().getOrgClient().getOrgList().getOrgs(), null).toAdminReference(endpoint);
|
orgRef = Iterables.getFirst(context.getApi().getOrgClient().getOrgList().getOrgs(), null).toAdminReference(endpoint);
|
||||||
}
|
}
|
||||||
|
@ -186,36 +187,47 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
||||||
|
|
||||||
assertTrue(catalog.isPublished(), String.format(OBJ_FIELD_EQ,
|
assertTrue(catalog.isPublished(), String.format(OBJ_FIELD_EQ,
|
||||||
CATALOG, "isPublished", true, catalog.isPublished()));
|
CATALOG, "isPublished", true, catalog.isPublished()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(testName = "DELETE /admin/catalog/{id}",
|
@Test(testName = "DELETE /admin/catalog/{id}",
|
||||||
dependsOnMethods = { "testUpdateCatalog" } )
|
dependsOnMethods = { "testCreateCatalog" } )
|
||||||
public void testDeleteCatalog() {
|
public void testDeleteCatalog() {
|
||||||
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
|
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
|
||||||
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
|
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
|
||||||
// catalog.getCatalogItems().getCatalogItems().toString()));
|
// catalog.getCatalogItems().getCatalogItems().toString()));
|
||||||
catalogClient.deleteCatalog(catalog.getHref());
|
AdminCatalog deleteCatalog = AdminCatalog.builder()
|
||||||
|
.name("Test Catalog " + random.nextInt())
|
||||||
|
.description("created by testCreateCatalog()")
|
||||||
|
.build();
|
||||||
|
deleteCatalog = catalogClient.createCatalog(orgRef.getHref(), deleteCatalog);
|
||||||
|
catalogClient.deleteCatalog(deleteCatalog.getHref());
|
||||||
|
|
||||||
Error expected = Error.builder()
|
Error expected = Error.builder()
|
||||||
.message("No access to entity \"(com.vmware.vcloud.entity.catalog:"+
|
.message("No access to entity \"(com.vmware.vcloud.entity.catalog:"+
|
||||||
catalog.getId().substring("urn:vcloud:catalog:".length())+")\".")
|
deleteCatalog.getId().substring("urn:vcloud:catalog:".length())+")\".")
|
||||||
.majorErrorCode(403)
|
.majorErrorCode(403)
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
catalog = catalogClient.getCatalog(catalog.getHref());
|
deleteCatalog = catalogClient.getCatalog(deleteCatalog.getHref());
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (VCloudDirectorException vde) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(vde.getError(), expected);
|
||||||
catalog = null;
|
deleteCatalog = null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a VCloudDirectorException");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (catalog != null) { // guard against NPE on the .toStrings
|
if (deleteCatalog != null) { // guard against NPE on the .toStrings
|
||||||
assertNull(catalog, String.format(OBJ_DEL, CATALOG, catalog.toString()));
|
assertNull(deleteCatalog, String.format(OBJ_DEL, CATALOG, deleteCatalog.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
protected void tidyUp() {
|
||||||
|
if (catalog != null) {
|
||||||
|
catalogClient.deleteCatalog(catalog.getHref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue