PageRenderTime 29ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/regularfry/jclouds
Java | 137 lines | 104 code | 10 blank | 23 comment | 1 complexity | f8000e40aa2732b2c96362df65960cb8 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.CATALOGITEM_XML;
  21. import static org.testng.Assert.assertEquals;
  22. import java.io.InputStream;
  23. import java.net.URI;
  24. import org.jclouds.http.functions.ParseSax;
  25. import org.jclouds.http.functions.ParseSax.Factory;
  26. import org.jclouds.http.functions.config.SaxParserModule;
  27. import org.jclouds.vcloud.domain.Catalog;
  28. import org.jclouds.vcloud.domain.ReferenceType;
  29. import org.jclouds.vcloud.domain.Task;
  30. import org.jclouds.vcloud.domain.internal.CatalogImpl;
  31. import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
  32. import org.testng.annotations.Test;
  33. import com.google.common.collect.ImmutableList;
  34. import com.google.common.collect.ImmutableMap;
  35. import com.google.inject.Guice;
  36. import com.google.inject.Injector;
  37. /**
  38. * Tests behavior of {@code CatalogHandler}
  39. *
  40. * @author Adrian Cole
  41. */
  42. @Test(groups = "unit")
  43. public class CatalogHandlerTest {
  44. private Injector injector;
  45. private Factory factory;
  46. public void testVCloud1_0() {
  47. InputStream is = getClass().getResourceAsStream("/catalog-blank.xml");
  48. injector = Guice.createInjector(new SaxParserModule());
  49. factory = injector.getInstance(ParseSax.Factory.class);
  50. Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(is);
  51. assertEquals(result, new CatalogImpl("Jclouds-private", "application/vnd.vmware.vcloud.catalog+xml", URI
  52. .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/921222081"), new ReferenceTypeImpl(null,
  53. "application/vnd.vmware.vcloud.org+xml", URI
  54. .create("https://vcenterprise.bluelock.com/api/v1.0/org/9566014")), null, ImmutableMap
  55. .<String, ReferenceType> of(), ImmutableList.<Task> of(), false, false));
  56. }
  57. public void testTerremark() {
  58. InputStream is = getClass().getResourceAsStream("/catalog.xml");
  59. injector = Guice.createInjector(new SaxParserModule());
  60. factory = injector.getInstance(ParseSax.Factory.class);
  61. Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(is);
  62. assertEquals(result.getName(), "Miami Environment 1");
  63. assert result.getDescription() == null;
  64. assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"));
  65. assertEquals(result.get("CentOS 5.3 (32-bit)"), new ReferenceTypeImpl("CentOS 5.3 (32-bit)", CATALOGITEM_XML, URI
  66. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5")));
  67. assertEquals(result.get("CentOS 5.3 (64-bit)"), new ReferenceTypeImpl("CentOS 5.3 (64-bit)", CATALOGITEM_XML, URI
  68. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6")));
  69. assertEquals(result.get("RHEL 5.3 (32-bit)"), new ReferenceTypeImpl("RHEL 5.3 (32-bit)", CATALOGITEM_XML, URI
  70. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7")));
  71. assertEquals(result.get("RHEL 5.3 (64-bit)"), new ReferenceTypeImpl("RHEL 5.3 (64-bit)", CATALOGITEM_XML, URI
  72. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8")));
  73. assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new ReferenceTypeImpl("Ubuntu JeOS 9.04 (32-bit)",
  74. CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11")));
  75. assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new ReferenceTypeImpl("Ubuntu JeOS 9.04 (64-bit)",
  76. CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12")));
  77. assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new ReferenceTypeImpl("Ubuntu Server 9.04 (32-bit)",
  78. CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9")));
  79. assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new ReferenceTypeImpl("Ubuntu Server 9.04 (64-bit)",
  80. CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10")));
  81. assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new ReferenceTypeImpl(
  82. "Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML, URI
  83. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1")));
  84. assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new ReferenceTypeImpl(
  85. "Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML, URI
  86. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2")));
  87. assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new ReferenceTypeImpl(
  88. "Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML, URI
  89. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3")));
  90. assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new ReferenceTypeImpl(
  91. "Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML, URI
  92. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4")));
  93. assertEquals(result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"), new ReferenceTypeImpl(
  94. "Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)", CATALOGITEM_XML, URI
  95. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23")));
  96. assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new ReferenceTypeImpl(
  97. "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, URI
  98. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13")));
  99. assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new ReferenceTypeImpl(
  100. "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, URI
  101. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15")));
  102. assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new ReferenceTypeImpl(
  103. "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, URI
  104. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16")));
  105. assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new ReferenceTypeImpl(
  106. "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, URI
  107. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17")));
  108. assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new ReferenceTypeImpl(
  109. "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, URI
  110. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18")));
  111. assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new ReferenceTypeImpl(
  112. "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, URI
  113. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19")));
  114. assertEquals(result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"), new ReferenceTypeImpl(
  115. "Windows Server 2008 Standard w.SQL 2008 Web (64-bit)", CATALOGITEM_XML, URI
  116. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14")));
  117. assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new ReferenceTypeImpl(
  118. "Windows Web Server 2008 (32-bit)", CATALOGITEM_XML, URI
  119. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20")));
  120. assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new ReferenceTypeImpl(
  121. "Windows Web Server 2008 (64-bit)", CATALOGITEM_XML, URI
  122. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21")));
  123. assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new ReferenceTypeImpl(
  124. "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, URI
  125. .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22")));
  126. }
  127. }