PageRenderTime 136ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/functions/TerremarkECloudParseOsFromVAppTemplateNameTest.java

https://github.com/regularfry/jclouds
Java | 172 lines | 108 code | 11 blank | 53 comment | 0 complexity | c2a0de898179ae2cd724c9785200fd8f 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.trmk.ecloud.compute.functions;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.util.Map;
  23. import java.util.Set;
  24. import org.jclouds.compute.domain.OperatingSystem;
  25. import org.jclouds.compute.domain.OsFamily;
  26. import org.jclouds.compute.reference.ComputeServiceConstants;
  27. import org.jclouds.http.functions.ParseSax;
  28. import org.jclouds.http.functions.ParseSax.Factory;
  29. import org.jclouds.http.functions.config.SaxParserModule;
  30. import org.jclouds.json.Json;
  31. import org.jclouds.json.config.GsonModule;
  32. import org.jclouds.trmk.vcloud_0_8.xml.CatalogHandler;
  33. import org.testng.annotations.Test;
  34. import com.google.common.collect.ImmutableSet;
  35. import com.google.common.collect.Iterables;
  36. import com.google.common.collect.Sets;
  37. import com.google.inject.Guice;
  38. import com.google.inject.Injector;
  39. import com.google.inject.TypeLiteral;
  40. /**
  41. * @author Adrian Cole
  42. */
  43. @Test(groups = "unit", testName = "TerremarkECloudParseOsFromVAppTemplateNameTest")
  44. public class TerremarkECloudParseOsFromVAppTemplateNameTest {
  45. public Set<String> parseNames(String resource) {
  46. InputStream is = getClass().getResourceAsStream(resource);
  47. Injector injector = Guice.createInjector(new SaxParserModule());
  48. Factory factory = injector.getInstance(ParseSax.Factory.class);
  49. return factory.create(injector.getInstance(CatalogHandler.class)).parse(is).keySet();
  50. }
  51. public void test() {
  52. TerremarkECloudParseOsFromVAppTemplateName function = new TerremarkECloudParseOsFromVAppTemplateName(Guice
  53. .createInjector(new GsonModule())
  54. .getInstance(Json.class)
  55. .<Map<OsFamily, Map<String, String>>> fromJson(
  56. new ComputeServiceConstants.ReferenceData().osVersionMapJson,
  57. new TypeLiteral<Map<OsFamily, Map<String, String>>>() {
  58. }.getType()));
  59. Set<String> names = parseNames("/catalog-ecloud.xml");
  60. assertEquals(
  61. Sets.newLinkedHashSet(Iterables.transform(names, function)),
  62. ImmutableSet.of(
  63. // CentOS 5 (x64)
  64. new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.0").description("CentOS 5 (x64)")
  65. .is64Bit(true).build(),
  66. // CentOS 5 (x86)
  67. new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.0").description("CentOS 5 (x86)")
  68. .is64Bit(false).build(),
  69. // CentOS 5.5 x32
  70. new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.5").description("CentOS 5.5 x32")
  71. .is64Bit(false).build(),
  72. // CentOS 5.5 x64
  73. new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.5").description("CentOS 5.5 x64")
  74. .is64Bit(true).build(),
  75. // Red Hat Enterprise Linux 5 (x64)
  76. new OperatingSystem.Builder().family(OsFamily.RHEL).version("5.0")
  77. .description("Red Hat Enterprise Linux 5 (x64)").is64Bit(true).build(),
  78. // Red Hat Enterprise Linux 5 (x86)
  79. new OperatingSystem.Builder().family(OsFamily.RHEL).version("5.0")
  80. .description("Red Hat Enterprise Linux 5 (x86)").is64Bit(false).build(),
  81. // Red Hat Enterprise Linux 5.5 x32
  82. new OperatingSystem.Builder().family(OsFamily.RHEL).version("5.5")
  83. .description("Red Hat Enterprise Linux 5.5 x32").is64Bit(false).build(),
  84. // Red Hat Enterprise Linux 5.5 x64
  85. new OperatingSystem.Builder().family(OsFamily.RHEL).version("5.5")
  86. .description("Red Hat Enterprise Linux 5.5 x64").is64Bit(true).build(),
  87. // Sun Solaris 10 (x64)
  88. new OperatingSystem.Builder().family(OsFamily.SOLARIS).version("10")
  89. .description("Sun Solaris 10 (x64)").is64Bit(true).build(),
  90. // Ubuntu 8.04 LTS (x64)
  91. new OperatingSystem.Builder().family(OsFamily.UBUNTU).version("8.04")
  92. .description("Ubuntu 8.04 LTS (x64)").is64Bit(true).build(),
  93. // Ubuntu 8.04 LTS (x86)
  94. new OperatingSystem.Builder().family(OsFamily.UBUNTU).version("8.04")
  95. .description("Ubuntu 8.04 LTS (x86)").is64Bit(false).build(),
  96. // Ubuntu Server 10.04 x32
  97. new OperatingSystem.Builder().family(OsFamily.UBUNTU).version("10.04")
  98. .description("Ubuntu Server 10.04 x32").is64Bit(false).build(),
  99. // Ubuntu Server 10.04 x64
  100. new OperatingSystem.Builder().family(OsFamily.UBUNTU).version("10.04")
  101. .description("Ubuntu Server 10.04 x64").is64Bit(true).build(),
  102. // -Windows 2003 Std. R2 SQL 2005 Std. (x64)
  103. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2003 R2")
  104. .description("-Windows 2003 Std. R2 SQL 2005 Std. (x64)").is64Bit(true).build(),
  105. // -Windows 2003 Std. R2 SQL 2008 Std. (x64)
  106. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2003 R2")
  107. .description("-Windows 2003 Std. R2 SQL 2008 Std. (x64)").is64Bit(true).build(),
  108. // -Windows 2008 R2 Std wSQL 2008 R2 Std (x64)
  109. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008 R2")
  110. .description("-Windows 2008 R2 Std wSQL 2008 R2 Std (x64)").is64Bit(true).build(),
  111. // -Windows 2008 R2 Std wSQL 2008 R2 Web (x64)
  112. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008 R2")
  113. .description("-Windows 2008 R2 Std wSQL 2008 R2 Web (x64)").is64Bit(true).build(),
  114. // -Windows 2008 Std wSQL 2008 Std (x64)
  115. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  116. .description("-Windows 2008 Std wSQL 2008 Std (x64)").is64Bit(true).build(),
  117. // -Windows 2008 Std wSQL 2008 Web (x64)
  118. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  119. .description("-Windows 2008 Std wSQL 2008 Web (x64)").is64Bit(true).build(),
  120. // -Windows Server 2003 R2 Enterprise Edition (x64)
  121. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2003 R2")
  122. .description("-Windows Server 2003 R2 Enterprise Edition (x64)").is64Bit(true).build(),
  123. // -Windows Server 2003 R2 Enterprise Edition (x86)
  124. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2003 R2")
  125. .description("-Windows Server 2003 R2 Enterprise Edition (x86)").is64Bit(false).build(),
  126. // -Windows Server 2003 R2 Standard Edition (x64)
  127. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2003 R2")
  128. .description("-Windows Server 2003 R2 Standard Edition (x64)").is64Bit(true).build(),
  129. // -Windows Server 2003 R2 Standard Edition (x86)
  130. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2003 R2")
  131. .description("-Windows Server 2003 R2 Standard Edition (x86)").is64Bit(false).build(),
  132. // -Windows Server 2008 Enterprise Edition (x64)
  133. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  134. .description("-Windows Server 2008 Enterprise Edition (x64)").is64Bit(true).build(),
  135. // -Windows Server 2008 Enterprise Edition (x86)
  136. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  137. .description("-Windows Server 2008 Enterprise Edition (x86)").is64Bit(false).build(),
  138. // -Windows Server 2008 R2 Enterprise Edition (x64)
  139. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008 R2")
  140. .description("-Windows Server 2008 R2 Enterprise Edition (x64)").is64Bit(true).build(),
  141. // -Windows Server 2008 R2 Standard Edition (x64)
  142. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008 R2")
  143. .description("-Windows Server 2008 R2 Standard Edition (x64)").is64Bit(true).build(),
  144. // -Windows Server 2008 R2 Web Edition (x64)
  145. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008 R2")
  146. .description("-Windows Server 2008 R2 Web Edition (x64)").is64Bit(true).build(),
  147. // -Windows Server 2008 Standard Edition (x64)
  148. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  149. .description("-Windows Server 2008 Standard Edition (x64)").is64Bit(true).build(),
  150. // -Windows Server 2008 Standard Edition (x86)
  151. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  152. .description("-Windows Server 2008 Standard Edition (x86)").is64Bit(false).build(),
  153. // -Windows Server 2008 Web Edition (x64)
  154. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  155. .description("-Windows Server 2008 Web Edition (x64)").is64Bit(true).build(),
  156. // -Windows Server 2008 Web Edition (x86)
  157. new OperatingSystem.Builder().family(OsFamily.WINDOWS).version("2008")
  158. .description("-Windows Server 2008 Web Edition (x86)").is64Bit(false).build()
  159. ));
  160. }
  161. }