PageRenderTime 93ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/OrgNetworkHandlerTest.java

https://github.com/regularfry/jclouds
Java | 106 lines | 70 code | 13 blank | 23 comment | 4 complexity | 7d650081d10debbaed3b3a99bc379e70 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.vcloud.xml;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import org.jclouds.http.functions.ParseSax;
  24. import org.jclouds.http.functions.ParseSax.Factory;
  25. import org.jclouds.http.functions.config.SaxParserModule;
  26. import org.jclouds.vcloud.VCloudMediaType;
  27. import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
  28. import org.jclouds.vcloud.domain.network.DhcpService;
  29. import org.jclouds.vcloud.domain.network.FenceMode;
  30. import org.jclouds.vcloud.domain.network.IpRange;
  31. import org.jclouds.vcloud.domain.network.IpScope;
  32. import org.jclouds.vcloud.domain.network.OrgNetwork;
  33. import org.testng.annotations.Test;
  34. import com.google.common.collect.ImmutableList;
  35. import com.google.common.collect.ImmutableSet;
  36. import com.google.inject.Guice;
  37. import com.google.inject.Injector;
  38. /**
  39. * Tests behavior of {@code OrgNetworkHandler}
  40. *
  41. * @author Adrian Cole
  42. */
  43. @Test(groups = "unit")
  44. public class OrgNetworkHandlerTest {
  45. public void testIsolated() {
  46. InputStream is = getClass().getResourceAsStream("/orgnetwork-isolated.xml");
  47. Injector injector = Guice.createInjector(new SaxParserModule());
  48. Factory factory = injector.getInstance(ParseSax.Factory.class);
  49. OrgNetwork result = factory.create(injector.getInstance(OrgNetworkHandler.class)).parse(is);
  50. assertEquals(result.getName(), "isolation01");
  51. assertEquals(result.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/990419644"));
  52. assertEquals(result.getType(), "application/vnd.vmware.vcloud.network+xml");
  53. assertEquals(result.getOrg(), new ReferenceTypeImpl(null, VCloudMediaType.ORG_XML, URI
  54. .create("https://vcenterprise.bluelock.com/api/v1.0/org/9566014")));
  55. assertEquals(result.getDescription(), null);
  56. assertEquals(result.getTasks(), ImmutableList.of());
  57. assert result.getConfiguration() != null;
  58. assertEquals(result.getConfiguration().getIpScope(), new IpScope(false, "192.168.15.1", "255.255.255.0",
  59. "23.172.173.113", null, null,
  60. ImmutableSet.<IpRange> of(new IpRange("192.168.15.100", "192.168.15.199")), ImmutableSet.<String> of()));
  61. assertEquals(result.getConfiguration().getParentNetwork(), null);
  62. assertEquals(result.getConfiguration().getFenceMode(), FenceMode.ISOLATED);
  63. assert result.getConfiguration().getFeatures() != null;
  64. assertEquals(result.getConfiguration().getFeatures().getDhcpService(), new DhcpService(false, 3600, 7200,
  65. new IpRange("192.168.15.2", "192.168.15.99")));
  66. assertEquals(result.getConfiguration().getFeatures().getFirewallService(), null);
  67. assertEquals(result.getConfiguration().getFeatures().getNatService(), null);
  68. assertEquals(result.getNetworkPool(), null);
  69. assertEquals(result.getAllowedExternalIpAddresses(), ImmutableSet.<String> of());
  70. }
  71. public void testBridged() {
  72. InputStream is = getClass().getResourceAsStream("/orgnetwork-bridged.xml");
  73. Injector injector = Guice.createInjector(new SaxParserModule());
  74. Factory factory = injector.getInstance(ParseSax.Factory.class);
  75. OrgNetwork result = factory.create(injector.getInstance(OrgNetworkHandler.class)).parse(is);
  76. assertEquals(result.getName(), "internet01");
  77. assertEquals(result.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/758634723"));
  78. assertEquals(result.getType(), "application/vnd.vmware.vcloud.network+xml");
  79. assertEquals(result.getOrg(), new ReferenceTypeImpl(null, VCloudMediaType.ORG_XML, URI
  80. .create("https://vcenterprise.bluelock.com/api/v1.0/org/9566014")));
  81. assertEquals(result.getDescription(), null);
  82. assertEquals(result.getTasks(), ImmutableList.of());
  83. assert result.getConfiguration() != null;
  84. assertEquals(result.getConfiguration().getIpScope(), new IpScope(true, "174.47.101.161", "255.255.255.224",
  85. "24.172.173.113", null, null,
  86. ImmutableSet.<IpRange> of(new IpRange("174.47.101.164", "174.47.101.190")), ImmutableSet.<String> of()));
  87. assertEquals(result.getConfiguration().getParentNetwork(), null);
  88. assertEquals(result.getConfiguration().getFenceMode(), FenceMode.BRIDGED);
  89. assert result.getConfiguration().getFeatures() == null;
  90. assertEquals(result.getNetworkPool(), null);
  91. assertEquals(result.getAllowedExternalIpAddresses(), ImmutableSet.<String> of());
  92. }
  93. }