PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java

https://github.com/regularfry/jclouds
Java | 151 lines | 114 code | 13 blank | 24 comment | 0 complexity | 6dae6b76e320c87f8c34e58de2164597 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.xml;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import org.jclouds.date.DateService;
  24. import org.jclouds.http.functions.ParseSax;
  25. import org.jclouds.http.functions.ParseSax.Factory;
  26. import org.jclouds.http.functions.config.SaxParserModule;
  27. import org.jclouds.ovf.Network;
  28. import org.jclouds.vcloud.VCloudMediaType;
  29. import org.jclouds.vcloud.domain.GuestCustomizationSection;
  30. import org.jclouds.vcloud.domain.Status;
  31. import org.jclouds.vcloud.domain.TaskStatus;
  32. import org.jclouds.vcloud.domain.VAppTemplate;
  33. import org.jclouds.vcloud.domain.Vm;
  34. import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
  35. import org.jclouds.vcloud.domain.internal.TaskImpl;
  36. import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
  37. import org.testng.annotations.Test;
  38. import com.google.common.collect.ImmutableList;
  39. import com.google.common.collect.ImmutableSet;
  40. import com.google.common.collect.Iterables;
  41. import com.google.inject.Guice;
  42. import com.google.inject.Injector;
  43. /**
  44. * Tests behavior of {@code VAppTemplateHandler}
  45. *
  46. * @author Adrian Cole
  47. */
  48. @Test(groups = "unit")
  49. public class VAppTemplateHandlerTest {
  50. public void testUbuntuTemplate() {
  51. InputStream is = getClass().getResourceAsStream("/vAppTemplate.xml");
  52. Injector injector = Guice.createInjector(new SaxParserModule());
  53. Factory factory = injector.getInstance(ParseSax.Factory.class);
  54. VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(is);
  55. assertEquals(result.getName(), "Ubuntu Template");
  56. assertEquals(result.getHref(), URI
  57. .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921"));
  58. assertEquals(result.getType(), "application/vnd.vmware.vcloud.vAppTemplate+xml");
  59. assertEquals(result.getStatus(), Status.OFF);
  60. assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudMediaType.VDC_XML, URI
  61. .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439")));
  62. assertEquals(result.getDescription(), null);
  63. assertEquals(result.getTasks(), ImmutableList.of());
  64. assertEquals(result.getVAppScopedLocalId(), null);
  65. assert result.isOvfDescriptorUploaded();
  66. Vm vm = Iterables.getOnlyElement(result.getChildren());
  67. assertEquals(vm.getName(), "Ubuntu1004");
  68. assertEquals(vm.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vm-172837194"));
  69. // NOTE this is vAppTemplate not VM!
  70. assertEquals(vm.getType(), "application/vnd.vmware.vcloud.vAppTemplate+xml");
  71. assertEquals(vm.getStatus(), null);
  72. assertEquals(vm.getParent(), new ReferenceTypeImpl(null, VCloudMediaType.VAPPTEMPLATE_XML, URI
  73. .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921")));
  74. assertEquals(vm.getDescription(), null);
  75. assertEquals(vm.getTasks(), ImmutableList.of());
  76. assertEquals(vm.getVAppScopedLocalId(), "02_ubuntu_template");
  77. GuestCustomizationSection guestC = vm.getGuestCustomizationSection();
  78. assertEquals(guestC.getType(), VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML);
  79. assertEquals(
  80. guestC.getHref(),
  81. URI
  82. .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vm-172837194/guestCustomizationSection/"));
  83. assertEquals(guestC.getInfo(), "Specifies Guest OS Customization Settings");
  84. assertEquals(guestC.isEnabled(), new Boolean(true));
  85. assertEquals(guestC.shouldChangeSid(), new Boolean(false));
  86. assertEquals(guestC.getVirtualMachineId(), "172837194");
  87. assertEquals(guestC.isJoinDomainEnabled(), new Boolean(false));
  88. assertEquals(guestC.useOrgSettings(), new Boolean(false));
  89. assertEquals(guestC.getDomainName(), null);
  90. assertEquals(guestC.getDomainUserName(), null);
  91. assertEquals(guestC.getDomainUserPassword(), null);
  92. assertEquals(guestC.isAdminPasswordEnabled(), new Boolean(true));
  93. assertEquals(guestC.isAdminPasswordAuto(), new Boolean(true));
  94. assertEquals(guestC.getAdminPassword(), "%3eD%gmF");
  95. assertEquals(guestC.isResetPasswordRequired(), new Boolean(false));
  96. assertEquals(
  97. guestC.getCustomizationScript(),
  98. "#!/bin/bash if [ \"$1\" = \"postcustomization\" ]; then echo \"post customization\" touch /root/.postcustomization sleep 30 #regenerate keys /bin/rm /etc/ssh/ssh_host_* /usr/sbin/dpkg-reconfigure openssh-server echo \"completed\" fi");
  99. assertEquals(guestC.getComputerName(), "Ubuntu1004");
  100. assertEquals(guestC.getEdit(), null);
  101. VCloudNetworkSection network = result.getNetworkSection();
  102. assertEquals(
  103. network.getHref(),
  104. URI
  105. .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921/networkSection/"));
  106. assertEquals(network.getType(), VCloudMediaType.NETWORKSECTION_XML);
  107. assertEquals(network.getInfo(), "The list of logical networks");
  108. assertEquals(network.getNetworks(), ImmutableSet.of(new Network("vAppNet-vApp Internal", null)));
  109. }
  110. public void testCopyingTemplate() {
  111. InputStream is = getClass().getResourceAsStream("/vAppTemplate-copying.xml");
  112. Injector injector = Guice.createInjector(new SaxParserModule());
  113. Factory factory = injector.getInstance(ParseSax.Factory.class);
  114. DateService dateService = injector.getInstance(DateService.class);
  115. VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(is);
  116. assertEquals(result.getName(), "Ubuntu10.04_v2");
  117. assertEquals(result.getHref(), URI
  118. .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-699683881"));
  119. assertEquals(result.getType(), "application/vnd.vmware.vcloud.vAppTemplate+xml");
  120. assertEquals(result.getStatus(), Status.UNRESOLVED);
  121. assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudMediaType.VDC_XML, URI
  122. .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/105186609")));
  123. assertEquals(result.getDescription(), null);
  124. assertEquals(result.getTasks(), ImmutableList.of(new TaskImpl(URI
  125. .create("https://vcenterprise.bluelock.com/api/v1.0/task/q62gxhi32xgd9yrqvr"),
  126. "Copying Virtual Application Template Ubuntu10.04_v2(699683881)", TaskStatus.RUNNING, dateService
  127. .iso8601DateParse("2010-09-17T23:20:46.039-04:00"), dateService
  128. .iso8601DateParse("9999-12-31T23:59:59.999-05:00"), dateService
  129. .iso8601DateParse("2010-12-16T23:20:46.039-05:00"), new ReferenceTypeImpl("Ubuntu10.04_v2",
  130. "application/vnd.vmware.vcloud.vAppTemplate+xml",
  131. URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-699683881")),
  132. null)));
  133. assertEquals(result.getVAppScopedLocalId(), null);
  134. assert result.isOvfDescriptorUploaded();
  135. assertEquals(result.getChildren(), ImmutableList.of());
  136. assertEquals(result.getNetworkSection(), null);
  137. }
  138. }