Fix failing tests due to new ReturnNullOnNotFoundOr404 behaviour

This commit is contained in:
Andrew Donald Kennedy 2012-04-10 15:24:30 +01:00
parent a4d433d513
commit 9dbdbb13a7
3 changed files with 13 additions and 48 deletions

View File

@ -33,6 +33,7 @@ import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEqua
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals; import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
@ -42,7 +43,6 @@ import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; 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.CatalogType;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Media;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
@ -189,16 +189,8 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testDeleteCatalogItemMetadataValue") @Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testDeleteCatalogItemMetadataValue")
public void testDeleteCatalogItem() { public void testDeleteCatalogItem() {
catalogClient.deleteCatalogItem(catalogItem.getHref()); catalogClient.deleteCatalogItem(catalogItem.getHref());
try { catalogItem = catalogClient.getCatalogItem(catalogItem.getHref());
catalogClient.getCatalogItem(catalogItem.getHref()); assertNull(catalogItem);
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;
}
} }
@Test(description = "GET /catalog/{id}/metadata") @Test(description = "GET /catalog/{id}/metadata")
@ -283,15 +275,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
checkTask(deleteCatalogItemMetadataValue); checkTask(deleteCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue), assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue")); String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue"));
try { MetadataValue deleted = catalogClient.getMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY");
catalogClient.getMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY"); assertNull(deleted);
fail("The CatalogItem MetadataValue for KEY should have been deleted");
} catch (VCloudDirectorException vcde) {
Error error = vcde.getError();
checkError(error);
Integer majorErrorCode = error.getMajorErrorCode();
assertEquals(majorErrorCode, Integer.valueOf(403),
String.format(CORRECT_VALUE_OBJECT_FMT, "MajorErrorCode", "Error", "403",Integer.toString(majorErrorCode)));
}
} }
} }

View File

@ -33,7 +33,6 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull; import static org.testng.Assert.assertNull;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -69,11 +68,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.VAppNetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.VAppNetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**

View File

@ -20,8 +20,9 @@ package org.jclouds.vcloud.director.v1_5.features.admin;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.testng.Assert.assertEquals; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkUser;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertFalse;
@ -30,15 +31,11 @@ import java.net.URI;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings;
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.Role.DefaultRoles; import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
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.features.admin.AdminOrgClient;
import org.jclouds.vcloud.director.v1_5.features.admin.UserClient;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.jclouds.vcloud.director.v1_5.login.SessionClient; import org.jclouds.vcloud.director.v1_5.login.SessionClient;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
@ -90,7 +87,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testCreateUser() { public void testCreateUser() {
User newUser = randomTestUser("testCreateUser"); User newUser = randomTestUser("testCreateUser");
user = userClient.createUser(orgRef.getHref(), newUser); user = userClient.createUser(orgRef.getHref(), newUser);
Checks.checkUser(newUser); checkUser(newUser);
} }
@Test(description = "GET /admin/user/{id}", @Test(description = "GET /admin/user/{id}",
@ -98,7 +95,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testGetUser() { public void testGetUser() {
user = userClient.getUser(user.getHref()); user = userClient.getUser(user.getHref());
Checks.checkUser(user); checkUser(user);
} }
@Test(description = "PUT /admin/user/{id}", @Test(description = "PUT /admin/user/{id}",
@ -125,7 +122,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
userClient.updateUser(user.getHref(), newUser); userClient.updateUser(user.getHref(), newUser);
user = userClient.getUser(user.getHref()); user = userClient.getUser(user.getHref());
Checks.checkUser(user); checkUser(user);
assertTrue(equal(user.getFullName(), newUser.getFullName()), assertTrue(equal(user.getFullName(), newUser.getFullName()),
String.format(OBJ_FIELD_UPDATABLE, USER, "fullName")); String.format(OBJ_FIELD_UPDATABLE, USER, "fullName"));
assertTrue(equal(user.getEmailAddress(), newUser.getEmailAddress()), assertTrue(equal(user.getEmailAddress(), newUser.getEmailAddress()),
@ -213,8 +210,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
} }
} }
@Test(description = "DELETE /admin/user/{id}", @Test(description = "DELETE /admin/user/{id}", dependsOnMethods = { "testCreateUser" })
dependsOnMethods = { "testCreateUser" } )
public void testDeleteUser() { public void testDeleteUser() {
// Create a user to be deleted (so we remove dependencies on test ordering) // Create a user to be deleted (so we remove dependencies on test ordering)
User newUser = randomTestUser("testDeleteUser"+getTestDateTimeStamp()); User newUser = randomTestUser("testDeleteUser"+getTestDateTimeStamp());
@ -224,18 +220,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
userClient.deleteUser(userToBeDeleted.getHref()); userClient.deleteUser(userToBeDeleted.getHref());
// Confirm cannot no longer be accessed // Confirm cannot no longer be accessed
Error expected = Error.builder() User deleted = userClient.getUser(userToBeDeleted.getHref());
.message("No access to entity \"(com.vmware.vcloud.entity.user:"+ assertNull(deleted);
userToBeDeleted.getId().substring("urn:vcloud:user:".length())+")\".")
.majorErrorCode(403)
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build();
try {
userClient.getUser(userToBeDeleted.getHref());
fail("Should give HTTP 403 error for accessing user after deleting it ("+userToBeDeleted+")");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
}
} }
} }