PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java

https://github.com/andreisavu/jclouds
Java | 102 lines | 66 code | 13 blank | 23 comment | 0 complexity | 2e8f13845433ffa96af77f2ac6429f85 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.binders;
 20
 21import static org.easymock.EasyMock.createMock;
 22import static org.easymock.EasyMock.expect;
 23import static org.easymock.EasyMock.replay;
 24
 25import java.io.IOException;
 26import java.net.URI;
 27import java.util.Map;
 28
 29import javax.inject.Singleton;
 30
 31import org.jclouds.rest.internal.GeneratedHttpRequest;
 32import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
 33import org.jclouds.trmk.vcloud_0_8.domain.internal.ReferenceTypeImpl;
 34import org.jclouds.trmk.vcloud_0_8.endpoints.Network;
 35import org.jclouds.trmk.vcloud_0_8.internal.TerremarkVCloudApiMetadata;
 36import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
 37import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig;
 38import org.jclouds.util.Strings2;
 39import org.nnsoft.guice.rocoto.Rocoto;
 40import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
 41import org.testng.annotations.Test;
 42
 43import com.google.common.base.Supplier;
 44import com.google.common.base.Suppliers;
 45import com.google.common.collect.HashMultimap;
 46import com.google.common.collect.ImmutableList;
 47import com.google.common.collect.Maps;
 48import com.google.common.collect.Multimap;
 49import com.google.common.collect.Multimaps;
 50import com.google.inject.Guice;
 51import com.google.inject.Injector;
 52import com.google.inject.Provides;
 53
 54/**
 55 * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload}
 56 * 
 57 * @author Adrian Cole
 58 */
 59@Test(groups = "unit")
 60public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
 61   Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
 62
 63      @Override
 64      protected void bindConfigurations() {
 65         bindProperties(TerremarkVCloudApiMetadata.defaultProperties());
 66      }
 67
 68      @Network
 69      @Provides
 70      @Singleton
 71      Supplier<ReferenceType> provideNetwork() {
 72         return Suppliers.<ReferenceType>ofInstance(new ReferenceTypeImpl(null, null, URI
 73               .create("https://vcloud.safesecureweb.com/network/1990")));
 74      }
 75   }));
 76
 77   public void testAllOptions() throws IOException {
 78
 79      String expected = Strings2.toStringAndClose(getClass().getResourceAsStream(
 80            "/InstantiateVAppTemplateParams-options-test.xml"));
 81      Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap.<String, String> create());
 82      GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
 83      expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
 84      expect(request.getArgs()).andReturn(
 85            ImmutableList.<Object> of(InstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512)
 86                  .inGroup("group").withPassword("password").inRow("row")
 87                  .addNetworkConfig(new NetworkConfig(URI.create("http://network"))))).atLeastOnce();
 88      expect(request.getFirstHeaderOrNull("Content-Type")).andReturn("application/unknown").atLeastOnce();
 89      expect(request.getHeaders()).andReturn(headers).atLeastOnce();
 90      request.setPayload(expected);
 91      replay(request);
 92
 93       BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
 94            .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
 95
 96      Map<String, Object> map = Maps.newHashMap();
 97      map.put("name", "name");
 98      map.put("template", "https://vcloud/vAppTemplate/3");
 99      binder.bindToRequest(request, map);
100   }
101
102}