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

https://github.com/andreisavu/jclouds · Java · 81 lines · 45 code · 13 blank · 23 comment · 0 complexity · d6f020b6e8ee4382c502be58303af875 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.vcloud.binders;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.IOException;
  22. import java.net.URI;
  23. import org.jclouds.http.HttpRequest;
  24. import org.jclouds.vcloud.VCloudApiMetadata;
  25. import org.jclouds.vcloud.domain.NetworkConnection;
  26. import org.jclouds.vcloud.domain.NetworkConnectionSection;
  27. import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
  28. import org.nnsoft.guice.rocoto.Rocoto;
  29. import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
  30. import org.testng.annotations.Test;
  31. import com.google.common.collect.ImmutableSet;
  32. import com.google.inject.Guice;
  33. import com.google.inject.Injector;
  34. /**
  35. * Tests behavior of {@code BindNetworkConnectionSectionToXmlPayload}
  36. *
  37. * @author Adrian Cole
  38. */
  39. @Test(groups = "unit", testName = "BindNetworkConnectionSectionToXmlPayloadTest")
  40. public class BindNetworkConnectionSectionToXmlPayloadTest {
  41. Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
  42. @Override
  43. protected void bindConfigurations() {
  44. bindProperties(new VCloudApiMetadata().getDefaultProperties());
  45. }
  46. }));
  47. public void testWithIpAllocationModeNONE() throws IOException {
  48. HttpRequest request = HttpRequest.builder().endpoint("http://localhost/key").method("GET")
  49. .build();
  50. BindNetworkConnectionSectionToXmlPayload binder = injector
  51. .getInstance(BindNetworkConnectionSectionToXmlPayload.class);
  52. binder.bindToRequest(
  53. request,
  54. NetworkConnectionSection
  55. .builder()
  56. .type("application/vnd.vmware.vcloud.networkConnectionSection+xml")
  57. .info("Specifies the available VM network connections")
  58. .href(URI.create("https://1.1.1.1/api/v1.0/vApp/vm-1/networkConnectionSection/"))
  59. .connections(
  60. ImmutableSet.<NetworkConnection> of(NetworkConnection.builder().network("none")
  61. .ipAddressAllocationMode(IpAddressAllocationMode.NONE).build())).build());
  62. assertEquals(request.getPayload().getContentMetadata().getContentType(),
  63. "application/vnd.vmware.vcloud.networkConnectionSection+xml");
  64. assertEquals(
  65. request.getPayload().getRawContent(),
  66. "<NetworkConnectionSection xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:ovf=\"http://schemas.dmtf.org/ovf/envelope/1\" href=\"https://1.1.1.1/api/v1.0/vApp/vm-1/networkConnectionSection/\" ovf:required=\"false\" type=\"application/vnd.vmware.vcloud.networkConnectionSection+xml\"><ovf:Info>Specifies the available VM network connections</ovf:Info><NetworkConnection network=\"none\"><NetworkConnectionIndex>0</NetworkConnectionIndex><IsConnected>false</IsConnected><IpAddressAllocationMode>NONE</IpAddressAllocationMode></NetworkConnection></NetworkConnectionSection>");
  67. }
  68. }