PageRenderTime 64ms CodeModel.GetById 58ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/xml/VDCHandlerTest.java

https://github.com/regularfry/jclouds
Java | 81 lines | 50 code | 8 blank | 23 comment | 0 complexity | be7b378af7df400c068133885403a814 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.trmk.vcloud_0_8.xml;
20
21import static org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType.CATALOG_XML;
22import static org.testng.Assert.assertEquals;
23
24import java.io.InputStream;
25import java.net.URI;
26
27import org.jclouds.http.functions.ParseSax;
28import org.jclouds.http.functions.ParseSax.Factory;
29import org.jclouds.http.functions.config.SaxParserModule;
30import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
31import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
32import org.jclouds.trmk.vcloud_0_8.domain.VDC;
33import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
34import org.testng.annotations.Test;
35
36import com.google.common.collect.ImmutableMap;
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 testApplyInputStream() {
49      InputStream is = getClass().getResourceAsStream("/vdc.xml");
50      Injector injector = Guice.createInjector(new SaxParserModule());
51      Factory factory = injector.getInstance(ParseSax.Factory.class);
52
53      VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
54      assertEquals(result.getName(), "Miami Environment 1");
55      assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
56      assertEquals(result.getResourceEntities(), ImmutableMap.<String, ReferenceType> of(
57            "adriantest",
58            new ReferenceTypeImpl("adriantest", TerremarkVCloudMediaType.VAPP_XML, URI
59                  .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15124")),
60            "centos-53",
61            new ReferenceTypeImpl("centos-53", TerremarkVCloudMediaType.VAPP_XML, URI
62                  .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15120"))));
63
64      assertEquals(result.getAvailableNetworks(), ImmutableMap.of(
65            "10.114.34.128/26",
66            new ReferenceTypeImpl("10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml", URI
67                  .create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
68      assertEquals(
69            result.getCatalog(),
70            new ReferenceTypeImpl("Miami Environment 1", CATALOG_XML, URI
71                  .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")));
72      assertEquals(
73            result.getPublicIps(),
74            new ReferenceTypeImpl("Public IPs", "application/xml", URI
75                  .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps")));
76      assertEquals(
77            result.getInternetServices(),
78            new ReferenceTypeImpl("Internet Services", "application/xml", URI
79                  .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices")));
80   }
81}