You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/11/27 07:46:01 UTC
[52/79] stratos git commit: adding cloudstack dependancy
http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LimitApiTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LimitApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LimitApiTest.java
new file mode 100644
index 0000000..ea432f0
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LimitApiTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.ListResourceLimitsOptions;
+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 LimitApi}
+ */
+@Test(groups = "unit", testName = "LimitApiTest")
+public class LimitApiTest extends BaseCloudStackApiTest<LimitApi> {
+
+ public void testListResourceLimits() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(LimitApi.class, "listResourceLimits", ListResourceLimitsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listResourceLimits&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 testListResourceLimitsOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(LimitApi.class, "listResourceLimits", ListResourceLimitsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListResourceLimitsOptions.Builder.account("jclouds" , "23")));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listResourceLimits&listAll=true&account=jclouds&domainid=23 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);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiLiveTest.java
new file mode 100644
index 0000000..82d3a62
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiLiveTest.java
@@ -0,0 +1,226 @@
+/*
+ * 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 java.util.concurrent.TimeUnit.SECONDS;
+import static org.jclouds.cloudstack.predicates.NetworkPredicates.hasLoadBalancerService;
+import static org.jclouds.cloudstack.predicates.NetworkPredicates.isVirtualNetwork;
+import static org.jclouds.util.Predicates2.retry;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import org.jclouds.cloudstack.domain.AsyncJob;
+import org.jclouds.cloudstack.domain.JobResult;
+import org.jclouds.cloudstack.domain.LoadBalancerRule;
+import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm;
+import org.jclouds.cloudstack.domain.LoadBalancerRule.State;
+import org.jclouds.cloudstack.domain.Network;
+import org.jclouds.cloudstack.domain.PublicIPAddress;
+import org.jclouds.cloudstack.domain.VirtualMachine;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.jclouds.cloudstack.predicates.LoadBalancerRuleActive;
+import org.jclouds.ssh.SshException;
+import org.testng.annotations.AfterGroups;
+import org.testng.annotations.BeforeGroups;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.net.HostAndPort;
+
+/**
+ * Tests behavior of {@code LoadBalancerApiLiveTest}
+ */
+@Test(groups = "live", singleThreaded = true, testName = "LoadBalancerApiLiveTest")
+public class LoadBalancerApiLiveTest extends BaseCloudStackApiLiveTest {
+ private PublicIPAddress ip = null;
+ private VirtualMachine vm;
+ private LoadBalancerRule rule;
+ private Predicate<LoadBalancerRule> loadBalancerRuleActive;
+ private Network network;
+ private boolean networksDisabled;
+
+ @BeforeGroups(groups = "live")
+ public void setupContext() {
+ super.setupContext();
+ loadBalancerRuleActive = retry(new LoadBalancerRuleActive(client), 60, 1, 1, SECONDS);
+ prefix += "rule";
+ try {
+ network = find(client.getNetworkApi().listNetworks(),
+ Predicates.and(hasLoadBalancerService(), isVirtualNetwork(),
+ new Predicate<Network>() {
+ @Override
+ public boolean apply(Network network) {
+ return network.isDefault()
+ && !network.isSecurityGroupEnabled()
+ && !network.isSystem()
+ && network.getAccount().equals(user.getName());
+ }
+ }));
+ } catch (NoSuchElementException e) {
+ networksDisabled = true;
+ }
+ }
+
+ public void testCreateVm() {
+ if (networksDisabled)
+ return;
+ String defaultTemplate = template != null ? template.getImageId() : null;
+ vm = VirtualMachineApiLiveTest.createVirtualMachineInNetwork(network,
+ defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()),
+ client, jobComplete, virtualMachineRunning);
+ if (vm.getPassword() != null && !loginCredentials.getOptionalPassword().isPresent())
+ loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build();
+ }
+
+ @Test(dependsOnMethods = "testCreateVm")
+ public void testCreateLoadBalancerRule() throws Exception {
+ if (networksDisabled)
+ return;
+ int attempts = 0;
+ while (rule == null && attempts < 10) {
+ ip = reuseOrAssociate.apply(network);
+ try {
+ String jobId = client.getLoadBalancerApi().createLoadBalancerRuleForPublicIP(ip.getId(),
+ Algorithm.LEASTCONN, prefix, 22, 22);
+ assertTrue(jobComplete.apply(jobId));
+ AsyncJob<LoadBalancerRule> asyncJob = client.getAsyncJobApi().getAsyncJob(jobId);
+ LoadBalancerRule result = asyncJob.getResult();
+ rule = result;
+ } catch (IllegalStateException e) {
+ // very likely an ip conflict, so retry;
+ attempts++;
+ }
+ }
+ assertNotNull(rule, "Failed to get a load balancer rule after " + attempts + " attempts");
+ assert rule.getPublicIPId() == ip.getId() : rule;
+ assertEquals(rule.getPublicPort(), 22);
+ assertEquals(rule.getPrivatePort(), 22);
+ assertEquals(rule.getAlgorithm(), Algorithm.LEASTCONN);
+ assertEquals(rule.getName(), prefix);
+ assertEquals(rule.getState(), State.ADD);
+ assertEquals(client.getLoadBalancerApi().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId()).size(), 0);
+ checkRule(rule);
+
+ }
+
+ @Test(dependsOnMethods = "testCreateLoadBalancerRule")
+ public void testAssignToLoadBalancerRule() throws Exception {
+ if (networksDisabled)
+ return;
+ String jobId = client.getLoadBalancerApi().assignVirtualMachinesToLoadBalancerRule(rule.getId(), vm.getId());
+ assertTrue(jobComplete.apply(jobId));
+ AsyncJob<JobResult> result = client.getAsyncJobApi().getAsyncJob(jobId);
+ assertTrue(result.hasSucceed());
+ Set<VirtualMachine> machines = client.getLoadBalancerApi().listVirtualMachinesAssignedToLoadBalancerRule(
+ rule.getId());
+ assertEquals(machines.size(), 1);
+ assertTrue(loadBalancerRuleActive.apply(rule), rule.toString());
+ }
+
+ @Test(dependsOnMethods = "testAssignToLoadBalancerRule")
+ public void testCanSshInThroughNewLoadBalancerRule() throws Exception {
+ loopAndCheckSSH();
+ }
+
+ // note that when in LB mode, there's a chance you'll have a connection
+ // failure
+ private void loopAndCheckSSH() throws IOException {
+ for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate.
+ try {
+ checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22));
+ return;
+ } catch (SshException e) {
+ e.printStackTrace();
+ try {
+ Thread.sleep(10 * 1000);
+ } catch (InterruptedException e1) {
+ }
+ continue;
+ }
+ }
+ }
+
+ @Test(dependsOnMethods = "testAssignToLoadBalancerRule", expectedExceptions = SshException.class)
+ public void testRemoveFromLoadBalancerRule() throws Exception {
+ if (networksDisabled)
+ throw new SshException();
+ assertTrue(jobComplete.apply(client.getLoadBalancerApi().removeVirtualMachinesFromLoadBalancerRule(
+ rule.getId(), vm.getId())));
+ assertEquals(client.getLoadBalancerApi().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId()).size(), 0);
+ assertEquals(rule.getState(), State.ADD);
+ checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22));
+ }
+
+ @AfterGroups(groups = "live")
+ @Override
+ protected void tearDownContext() {
+ if (rule != null) {
+ assertTrue(jobComplete.apply(client.getLoadBalancerApi().deleteLoadBalancerRule(rule.getId())));
+ }
+ if (vm != null) {
+ assertTrue(jobComplete.apply(client.getVirtualMachineApi().destroyVirtualMachine(vm.getId())));
+ }
+ if (ip != null) {
+ client.getAddressApi().disassociateIPAddress(ip.getId());
+ }
+ super.tearDownContext();
+ }
+
+ public void testListLoadBalancerRules() throws Exception {
+ Set<LoadBalancerRule> response = client.getLoadBalancerApi().listLoadBalancerRules();
+ assert null != response;
+ assertTrue(response.size() >= 0);
+ for (LoadBalancerRule rule : response) {
+ LoadBalancerRule newDetails = findRuleWithId(rule.getId());
+ assertEquals(rule.getId(), newDetails.getId());
+ checkRule(rule);
+ }
+ }
+
+ private LoadBalancerRule findRuleWithId(final String id) {
+ return find(client.getLoadBalancerApi().listLoadBalancerRules(), new Predicate<LoadBalancerRule>() {
+
+ @Override
+ public boolean apply(LoadBalancerRule arg0) {
+ return arg0.getId() == id;
+ }
+
+ });
+ }
+
+ protected void checkRule(LoadBalancerRule rule) {
+ assertEquals(rule.getId(), findRuleWithId(rule.getId()).getId());
+ assert rule.getId() != null : rule;
+ assert rule.getAccount() != null : rule;
+ assert rule.getAlgorithm() != null : rule;
+ assert rule.getPrivatePort() > 0 : rule;
+ assert rule.getPublicPort() > 0 : rule;
+ assert rule.getDomain() != null : rule;
+ assert rule.getDomainId() != null : rule;
+ assert rule.getState() != null : rule;
+ assert rule.getName() != null : rule;
+ assert rule.getPublicIP() != null : rule;
+ assert rule.getPublicIPId() != null : rule;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiTest.java
new file mode 100644
index 0000000..5656072
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LoadBalancerApiTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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.LoadBalancerRule.Algorithm;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.CreateLoadBalancerRuleOptions;
+import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions;
+import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions;
+import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
+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.collect.ImmutableList;
+import com.google.common.reflect.Invokable;
+/**
+ * Tests behavior of {@code LoadBalancerApi}
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "LoadBalancerApiTest")
+public class LoadBalancerApiTest extends BaseCloudStackApiTest<LoadBalancerApi> {
+ public void testListLoadBalancerRules() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(LoadBalancerApi.class, "listLoadBalancerRules",
+ ListLoadBalancerRulesOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listLoadBalancerRules&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 testListLoadBalancerRulesOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(LoadBalancerApi.class, "listLoadBalancerRules",
+ ListLoadBalancerRulesOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListLoadBalancerRulesOptions.Builder.publicIPId("3")));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listLoadBalancerRules&listAll=true&publicipid=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);
+
+ }
+
+ HttpRequest createLoadBalancerRule = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "createLoadBalancerRule")
+ .addQueryParam("publicipid", "6")
+ .addQueryParam("algorithm", "leastconn")
+ .addQueryParam("name", "tcp")
+ .addQueryParam("privateport", "22")
+ .addQueryParam("publicport", "22").build();
+
+ public void testCreateLoadBalancerRuleForPublicIP() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(LoadBalancerApi.class, "createLoadBalancerRuleForPublicIP", String.class,
+ Algorithm.class, String.class, int.class, int.class, CreateLoadBalancerRuleOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(6, Algorithm.LEASTCONN, "tcp", 22, 22));
+
+ assertRequestLineEquals(httpRequest, createLoadBalancerRule.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 testUpdateLoadBalancerRule() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(LoadBalancerApi.class, "updateLoadBalancerRule", String.class, UpdateLoadBalancerRuleOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=updateLoadBalancerRule&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);
+
+ }
+
+ public void testDeleteLoadBalancerRule() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(LoadBalancerApi.class, "deleteLoadBalancerRule", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=deleteLoadBalancerRule&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);
+
+ }
+
+ public void testListVirtualMachinesAssignedToLoadBalancerRule() throws SecurityException, NoSuchMethodException,
+ IOException {
+ Invokable<?, ?> method = method(LoadBalancerApi.class, "listVirtualMachinesAssignedToLoadBalancerRule",
+ String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listLoadBalancerRuleInstances&listAll=true&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);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiLiveTest.java
new file mode 100644
index 0000000..2ecd4b6
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiLiveTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.BaseCloudStackApiLiveTest;
+import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code NATApiLiveTest}
+ */
+@Test(groups = "live", singleThreaded = true, testName = "NATApiLiveTest")
+public class NATApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ @Test(enabled = false)
+ // takes too long
+ public void testListIPForwardingRules() throws Exception {
+ Set<IPForwardingRule> response = client.getNATApi().listIPForwardingRules();
+ assert null != response;
+ assertTrue(response.size() >= 0);
+ for (IPForwardingRule rule : response) {
+ IPForwardingRule newDetails = getOnlyElement(client.getNATApi().listIPForwardingRules(
+ ListIPForwardingRulesOptions.Builder.id(rule.getId())));
+ assertEquals(rule.getId(), newDetails.getId());
+ checkRule(rule);
+ }
+ }
+
+ protected void checkRule(IPForwardingRule rule) {
+ assertEquals(rule.getId(), client.getNATApi().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/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiTest.java
new file mode 100644
index 0000000..2308e01
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NATApiTest.java
@@ -0,0 +1,200 @@
+/*
+ * 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.BaseCloudStackApiTest;
+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 NATApi}
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "NATApiTest")
+public class NATApiTest extends BaseCloudStackApiTest<NATApi> {
+ public void testListIPForwardingRules() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(NATApi.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(NATApi.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(NATApi.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(NATApi.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(NATApi.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(NATApi.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(NATApi.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(NATApi.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/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java
new file mode 100644
index 0000000..23978c9
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiLiveTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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}
+ */
+@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/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java
new file mode 100644
index 0000000..b53fc5f
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/NetworkApiTest.java
@@ -0,0 +1,171 @@
+/*
+ * 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}
+ */
+// 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/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java
new file mode 100644
index 0000000..2bbdf20
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiLiveTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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}
+ */
+@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/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java
new file mode 100644
index 0000000..6315fea
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/OfferingApiTest.java
@@ -0,0 +1,204 @@
+/*
+ * 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}
+ */
+// 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/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiExpectTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiExpectTest.java
new file mode 100644
index 0000000..b7665be
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiExpectTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.CloudStackContext;
+import org.jclouds.cloudstack.domain.Project;
+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 ProjectApi
+ */
+@Test(groups = "unit", testName = "ProjectApiExpectTest")
+public class ProjectApiExpectTest extends BaseCloudStackExpectTest<ProjectApi> {
+
+
+ public void testListProjectsWhenResponseIs2xx() {
+
+ ProjectApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=listProjects&listAll=true&apiKey=identity&signature=vtCqaYXfXttr6mD18Es0e22QBIQ%3D")
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/listprojectsresponse.json"))
+ .build());
+
+ Set<Project> projects = ImmutableSet.of(
+ Project.builder()
+ .id("489da162-0b77-489d-b044-ce39aa018b1f")
+ .account("thyde")
+ .displayText("")
+ .domain("ROOT")
+ .domainId("41a4917b-7952-499d-ba7f-4c57464d3dc8")
+ .name("NN-HA-T1")
+ .state(Project.State.ACTIVE).build(),
+ Project.builder()
+ .id("1c11f22c-15ac-4fa7-b833-4d748df317b7")
+ .account("prasadm")
+ .displayText("Hive")
+ .domain("ROOT")
+ .domainId("41a4917b-7952-499d-ba7f-4c57464d3dc8")
+ .name("hive")
+ .state(Project.State.ACTIVE).build());
+
+ assertEquals(client.listProjects(), projects);
+ }
+
+ @Override
+ protected ProjectApi clientFrom(CloudStackContext context) {
+ return context.getApi().getProjectApi();
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiLiveTest.java
new file mode 100644
index 0000000..071c9d9
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiLiveTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+
+import org.jclouds.cloudstack.domain.Project;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code ProjectApi}
+ */
+@Test(groups = "live", singleThreaded = true, testName = "ProjectApiLiveTest")
+public class ProjectApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ @Test
+ public void testListAccounts() throws Exception {
+ for (Project project : client.getProjectApi().listProjects())
+ checkProject(project);
+ }
+
+ protected void checkProject(Project project) {
+ assertNotNull(project.getId());
+ assertEquals(project.toString(), client.getProjectApi().getProject(project.getId()).toString());
+ assertNotNull(project.getState());
+ assertNotEquals(project.getState(), Project.State.UNRECOGNIZED);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiTest.java
new file mode 100644
index 0000000..6b06c93
--- /dev/null
+++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ProjectApiTest.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.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.ListProjectsOptions;
+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 ProjectApi}
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during
+// surefire
+@Test(groups = "unit", testName = "ProjectApiTest")
+public class ProjectApiTest extends BaseCloudStackApiTest<ProjectApi> {
+
+ public void testListProjects() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(ProjectApi.class, "listProjects", ListProjectsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listProjects&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 testListProjectsOptions() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(ProjectApi.class, "listProjects", ListProjectsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(
+ ListProjectsOptions.Builder.accountInDomain("jclouds", "123")));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listProjects&listAll=true&account=jclouds&domainid=123 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 testGetAccount() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(ProjectApi.class, "getProject", String.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("3"));
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listProjects&listAll=true&id=3 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);
+
+ }
+
+}