From 75752db64c5a73a5939f24d01e0d011c1e9d4c37 Mon Sep 17 00:00:00 2001 From: Richard Downer Date: Wed, 16 Nov 2011 21:09:18 +0000 Subject: [PATCH] Add TemplateClientLiveTest.testExtractTemplate() --- .../features/TemplateClientLiveTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java index 4fc59ff138..91ba0160af 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java @@ -28,6 +28,9 @@ import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; import javax.annotation.Nullable; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLDecoder; import java.util.Random; import java.util.Set; @@ -73,6 +76,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest { } } + @Test(enabled = true) public void testCreateTemplate() throws Exception { Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null); assertNotNull(zone); @@ -121,4 +125,25 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest { super.tearDown(); } + @Test(enabled = true, dependsOnMethods = "testCreateTemplate") + public void testExtractTemplate() throws Exception { + // Initiate the extraction and wait for it to complete + AsyncCreateResponse response = client.getTemplateClient().extractTemplate(template.getId(), ExtractMode.HTTP_DOWNLOAD, template.getZoneId()); + assert jobComplete.apply(response.getJobId()) : template; + + // Get the result + AsyncJob asyncJob = client.getAsyncJobClient().getAsyncJob(response.getJobId()); + TemplateExtraction extract = asyncJob.getResult(); + assertNotNull(extract); + + // Check that the URL can be retrieved + String extractUrl = extract.getUrl(); + assertNotNull(extractUrl); + URL url = new URL(URLDecoder.decode(extractUrl, "utf-8")); + HttpURLConnection connection = (HttpURLConnection)url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + assertEquals(connection.getResponseCode(), 200); + connection.disconnect(); + } }