/apis/cloudservers/src/test/java/org/jclouds/cloudservers/options/CreateSharedIpGroupOptionsTest.java

https://github.com/andreisavu/jclouds · Java · 75 lines · 41 code · 11 blank · 23 comment · 0 complexity · ce94dfa00f1e05445f91dd829bc5ae56 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.cloudservers.options;
  20. import static org.jclouds.cloudservers.options.CreateSharedIpGroupOptions.Builder.withServer;
  21. import static org.testng.Assert.assertEquals;
  22. import org.jclouds.http.HttpRequest;
  23. import org.jclouds.json.config.GsonModule;
  24. import org.testng.annotations.Test;
  25. import com.google.common.collect.ImmutableMap;
  26. import com.google.inject.Guice;
  27. import com.google.inject.Injector;
  28. /**
  29. * Tests behavior of {@code ParseFlavorFromJsonResponse}
  30. *
  31. * @author Adrian Cole
  32. */
  33. @Test(groups = "unit")
  34. public class CreateSharedIpGroupOptionsTest {
  35. Injector injector = Guice.createInjector(new GsonModule());
  36. @Test
  37. public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
  38. CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
  39. HttpRequest request = buildRequest(options);
  40. assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\"}}", request.getPayload().getRawContent());
  41. }
  42. private HttpRequest buildRequest(CreateSharedIpGroupOptions options) {
  43. injector.injectMembers(options);
  44. HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();;
  45. options.bindToRequest(request, ImmutableMap.<String,Object>of("name", "foo"));
  46. return request;
  47. }
  48. @Test
  49. public void testWithServer() {
  50. CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
  51. options.withServer(3);
  52. HttpRequest request = buildRequest(options);
  53. assertSharedIpGroup(request);
  54. }
  55. @Test
  56. public void testWithServerStatic() {
  57. CreateSharedIpGroupOptions options = withServer(3);
  58. HttpRequest request = buildRequest(options);
  59. assertSharedIpGroup(request);
  60. }
  61. private void assertSharedIpGroup(HttpRequest request) {
  62. assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\",\"server\":3}}", request.getPayload().getRawContent());
  63. }
  64. }