diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ParseAsyncJobFromHttpResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ParseAsyncJobFromHttpResponseTest.java index 400a162d08..8e6b539ff2 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ParseAsyncJobFromHttpResponseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ParseAsyncJobFromHttpResponseTest.java @@ -19,13 +19,11 @@ package org.jclouds.cloudstack.functions; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; import java.io.InputStream; -import org.jclouds.cloudstack.domain.AsyncJob; -import org.jclouds.cloudstack.domain.AsyncJobError; -import org.jclouds.cloudstack.domain.IPForwardingRule; -import org.jclouds.cloudstack.domain.PublicIPAddress; +import org.jclouds.cloudstack.domain.*; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.domain.JsonBall; import org.jclouds.http.HttpResponse; @@ -187,4 +185,14 @@ public class ParseAsyncJobFromHttpResponseTest { assertEquals(response, expects); } + public void testOverloadedKeyName() { + InputStream is = getClass().getResourceAsStream("/queryasyncjobresultresponse-createtemplate.json"); + ParseAsyncJobFromHttpResponse parser = i.getInstance(ParseAsyncJobFromHttpResponse.class); + AsyncJob response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))); + assertTrue(response.getResult() instanceof Template, "response expected to be Template, actually is "+response.getResult().getClass()); + + is = getClass().getResourceAsStream("/queryasyncjobresultresponse-extracttemplate.json"); + response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))); + assertTrue(response.getResult() instanceof TemplateExtraction, "response expected to be TemplateExtraction, actually is "+response.getResult().getClass()); + } } diff --git a/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-createtemplate.json b/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-createtemplate.json new file mode 100644 index 0000000000..ed2b886e7b --- /dev/null +++ b/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-createtemplate.json @@ -0,0 +1 @@ +{ "queryasyncjobresultresponse" : {"jobid":2716,"jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"template":{"id":249,"name":"jclouds-c5c7dce0","displaytext":"jclouds live testCreateTemplate","ispublic":false,"created":"2011-11-16T06:43:00-0800","isready":true,"passwordenabled":false,"format":"VHD","isfeatured":false,"crossZones":false,"ostypeid":12,"ostypename":"CentOS 5.3 (64-bit)","account":"jcloud2","zoneid":1,"zonename":"Demo5","status":"Download Complete","size":8589934592,"templatetype":"USER","hypervisor":"XenServer","domain":"jCloud","domainid":11,"isextractable":true,"checksum":"bdc1c2c49b747694f97be5042323a1fa","sourcetemplateid":202}}} } \ No newline at end of file diff --git a/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-extracttemplate.json b/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-extracttemplate.json new file mode 100644 index 0000000000..387f56fcd4 --- /dev/null +++ b/apis/cloudstack/src/test/resources/queryasyncjobresultresponse-extracttemplate.json @@ -0,0 +1 @@ +{ "queryasyncjobresultresponse" : {"jobid":2720,"jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"template":{"id":249,"name":"jclouds-c5c7dce0","extractId":6,"accountid":19,"state":"DOWNLOAD_URL_CREATED","zoneid":1,"zonename":"Demo5","extractMode":"HTTP_DOWNLOAD","url":"https:%2F%2F72-52-126-96.realhostip.com%2Fuserdata%2Ff52f8e7d-7c89-4cf7-8e5a-b5ea17366d73.vhd"}}} } \ No newline at end of file