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.testing.async;
29  
30  import java.util.function.Consumer;
31  
32  import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
33  import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder;
34  import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
35  import org.apache.hc.client5.http.impl.async.MinimalH2AsyncClient;
36  import org.apache.hc.client5.http.impl.async.MinimalHttpAsyncClient;
37  import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
38  import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
39  import org.apache.hc.client5.testing.async.extension.TestAsyncResources;
40  import org.apache.hc.core5.function.Decorator;
41  import org.apache.hc.core5.http.HttpHost;
42  import org.apache.hc.core5.http.URIScheme;
43  import org.apache.hc.core5.http.config.Http1Config;
44  import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
45  import org.apache.hc.core5.http.protocol.HttpProcessor;
46  import org.apache.hc.core5.http2.config.H2Config;
47  import org.apache.hc.core5.testing.nio.H2TestServer;
48  import org.apache.hc.core5.util.Timeout;
49  import org.junit.jupiter.api.extension.RegisterExtension;
50  
51  public abstract class AbstractIntegrationTestBase {
52  
53      public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
54  
55      @RegisterExtension
56      private final TestAsyncResources testResources;
57  
58      protected AbstractIntegrationTestBase(final URIScheme scheme) {
59          this.testResources = new TestAsyncResources(scheme, TIMEOUT);
60      }
61  
62      public URIScheme scheme() {
63          return testResources.scheme();
64      }
65  
66      public H2TestServer startServer(
67              final H2Config h2Config,
68              final HttpProcessor httpProcessor,
69              final Decorator<AsyncServerExchangeHandler> exchangeHandlerDecorator) throws Exception {
70          return testResources.startServer(h2Config, httpProcessor, exchangeHandlerDecorator);
71      }
72  
73      public H2TestServer startServer(
74              final Http1Config http1Config,
75              final HttpProcessor httpProcessor,
76              final Decorator<AsyncServerExchangeHandler> exchangeHandlerDecorator) throws Exception {
77          return testResources.startServer(http1Config, httpProcessor, exchangeHandlerDecorator);
78      }
79  
80      public HttpHost targetHost() {
81          return testResources.targetHost();
82      }
83  
84      public CloseableHttpAsyncClient startClient(
85              final Consumer<PoolingAsyncClientConnectionManagerBuilder> connManagerCustomizer,
86              final Consumer<HttpAsyncClientBuilder> clientCustomizer) throws Exception {
87          return testResources.startClient(connManagerCustomizer, clientCustomizer);
88      }
89  
90      public CloseableHttpAsyncClient startClient(
91              final Consumer<HttpAsyncClientBuilder> clientCustomizer) throws Exception {
92          return testResources.startClient(clientCustomizer);
93      }
94  
95      public PoolingAsyncClientConnectionManager connManager() {
96          return testResources.connManager();
97      }
98  
99      public CloseableHttpAsyncClient startH2Client(
100             final Consumer<H2AsyncClientBuilder> clientCustomizer) throws Exception {
101         return testResources.startH2Client(clientCustomizer);
102     }
103 
104     public MinimalHttpAsyncClient startMinimalClient(
105             final Http1Config http1Config,
106             final H2Config h2Config,
107             final Consumer<PoolingAsyncClientConnectionManagerBuilder> connManagerCustomizer) throws Exception {
108         return testResources.startMinimalClient(http1Config, h2Config, connManagerCustomizer);
109     }
110 
111     public MinimalHttpAsyncClient startMinimalH2Client(
112             final Http1Config http1Config,
113             final H2Config h2Config,
114             final Consumer<PoolingAsyncClientConnectionManagerBuilder> connManagerCustomizer) throws Exception {
115         return testResources.startMinimalClient(http1Config, h2Config, connManagerCustomizer);
116     }
117 
118     public MinimalH2AsyncClient startMinimalH2Client(final H2Config h2Config) throws Exception {
119         return testResources.startMinimalH2Client(h2Config);
120     }
121 
122 }