PageRenderTime 34ms CodeModel.GetById 26ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCloneVAppTemplateParamsToXmlPayloadTest.java

https://github.com/andreisavu/jclouds
Java | 123 lines | 82 code | 18 blank | 23 comment | 0 complexity | 019670d8717b64dba8c8254648647635 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.createMock;
 22import static org.easymock.EasyMock.expect;
 23import static org.easymock.EasyMock.replay;
 24import static org.easymock.EasyMock.verify;
 25
 26import java.io.IOException;
 27import java.net.URI;
 28import java.util.Properties;
 29
 30import org.jclouds.rest.internal.GeneratedHttpRequest;
 31import org.jclouds.util.Strings2;
 32import org.jclouds.vcloud.VCloudApiMetadata;
 33import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
 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 BindCloneVAppTemplateParamsToXmlPayload}
 46 * 
 47 * @author Adrian Cole
 48 */
 49@Test(groups = "unit")
 50public class BindCloneVAppTemplateParamsToXmlPayloadTest {
 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 VCloudApiMetadata().getDefaultProperties());
 59      }
 60   });
 61
 62   public void testWithDescription() throws IOException {
 63      String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate.xml"));
 64
 65      CloneVAppTemplateOptions options = new CloneVAppTemplateOptions()
 66               .description("The description of the new vAppTemplate");
 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      BindCloneVAppTemplateParamsToXmlPayload binder = injector
 74               .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
 75
 76      Builder<String, Object> map = ImmutableMap.builder();
 77      map.put("name", "new-linux-server");
 78      map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
 79      binder.bindToRequest(request, map.build());
 80      verify(request);
 81   }
 82
 83   public void testWithDescriptionSourceDelete() throws IOException {
 84      String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVAppTemplate.xml"));
 85
 86      CloneVAppTemplateOptions options = new CloneVAppTemplateOptions()
 87               .description("The description of the new vAppTemplate");
 88      GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
 89      expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
 90      expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
 91      request.setPayload(expected);
 92      replay(request);
 93
 94      BindCloneVAppTemplateParamsToXmlPayload binder = injector
 95               .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
 96
 97      Builder<String, Object> map = ImmutableMap.builder();
 98      map.put("name", "new-linux-server");
 99      map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
100      map.put("IsSourceDelete", "true");
101      binder.bindToRequest(request, map.build());
102      verify(request);
103   }
104
105   public void testDefault() throws IOException {
106      String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate-default.xml"));
107
108      GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
109      expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
110      expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
111      request.setPayload(expected);
112      replay(request);
113
114      BindCloneVAppTemplateParamsToXmlPayload binder = injector
115               .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
116
117      Builder<String, Object> map = ImmutableMap.builder();
118      map.put("name", "my-vapptemplate");
119      map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181");
120      binder.bindToRequest(request, map.build());
121      verify(request);
122   }
123}