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

https://github.com/raschyoung/jclouds · Java · 93 lines · 60 code · 8 blank · 25 comment · 1 complexity · 7059f3c04071d331a128ce8f84aeecc7 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.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. }