PageRenderTime 64ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VMHandlerTest.java

https://github.com/mattiasholmqvist/jclouds
Java | 150 lines | 115 code | 12 blank | 23 comment | 0 complexity | 194d30cb5ad656f5c81283e1ef9d6c95 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.savvis.vpdc.xml;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import org.jclouds.cim.ResourceAllocationSettingData;
  24. import org.jclouds.cim.VirtualSystemSettingData;
  25. import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
  26. import org.jclouds.http.functions.ParseSax;
  27. import org.jclouds.http.functions.ParseSax.Factory;
  28. import org.jclouds.http.functions.config.SaxParserModule;
  29. import org.jclouds.ovf.OperatingSystemSection;
  30. import org.jclouds.ovf.ProductSection;
  31. import org.jclouds.ovf.Property;
  32. import org.jclouds.ovf.VirtualHardwareSection;
  33. import org.jclouds.savvis.vpdc.domain.NetworkConfigSection;
  34. import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection;
  35. import org.jclouds.savvis.vpdc.domain.VM;
  36. import org.testng.annotations.Test;
  37. import com.google.inject.Guice;
  38. import com.google.inject.Injector;
  39. /**
  40. * Tests behavior of {@code VMHandler}
  41. *
  42. * @author Adrian Cole
  43. */
  44. @Test(groups = "unit")
  45. public class VMHandlerTest {
  46. public void testVCloud1_0() {
  47. InputStream is = getClass().getResourceAsStream("/vm.xml");
  48. Injector injector = Guice.createInjector(new SaxParserModule());
  49. Factory factory = injector.getInstance(ParseSax.Factory.class);
  50. VM result = factory.create(injector.getInstance(VMHandler.class)).parse(is);
  51. VM expected = VM
  52. .builder()
  53. .id("1001")
  54. .status(VM.Status.ON)
  55. .name("znHost2")
  56. .type("application/vnd.vmware.vcloud.vApp+xml")
  57. .href(
  58. URI
  59. .create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001"))
  60. .networkConfigSection(
  61. NetworkConfigSection.builder().network("VM Tier01").gateway("0.0.0.0").netmask("0.0.0.0").info(
  62. "MAC=00:00:00:00:00:00").fenceMode("allowInOut").dhcp(true).internalToExternalNATRule(
  63. "10.76.2.4", "206.24.124.1").build())
  64. .networkConnectionSection(
  65. NetworkConnectionSection.builder().network("VM Tier01").info(
  66. "Read only description of a network connection to a deployed vApp").ipAddress(
  67. "10.76.0.5").build())
  68. .operatingSystemSection(
  69. OperatingSystemSection.builder().id(80).info("Specifies the operating system installed")
  70. .description("Red Hat Enterprise Linux 5.x 64bit").build())
  71. .productSection(
  72. ProductSection
  73. .builder()
  74. .info("vCenter Information")
  75. .property(
  76. Property.builder().value("false").key("vmwareToolsEnabled").label(
  77. "VMWare Tools Enabled status").description(
  78. "VMWare Tools Enabled status").build())
  79. .property(
  80. Property.builder().value("10.12.46.171").key("vmwareESXHost").label(
  81. "VMWare ESXHost Ipaddress").description("VMWare ESXHost Ipaddress")
  82. .build())
  83. .property(
  84. Property.builder().value("cussl01s01c01alun088bal,cussl01s01c01alun089bal")
  85. .key("datastores").label("Datastore Name").description(
  86. "Datastore Name").build())
  87. .property(
  88. Property
  89. .builder()
  90. .value("[Totalcapacity=1335915184128,UsedCapacity=549755813888]")
  91. .key("cussl01s01c01alun088bal")
  92. .label("Datastore Capacity")
  93. .description(
  94. "Datastore cussl01s01c01alun088bal Total Capacity, Used Capacity in comma separated")
  95. .build())
  96. .property(
  97. Property
  98. .builder()
  99. .value("[Totalcapacity=1335915184129,UsedCapacity=549755813889]")
  100. .key("cussl01s01c01alun089bal")
  101. .label("Datastore Capacity")
  102. .description(
  103. "Datastore cussl01s01c01alun089bal Total Capacity, Used Capacity in comma separated")
  104. .build()).property(
  105. Property.builder().value(
  106. "[name=3282176-1949-bal-tier01,ip=0.0.0.0,mac=00:50:56:8c:3f:3c]")
  107. .key("customerPortprofile").label("customerPortprofile")
  108. .description("customerPortprofile").build()).property(
  109. Property.builder().value(
  110. "[name=vm-server-mgmt,ip=0.0.0.0,mac=00:50:56:8c:39:75]").key(
  111. "savvisPortprofile").label("savvisPortprofile").description(
  112. "savvisPortprofile").build()).build()).virtualHardwareSection(
  113. VirtualHardwareSection.builder().info("UUID=52254cd2-d848-4e7d-b8f3-3d257fed7666").system(
  114. VirtualSystemSettingData.builder().description("Virtual Hardware Family").elementName(
  115. "znHost2").instanceID("1").virtualSystemIdentifier("znHost2").build()).item(
  116. ResourceAllocationSettingData.builder().allocationUnits("3 GHz").description(
  117. "Number of Virtual CPUs").elementName("1 CPU").instanceID("2").resourceType(
  118. ResourceType.PROCESSOR).virtualQuantity(1l).build()).item(
  119. ResourceAllocationSettingData.builder().allocationUnits("Gigabytes").description(
  120. "Memory Size").elementName("Memory").instanceID("3").resourceType(
  121. ResourceType.MEMORY).virtualQuantity(2l).build()).item(
  122. ResourceAllocationSettingData.builder().connection("VM Tier01").elementName("Network")
  123. .instanceID("4").resourceType(ResourceType.ETHERNET_ADAPTER).virtualQuantity(
  124. 1l).build()).item(
  125. ResourceAllocationSettingData.builder().allocationUnits("Gigabytes")
  126. .caption("1234567").description("Hard Disk").elementName("C:\\")
  127. .hostResource("boot").instanceID("5").resourceType(
  128. ResourceType.BASE_PARTITIONABLE_UNIT).virtualQuantity(25l).build())
  129. .item(
  130. ResourceAllocationSettingData.builder().allocationUnits("Gigabytes").caption(
  131. "1234568").description("Hard Disk").elementName("D:\\")
  132. .hostResource("data").instanceID("6").resourceType(
  133. ResourceType.PARTITIONABLE_UNIT).virtualQuantity(50l)
  134. .build()).build())
  135. .build();
  136. assertEquals(result, expected);
  137. }
  138. }