From c58440f6012c5629d3b86111e492940ad4c83bba Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 30 Jan 2013 09:04:40 -0800 Subject: [PATCH] fix issue #1254 cloudstack renamed deployvirtualmachineresponse in version 4.1 --- .../features/VirtualMachineAsyncClient.java | 2 +- .../VirtualMachineAsyncClientTest.java | 20 --------- .../VirtualMachineClientExpectTest.java | 43 +++++++++++++++--- .../DeployVirtualMachineResponse3xTest.java | 43 ++++++++++++++++++ .../DeployVirtualMachineResponse4xTest.java | 44 +++++++++++++++++++ .../deployvirtualmachineresponse4x.json | 1 + 6 files changed, 127 insertions(+), 26 deletions(-) create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DeployVirtualMachineResponse3xTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DeployVirtualMachineResponse4xTest.java create mode 100644 apis/cloudstack/src/test/resources/deployvirtualmachineresponse4x.json diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java index 427eb5260a..0aa105c9f6 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java @@ -80,7 +80,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "deployVirtualMachine") - @Unwrap + @SelectJson({ "deployvirtualmachine", "deployvirtualmachineresponse" }) @Consumes(MediaType.APPLICATION_JSON) ListenableFuture deployVirtualMachineInZone(@QueryParam("zoneid") String zoneId, @QueryParam("serviceofferingid") String serviceOfferingId, @QueryParam("templateid") String templateId, diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java index 650cd32ba6..31158ab3ce 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java @@ -23,7 +23,6 @@ import java.lang.reflect.Method; 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.functions.IdentityFunction; import org.jclouds.http.HttpRequest; @@ -103,25 +102,6 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest } - public void testDeployVirtualMachineInZone() throws SecurityException, NoSuchMethodException, IOException { - Method method = VirtualMachineAsyncClient.class.getMethod("deployVirtualMachineInZone", String.class, String.class, - String.class, DeployVirtualMachineOptions[].class); - HttpRequest httpRequest = processor.createRequest(method, 6, 4, 5); - - assertRequestLineEquals( - httpRequest, - "GET http://localhost:8080/client/api?response=json&command=deployVirtualMachine&zoneid=6&templateid=5&serviceofferingid=4 HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - public void testRebootVirtualMachine() throws SecurityException, NoSuchMethodException, IOException { Method method = VirtualMachineAsyncClient.class.getMethod("rebootVirtualMachine", String.class); HttpRequest httpRequest = processor.createRequest(method, 5); 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 b029d8a656..1f7bb78a77 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 @@ -25,6 +25,7 @@ import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; 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; @@ -59,11 +60,8 @@ public class VirtualMachineClientExpectTest extends BaseCloudStackExpectTest { + + @Override + public String resource() { + return "/deployvirtualmachineresponse.json"; + } + + @Override + @SelectJson({ "deployvirtualmachine", "deployvirtualmachineresponse" }) + public AsyncCreateResponse expected() { + return AsyncCreateResponse.builder().id("1234").jobId("50006").build(); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DeployVirtualMachineResponse4xTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DeployVirtualMachineResponse4xTest.java new file mode 100644 index 0000000000..40e110b0be --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/DeployVirtualMachineResponse4xTest.java @@ -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 { + + @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(); + } +} diff --git a/apis/cloudstack/src/test/resources/deployvirtualmachineresponse4x.json b/apis/cloudstack/src/test/resources/deployvirtualmachineresponse4x.json new file mode 100644 index 0000000000..cf04a8d2f1 --- /dev/null +++ b/apis/cloudstack/src/test/resources/deployvirtualmachineresponse4x.json @@ -0,0 +1 @@ + { "deployvirtualmachineresponse" : {"id":"1cce6cb7-2268-47ff-9696-d9e610f6619a","jobid":"13330fc9-8b3e-4582-aa3e-90883c041ff0"}, "cloudstack-version": "4.1.0-SNAPSHOT" } \ No newline at end of file