mirror of https://github.com/apache/jclouds.git
Live test disable / enableUser API
This commit is contained in:
parent
7b6ebefbd4
commit
616485364b
|
@ -30,6 +30,25 @@ import com.google.gson.annotations.SerializedName;
|
|||
*/
|
||||
public class User implements Comparable<User> {
|
||||
|
||||
public static enum State {
|
||||
ENABLED,
|
||||
DISABLED,
|
||||
UNKNOWN;
|
||||
|
||||
public static State fromValue(String value) {
|
||||
try {
|
||||
return valueOf(value.toUpperCase());
|
||||
} catch(IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
@ -41,7 +60,7 @@ public class User implements Comparable<User> {
|
|||
private String lastName;
|
||||
private String email;
|
||||
private Date created;
|
||||
private String state;
|
||||
private State state;
|
||||
private String account;
|
||||
private Account.Type accountType;
|
||||
private String domain;
|
||||
|
@ -80,7 +99,7 @@ public class User implements Comparable<User> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder state(String state) {
|
||||
public Builder state(State state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
@ -143,7 +162,7 @@ public class User implements Comparable<User> {
|
|||
private String lastName;
|
||||
private String email;
|
||||
private Date created;
|
||||
private String state;
|
||||
private State state;
|
||||
private String account;
|
||||
@SerializedName("accounttype")
|
||||
private Account.Type accountType;
|
||||
|
@ -157,7 +176,7 @@ public class User implements Comparable<User> {
|
|||
@SerializedName("secretkey")
|
||||
private String secretKey;
|
||||
|
||||
public User(long id, String name, String firstname, String lastname, String email, Date created, String state,
|
||||
public User(long id, String name, String firstname, String lastname, String email, Date created, State state,
|
||||
String account, Type accountType, String domain, long domainId, String timeZone, String apiKey,
|
||||
String secretKey) {
|
||||
this.id = id;
|
||||
|
@ -228,7 +247,7 @@ public class User implements Comparable<User> {
|
|||
*
|
||||
* @return the user state
|
||||
*/
|
||||
public String getState() {
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListUsersOptions;
|
||||
|
@ -26,6 +27,7 @@ import org.jclouds.rest.annotations.ExceptionParser;
|
|||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
|
@ -73,9 +75,9 @@ public interface DomainUserAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "disableUser")
|
||||
@SelectJson("user")
|
||||
@Unwrap
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<User> disableUser(@QueryParam("id") long userId);
|
||||
ListenableFuture<AsyncCreateResponse> disableUser(@QueryParam("id") long userId);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.options.ListUsersOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
@ -57,6 +58,6 @@ public interface DomainUserClient {
|
|||
/**
|
||||
* Disable a user with a specific ID
|
||||
*/
|
||||
User disableUser(long userId);
|
||||
AsyncCreateResponse disableUser(long userId);
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.jclouds.cloudstack.domain.PublicIPAddress;
|
|||
import org.jclouds.cloudstack.domain.SecurityGroup;
|
||||
import org.jclouds.cloudstack.domain.Template;
|
||||
import org.jclouds.cloudstack.domain.TemplateExtraction;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.json.Json;
|
||||
|
@ -62,6 +63,7 @@ public class ParseTypedAsyncJob implements Function<AsyncJob<Map<String, JsonBal
|
|||
@VisibleForTesting
|
||||
@Named("jclouds.cloudstack.jobresult-type-map")
|
||||
Map<String, Class<?>> typeMap = ImmutableMap.<String, Class<?>>builder()
|
||||
.put("user", User.class)
|
||||
.put("securitygroup", SecurityGroup.class)
|
||||
.put("portforwardingrule", PortForwardingRule.class)
|
||||
.put("ipforwardingrule", IPForwardingRule.class)
|
||||
|
|
|
@ -18,26 +18,37 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.AsyncJob;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.cloudstack.features.GlobalUserClientLiveTest.createTestAccount;
|
||||
import static org.jclouds.cloudstack.features.GlobalUserClientLiveTest.createTestUser;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code DomainUserClient}
|
||||
*
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "DomainUserClientLiveTest")
|
||||
public class DomainUserClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
@Test
|
||||
public void testListUsers() {
|
||||
assert domainAdminEnabled;
|
||||
|
||||
Set<User> users = domainAdminClient.getUserClient().listUsers();
|
||||
|
||||
assert users.size() > 0;
|
||||
assert users.contains(user); // contains the current user
|
||||
|
||||
for(User user : users) {
|
||||
for (User user : users) {
|
||||
checkUser(user);
|
||||
}
|
||||
}
|
||||
|
@ -47,4 +58,36 @@ public class DomainUserClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assert user.getAccount() != null;
|
||||
assert user.getDomain() != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnableDisableUser() {
|
||||
assert globalAdminEnabled && domainAdminEnabled;
|
||||
|
||||
Account testAccount = null;
|
||||
User testUser = null;
|
||||
try {
|
||||
testAccount = createTestAccount(globalAdminClient, prefix);
|
||||
testUser = createTestUser(globalAdminClient, testAccount, prefix);
|
||||
|
||||
AsyncCreateResponse response = domainAdminClient.getUserClient().disableUser(testUser.getId());
|
||||
assertNotNull(response);
|
||||
assertTrue(jobComplete.apply(response.getJobId()));
|
||||
|
||||
AsyncJob<User> job = domainAdminClient.getAsyncJobClient().getAsyncJob(response.getJobId());
|
||||
assertNotNull(job);
|
||||
assertEquals(job.getResult().getState(), User.State.DISABLED);
|
||||
|
||||
User updated = domainAdminClient.getUserClient().enableUser(testUser.getId());
|
||||
assertNotNull(updated);
|
||||
assertEquals(updated.getState(), User.State.ENABLED);
|
||||
|
||||
} finally {
|
||||
if (testUser != null) {
|
||||
globalAdminClient.getUserClient().deleteUser(testUser.getId());
|
||||
}
|
||||
if (testAccount != null) {
|
||||
globalAdminClient.getAccountClient().deleteAccount(testAccount.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.google.common.collect.Iterables;
|
|||
import com.google.inject.Module;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.CloudStackContext;
|
||||
import org.jclouds.cloudstack.CloudStackGlobalClient;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.ApiKeyPair;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
|
@ -46,20 +47,25 @@ import static org.testng.Assert.assertNotNull;
|
|||
@Test(groups = "live", singleThreaded = true, testName = "GlobalUserClientLiveTest")
|
||||
public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
private Account createTestAccount() {
|
||||
return globalAdminClient.getAccountClient().createAccount(
|
||||
public static Account createTestAccount(CloudStackGlobalClient client, String prefix) {
|
||||
return client.getAccountClient().createAccount(
|
||||
prefix + "-account", Account.Type.USER, "dummy@example.com",
|
||||
"First", "Last", "hashed-password");
|
||||
}
|
||||
|
||||
public static User createTestUser(CloudStackGlobalClient client, Account account, String prefix) {
|
||||
return client.getUserClient().createUser(prefix + "-user",
|
||||
account.getName(), "dummy2@example.com", "md5-password", "First", "Last");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUser() {
|
||||
Account testAccount = createTestAccount();
|
||||
assert globalAdminEnabled;
|
||||
|
||||
Account testAccount = createTestAccount(globalAdminClient, prefix);
|
||||
User testUser = null;
|
||||
try {
|
||||
testUser = globalAdminClient.getUserClient().createUser(prefix + "-user",
|
||||
testAccount.getName(), "dummy2@example.com", "md5-password", "First", "Last");
|
||||
testUser = createTestUser(globalAdminClient, testAccount, prefix);
|
||||
|
||||
assertNotNull(testUser);
|
||||
assertEquals(testUser.getName(), prefix + "-user");
|
||||
|
@ -71,13 +77,14 @@ public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assertNotNull(updatedUser);
|
||||
assertEquals(updatedUser.getName(), prefix + "-user-2");
|
||||
|
||||
/*
|
||||
ApiKeyPair apiKeys = globalAdminClient.getUserClient()
|
||||
.registerUserKeys(updatedUser.getId());
|
||||
|
||||
assertNotNull(apiKeys.getApiKey());
|
||||
assertNotNull(apiKeys.getSecretKey());
|
||||
|
||||
checkAuthAsUser(apiKeys);
|
||||
checkAuthAsUser(apiKeys); */
|
||||
|
||||
} finally {
|
||||
if (testUser != null) {
|
||||
|
|
|
@ -96,7 +96,7 @@ public class ListAccountsResponseTest extends BaseSetParserTest<Account> {
|
|||
ImmutableSet.of(User.builder().id(505).name("jclouds").firstName("Adrian").lastName("Cole")
|
||||
.email("adrian@jclouds.org")
|
||||
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-04-19T01:57:24+0000"))
|
||||
.state("enabled").account("jclouds").accountType(Type.USER).domainId(457)
|
||||
.state(User.State.ENABLED).account("jclouds").accountType(Type.USER).domainId(457)
|
||||
.domain("AA000062-jclouds-dev").apiKey("APIKEY").secretKey("SECRETKEY").build())).build());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue