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

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