Live test disable / enableAccount API

This commit is contained in:
andreisavu 2011-12-12 22:55:42 +02:00
parent 616485364b
commit b6a58941e9
7 changed files with 63 additions and 21 deletions

View File

@ -20,11 +20,13 @@ package org.jclouds.cloudstack.features;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -53,7 +55,7 @@ public interface DomainAccountAsyncClient extends AccountAsyncClient {
@SelectJson("account") @SelectJson("account")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Account> enableAccount(@QueryParam("account") long accountId, @QueryParam("domainid") long domainId); ListenableFuture<Account> enableAccount(@QueryParam("account") String accountName, @QueryParam("domainid") long domainId);
/** /**
@ -61,10 +63,10 @@ public interface DomainAccountAsyncClient extends AccountAsyncClient {
*/ */
@GET @GET
@QueryParams(keys = "command", values = "disableAccount") @QueryParams(keys = "command", values = "disableAccount")
@SelectJson("account") @Unwrap
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Account> disableAccount(@QueryParam("account") long accountId, ListenableFuture<AsyncCreateResponse> disableAccount(@QueryParam("account") String accountName,
@QueryParam("domainid") long domainId, @QueryParam("lock") boolean onlyLock); @QueryParam("domainid") long domainId, @QueryParam("lock") boolean onlyLock);
} }

View File

@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
/** /**
@ -38,23 +39,23 @@ public interface DomainAccountClient extends AccountClient {
/** /**
* Enable an account * Enable an account
* *
* @param accountId * @param accountName
* the account ID you are enabling * the account name you are enabling
* @param domainId * @param domainId
* the domain ID * the domain ID
*/ */
public Account enableAccount(long accountId, long domainId); Account enableAccount(String accountName, long domainId);
/** /**
* Disable or lock an account * Disable or lock an account
* *
* @param accountId * @param accountName
* the account ID you are disabling * the account name you are disabling
* @param domainId * @param domainId
* the domain ID * the domain ID
* @param onlyLock * @param onlyLock
* only lock if true disable otherwise * only lock if true disable otherwise
*/ */
public Account disableAccount(long accountId, long domainId, boolean onlyLock); AsyncCreateResponse disableAccount(String accountName, long domainId, boolean onlyLock);
} }

View File

@ -29,6 +29,7 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.domain.AsyncJob; import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.AsyncJob.Builder; import org.jclouds.cloudstack.domain.AsyncJob.Builder;
import org.jclouds.cloudstack.domain.AsyncJobError; import org.jclouds.cloudstack.domain.AsyncJobError;
@ -64,6 +65,7 @@ public class ParseTypedAsyncJob implements Function<AsyncJob<Map<String, JsonBal
@Named("jclouds.cloudstack.jobresult-type-map") @Named("jclouds.cloudstack.jobresult-type-map")
Map<String, Class<?>> typeMap = ImmutableMap.<String, Class<?>>builder() Map<String, Class<?>> typeMap = ImmutableMap.<String, Class<?>>builder()
.put("user", User.class) .put("user", User.class)
.put("account", Account.class)
.put("securitygroup", SecurityGroup.class) .put("securitygroup", SecurityGroup.class)
.put("portforwardingrule", PortForwardingRule.class) .put("portforwardingrule", PortForwardingRule.class)
.put("ipforwardingrule", IPForwardingRule.class) .put("ipforwardingrule", IPForwardingRule.class)

View File

