PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayloadTest.java

https://github.com/regularfry/jclouds
Java | 120 lines | 79 code | 18 blank | 23 comment | 0 complexity | 93a77d17a5186b49c967ff2a476eb517 MD5 | raw file
  1. /**
  2. * Licensed to jclouds, Inc. (jclouds) under one or more
  3. * contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. jclouds licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.jclouds.vcloud.binders;
  20. import static org.easymock.EasyMock.expect;
  21. import static org.easymock.classextension.EasyMock.createMock;
  22. import static org.easymock.classextension.EasyMock.replay;
  23. import static org.easymock.classextension.EasyMock.verify;
  24. import java.io.IOException;
  25. import java.net.URI;
  26. import java.util.Properties;
  27. import org.jclouds.PropertiesBuilder;
  28. import org.jclouds.rest.internal.GeneratedHttpRequest;
  29. import org.jclouds.util.Strings2;
  30. import org.jclouds.vcloud.options.CloneVAppOptions;
  31. import org.testng.annotations.Test;
  32. import com.google.common.collect.ImmutableList;
  33. import com.google.common.collect.ImmutableMap;
  34. import com.google.common.collect.ImmutableMap.Builder;
  35. import com.google.inject.AbstractModule;
  36. import com.google.inject.Guice;
  37. import com.google.inject.Injector;
  38. import com.google.inject.name.Names;
  39. /**
  40. * Tests behavior of {@code BindCloneVAppParamsToXmlPayload}
  41. *
  42. * @author Adrian Cole
  43. */
  44. @Test(groups = "unit")
  45. public class BindCloneVAppParamsToXmlPayloadTest {
  46. Injector injector = Guice.createInjector(new AbstractModule() {
  47. @Override
  48. protected void configure() {
  49. Properties props = new Properties();
  50. props.setProperty("jclouds.vcloud.xml.ns", "http://www.vmware.com/vcloud/v1");
  51. props.setProperty("jclouds.vcloud.xml.schema", "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
  52. Names.bindProperties(binder(), new PropertiesBuilder(props).build());
  53. }
  54. });
  55. public void testWithDescriptionDeployOn() throws IOException {
  56. String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml"));
  57. CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
  58. "The description of the new vApp");
  59. GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
  60. expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
  61. expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
  62. request.setPayload(expected);
  63. replay(request);
  64. BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
  65. Builder<String, String> map = ImmutableMap.<String, String> builder();
  66. map.put("name", "new-linux-server");
  67. map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
  68. binder.bindToRequest(request, map.build());
  69. verify(request);
  70. }
  71. public void testWithDescriptionDeployOnSourceDelete() throws IOException {
  72. String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVApp.xml"));
  73. CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
  74. "The description of the new vApp");
  75. GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
  76. expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
  77. expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
  78. request.setPayload(expected);
  79. replay(request);
  80. BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
  81. Builder<String, String> map = ImmutableMap.<String, String> builder();
  82. map.put("name", "new-linux-server");
  83. map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
  84. map.put("IsSourceDelete", "true");
  85. binder.bindToRequest(request, map.build());
  86. verify(request);
  87. }
  88. public void testDefault() throws IOException {
  89. String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml"));
  90. GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
  91. expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
  92. expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
  93. request.setPayload(expected);
  94. replay(request);
  95. BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
  96. Builder<String, String> map = ImmutableMap.<String, String> builder();
  97. map.put("name", "my-vapp");
  98. map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181");
  99. binder.bindToRequest(request, map.build());
  100. verify(request);
  101. }
  102. }