/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java
Java | 126 lines | 89 code | 14 blank | 23 comment | 0 complexity | 5c38e130b0770b2bab872a2067699aa7 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.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
22import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
23import static org.testng.Assert.assertEquals;
24
25import java.io.InputStream;
26import java.net.URI;
27
28import org.jclouds.http.functions.ParseSax;
29import org.jclouds.http.functions.ParseSax.Factory;
30import org.jclouds.http.functions.config.SaxParserModule;
31import org.jclouds.vcloud.VCloudMediaType;
32import org.jclouds.vcloud.domain.Org;
33import org.jclouds.vcloud.domain.ReferenceType;
34import org.jclouds.vcloud.domain.Task;
35import org.jclouds.vcloud.domain.internal.OrgImpl;
36import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
37import org.testng.annotations.Test;
38
39import com.google.common.collect.ImmutableMap;
40import com.google.common.collect.ImmutableSet;
41import com.google.inject.Guice;
42import com.google.inject.Injector;
43
44/**
45 * Tests behavior of {@code OrgHandler}
46 *
47 * @author Adrian Cole
48 */
49@Test(groups = "unit")
50public class OrgHandlerTest {
51
52 public void testApplyInputStream() {
53 InputStream is = getClass().getResourceAsStream("/org-1.0.xml");
54
55 Injector injector = Guice.createInjector(new SaxParserModule());
56 Factory factory = injector.getInstance(ParseSax.Factory.class);
57
58 Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
59 assertEquals(result.getName(), "ExampleOrg");
60 assertEquals(result.getFullName(), "ExampleOrg");
61 assertEquals(result.getDescription(), "Example Corp's Primary Organization.");
62 assertEquals(result.getHref(), URI.create("http://vcloud.example.com/api/v1.0/org/5"));
63 assertEquals(result.getCatalogs(), ImmutableMap.of("Main Catalog", new ReferenceTypeImpl("Main Catalog",
64 CATALOG_XML, URI.create("http://vcloud.example.com/api/v1.0/catalog/32")), "Shared Catalog",
65 new ReferenceTypeImpl("Shared Catalog", CATALOG_XML, URI
66 .create("http://vcloud.example.com/api/v1.0/catalog/37"))));
67 assertEquals(result.getVDCs(), ImmutableMap.of("ExampleVdc01", new ReferenceTypeImpl("ExampleVdc01",
68 VCloudMediaType.VDC_XML, URI.create("http://vcloud.example.com/api/v1.0/vdc/5"))));
69 assertEquals(result.getNetworks(), ImmutableMap.of("TestNetwork", new ReferenceTypeImpl("TestNetwork",
70 VCloudMediaType.NETWORK_XML, URI.create("http://vcloud.example.com/api/v1.0/network/14")),
71 "ProductionNetwork", new ReferenceTypeImpl("ProductionNetwork", VCloudMediaType.NETWORK_XML, URI
72 .create("http://vcloud.example.com/api/v1.0/network/54"))));
73 assertEquals(result.getTasksList(), new ReferenceTypeImpl(null, TASKSLIST_XML, URI
74 .create("http://vcloud.example.com/api/v1.0/tasksList/5")));
75 }
76
77 public void testTerremark() {
78 InputStream is = getClass().getResourceAsStream("/org.xml");
79
80 Injector injector = Guice.createInjector(new SaxParserModule());
81 Factory factory = injector.getInstance(ParseSax.Factory.class);
82
83 Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
84 assertEquals(result.getName(), "adrian@jclouds.org");
85 assertEquals(result.getFullName(), "adrian@jclouds.org");
86 assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
87 assertEquals(result.getCatalogs(), ImmutableMap.of("Miami Environment 1 Catalog", new ReferenceTypeImpl(
88 "Miami Environment 1 Catalog", CATALOG_XML, URI
89 .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))));
90 assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new ReferenceTypeImpl(
91 "Miami Environment 1", VCloudMediaType.VDC_XML, URI
92 .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))));
93 assertEquals(result.getTasksList(), new ReferenceTypeImpl("Miami Environment 1 Tasks List", TASKSLIST_XML, URI
94 .create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32")));
95 }
96
97 public void testHosting() {
98 InputStream is = getClass().getResourceAsStream("/org-hosting.xml");
99 Injector injector = Guice.createInjector(new SaxParserModule());
100 Factory factory = injector.getInstance(ParseSax.Factory.class);
101 Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
102 assertEquals(result.getName(), "Customer 188849");
103 assertEquals(result.getFullName(), "Customer 188849");
104 assertEquals(result.getHref(), URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/188849"));
105 assertEquals(result.getCatalogs(), ImmutableMap.of("HMS Shared Catalog", new ReferenceTypeImpl(
106 "HMS Shared Catalog", CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))));
107 assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter", new ReferenceTypeImpl(
108 "188849 Virtual DataCenter", VCloudMediaType.VDC_XML, URI
109 .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"))));
110 assertEquals(result.getTasksList(), new ReferenceTypeImpl("188849 Task List", TASKSLIST_XML, URI
111 .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849")));
112 }
113
114 public void testSavvis() {
115 InputStream is = getClass().getResourceAsStream("/org-savvis.xml");
116 Injector injector = Guice.createInjector(new SaxParserModule());
117 Factory factory = injector.getInstance(ParseSax.Factory.class);
118 Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is);
119 assertEquals(result, new OrgImpl("607968.0", null, null, "607968.0", "Gravitant Inc", ImmutableMap
120 .<String, ReferenceType> of(), ImmutableMap.<String, ReferenceType> of("GravDataCenter1(Saved)",
121 new ReferenceTypeImpl("GravDataCenter1(Saved)", "application/vnd.vmware.vcloud.vdc+xml", URI
122 .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/607968.0/vdc/2826"))),
123 ImmutableMap.<String, ReferenceType> of(), null, ImmutableSet.<Task> of()));
124
125 }
126}