correctly use roles for create/update User tests

This commit is contained in:
danikov 2012-03-20 19:13:46 +00:00
parent f25fb0807f
commit 0b9fbc025c
2 changed files with 41 additions and 16 deletions

View File

@ -110,7 +110,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
@Test(testName = "PUT /admin/catalog/{id}/owner", @Test(testName = "PUT /admin/catalog/{id}/owner",
dependsOnMethods = { "testGetCatalog" }) dependsOnMethods = { "testGetCatalog" })
public void updateCatalogOwner() { public void updateCatalogOwner() {
User newOwnerUser = UserClientLiveTest.randomTestUser("testUpdateCatalogOwner"); User newOwnerUser = UserClientLiveTest.randomTestUser("testUpdateCatalogOwner", context);
newOwnerUser = context.getApi().getUserClient().createUser(orgRef.getHref(), newOwnerUser); newOwnerUser = context.getApi().getUserClient().createUser(orgRef.getHref(), newOwnerUser);
assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner"); assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner");

View File

@ -27,18 +27,25 @@ import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertFalse;
import java.net.URI; import java.net.URI;
import java.util.Random;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
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.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Error; 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.RoleReferences;
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.domain.query.QueryResultRecordType;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRoleRecord;
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.AssertJUnit;
import org.testng.annotations.AfterClass; 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;
@ -65,6 +72,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
*/ */
private Reference orgRef; private Reference orgRef;
private User user; private User user;
private static Random random = new Random();
@Override @Override
@BeforeClass(inheritGroups = true) @BeforeClass(inheritGroups = true)
@ -86,12 +94,38 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(testName = "POST /admin/org/{id}/users") @Test(testName = "POST /admin/org/{id}/users")
public void testCreateUser() { public void testCreateUser() {
User newUser = randomTestUser("testCreateUser"); User newUser = randomTestUser("testCreateUser", context);
user = userClient.createUser(orgRef.getHref(), newUser); user = userClient.createUser(orgRef.getHref(), newUser);
Checks.checkUser(newUser); Checks.checkUser(newUser);
} }
public static User randomTestUser(String prefix) { public static Reference vAppUserRole(RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context) {
RoleReferences roles = context.getApi().getAdminQueryClient().roleReferencesQueryAll();
for (Reference role : roles.getReferences()) {
if (equal(role.getName(), "vApp User")) {
return Reference.builder().fromReference(role).build();
}
}
return null;
}
public static Reference nonVAppUserRole(RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context) {
RoleReferences roles = context.getApi().getAdminQueryClient().roleReferencesQueryAll();
for (Reference role : roles.getReferences()) {
if (!equal(role.getName(), "vApp User")) {
return Reference.builder().fromReference(role).build();
}
}
return null;
}
public static User randomTestUser(String prefix, RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context) {
return randomTestUser(prefix, vAppUserRole(context));
}
public static User randomTestUser(String prefix, Reference role) {
return User.builder() return User.builder()
.name(prefix+random.nextInt()) .name(prefix+random.nextInt())
.fullName("testFullName") .fullName("testFullName")
@ -104,10 +138,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.alertEmail("testAlert@test.com") .alertEmail("testAlert@test.com")
.isExternal(false) .isExternal(false)
.isGroupRole(false) .isGroupRole(false)
.role(Reference.builder() // FIXME: auto-fetch a role? or inject .role(role)
.name("vApp User")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/ff1e0c91-1288-3664-82b7-a6fa303af4d1"))
.build())
.password("password") .password("password")
.build(); .build();
} }
@ -123,9 +154,6 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(testName = "PUT /admin/user/{id}", @Test(testName = "PUT /admin/user/{id}",
dependsOnMethods = { "testGetUser" }) dependsOnMethods = { "testGetUser" })
public void testUpdateUser() { public void testUpdateUser() {
// TODO It seems that role.href doesn't need to be valid! I can run on
// greenhousedata with a bluelock uri!
User oldUser = user.toBuilder().build(); User oldUser = user.toBuilder().build();
User newUser = user.toBuilder() User newUser = user.toBuilder()
.fullName("new"+oldUser.getFullName()) .fullName("new"+oldUser.getFullName())
@ -141,10 +169,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.password("newPassword") .password("newPassword")
// TODO test setting other fields? // TODO test setting other fields?
// .name("new"+oldUser.getName()) // .name("new"+oldUser.getName())
// .role(Reference.builder() // FIXME: auto-fetch a role? or inject .role(nonVAppUserRole(context))
// .name("vApp Author")
// .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/1bf4457f-a253-3cf1-b163-f319f1a31802"))
// .build())
.build(); .build();
userClient.updateUser(user.getHref(), newUser); userClient.updateUser(user.getHref(), newUser);