From 96b7231b252b07d4263af736e32ce35d58a7017b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 5 Nov 2012 11:26:38 -0300 Subject: [PATCH] refactored cloudstack expect tests and added CloudStackComputeServiceAdapterExpectTest --- .../PasswordAuthenticationExpectTest.java | 24 +-- ...dStackComputeServiceAdapterExpectTest.java | 116 ++++++++++++ ...oudStackComputeServiceAdapterLiveTest.java | 2 +- .../features/AccountClientExpectTest.java | 6 +- .../DomainDomainClientExpectTest.java | 6 +- .../features/FirewallClientExpectTest.java | 6 +- .../GlobalConfigurationClientExpectTest.java | 6 +- .../GlobalDomainClientExpectTest.java | 6 +- .../features/GlobalHostClientExpectTest.java | 6 +- .../features/GlobalPodClientExpectTest.java | 6 +- .../features/GlobalVlanClientExpectTest.java | 6 +- .../features/GlobalZoneClientExpectTest.java | 6 +- .../features/SSHKeyPairClientExpectTest.java | 6 +- .../features/SessionClientExpectTest.java | 4 +- .../VirtualMachineClientExpectTest.java | 6 +- .../features/ZoneClientExpectTest.java | 6 +- ...dStackComputeServiceContextExpectTest.java | 168 ++++++++++++++++++ ...est.java => BaseCloudStackExpectTest.java} | 49 +++-- .../deployvirtualmachineresponse.json | 1 + .../src/test/resources/getzoneresponse.json | 1 + ...asyncjobresultresponse-virtualmachine.json | 53 ++++++ 21 files changed, 406 insertions(+), 84 deletions(-) create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterExpectTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/BaseCloudStackComputeServiceContextExpectTest.java rename apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/{BaseCloudStackRestClientExpectTest.java => BaseCloudStackExpectTest.java} (65%) create mode 100644 apis/cloudstack/src/test/resources/deployvirtualmachineresponse.json create mode 100644 apis/cloudstack/src/test/resources/getzoneresponse.json create mode 100644 apis/cloudstack/src/test/resources/queryasyncjobresultresponse-virtualmachine.json diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/PasswordAuthenticationExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/PasswordAuthenticationExpectTest.java index bf87bb0c94..95a1e70684 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/PasswordAuthenticationExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/PasswordAuthenticationExpectTest.java @@ -20,18 +20,16 @@ package org.jclouds.cloudstack; import static org.testng.Assert.assertNotNull; -import java.net.URI; -import java.net.URLEncoder; import java.util.Properties; import org.jclouds.cloudstack.config.CloudStackProperties; import org.jclouds.cloudstack.features.AccountClient; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; +import org.jclouds.util.Strings2; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableMultimap; import com.google.common.net.HttpHeaders; /** @@ -40,7 +38,7 @@ import com.google.common.net.HttpHeaders; * @author Adrian Cole */ @Test(groups = "unit", testName = "PasswordAuthenticationExpectTest") -public class PasswordAuthenticationExpectTest extends BaseCloudStackRestClientExpectTest { +public class PasswordAuthenticationExpectTest extends BaseCloudStackExpectTest { /** * this reflects the properties that a user would pass to createContext @@ -52,27 +50,21 @@ public class PasswordAuthenticationExpectTest extends BaseCloudStackRestClientEx return contextProperties; } - - @SuppressWarnings("deprecation") public void testLoginWithPasswordSetsSessionKeyAndCookie() { CloudStackContext context = requestsSendResponses( - loginRequest, loginResponse, + login, loginResponse, HttpRequest.builder() .method("GET") - .endpoint( - URI.create("http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&sessionkey=" + URLEncoder.encode(sessionKey))) - .headers( - ImmutableMultimap.builder() - .put("Accept", "application/json") - .put(HttpHeaders.COOKIE, "JSESSIONID=" + jSessionId) - .build()) + .endpoint("http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&sessionkey=" + Strings2.urlEncode(sessionKey)) + .addHeader("Accept", "application/json") + .addHeader(HttpHeaders.COOKIE, "JSESSIONID=" + jSessionId) .build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/listaccountsresponse.json")) .build() - , logoutRequest, logoutResponse); + ,logout, logoutResponse); AccountClient client = context.getProviderSpecificContext().getApi().getAccountClient(); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterExpectTest.java new file mode 100644 index 0000000000..ca6d9a4f62 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterExpectTest.java @@ -0,0 +1,116 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.compute; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.Map; + +import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions; +import org.jclouds.cloudstack.compute.strategy.CloudStackComputeServiceAdapter; +import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.cloudstack.internal.BaseCloudStackComputeServiceContextExpectTest; +import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Injector; + +/** + * Tests the compute service abstraction of the cloudstack api. + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class CloudStackComputeServiceAdapterExpectTest extends BaseCloudStackComputeServiceContextExpectTest { + + public void testCreateNodeWithGroupEncodedIntoNameWithKeyPair() { + HttpRequest deployVM = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "deployVirtualMachine") + .addQueryParam("zoneid", "1") + .addQueryParam("templateid", "4") + .addQueryParam("serviceofferingid", "1") + .addQueryParam("displayname", "test-e92") + .addQueryParam("name", "test-e92") + .addQueryParam("networkids", "204") + .addQueryParam("keypair", "mykeypair") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "hI%2FU4cWXdU6KTZKbJvzPCmOpGmU%3D") + .addHeader("Accept", "application/json") + .build(); + + HttpResponse deployVMResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/deployvirtualmachineresponse.json")) + .build(); + + HttpRequest queryAsyncJobResult = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "queryAsyncJobResult") + .addQueryParam("jobid", "50006") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "v8BWKMxd%2BIzHIuTaZ9sNSzCWqFI%3D") + .addHeader("Accept", "application/json") + .build(); + + HttpResponse queryAsyncJobResultResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/queryasyncjobresultresponse-virtualmachine.json")) + .build(); + + Map requestResponseMap = ImmutableMap. builder() + .put(listTemplates, listTemplatesResponse) + .put(listOsTypes, listOsTypesResponse) + .put(listOsCategories, listOsCategoriesResponse) + .put(listZones, listZonesResponse) + .put(listServiceOfferings, listServiceOfferingsResponse) + .put(listAccounts, listAccountsResponse) + .put(listNetworks, listNetworksResponse) + .put(getZone, getZoneResponse) + .put(deployVM, deployVMResponse) + .put(queryAsyncJobResult, queryAsyncJobResultResponse) + .build(); + + Injector forKeyPair = requestsSendResponses(requestResponseMap); + + Template template = forKeyPair.getInstance(TemplateBuilder.class).osFamily(OsFamily.CENTOS).build(); + template.getOptions().as(CloudStackTemplateOptions.class).keyPair("mykeypair").setupStaticNat(false); + + CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class); + + NodeAndInitialCredentials server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", + template); + assertNotNull(server); + assertEquals(server.getCredentials(), LoginCredentials.builder().password("dD7jwajkh").build()); + } + + @Override + protected Injector clientFrom(CloudStackContext context) { + return context.utils().injector(); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java index 932efb8b96..38f3f48bb9 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java @@ -166,7 +166,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien new DefaultCredentialsFromImageOrOverridingCredentials()); @Test - public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException { + public void testCreateNodeWithGroupEncodedIntoName() { String group = prefix + "-foo"; String name = group + "-node-" + new Random().nextInt(); Template template = view.getComputeService().templateBuilder().build(); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java index 9031a3bc29..7481e81949 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientExpectTest.java @@ -25,7 +25,7 @@ import java.util.Set; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.User; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableSet; * @author Andrei Savu */ @Test(groups = "unit", testName = "AccountClientExpectTest") -public class AccountClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class AccountClientExpectTest extends BaseCloudStackExpectTest { public void testListAccountsWhenResponseIs2xx() { @@ -106,4 +106,4 @@ public class AccountClientExpectTest extends BaseCloudStackRestClientExpectTest< protected AccountClient clientFrom(CloudStackContext context) { return context.getProviderSpecificContext().getApi().getAccountClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientExpectTest.java index 8e342f448e..bba64cfd2d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientExpectTest.java @@ -26,7 +26,7 @@ import java.net.URI; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.Domain; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableSet; * @author Andrei Savu */ @Test(groups = "unit", testName = "DomainDomainClientExpectTest") -public class DomainDomainClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class DomainDomainClientExpectTest extends BaseCloudStackExpectTest { public void testListDomainsWhenResponseIs2xx() { DomainDomainClient client = requestSendsResponse( @@ -157,4 +157,4 @@ public class DomainDomainClientExpectTest extends BaseCloudStackRestClientExpect protected DomainDomainClient clientFrom(CloudStackContext context) { return context.getDomainContext().getApi().getDomainClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientExpectTest.java index 460d033e59..2653b7b5a4 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientExpectTest.java @@ -28,7 +28,7 @@ import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.FirewallRule; import org.jclouds.cloudstack.domain.PortForwardingRule; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableSet; * @author Andrei Savu */ @Test(groups = "unit", testName = "FirewallClientExpectTest") -public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class FirewallClientExpectTest extends BaseCloudStackExpectTest { public void testListFirewallRulesWhenResponseIs2xx() { FirewallClient client = requestSendsResponse( @@ -282,4 +282,4 @@ public class FirewallClientExpectTest extends BaseCloudStackRestClientExpectTest protected FirewallClient clientFrom(CloudStackContext context) { return context.getProviderSpecificContext().getApi().getFirewallClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java index afe3cf83aa..8b1f48d0fe 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java @@ -25,7 +25,7 @@ import java.net.URI; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.ConfigurationEntry; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -38,7 +38,7 @@ import com.google.common.collect.ImmutableSet; * @author Andrei Savu */ @Test(groups = "unit", testName = "GlobalConfigurationClientExpectTest") -public class GlobalConfigurationClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class GlobalConfigurationClientExpectTest extends BaseCloudStackExpectTest { @Test public void testListConfigurationEntriesWhenResponseIs2xx() { @@ -126,4 +126,4 @@ public class GlobalConfigurationClientExpectTest extends BaseCloudStackRestClien protected GlobalConfigurationClient clientFrom(CloudStackContext context) { return context.getGlobalContext().getApi().getConfigurationClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java index 0a4defe533..aa2422159d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java @@ -26,7 +26,7 @@ import java.net.URI; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.Domain; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -37,7 +37,7 @@ import org.testng.annotations.Test; * @author Andrei Savu */ @Test(groups = "unit", testName = "GlobalDomainClientExpectTest") -public class GlobalDomainClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class GlobalDomainClientExpectTest extends BaseCloudStackExpectTest { public void testCreateDomainWhenResponseIs2xx() { GlobalDomainClient client = requestSendsResponse( @@ -145,4 +145,4 @@ public class GlobalDomainClientExpectTest extends BaseCloudStackRestClientExpect protected GlobalDomainClient clientFrom(CloudStackContext context) { return context.getGlobalContext().getApi().getDomainClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java index 1f17abdf83..0f998ec79f 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java @@ -30,7 +30,7 @@ import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.AllocationState; import org.jclouds.cloudstack.domain.Cluster; import org.jclouds.cloudstack.domain.Host; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.cloudstack.options.AddClusterOptions; import org.jclouds.cloudstack.options.AddHostOptions; import org.jclouds.cloudstack.options.AddSecondaryStorageOptions; @@ -49,7 +49,7 @@ import com.google.common.collect.ImmutableSet; * @author Richard Downer */ @Test(groups = "unit", testName = "GlobalConfigurationClientExpectTest") -public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest { @Test public void testListHostsWhenResponseIs2xx() { @@ -328,4 +328,4 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe protected GlobalHostClient clientFrom(CloudStackContext context) { return context.getGlobalContext().getApi().getHostClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java index 18e7d0d98a..043a167bc8 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java @@ -25,7 +25,7 @@ import java.net.URI; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.AllocationState; import org.jclouds.cloudstack.domain.Pod; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.cloudstack.options.CreatePodOptions; import org.jclouds.cloudstack.options.UpdatePodOptions; import org.jclouds.http.HttpRequest; @@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableSet; * @author Richard Downer */ @Test(groups = "unit", testName = "GlobalPodClientExpectTest") -public class GlobalPodClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class GlobalPodClientExpectTest extends BaseCloudStackExpectTest { public void testListPodsWhenResponseIs2xx() { GlobalPodClient client = requestSendsResponse( @@ -201,4 +201,4 @@ public class GlobalPodClientExpectTest extends BaseCloudStackRestClientExpectTes protected GlobalPodClient clientFrom(CloudStackContext context) { return context.getGlobalContext().getApi().getPodClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientExpectTest.java index 259d5479c7..4e7cfd7244 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientExpectTest.java @@ -24,7 +24,7 @@ import java.net.URI; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.VlanIPRange; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -38,7 +38,7 @@ import com.google.common.collect.ImmutableSet; * @author Richard Downer */ @Test(groups = "unit", testName = "GlobalVlanClientExpectTest") -public class GlobalVlanClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class GlobalVlanClientExpectTest extends BaseCloudStackExpectTest { public void testListVlanIpRangesWhenResponseIs2xx() { GlobalVlanClient client = requestSendsResponse( @@ -170,4 +170,4 @@ public class GlobalVlanClientExpectTest extends BaseCloudStackRestClientExpectTe protected GlobalVlanClient clientFrom(CloudStackContext context) { return context.getGlobalContext().getApi().getVlanClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientExpectTest.java index fb2fcb2e1b..d3ed7c1fb5 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientExpectTest.java @@ -28,7 +28,7 @@ import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.AllocationState; import org.jclouds.cloudstack.domain.NetworkType; import org.jclouds.cloudstack.domain.Zone; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableMultimap; * @author Andrei Savu */ @Test(groups = "unit", testName = "GlobalZoneClientExpectTest") -public class GlobalZoneClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class GlobalZoneClientExpectTest extends BaseCloudStackExpectTest { public void testCreateZoneWhenResponseIs2xxAnd404() { HttpRequest request = HttpRequest.builder() @@ -134,4 +134,4 @@ public class GlobalZoneClientExpectTest extends BaseCloudStackRestClientExpectTe protected GlobalZoneClient clientFrom(CloudStackContext context) { return context.getGlobalContext().getApi().getZoneClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SSHKeyPairClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SSHKeyPairClientExpectTest.java index 69e83adf2d..dc03cd90f2 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SSHKeyPairClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SSHKeyPairClientExpectTest.java @@ -25,7 +25,7 @@ import java.net.URI; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.SshKeyPair; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.crypto.SshKeys; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -41,7 +41,7 @@ import com.sun.jersey.api.uri.UriComponent; * @author Andrei Savu */ @Test(groups = "unit", testName = "SSHKeyPairClientExpectTest") -public class SSHKeyPairClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class SSHKeyPairClientExpectTest extends BaseCloudStackExpectTest { @Test public void testListAndGetSSHKeyPairsWhenResponseIs2xx() { @@ -182,4 +182,4 @@ public class SSHKeyPairClientExpectTest extends BaseCloudStackRestClientExpectTe protected SSHKeyPairClient clientFrom(CloudStackContext context) { return context.getProviderSpecificContext().getApi().getSSHKeyPairClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientExpectTest.java index 54bc12175a..7abc4eb248 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientExpectTest.java @@ -28,7 +28,7 @@ import java.net.URLEncoder; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.LoginResponse; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap; * @author Andrei Savu */ @Test(groups = "live", singleThreaded = true, testName = "SessionClientExpectTest") -public class SessionClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class SessionClientExpectTest extends BaseCloudStackExpectTest { @SuppressWarnings("deprecation") public void testLoginWhenResponseIs2xxIncludesJSessionId() throws IOException { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java index 09f129bb20..e40772083e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java @@ -27,7 +27,7 @@ import java.security.cert.CertificateException; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.EncryptedPasswordAndPrivateKey; import org.jclouds.cloudstack.functions.WindowsLoginCredentialsFromEncryptedData; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.crypto.Crypto; import org.jclouds.encryption.bouncycastle.BouncyCastleCrypto; import org.jclouds.http.HttpRequest; @@ -40,7 +40,7 @@ import org.testng.annotations.Test; * @author Andrei Savu */ @Test(groups = "unit", testName = "VirtualMachineClientExpectTest") -public class VirtualMachineClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class VirtualMachineClientExpectTest extends BaseCloudStackExpectTest { public void testGetPasswordForVirtualMachineWhenResponseIs2xx() throws NoSuchAlgorithmException, CertificateException { String privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" + @@ -90,4 +90,4 @@ public class VirtualMachineClientExpectTest extends BaseCloudStackRestClientExpe protected VirtualMachineClient clientFrom(CloudStackContext context) { return context.getProviderSpecificContext().getApi().getVirtualMachineClient(); } -} \ No newline at end of file +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneClientExpectTest.java index fdf48311f0..2ff8148453 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneClientExpectTest.java @@ -25,7 +25,7 @@ import java.net.URI; import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.NetworkType; import org.jclouds.cloudstack.domain.Zone; -import org.jclouds.cloudstack.internal.BaseCloudStackRestClientExpectTest; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -38,7 +38,7 @@ import com.google.common.collect.ImmutableSet; * @author Andrei Savu */ @Test(groups = "unit", testName = "ZoneClientExpectTest") -public class ZoneClientExpectTest extends BaseCloudStackRestClientExpectTest { +public class ZoneClientExpectTest extends BaseCloudStackExpectTest { public void testListZonesWhenResponseIs2xx() { @@ -91,4 +91,4 @@ public class ZoneClientExpectTest extends BaseCloudStackRestClientExpectTest extends BaseCloudStackExpectTest { + + public BaseCloudStackComputeServiceContextExpectTest() { + // to match the api key name in listaccountsresponse.json + identity = "APIKEY"; + } + + protected final HttpRequest listTemplates = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listTemplates") + .addQueryParam("listAll", "true") + .addQueryParam("templatefilter", "executable") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "Xk6lF%2Fv3SbhrxTKqaC2IWoBPKHo%3D") + .addHeader("Accept", "application/json") + .build(); + + //TODO: update or add new resource files to have more recent data, ex. ubuntu template + protected final HttpResponse listTemplatesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listtemplatesresponse.json")) + .build(); + + protected final HttpRequest listOsTypes = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listOsTypes") + .addQueryParam("listAll", "true") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "8BsE8MsOAhUzo1Q4Y3UD%2Fe96u84%3D") + .addHeader("Accept", "application/json") + .build(); + + protected final HttpResponse listOsTypesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listostypesresponse.json")) + .build(); + + protected final HttpRequest listOsCategories = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listOsCategories") + .addQueryParam("listAll", "true") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "OojW4ssh%2FRQ3CubAzXue4svlofM%3D") +// .addHeader("Accept", "application/json") //TODO: why are we not passing this? + .build(); + + protected final HttpResponse listOsCategoriesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listoscategoriesresponse.json")) + .build(); + + protected final HttpRequest listZones = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listZones") + .addQueryParam("listAll", "true") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "GTUgn%2FLHDioJRq48kurOdCAYueo%3D") + .addHeader("Accept", "application/json") + .build(); + + protected final HttpResponse listZonesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listzonesresponse.json")) + .build(); + + protected final HttpRequest listServiceOfferings = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listServiceOfferings") + .addQueryParam("listAll", "true") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "jUien8oeEan7bjKKQbBlzvFuMjw%3D") + .addHeader("Accept", "application/json") + .build(); + + protected final HttpResponse listServiceOfferingsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listserviceofferingsresponse.json")) + .build(); + + protected final HttpRequest listAccounts = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listAccounts") + .addQueryParam("listAll", "true") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "E4wuKXCkioaNIiL8hL8FD9K5K2c%3D") + .addHeader("Accept", "application/json") + .build(); + + protected final HttpResponse listAccountsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listaccountsresponse.json")) + .build(); + + protected final HttpRequest listNetworks = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listNetworks") + .addQueryParam("listAll", "true") + .addQueryParam("account", "jclouds") // account and domain came from above + .addQueryParam("domainid", "457") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "FDiGGBiG%2FsVj0k6DmZIgMNU8SqI%3D") + .addHeader("Accept", "application/json") + .build(); + + protected final HttpResponse listNetworksResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listnetworksresponse.json")) + .build(); + + protected final HttpRequest getZone = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listZones") + .addQueryParam("listAll", "true") + .addQueryParam("id", "1") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "q5GMO9iUYIFs5S58DdAuYAy8yu0%3D") + .addHeader("Accept", "application/json") + .build(); + + protected final HttpResponse getZoneResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/getzoneresponse.json")) + .build(); + + protected final HttpRequest listCapabilities = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("listAll", "true") + .addQueryParam("command", "listCapabilities") + .addQueryParam("apiKey", "APIKEY") + .addQueryParam("signature", "vVdhtet%2FzG59FXgkYkAzEQQ4q1o%3D") + .addHeader("Accept", "application/json") + .build(); + + protected final HttpResponse listCapabilitiesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/listcapabilitiesresponse.json")) + .build(); + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/BaseCloudStackRestClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/BaseCloudStackExpectTest.java similarity index 65% rename from apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/BaseCloudStackRestClientExpectTest.java rename to apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/BaseCloudStackExpectTest.java index d397436b29..b72be4aa44 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/BaseCloudStackRestClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/internal/BaseCloudStackExpectTest.java @@ -19,9 +19,8 @@ package org.jclouds.cloudstack.internal; import static org.jclouds.crypto.CryptoStreams.md5Hex; +import static org.jclouds.util.Strings2.urlEncode; -import java.net.URI; -import java.net.URLEncoder; import java.util.Properties; import org.jclouds.apis.ApiMetadata; @@ -32,7 +31,6 @@ import org.jclouds.http.HttpResponse; import org.jclouds.rest.internal.BaseRestClientExpectTest; import com.google.common.base.Function; -import com.google.common.collect.ImmutableMultimap; import com.google.inject.Module; /** @@ -40,9 +38,9 @@ import com.google.inject.Module; * * @author Andrei Savu */ -public abstract class BaseCloudStackRestClientExpectTest extends BaseRestClientExpectTest { +public abstract class BaseCloudStackExpectTest extends BaseRestClientExpectTest { - public BaseCloudStackRestClientExpectTest() { + public BaseCloudStackExpectTest() { provider = "cloudstack"; } @@ -51,7 +49,6 @@ public abstract class BaseCloudStackRestClientExpectTest extends BaseRestClie return new CloudStackApiMetadata(); } - @Override public S createClient(Function fn, Module module, Properties props) { return (S) clientFrom(createInjector(fn, module, props).getInstance(CloudStackContext.class)); @@ -59,36 +56,30 @@ public abstract class BaseCloudStackRestClientExpectTest extends BaseRestClie protected abstract S clientFrom(CloudStackContext context); - protected final HttpRequest loginRequest = HttpRequest.builder() - .method("GET") - .endpoint( - URI.create("http://localhost:8080/client/api?response=json&command=login&" + - "username=identity&password=" + md5Hex("credential")+ "&domain=")) - .headers( - ImmutableMultimap.builder() - .put("Accept", "application/json") - .build()) - .build(); + protected final HttpRequest login = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "login") + .addQueryParam("username", "identity") + .addQueryParam("password", md5Hex("credential")) + .addQueryParam("domain", "") + .addHeader("Accept", "application/json") + .build(); protected final String jSessionId = "90DD65D13AEAA590ECCA312D150B9F6D"; protected final String sessionKey = "uYT4/MNiglgAKiZRQkvV8QP8gn0="; - protected final HttpResponse loginResponse = HttpResponse.builder() - .statusCode(200) - .headers( - ImmutableMultimap.builder() - .put("Set-Cookie", "JSESSIONID="+jSessionId+"; Path=/client") - .build()) + protected final HttpResponse loginResponse = HttpResponse.builder().statusCode(200) + .addHeader("Set-Cookie", "JSESSIONID=" + jSessionId + "; Path=/client") .payload(payloadFromResource("/loginresponse.json")) .build(); - @SuppressWarnings("deprecation") - protected final HttpRequest logoutRequest = HttpRequest.builder() - .method("GET") - .endpoint( - URI.create("http://localhost:8080/client/api?response=json&command=logout&" + - "sessionkey=" + URLEncoder.encode(sessionKey))) - .build(); + protected final HttpRequest logout = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "logout") + .addQueryParam("sessionkey", urlEncode(sessionKey)) + .build(); protected final HttpResponse logoutResponse = HttpResponse.builder().statusCode(200).build(); diff --git a/apis/cloudstack/src/test/resources/deployvirtualmachineresponse.json b/apis/cloudstack/src/test/resources/deployvirtualmachineresponse.json new file mode 100644 index 0000000000..3b7bf7a54f --- /dev/null +++ b/apis/cloudstack/src/test/resources/deployvirtualmachineresponse.json @@ -0,0 +1 @@ +{ "deployvirtualmachine" : {"id":1234, "jobid":50006} } \ No newline at end of file diff --git a/apis/cloudstack/src/test/resources/getzoneresponse.json b/apis/cloudstack/src/test/resources/getzoneresponse.json new file mode 100644 index 0000000000..65dc9250ba --- /dev/null +++ b/apis/cloudstack/src/test/resources/getzoneresponse.json @@ -0,0 +1 @@ +{ "listzonesresponse" : { "zone" : [ {"id":1,"name":"San Jose 1","networktype":"Advanced","securitygroupsenabled":false} ] } } \ No newline at end of file diff --git a/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-virtualmachine.json b/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-virtualmachine.json new file mode 100644 index 0000000000..6e4654aa17 --- /dev/null +++ b/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-virtualmachine.json @@ -0,0 +1,53 @@ +{ + "queryasyncjobresultresponse": { + "jobid": 50006, + "accountid": 3, + "userid": 3, + "cmd": "com.cloud.api.commands.DeployVMCmd", + "jobstatus": 1, + "jobprocstatus": 0, + "jobresultcode": 0, + "jobresult": { + "virtualmachine": { + "id": 1234, + "name": "i-3-218-VM", + "displayname": "i-3-218-VM", + "account": "adrian", + "domainid": 1, + "domain": "ROOT", + "created": "2011-02-27T08:39:10-0800", + "state": "Running", + "haenable": false, + "zoneid": 1, + "zonename": "San Jose 1", + "templateid": 203, + "templatename": "Centos 5.3 Password Managed", + "templatedisplaytext": "Centos 5.3 Password Managed", + "passwordenabled": true, + "serviceofferingid": 1, + "serviceofferingname": "Small Instance", + "cpunumber": 1, + "cpuspeed": 500, + "memory": 512, + "guestosid": 12, + "rootdeviceid": 0, + "rootdevicetype": "NetworkFilesystem", + "securitygroup": [], + "password": "dD7jwajkh", + "nic": [{ + "id": 250, + "networkid": 204, + "netmask": "255.255.255.0", + "gateway": "10.1.1.1", + "ipaddress": "10.1.1.195", + "traffictype": "Guest", + "type": "Virtual", + "isdefault": true + }], + "hypervisor": "XenServer" + } + }, + "created": "2011-02-27T08:39:10-0800" + } + +} \ No newline at end of file