View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.client.config;
29  
30  import java.net.InetAddress;
31  import java.util.Arrays;
32  
33  import org.apache.http.HttpHost;
34  import org.junit.Assert;
35  import org.junit.Test;
36  
37  public class TestRequestConfig {
38  
39      @Test
40      public void testBasics() {
41          final RequestConfig config = RequestConfig.custom().build();
42          config.toString();
43      }
44  
45      @Test
46      public void testDefaults() {
47          final RequestConfig config = RequestConfig.DEFAULT;
48          Assert.assertEquals(-1, config.getSocketTimeout());
49          Assert.assertEquals(-1, config.getConnectTimeout());
50          Assert.assertEquals(-1, config.getConnectionRequestTimeout());
51          Assert.assertEquals(false, config.isExpectContinueEnabled());
52          Assert.assertEquals(true, config.isAuthenticationEnabled());
53          Assert.assertEquals(true, config.isRedirectsEnabled());
54          Assert.assertEquals(true, config.isRelativeRedirectsAllowed());
55          Assert.assertEquals(false, config.isCircularRedirectsAllowed());
56          Assert.assertEquals(50, config.getMaxRedirects());
57          Assert.assertEquals(null, config.getCookieSpec());
58          Assert.assertEquals(null, config.getLocalAddress());
59          Assert.assertEquals(null, config.getProxy());
60          Assert.assertEquals(null, config.getTargetPreferredAuthSchemes());
61          Assert.assertEquals(null, config.getProxyPreferredAuthSchemes());
62          Assert.assertEquals(true, config.isContentCompressionEnabled());
63      }
64  
65      @Test
66      public void testBuildAndCopy() throws Exception {
67          final RequestConfig config0 = RequestConfig.custom()
68                  .setSocketTimeout(22)
69                  .setConnectTimeout(33)
70                  .setConnectionRequestTimeout(44)
71                  .setExpectContinueEnabled(true)
72                  .setAuthenticationEnabled(false)
73                  .setRedirectsEnabled(false)
74                  .setRelativeRedirectsAllowed(false)
75                  .setCircularRedirectsAllowed(true)
76                  .setMaxRedirects(100)
77                  .setCookieSpec(CookieSpecs.STANDARD)
78                  .setLocalAddress(InetAddress.getLocalHost())
79                  .setProxy(new HttpHost("someproxy"))
80                  .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM))
81                  .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.DIGEST))
82                  .setContentCompressionEnabled(false)
83                  .setNormalizeUri(false)
84                  .build();
85          final RequestConfig config = RequestConfig.copy(config0).build();
86          Assert.assertEquals(22, config.getSocketTimeout());
87          Assert.assertEquals(33, config.getConnectTimeout());
88          Assert.assertEquals(44, config.getConnectionRequestTimeout());
89          Assert.assertEquals(true, config.isExpectContinueEnabled());
90          Assert.assertEquals(false, config.isAuthenticationEnabled());
91          Assert.assertEquals(false, config.isRedirectsEnabled());
92          Assert.assertEquals(false, config.isRelativeRedirectsAllowed());
93          Assert.assertEquals(true, config.isCircularRedirectsAllowed());
94          Assert.assertEquals(100, config.getMaxRedirects());
95          Assert.assertEquals(CookieSpecs.STANDARD, config.getCookieSpec());
96          Assert.assertEquals(InetAddress.getLocalHost(), config.getLocalAddress());
97          Assert.assertEquals(new HttpHost("someproxy"), config.getProxy());
98          Assert.assertEquals(Arrays.asList(AuthSchemes.NTLM), config.getTargetPreferredAuthSchemes());
99          Assert.assertEquals(Arrays.asList(AuthSchemes.DIGEST), config.getProxyPreferredAuthSchemes());
100         Assert.assertEquals(false, config.isContentCompressionEnabled());
101         Assert.assertEquals(false, config.isNormalizeUri());
102     }
103 
104 }