public void testAllOptions() throws IOException { String expected = Strings2.toStringAndClose( getClass().getResourceAsStream("/InstantiateVAppTemplateParams-options-test.xml")); Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap.<String, String>create()); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getArgs()) .andReturn( ImmutableList.<Object>of( InstantiateVAppTemplateOptions.Builder.processorCount(2) .memory(512) .inGroup("group") .withPassword("password") .inRow("row") .addNetworkConfig(new NetworkConfig(URI.create("http://network"))))) .atLeastOnce(); expect(request.getFirstHeaderOrNull("Content-Type")) .andReturn("application/unknown") .atLeastOnce(); expect(request.getHeaders()).andReturn(headers).atLeastOnce(); request.setPayload(expected); replay(request); BindInstantiateVAppTemplateParamsToXmlPayload binder = injector.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); Map<String, String> map = Maps.newHashMap(); map.put("name", "name"); map.put("template", "https://vcloud/vAppTemplate/3"); binder.bindToRequest(request, map); }
public void testDefault() throws IOException { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getArgs()).andReturn(ImmutableList.<Object>of()).atLeastOnce(); request.setPayload(expected); replay(request); BindCloneVCloudExpressVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVCloudExpressVAppParamsToXmlPayload.class); Map<String, String> map = Maps.newHashMap(); map.put("newName", "my-vapp"); map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"); binder.bindToRequest(request, map); verify(request); }
public void testWithDescriptionDeployOn() throws IOException { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")); CloneVAppOptions options = new CloneVAppOptions() .deploy() .powerOn() .withDescription("The description of the new vApp"); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getArgs()).andReturn(ImmutableList.<Object>of(options)).atLeastOnce(); request.setPayload(expected); replay(request); BindCloneVCloudExpressVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVCloudExpressVAppParamsToXmlPayload.class); Map<String, String> map = Maps.newHashMap(); map.put("newName", "new-linux-server"); map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201"); binder.bindToRequest(request, map); verify(request); }