/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/xml/ovf/VAppHandlerTest.java
Java | 184 lines | 131 code | 29 blank | 24 comment | 0 complexity | 1a1dbf1ad3173c19be2cca84cd8f5fc1 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.ovf;
20
21import static org.testng.Assert.assertEquals;
22
23import java.io.InputStream;
24import java.net.URI;
25import java.net.UnknownHostException;
26import java.util.Properties;
27import java.util.Set;
28
29import org.jclouds.Constants;
30import org.jclouds.cim.ResourceAllocationSettingData;
31import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
32import org.jclouds.cim.VirtualSystemSettingData;
33import org.jclouds.http.functions.BaseHandlerTest;
34import org.jclouds.http.functions.ParseSax;
35import org.jclouds.http.functions.config.SaxParserModule;
36import org.jclouds.trmk.vcloud_0_8.domain.Status;
37import org.jclouds.trmk.vcloud_0_8.domain.VApp;
38import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
39import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl;
40import org.jclouds.trmk.vcloud_0_8.xml.VAppHandler;
41import org.testng.annotations.BeforeTest;
42import org.testng.annotations.Test;
43
44import com.google.common.collect.ImmutableListMultimap;
45import com.google.common.collect.ImmutableSet;
46import com.google.common.collect.ListMultimap;
47import com.google.inject.AbstractModule;
48import com.google.inject.Guice;
49import com.google.inject.name.Names;
50
51/**
52 * Tests behavior of {@code VCloudExpressVAppHandler}
53 *
54 * @author Adrian Cole
55 */
56// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
57@Test(groups = "unit", testName = "VCloudExpressVAppHandlerTest")
58public class VAppHandlerTest extends BaseHandlerTest {
59 @BeforeTest
60 @Override
61 protected void setUpInjector() {
62 injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
63
64 @Override
65 protected void configure() {
66 Properties toBind = new Properties();
67 toBind.setProperty(Constants.PROPERTY_API_VERSION, "0.8");
68 Names.bindProperties(binder(), toBind);
69 }
70
71 });
72 factory = injector.getInstance(ParseSax.Factory.class);
73 }
74
75 public void testInstantiated() throws UnknownHostException {
76 InputStream is = getClass().getResourceAsStream("/instantiatedvapp.xml");
77
78 VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
79
80 VApp expects = new VAppImpl("centos53", URI
81 .create("http://10.150.4.49/api/v0.8/vApp/10"), Status.RESOLVED, 123456789l, new ReferenceTypeImpl(null,
82 "application/vnd.vmware.vcloud.vdc+xml", URI.create("http://10.150.4.49/api/v0.8/vdc/4")),
83 ImmutableListMultimap.<String, String> of(), null, null, null, ImmutableSet
84 .<ResourceAllocationSettingData> of());
85 assertEquals(result, expects);
86 }
87
88 public void testDefault() throws UnknownHostException {
89 InputStream is = getClass().getResourceAsStream("/vapp.xml");
90
91 VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
92
93 ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network",
94 "10.150.4.93");
95
96 VirtualSystemSettingData system = VirtualSystemSettingData.builder().instanceID("0").elementName(
97 "Virtual Hardware Family").virtualSystemIdentifier("centos53").virtualSystemType("vmx-07").build();
98
99 Set<ResourceAllocationSettingData> resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> of(
100 ResourceAllocationSettingData.builder().instanceID("1").elementName("1 virtual CPU(s)").description(
101 "Number of Virtual CPUs").resourceType(ResourceType.PROCESSOR).virtualQuantity(1l)
102 .allocationUnits("hertz * 10^6").virtualQuantityUnits("count").build(),
103
104 ResourceAllocationSettingData.builder().instanceID("2").elementName("16MB of memory").description(
105 "Memory Size").resourceType(ResourceType.MEMORY).virtualQuantity(16l).allocationUnits(
106 "byte * 2^20").virtualQuantityUnits("byte * 2^20").build(),
107
108 ResourceAllocationSettingData.builder().instanceID("3").elementName("SCSI Controller 0").description(
109 "SCSI Controller").resourceType(ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic")
110 .address("0").build(),
111
112 ResourceAllocationSettingData.builder().instanceID("8").elementName("Network Adapter 1").description(
113 "PCNet32 ethernet adapter on \"Internal\" network").resourceType(ResourceType.ETHERNET_ADAPTER)
114 .resourceSubType("PCNet32").addressOnParent("7").connection("Internal").automaticAllocation(
115 true).build(),
116
117 ResourceAllocationSettingData.builder().instanceID("9").elementName("Hard Disk 1").resourceType(
118 ResourceType.DISK_DRIVE).hostResource("104857").addressOnParent("0").parent("3")
119 .virtualQuantity(104857l).build());
120
121 VApp expects = new VAppImpl("centos53", URI
122 .create("http://10.150.4.49/api/v0.8/vApp/10"), Status.ON, Long.valueOf(104857), new ReferenceTypeImpl(null,
123 "application/vnd.vmware.vcloud.vdc+xml", URI.create("http://10.150.4.49/api/v0.8/vdc/4")),
124 networkToAddresses, null, "Other Linux (32-bit)", system, resourceAllocations);
125 assertEquals(result.getHref(), expects.getHref());
126 assertEquals(result.getName(), expects.getName());
127 assertEquals(result.getNetworkToAddresses(), expects.getNetworkToAddresses());
128 assertEquals(result.getOperatingSystemDescription(), expects.getOperatingSystemDescription());
129 assertEquals(result.getResourceAllocations().toString(), expects.getResourceAllocations().toString());
130 assertEquals(result.getSize(), expects.getSize());
131 assertEquals(result.getStatus(), expects.getStatus());
132 assertEquals(result.getSystem().toString(), expects.getSystem().toString());
133 assertEquals(result.getType(), expects.getType());
134 assertEquals(result.getVDC(), expects.getVDC());
135 }
136
137 public void testLatest() throws UnknownHostException {
138 InputStream is = getClass().getResourceAsStream("/vapp2.xml");
139
140 VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
141
142 ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network",
143 "10.23.119.221");
144 VirtualSystemSettingData system = VirtualSystemSettingData.builder().instanceID("0").elementName(
145 "Virtual Hardware Family").virtualSystemIdentifier("m1").virtualSystemType("vmx-07").build();
146
147 Set<ResourceAllocationSettingData> resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> of(
148 ResourceAllocationSettingData.builder().instanceID("1").elementName("1 virtual CPU(s)").description(
149 "Number of Virtual CPUs").resourceType(ResourceType.PROCESSOR).virtualQuantity(1l)
150 .allocationUnits("hertz * 10^6").virtualQuantityUnits("count").build(),
151
152 ResourceAllocationSettingData.builder().instanceID("2").elementName("512MB of memory").description(
153 "Memory Size").resourceType(ResourceType.MEMORY).virtualQuantity(512l).allocationUnits(
154 "byte * 2^20").virtualQuantityUnits("byte * 2^20").build(),
155
156 ResourceAllocationSettingData.builder().instanceID("3").elementName("SCSI Controller 0").description(
157 "SCSI Controller").resourceType(ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic")
158 .address("0").build(),
159
160 ResourceAllocationSettingData.builder().instanceID("8").elementName("Network Adapter 1").description(
161 "PCNet32 ethernet adapter on \"Internal\" network").resourceType(ResourceType.ETHERNET_ADAPTER)
162 .resourceSubType("PCNet32").addressOnParent("7").connection("Internal").automaticAllocation(
163 true).build(),
164
165 ResourceAllocationSettingData.builder().instanceID("9").elementName("Hard Disk 1").resourceType(
166 ResourceType.DISK_DRIVE).hostResource("10485760").addressOnParent("0").parent("3")
167 .virtualQuantity(10485760l).build());
168
169 VApp expects = new VAppImpl("m1", URI.create("http://localhost:8000/api/v0.8/vApp/80"),
170 Status.ON, Long.valueOf(10485760), new ReferenceTypeImpl(null, "application/vnd.vmware.vcloud.vdc+xml", URI
171 .create("http://localhost:8000/api/v0.8/vdc/28")), networkToAddresses, null,
172 "Microsoft Windows XP Professional (32-bit)", system, resourceAllocations);
173 assertEquals(result.getHref(), expects.getHref());
174 assertEquals(result.getName(), expects.getName());
175 assertEquals(result.getNetworkToAddresses(), expects.getNetworkToAddresses());
176 assertEquals(result.getOperatingSystemDescription(), expects.getOperatingSystemDescription());
177 assertEquals(result.getResourceAllocations().toString(), expects.getResourceAllocations().toString());
178 assertEquals(result.getSize(), expects.getSize());
179 assertEquals(result.getStatus(), expects.getStatus());
180 assertEquals(result.getSystem().toString(), expects.getSystem().toString());
181 assertEquals(result.getType(), expects.getType());
182 assertEquals(result.getVDC(), expects.getVDC());
183 }
184}