Skip to content

Commit 6c2ee9b

Browse files
committed
Add test
1 parent 87ae85e commit 6c2ee9b

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
package org.apache.hc.client5.http.impl.async;
28+
29+
import org.apache.hc.core5.http.config.CharCodingConfig;
30+
import org.apache.hc.core5.http2.config.H2Config;
31+
import org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler;
32+
import org.apache.hc.core5.reactor.IOEventHandler;
33+
import org.apache.hc.core5.reactor.ProtocolIOSession;
34+
import org.junit.jupiter.api.Assertions;
35+
import org.junit.jupiter.api.Test;
36+
import org.mockito.Mockito;
37+
38+
class TestH2TunnelProtocolStarter {
39+
40+
@Test
41+
void testCreatesMinimalH2HandlerWithoutPushOrLogging() {
42+
final H2TunnelProtocolStarter starter = new H2TunnelProtocolStarter(
43+
H2Config.DEFAULT, CharCodingConfig.DEFAULT);
44+
final ProtocolIOSession ioSession = Mockito.mock(ProtocolIOSession.class);
45+
Mockito.when(ioSession.getId()).thenReturn("test-tunnel");
46+
47+
final IOEventHandler handler = starter.createHandler(ioSession, null);
48+
49+
Assertions.assertNotNull(handler);
50+
Assertions.assertInstanceOf(ClientH2PrefaceHandler.class, handler);
51+
}
52+
53+
@Test
54+
void testDefaultsWhenNullConfig() {
55+
final H2TunnelProtocolStarter starter = new H2TunnelProtocolStarter(null, null);
56+
final ProtocolIOSession ioSession = Mockito.mock(ProtocolIOSession.class);
57+
Mockito.when(ioSession.getId()).thenReturn("test-tunnel-null");
58+
59+
final IOEventHandler handler = starter.createHandler(ioSession, null);
60+
61+
Assertions.assertNotNull(handler);
62+
Assertions.assertInstanceOf(ClientH2PrefaceHandler.class, handler);
63+
}
64+
65+
@Test
66+
void testCustomH2ConfigIsRespected() {
67+
final H2Config customConfig = H2Config.custom()
68+
.setMaxFrameSize(32768)
69+
.setInitialWindowSize(128 * 1024)
70+
.setPushEnabled(false)
71+
.build();
72+
final H2TunnelProtocolStarter starter = new H2TunnelProtocolStarter(
73+
customConfig, CharCodingConfig.DEFAULT);
74+
final ProtocolIOSession ioSession = Mockito.mock(ProtocolIOSession.class);
75+
Mockito.when(ioSession.getId()).thenReturn("test-tunnel-custom");
76+
77+
final IOEventHandler handler = starter.createHandler(ioSession, null);
78+
79+
Assertions.assertNotNull(handler);
80+
Assertions.assertInstanceOf(ClientH2PrefaceHandler.class, handler);
81+
}
82+
83+
}

0 commit comments

Comments
 (0)