1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 }