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:14:54 UTC
[07/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/NATAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATAsyncClientTest.java
deleted file mode 100644
index 2689969..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATAsyncClientTest.java
+++ /dev/null
@@ -1,202 +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.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
-import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
-import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
-import org.jclouds.http.HttpRequest;
-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.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-/**
- * Tests behavior of {@code NATAsyncClient}
- *
- * @author Adrian Cole
- */
-// NOTE:without testName, this will not call @Before* and fail w/NPE during
-// surefire
-@Test(groups = "unit", testName = "NATAsyncClientTest")
-public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncClient> {
- public void testListIPForwardingRules() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "listIPForwardingRules", ListIPForwardingRulesOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listIpForwardingRules&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 testListIPForwardingRulesOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "listIPForwardingRules", ListIPForwardingRulesOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
- ListIPForwardingRulesOptions.Builder.virtualMachineId("3")));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listIpForwardingRules&listAll=true&virtualmachineid=3 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 testGetIPForwardingRule() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "getIPForwardingRule", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listIpForwardingRules&listAll=true&id=5 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-
- HttpRequest createIpForwardingRule = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "createIpForwardingRule")
- .addQueryParam("ipaddressid", "7")
- .addQueryParam("protocol", "tcp")
- .addQueryParam("startport", "22").build();
-
- public void testCreateIPForwardingRuleForVirtualMachine() throws SecurityException, NoSuchMethodException,
- IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "createIPForwardingRule", String.class, String.class, int.class,
- CreateIPForwardingRuleOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(7, "tcp", 22));
-
- assertRequestLineEquals(httpRequest, createIpForwardingRule.getRequestLine());
- 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);
-
- }
-
- HttpRequest createIpForwardingRuleOptions = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "createIpForwardingRule")
- .addQueryParam("ipaddressid", "7")
- .addQueryParam("protocol", "tcp")
- .addQueryParam("startport", "22")
- .addQueryParam("endport", "22").build();
-
- public void testCreateIPForwardingRuleForVirtualMachineOptions() throws SecurityException, NoSuchMethodException,
- IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "createIPForwardingRule", String.class, String.class, int.class,
- CreateIPForwardingRuleOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(7, "tcp", 22,
- CreateIPForwardingRuleOptions.Builder.endPort(22)));
-
- assertRequestLineEquals(httpRequest, createIpForwardingRuleOptions.getRequestLine());
- 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 testEnableStaticNATForVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "enableStaticNATForVirtualMachine", String.class, String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5, 6));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=enableStaticNat&virtualmachineid=5&ipaddressid=6 HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testDisableStaticNATOnPublicIP() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "disableStaticNATOnPublicIP", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=disableStaticNat&ipaddressid=5 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);
-
- }
-
- public void testDeleteIPForwardingRule() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NATAsyncClient.class, "deleteIPForwardingRule", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=deleteIpForwardingRule&id=5 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);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATClientLiveTest.java
deleted file mode 100644
index ef2cb33..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NATClientLiveTest.java
+++ /dev/null
@@ -1,65 +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.collect.Iterables.getOnlyElement;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Set;
-
-import org.jclouds.cloudstack.domain.IPForwardingRule;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code NATClientLiveTest}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "NATClientLiveTest")
-public class NATClientLiveTest extends BaseCloudStackClientLiveTest {
-
- @Test(enabled = false)
- // takes too long
- public void testListIPForwardingRules() throws Exception {
- Set<IPForwardingRule> response = client.getNATClient().listIPForwardingRules();
- assert null != response;
- assertTrue(response.size() >= 0);
- for (IPForwardingRule rule : response) {
- IPForwardingRule newDetails = getOnlyElement(client.getNATClient().listIPForwardingRules(
- ListIPForwardingRulesOptions.Builder.id(rule.getId())));
- assertEquals(rule.getId(), newDetails.getId());
- checkRule(rule);
- }
- }
-
- protected void checkRule(IPForwardingRule rule) {
- assertEquals(rule.getId(), client.getNATClient().getIPForwardingRule(rule.getId()).getId());
- assert rule.getId() != null : rule;
- assert rule.getIPAddress() != null : rule;
- assert rule.getIPAddressId() != null : rule;
- assert rule.getStartPort() > 0 : rule;
- assert rule.getProtocol() != null : rule;
- assert rule.getEndPort() > 0 : rule;
- assert rule.getState() != null : rule;
- assert rule.getVirtualMachineId() != null : rule;
- assert rule.getVirtualMachineName() != null : rule;
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java
new file mode 100644
index 0000000..ce160fa
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java
@@ -0,0 +1,188 @@
+/*
+ * 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.Iterables.find;
+import static com.google.common.collect.Iterables.get;
+import static com.google.common.collect.Iterables.getOnlyElement;
+import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.vlan;
+import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.specifyVLAN;
+import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.accountInDomain;
+import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jclouds.cloudstack.domain.GuestIPType;
+import org.jclouds.cloudstack.domain.Network;
+import org.jclouds.cloudstack.domain.NetworkOffering;
+import org.jclouds.cloudstack.domain.Zone;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
+import org.jclouds.cloudstack.predicates.ZonePredicates;
+import org.testng.annotations.BeforeGroups;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code NetworkApiLiveTest}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live", singleThreaded = true, testName = "NetworkApiLiveTest")
+public class NetworkApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ private boolean networksSupported;
+ private Zone zone;
+
+ @BeforeGroups(groups = "live")
+ public void setupContext() {
+ super.setupContext();
+
+ try {
+ zone = find(client.getZoneApi().listZones(), ZonePredicates.supportsAdvancedNetworks());
+ networksSupported = true;
+ } catch (NoSuchElementException e) {
+ }
+ }
+
+ @Test
+ public void testCreateGuestVirtualNetwork() {
+ if (!networksSupported)
+ return;
+ final NetworkOffering offering;
+ try {
+ offering = find(client.getOfferingApi().listNetworkOfferings(),
+ NetworkOfferingPredicates.supportsGuestVirtualNetworks());
+
+ } catch (NoSuchElementException e) {
+ Logger.getAnonymousLogger().log(Level.SEVERE, "guest networks not supported, skipping test");
+ return;
+ }
+ String name = prefix + "-virtual";
+
+ Network network = null;
+ try {
+ network = client.getNetworkApi().createNetworkInZone(zone.getId(), offering.getId(), name, name);
+ checkNetwork(network);
+ } catch (IllegalStateException e) {
+ Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e);
+ } finally {
+ if (network != null) {
+ String jobId = client.getNetworkApi().deleteNetwork(network.getId());
+ if (jobId != null)
+ jobComplete.apply(jobId);
+ }
+ }
+ }
+
+ @Test
+ public void testCreateVLANNetwork() {
+ skipIfNotDomainAdmin();
+ if (!networksSupported)
+ return;
+
+ final NetworkOffering offering;
+ try {
+ offering = get(
+ cloudStackContext.getApi().getOfferingApi().listNetworkOfferings(specifyVLAN(true).zoneId(zone.getId())), 0);
+ } catch (NoSuchElementException e) {
+ Logger.getAnonymousLogger().log(Level.SEVERE, "VLAN networks not supported, skipping test");
+ return;
+ }
+ String name = prefix + "-vlan";
+
+ Network network = null;
+ try {
+ network = domainAdminClient
+ .getNetworkApi()
+ // startIP/endIP/netmask/gateway must be specified together
+ .createNetworkInZone(zone.getId(), offering.getId(), name, name,
+ vlan("65").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
+ checkNetwork(network);
+ } catch (IllegalStateException e) {
+ Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e);
+ } finally {
+ if (network != null) {
+ String jobId = adminClient.getNetworkApi().deleteNetwork(network.getId());
+ if (jobId != null)
+ adminJobComplete.apply(jobId);
+ }
+ }
+ }
+
+ @Test
+ public void testListNetworks() throws Exception {
+ if (!networksSupported)
+ return;
+ Set<Network> response = client.getNetworkApi().listNetworks(
+ accountInDomain(user.getAccount(), user.getDomainId()));
+ assert null != response;
+ long networkCount = response.size();
+ assertTrue(networkCount >= 0);
+ for (Network network : response) {
+ Network newDetails = getOnlyElement(client.getNetworkApi().listNetworks(id(network.getId())));
+ assertEquals(network, newDetails);
+ assertEquals(network, client.getNetworkApi().getNetwork(network.getId()));
+ checkNetwork(network);
+ }
+ }
+
+ private void checkNetwork(Network network) {
+ assert network.getId() != null : network;
+ assert network.getName() != null : network;
+ assert network.getDNS().size() != 0 : network;
+ assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network;
+ assert network.getBroadcastDomainType() != null : network;
+ assert network.getDisplayText() != null : network;
+ // Network domain can be null sometimes
+ // assert network.getNetworkDomain() != null : network;
+ assert network.getNetworkOfferingAvailability() != null : network;
+ assert network.getNetworkOfferingDisplayText() != null : network;
+ assert network.getNetworkOfferingId() != null : network;
+ assert network.getNetworkOfferingName() != null : network;
+ assert network.getRelated() != null : network;
+ assert network.getServices().size() != 0 : network;
+ assert network.getState() != null : network;
+ assert network.getTrafficType() != null : network;
+ assert network.getZoneId() != null : network;
+ assert network.getDomain() != null : network;
+ switch (network.getGuestIPType()) {
+ case VIRTUAL:
+ assert network.getNetmask() == null : network;
+ assert network.getGateway() == null : network;
+ assert network.getVLAN() == null : network;
+ assert network.getStartIP() == null : network;
+ assert network.getEndIP() == null : network;
+ break;
+ case DIRECT:
+ // TODO: I've found a network that doesn't have a netmask associated
+ assert network.getNetmask() != null : network;
+ assert network.getGateway() != null : network;
+ assert network.getVLAN() != null : network;
+ assertEquals(network.getBroadcastURI(), URI.create("vlan://" + network.getVLAN()));
+ assert network.getStartIP() != null : network;
+ assert network.getEndIP() != null : network;
+ break;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java
new file mode 100644
index 0000000..afd5f6a
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java
@@ -0,0 +1,173 @@
+/*
+ * 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.domain.NetworkType;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.CreateNetworkOptions;
+import org.jclouds.cloudstack.options.ListNetworksOptions;
+import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
+import org.jclouds.functions.IdentityFunction;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.functions.ParseFirstJsonValueNamed;
+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 NetworkApi}
+ *
+ * @author Adrian Cole
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "NetworkApiTest")
+public class NetworkApiTest extends BaseCloudStackApiTest<NetworkApi> {
+ public void testListNetworks() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(NetworkApi.class, "listNetworks", ListNetworksOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listNetworks&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 testListNetworksOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(NetworkApi.class, "listNetworks", ListNetworksOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListNetworksOptions.Builder.type(NetworkType.ADVANCED)
+ .domainId("6").id("5")));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listNetworks&listAll=true&type=Advanced&domainid=6&id=5 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 testGetNetwork() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(NetworkApi.class, "getNetwork", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("id"));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listNetworks&listAll=true&id=id 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);
+
+ }
+
+ HttpRequest createNetwork = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "createNetwork")
+ .addQueryParam("zoneid", "1")
+ .addQueryParam("networkofferingid", "2")
+ .addQueryParam("name", "named")
+ .addQueryParam("displaytext", "lovely").build();
+
+ public void testCreateNetworkInZone() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(NetworkApi.class, "createNetworkInZone", String.class, String.class, String.class,
+ String.class, CreateNetworkOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1, 2, "named", "lovely"));
+
+ assertRequestLineEquals(httpRequest, createNetwork.getRequestLine());
+ 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);
+
+ }
+
+ HttpRequest createNetworkOptions = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "createNetwork")
+ .addQueryParam("zoneid", "1")
+ .addQueryParam("networkofferingid", "2")
+ .addQueryParam("name", "named")
+ .addQueryParam("displaytext", "lovely")
+ .addQueryParam("netmask", "255.255.255.0")
+ .addQueryParam("domainid", "6").build();
+
+ public void testCreateNetworkInZoneOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(NetworkApi.class, "createNetworkInZone", String.class, String.class, String.class,
+ String.class, CreateNetworkOptions[].class);
+
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1, 2, "named", "lovely", CreateNetworkOptions.Builder
+ .netmask("255.255.255.0").domainId("6")));
+
+ assertRequestLineEquals(httpRequest, createNetworkOptions.getRequestLine());
+ 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);
+
+ }
+
+ public void testDeleteNetwork() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(NetworkApi.class, "deleteNetwork", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=deleteNetwork&id=5 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);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java
deleted file mode 100644
index 688e744..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java
+++ /dev/null
@@ -1,173 +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.domain.NetworkType;
-import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.cloudstack.options.CreateNetworkOptions;
-import org.jclouds.cloudstack.options.ListNetworksOptions;
-import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
-import org.jclouds.functions.IdentityFunction;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.functions.ParseFirstJsonValueNamed;
-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 NetworkAsyncClient}
- *
- * @author Adrian Cole
- */
-// NOTE:without testName, this will not call @Before* and fail w/NPE during
-// surefire
-@Test(groups = "unit", testName = "NetworkAsyncClientTest")
-public class NetworkAsyncClientTest extends BaseCloudStackAsyncClientTest<NetworkAsyncClient> {
- public void testListNetworks() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NetworkAsyncClient.class, "listNetworks", ListNetworksOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listNetworks&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 testListNetworksOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NetworkAsyncClient.class, "listNetworks", ListNetworksOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListNetworksOptions.Builder.type(NetworkType.ADVANCED)
- .domainId("6").id("5")));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listNetworks&listAll=true&type=Advanced&domainid=6&id=5 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 testGetNetwork() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NetworkAsyncClient.class, "getNetwork", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("id"));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listNetworks&listAll=true&id=id 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);
-
- }
-
- HttpRequest createNetwork = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "createNetwork")
- .addQueryParam("zoneid", "1")
- .addQueryParam("networkofferingid", "2")
- .addQueryParam("name", "named")
- .addQueryParam("displaytext", "lovely").build();
-
- public void testCreateNetworkInZone() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NetworkAsyncClient.class, "createNetworkInZone", String.class, String.class, String.class,
- String.class, CreateNetworkOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1, 2, "named", "lovely"));
-
- assertRequestLineEquals(httpRequest, createNetwork.getRequestLine());
- 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);
-
- }
-
- HttpRequest createNetworkOptions = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "createNetwork")
- .addQueryParam("zoneid", "1")
- .addQueryParam("networkofferingid", "2")
- .addQueryParam("name", "named")
- .addQueryParam("displaytext", "lovely")
- .addQueryParam("netmask", "255.255.255.0")
- .addQueryParam("domainid", "6").build();
-
- public void testCreateNetworkInZoneOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NetworkAsyncClient.class, "createNetworkInZone", String.class, String.class, String.class,
- String.class, CreateNetworkOptions[].class);
-
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1, 2, "named", "lovely", CreateNetworkOptions.Builder
- .netmask("255.255.255.0").domainId("6")));
-
- assertRequestLineEquals(httpRequest, createNetworkOptions.getRequestLine());
- 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);
-
- }
-
- public void testDeleteNetwork() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(NetworkAsyncClient.class, "deleteNetwork", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=deleteNetwork&id=5 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);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java
deleted file mode 100644
index 3dd1b85..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java
+++ /dev/null
@@ -1,188 +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.collect.Iterables.find;
-import static com.google.common.collect.Iterables.get;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.vlan;
-import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.specifyVLAN;
-import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.accountInDomain;
-import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URI;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.jclouds.cloudstack.domain.GuestIPType;
-import org.jclouds.cloudstack.domain.Network;
-import org.jclouds.cloudstack.domain.NetworkOffering;
-import org.jclouds.cloudstack.domain.Zone;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
-import org.jclouds.cloudstack.predicates.ZonePredicates;
-import org.testng.annotations.BeforeGroups;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code NetworkClientLiveTest}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "NetworkClientLiveTest")
-public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
-
- private boolean networksSupported;
- private Zone zone;
-
- @BeforeGroups(groups = "live")
- public void setupContext() {
- super.setupContext();
-
- try {
- zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
- networksSupported = true;
- } catch (NoSuchElementException e) {
- }
- }
-
- @Test
- public void testCreateGuestVirtualNetwork() {
- if (!networksSupported)
- return;
- final NetworkOffering offering;
- try {
- offering = find(client.getOfferingClient().listNetworkOfferings(),
- NetworkOfferingPredicates.supportsGuestVirtualNetworks());
-
- } catch (NoSuchElementException e) {
- Logger.getAnonymousLogger().log(Level.SEVERE, "guest networks not supported, skipping test");
- return;
- }
- String name = prefix + "-virtual";
-
- Network network = null;
- try {
- network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), name, name);
- checkNetwork(network);
- } catch (IllegalStateException e) {
- Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e);
- } finally {
- if (network != null) {
- String jobId = client.getNetworkClient().deleteNetwork(network.getId());
- if (jobId != null)
- jobComplete.apply(jobId);
- }
- }
- }
-
- @Test
- public void testCreateVLANNetwork() {
- skipIfNotDomainAdmin();
- if (!networksSupported)
- return;
-
- final NetworkOffering offering;
- try {
- offering = get(
- cloudStackContext.getApi().getOfferingClient().listNetworkOfferings(specifyVLAN(true).zoneId(zone.getId())), 0);
- } catch (NoSuchElementException e) {
- Logger.getAnonymousLogger().log(Level.SEVERE, "VLAN networks not supported, skipping test");
- return;
- }
- String name = prefix + "-vlan";
-
- Network network = null;
- try {
- network = domainAdminClient
- .getNetworkClient()
- // startIP/endIP/netmask/gateway must be specified together
- .createNetworkInZone(zone.getId(), offering.getId(), name, name,
- vlan("65").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
- checkNetwork(network);
- } catch (IllegalStateException e) {
- Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e);
- } finally {
- if (network != null) {
- String jobId = adminClient.getNetworkClient().deleteNetwork(network.getId());
- if (jobId != null)
- adminJobComplete.apply(jobId);
- }
- }
- }
-
- @Test
- public void testListNetworks() throws Exception {
- if (!networksSupported)
- return;
- Set<Network> response = client.getNetworkClient().listNetworks(
- accountInDomain(user.getAccount(), user.getDomainId()));
- assert null != response;
- long networkCount = response.size();
- assertTrue(networkCount >= 0);
- for (Network network : response) {
- Network newDetails = getOnlyElement(client.getNetworkClient().listNetworks(id(network.getId())));
- assertEquals(network, newDetails);
- assertEquals(network, client.getNetworkClient().getNetwork(network.getId()));
- checkNetwork(network);
- }
- }
-
- private void checkNetwork(Network network) {
- assert network.getId() != null : network;
- assert network.getName() != null : network;
- assert network.getDNS().size() != 0 : network;
- assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network;
- assert network.getBroadcastDomainType() != null : network;
- assert network.getDisplayText() != null : network;
- // Network domain can be null sometimes
- // assert network.getNetworkDomain() != null : network;
- assert network.getNetworkOfferingAvailability() != null : network;
- assert network.getNetworkOfferingDisplayText() != null : network;
- assert network.getNetworkOfferingId() != null : network;
- assert network.getNetworkOfferingName() != null : network;
- assert network.getRelated() != null : network;
- assert network.getServices().size() != 0 : network;
- assert network.getState() != null : network;
- assert network.getTrafficType() != null : network;
- assert network.getZoneId() != null : network;
- assert network.getDomain() != null : network;
- switch (network.getGuestIPType()) {
- case VIRTUAL:
- assert network.getNetmask() == null : network;
- assert network.getGateway() == null : network;
- assert network.getVLAN() == null : network;
- assert network.getStartIP() == null : network;
- assert network.getEndIP() == null : network;
- break;
- case DIRECT:
- // TODO: I've found a network that doesn't have a netmask associated
- assert network.getNetmask() != null : network;
- assert network.getGateway() != null : network;
- assert network.getVLAN() != null : network;
- assertEquals(network.getBroadcastURI(), URI.create("vlan://" + network.getVLAN()));
- assert network.getStartIP() != null : network;
- assert network.getEndIP() != null : network;
- break;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java
new file mode 100644
index 0000000..3cab8bc
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.NoSuchElementException;
+import java.util.Set;
+
+import org.jclouds.cloudstack.domain.DiskOffering;
+import org.jclouds.cloudstack.domain.NetworkOffering;
+import org.jclouds.cloudstack.domain.ServiceOffering;
+import org.jclouds.cloudstack.domain.StorageType;
+import org.jclouds.cloudstack.domain.TrafficType;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
+import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
+import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of {@code OfferingApi}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live", singleThreaded = true, testName = "OfferingApiLiveTest")
+public class OfferingApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ public void testListDiskOfferings() throws Exception {
+ Set<DiskOffering> response = client.getOfferingApi().listDiskOfferings();
+ assert null != response;
+ long offeringCount = response.size();
+ assertTrue(offeringCount >= 0);
+ for (DiskOffering offering : response) {
+ try {
+ DiskOffering newDetails = Iterables.getOnlyElement(client.getOfferingApi().listDiskOfferings(
+ ListDiskOfferingsOptions.Builder.id(offering.getId())));
+ assertEquals(offering, newDetails);
+ assertEquals(offering, client.getOfferingApi().getDiskOffering(offering.getId()));
+ assert offering.getId() != null : offering;
+ assert offering.getName() != null : offering;
+ assert offering.getCreated() != null : offering;
+ assert offering.getDisplayText() != null : offering;
+ assert offering.getDiskSize() > 0 || (offering.getDiskSize() == 0 && offering.isCustomized()) : offering;
+ assert offering.getTags() != null : offering;
+
+ } catch (NoSuchElementException e) {
+ // This bug is present both in 2.2.8 and 2.2.12
+ assertTrue(Predicates.in(ImmutableSet.of("2.2.8", "2.2.12")).apply(apiVersion));
+ }
+ }
+ }
+
+ public void testListServiceOfferings() throws Exception {
+ Set<ServiceOffering> response = client.getOfferingApi().listServiceOfferings();
+ assert null != response;
+ long offeringCount = response.size();
+ assertTrue(offeringCount >= 0);
+ for (ServiceOffering offering : response) {
+ ServiceOffering newDetails = Iterables.getOnlyElement(client.getOfferingApi().listServiceOfferings(
+ ListServiceOfferingsOptions.Builder.id(offering.getId())));
+ assertEquals(offering, newDetails);
+
+ assert offering.getId() != null : offering;
+ assert offering.getName() != null : offering;
+ assert offering.getDisplayText() != null : offering;
+ assert offering.getCpuNumber() > 0 : offering;
+ assert offering.getCpuSpeed() > 0 : offering;
+ assert offering.getMemory() > 0 : offering;
+ assert offering.getStorageType() != null && StorageType.UNRECOGNIZED != offering.getStorageType() : offering;
+ assert offering.getTags() != null : offering;
+ }
+ }
+
+ public void testListNetworkOfferings() throws Exception {
+ Set<NetworkOffering> response = client.getOfferingApi().listNetworkOfferings();
+ assert null != response;
+ long offeringCount = response.size();
+ assertTrue(offeringCount >= 0);
+ for (NetworkOffering offering : response) {
+ NetworkOffering newDetails = Iterables.getOnlyElement(client.getOfferingApi().listNetworkOfferings(
+ ListNetworkOfferingsOptions.Builder.id(offering.getId())));
+ assertEquals(offering, newDetails);
+ assertEquals(offering, client.getOfferingApi().getNetworkOffering(offering.getId()));
+ assert offering.getId() != null : offering;
+ assert offering.getName() != null : offering;
+ assert offering.getDisplayText() != null : offering;
+ assert offering.getMaxConnections() == null || offering.getMaxConnections() > 0 : offering;
+ assert offering.getTrafficType() != null && TrafficType.UNRECOGNIZED != offering.getTrafficType() : offering;
+ assert offering.getTags() != null : offering;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java
new file mode 100644
index 0000000..c03dbc7
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java
@@ -0,0 +1,206 @@
+/*
+ * 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.domain.NetworkOfferingAvailabilityType.DEFAULT;
+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.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
+import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
+import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
+import org.jclouds.functions.IdentityFunction;
+import org.jclouds.http.functions.ParseFirstJsonValueNamed;
+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 OfferingApi}
+ *
+ * @author Adrian Cole
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "OfferingApiTest")
+public class OfferingApiTest extends BaseCloudStackApiTest<OfferingApi> {
+ public void testListDiskOfferings() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "listDiskOfferings", ListDiskOfferingsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&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 testListDiskOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "listDiskOfferings", ListDiskOfferingsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListDiskOfferingsOptions.Builder.domainId("6").id("5")));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&listAll=true&domainid=6&id=5 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 testGetDiskOffering() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "getDiskOffering", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("5"));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&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 testListNetworkOfferings() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "listNetworkOfferings", ListNetworkOfferingsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&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 testListNetworkOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "listNetworkOfferings", ListNetworkOfferingsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
+ ListNetworkOfferingsOptions.Builder.availability(DEFAULT).isShared(true).id("6")));
+
+ assertRequestLineEquals(
+ httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&listAll=true&availability=Default&isshared=true&id=6 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 testGetNetworkOffering() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "getNetworkOffering", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("5"));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&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 testListServiceOfferings() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "listServiceOfferings", ListServiceOfferingsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&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 testListServiceOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "listServiceOfferings", ListServiceOfferingsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListServiceOfferingsOptions.Builder.virtualMachineId("4")
+ .domainId("5").id("6")));
+
+ assertRequestLineEquals(
+ httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&listAll=true&virtualmachineid=4&domainid=5&id=6 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 testGetServiceOffering() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(OfferingApi.class, "getServiceOffering", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("5"));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&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);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java
deleted file mode 100644
index 82cd713..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java
+++ /dev/null
@@ -1,206 +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.domain.NetworkOfferingAvailabilityType.DEFAULT;
-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.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
-import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
-import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
-import org.jclouds.functions.IdentityFunction;
-import org.jclouds.http.functions.ParseFirstJsonValueNamed;
-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 OfferingAsyncClient}
- *
- * @author Adrian Cole
- */
-// NOTE:without testName, this will not call @Before* and fail w/NPE during
-// surefire
-@Test(groups = "unit", testName = "OfferingAsyncClientTest")
-public class OfferingAsyncClientTest extends BaseCloudStackAsyncClientTest<OfferingAsyncClient> {
- public void testListDiskOfferings() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "listDiskOfferings", ListDiskOfferingsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&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 testListDiskOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "listDiskOfferings", ListDiskOfferingsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListDiskOfferingsOptions.Builder.domainId("6").id("5")));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&listAll=true&domainid=6&id=5 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 testGetDiskOffering() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "getDiskOffering", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("5"));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&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 testListNetworkOfferings() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "listNetworkOfferings", ListNetworkOfferingsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&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 testListNetworkOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "listNetworkOfferings", ListNetworkOfferingsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
- ListNetworkOfferingsOptions.Builder.availability(DEFAULT).isShared(true).id("6")));
-
- assertRequestLineEquals(
- httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&listAll=true&availability=Default&isshared=true&id=6 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 testGetNetworkOffering() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "getNetworkOffering", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("5"));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&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 testListServiceOfferings() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "listServiceOfferings", ListServiceOfferingsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&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 testListServiceOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "listServiceOfferings", ListServiceOfferingsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListServiceOfferingsOptions.Builder.virtualMachineId("4")
- .domainId("5").id("6")));
-
- assertRequestLineEquals(
- httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&listAll=true&virtualmachineid=4&domainid=5&id=6 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 testGetServiceOffering() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(OfferingAsyncClient.class, "getServiceOffering", String.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("5"));
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&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);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java
deleted file mode 100644
index fdb65b7..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java
+++ /dev/null
@@ -1,112 +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.NoSuchElementException;
-import java.util.Set;
-
-import org.jclouds.cloudstack.domain.DiskOffering;
-import org.jclouds.cloudstack.domain.NetworkOffering;
-import org.jclouds.cloudstack.domain.ServiceOffering;
-import org.jclouds.cloudstack.domain.StorageType;
-import org.jclouds.cloudstack.domain.TrafficType;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
-import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
-import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
-/**
- * Tests behavior of {@code OfferingClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "OfferingClientLiveTest")
-public class OfferingClientLiveTest extends BaseCloudStackClientLiveTest {
-
- public void testListDiskOfferings() throws Exception {
- Set<DiskOffering> response = client.getOfferingClient().listDiskOfferings();
- assert null != response;
- long offeringCount = response.size();
- assertTrue(offeringCount >= 0);
- for (DiskOffering offering : response) {
- try {
- DiskOffering newDetails = Iterables.getOnlyElement(client.getOfferingClient().listDiskOfferings(
- ListDiskOfferingsOptions.Builder.id(offering.getId())));
- assertEquals(offering, newDetails);
- assertEquals(offering, client.getOfferingClient().getDiskOffering(offering.getId()));
- assert offering.getId() != null : offering;
- assert offering.getName() != null : offering;
- assert offering.getCreated() != null : offering;
- assert offering.getDisplayText() != null : offering;
- assert offering.getDiskSize() > 0 || (offering.getDiskSize() == 0 && offering.isCustomized()) : offering;
- assert offering.getTags() != null : offering;
-
- } catch (NoSuchElementException e) {
- // This bug is present both in 2.2.8 and 2.2.12
- assertTrue(Predicates.in(ImmutableSet.of("2.2.8", "2.2.12")).apply(apiVersion));
- }
- }
- }
-
- public void testListServiceOfferings() throws Exception {
- Set<ServiceOffering> response = client.getOfferingClient().listServiceOfferings();
- assert null != response;
- long offeringCount = response.size();
- assertTrue(offeringCount >= 0);
- for (ServiceOffering offering : response) {
- ServiceOffering newDetails = Iterables.getOnlyElement(client.getOfferingClient().listServiceOfferings(
- ListServiceOfferingsOptions.Builder.id(offering.getId())));
- assertEquals(offering, newDetails);
-
- assert offering.getId() != null : offering;
- assert offering.getName() != null : offering;
- assert offering.getDisplayText() != null : offering;
- assert offering.getCpuNumber() > 0 : offering;
- assert offering.getCpuSpeed() > 0 : offering;
- assert offering.getMemory() > 0 : offering;
- assert offering.getStorageType() != null && StorageType.UNRECOGNIZED != offering.getStorageType() : offering;
- assert offering.getTags() != null : offering;
- }
- }
-
- public void testListNetworkOfferings() throws Exception {
- Set<NetworkOffering> response = client.getOfferingClient().listNetworkOfferings();
- assert null != response;
- long offeringCount = response.size();
- assertTrue(offeringCount >= 0);
- for (NetworkOffering offering : response) {
- NetworkOffering newDetails = Iterables.getOnlyElement(client.getOfferingClient().listNetworkOfferings(
- ListNetworkOfferingsOptions.Builder.id(offering.getId())));
- assertEquals(offering, newDetails);
- assertEquals(offering, client.getOfferingClient().getNetworkOffering(offering.getId()));
- assert offering.getId() != null : offering;
- assert offering.getName() != null : offering;
- assert offering.getDisplayText() != null : offering;
- assert offering.getMaxConnections() == null || offering.getMaxConnections() > 0 : offering;
- assert offering.getTrafficType() != null && TrafficType.UNRECOGNIZED != offering.getTrafficType() : offering;
- assert offering.getTags() != null : offering;
- }
- }
-}