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 package org.apache.hc.client5.testing.async;
28
29 import java.util.function.Consumer;
30
31 import org.apache.hc.client5.http.AuthenticationStrategy;
32 import org.apache.hc.client5.http.auth.AuthSchemeFactory;
33 import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
34 import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder;
35 import org.apache.hc.core5.function.Decorator;
36 import org.apache.hc.core5.http.HttpRequestInterceptor;
37 import org.apache.hc.core5.http.HttpResponseInterceptor;
38 import org.apache.hc.core5.http.URIScheme;
39 import org.apache.hc.core5.http.config.Lookup;
40 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
41 import org.apache.hc.core5.http2.config.H2Config;
42 import org.apache.hc.core5.testing.nio.H2TestServer;
43
44 public abstract class TestH2ClientAuthentication extends AbstractHttpAsyncClientAuthenticationTest<CloseableHttpAsyncClient> {
45
46 public TestH2ClientAuthentication(final URIScheme scheme) {
47 super(scheme);
48 }
49
50 @Override
51 protected H2TestServer startServer(final Decorator<AsyncServerExchangeHandler> exchangeHandlerDecorator) throws Exception {
52 return startServer(H2Config.DEFAULT, null, exchangeHandlerDecorator);
53 }
54
55 @Override
56 protected CloseableHttpAsyncClient startClientCustom(final Consumer<TestClientBuilder> clientCustomizer) throws Exception {
57
58 return startH2Client(new Consumer<H2AsyncClientBuilder>() {
59
60 @Override
61 public void accept(final H2AsyncClientBuilder builder) {
62
63 clientCustomizer.accept(new TestClientBuilder() {
64
65 @Override
66 public TestClientBuilder setDefaultAuthSchemeRegistry(final Lookup<AuthSchemeFactory> authSchemeRegistry) {
67 builder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
68 return this;
69 }
70
71 @Override
72 public TestClientBuilder setTargetAuthenticationStrategy(final AuthenticationStrategy targetAuthStrategy) {
73 builder.setTargetAuthenticationStrategy(targetAuthStrategy);
74 return this;
75 }
76
77 @Override
78 public TestClientBuilder addResponseInterceptor(final HttpResponseInterceptor responseInterceptor) {
79 builder.addResponseInterceptorLast(responseInterceptor);
80 return this;
81 }
82
83 @Override
84 public TestClientBuilder addRequestInterceptor(final HttpRequestInterceptor requestInterceptor) {
85 builder.addRequestInterceptorFirst(requestInterceptor);
86 return this;
87 }
88
89 });
90
91 }
92
93 });
94 }
95
96 }