PageRenderTime 83ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

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