PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java

https://github.com/raschyoung/jclouds
Java | 86 lines | 50 code | 13 blank | 23 comment | 0 complexity | 05168390f46b26aa6c5de82c9c817872 MD5 | raw file
  1. /**
  2. *
  3. * Copyright (C) 2011 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.cloudsigma.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.cloudsigma.domain.ClaimType;
  26. import org.jclouds.cloudsigma.domain.Drive;
  27. import org.jclouds.cloudsigma.domain.DriveData;
  28. import org.jclouds.cloudsigma.functions.BaseDriveToMap;
  29. import org.jclouds.cloudsigma.functions.DriveDataToMap;
  30. import org.jclouds.http.HttpRequest;
  31. import org.jclouds.util.Strings2;
  32. import org.testng.annotations.Test;
  33. import com.google.common.base.Function;
  34. import com.google.common.collect.ImmutableSet;
  35. import com.google.inject.AbstractModule;
  36. import com.google.inject.Guice;
  37. import com.google.inject.TypeLiteral;
  38. /**
  39. *
  40. * @author Adrian Cole
  41. */
  42. @Test(groups = { "unit" })
  43. public class BindDriveDataToPlainTextStringTest {
  44. private static final BindDriveDataToPlainTextString FN = Guice.createInjector(new AbstractModule() {
  45. @Override
  46. protected void configure() {
  47. bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
  48. }).to(BaseDriveToMap.class);
  49. bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
  50. }).to(DriveDataToMap.class);
  51. }
  52. }).getInstance(BindDriveDataToPlainTextString.class);
  53. public void testSimple() {
  54. HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
  55. FN.bindToRequest(request, new DriveData.Builder().name("foo").size(100l).build());
  56. assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
  57. assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100");
  58. }
  59. public void testComplete() throws IOException {
  60. DriveData input = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
  61. //
  62. .size(8589934592l)//
  63. .claimType(ClaimType.SHARED)//
  64. .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
  65. .use(ImmutableSet.of("tag1", "tag2"))//
  66. .build();
  67. HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
  68. FN.bindToRequest(request, input);
  69. assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
  70. assertEquals(request.getPayload().getRawContent(),
  71. Strings2.toStringAndClose(BindDriveDataToPlainTextStringTest.class.getResourceAsStream("/drive_data.txt")));
  72. }
  73. }