/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java

http://github.com/jclouds/jclouds · Java · 87 lines · 52 code · 14 blank · 21 comment · 0 complexity · 47bb034ab01224b4a22874c981c4f732 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.cloudsigma.binders;
  18. import static org.testng.Assert.assertEquals;
  19. import java.io.IOException;
  20. import java.util.Map;
  21. import javax.ws.rs.core.MediaType;
  22. import org.jclouds.cloudsigma.domain.ClaimType;
  23. import org.jclouds.cloudsigma.domain.CreateDriveRequest;
  24. import org.jclouds.cloudsigma.domain.Drive;
  25. import org.jclouds.cloudsigma.domain.DriveData;
  26. import org.jclouds.cloudsigma.functions.BaseDriveToMap;
  27. import org.jclouds.cloudsigma.functions.DriveDataToMap;
  28. import org.jclouds.http.HttpRequest;
  29. import org.jclouds.util.Strings2;
  30. import org.testng.annotations.Test;
  31. import com.google.common.base.Function;
  32. import com.google.common.collect.ImmutableSet;
  33. import com.google.inject.AbstractModule;
  34. import com.google.inject.Guice;
  35. import com.google.inject.TypeLiteral;
  36. /**
  37. *
  38. * @author Adrian Cole
  39. */
  40. @Test(groups = { "unit" })
  41. public class BindDriveToPlainTextStringTest {
  42. private static final BindDriveToPlainTextString FN = Guice.createInjector(new AbstractModule() {
  43. @Override
  44. protected void configure() {
  45. bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
  46. }).to(BaseDriveToMap.class);
  47. bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
  48. }).to(DriveDataToMap.class);
  49. }
  50. }).getInstance(BindDriveToPlainTextString.class);
  51. public void testSimple() {
  52. HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build();
  53. FN.bindToRequest(request, new CreateDriveRequest.Builder().name("foo").size(100l).build());
  54. assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
  55. assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100");
  56. }
  57. public void testComplete() throws IOException {
  58. CreateDriveRequest input = new CreateDriveRequest.Builder()
  59. .name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
  60. //
  61. .size(8589934592l)//
  62. .claimType(ClaimType.SHARED)//
  63. .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
  64. .use(ImmutableSet.of("tag1", "tag2"))//
  65. .encryptionCipher("aes-xts-plain").avoid(ImmutableSet.of("avoid1")).build();
  66. HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build();
  67. FN.bindToRequest(request, input);
  68. assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
  69. assertEquals(request.getPayload().getRawContent(),
  70. Strings2.toStringAndClose(BindDriveToPlainTextStringTest.class
  71. .getResourceAsStream("/create_drive.txt")));
  72. }
  73. }