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.net.InetSocketAddress;
31 import java.util.function.Consumer;
32
33 import org.apache.hc.client5.testing.extension.async.ClientProtocolLevel;
34 import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
35 import org.apache.hc.client5.testing.extension.async.TestAsyncClient;
36 import org.apache.hc.client5.testing.extension.async.TestAsyncClientBuilder;
37 import org.apache.hc.client5.testing.extension.async.TestAsyncResources;
38 import org.apache.hc.client5.testing.extension.async.TestAsyncServer;
39 import org.apache.hc.client5.testing.extension.async.TestAsyncServerBootstrap;
40 import org.apache.hc.core5.http.HttpHost;
41 import org.apache.hc.core5.http.URIScheme;
42 import org.apache.hc.core5.util.Timeout;
43 import org.junit.jupiter.api.extension.RegisterExtension;
44
45 abstract class AbstractIntegrationTestBase {
46
47 public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
48
49 @RegisterExtension
50 private final TestAsyncResources testResources;
51
52 protected AbstractIntegrationTestBase(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
53 this.testResources = new TestAsyncResources(scheme, clientProtocolLevel, serverProtocolLevel, TIMEOUT);
54 }
55
56 public URIScheme scheme() {
57 return testResources.scheme();
58 }
59
60 public ServerProtocolLevel getServerProtocolLevel() {
61 return testResources.getServerProtocolLevel();
62 }
63
64 public ClientProtocolLevel getClientProtocolLevel() {
65 return testResources.getClientProtocolLevel();
66 }
67
68 public void configureServer(final Consumer<TestAsyncServerBootstrap> serverCustomizer) {
69 testResources.configureServer(serverCustomizer);
70 }
71
72 public HttpHost startServer() throws Exception {
73 final TestAsyncServer server = testResources.server();
74 final InetSocketAddress inetSocketAddress = server.start();
75 return new HttpHost(testResources.scheme().id, "localhost", inetSocketAddress.getPort());
76 }
77
78 public void configureClient(final Consumer<TestAsyncClientBuilder> clientCustomizer) {
79 testResources.configureClient(clientCustomizer);
80 }
81
82 public TestAsyncClient startClient() throws Exception {
83 final TestAsyncClient client = testResources.client();
84 client.start();
85 return client;
86 }
87
88 }