1
+ /*
2
+ * Copyright 2005-2022 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
1
17
package org .springframework .ws .transport .http ;
2
18
19
+ import static org .assertj .core .api .Assertions .*;
20
+
3
21
import java .time .Duration ;
4
22
5
23
import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
6
24
import org .apache .hc .client5 .http .impl .classic .HttpClientBuilder ;
7
25
import org .junit .jupiter .api .Test ;
8
26
9
- import static org .assertj .core .api .Assertions .*;
10
-
11
27
class HttpComponents5MessageSenderTest {
12
28
13
29
@ Test
14
- void afterPropertiesSet_createHttpClient () throws Exception {
30
+ void afterPropertiesSetShouldProperlyInitializeHttpClient () throws Exception {
31
+
15
32
HttpComponents5MessageSender messageSender = new HttpComponents5MessageSender ();
16
33
assertThat (messageSender .getHttpClient ()).isNull ();
34
+
17
35
Duration timeout = Duration .ofSeconds (1 );
18
36
assertThatCode (() -> messageSender .setConnectionTimeout (timeout )).doesNotThrowAnyException ();
37
+
19
38
messageSender .afterPropertiesSet ();
20
39
assertThat (messageSender .getHttpClient ()).isNotNull ();
21
40
}
22
41
23
42
@ Test
24
- void afterPropertiesSet_httpClientAlreadySet () throws Exception {
43
+ void afterPropertiesSetShouldUseAlreadyProvidedHttpClientIfAvailable () throws Exception {
44
+
25
45
CloseableHttpClient httpClient = HttpClientBuilder .create ().build ();
26
46
HttpComponents5MessageSender messageSender = new HttpComponents5MessageSender (httpClient );
47
+
27
48
Duration timeout = Duration .ofSeconds (1 );
28
49
assertThatCode (() -> messageSender .setConnectionTimeout (timeout )).isInstanceOf (IllegalStateException .class );
50
+
29
51
messageSender .afterPropertiesSet ();
30
52
assertThat (messageSender .getHttpClient ()).isSameAs (httpClient );
31
53
}
32
-
33
- }
54
+ }
0 commit comments