PageRenderTime 90ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/andreisavu/jclouds
Java | 123 lines | 82 code | 18 blank | 23 comment | 0 complexity | 019670d8717b64dba8c8254648647635 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.createMock;
  21. import static org.easymock.EasyMock.expect;
  22. import static org.easymock.EasyMock.replay;
  23. import static org.easymock.EasyMock.verify;
  24. import java.io.IOException;
  25. import java.net.URI;
  26. import java.util.Properties;
  27. import org.jclouds.rest.internal.GeneratedHttpRequest;
  28. import org.jclouds.util.Strings2;
  29. import org.jclouds.vcloud.VCloudApiMetadata;
  30. import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
  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 BindCloneVAppTemplateParamsToXmlPayload}
  41. *
  42. * @author Adrian Cole
  43. */
  44. @Test(groups = "unit")
  45. public class BindCloneVAppTemplateParamsToXmlPayloadTest {
  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 VCloudApiMetadata().getDefaultProperties());
  53. }
  54. });
  55. public void testWithDescription() throws IOException {
  56. String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate.xml"));
  57. CloneVAppTemplateOptions options = new CloneVAppTemplateOptions()
  58. .description("The description of the new vAppTemplate");
  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. BindCloneVAppTemplateParamsToXmlPayload binder = injector
  65. .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
  66. Builder<String, Object> map = ImmutableMap.builder();
  67. map.put("name", "new-linux-server");
  68. map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
  69. binder.bindToRequest(request, map.build());
  70. verify(request);
  71. }
  72. public void testWithDescriptionSourceDelete() throws IOException {
  73. String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVAppTemplate.xml"));
  74. CloneVAppTemplateOptions options = new CloneVAppTemplateOptions()
  75. .description("The description of the new vAppTemplate");
  76. GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
  77. expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
  78. expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
  79. request.setPayload(expected);
  80. replay(request);
  81. BindCloneVAppTemplateParamsToXmlPayload binder = injector
  82. .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
  83. Builder<String, Object> map = ImmutableMap.builder();
  84. map.put("name", "new-linux-server");
  85. map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
  86. map.put("IsSourceDelete", "true");
  87. binder.bindToRequest(request, map.build());
  88. verify(request);
  89. }
  90. public void testDefault() throws IOException {
  91. String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate-default.xml"));
  92. GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
  93. expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
  94. expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
  95. request.setPayload(expected);
  96. replay(request);
  97. BindCloneVAppTemplateParamsToXmlPayload binder = injector
  98. .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
  99. Builder<String, Object> map = ImmutableMap.builder();
  100. map.put("name", "my-vapptemplate");
  101. map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181");
  102. binder.bindToRequest(request, map.build());
  103. verify(request);
  104. }
  105. }