@Test public void testListTemplates() throws Exception { Set<Template> response = client.getTemplateClient().listTemplates(); assert null != response; long templateCount = response.size(); assertTrue(templateCount >= 0); for (Template template : response) { Template newDetails = Iterables.getOnlyElement( client .getTemplateClient() .listTemplates(zoneId(template.getZoneId()).id(template.getId()))); Logger.CONSOLE.info("Checking template: " + template); assertEquals(template, newDetails); assertEquals( template, client.getTemplateClient().getTemplateInZone(template.getId(), template.getZoneId())); assert template.getId() > 0 : template; assert template.getName() != null : template; assert template.getDisplayText() != null : template; assert template.getCreated() != null : template; assert template.getFormat() != null && template.getFormat() != Template.Format.UNRECOGNIZED : template; assert template.getOSType() != null : template; assert template.getOSTypeId() > 0 : template; assert template.getAccount() != null : template; assert template.getZone() != null : template; assert template.getZoneId() > 0 : template; assert (template.getStatus() == null || template.getStatus().equals("Download Complete")) : template; assert template.getType() != null && template.getType() != Template.Type.UNRECOGNIZED : template; assert template.getHypervisor() != null : template; assert template.getDomain() != null : template; assert template.getDomainId() > 0 : template; assert template.getSize() > 0 : template; } }
@Test(enabled = true, dependsOnMethods = "testRegisterTemplate") public void testExtractTemplate() throws Exception { // Initiate the extraction and wait for it to complete AsyncCreateResponse response = client .getTemplateClient() .extractTemplate( registeredTemplate.getId(), ExtractMode.HTTP_DOWNLOAD, registeredTemplate.getZoneId()); assertTrue(jobComplete.apply(response.getJobId()), registeredTemplate.toString()); // Get the result AsyncJob<TemplateExtraction> 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); URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8")); assertTrue(context.utils().http().exists(uri), "does not exist: " + uri); }