PageRenderTime 21ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

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

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