Add listStoragePools to the GlobalStoragePool[Async]Client, with tests

This commit is contained in:
Richard Downer 2011-12-14 16:45:41 +00:00
parent ec46da8b59
commit c000db598d
4 changed files with 93 additions and 0 deletions

View File

@ -18,9 +18,19 @@
*/ */
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.StoragePool;
import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.ListStoragePoolsOptions;
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.SkipEncoding;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.core.MediaType;
import java.util.Set;
/** /**
* Provides asynchronous access to CloudStack storage pool features. * Provides asynchronous access to CloudStack storage pool features.
@ -32,5 +42,13 @@ import org.jclouds.rest.annotations.RequestFilters;
*/ */
@RequestFilters(QuerySigner.class) @RequestFilters(QuerySigner.class)
@QueryParams(keys = "response", values = "json") @QueryParams(keys = "response", values = "json")
@SkipEncoding({'/'})
public interface GlobalStoragePoolAsyncClient { public interface GlobalStoragePoolAsyncClient {
@GET
@QueryParams(keys = "command", values = "listStoragePools")
@SelectJson("storagepool")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Set<StoragePool>> listStoragePools(ListStoragePoolsOptions... options);
} }

View File

@ -18,8 +18,11 @@
*/ */
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.StoragePool;
import org.jclouds.cloudstack.options.ListStoragePoolsOptions;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -32,4 +35,7 @@ import java.util.concurrent.TimeUnit;
*/ */
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface GlobalStoragePoolClient { public interface GlobalStoragePoolClient {
Set<StoragePool> listStoragePools(ListStoragePoolsOptions... options);
} }

View File

@ -19,9 +19,15 @@
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import org.jclouds.cloudstack.options.ListStoragePoolsOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.lang.reflect.Method;
/** /**
* Tests behavior of {@code GlobalStoragePoolAsyncClient} * Tests behavior of {@code GlobalStoragePoolAsyncClient}
* *
@ -30,6 +36,38 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "GlobalStoragePoolAsyncClientTest") @Test(groups = "unit", testName = "GlobalStoragePoolAsyncClientTest")
public class GlobalStoragePoolAsyncClientTest extends BaseCloudStackAsyncClientTest<GlobalStoragePoolAsyncClient> { public class GlobalStoragePoolAsyncClientTest extends BaseCloudStackAsyncClientTest<GlobalStoragePoolAsyncClient> {
public void testListStoragePools() throws NoSuchMethodException {
Method method = GlobalStoragePoolAsyncClient.class.getMethod("listStoragePools", ListStoragePoolsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listStoragePools HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testListStoragePoolsOptions() throws NoSuchMethodException {
Method method = GlobalStoragePoolAsyncClient.class.getMethod("listStoragePools", ListStoragePoolsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, ListStoragePoolsOptions.Builder.clusterId(3).id(4).ipAddress("192.168.42.42").keyword("fred").name("bob").path("/mnt/store42").podId(4).zoneId(5));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listStoragePools&clusterid=3&id=4&ipaddress=192.168.42.42&keyword=fred&name=bob&path=/mnt/store42&podid=4&zoneid=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<GlobalStoragePoolAsyncClient>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<GlobalStoragePoolAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GlobalStoragePoolAsyncClient>>() { return new TypeLiteral<RestAnnotationProcessor<GlobalStoragePoolAsyncClient>>() {

View File

@ -18,8 +18,14 @@
*/ */
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import com.google.common.base.Strings;
import org.jclouds.cloudstack.domain.StoragePool;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.Set;
import static org.testng.Assert.*;
/** /**
* Tests behavior of {@code GlobalStoragePoolClient} * Tests behavior of {@code GlobalStoragePoolClient}
* *
@ -28,4 +34,29 @@ import org.testng.annotations.Test;
@Test(groups = "live", singleThreaded = true, testName = "GlobalStoragePoolClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "GlobalStoragePoolClientLiveTest")
public class GlobalStoragePoolClientLiveTest extends BaseCloudStackClientLiveTest { public class GlobalStoragePoolClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testListStoragePools() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
Set<StoragePool> result = globalAdminClient.getStoragePoolClient().listStoragePools();
assertNotNull(result);
assertTrue(result.size() > 0);
for(StoragePool pool : result) {
assertTrue(pool.getId() > 0);
assertFalse(Strings.isNullOrEmpty(pool.getName()));
assertFalse(Strings.isNullOrEmpty(pool.getPath()));
assertNotNull(pool.getTags());
assertTrue(pool.getState() != StoragePool.State.UNRECOGNIZED);
assertTrue(pool.getType() != StoragePool.Type.UNRECOGNIZED);
assertTrue(pool.getZoneId() > 0);
assertFalse(Strings.isNullOrEmpty(pool.getZoneName()));
assertTrue(pool.getPodId() > 0);
assertFalse(Strings.isNullOrEmpty(pool.getPodName()));
assertTrue(pool.getClusterId() > 0);
assertFalse(Strings.isNullOrEmpty(pool.getClusterName()));
assertNotNull(pool.getCreated());
assertTrue(pool.getDiskSizeTotal() > 0);
}
}
} }