PageRenderTime 5173ms CodeModel.GetById 15ms RepoModel.GetById 2ms app.codeStats 1ms

/apis/atmos/src/test/java/org/jclouds/atmos/binders/BindUserMetadataToHeadersTest.java

http://github.com/jclouds/jclouds
Java | 85 lines | 55 code | 11 blank | 19 comment | 0 complexity | 5727ea8b5e792a0762b85c5e754d6006 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.atmos.binders;
  18. import static org.testng.Assert.assertEquals;
  19. import java.io.File;
  20. import org.jclouds.atmos.domain.UserMetadata;
  21. import org.jclouds.http.HttpRequest;
  22. import org.testng.annotations.Test;
  23. import com.google.inject.Guice;
  24. import com.google.inject.Injector;
  25. /**
  26. * Tests behavior of {@code BindUserMetadataToHeaders}
  27. */
  28. @Test(groups = "unit")
  29. public class BindUserMetadataToHeadersTest {
  30. Injector injector = Guice.createInjector();
  31. BindUserMetadataToHeaders binder = injector.getInstance(BindUserMetadataToHeaders.class);
  32. public void testMeta() {
  33. UserMetadata metadata = new UserMetadata();
  34. metadata.getMetadata().put("apple", "bear");
  35. metadata.getMetadata().put("sushi", "king");
  36. HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
  37. request = binder.bindToRequest(request, metadata);
  38. assertEquals(request.getFirstHeaderOrNull("x-emc-meta"), "apple=bear,sushi=king");
  39. }
  40. public void testListableMeta() {
  41. UserMetadata metadata = new UserMetadata();
  42. metadata.getListableMetadata().put("apple", "bear");
  43. metadata.getListableMetadata().put("sushi", "king");
  44. HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
  45. request = binder.bindToRequest(request, metadata);
  46. assertEquals(request.getFirstHeaderOrNull("x-emc-listable-meta"), "apple=bear,sushi=king");
  47. }
  48. public void testTags() {
  49. UserMetadata tagsdata = new UserMetadata();
  50. tagsdata.getTags().add("apple");
  51. tagsdata.getTags().add("sushi");
  52. HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
  53. request = binder.bindToRequest(request, tagsdata);
  54. assertEquals(request.getFirstHeaderOrNull("x-emc-tags"), "apple,sushi");
  55. }
  56. public void testListableTags() {
  57. UserMetadata tagsdata = new UserMetadata();
  58. tagsdata.getListableTags().add("apple");
  59. tagsdata.getListableTags().add("sushi");
  60. HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
  61. request = binder.bindToRequest(request, tagsdata);
  62. assertEquals(request.getFirstHeaderOrNull("x-emc-listable-tags"), "apple,sushi");
  63. }
  64. @Test(expectedExceptions = IllegalArgumentException.class)
  65. public void testMustBeUserMetadata() {
  66. HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
  67. binder.bindToRequest(request, new File("foo"));
  68. }
  69. @Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
  70. public void testNullIsBad() {
  71. HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
  72. binder.bindToRequest(request, null);
  73. }
  74. }