PageRenderTime 670ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/xml/ovf/VAppHandlerTest.java

https://github.com/raschyoung/jclouds
Java | 184 lines | 131 code | 29 blank | 24 comment | 0 complexity | 7feb3cefbb0a26cced7a7783acaa8bbc MD5 | raw file
  1. /**
  2. *
  3. * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
  4. *
  5. * ====================================================================
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * 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, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.jclouds.trmk.vcloud_0_8.xml.ovf;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import java.net.UnknownHostException;
  24. import java.util.Properties;
  25. import java.util.Set;
  26. import org.jclouds.Constants;
  27. import org.jclouds.cim.ResourceAllocationSettingData;
  28. import org.jclouds.cim.VirtualSystemSettingData;
  29. import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
  30. import org.jclouds.http.functions.BaseHandlerTest;
  31. import org.jclouds.http.functions.ParseSax;
  32. import org.jclouds.http.functions.config.SaxParserModule;
  33. import org.jclouds.trmk.vcloud_0_8.domain.Status;
  34. import org.jclouds.trmk.vcloud_0_8.domain.VApp;
  35. import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
  36. import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl;
  37. import org.jclouds.trmk.vcloud_0_8.xml.VAppHandler;
  38. import org.testng.annotations.BeforeTest;
  39. import org.testng.annotations.Test;
  40. import com.google.common.collect.ImmutableListMultimap;
  41. import com.google.common.collect.ImmutableSet;
  42. import com.google.common.collect.ListMultimap;
  43. import com.google.inject.AbstractModule;
  44. import com.google.inject.Guice;
  45. import com.google.inject.name.Names;
  46. /**
  47. * Tests behavior of {@code VCloudExpressVAppHandler}
  48. *
  49. * @author Adrian Cole
  50. */
  51. // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
  52. @Test(groups = "unit", testName = "VCloudExpressVAppHandlerTest")
  53. public class VAppHandlerTest extends BaseHandlerTest {
  54. @BeforeTest
  55. @Override
  56. protected void setUpInjector() {
  57. injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
  58. @Override
  59. protected void configure() {
  60. Properties toBind = new Properties();
  61. toBind.setProperty(Constants.PROPERTY_API_VERSION, "0.8");
  62. Names.bindProperties(binder(), toBind);
  63. }
  64. });
  65. factory = injector.getInstance(ParseSax.Factory.class);
  66. }
  67. public void testInstantiated() throws UnknownHostException {
  68. InputStream is = getClass().getResourceAsStream("/instantiatedvapp.xml");
  69. VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
  70. VApp expects = new VAppImpl("centos53", URI
  71. .create("http://10.150.4.49/api/v0.8/vApp/10"), Status.RESOLVED, 123456789l, new ReferenceTypeImpl(null,
  72. "application/vnd.vmware.vcloud.vdc+xml", URI.create("http://10.150.4.49/api/v0.8/vdc/4")),
  73. ImmutableListMultimap.<String, String> of(), null, null, null, ImmutableSet
  74. .<ResourceAllocationSettingData> of());
  75. assertEquals(result, expects);
  76. }
  77. public void testDefault() throws UnknownHostException {
  78. InputStream is = getClass().getResourceAsStream("/vapp.xml");
  79. VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
  80. ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network",
  81. "10.150.4.93");
  82. VirtualSystemSettingData system = VirtualSystemSettingData.builder().instanceID("0").elementName(
  83. "Virtual Hardware Family").virtualSystemIdentifier("centos53").virtualSystemType("vmx-07").build();
  84. Set<ResourceAllocationSettingData> resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> of(
  85. ResourceAllocationSettingData.builder().instanceID("1").elementName("1 virtual CPU(s)").description(
  86. "Number of Virtual CPUs").resourceType(ResourceType.PROCESSOR).virtualQuantity(1l)
  87. .allocationUnits("hertz * 10^6").virtualQuantityUnits("count").build(),
  88. ResourceAllocationSettingData.builder().instanceID("2").elementName("16MB of memory").description(
  89. "Memory Size").resourceType(ResourceType.MEMORY).virtualQuantity(16l).allocationUnits(
  90. "byte * 2^20").virtualQuantityUnits("byte * 2^20").build(),
  91. ResourceAllocationSettingData.builder().instanceID("3").elementName("SCSI Controller 0").description(
  92. "SCSI Controller").resourceType(ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic")
  93. .address("0").build(),
  94. ResourceAllocationSettingData.builder().instanceID("8").elementName("Network Adapter 1").description(
  95. "PCNet32 ethernet adapter on \"Internal\" network").resourceType(ResourceType.ETHERNET_ADAPTER)
  96. .resourceSubType("PCNet32").addressOnParent("7").connection("Internal").automaticAllocation(
  97. true).build(),
  98. ResourceAllocationSettingData.builder().instanceID("9").elementName("Hard Disk 1").resourceType(
  99. ResourceType.DISK_DRIVE).hostResource("104857").addressOnParent("0").parent("3")
  100. .virtualQuantity(104857l).build());
  101. VApp expects = new VAppImpl("centos53", URI
  102. .create("http://10.150.4.49/api/v0.8/vApp/10"), Status.ON, new Long(104857), new ReferenceTypeImpl(null,
  103. "application/vnd.vmware.vcloud.vdc+xml", URI.create("http://10.150.4.49/api/v0.8/vdc/4")),
  104. networkToAddresses, null, "Other Linux (32-bit)", system, resourceAllocations);
  105. assertEquals(result.getHref(), expects.getHref());
  106. assertEquals(result.getName(), expects.getName());
  107. assertEquals(result.getNetworkToAddresses(), expects.getNetworkToAddresses());
  108. assertEquals(result.getOperatingSystemDescription(), expects.getOperatingSystemDescription());
  109. assertEquals(result.getResourceAllocations().toString(), expects.getResourceAllocations().toString());
  110. assertEquals(result.getSize(), expects.getSize());
  111. assertEquals(result.getStatus(), expects.getStatus());
  112. assertEquals(result.getSystem().toString(), expects.getSystem().toString());
  113. assertEquals(result.getType(), expects.getType());
  114. assertEquals(result.getVDC(), expects.getVDC());
  115. }
  116. public void testLatest() throws UnknownHostException {
  117. InputStream is = getClass().getResourceAsStream("/vapp2.xml");
  118. VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
  119. ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network",
  120. "10.23.119.221");
  121. VirtualSystemSettingData system = VirtualSystemSettingData.builder().instanceID("0").elementName(
  122. "Virtual Hardware Family").virtualSystemIdentifier("m1").virtualSystemType("vmx-07").build();
  123. Set<ResourceAllocationSettingData> resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> of(
  124. ResourceAllocationSettingData.builder().instanceID("1").elementName("1 virtual CPU(s)").description(
  125. "Number of Virtual CPUs").resourceType(ResourceType.PROCESSOR).virtualQuantity(1l)
  126. .allocationUnits("hertz * 10^6").virtualQuantityUnits("count").build(),
  127. ResourceAllocationSettingData.builder().instanceID("2").elementName("512MB of memory").description(
  128. "Memory Size").resourceType(ResourceType.MEMORY).virtualQuantity(512l).allocationUnits(
  129. "byte * 2^20").virtualQuantityUnits("byte * 2^20").build(),
  130. ResourceAllocationSettingData.builder().instanceID("3").elementName("SCSI Controller 0").description(
  131. "SCSI Controller").resourceType(ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic")
  132. .address("0").build(),
  133. ResourceAllocationSettingData.builder().instanceID("8").elementName("Network Adapter 1").description(
  134. "PCNet32 ethernet adapter on \"Internal\" network").resourceType(ResourceType.ETHERNET_ADAPTER)
  135. .resourceSubType("PCNet32").addressOnParent("7").connection("Internal").automaticAllocation(
  136. true).build(),
  137. ResourceAllocationSettingData.builder().instanceID("9").elementName("Hard Disk 1").resourceType(
  138. ResourceType.DISK_DRIVE).hostResource("10485760").addressOnParent("0").parent("3")
  139. .virtualQuantity(10485760l).build());
  140. VApp expects = new VAppImpl("m1", URI.create("http://localhost:8000/api/v0.8/vApp/80"),
  141. Status.ON, new Long(10485760), new ReferenceTypeImpl(null, "application/vnd.vmware.vcloud.vdc+xml", URI
  142. .create("http://localhost:8000/api/v0.8/vdc/28")), networkToAddresses, null,
  143. "Microsoft Windows XP Professional (32-bit)", system, resourceAllocations);
  144. assertEquals(result.getHref(), expects.getHref());
  145. assertEquals(result.getName(), expects.getName());
  146. assertEquals(result.getNetworkToAddresses(), expects.getNetworkToAddresses());
  147. assertEquals(result.getOperatingSystemDescription(), expects.getOperatingSystemDescription());
  148. assertEquals(result.getResourceAllocations().toString(), expects.getResourceAllocations().toString());
  149. assertEquals(result.getSize(), expects.getSize());
  150. assertEquals(result.getStatus(), expects.getStatus());
  151. assertEquals(result.getSystem().toString(), expects.getSystem().toString());
  152. assertEquals(result.getType(), expects.getType());
  153. assertEquals(result.getVDC(), expects.getVDC());
  154. }
  155. }