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