PageRenderTime 74ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/raschyoung/jclouds
Java | 193 lines | 158 code | 12 blank | 23 comment | 0 complexity | 47be0717d1676bba90a59f2a76ec2ea3 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.savvis.vpdc.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.SaxParserModule;
  26. import org.jclouds.savvis.vpdc.domain.Resource;
  27. import org.jclouds.savvis.vpdc.domain.ResourceImpl;
  28. import org.jclouds.savvis.vpdc.domain.VDC;
  29. import org.jclouds.savvis.vpdc.domain.VDC.Status;
  30. import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
  31. import org.testng.annotations.Test;
  32. import com.google.common.collect.ImmutableSet;
  33. import com.google.inject.Guice;
  34. import com.google.inject.Injector;
  35. /**
  36. * Tests behavior of {@code VDCHandler}
  37. *
  38. * @author Adrian Cole
  39. */
  40. @Test(groups = "unit")
  41. public class VDCHandlerTest {
  42. public void test() {
  43. InputStream is = getClass().getResourceAsStream("/vdc.xml");
  44. Injector injector = Guice.createInjector(new SaxParserModule());
  45. Factory factory = injector.getInstance(ParseSax.Factory.class);
  46. VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
  47. assertEquals(result.getName(), "demo_vpdcname");
  48. assertEquals(result.getDescription(),
  49. "ServiceProfileName = Balanced; ServiceLocation = North America; Email = jim@company.com;");
  50. assertEquals(result.getStatus(), Status.DEPLOYED);
  51. assertEquals(
  52. result.getResourceEntities(),
  53. ImmutableSet
  54. .<Resource> of(
  55. new ResourceImpl(
  56. "1001",
  57. "DemoHost-1",
  58. VCloudMediaType.VAPP_XML,
  59. URI
  60. .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")),
  61. new ResourceImpl(
  62. "1002",
  63. "DemoHost-2",
  64. VCloudMediaType.VAPP_XML,
  65. URI
  66. .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")),
  67. new ResourceImpl(
  68. "1003",
  69. "DemoHost-3",
  70. VCloudMediaType.VAPP_XML,
  71. URI
  72. .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1003")),
  73. new ResourceImpl(
  74. "1234",
  75. "CustomerTemplateName",
  76. VCloudMediaType.VAPPTEMPLATE_XML,
  77. URI
  78. .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vAppTemplate/1234")),
  79. new ResourceImpl(
  80. "FirewallService",
  81. "firewall",
  82. "api.symphonyvpdc.savvis.net+xml",
  83. URI
  84. .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/FirewallService"))));
  85. assertEquals(result.getAvailableNetworks(), ImmutableSet.of());
  86. }
  87. public void test1net() {
  88. InputStream is = getClass().getResourceAsStream("/vdc-1net.xml");
  89. Injector injector = Guice.createInjector(new SaxParserModule());
  90. Factory factory = injector.getInstance(ParseSax.Factory.class);
  91. VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
  92. assertEquals(result.getName(), "demo6");
  93. assertEquals(result.getDescription(),
  94. "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;");
  95. assertEquals(result.getStatus(), Status.DEPLOYED);
  96. assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1",
  97. VCloudMediaType.VAPP_XML, URI
  98. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1001")),
  99. new ResourceImpl("1002", "Host2", VCloudMediaType.VAPP_XML, URI
  100. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1002")),
  101. new ResourceImpl("1003", "Host3", VCloudMediaType.VAPP_XML, URI
  102. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1003")),
  103. new ResourceImpl("1004", "Host4", VCloudMediaType.VAPP_XML, URI
  104. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1004"))));
  105. assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
  106. "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
  107. URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/network/VM-Tier01"))
  108. .build()));
  109. }
  110. public void testFailed() {
  111. InputStream is = getClass().getResourceAsStream("/vdc-failed.xml");
  112. Injector injector = Guice.createInjector(new SaxParserModule());
  113. Factory factory = injector.getInstance(ParseSax.Factory.class);
  114. VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
  115. assertEquals(result.getName(), "Demo7");
  116. assertEquals(result.getDescription(),
  117. "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;");
  118. assertEquals(result.getStatus(), Status.FAILED);
  119. assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1",
  120. VCloudMediaType.VAPP_XML, URI
  121. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/vApp/1001"))));
  122. assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
  123. "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
  124. URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/network/VM-Tier01"))
  125. .build()));
  126. }
  127. public void testSaved() {
  128. InputStream is = getClass().getResourceAsStream("/vdc-saved.xml");
  129. Injector injector = Guice.createInjector(new SaxParserModule());
  130. Factory factory = injector.getInstance(ParseSax.Factory.class);
  131. VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
  132. assertEquals(result.getName(), "CloudBurst1");
  133. assertEquals(result.getDescription(),
  134. "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = me@my.com;");
  135. assertEquals(result.getStatus(), Status.SAVED);
  136. assertEquals(
  137. result.getResourceEntities(),
  138. ImmutableSet
  139. .of(
  140. ResourceImpl
  141. .builder()
  142. .name("templateHost")
  143. .type("application/vnd.vmware.vcloud.vApp+xml")
  144. .id("1001")
  145. .href(
  146. URI
  147. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1001"))
  148. .build(),
  149. ResourceImpl
  150. .builder()
  151. .name("host-c501")
  152. .type("application/vnd.vmware.vcloud.vApp+xml")
  153. .id("1037")
  154. .href(
  155. URI
  156. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1037"))
  157. .build(),
  158. ResourceImpl
  159. .builder()
  160. .name("host-c501")
  161. .type("application/vnd.vmware.vcloud.vApp+xml")
  162. .id("1038")
  163. .href(
  164. URI
  165. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1038"))
  166. .build(),
  167. ResourceImpl
  168. .builder()
  169. .name("host-c601")
  170. .type("application/vnd.vmware.vcloud.vApp+xml")
  171. .id("1039")
  172. .href(
  173. URI
  174. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1039"))
  175. .build()));
  176. assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
  177. "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
  178. URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/network/VM-Tier01"))
  179. .build()));
  180. }
  181. }