public void testDefault() throws Exception { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml")); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Builder<String, Object> map = ImmutableMap.builder(); map.put("name", "my-vapp"); map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"); assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected); } }
public void testDefault() throws Exception { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Map<String, Object> map = Maps.newHashMap(); map.put("newName", "my-vapp"); map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); } }
public void testSaveStateTrue() throws IOException { String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>"; GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindUndeployVAppParamsToXmlPayload binder = injector.getInstance(BindUndeployVAppParamsToXmlPayload.class); Map<String, Object> map = Maps.newHashMap(); map.put("saveState", "true"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); }
public void testPowerOnTrue() throws IOException { String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>"; GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindDeployVAppParamsToXmlPayload binder = injector.getInstance(BindDeployVAppParamsToXmlPayload.class); Map<String, Object> map = Maps.newHashMap(); map.put("powerOn", "true"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); }
public void testDefault() throws IOException { String expected = toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate-default.xml")); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindCloneVAppTemplateParamsToXmlPayload binder = injector .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class); Builder<String, Object> map = ImmutableMap.builder(); map.put("name", "my-vapptemplate"); map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181"); assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected); } }
public void testDefault() throws IOException { String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>"; GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindUndeployVAppParamsToXmlPayload binder = injector.getInstance(BindUndeployVAppParamsToXmlPayload.class); Map<String, Object> map = Maps.newHashMap(); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); } }
public void testDefault() throws IOException { String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>"; GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindDeployVAppParamsToXmlPayload binder = injector.getInstance(BindDeployVAppParamsToXmlPayload.class); Map<String, Object> map = Maps.newHashMap(); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); } }
public void testDefault() throws IOException { String expected = "name newdrive"; GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); Map<String, Object> map = ImmutableMap.<String, Object> of("name", "newdrive"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); }
public void testWithDescription() throws IOException { String expected = toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate.xml")); CloneVAppTemplateOptions options = new CloneVAppTemplateOptions() .description("The description of the new vAppTemplate"); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(options)); BindCloneVAppTemplateParamsToXmlPayload binder = injector .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class); Builder<String, Object> map = ImmutableMap.builder(); map.put("name", "new-linux-server"); map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201"); assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected); }
public void testDefault() throws IOException { String expected = "<CatalogItem xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" name=\"myname\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd\"><Description>mydescription</Description><Entity href=\"http://fooentity\"/><Property key=\"foo\">bar</Property></CatalogItem>"; CatalogItemOptions options = CatalogItemOptions.Builder.description("mydescription").properties( ImmutableMap.of("foo", "bar")); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(options)); BindCatalogItemToXmlPayload binder = injector.getInstance(BindCatalogItemToXmlPayload.class); Map<String, Object> map = ImmutableMap.<String, Object> of("name", "myname", "Entity", "http://fooentity"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); } }
@Test public void testBuildOneClassForm() throws SecurityException, NoSuchMethodException { Invokable<?, ?> method = method(TestClassForm.class, "oneForm", String.class); Object form = processor.apply(Invocation.create(method, ImmutableList.<Object> of("robot"))) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot"); }
@Test public void testBuildOneForm() throws SecurityException, NoSuchMethodException { Invokable<?, ?> method = method(TestFormReplace.class, "oneForm", String.class); Object form = processor.apply(Invocation.create(method, ImmutableList.<Object> of("robot"))) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot"); }
@Test public void testBuildTwoForm() throws SecurityException, NoSuchMethodException { Invokable<?, ?> method = method(TestFormReplace.class, "twoForm", String.class); Object form = processor.apply(Invocation.create(method, ImmutableList.<Object> of("robot"))) .getPayload().getRawContent(); assertEquals(form, "slash=/robot&hyphen=-robot"); }
@Test public void testBuildTwoForms() throws SecurityException, NoSuchMethodException { Invokable<?, ?> method = method(TestFormReplace.class, "twoForms", String.class, String.class); Object form = processor.apply(Invocation.create(method, ImmutableList.<Object> of("robot", "eggs"))) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot/eggs"); }
public void testWithDescriptionDeployOnSourceDelete() throws Exception { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVApp.xml")); CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description( "The description of the new vApp"); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(options)); BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Builder<String, Object> map = ImmutableMap.builder(); map.put("name", "new-linux-server"); map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201"); map.put("IsSourceDelete", "true"); assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected); }
@Test public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException { Invokable<?, ?> method = method(TestFormReplace.class, "twoFormsOutOfOrder", String.class, String.class); Object form = processor.apply(Invocation.create(method, ImmutableList.<Object> of("robot", "eggs"))) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/eggs/robot"); }
public void testWithDescriptionDeployOn() throws Exception { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml")); CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description( "The description of the new vApp"); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(options)); BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Builder<String, Object> map = ImmutableMap.builder(); map.put("name", "new-linux-server"); map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201"); assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected); }
public void testWithDescriptionDeployOn() throws Exception { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")); CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().withDescription( "The description of the new vApp"); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(options)); BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Map<String, Object> map = Maps.newHashMap(); map.put("newName", "new-linux-server"); map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); }
public void testWithSize() throws IOException { String expected = "name newdrive\nsize 1024"; GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(new CloneDriveOptions().size(1024))); Map<String, Object> map = ImmutableMap.<String, Object> of("name", "newdrive"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); }
@Test public void testDecodes() throws SecurityException, NoSuchMethodException { Invokable<?, Object> testPayload = method(TestPayload.class, "changeAdminPass", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList.<Object> of("foo"))) .method("POST").endpoint("http://localhost").build(); GeneratedHttpRequest newRequest = binder() .bindToRequest(request, ImmutableMap.<String,Object>of("adminPass", "foo")); assertEquals(newRequest.getRequestLine(), request.getRequestLine()); assertEquals(newRequest.getPayload().getRawContent(), "{\"changePassword\":{\"adminPass\":\"foo\"}}"); }