From 8dbb04d0d15a922791f8e2b63c061539334eb0e8 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Tue, 23 May 2023 13:40:30 -0500 Subject: [PATCH] Polishing. See #1357. --- .../http/HttpComponents5ClientFactory.java | 9 +++-- .../HttpComponents5MessageSenderTest.java | 33 +++++++++++++++---- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/spring-ws-core/src/main/java/org/springframework/ws/transport/http/HttpComponents5ClientFactory.java b/spring-ws-core/src/main/java/org/springframework/ws/transport/http/HttpComponents5ClientFactory.java index 191ba33e..7d23dc1d 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/transport/http/HttpComponents5ClientFactory.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/transport/http/HttpComponents5ClientFactory.java @@ -45,11 +45,10 @@ import org.springframework.ws.client.support.interceptor.ClientInterceptor; public class HttpComponents5ClientFactory implements FactoryBean { /** - * AuthScope to match any Host. + * {@link AuthScope} to match any Host. *

- * HEADS-UP: ANY has been removed from {@link AuthScope} since httpcomponents version 5.x. It has been - * redefined here to ease migration from httpcomponents 4. The associated functionality might be removed in a future - * version of apache httpcomponents. Consider using a {@link ClientInterceptor} to implement http client agnostic + * NOTE: {@code ANY} was removed from {@link AuthScope} in HttpComponents 5.0. This value object will easy + * migration from HttpComponents 4. Consider using a {@link ClientInterceptor} to implement http client agnostic * preemptive basic auth. * * @see AuthScope#AuthScope(String, String, int, String, String) @@ -91,7 +90,7 @@ public class HttpComponents5ClientFactory implements FactoryBean - * By default, the {@link #ANY} is used. + * By default, {@link #ANY} is used. * * @see #setCredentials(Credentials) */ diff --git a/spring-ws-core/src/test/java/org/springframework/ws/transport/http/HttpComponents5MessageSenderTest.java b/spring-ws-core/src/test/java/org/springframework/ws/transport/http/HttpComponents5MessageSenderTest.java index 75f7ee06..2496ddc1 100644 --- a/spring-ws-core/src/test/java/org/springframework/ws/transport/http/HttpComponents5MessageSenderTest.java +++ b/spring-ws-core/src/test/java/org/springframework/ws/transport/http/HttpComponents5MessageSenderTest.java @@ -1,33 +1,54 @@ +/* + * Copyright 2005-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.ws.transport.http; +import static org.assertj.core.api.Assertions.*; + import java.time.Duration; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; - class HttpComponents5MessageSenderTest { @Test - void afterPropertiesSet_createHttpClient() throws Exception { + void afterPropertiesSetShouldProperlyInitializeHttpClient() throws Exception { + HttpComponents5MessageSender messageSender = new HttpComponents5MessageSender(); assertThat(messageSender.getHttpClient()).isNull(); + Duration timeout = Duration.ofSeconds(1); assertThatCode(() -> messageSender.setConnectionTimeout(timeout)).doesNotThrowAnyException(); + messageSender.afterPropertiesSet(); assertThat(messageSender.getHttpClient()).isNotNull(); } @Test - void afterPropertiesSet_httpClientAlreadySet() throws Exception { + void afterPropertiesSetShouldUseAlreadyProvidedHttpClientIfAvailable() throws Exception { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpComponents5MessageSender messageSender = new HttpComponents5MessageSender(httpClient); + Duration timeout = Duration.ofSeconds(1); assertThatCode(() -> messageSender.setConnectionTimeout(timeout)).isInstanceOf(IllegalStateException.class); + messageSender.afterPropertiesSet(); assertThat(messageSender.getHttpClient()).isSameAs(httpClient); } - -} \ No newline at end of file +}