Statistics
| Branch: | Revision:

root / extensions / httpnio / src / test / java / org / jclouds / http / httpnio / util / NioHttpUtilsTest.java @ 35e7942d

History | View | Annotate | Download (2.6 kB)

1
/**
2
 *
3
 * Copyright (C) 2009 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.http.httpnio.util;
20

    
21
import static org.testng.Assert.assertEquals;
22

    
23
import java.net.URI;
24

    
25
import org.apache.http.HttpEntityEnclosingRequest;
26
import org.jclouds.http.HttpRequest;
27
import org.mortbay.jetty.HttpMethods;
28
import org.testng.annotations.DataProvider;
29
import org.testng.annotations.Test;
30

    
31
import com.google.common.collect.ImmutableMultimap;
32

    
33
/**
34
 * Tests parsing of nio
35
 * 
36
 * @author Adrian Cole
37
 */
38
@Test(testName = "httpnio.NioHttpUtilsTest")
39
public class NioHttpUtilsTest {
40
   @DataProvider(name = "gets")
41
   public Object[][] createData() {
42
      return new Object[][] { { "object" }, { "/path" }, { "sp%20ace" }, { "unic₪de" },
43
               { "qu?stion" } };
44
   }
45

    
46
   @Test(dataProvider = "gets")
47
   public void testConvert(String uri) {
48
      HttpEntityEnclosingRequest apacheRequest = NioHttpUtils
49
               .convertToApacheRequest(new HttpRequest(HttpMethods.GET, URI
50
                        .create("https://s3.amazonaws.com:443/" + uri), ImmutableMultimap.of(
51
                        "Host", "s3.amazonaws.com")));
52
      assertEquals(apacheRequest.getHeaders("Host")[0].getValue(), "s3.amazonaws.com");
53
      assertEquals(apacheRequest.getRequestLine().getMethod(), "GET");
54
      assertEquals(apacheRequest.getRequestLine().getUri(), "/" + uri);
55
   }
56

    
57
   public void testConvertWithQuery() {
58
      HttpEntityEnclosingRequest apacheRequest = NioHttpUtils
59
               .convertToApacheRequest(new HttpRequest(HttpMethods.GET, URI
60
                        .create("https://s3.amazonaws.com:443/?max-keys=0"), ImmutableMultimap.of(
61
                        "Host", "s3.amazonaws.com")));
62
      assertEquals(apacheRequest.getHeaders("Host")[0].getValue(), "s3.amazonaws.com");
63
      assertEquals(apacheRequest.getRequestLine().getMethod(), "GET");
64
      assertEquals(apacheRequest.getRequestLine().getUri(), "/?max-keys=0");
65
   }
66
}