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.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
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.CatalogType;
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.Media;
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")
public void testDeleteCatalogItem() {
catalogClient.deleteCatalogItem(catalogItem.getHref());
try {
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;
}
catalogItem = catalogClient.getCatalogItem(catalogItem.getHref());
assertNull(catalogItem);
}
@Test(description = "GET /catalog/{id}/metadata")
@ -283,15 +275,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
checkTask(deleteCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue"));
try {
catalogClient.getMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY");
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)));
}
MetadataValue deleted = catalogClient.getMetadataClient().getMetadataValue(catalogItem.getHref(), "KEY");
assertNull(deleted);
}
}

View File

@ -33,7 +33,6 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import java.io.IOException;
import java.net.URI;
import java.text.ParseException;
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.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
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 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.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertFalse;
@ -30,15 +31,11 @@ import java.net.URI;
import org.jclouds.rest.AuthorizationException;
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.Reference;
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.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.login.SessionClient;
import org.testng.annotations.AfterClass;
@ -90,7 +87,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testCreateUser() {
User newUser = randomTestUser("testCreateUser");
user = userClient.createUser(orgRef.getHref(), newUser);
Checks.checkUser(newUser);
checkUser(newUser);
}
@Test(description = "GET /admin/user/{id}",
@ -98,7 +95,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testGetUser() {
user = userClient.getUser(user.getHref());
Checks.checkUser(user);
checkUser(user);
}
@Test(description = "PUT /admin/user/{id}",
@ -125,7 +122,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
userClient.updateUser(user.getHref(), newUser);
user = userClient.getUser(user.getHref());
Checks.checkUser(user);
checkUser(user);
assertTrue(equal(user.getFullName(), newUser.getFullName()),
String.format(OBJ_FIELD_UPDATABLE, USER, "fullName"));
assertTrue(equal(user.getEmailAddress(), newUser.getEmailAddress()),
@ -213,8 +210,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
}
@Test(description = "DELETE /admin/user/{id}",
dependsOnMethods = { "testCreateUser" } )
@Test(description = "DELETE /admin/user/{id}", dependsOnMethods = { "testCreateUser" })
public void testDeleteUser() {
// Create a user to be deleted (so we remove dependencies on test ordering)
User newUser = randomTestUser("testDeleteUser"+getTestDateTimeStamp());
@ -224,18 +220,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
userClient.deleteUser(userToBeDeleted.getHref());
// Confirm cannot no longer be accessed
Error expected = Error.builder()
.message("No access to entity \"(com.vmware.vcloud.entity.user:"+
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);
}
User deleted = userClient.getUser(userToBeDeleted.getHref());
assertNull(deleted);
}
}