mirror of https://github.com/apache/jclouds.git
adminCatalog live test now uses its own user/owner
This commit is contained in:
parent
4200f59c29
commit
f301a2ec18
|
@ -124,7 +124,14 @@ public class User extends EntityType {
|
|||
private Reference role;
|
||||
private String password;
|
||||
private List<Reference> groups = Lists.newArrayList();
|
||||
|
||||
|
||||
/**
|
||||
* @see EntityType#getName()
|
||||
*/
|
||||
public B name(String name) {
|
||||
return super.name(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see User#getFullName()
|
||||
*/
|
||||
|
|
|
@ -23,20 +23,23 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
|
|||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
|
||||
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;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
|
||||
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.Owner;
|
||||
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.User;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -106,24 +109,27 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
@Test(testName = "PUT /admin/catalog/{id}/owner",
|
||||
dependsOnMethods = { "testGetCatalog" })
|
||||
public void updateCatalogOwner() {
|
||||
User newOwnerUser = UserClientLiveTest.randomTestUser("testUpdateCatalogOwner");
|
||||
newOwnerUser = context.getApi().getUserClient().createUser(orgRef.getHref(), newOwnerUser);
|
||||
assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner");
|
||||
|
||||
Owner oldOwner = owner;
|
||||
Owner newOwner = Owner.builder() // TODO auto-find a new owner?
|
||||
Owner newOwner = Owner.builder()
|
||||
.type("application/vnd.vmware.vcloud.owner+xml")
|
||||
.user(Reference.builder()
|
||||
.type("application/vnd.vmware.admin.user+xml")
|
||||
.name("adk@cloudsoftcorp.com")
|
||||
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9"))
|
||||
.build())
|
||||
.user(Reference.builder().fromEntity(newOwnerUser).build())
|
||||
.build();
|
||||
|
||||
try {
|
||||
catalogClient.setOwner(catalog.getHref(), newOwner);
|
||||
owner = catalogClient.getOwner(catalog.getHref());
|
||||
Checks.checkOwner(owner);
|
||||
assertTrue(equal(owner, newOwner), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "owner"));
|
||||
assertTrue(equal(owner.toBuilder().links(Collections.<Link>emptySet()).build(),
|
||||
newOwner.toBuilder().user(newOwner.getUser().toBuilder().id(null).build()).build()),
|
||||
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "owner"));
|
||||
} finally {
|
||||
catalogClient.setOwner(catalog.getHref(), oldOwner);
|
||||
owner = catalogClient.getOwner(catalog.getHref());
|
||||
context.getApi().getUserClient().deleteUser(newOwnerUser.getHref());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,10 +86,12 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "POST /admin/org/{id}/users")
|
||||
public void testCreateUser() {
|
||||
String name = "a"+random.nextInt();
|
||||
|
||||
Checks.checkUser(randomTestUser("testCreateUser"));
|
||||
}
|
||||
|
||||
public static User randomTestUser(String prefix) {
|
||||
User newUser = User.builder()
|
||||
.name(name)
|
||||
.name(prefix+random.nextInt())
|
||||
.fullName("testFullName")
|
||||
.emailAddress("test@test.com")
|
||||
.telephone("555-1234")
|
||||
|
@ -106,9 +108,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
.build())
|
||||
.password("password")
|
||||
.build();
|
||||
user = userClient.createUser(orgRef.getHref(), newUser);
|
||||
|
||||
Checks.checkUser(user);
|
||||
return newUser;
|
||||
}
|
||||
|
||||
@Test(testName = "GET /admin/user/{id}",
|
||||
|
|
|
@ -120,7 +120,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
protected URI vdcURI;
|
||||
protected URI userURI;
|
||||
|
||||
protected Random random = new Random();
|
||||
protected static Random random = new Random();
|
||||
|
||||
protected BaseVCloudDirectorClientLiveTest() {
|
||||
provider = "vcloud-director";
|
||||
|
|
Loading…
Reference in New Issue