PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/regularfry/jclouds
Java | 62 lines | 29 code | 10 blank | 23 comment | 0 complexity | e5dd078fefdfc79869a94a0a626c0e34 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;
25
26import javax.ws.rs.HttpMethod;
27
28import org.jclouds.http.HttpRequest;
29import org.testng.annotations.Test;
30
31import com.google.inject.Guice;
32import com.google.inject.Injector;
33
34/**
35 * Tests behavior of {@code BindInstanceIdsToIndexedFormParams}
36 * 
37 * @author Adrian Cole
38 */
39@Test(groups = "unit")
40public class BindInstanceIdsToIndexedFormParamsTest {
41   Injector injector = Guice.createInjector();
42   BindInstanceIdsToIndexedFormParams binder = injector.getInstance(BindInstanceIdsToIndexedFormParams.class);
43
44   public void test() {
45
46      HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
47      request = binder.bindToRequest(request, new String[] { "alpha", "omega" });
48      assertEquals(request.getPayload().getRawContent(), "InstanceId.1=alpha&InstanceId.2=omega");
49   }
50
51   @Test(expectedExceptions = IllegalArgumentException.class)
52   public void testMustBeArray() {
53      HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
54      binder.bindToRequest(request, new File("foo"));
55   }
56
57   @Test(expectedExceptions = NullPointerException.class)
58   public void testNullIsBad() {
59      HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build();
60      binder.bindToRequest(request, null);
61   }
62}