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.hc.client5.http.config;
29  
30  import java.util.Collections;
31  import java.util.concurrent.TimeUnit;
32  
33  import org.apache.hc.client5.http.auth.StandardAuthScheme;
34  import org.apache.hc.client5.http.cookie.StandardCookieSpec;
35  import org.apache.hc.core5.util.TimeValue;
36  import org.apache.hc.core5.util.Timeout;
37  import org.junit.jupiter.api.Assertions;
38  import org.junit.jupiter.api.Test;
39  
40  public class TestRequestConfig {
41  
42      @Test
43      public void testBasics() {
44          final RequestConfig config = RequestConfig.custom().build();
45          config.toString();
46      }
47  
48      @Test
49      public void testDefaults() {
50          final RequestConfig config = RequestConfig.DEFAULT;
51          Assertions.assertEquals(Timeout.ofMinutes(3), config.getConnectionRequestTimeout());
52          Assertions.assertFalse(config.isExpectContinueEnabled());
53          Assertions.assertTrue(config.isAuthenticationEnabled());
54          Assertions.assertTrue(config.isRedirectsEnabled());
55          Assertions.assertFalse(config.isCircularRedirectsAllowed());
56          Assertions.assertEquals(50, config.getMaxRedirects());
57          Assertions.assertNull(config.getCookieSpec());
58          Assertions.assertNull(config.getTargetPreferredAuthSchemes());
59          Assertions.assertNull(config.getProxyPreferredAuthSchemes());
60          Assertions.assertTrue(config.isContentCompressionEnabled());
61      }
62  
63      @Test
64      public void testBuildAndCopy() throws Exception {
65          final RequestConfig config0 = RequestConfig.custom()
66                  .setConnectionRequestTimeout(44, TimeUnit.MILLISECONDS)
67                  .setExpectContinueEnabled(true)
68                  .setAuthenticationEnabled(false)
69                  .setRedirectsEnabled(false)
70                  .setCircularRedirectsAllowed(true)
71                  .setMaxRedirects(100)
72                  .setCookieSpec(StandardCookieSpec.STRICT)
73                  .setTargetPreferredAuthSchemes(Collections.singletonList(StandardAuthScheme.NTLM))
74                  .setProxyPreferredAuthSchemes(Collections.singletonList(StandardAuthScheme.DIGEST))
75                  .setContentCompressionEnabled(false)
76                  .build();
77          final RequestConfig config = RequestConfig.copy(config0).build();
78          Assertions.assertEquals(TimeValue.ofMilliseconds(44), config.getConnectionRequestTimeout());
79          Assertions.assertTrue(config.isExpectContinueEnabled());
80          Assertions.assertFalse(config.isAuthenticationEnabled());
81          Assertions.assertFalse(config.isRedirectsEnabled());
82          Assertions.assertTrue(config.isCircularRedirectsAllowed());
83          Assertions.assertEquals(100, config.getMaxRedirects());
84          Assertions.assertEquals(StandardCookieSpec.STRICT, config.getCookieSpec());
85          Assertions.assertEquals(Collections.singletonList(StandardAuthScheme.NTLM), config.getTargetPreferredAuthSchemes());
86          Assertions.assertEquals(Collections.singletonList(StandardAuthScheme.DIGEST), config.getProxyPreferredAuthSchemes());
87          Assertions.assertFalse(config.isContentCompressionEnabled());
88      }
89  
90  }