PageRenderTime 45ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java

https://github.com/regularfry/jclouds
Java | 126 lines | 89 code | 14 blank | 23 comment | 0 complexity | 5c38e130b0770b2bab872a2067699aa7 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.vcloud.xml;
  20. import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
  21. import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
  22. import static org.testng.Assert.assertEquals;
  23. import java.io.InputStream;
  24. import java.net.URI;
  25. import org.jclouds.http.functions.ParseSax;
  26. import org.jclouds.http.functions.ParseSax.Factory;
  27. import org.jclouds.http.functions.config.SaxParserModule;
  28. import org.jclouds.vcloud.VCloudMediaType;
  29. import org.jclouds.vcloud.domain.Org;
  30. import org.jclouds.vcloud.domain.ReferenceType;
  31. import org.jclouds.vcloud.domain.Task;
  32. import org.jclouds.vcloud.domain.internal.OrgImpl;
  33. import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
  34. import org.testng.annotations.Test;
  35. import com.google.common.collect.ImmutableMap;
  36. import com.google.common.collect.ImmutableSet;
  37. import com.google.inject.Guice;
  38. import com.google.inject.Injector;
  39. /**
  40. * Tests behavior of {@code OrgHandler}
  41. *
  42. * @author Adrian Cole
  43. */
  44. @Test(groups = "unit")
  45. public class OrgHandlerTest {
  46. public void testApplyInputStream() {
  47. InputStream is = getClass().getResourceAsStream("/org-1.0.xml");
  48. Injector injector = Guice.createInjector(new SaxParserModule());
  49. Factory factory = injector.getInstance(ParseSax.Factory.class);
  50. Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
  51. assertEquals(result.getName(), "ExampleOrg");
  52. assertEquals(result.getFullName(), "ExampleOrg");
  53. assertEquals(result.getDescription(), "Example Corp's Primary Organization.");
  54. assertEquals(result.getHref(), URI.create("http://vcloud.example.com/api/v1.0/org/5"));
  55. assertEquals(result.getCatalogs(), ImmutableMap.of("Main Catalog", new ReferenceTypeImpl("Main Catalog",
  56. CATALOG_XML, URI.create("http://vcloud.example.com/api/v1.0/catalog/32")), "Shared Catalog",
  57. new ReferenceTypeImpl("Shared Catalog", CATALOG_XML, URI
  58. .create("http://vcloud.example.com/api/v1.0/catalog/37"))));
  59. assertEquals(result.getVDCs(), ImmutableMap.of("ExampleVdc01", new ReferenceTypeImpl("ExampleVdc01",
  60. VCloudMediaType.VDC_XML, URI.create("http://vcloud.example.com/api/v1.0/vdc/5"))));
  61. assertEquals(result.getNetworks(), ImmutableMap.of("TestNetwork", new ReferenceTypeImpl("TestNetwork",
  62. VCloudMediaType.NETWORK_XML, URI.create("http://vcloud.example.com/api/v1.0/network/14")),
  63. "ProductionNetwork", new ReferenceTypeImpl("ProductionNetwork", VCloudMediaType.NETWORK_XML, URI
  64. .create("http://vcloud.example.com/api/v1.0/network/54"))));
  65. assertEquals(result.getTasksList(), new ReferenceTypeImpl(null, TASKSLIST_XML, URI
  66. .create("http://vcloud.example.com/api/v1.0/tasksList/5")));
  67. }
  68. public void testTerremark() {
  69. InputStream is = getClass().getResourceAsStream("/org.xml");
  70. Injector injector = Guice.createInjector(new SaxParserModule());
  71. Factory factory = injector.getInstance(ParseSax.Factory.class);
  72. Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
  73. assertEquals(result.getName(), "adrian@jclouds.org");
  74. assertEquals(result.getFullName(), "adrian@jclouds.org");
  75. assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
  76. assertEquals(result.getCatalogs(), ImmutableMap.of("Miami Environment 1 Catalog", new ReferenceTypeImpl(
  77. "Miami Environment 1 Catalog", CATALOG_XML, URI
  78. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))));
  79. assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new ReferenceTypeImpl(
  80. "Miami Environment 1", VCloudMediaType.VDC_XML, URI
  81. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))));
  82. assertEquals(result.getTasksList(), new ReferenceTypeImpl("Miami Environment 1 Tasks List", TASKSLIST_XML, URI
  83. .create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32")));
  84. }
  85. public void testHosting() {
  86. InputStream is = getClass().getResourceAsStream("/org-hosting.xml");
  87. Injector injector = Guice.createInjector(new SaxParserModule());
  88. Factory factory = injector.getInstance(ParseSax.Factory.class);
  89. Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
  90. assertEquals(result.getName(), "Customer 188849");
  91. assertEquals(result.getFullName(), "Customer 188849");
  92. assertEquals(result.getHref(), URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/188849"));
  93. assertEquals(result.getCatalogs(), ImmutableMap.of("HMS Shared Catalog", new ReferenceTypeImpl(
  94. "HMS Shared Catalog", CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))));
  95. assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter", new ReferenceTypeImpl(
  96. "188849 Virtual DataCenter", VCloudMediaType.VDC_XML, URI
  97. .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"))));
  98. assertEquals(result.getTasksList(), new ReferenceTypeImpl("188849 Task List", TASKSLIST_XML, URI
  99. .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849")));
  100. }
  101. public void testSavvis() {
  102. InputStream is = getClass().getResourceAsStream("/org-savvis.xml");
  103. Injector injector = Guice.createInjector(new SaxParserModule());
  104. Factory factory = injector.getInstance(ParseSax.Factory.class);
  105. Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
  106. assertEquals(result, new OrgImpl("607968.0", null, null, "607968.0", "Gravitant Inc", ImmutableMap
  107. .<String, ReferenceType> of(), ImmutableMap.<String, ReferenceType> of("GravDataCenter1(Saved)",
  108. new ReferenceTypeImpl("GravDataCenter1(Saved)", "application/vnd.vmware.vcloud.vdc+xml", URI
  109. .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/607968.0/vdc/2826"))),
  110. ImmutableMap.<String, ReferenceType> of(), null, ImmutableSet.<Task> of()));
  111. }
  112. }