/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java
Java | 193 lines | 158 code | 12 blank | 23 comment | 0 complexity | 47be0717d1676bba90a59f2a76ec2ea3 MD5 | raw file
1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.savvis.vpdc.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.savvis.vpdc.domain.Resource;
30import org.jclouds.savvis.vpdc.domain.ResourceImpl;
31import org.jclouds.savvis.vpdc.domain.VDC;
32import org.jclouds.savvis.vpdc.domain.VDC.Status;
33import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
34import org.testng.annotations.Test;
35
36import com.google.common.collect.ImmutableSet;
37import com.google.inject.Guice;
38import com.google.inject.Injector;
39
40/**
41 * Tests behavior of {@code VDCHandler}
42 *
43 * @author Adrian Cole
44 */
45@Test(groups = "unit")
46public class VDCHandlerTest {
47
48 public void test() {
49 InputStream is = getClass().getResourceAsStream("/vdc.xml");
50 Injector injector = Guice.createInjector(new SaxParserModule());
51 Factory factory = injector.getInstance(ParseSax.Factory.class);
52 VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
53 assertEquals(result.getName(), "demo_vpdcname");
54 assertEquals(result.getDescription(),
55 "ServiceProfileName = Balanced; ServiceLocation = North America; Email = jim@company.com;");
56 assertEquals(result.getStatus(), Status.DEPLOYED);
57 assertEquals(
58 result.getResourceEntities(),
59 ImmutableSet
60 .<Resource> of(
61 new ResourceImpl(
62 "1001",
63 "DemoHost-1",
64 VCloudMediaType.VAPP_XML,
65 URI
66 .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")),
67 new ResourceImpl(
68 "1002",
69 "DemoHost-2",
70 VCloudMediaType.VAPP_XML,
71 URI
72 .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")),
73 new ResourceImpl(
74 "1003",
75 "DemoHost-3",
76 VCloudMediaType.VAPP_XML,
77 URI
78 .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1003")),
79 new ResourceImpl(
80 "1234",
81 "CustomerTemplateName",
82 VCloudMediaType.VAPPTEMPLATE_XML,
83 URI
84 .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vAppTemplate/1234")),
85 new ResourceImpl(
86 "FirewallService",
87 "firewall",
88 "api.symphonyvpdc.savvis.net+xml",
89 URI
90 .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/FirewallService"))));
91 assertEquals(result.getAvailableNetworks(), ImmutableSet.of());
92 }
93
94 public void test1net() {
95 InputStream is = getClass().getResourceAsStream("/vdc-1net.xml");
96 Injector injector = Guice.createInjector(new SaxParserModule());
97 Factory factory = injector.getInstance(ParseSax.Factory.class);
98 VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
99 assertEquals(result.getName(), "demo6");
100 assertEquals(result.getDescription(),
101 "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;");
102 assertEquals(result.getStatus(), Status.DEPLOYED);
103 assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1",
104 VCloudMediaType.VAPP_XML, URI
105 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1001")),
106 new ResourceImpl("1002", "Host2", VCloudMediaType.VAPP_XML, URI
107 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1002")),
108 new ResourceImpl("1003", "Host3", VCloudMediaType.VAPP_XML, URI
109 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1003")),
110 new ResourceImpl("1004", "Host4", VCloudMediaType.VAPP_XML, URI
111 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1004"))));
112 assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
113 "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
114 URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/network/VM-Tier01"))
115 .build()));
116
117 }
118
119 public void testFailed() {
120 InputStream is = getClass().getResourceAsStream("/vdc-failed.xml");
121 Injector injector = Guice.createInjector(new SaxParserModule());
122 Factory factory = injector.getInstance(ParseSax.Factory.class);
123 VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
124 assertEquals(result.getName(), "Demo7");
125 assertEquals(result.getDescription(),
126 "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;");
127 assertEquals(result.getStatus(), Status.FAILED);
128 assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1",
129 VCloudMediaType.VAPP_XML, URI
130 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/vApp/1001"))));
131 assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
132 "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
133 URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/network/VM-Tier01"))
134 .build()));
135
136 }
137
138 public void testSaved() {
139 InputStream is = getClass().getResourceAsStream("/vdc-saved.xml");
140 Injector injector = Guice.createInjector(new SaxParserModule());
141 Factory factory = injector.getInstance(ParseSax.Factory.class);
142 VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
143 assertEquals(result.getName(), "CloudBurst1");
144 assertEquals(result.getDescription(),
145 "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = me@my.com;");
146 assertEquals(result.getStatus(), Status.SAVED);
147 assertEquals(
148 result.getResourceEntities(),
149 ImmutableSet
150 .of(
151 ResourceImpl
152 .builder()
153 .name("templateHost")
154 .type("application/vnd.vmware.vcloud.vApp+xml")
155 .id("1001")
156 .href(
157 URI
158 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1001"))
159 .build(),
160 ResourceImpl
161 .builder()
162 .name("host-c501")
163 .type("application/vnd.vmware.vcloud.vApp+xml")
164 .id("1037")
165 .href(
166 URI
167 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1037"))
168 .build(),
169 ResourceImpl
170 .builder()
171 .name("host-c501")
172 .type("application/vnd.vmware.vcloud.vApp+xml")
173 .id("1038")
174 .href(
175 URI
176 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1038"))
177 .build(),
178 ResourceImpl
179 .builder()
180 .name("host-c601")
181 .type("application/vnd.vmware.vcloud.vApp+xml")
182 .id("1039")
183 .href(
184 URI
185 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1039"))
186 .build()));
187 assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
188 "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
189 URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/network/VM-Tier01"))
190 .build()));
191
192 }
193}