/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/xml/CatalogItemHandlerTest.java

https://github.com/regularfry/jclouds · Java · 93 lines · 60 code · 8 blank · 25 comment · 1 complexity · ee5aab49d4acfcdefa3a1351633cebc9 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.vcloud_0_8.xml;
  20. import static com.google.common.base.Preconditions.checkNotNull;
  21. import static org.testng.Assert.assertEquals;
  22. import java.io.InputStream;
  23. import java.net.URI;
  24. import java.util.Properties;
  25. import org.jclouds.http.functions.BaseHandlerTest;
  26. import org.jclouds.http.functions.ParseSax;
  27. import org.jclouds.http.functions.config.SaxParserModule;
  28. import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudPropertiesBuilder;
  29. import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
  30. import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
  31. import org.jclouds.trmk.vcloud_0_8.domain.internal.CatalogItemImpl;
  32. import org.jclouds.trmk.vcloud_0_8.xml.CatalogItemHandler;
  33. import org.testng.annotations.BeforeTest;
  34. import org.testng.annotations.Test;
  35. import com.google.common.collect.ImmutableSortedMap;
  36. import com.google.inject.Guice;
  37. import com.google.inject.name.Names;
  38. /**
  39. * Tests behavior of {@code CatalogItemHandler}
  40. *
  41. * @author Adrian Cole
  42. */
  43. // NOTE:without testName, this will not call @Before* and fail w/NPE during
  44. // surefire
  45. @Test(groups = "unit", testName = "CatalogItemHandlerTest")
  46. public class CatalogItemHandlerTest extends BaseHandlerTest {
  47. @Override
  48. @BeforeTest
  49. protected void setUpInjector() {
  50. injector = Guice.createInjector(new SaxParserModule() {
  51. @Override
  52. public void configure() {
  53. super.configure();
  54. Properties props = new Properties();
  55. Names.bindProperties(binder(),
  56. checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(), "properties"));
  57. }
  58. });
  59. factory = injector.getInstance(ParseSax.Factory.class);
  60. assert factory != null;
  61. }
  62. public void testApplyInputStream() {
  63. InputStream is = getClass().getResourceAsStream("/catalogItem-terremark.xml");
  64. CatalogItem result = (CatalogItem) factory.create(
  65. injector.getInstance(CatalogItemHandler.class)).parse(is);
  66. assertEquals(
  67. result,
  68. new CatalogItemImpl(
  69. "Windows Web Server 2008 R2 (64-bit)",
  70. URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22"),
  71. null,
  72. new ReferenceTypeImpl(
  73. "Compute Options",
  74. "application/xml",
  75. URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22/options/compute")),
  76. new ReferenceTypeImpl(
  77. "Customization Options",
  78. "application/xml",
  79. URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22/options/customization")),
  80. new ReferenceTypeImpl("Windows Web Server 2008 R2 (64-bit)",
  81. "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
  82. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vAppTemplate/22")),
  83. ImmutableSortedMap.of("LicensingCost", "0")));
  84. }
  85. }