Add TemplateClientLiveTest.testExtractTemplate()

This commit is contained in:
Richard Downer 2011-11-16 21:09:18 +00:00
parent 1e7592ac98
commit 75752db64c
1 changed files with 25 additions and 0 deletions

View File

@ -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<TemplateExtraction> asyncJob = client.getAsyncJobClient().<TemplateExtraction>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();
}
}