VApp vApp = createMock(VApp.class);
InternetServiceAndPublicIpAddressSupplier supplier = createMock(InternetServiceAndPublicIpAddressSupplier.class);
expect(client.getVAppTemplate(templateURI)).andReturn(template);
expect(
client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name",
new InstantiateVAppTemplateOptions().productProperty("password", "password"))).andReturn(vApp);
Task task = createMock(Task.class);
URI vappLocation = URI.create("vapp");
URI taskLocation = URI.create("task");
expect(vApp.getHref()).andReturn(vappLocation).atLeastOnce();
expect(vApp.getName()).andReturn("name").atLeastOnce();
expect(client.deployVApp(vappLocation)).andReturn(task);
expect(task.getHref()).andReturn(taskLocation).atLeastOnce();
Predicate<URI> successTester = createMock(Predicate.class);
expect(successTester.apply(taskLocation)).andReturn(true).atLeastOnce();
expect(client.powerOnVApp(vappLocation)).andReturn(task);
Predicate<VApp> notFoundTester = createMock(Predicate.class);
Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus = createMock(Map.class);
TerremarkVCloudComputeClient computeClient = new TerremarkVCloudComputeClient(client,
new Provider<String>() {
@Override
public String get() {
return "password";
}
}, successTester, vAppStatusToNodeStatus, credentialStore, supplier);
replay(vdc);
replay(template);
replay(vApp);
replay(task);
replay(client);
replay(successTester);
replay(notFoundTester);
replay(vAppStatusToNodeStatus);
NodeAndInitialCredentials<VApp> response = computeClient.startAndReturnCredentials(vdcURI, templateURI, "name", new InstantiateVAppTemplateOptions());
assertEquals(response.getNodeId(), "vapp");
assertEquals(response.getNode(),vApp);
assertEquals(response.getCredentials(), LoginCredentials.builder().password("password").build());