/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java
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 */
19package org.jclouds.cloudsigma.binders;
20
21import static org.testng.Assert.assertEquals;
22
23import java.io.IOException;
24import java.net.URI;
25import java.util.Map;
26
27import javax.ws.rs.core.MediaType;
28
29import org.jclouds.cloudsigma.domain.ClaimType;
30import org.jclouds.cloudsigma.domain.Drive;
31import org.jclouds.cloudsigma.domain.DriveData;
32import org.jclouds.cloudsigma.functions.BaseDriveToMap;
33import org.jclouds.cloudsigma.functions.DriveDataToMap;
34import org.jclouds.http.HttpRequest;
35import org.jclouds.util.Strings2;
36import org.testng.annotations.Test;
37
38import com.google.common.base.Function;
39import com.google.common.collect.ImmutableSet;
40import com.google.inject.AbstractModule;
41import com.google.inject.Guice;
42import com.google.inject.TypeLiteral;
43
44/**
45 *
46 * @author Adrian Cole
47 */
48@Test(groups = { "unit" })
49public class BindDriveDataToPlainTextStringTest {
50
51 private static final BindDriveDataToPlainTextString FN = Guice.createInjector(new AbstractModule() {
52
53 @Override
54 protected void configure() {
55 bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
56 }).to(BaseDriveToMap.class);
57 bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
58 }).to(DriveDataToMap.class);
59 }
60
61 }).getInstance(BindDriveDataToPlainTextString.class);
62
63 public void testSimple() {
64 HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
65 FN.bindToRequest(request, new DriveData.Builder().name("foo").size(100l).build());
66 assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
67 assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100");
68 }
69
70 public void testComplete() throws IOException {
71 DriveData input = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
72 //
73 .size(8589934592l)//
74 .claimType(ClaimType.SHARED)//
75 .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
76 .use(ImmutableSet.of("tag1", "tag2"))//
77 .build();
78
79 HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
80 FN.bindToRequest(request, input);
81 assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
82 assertEquals(request.getPayload().getRawContent(),
83 Strings2.toStringAndClose(BindDriveDataToPlainTextStringTest.class.getResourceAsStream("/drive_data.txt")));
84
85 }
86}