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

https://github.com/regularfry/jclouds · Java · 86 lines · 52 code · 11 blank · 23 comment · 0 complexity · d82e4225739a9e19d07675351178b82f 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.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
  21. import static org.testng.Assert.assertEquals;
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import java.net.URI;
  25. import java.util.Map;
  26. import javax.inject.Named;
  27. import javax.inject.Singleton;
  28. import org.jclouds.http.HttpRequest;
  29. import org.jclouds.trmk.vcloud_0_8.binders.BindAddNodeServiceToXmlPayload;
  30. import org.jclouds.util.Strings2;
  31. import org.testng.annotations.Test;
  32. import com.google.common.collect.Maps;
  33. import com.google.inject.AbstractModule;
  34. import com.google.inject.Guice;
  35. import com.google.inject.Injector;
  36. import com.google.inject.Provides;
  37. import com.google.inject.name.Names;
  38. /**
  39. * Tests behavior of {@code BindAddNodeServiceToXmlPayload}
  40. *
  41. * @author Adrian Cole
  42. */
  43. @Test(groups = "unit")
  44. public class BindAddNodeServiceToXmlPayloadTest {
  45. Injector injector = Guice.createInjector(new AbstractModule() {
  46. @Override
  47. protected void configure() {
  48. bindConstant().annotatedWith(Names.named(PROPERTY_TERREMARK_EXTENSION_NS)).to(
  49. "urn:tmrk:vCloudExpressExtensions-1.6");
  50. }
  51. @SuppressWarnings("unused")
  52. @Singleton
  53. @Provides
  54. @Named("CreateNodeService")
  55. String provideInstantiateVAppTemplateParams() throws IOException {
  56. InputStream is = getClass().getResourceAsStream("/CreateNodeService.xml");
  57. return Strings2.toStringAndClose(is);
  58. }
  59. });
  60. public void testApplyInputStream() throws IOException {
  61. String expected = Strings2.toStringAndClose(getClass().getResourceAsStream(
  62. "/CreateNodeService-test.xml"));
  63. HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
  64. BindAddNodeServiceToXmlPayload binder = injector
  65. .getInstance(BindAddNodeServiceToXmlPayload.class);
  66. Map<String, String> map = Maps.newHashMap();
  67. map.put("name", "Node for Jim");
  68. map.put("ipAddress", "172.16.20.3");
  69. map.put("port", "80");
  70. map.put("enabled", "false");
  71. map.put("description", "Some test node");
  72. binder.bindToRequest(request, map);
  73. assertEquals(request.getPayload().getRawContent(), expected);
  74. }
  75. }