node = getOnlyElement(client.createNodesInGroup(group, 1));
Predicate<URI> taskTester = retry(new TaskSuccess(getVCloudApi()), 600, 5, SECONDS);
// I have to undeploy first
Task task = getVCloudApi().getVAppApi().undeployVApp(URI.create(node.getId()));
// wait up to ten minutes per above
assert taskTester.apply(task.getHref()) : node;
VApp vApp = getVCloudApi().getVAppApi().getVApp(URI.create(node.getId()));
// wait up to ten minutes per above
assertEquals(vApp.getStatus(), Status.OFF);
// vdc is equiv to the node's location
// vapp uri is the same as the node's id
vappTemplate = getVCloudApi().getVAppTemplateApi().captureVAppAsTemplateInVDC(URI.create(node.getId()),
group, URI.create(node.getLocation().getId()));
assertEquals(vappTemplate.getName(), group);
task = vappTemplate.getTasks().get(0);
// wait up to ten minutes per above
assert taskTester.apply(task.getHref()) : vappTemplate;
item = getVCloudApi().getCatalogApi().addVAppTemplateOrMediaImageToCatalogAndNameItem(
vappTemplate.getHref(),
getVCloudApi().getCatalogApi().findCatalogInOrgNamed(null, null).getHref(), "fooname",
CatalogItemOptions.Builder.description("description").properties(ImmutableMap.of("foo", "bar")));