/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayloadTest.java
Java | 120 lines | 79 code | 18 blank | 23 comment | 0 complexity | 93a77d17a5186b49c967ff2a476eb517 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.binders;
20
21import static org.easymock.EasyMock.expect;
22import static org.easymock.classextension.EasyMock.createMock;
23import static org.easymock.classextension.EasyMock.replay;
24import static org.easymock.classextension.EasyMock.verify;
25
26import java.io.IOException;
27import java.net.URI;
28import java.util.Properties;
29
30import org.jclouds.PropertiesBuilder;
31import org.jclouds.rest.internal.GeneratedHttpRequest;
32import org.jclouds.util.Strings2;
33import org.jclouds.vcloud.options.CloneVAppOptions;
34import org.testng.annotations.Test;
35
36import com.google.common.collect.ImmutableList;
37import com.google.common.collect.ImmutableMap;
38import com.google.common.collect.ImmutableMap.Builder;
39import com.google.inject.AbstractModule;
40import com.google.inject.Guice;
41import com.google.inject.Injector;
42import com.google.inject.name.Names;
43
44/**
45 * Tests behavior of {@code BindCloneVAppParamsToXmlPayload}
46 *
47 * @author Adrian Cole
48 */
49@Test(groups = "unit")
50public class BindCloneVAppParamsToXmlPayloadTest {
51 Injector injector = Guice.createInjector(new AbstractModule() {
52
53 @Override
54 protected void configure() {
55 Properties props = new Properties();
56 props.setProperty("jclouds.vcloud.xml.ns", "http://www.vmware.com/vcloud/v1");
57 props.setProperty("jclouds.vcloud.xml.schema", "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
58 Names.bindProperties(binder(), new PropertiesBuilder(props).build());
59 }
60 });
61
62 public void testWithDescriptionDeployOn() throws IOException {
63 String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml"));
64
65 CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
66 "The description of the new vApp");
67 GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
68 expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
69 expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
70 request.setPayload(expected);
71 replay(request);
72
73 BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
74
75 Builder<String, String> map = ImmutableMap.<String, String> builder();
76 map.put("name", "new-linux-server");
77 map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
78 binder.bindToRequest(request, map.build());
79 verify(request);
80 }
81
82 public void testWithDescriptionDeployOnSourceDelete() throws IOException {
83 String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVApp.xml"));
84
85 CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
86 "The description of the new vApp");
87 GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
88 expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
89 expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
90 request.setPayload(expected);
91 replay(request);
92
93 BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
94
95 Builder<String, String> map = ImmutableMap.<String, String> builder();
96 map.put("name", "new-linux-server");
97 map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
98 map.put("IsSourceDelete", "true");
99 binder.bindToRequest(request, map.build());
100 verify(request);
101 }
102
103 public void testDefault() throws IOException {
104 String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml"));
105
106 GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
107 expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
108 expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
109 request.setPayload(expected);
110 replay(request);
111
112 BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
113
114 Builder<String, String> map = ImmutableMap.<String, String> builder();
115 map.put("name", "my-vapp");
116 map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181");
117 binder.bindToRequest(request, map.build());
118 verify(request);
119 }
120}