PageRenderTime 41ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/binders/BindTagsToIndexedFormParamsTest.java

https://github.com/ahgittin/legacy-jclouds
Java | 65 lines | 33 code | 9 blank | 23 comment | 0 complexity | e798e7dd64fb705eda2e336628406ff1 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.aws.ec2.binders;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.File;
  22. import org.jclouds.http.HttpRequest;
  23. import org.testng.annotations.Test;
  24. import com.google.common.collect.ImmutableMap;
  25. import com.google.inject.Guice;
  26. import com.google.inject.Injector;
  27. /**
  28. * Tests behavior of {@code BindTagsToIndexedFormParams}
  29. *
  30. * @author grkvlt@apache.org
  31. */
  32. @Test(groups = "unit")
  33. public class BindTagsToIndexedFormParamsTest {
  34. Injector injector = Guice.createInjector();
  35. BindTagsToIndexedFormParams binder = injector.getInstance(BindTagsToIndexedFormParams.class);
  36. public void test() {
  37. HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
  38. request = binder.bindToRequest(request, ImmutableMap.<String, String>builder().put("one", "alpha").put("two", "beta").build());
  39. assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=one&Tag.1.Value=alpha&Tag.2.Key=two&Tag.2.Value=beta");
  40. }
  41. public void testEmpty() {
  42. HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
  43. request = binder.bindToRequest(request, ImmutableMap.<String, String>builder().put("empty", "").build());
  44. assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=empty&Tag.1.Value=");
  45. }
  46. @Test(expectedExceptions = IllegalArgumentException.class)
  47. public void testMustBeArray() {
  48. HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();;
  49. binder.bindToRequest(request, new File("foo"));
  50. }
  51. @Test(expectedExceptions = NullPointerException.class)
  52. public void testNullIsBad() {
  53. HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
  54. binder.bindToRequest(request, null);
  55. }
  56. }