PageRenderTime 66ms CodeModel.GetById 34ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 1ms

/apis/ec2/src/test/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParamsTest.java

https://github.com/gnodet/jclouds
Java | 74 lines | 41 code | 10 blank | 23 comment | 0 complexity | 916b58da15d47acdbfb13fe1dba1a5b0 MD5 | raw file
 1/**
 2 * Licensed to jclouds, Inc. (jclouds) under one or more
 3 * contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  jclouds licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.ec2.binders;
20
21import static org.testng.Assert.assertEquals;
22
23import java.io.File;
24import java.net.URI;
25import java.util.Date;
26import java.util.Map;
27
28import javax.ws.rs.HttpMethod;
29
30import org.jclouds.ec2.domain.Attachment.Status;
31import org.jclouds.ec2.domain.BlockDevice;
32import org.jclouds.http.HttpRequest;
33import org.testng.annotations.Test;
34
35import com.google.common.collect.Maps;
36import com.google.inject.Guice;
37import com.google.inject.Injector;
38
39/**
40 * Tests behavior of {@code BindBlockDeviceMappingToIndexedFormParams}
41 * 
42 * @author Adrian Cole
43 */
44@Test(groups = "unit")
45public class BindBlockDeviceMappingToIndexedFormParamsTest {
46   Injector injector = Guice.createInjector();
47   BindBlockDeviceMappingToIndexedFormParams binder = injector
48         .getInstance(BindBlockDeviceMappingToIndexedFormParams.class);
49
50   public void testMapping() {
51      Map<String, BlockDevice> mapping = Maps.newLinkedHashMap();
52      mapping.put("apple", new BlockDevice("appleId", true));
53      Date date = new Date(999999l);
54      mapping.put("cranberry", new BlockDevice("cranberry", Status.ATTACHED, date, false));
55
56      HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
57      request = binder.bindToRequest(request, mapping);
58      assertEquals(
59            request.getPayload().getRawContent(),
60            "BlockDeviceMapping.1.Ebs.VolumeId=appleId&BlockDeviceMapping.1.DeviceName=apple&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.2.Ebs.VolumeId=cranberry&BlockDeviceMapping.2.DeviceName=cranberry&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false");
61   }
62
63   @Test(expectedExceptions = IllegalArgumentException.class)
64   public void testMustBeBlockDeviceMapping() {
65      HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
66      binder.bindToRequest(request, new File("foo"));
67   }
68
69   @Test(expectedExceptions = NullPointerException.class)
70   public void testNullIsBad() {
71      HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build();
72      binder.bindToRequest(request, null);
73   }
74}