@ -18,8 +18,16 @@
*/ */
package org.jclouds.cloudstack.features; 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.testng.annotations.Test; import org.testng.annotations.Test;
import static org.jclouds.cloudstack.features.GlobalAccountClientLiveTest.createTestAccount;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
/** /**
* Tests behavior of {@code DomainAccountClient} * Tests behavior of {@code DomainAccountClient}
* *
@ -28,4 +36,32 @@ import org.testng.annotations.Test;
@Test(groups = "live", singleThreaded = true, testName = "DomainAccountClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "DomainAccountClientLiveTest")
public class DomainAccountClientLiveTest extends BaseCloudStackClientLiveTest { public class DomainAccountClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testEnableDisableAccount() {
assert globalAdminEnabled;
Account testAccount = null;
try {
testAccount = createTestAccount(globalAdminClient, prefix);
AsyncCreateResponse response = domainAdminClient.getAccountClient()
.disableAccount(testAccount.getName(), testAccount.getDomainId(), false);
assertNotNull(response);
assertTrue(jobComplete.apply(response.getJobId()));
AsyncJob<Account> job = domainAdminClient.getAsyncJobClient().getAsyncJob(response.getJobId());
assertEquals(job.getResult().getState(), Account.State.DISABLED);
Account updated = domainAdminClient.getAccountClient()
.enableAccount(testAccount.getName(), testAccount.getDomainId());
assertNotNull(updated);
assertEquals(updated.getState(), Account.State.ENABLED);
} finally {
if (testAccount != null) {
globalAdminClient.getAccountClient().deleteAccount(testAccount.getId());
}
}
}
} }

View File

@ -22,12 +22,11 @@ import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.AsyncJob; import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.User; import org.jclouds.cloudstack.domain.User;
import org.jclouds.logging.Logger;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.Set; import java.util.Set;
import static org.jclouds.cloudstack.features.GlobalUserClientLiveTest.createTestAccount; import static org.jclouds.cloudstack.features.GlobalAccountClientLiveTest.createTestAccount;
import static org.jclouds.cloudstack.features.GlobalUserClientLiveTest.createTestUser; import static org.jclouds.cloudstack.features.GlobalUserClientLiveTest.createTestUser;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.CloudStackGlobalClient;
import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.Account;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -32,13 +33,19 @@ import static org.testng.Assert.assertNotNull;
@Test(groups = "live", singleThreaded = true, testName = "GlobalAccountClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "GlobalAccountClientLiveTest")
public class GlobalAccountClientLiveTest extends BaseCloudStackClientLiveTest { public class GlobalAccountClientLiveTest extends BaseCloudStackClientLiveTest {
public static Account createTestAccount(CloudStackGlobalClient client, String prefix) {
return client.getAccountClient().createAccount(
prefix + "-account", Account.Type.USER, "dummy@example.com",
"First", "Last", "hashed-password");
}
@Test @Test
public void testCreateAndRemoveAccount() { public void testCreateAndRemoveAccount() {
assert globalAdminEnabled;
Account account = null; Account account = null;
try { try {
account = globalAdminClient.getAccountClient().createAccount( account = createTestAccount(globalAdminClient, prefix);
prefix + "-account", Account.Type.USER, "dummy@example.com",
"First", "Last", "hashed-password");
assertNotNull(account); assertNotNull(account);
assertEquals(account.getName(), prefix + "-account"); assertEquals(account.getName(), prefix + "-account");

View File

@ -19,10 +19,8 @@
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Module; import com.google.inject.Module;
import org.jclouds.cloudstack.CloudStackClient; import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.CloudStackContext;
import org.jclouds.cloudstack.CloudStackGlobalClient; import org.jclouds.cloudstack.CloudStackGlobalClient;
import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.domain.ApiKeyPair; import org.jclouds.cloudstack.domain.ApiKeyPair;
@ -37,6 +35,7 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.cloudstack.features.GlobalAccountClientLiveTest.createTestAccount;
import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.userName; import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.userName;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -47,11 +46,7 @@ import static org.testng.Assert.assertNotNull;
@Test(groups = "live", singleThreaded = true, testName = "GlobalUserClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "GlobalUserClientLiveTest")
public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest { public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest {
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) { public static User createTestUser(CloudStackGlobalClient client, Account account, String prefix) {
return client.getUserClient().createUser(prefix + "-user", return client.getUserClient().createUser(prefix + "-user",