fix issue #1254 cloudstack renamed deployvirtualmachineresponse in version 4.1

This commit is contained in:
Adrian Cole 2013-01-30 09:04:40 -08:00
parent 55a10d4c5d
commit bb36c363b7
6 changed files with 127 additions and 35 deletions

View File

@ -38,7 +38,6 @@ import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Unwrap;
import com.google.common.util.concurrent.ListenableFuture;
@ -80,7 +79,7 @@ public interface VirtualMachineAsyncClient {
*/
@GET
@QueryParams(keys = "command", values = "deployVirtualMachine")
@Unwrap
@SelectJson({ "deployvirtualmachine", "deployvirtualmachineresponse" })
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<AsyncCreateResponse> deployVirtualMachineInZone(@QueryParam("zoneid") String zoneId,
@QueryParam("serviceofferingid") String serviceOfferingId, @QueryParam("templateid") String templateId,

View File

@ -26,13 +26,10 @@ import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
import org.jclouds.cloudstack.options.AssignVirtualMachineOptions;
import org.jclouds.cloudstack.options.DeployVirtualMachineOptions;
import org.jclouds.cloudstack.options.ListVirtualMachinesOptions;
import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test;
@ -104,31 +101,6 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
}
HttpRequest deployVirtualMachine = HttpRequest.builder().method("GET")
.endpoint("http://localhost:8080/client/api")
.addQueryParam("response", "json")
.addQueryParam("command", "deployVirtualMachine")
.addQueryParam("zoneid", "6")
.addQueryParam("serviceofferingid", "4")
.addQueryParam("templateid", "5").build();
public void testDeployVirtualMachineInZone() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualMachineAsyncClient.class, "deployVirtualMachineInZone", String.class, String.class,
String.class, DeployVirtualMachineOptions[].class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(6, 4, 5));
assertRequestLineEquals(httpRequest, deployVirtualMachine.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 testRebootVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualMachineAsyncClient.class, "rebootVirtualMachine", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5));

View File

@ -26,6 +26,7 @@ import java.security.cert.CertificateException;
import org.jclouds.cloudstack.CloudStackApiMetadata;
import org.jclouds.cloudstack.CloudStackContext;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.EncryptedPasswordAndPrivateKey;
import org.jclouds.cloudstack.functions.WindowsLoginCredentialsFromEncryptedData;
import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
@ -60,11 +61,8 @@ public class VirtualMachineClientExpectTest extends BaseCloudStackExpectTest<Vir
"-----END RSA PRIVATE KEY-----";
VirtualMachineClient client = requestSendsResponse(
HttpRequest.builder()
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=getVMPassword&id=1&apiKey=identity&signature=SVA2r1KRj4yG03rATMLPZWS%2BKnw%3D"))
HttpRequest.builder().method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=getVMPassword&id=1&apiKey=identity&signature=SVA2r1KRj4yG03rATMLPZWS%2BKnw%3D")
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()
@ -84,6 +82,41 @@ public class VirtualMachineClientExpectTest extends BaseCloudStackExpectTest<Vir
assertEquals(passwordDecrypt.apply(
EncryptedPasswordAndPrivateKey.builder().encryptedPassword(actual).privateKey(privateKey).build()).getPassword(), "bX7vvptvw");
}
HttpRequest deployVirtualMachineInZone = HttpRequest.builder().method("GET")
.endpoint("http://localhost:8080/client/api")
.addQueryParam("response", "json")
.addQueryParam("command", "deployVirtualMachine")
.addQueryParam("zoneid", "zone1")
.addQueryParam("serviceofferingid", "serviceOffering1")
.addQueryParam("templateid", "template1")
.addQueryParam("apiKey", "identity")
.addQueryParam("signature", "pBjjnTq7/ezN94Uj0gpy2T//cJQ%3D")
.addHeader("Accept", "application/json")
.build();
public void testDeployVirtualMachineIs2xxVersion3x() {
HttpResponse deployVirtualMachineInZoneResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/deployvirtualmachineresponse.json")).build();
VirtualMachineClient client = requestSendsResponse(deployVirtualMachineInZone, deployVirtualMachineInZoneResponse);
AsyncCreateResponse async = client.deployVirtualMachineInZone("zone1", "serviceOffering1", "template1");
assertEquals(async, AsyncCreateResponse.builder().id("1234").jobId("50006").build());
}
public void testDeployVirtualMachineIs2xxVersion4x() {
HttpResponse deployVirtualMachineInZoneResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/deployvirtualmachineresponse4x.json")).build();
VirtualMachineClient client = requestSendsResponse(deployVirtualMachineInZone, deployVirtualMachineInZoneResponse);
AsyncCreateResponse async = client.deployVirtualMachineInZone("zone1", "serviceOffering1", "template1");
assertEquals(
async,
AsyncCreateResponse.builder().id("1cce6cb7-2268-47ff-9696-d9e610f6619a")
.jobId("13330fc9-8b3e-4582-aa3e-90883c041ff0").build());
}
@Override
protected VirtualMachineClient clientFrom(CloudStackContext context) {

View File

@ -0,0 +1,43 @@
/**
* 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.parse;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "DeployVirtualMachineResponse3xTest")
public class DeployVirtualMachineResponse3xTest extends BaseItemParserTest<AsyncCreateResponse> {
@Override
public String resource() {
return "/deployvirtualmachineresponse.json";
}
@Override
@SelectJson({ "deployvirtualmachine", "deployvirtualmachineresponse" })
public AsyncCreateResponse expected() {
return AsyncCreateResponse.builder().id("1234").jobId("50006").build();
}
}

View File

@ -0,0 +1,44 @@
/**
* 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.parse;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "DeployVirtualMachineResponse3xTest")
public class DeployVirtualMachineResponse4xTest extends BaseItemParserTest<AsyncCreateResponse> {
@Override
public String resource() {
return "/deployvirtualmachineresponse4x.json";
}
@Override
@SelectJson({ "deployvirtualmachine", "deployvirtualmachineresponse" })
public AsyncCreateResponse expected() {
return AsyncCreateResponse.builder().id("1cce6cb7-2268-47ff-9696-d9e610f6619a")
.jobId("13330fc9-8b3e-4582-aa3e-90883c041ff0").build();
}
}

View File

@ -0,0 +1 @@
{ "deployvirtualmachineresponse" : {"id":"1cce6cb7-2268-47ff-9696-d9e610f6619a","jobid":"13330fc9-8b3e-4582-aa3e-90883c041ff0"}, "cloudstack-version": "4.1.0-SNAPSHOT" }