PageRenderTime 576ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java

https://github.com/jraghu/jclouds
Java | 175 lines | 137 code | 15 blank | 23 comment | 0 complexity | 0fc666a31d5db717ff319e6f0cd17989 MD5 | raw file
  1. /**
  2. *
  3. * Copyright (C) 2009 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.vcloud.xml;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import org.jclouds.http.functions.ParseSax;
  24. import org.jclouds.http.functions.ParseSax.Factory;
  25. import org.jclouds.http.functions.config.ParserModule;
  26. import org.jclouds.vcloud.domain.Capacity;
  27. import org.jclouds.vcloud.domain.NamedResource;
  28. import org.jclouds.vcloud.domain.Quota;
  29. import org.jclouds.vcloud.domain.VDC;
  30. import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
  31. import org.jclouds.vcloud.endpoints.VCloudApi;
  32. import org.testng.annotations.Test;
  33. import com.google.common.collect.ImmutableMap;
  34. import com.google.inject.AbstractModule;
  35. import com.google.inject.Guice;
  36. import com.google.inject.Injector;
  37. import com.google.inject.Provides;
  38. /**
  39. * Tests behavior of {@code VDCHandler}
  40. *
  41. * @author Adrian Cole
  42. */
  43. @Test(groups = "unit", testName = "vcloud.VDCHandlerTest")
  44. public class VDCHandlerTest {
  45. public void testApplyInputStream() {
  46. InputStream is = getClass().getResourceAsStream("/vdc.xml");
  47. Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
  48. @Override
  49. protected void configure() {
  50. }
  51. @SuppressWarnings("unused")
  52. @Provides
  53. @VCloudApi
  54. URI provide() {
  55. return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
  56. }
  57. });
  58. Factory factory = injector.getInstance(ParseSax.Factory.class);
  59. VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
  60. assertEquals(result.getName(), "Miami Environment 1");
  61. assertEquals(result.getLocation(), URI
  62. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
  63. assertEquals(result.getDescription(), null);
  64. assertEquals(result.getStorageCapacity(), null);
  65. assertEquals(result.getCpuCapacity(), null);
  66. assertEquals(result.getMemoryCapacity(), null);
  67. assertEquals(result.getInstantiatedVmsQuota(), null);
  68. assertEquals(result.getDeployedVmsQuota(), null);
  69. assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedResource> of());
  70. assertEquals(
  71. result.getAvailableNetworks(),
  72. ImmutableMap
  73. .of(
  74. "10.114.34.128/26",
  75. new NamedResourceImpl(
  76. "1708",
  77. "10.114.34.128/26",
  78. "application/vnd.vmware.vcloud.network+xml",
  79. URI
  80. .create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
  81. }
  82. public void testApplyHosting() {
  83. InputStream is = getClass().getResourceAsStream("/vdc-hosting.xml");
  84. Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
  85. @Override
  86. protected void configure() {
  87. }
  88. @SuppressWarnings("unused")
  89. @Provides
  90. @VCloudApi
  91. URI provide() {
  92. return URI.create("https://vcloud.safesecureweb.com/api/v0.8");
  93. }
  94. });
  95. Factory factory = injector.getInstance(ParseSax.Factory.class);
  96. VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
  97. assertEquals(result.getName(), "vDC Name");
  98. assertEquals(result.getLocation(), URI
  99. .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"));
  100. assertEquals(result.getDescription(), "vDC Name");
  101. assertEquals(result.getStorageCapacity(), new Capacity("bytes * 10^9", 0, 40960));
  102. assertEquals(result.getCpuCapacity(), new Capacity("hz * 10^6", 0, 2400));
  103. assertEquals(result.getMemoryCapacity(), new Capacity("bytes * 10^9", 0, 2));
  104. assertEquals(result.getInstantiatedVmsQuota(), new Quota(0, 2));
  105. assertEquals(result.getDeployedVmsQuota(), new Quota(0, 2));
  106. assertEquals(
  107. result.getResourceEntities(),
  108. new ImmutableMap.Builder<String, NamedResource>()
  109. .put(
  110. "Plesk (Linux) 64-bit Template",
  111. new NamedResourceImpl(
  112. "1",
  113. "Plesk (Linux) 64-bit Template",
  114. "application/vnd.vmware.vcloud.vAppTemplate+xml",
  115. URI
  116. .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/1")))
  117. .put(
  118. "Windows 2008 Datacenter 64 Bit Template",
  119. new NamedResourceImpl(
  120. "2",
  121. "Windows 2008 Datacenter 64 Bit Template",
  122. "application/vnd.vmware.vcloud.vAppTemplate+xml",
  123. URI
  124. .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")))
  125. .put(
  126. "Cent OS 64 Bit Template",
  127. new NamedResourceImpl(
  128. "3",
  129. "Cent OS 64 Bit Template",
  130. "application/vnd.vmware.vcloud.vAppTemplate+xml",
  131. URI
  132. .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3")))
  133. .put(
  134. "cPanel (Linux) 64 Bit Template",
  135. new NamedResourceImpl(
  136. "4",
  137. "cPanel (Linux) 64 Bit Template",
  138. "application/vnd.vmware.vcloud.vAppTemplate+xml",
  139. URI
  140. .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4")))
  141. .put(
  142. "188849-1",
  143. new NamedResourceImpl(
  144. "188849-1",
  145. "188849-1",
  146. "application/vnd.vmware.vcloud.vApp+xml",
  147. URI
  148. .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")))
  149. .put(
  150. "188849-2",
  151. new NamedResourceImpl(
  152. "188849-2",
  153. "188849-2",
  154. "application/vnd.vmware.vcloud.vApp+xml",
  155. URI
  156. .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-2")))
  157. .build());
  158. assertEquals(result.getAvailableNetworks(), ImmutableMap.<String, NamedResource> of());
  159. }
  160. }