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

https://github.com/andreisavu/jclouds · Java · 86 lines · 48 code · 15 blank · 23 comment · 0 complexity · f4d98b3dbbf9daecc5d7e806e8ee95c6 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.easymock.EasyMock.createMock;
  21. import static org.easymock.EasyMock.expect;
  22. import static org.easymock.EasyMock.replay;
  23. import static org.easymock.EasyMock.verify;
  24. import java.io.IOException;
  25. import java.net.URI;
  26. import java.util.Map;
  27. import org.jclouds.rest.internal.GeneratedHttpRequest;
  28. import org.jclouds.vcloud.VCloudApiMetadata;
  29. import org.nnsoft.guice.rocoto.Rocoto;
  30. import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
  31. import org.testng.annotations.Test;
  32. import com.google.common.collect.Maps;
  33. import com.google.inject.Guice;
  34. import com.google.inject.Injector;
  35. /**
  36. * Tests behavior of {@code BindUndeployVAppParamsToXmlPayload}
  37. *
  38. * @author Adrian Cole
  39. */
  40. @Test(groups = "unit")
  41. public class BindUndeployVAppParamsToXmlPayloadTest {
  42. Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
  43. @Override
  44. protected void bindConfigurations() {
  45. bindProperties(new VCloudApiMetadata().getDefaultProperties());
  46. }
  47. }));
  48. public void testSaveStateTrue() throws IOException {
  49. String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>";
  50. GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
  51. expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
  52. request.setPayload(expected);
  53. replay(request);
  54. BindUndeployVAppParamsToXmlPayload binder = injector.getInstance(BindUndeployVAppParamsToXmlPayload.class);
  55. Map<String, Object> map = Maps.newHashMap();
  56. map.put("saveState", "true");
  57. binder.bindToRequest(request, map);
  58. verify(request);
  59. }
  60. public void testDefault() throws IOException {
  61. String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>";
  62. GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
  63. expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
  64. request.setPayload(expected);
  65. replay(request);
  66. BindUndeployVAppParamsToXmlPayload binder = injector.getInstance(BindUndeployVAppParamsToXmlPayload.class);
  67. Map<String, Object> map = Maps.newHashMap();
  68. binder.bindToRequest(request, map);
  69. verify(request);
  70. }
  71. }