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      }
63  
64      @Test
65      public void testBuildAndCopy() throws Exception {
66          final RequestConfig config0 = RequestConfig.custom()
67                  .setSocketTimeout(22)
68                  .setConnectTimeout(33)
69                  .setConnectionRequestTimeout(44)
70                  .setExpectContinueEnabled(true)
71                  .setAuthenticationEnabled(false)
72                  .setRedirectsEnabled(false)
73                  .setRelativeRedirectsAllowed(false)
74                  .setCircularRedirectsAllowed(true)
75                  .setMaxRedirects(100)
76                  .setCookieSpec(CookieSpecs.STANDARD)
77                  .setLocalAddress(InetAddress.getLocalHost())
78                  .setProxy(new HttpHost("someproxy"))
79                  .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM))
80                  .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.DIGEST))
81                  .build();
82          final RequestConfig config = RequestConfig.copy(config0).build();
83          Assert.assertEquals(22, config.getSocketTimeout());
84          Assert.assertEquals(33, config.getConnectTimeout());
85          Assert.assertEquals(44, config.getConnectionRequestTimeout());
86          Assert.assertEquals(true, config.isExpectContinueEnabled());
87          Assert.assertEquals(false, config.isAuthenticationEnabled());
88          Assert.assertEquals(false, config.isRedirectsEnabled());
89          Assert.assertEquals(false, config.isRelativeRedirectsAllowed());
90          Assert.assertEquals(true, config.isCircularRedirectsAllowed());
91          Assert.assertEquals(100, config.getMaxRedirects());
92          Assert.assertEquals(CookieSpecs.STANDARD, config.getCookieSpec());
93          Assert.assertEquals(InetAddress.getLocalHost(), config.getLocalAddress());
94          Assert.assertEquals(new HttpHost("someproxy"), config.getProxy());
95          Assert.assertEquals(Arrays.asList(AuthSchemes.NTLM), config.getTargetPreferredAuthSchemes());
96          Assert.assertEquals(Arrays.asList(AuthSchemes.DIGEST), config.getProxyPreferredAuthSchemes());
97      }
98  
99  }