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

https://github.com/regularfry/jclouds · Java · 79 lines · 43 code · 13 blank · 23 comment · 0 complexity · 27f89d691e3240a04bb31f1e02f27f7f 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.RebuildServerOptions.Builder.withImage;
  21. import static org.testng.Assert.assertEquals;
  22. import java.net.URI;
  23. import java.util.HashMap;
  24. import javax.ws.rs.HttpMethod;
  25. import org.jclouds.http.HttpRequest;
  26. import org.jclouds.json.config.GsonModule;
  27. import org.testng.annotations.Test;
  28. import com.google.inject.Guice;
  29. import com.google.inject.Injector;
  30. /**
  31. * Tests behavior of {@code ParseFlavorFromJsonResponse}
  32. *
  33. * @author Adrian Cole
  34. */
  35. @Test(groups = "unit")
  36. public class RebuildServerOptionsTest {
  37. Injector injector = Guice.createInjector(new GsonModule());
  38. @Test
  39. public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
  40. RebuildServerOptions options = new RebuildServerOptions();
  41. HttpRequest request = buildRequest(options);
  42. assertEquals("{\"rebuild\":{}}", request.getPayload().getRawContent());
  43. }
  44. private HttpRequest buildRequest(RebuildServerOptions options) {
  45. injector.injectMembers(options);
  46. HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
  47. options.bindToRequest(request, new HashMap<String, String>());
  48. return request;
  49. }
  50. @Test
  51. public void testWithServer() {
  52. RebuildServerOptions options = new RebuildServerOptions();
  53. options.withImage(3);
  54. HttpRequest request = buildRequest(options);
  55. assertRebuild(request);
  56. }
  57. @Test
  58. public void testWithServerStatic() {
  59. RebuildServerOptions options = withImage(3);
  60. HttpRequest request = buildRequest(options);
  61. assertRebuild(request);
  62. }
  63. private void assertRebuild(HttpRequest request) {
  64. assertEquals("{\"rebuild\":{\"imageId\":3}}", request.getPayload().getRawContent());
  65. }
  66. }