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 testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudExpressAsyncClient.class.getMethod( "instantiateVAppTemplateInVDC", URI.class, URI.class, String.class, InstantiateVAppTemplateOptions[].class); HttpRequest request = processor.createRequest( method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"), "name", InstantiateVAppTemplateOptions.Builder.processorCount(2) .memory(512) .inGroup("group") .withPassword("password") .inRow("row") .addNetworkConfig(new NetworkConfig(URI.create("http://network")))); assertRequestLineEquals( request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertPayloadEquals( request, Strings2.toStringAndClose( getClass().getResourceAsStream("/InstantiateVAppTemplateParams-options-test.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); assertExceptionParserClassEquals(method, null); checkFilters(request); }