PageRenderTime 59ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

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