PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/regularfry/jclouds
Java | 81 lines | 50 code | 8 blank | 23 comment | 0 complexity | be7b378af7df400c068133885403a814 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.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOG_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.trmk.vcloud_0_8.TerremarkVCloudMediaType;
  28. import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
  29. import org.jclouds.trmk.vcloud_0_8.domain.VDC;
  30. import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
  31. import org.testng.annotations.Test;
  32. import com.google.common.collect.ImmutableMap;
  33. import com.google.inject.Guice;
  34. import com.google.inject.Injector;
  35. /**
  36. * Tests behavior of {@code VDCHandler}
  37. *
  38. * @author Adrian Cole
  39. */
  40. @Test(groups = "unit")
  41. public class VDCHandlerTest {
  42. public void testApplyInputStream() {
  43. InputStream is = getClass().getResourceAsStream("/vdc.xml");
  44. Injector injector = Guice.createInjector(new SaxParserModule());
  45. Factory factory = injector.getInstance(ParseSax.Factory.class);
  46. VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
  47. assertEquals(result.getName(), "Miami Environment 1");
  48. assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
  49. assertEquals(result.getResourceEntities(), ImmutableMap.<String, ReferenceType> of(
  50. "adriantest",
  51. new ReferenceTypeImpl("adriantest", TerremarkVCloudMediaType.VAPP_XML, URI
  52. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15124")),
  53. "centos-53",
  54. new ReferenceTypeImpl("centos-53", TerremarkVCloudMediaType.VAPP_XML, URI
  55. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15120"))));
  56. assertEquals(result.getAvailableNetworks(), ImmutableMap.of(
  57. "10.114.34.128/26",
  58. new ReferenceTypeImpl("10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml", URI
  59. .create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
  60. assertEquals(
  61. result.getCatalog(),
  62. new ReferenceTypeImpl("Miami Environment 1", CATALOG_XML, URI
  63. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")));
  64. assertEquals(
  65. result.getPublicIps(),
  66. new ReferenceTypeImpl("Public IPs", "application/xml", URI
  67. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps")));
  68. assertEquals(
  69. result.getInternetServices(),
  70. new ReferenceTypeImpl("Internet Services", "application/xml", URI
  71. .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices")));
  72. }
  73. }