PageRenderTime 98ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindDriveToPlainTextStringTest.java

https://github.com/chmouel/jclouds
Java | 92 lines | 54 code | 15 blank | 23 comment | 0 complexity | cee21524ec4447002ad780600d1f159b MD5 | raw file
Possible License(s): Apache-2.0
  1. /**
  2. *
  3. * Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
  4. *
  5. * ====================================================================
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * 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, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.jclouds.elasticstack.binders;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.IOException;
  22. import java.net.URI;
  23. import java.util.Map;
  24. import javax.ws.rs.core.MediaType;
  25. import org.jclouds.elasticstack.domain.ClaimType;
  26. import org.jclouds.elasticstack.domain.CreateDriveRequest;
  27. import org.jclouds.elasticstack.domain.Drive;
  28. import org.jclouds.elasticstack.domain.DriveData;
  29. import org.jclouds.elasticstack.functions.CreateDriveRequestToMap;
  30. import org.jclouds.elasticstack.functions.DriveDataToMap;
  31. import org.jclouds.http.HttpRequest;
  32. import org.jclouds.util.Utils;
  33. import org.testng.annotations.Test;
  34. import com.google.common.base.Function;
  35. import com.google.common.collect.ImmutableMap;
  36. import com.google.common.collect.ImmutableSet;
  37. import com.google.inject.AbstractModule;
  38. import com.google.inject.Guice;
  39. import com.google.inject.TypeLiteral;
  40. /**
  41. *
  42. * @author Adrian Cole
  43. */
  44. @Test(groups = { "unit" })
  45. public class BindDriveToPlainTextStringTest {
  46. private static final BindDriveToPlainTextString FN = Guice.createInjector(new AbstractModule() {
  47. @Override
  48. protected void configure() {
  49. bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
  50. }).to(CreateDriveRequestToMap.class);
  51. bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
  52. }).to(DriveDataToMap.class);
  53. }
  54. }).getInstance(BindDriveToPlainTextString.class);
  55. public void testSimple() {
  56. HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
  57. FN.bindToRequest(request, new CreateDriveRequest.Builder().name("foo").size(100l).build());
  58. assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
  59. assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100");
  60. }
  61. public void testComplete() throws IOException {
  62. CreateDriveRequest input = new CreateDriveRequest.Builder()
  63. .name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
  64. //
  65. .size(8589934592l)//
  66. .claimType(ClaimType.SHARED)//
  67. .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
  68. .tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
  69. .encryptionCipher("aes-xts-plain").avoid(ImmutableSet.of("avoid1")).build();
  70. HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
  71. FN.bindToRequest(request, input);
  72. assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
  73. assertEquals(request.getPayload().getRawContent(),
  74. Utils.toStringAndClose(BindDriveToPlainTextStringTest.class
  75. .getResourceAsStream("/create_drive.txt")));
  76. }
  77. }