PageRenderTime 900ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/jclouds/jclouds
Java | 104 lines | 70 code | 13 blank | 21 comment | 4 complexity | b87c629de456bdfdc025ca02f0268770 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jclouds.vcloud.xml;
  18. import static org.testng.Assert.assertEquals;
  19. import java.io.InputStream;
  20. import java.net.URI;
  21. import org.jclouds.http.functions.ParseSax;
  22. import org.jclouds.http.functions.ParseSax.Factory;
  23. import org.jclouds.http.functions.config.SaxParserModule;
  24. import org.jclouds.vcloud.VCloudMediaType;
  25. import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
  26. import org.jclouds.vcloud.domain.network.DhcpService;
  27. import org.jclouds.vcloud.domain.network.FenceMode;
  28. import org.jclouds.vcloud.domain.network.IpRange;
  29. import org.jclouds.vcloud.domain.network.IpScope;
  30. import org.jclouds.vcloud.domain.network.OrgNetwork;
  31. import org.testng.annotations.Test;
  32. import com.google.common.collect.ImmutableList;
  33. import com.google.common.collect.ImmutableSet;
  34. import com.google.inject.Guice;
  35. import com.google.inject.Injector;
  36. /**
  37. * Tests behavior of {@code OrgNetworkHandler}
  38. *
  39. * @author Adrian Cole
  40. */
  41. @Test(groups = "unit")
  42. public class OrgNetworkHandlerTest {
  43. public void testIsolated() {
  44. InputStream is = getClass().getResourceAsStream("/orgnetwork-isolated.xml");
  45. Injector injector = Guice.createInjector(new SaxParserModule());
  46. Factory factory = injector.getInstance(ParseSax.Factory.class);
  47. OrgNetwork result = factory.create(injector.getInstance(OrgNetworkHandler.class)).parse(is);
  48. assertEquals(result.getName(), "isolation01");
  49. assertEquals(result.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/990419644"));
  50. assertEquals(result.getType(), "application/vnd.vmware.vcloud.network+xml");
  51. assertEquals(result.getOrg(), new ReferenceTypeImpl(null, VCloudMediaType.ORG_XML, URI
  52. .create("https://vcenterprise.bluelock.com/api/v1.0/org/9566014")));
  53. assertEquals(result.getDescription(), null);
  54. assertEquals(result.getTasks(), ImmutableList.of());
  55. assert result.getConfiguration() != null;
  56. assertEquals(result.getConfiguration().getIpScope(), new IpScope(false, "192.168.15.1", "255.255.255.0",
  57. "23.172.173.113", null, null,
  58. ImmutableSet.<IpRange> of(new IpRange("192.168.15.100", "192.168.15.199")), ImmutableSet.<String> of()));
  59. assertEquals(result.getConfiguration().getParentNetwork(), null);
  60. assertEquals(result.getConfiguration().getFenceMode(), FenceMode.ISOLATED);
  61. assert result.getConfiguration().getFeatures() != null;
  62. assertEquals(result.getConfiguration().getFeatures().getDhcpService(), new DhcpService(false, 3600, 7200,
  63. new IpRange("192.168.15.2", "192.168.15.99")));
  64. assertEquals(result.getConfiguration().getFeatures().getFirewallService(), null);
  65. assertEquals(result.getConfiguration().getFeatures().getNatService(), null);
  66. assertEquals(result.getNetworkPool(), null);
  67. assertEquals(result.getAllowedExternalIpAddresses(), ImmutableSet.<String> of());
  68. }
  69. public void testBridged() {
  70. InputStream is = getClass().getResourceAsStream("/orgnetwork-bridged.xml");
  71. Injector injector = Guice.createInjector(new SaxParserModule());
  72. Factory factory = injector.getInstance(ParseSax.Factory.class);
  73. OrgNetwork result = factory.create(injector.getInstance(OrgNetworkHandler.class)).parse(is);
  74. assertEquals(result.getName(), "internet01");
  75. assertEquals(result.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/758634723"));
  76. assertEquals(result.getType(), "application/vnd.vmware.vcloud.network+xml");
  77. assertEquals(result.getOrg(), new ReferenceTypeImpl(null, VCloudMediaType.ORG_XML, URI
  78. .create("https://vcenterprise.bluelock.com/api/v1.0/org/9566014")));
  79. assertEquals(result.getDescription(), null);
  80. assertEquals(result.getTasks(), ImmutableList.of());
  81. assert result.getConfiguration() != null;
  82. assertEquals(result.getConfiguration().getIpScope(), new IpScope(true, "174.47.101.161", "255.255.255.224",
  83. "24.172.173.113", null, null,
  84. ImmutableSet.<IpRange> of(new IpRange("174.47.101.164", "174.47.101.190")), ImmutableSet.<String> of()));
  85. assertEquals(result.getConfiguration().getParentNetwork(), null);
  86. assertEquals(result.getConfiguration().getFenceMode(), FenceMode.BRIDGED);
  87. assert result.getConfiguration().getFeatures() == null;
  88. assertEquals(result.getNetworkPool(), null);
  89. assertEquals(result.getAllowedExternalIpAddresses(), ImmutableSet.<String> of());
  90. }
  91. }