refactored cloudstack expect tests and added CloudStackComputeServiceAdapterExpectTest

This commit is contained in:
Adrian Cole 2012-11-05 11:26:38 -03:00
parent 691152c3d8
commit 96b7231b25
21 changed files with 406 additions and 84 deletions

View File

@ -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<CloudStackContext> {
public class PasswordAuthenticationExpectTest extends BaseCloudStackExpectTest<CloudStackContext> {
/**
* 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.<String, String>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();

View File

@ -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<Injector> {
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<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> 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<VirtualMachine> 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();
}
}

View File

@ -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();

View File

@ -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<AccountClient> {
public class AccountClientExpectTest extends BaseCloudStackExpectTest<AccountClient> {
public void testListAccountsWhenResponseIs2xx() {
@ -106,4 +106,4 @@ public class AccountClientExpectTest extends BaseCloudStackRestClientExpectTest<
protected AccountClient clientFrom(CloudStackContext context) {
return context.getProviderSpecificContext().getApi().getAccountClient();
}
}
}

View File

@ -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<DomainDomainClient> {
public class DomainDomainClientExpectTest extends BaseCloudStackExpectTest<DomainDomainClient> {
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();
}
}
}

View File

@ -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<FirewallClient> {
public class FirewallClientExpectTest extends BaseCloudStackExpectTest<FirewallClient> {
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();
}
}
}

View File

@ -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<GlobalConfigurationClient> {
public class GlobalConfigurationClientExpectTest extends BaseCloudStackExpectTest<GlobalConfigurationClient> {
@Test
public void testListConfigurationEntriesWhenResponseIs2xx() {
@ -126,4 +126,4 @@ public class GlobalConfigurationClientExpectTest extends BaseCloudStackRestClien
protected GlobalConfigurationClient clientFrom(CloudStackContext context) {
return context.getGlobalContext().getApi().getConfigurationClient();
}
}
}

View File

@ -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<GlobalDomainClient> {
public class GlobalDomainClientExpectTest extends BaseCloudStackExpectTest<GlobalDomainClient> {
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();
}
}
}

View File

@ -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<GlobalHostClient> {
public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalHostClient> {
@Test
public void testListHostsWhenResponseIs2xx() {
@ -328,4 +328,4 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe
protected GlobalHostClient clientFrom(CloudStackContext context) {
return context.getGlobalContext().getApi().getHostClient();
}
}
}

View File

@ -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<GlobalPodClient> {
public class GlobalPodClientExpectTest extends BaseCloudStackExpectTest<GlobalPodClient> {
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();
}
}
}

View File

@ -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<GlobalVlanClient> {
public class GlobalVlanClientExpectTest extends BaseCloudStackExpectTest<GlobalVlanClient> {
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();
}
}
}

View File

@ -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<GlobalZoneClient> {
public class GlobalZoneClientExpectTest extends BaseCloudStackExpectTest<GlobalZoneClient> {
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();
}
}
}

View File

@ -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<SSHKeyPairClient> {
public class SSHKeyPairClientExpectTest extends BaseCloudStackExpectTest<SSHKeyPairClient> {
@Test
public void testListAndGetSSHKeyPairsWhenResponseIs2xx() {
@ -182,4 +182,4 @@ public class SSHKeyPairClientExpectTest extends BaseCloudStackRestClientExpectTe
protected SSHKeyPairClient clientFrom(CloudStackContext context) {
return context.getProviderSpecificContext().getApi().getSSHKeyPairClient();
}
}
}

View File

@ -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<SessionClient> {
public class SessionClientExpectTest extends BaseCloudStackExpectTest<SessionClient> {
@SuppressWarnings("deprecation")
public void testLoginWhenResponseIs2xxIncludesJSessionId() throws IOException {

View File

@ -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<VirtualMachineClient> {
public class VirtualMachineClientExpectTest extends BaseCloudStackExpectTest<VirtualMachineClient> {
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();
}
}
}

View File

@ -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<ZoneClient> {
public class ZoneClientExpectTest extends BaseCloudStackExpectTest<ZoneClient> {
public void testListZonesWhenResponseIs2xx() {
@ -91,4 +91,4 @@ public class ZoneClientExpectTest extends BaseCloudStackRestClientExpectTest<Zon
protected ZoneClient clientFrom(CloudStackContext context) {
return context.getProviderSpecificContext().getApi().getZoneClient();
}
}
}

View File

@ -0,0 +1,168 @@
/**
* 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.internal;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
/**
* Base class for writing CloudStack Expect tests with the ComputeService
* abstraction
*
*/
public abstract class BaseCloudStackComputeServiceContextExpectTest<T> extends BaseCloudStackExpectTest<T> {
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();
}

View File

@ -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<S> extends BaseRestClientExpectTest<S> {
public abstract class BaseCloudStackExpectTest<S> extends BaseRestClientExpectTest<S> {
public BaseCloudStackRestClientExpectTest() {
public BaseCloudStackExpectTest() {
provider = "cloudstack";
}
@ -51,7 +49,6 @@ public abstract class BaseCloudStackRestClientExpectTest<S> extends BaseRestClie
return new CloudStackApiMetadata();
}
@Override
public S createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return (S) clientFrom(createInjector(fn, module, props).getInstance(CloudStackContext.class));
@ -59,36 +56,30 @@ public abstract class BaseCloudStackRestClientExpectTest<S> 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.<String, String>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.<String, String>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();

View File

@ -0,0 +1 @@
{ "deployvirtualmachine" : {"id":1234, "jobid":50006} }

View File

@ -0,0 +1 @@
{ "listzonesresponse" : { "zone" : [ {"id":1,"name":"San Jose 1","networktype":"Advanced","securitygroupsenabled":false} ] } }

View File

@ -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"
}
}