PageRenderTime 5130ms CodeModel.GetById 36ms RepoModel.GetById 7ms app.codeStats 0ms

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

http://github.com/jclouds/jclouds
Java | 73 lines | 41 code | 11 blank | 21 comment | 0 complexity | 324f5e8284d7f0fc6b8ae68d5f89f9c9 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jclouds.cloudservers.options;
  18. import static org.jclouds.cloudservers.options.CreateSharedIpGroupOptions.Builder.withServer;
  19. import static org.testng.Assert.assertEquals;
  20. import org.jclouds.http.HttpRequest;
  21. import org.jclouds.json.config.GsonModule;
  22. import org.testng.annotations.Test;
  23. import com.google.common.collect.ImmutableMap;
  24. import com.google.inject.Guice;
  25. import com.google.inject.Injector;
  26. /**
  27. * Tests behavior of {@code ParseFlavorFromJsonResponse}
  28. *
  29. * @author Adrian Cole
  30. */
  31. @Test(groups = "unit")
  32. public class CreateSharedIpGroupOptionsTest {
  33. Injector injector = Guice.createInjector(new GsonModule());
  34. @Test
  35. public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
  36. CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
  37. HttpRequest request = buildRequest(options);
  38. assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\"}}", request.getPayload().getRawContent());
  39. }
  40. private HttpRequest buildRequest(CreateSharedIpGroupOptions options) {
  41. injector.injectMembers(options);
  42. HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();;
  43. options.bindToRequest(request, ImmutableMap.<String,Object>of("name", "foo"));
  44. return request;
  45. }
  46. @Test
  47. public void testWithServer() {
  48. CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
  49. options.withServer(3);
  50. HttpRequest request = buildRequest(options);
  51. assertSharedIpGroup(request);
  52. }
  53. @Test
  54. public void testWithServerStatic() {
  55. CreateSharedIpGroupOptions options = withServer(3);
  56. HttpRequest request = buildRequest(options);
  57. assertSharedIpGroup(request);
  58. }
  59. private void assertSharedIpGroup(HttpRequest request) {
  60. assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\",\"server\":3}}", request.getPayload().getRawContent());
  61. }
  62. }