You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ab...@apache.org on 2013/07/01 21:15:02 UTC
[15/24] JCLOUDS-151 - CloudStack refactored to remove async,
*Client renamed to *Api.
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java
deleted file mode 100644
index 04c7a87..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static org.testng.Assert.assertEquals;
-
-import java.util.Set;
-
-import org.jclouds.cloudstack.CloudStackApiMetadata;
-import org.jclouds.cloudstack.CloudStackContext;
-import org.jclouds.cloudstack.domain.Account;
-import org.jclouds.cloudstack.domain.User;
-import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableSet;
-
-/**
- * Test the CloudStack AccountClient
- *
- * @author Andrei Savu
- */
-@Test(groups = "unit", testName = "AccountClientExpectTest")
-public class AccountClientExpectTest extends BaseCloudStackExpectTest<AccountClient> {
-
-
- public void testListAccountsWhenResponseIs2xx() {
-
- AccountClient client = requestSendsResponse(
- HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&apiKey=identity&signature=yMZYMZxzFlaUsbfxtuppMwNhpXI%3D")
- .addHeader("Accept", "application/json")
- .build(),
- HttpResponse.builder()
- .statusCode(200)
- .payload(payloadFromResource("/listaccountsresponse.json"))
- .build());
-
- Set<User> users = 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(User.State.ENABLED)
- .account("jclouds")
- .accountType(Account.Type.USER)
- .domainId("457")
- .domain("AA000062-jclouds-dev")
- .apiKey("APIKEY")
- .secretKey("SECRETKEY").build());
-
- assertEquals(client.listAccounts(),
- ImmutableSet.of(Account.builder()
- .id("505")
- .name("jclouds")
- .type(Account.Type.USER)
- .domainId("457")
- .domain("AA000062-jclouds-dev")
- .receivedBytes(318900216)
- .sentBytes(23189677)
- .VMLimit(15l)
- .VMs(1)
- .IPsAvailable(14l)
- .IPLimit(15l)
- .IPs(0)
- .IPsAvailable(15l)
- .volumeLimit(90l)
- .volumes(2)
- .volumesAvailable(88l)
- .snapshotLimit(250l)
- .snapshots(0)
- .snapshotsAvailable(250l)
- .templateLimit(15l)
- .templates(0)
- .templatesAvailable(15l)
- .VMsAvailable(14l)
- .VMsStopped(0)
- .VMsRunning(1)
- .state(Account.State.ENABLED)
- .users(users).build()));
- }
-
- @Override
- protected AccountClient clientFrom(CloudStackContext context) {
- return context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi().getAccountClient();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java
deleted file mode 100644
index 262e842..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static org.testng.Assert.assertEquals;
-
-import org.jclouds.cloudstack.domain.Account;
-import org.jclouds.cloudstack.domain.User;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code AccountClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "AccountClientLiveTest")
-public class AccountClientLiveTest extends BaseCloudStackClientLiveTest {
-
- @Test
- public void testListAccounts() throws Exception {
- for (Account securityAccount : client.getAccountClient().listAccounts())
- checkAccount(securityAccount);
- }
-
- protected void checkAccount(Account account) {
- assert account.getId() != null : account;
- assertEquals(account.toString(), client.getAccountClient().getAccount(account.getId()).toString());
- assert account.getName() != null : account;
- assert account.getType() != null && account.getType() != Account.Type.UNRECOGNIZED : account;
- assert account.getDomain() != null : account;
- assert account.getDomainId() != null : account;
- assert account.getUsers() != null : account;
- for (User user : account.getUsers()) {
- assert user.getName() != null : user;
- assert user.getAccountType().equals(account.getType()) : user;
- assert user.getDomain().equals(account.getDomain()) : user;
- assert user.getDomainId().equals(account.getDomainId()) : user;
- assert user.getCreated() != null : user;
- assert user.getEmail() != null : user;
- assert user.getLastName() != null : user;
- assert user.getFirstName() != null : user;
- assert user.getId() != null : user;
- assert user.getState() != null : user;
- }
- assert account.getIPsAvailable() == null || account.getIPsAvailable() >= 0 : account;
- assert account.getIPLimit() == null || account.getIPLimit() >= 0 : account;
- assert account.getIPs() >= 0 : account;
- assert account.getReceivedBytes() >= 0 : account;
- assert account.getSentBytes() >= 0 : account;
- assert account.getSnapshotsAvailable() == null || account.getSnapshotsAvailable() >= 0 : account;
- assert account.getSnapshotLimit() == null || account.getSnapshotLimit() >= 0 : account;
- assert account.getSnapshots() >= 0 : account;
- assert account.getState() != null && account.getState() != Account.State.UNRECOGNIZED : account;
- assert account.getTemplatesAvailable() == null || account.getTemplatesAvailable() >= 0 : account;
- assert account.getTemplateLimit() == null || account.getTemplateLimit() >= 0 : account;
- assert account.getTemplates() >= 0 : account;
- assert account.getVMsAvailable() == null || account.getVMsAvailable() >= 0 : account;
- assert account.getVMLimit() == null || account.getVMLimit() >= 0 : account;
- assert account.getVMsRunning() >= 0 : account;
- assert account.getVMsStopped() >= 0 : account;
- assert account.getVMs() >= 0 : account;
- assert account.getVolumesAvailable() == null || account.getVolumesAvailable() >= 0 : account;
- assert account.getVolumeLimit() == null || account.getVolumeLimit() >= 0 : account;
- assert account.getVolumes() >= 0 : account;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java
new file mode 100644
index 0000000..d7f6d12
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.collect.Iterables.getOnlyElement;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.cloudstack.domain.AsyncCreateResponse;
+import org.jclouds.cloudstack.domain.PublicIPAddress;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
+import org.testng.annotations.AfterGroups;
+import org.testng.annotations.BeforeGroups;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of {@code AddressApi}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live", singleThreaded = true, testName = "AddressApiLiveTest")
+public class AddressApiLiveTest extends BaseCloudStackApiLiveTest {
+ private boolean networksEnabled;
+
+ @BeforeGroups(groups = "live")
+ void networksEnabled() {
+ networksEnabled = client.getNetworkApi().listNetworks().size() > 0;
+ }
+
+ private PublicIPAddress ip = null;
+
+ public void testAssociateDisassociatePublicIPAddress() throws Exception {
+ if (!networksEnabled)
+ return;
+ AsyncCreateResponse job = client.getAddressApi().associateIPAddressInZone(
+ Iterables.get(client.getNetworkApi().listNetworks(), 0).getZoneId());
+ checkState(jobComplete.apply(job.getJobId()), "job %s failed to complete", job.getJobId());
+ ip = client.getAsyncJobApi().<PublicIPAddress> getAsyncJob(job.getJobId()).getResult();
+ checkIP(ip);
+ }
+
+ @AfterGroups(groups = "live")
+ @Override
+ protected void tearDownContext() {
+ if (ip != null) {
+ client.getAddressApi().disassociateIPAddress(ip.getId());
+ }
+ super.tearDownContext();
+ }
+
+ public void testListPublicIPAddresss() throws Exception {
+ if (!networksEnabled)
+ return;
+ Set<PublicIPAddress> response = client.getAddressApi().listPublicIPAddresses();
+ assert null != response;
+ assertTrue(response.size() >= 0);
+ for (PublicIPAddress ip : response) {
+ PublicIPAddress newDetails = getOnlyElement(client.getAddressApi().listPublicIPAddresses(
+ ListPublicIPAddressesOptions.Builder.id(ip.getId())));
+ assertEquals(ip.getId(), newDetails.getId());
+ checkIP(ip);
+ }
+ }
+
+ protected void checkIP(PublicIPAddress ip) {
+ assertEquals(ip.getId(), client.getAddressApi().getPublicIPAddress(ip.getId()).getId());
+ assert ip.getId() != null : ip;
+ assert ip.getAccount() != null : ip;
+ assert ip.getDomain() != null : ip;
+ assert ip.getDomainId() != null : ip;
+ assert ip.getState() != null : ip;
+ assert ip.getZoneId() != null : ip;
+ assert ip.getZoneName() != null : ip;
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java
new file mode 100644
index 0000000..73da2cd
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static org.jclouds.reflect.Reflection2.method;
+
+import java.io.IOException;
+
+import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
+import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.cloudstack.functions.CloudStackFallbacks.VoidOnNotFoundOr404OrUnableToFindAccountOwner;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.AssociateIPAddressOptions;
+import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
+import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
+import org.jclouds.functions.IdentityFunction;
+import org.jclouds.http.functions.ParseFirstJsonValueNamed;
+import org.jclouds.http.functions.ReleasePayloadAndReturn;
+import org.jclouds.http.functions.UnwrapOnlyJsonValue;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Functions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.reflect.Invokable;
+/**
+ * Tests behavior of {@code AddressApi}
+ *
+ * @author Adrian Cole
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "AddressApiTest")
+public class AddressApiTest extends BaseCloudStackApiTest<AddressApi> {
+ public void testListPublicIPAddresses() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AddressApi.class, "listPublicIPAddresses", ListPublicIPAddressesOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testListPublicIPAddressesOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AddressApi.class, "listPublicIPAddresses", ListPublicIPAddressesOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
+ ListPublicIPAddressesOptions.Builder.accountInDomain("adrian", "6").usesVirtualNetwork(true)));
+
+ assertRequestLineEquals(
+ httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true&account=adrian&domainid=6&forvirtualnetwork=true HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testGetPublicIPAddress() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AddressApi.class, "getPublicIPAddress", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true&id=5 HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest,
+ Functions.compose(IdentityFunction.INSTANCE, IdentityFunction.INSTANCE).getClass());
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testAssociateIPAddressInZone() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AddressApi.class, "associateIPAddressInZone", String.class,
+ AssociateIPAddressOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(6));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=associateIpAddress&zoneid=6 HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testDisassociateIPAddress() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AddressApi.class, "disassociateIPAddress", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=disassociateIpAddress&id=5 HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, VoidOnNotFoundOr404OrUnableToFindAccountOwner.class);
+
+ checkFilters(httpRequest);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java
deleted file mode 100644
index 04af035..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static org.jclouds.reflect.Reflection2.method;
-
-import java.io.IOException;
-
-import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.cloudstack.functions.CloudStackFallbacks.VoidOnNotFoundOr404OrUnableToFindAccountOwner;
-import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.cloudstack.options.AssociateIPAddressOptions;
-import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
-import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
-import org.jclouds.functions.IdentityFunction;
-import org.jclouds.http.functions.ParseFirstJsonValueNamed;
-import org.jclouds.http.functions.ReleasePayloadAndReturn;
-import org.jclouds.http.functions.UnwrapOnlyJsonValue;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Functions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-/**
- * Tests behavior of {@code AddressAsyncClient}
- *
- * @author Adrian Cole
- */
-// NOTE:without testName, this will not call @Before* and fail w/NPE during
-// surefire
-@Test(groups = "unit", testName = "AddressAsyncClientTest")
-public class AddressAsyncClientTest extends BaseCloudStackAsyncClientTest<AddressAsyncClient> {
- public void testListPublicIPAddresses() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AddressAsyncClient.class, "listPublicIPAddresses", ListPublicIPAddressesOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testListPublicIPAddressesOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AddressAsyncClient.class, "listPublicIPAddresses", ListPublicIPAddressesOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
- ListPublicIPAddressesOptions.Builder.accountInDomain("adrian", "6").usesVirtualNetwork(true)));
-
- assertRequestLineEquals(
- httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true&account=adrian&domainid=6&forvirtualnetwork=true HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testGetPublicIPAddress() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AddressAsyncClient.class, "getPublicIPAddress", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true&id=5 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest,
- Functions.compose(IdentityFunction.INSTANCE, IdentityFunction.INSTANCE).getClass());
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testAssociateIPAddressInZone() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AddressAsyncClient.class, "associateIPAddressInZone", String.class,
- AssociateIPAddressOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(6));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=associateIpAddress&zoneid=6 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testDisassociateIPAddress() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AddressAsyncClient.class, "disassociateIPAddress", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=disassociateIpAddress&id=5 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, VoidOnNotFoundOr404OrUnableToFindAccountOwner.class);
-
- checkFilters(httpRequest);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressClientLiveTest.java
deleted file mode 100644
index dcc4d34..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressClientLiveTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Set;
-
-import org.jclouds.cloudstack.domain.AsyncCreateResponse;
-import org.jclouds.cloudstack.domain.PublicIPAddress;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
-import org.testng.annotations.AfterGroups;
-import org.testng.annotations.BeforeGroups;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.Iterables;
-
-/**
- * Tests behavior of {@code AddressClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "AddressClientLiveTest")
-public class AddressClientLiveTest extends BaseCloudStackClientLiveTest {
- private boolean networksEnabled;
-
- @BeforeGroups(groups = "live")
- void networksEnabled() {
- networksEnabled = client.getNetworkClient().listNetworks().size() > 0;
- }
-
- private PublicIPAddress ip = null;
-
- public void testAssociateDisassociatePublicIPAddress() throws Exception {
- if (!networksEnabled)
- return;
- AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone(
- Iterables.get(client.getNetworkClient().listNetworks(), 0).getZoneId());
- checkState(jobComplete.apply(job.getJobId()), "job %s failed to complete", job.getJobId());
- ip = client.getAsyncJobClient().<PublicIPAddress> getAsyncJob(job.getJobId()).getResult();
- checkIP(ip);
- }
-
- @AfterGroups(groups = "live")
- @Override
- protected void tearDownContext() {
- if (ip != null) {
- client.getAddressClient().disassociateIPAddress(ip.getId());
- }
- super.tearDownContext();
- }
-
- public void testListPublicIPAddresss() throws Exception {
- if (!networksEnabled)
- return;
- Set<PublicIPAddress> response = client.getAddressClient().listPublicIPAddresses();
- assert null != response;
- assertTrue(response.size() >= 0);
- for (PublicIPAddress ip : response) {
- PublicIPAddress newDetails = getOnlyElement(client.getAddressClient().listPublicIPAddresses(
- ListPublicIPAddressesOptions.Builder.id(ip.getId())));
- assertEquals(ip.getId(), newDetails.getId());
- checkIP(ip);
- }
- }
-
- protected void checkIP(PublicIPAddress ip) {
- assertEquals(ip.getId(), client.getAddressClient().getPublicIPAddress(ip.getId()).getId());
- assert ip.getId() != null : ip;
- assert ip.getAccount() != null : ip;
- assert ip.getDomain() != null : ip;
- assert ip.getDomainId() != null : ip;
- assert ip.getState() != null : ip;
- assert ip.getZoneId() != null : ip;
- assert ip.getZoneName() != null : ip;
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java
new file mode 100644
index 0000000..ced5d2a
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.cloudstack.domain.AsyncJob;
+import org.jclouds.cloudstack.domain.AsyncJob.ResultCode;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code AsyncJobApiLiveTest}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live", singleThreaded = true, testName = "AsyncJobApiLiveTest")
+public class AsyncJobApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ @Test(enabled = true)
+ public void testListAsyncJobs() throws Exception {
+ Set<AsyncJob<?>> response = client.getAsyncJobApi().listAsyncJobs();
+ assert null != response;
+
+ long asyncJobCount = response.size();
+ assertTrue(asyncJobCount >= 0);
+
+ for (AsyncJob<?> asyncJob : response) {
+ assert asyncJob.getCmd() != null : asyncJob;
+ assert asyncJob.getUserId() != null : asyncJob;
+ checkJob(asyncJob);
+
+ AsyncJob<?> query = client.getAsyncJobApi().getAsyncJob(asyncJob.getId());
+ assertEquals(query.getId(), asyncJob.getId());
+
+ assert query.getResultType() != null : query;
+ checkJob(query);
+ }
+ }
+
+ private void checkJob(AsyncJob<?> query) {
+ assert query.getStatus().code() >= 0 : query;
+ assert query.getResultCode().code() >= 0 : query;
+ assert query.getProgress() >= 0 : query;
+ if (query.getResultCode() == ResultCode.SUCCESS) {
+ if (query.getResult() != null) {
+ assertEquals(query.getResult().getClass().getPackage(), AsyncJob.class.getPackage());
+ }
+ } else if (query.getResultCode() == ResultCode.FAIL) {
+ assert query.getResult() == null : query;
+ assert query.getError() != null : query;
+ } else {
+ assert query.getResult() == null : query;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java
new file mode 100644
index 0000000..b8f0d5d
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static org.jclouds.reflect.Reflection2.method;
+
+import java.io.IOException;
+
+import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
+import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.cloudstack.functions.ParseAsyncJobFromHttpResponse;
+import org.jclouds.cloudstack.functions.ParseAsyncJobsFromHttpResponse;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.ListAsyncJobsOptions;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.reflect.Invokable;
+
+/**
+ * Tests behavior of {@code AsyncJobApi}
+ *
+ * @author Adrian Cole
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "AsyncJobApiTest")
+public class AsyncJobApiTest extends BaseCloudStackApiTest<AsyncJobApi> {
+
+ public void testGetAsyncJob() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AsyncJobApi.class, "getAsyncJob", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(11l));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=queryAsyncJobResult&jobid=11 HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobFromHttpResponse.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testListAsyncJobs() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AsyncJobApi.class, "listAsyncJobs", ListAsyncJobsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs&listAll=true HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobsFromHttpResponse.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testListAsyncJobsOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(AsyncJobApi.class, "listAsyncJobs", ListAsyncJobsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
+ ListAsyncJobsOptions.Builder.accountInDomain("adrian", "5")));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs&listAll=true&account=adrian&domainid=5 HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobsFromHttpResponse.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java
deleted file mode 100644
index 057f08c..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static org.jclouds.reflect.Reflection2.method;
-
-import java.io.IOException;
-
-import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.cloudstack.functions.ParseAsyncJobFromHttpResponse;
-import org.jclouds.cloudstack.functions.ParseAsyncJobsFromHttpResponse;
-import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.cloudstack.options.ListAsyncJobsOptions;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-
-/**
- * Tests behavior of {@code AsyncJobAsyncClient}
- *
- * @author Adrian Cole
- */
-// NOTE:without testName, this will not call @Before* and fail w/NPE during
-// surefire
-@Test(groups = "unit", testName = "AsyncJobAsyncClientTest")
-public class AsyncJobAsyncClientTest extends BaseCloudStackAsyncClientTest<AsyncJobAsyncClient> {
-
- public void testGetAsyncJob() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AsyncJobAsyncClient.class, "getAsyncJob", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(11l));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=queryAsyncJobResult&jobid=11 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobFromHttpResponse.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testListAsyncJobs() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AsyncJobAsyncClient.class, "listAsyncJobs", ListAsyncJobsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs&listAll=true HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobsFromHttpResponse.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testListAsyncJobsOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AsyncJobAsyncClient.class, "listAsyncJobs", ListAsyncJobsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
- ListAsyncJobsOptions.Builder.accountInDomain("adrian", "5")));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs&listAll=true&account=adrian&domainid=5 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobsFromHttpResponse.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java
deleted file mode 100644
index c2b9113..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Set;
-
-import org.jclouds.cloudstack.domain.AsyncJob;
-import org.jclouds.cloudstack.domain.AsyncJob.ResultCode;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code AsyncJobClientLiveTest}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "AsyncJobClientLiveTest")
-public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest {
-
- @Test(enabled = true)
- public void testListAsyncJobs() throws Exception {
- Set<AsyncJob<?>> response = client.getAsyncJobClient().listAsyncJobs();
- assert null != response;
-
- long asyncJobCount = response.size();
- assertTrue(asyncJobCount >= 0);
-
- for (AsyncJob<?> asyncJob : response) {
- assert asyncJob.getCmd() != null : asyncJob;
- assert asyncJob.getUserId() != null : asyncJob;
- checkJob(asyncJob);
-
- AsyncJob<?> query = client.getAsyncJobClient().getAsyncJob(asyncJob.getId());
- assertEquals(query.getId(), asyncJob.getId());
-
- assert query.getResultType() != null : query;
- checkJob(query);
- }
- }
-
- private void checkJob(AsyncJob<?> query) {
- assert query.getStatus().code() >= 0 : query;
- assert query.getResultCode().code() >= 0 : query;
- assert query.getProgress() >= 0 : query;
- if (query.getResultCode() == ResultCode.SUCCESS) {
- if (query.getResult() != null) {
- assertEquals(query.getResult().getClass().getPackage(), AsyncJob.class.getPackage());
- }
- } else if (query.getResultCode() == ResultCode.FAIL) {
- assert query.getResult() == null : query;
- assert query.getError() != null : query;
- } else {
- assert query.getResult() == null : query;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java
new file mode 100644
index 0000000..4038c29
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import org.jclouds.cloudstack.domain.Capabilities;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code ConfigurationApiLiveTest}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live", singleThreaded = true, testName = "ConfigurationApiLiveTest")
+public class ConfigurationApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ public void testListCapabilities() throws Exception {
+ Capabilities response = client.getConfigurationApi().listCapabilities();
+ assert null != response;
+ assert null != response.getCloudStackVersion();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java
new file mode 100644
index 0000000..2b79497
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static org.jclouds.reflect.Reflection2.method;
+
+import java.io.IOException;
+
+import org.jclouds.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
+import org.jclouds.http.functions.ParseFirstJsonValueNamed;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.reflect.Invokable;
+/**
+ * Tests behavior of {@code ConfigurationApi}
+ *
+ * @author Adrian Cole
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "ConfigurationApiTest")
+public class ConfigurationApiTest extends BaseCloudStackApiTest<ConfigurationApi> {
+
+ public void testListCapabilities() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(ConfigurationApi.class, "listCapabilities");
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&listAll=true&command=listCapabilities HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class);
+
+ checkFilters(httpRequest);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationAsyncClientTest.java
deleted file mode 100644
index 0ec57f4..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationAsyncClientTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static org.jclouds.reflect.Reflection2.method;
-
-import java.io.IOException;
-
-import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
-import org.jclouds.http.functions.ParseFirstJsonValueNamed;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-/**
- * Tests behavior of {@code ConfigurationAsyncClient}
- *
- * @author Adrian Cole
- */
-// NOTE:without testName, this will not call @Before* and fail w/NPE during
-// surefire
-@Test(groups = "unit", testName = "ConfigurationAsyncClientTest")
-public class ConfigurationAsyncClientTest extends BaseCloudStackAsyncClientTest<ConfigurationAsyncClient> {
-
- public void testListCapabilities() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(ConfigurationAsyncClient.class, "listCapabilities");
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&listAll=true&command=listCapabilities HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class);
-
- checkFilters(httpRequest);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationClientLiveTest.java
deleted file mode 100644
index edb5b62..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ConfigurationClientLiveTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import org.jclouds.cloudstack.domain.Capabilities;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code ConfigurationClientLiveTest}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "ConfigurationClientLiveTest")
-public class ConfigurationClientLiveTest extends BaseCloudStackClientLiveTest {
-
- public void testListCapabilities() throws Exception {
- Capabilities response = client.getConfigurationClient().listCapabilities();
- assert null != response;
- assert null != response.getCloudStackVersion();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java
new file mode 100644
index 0000000..06c30f2
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static org.jclouds.cloudstack.features.GlobalAccountApiLiveTest.createTestAccount;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.cloudstack.domain.Account;
+import org.jclouds.cloudstack.domain.AsyncCreateResponse;
+import org.jclouds.cloudstack.domain.AsyncJob;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code DomainAccountApi}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live", singleThreaded = true, testName = "DomainAccountApiLiveTest")
+public class DomainAccountApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ @Test
+ public void testEnableDisableAccount() {
+ skipIfNotGlobalAdmin();
+
+ Account testAccount = null;
+ try {
+ testAccount = createTestAccount(globalAdminClient, prefix);
+
+ AsyncCreateResponse response = domainAdminClient.getAccountApi()
+ .disableAccount(testAccount.getName(), testAccount.getDomainId(), false);
+ assertNotNull(response);
+ assertTrue(jobComplete.apply(response.getJobId()));
+
+ AsyncJob<Account> job = domainAdminClient.getAsyncJobApi().getAsyncJob(response.getJobId());
+ assertEquals(job.getResult().getState(), Account.State.DISABLED);
+
+ Account updated = domainAdminClient.getAccountApi()
+ .enableAccount(testAccount.getName(), testAccount.getDomainId());
+ assertNotNull(updated);
+ assertEquals(updated.getState(), Account.State.ENABLED);
+
+ } finally {
+ if (testAccount != null) {
+ globalAdminClient.getAccountApi().deleteAccount(testAccount.getId());
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java
new file mode 100644
index 0000000..4746f0f
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static org.jclouds.reflect.Reflection2.method;
+
+import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.http.functions.ParseFirstJsonValueNamed;
+import org.jclouds.http.functions.UnwrapOnlyJsonValue;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.reflect.Invokable;
+/**
+ * Tests behavior of {@code DomainAccountApi}
+ *
+ * @author Adrian
+ */
+@Test(groups = "unit", testName = "DomainAccountApiTest")
+public class DomainAccountApiTest extends BaseCloudStackApiTest<DomainAccountApi> {
+
+ public void testEnableAccount() throws Exception {
+ Invokable<?, ?> method = method(DomainAccountApi.class, "enableAccount", String.class, String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("goo", "2"));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=enableAccount&account=goo&domainid=2 HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+ }
+
+ public void testDisableAccount() throws Exception {
+ Invokable<?, ?> method = method(DomainAccountApi.class, "disableAccount", String.class, String.class, boolean.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("1", "2", true));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=disableAccount&account=1&domainid=2&lock=true HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountAsyncClientTest.java
deleted file mode 100644
index 251e8e3..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountAsyncClientTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-import static org.jclouds.reflect.Reflection2.method;
-
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.http.functions.ParseFirstJsonValueNamed;
-import org.jclouds.http.functions.UnwrapOnlyJsonValue;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-/**
- * Tests behavior of {@code DomainAccountAsyncClient}
- *
- * @author Adrian
- */
-@Test(groups = "unit", testName = "DomainAccountAsyncClientTest")
-public class DomainAccountAsyncClientTest extends BaseCloudStackAsyncClientTest<DomainAccountAsyncClient> {
-
- public void testEnableAccount() throws Exception {
- Invokable<?, ?> method = method(DomainAccountAsyncClient.class, "enableAccount", String.class, String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("goo", "2"));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=enableAccount&account=goo&domainid=2 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
- }
-
- public void testDisableAccount() throws Exception {
- Invokable<?, ?> method = method(DomainAccountAsyncClient.class, "disableAccount", String.class, String.class, boolean.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("1", "2", true));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=disableAccount&account=1&domainid=2&lock=true HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java
deleted file mode 100644
index f4d81f5..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.cloudstack.features;
-
-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;
-
-import org.jclouds.cloudstack.domain.Account;
-import org.jclouds.cloudstack.domain.AsyncCreateResponse;
-import org.jclouds.cloudstack.domain.AsyncJob;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code DomainAccountClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "DomainAccountClientLiveTest")
-public class DomainAccountClientLiveTest extends BaseCloudStackClientLiveTest {
-
- @Test
- public void testEnableDisableAccount() {
- skipIfNotGlobalAdmin();
-
- 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());
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java
new file mode 100644
index 0000000..469d336
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.net.URI;
+
+import org.jclouds.cloudstack.CloudStackContext;
+import org.jclouds.cloudstack.domain.Domain;
+import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Test the CloudStack DomainDomainApi
+ *
+ * @author Andrei Savu
+ */
+@Test(groups = "unit", testName = "DomainDomainApiExpectTest")
+public class DomainDomainApiExpectTest extends BaseCloudStackExpectTest<DomainDomainApi> {
+
+ public void testListDomainsWhenResponseIs2xx() {
+ DomainDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=listDomains&listAll=true&apiKey=identity&signature=sVFaGTu0DNSTVtWy3wtRt7KTx0w%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/listdomainsresponse.json"))
+ .build());
+
+ assertEquals(client.listDomains(),
+ ImmutableSet.of(
+ Domain.builder().id("1").name("ROOT").level(0).hasChild(true).build(),
+ Domain.builder().id("2").name("jclouds1").level(1).parentDomainId("1")
+ .parentDomainName("ROOT").hasChild(false).build()
+ ));
+ }
+
+ public void testListDomainsWhenResponseIs404() {
+ DomainDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=listDomains&listAll=true&apiKey=identity&signature=sVFaGTu0DNSTVtWy3wtRt7KTx0w%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(404)
+ .build());
+
+ assertEquals(client.listDomains(), ImmutableSet.of());
+ }
+
+ public void testGetDomainWhenResponseIs2xx() {
+ DomainDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST/cIRUHvWhfWovJugU%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/getdomainresponse.json"))
+ .build());
+
+ assertEquals(client.getDomainById("1"),
+ Domain.builder().id("1").name("ROOT").level(0).hasChild(true).build());
+ }
+
+ public void testGetDomainWhenResponseIs404() {
+ DomainDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST/cIRUHvWhfWovJugU%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(404)
+ .build());
+
+ assertNull(client.getDomainById("1"));
+ }
+
+ public void testListDomainChildrenWhenResponseIs2xx() {
+ DomainDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=listDomainChildren&listAll=true&id=1&isrecursive=true&apiKey=identity&signature=Jn6kFkloRvfaaivlJiHd0F5J3Jk%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/listdomainchildrenresponse.json"))
+ .build());
+
+ assertEquals(client.listDomainChildren(parentDomainId("1").isRecursive(true)),
+ ImmutableSet.of(
+ Domain.builder().id("2").name("jclouds1").level(1).parentDomainId("1")
+ .parentDomainName("ROOT").hasChild(false).build(),
+ Domain.builder().id("3").name("jclouds2").level(1).parentDomainId("1")
+ .parentDomainName("ROOT").hasChild(false).build()
+ ));
+ }
+
+ public void testListDomainChildrenWhenResponseIs404() {
+ DomainDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=listDomainChildren&listAll=true&id=1&isrecursive=true&apiKey=identity&" +
+ "signature=Jn6kFkloRvfaaivlJiHd0F5J3Jk%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(404)
+ .build());
+
+ assertEquals(client.listDomainChildren(parentDomainId("1").isRecursive(true)), ImmutableSet.of());
+ }
+
+ @Override
+ protected DomainDomainApi clientFrom(CloudStackContext context) {
+ return context.getDomainApi().getDomainClient();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java
new file mode 100644
index 0000000..5e491d0
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.cloudstack.features;
+
+import static com.google.common.collect.Sets.newHashSet;
+import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId;
+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 java.util.NoSuchElementException;
+import java.util.Set;
+
+import org.jclouds.cloudstack.domain.Domain;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
+/**
+ * Tests behavior of {@code DomainDomainApi}
+ *
+ * @author Andrei Savu
+ */
+@Test(groups = "live", singleThreaded = true, testName = "DomainDomainApiLiveTest")
+public class DomainDomainApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ @Test
+ public void testListDomains() {
+ skipIfNotDomainAdmin();
+
+ Set<Domain> domains = domainAdminClient.getDomainClient().listDomains();
+ for (Domain candidate : domains) {
+ checkDomain(candidate);
+ }
+ }
+
+ private void checkDomain(Domain domain) {
+ assertNotNull(domain.getId());
+ if (domain.getLevel() == 0 /* global ROOT */) {
+ assertNull(domain.getParentDomainName());
+ assertNull(domain.getParentDomainId());
+ } else {
+ assertNotNull(domain.getParentDomainName());
+ assertNotNull(domain.getParentDomainId());
+ }
+ }
+
+ @Test
+ public void testListDomainChildren() {
+ skipIfNotDomainAdmin();
+
+ Set<Domain> domains = domainAdminClient.getDomainClient().listDomains();
+ Domain root = findRootOfVisibleTree(domains);
+ if (domains.size() > 1) {
+ assertTrue(root.hasChild());
+ }
+
+ Set<Domain> children = domainAdminClient.getDomainClient()
+ .listDomainChildren(parentDomainId(root.getId()).isRecursive(true));
+ assertEquals(domains.size() - 1, children.size());
+ assertTrue(Sets.difference(domains, children).contains(root));
+ }
+
+ private Domain findRootOfVisibleTree(Set<Domain> domains) {
+ final Set<String> names = newHashSet(Iterables.transform(domains,
+ new Function<Domain, String>() {
+ @Override
+ public String apply(Domain domain) {
+ return domain.getName();
+ }
+ }));
+
+ for (Domain candidate : domains) {
+ if (candidate.getParentDomainId() == null ||
+ !names.contains(candidate.getParentDomainName())) {
+ return candidate;
+ }
+ }
+ throw new NoSuchElementException("No root node found in this tree");
+ }
+}