Skip to content

Commit 068dc7d

Browse files
committed
Remove use of TestHttpClientAdapter
Now that HttpClientAdapter is deprecated and replaced by HttpExchangeAdapter and ReactorHttpExchangeAdapter, our tests should use the new contracts. See gh-30117
1 parent 3be4c0a commit 068dc7d

22 files changed

+222
-362
lines changed

spring-web/src/test/java/org/springframework/web/service/invoker/CookieValueArgumentResolverTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
*/
3636
class CookieValueArgumentResolverTests {
3737

38-
private final TestHttpClientAdapter client = new TestHttpClientAdapter();
38+
private final TestExchangeAdapter client = new TestExchangeAdapter();
3939

40-
private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class);
40+
private final Service service =
41+
HttpServiceProxyFactory.builderFor(this.client).build().createClient(Service.class);
4142

4243

4344
@Test

spring-web/src/test/java/org/springframework/web/service/invoker/HttpClientServiceMethodTests.java

-39
This file was deleted.

spring-web/src/test/java/org/springframework/web/service/invoker/HttpExchangeAdapterServiceMethodTests.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.junit.jupiter.api.BeforeEach;
2020

2121
/**
22-
* Tests for {@link HttpServiceMethod} with a blocking test {@link TestHttpExchangeAdapter} that
22+
* Tests for {@link HttpServiceMethod} with a blocking test {@link TestExchangeAdapter} that
2323
* stubs the client invocations.
2424
* <p>
2525
* The tests do not create or invoke {@code HttpServiceMethod} directly but rather use
@@ -32,10 +32,8 @@ class HttpExchangeAdapterServiceMethodTests extends HttpServiceMethodTests {
3232

3333
@BeforeEach
3434
void setUp() {
35-
this.client = new TestHttpExchangeAdapter();
36-
this.proxyFactory = HttpServiceProxyFactory.builder()
37-
.exchangeAdapter((HttpExchangeAdapter) this.client)
38-
.build();
35+
this.client = new TestExchangeAdapter();
36+
this.proxyFactory = HttpServiceProxyFactory.builderFor(this.client).build();
3937
}
4038

4139
}

spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
*/
3636
class HttpMethodArgumentResolverTests {
3737

38-
private final TestHttpClientAdapter client = new TestHttpClientAdapter();
38+
private final TestExchangeAdapter client = new TestExchangeAdapter();
3939

40-
private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class);
40+
private final Service service =
41+
HttpServiceProxyFactory.builderFor(this.client).build().createClient(Service.class);
4142

4243

4344
@Test

spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
3737

3838
/**
39-
* Base class for testing {@link HttpServiceMethod} with a test {@link TestHttpClientAdapter}
40-
* and a test {@link TestHttpExchangeAdapter} that stub the client invocations.
39+
* Base class for testing {@link HttpServiceMethod} with a test {@link TestExchangeAdapter}
40+
* and a test {@link TestExchangeAdapter} that stub the client invocations.
4141
*
4242
* <p>
4343
* The tests do not create or invoke {@code HttpServiceMethod} directly but rather use
@@ -52,7 +52,7 @@ abstract class HttpServiceMethodTests {
5252
protected static final ParameterizedTypeReference<String> BODY_TYPE = new ParameterizedTypeReference<>() {
5353
};
5454

55-
protected TestAdapter client;
55+
protected TestExchangeAdapter client;
5656

5757
protected HttpServiceProxyFactory proxyFactory;
5858

@@ -66,19 +66,19 @@ void blockingService() {
6666
assertThat(headers).isNotNull();
6767

6868
String body = service.getBody();
69-
assertThat(body).isEqualTo(client.getInvokedMethodReference());
69+
assertThat(body).isEqualTo(client.getInvokedMethodName());
7070

7171
Optional<String> optional = service.getBodyOptional();
72-
assertThat(optional).contains("body");
72+
assertThat(optional.get()).startsWith("exchangeForBody");
7373

7474
ResponseEntity<String> entity = service.getEntity();
75-
assertThat(entity.getBody()).isEqualTo("entity");
75+
assertThat(entity.getBody()).startsWith("exchangeForEntity");
7676

7777
ResponseEntity<Void> voidEntity = service.getVoidEntity();
7878
assertThat(voidEntity.getBody()).isNull();
7979

8080
List<String> list = service.getList();
81-
assertThat(list.get(0)).isEqualTo("body");
81+
assertThat(list.get(0)).startsWith("exchangeForBody");
8282
}
8383

8484
@Test
@@ -104,10 +104,8 @@ void methodAnnotatedService() {
104104

105105
@Test
106106
void typeAndMethodAnnotatedService() {
107-
HttpExchangeAdapter actualClient = this.client instanceof HttpClientAdapter httpClient
108-
? httpClient.asHttpExchangeAdapter() : (HttpExchangeAdapter) client;
109107
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder()
110-
.exchangeAdapter(actualClient)
108+
.exchangeAdapter(this.client)
111109
.embeddedValueResolver(value -> (value.equals("${baseUrl}") ? "/base" : value))
112110
.build();
113111

@@ -131,7 +129,7 @@ void typeAndMethodAnnotatedService() {
131129
}
132130

133131
protected void verifyClientInvocation(String methodName, @Nullable ParameterizedTypeReference<?> expectedBodyType) {
134-
assertThat(this.client.getInvokedMethodReference()).isEqualTo(methodName);
132+
assertThat(this.client.getInvokedMethodName()).isEqualTo(methodName);
135133
assertThat(this.client.getBodyType()).isEqualTo(expectedBodyType);
136134
}
137135

spring-web/src/test/java/org/springframework/web/service/invoker/MultipartFileArgumentResolverTests.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.Optional;
2020

21-
import org.junit.jupiter.api.BeforeEach;
2221
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.http.HttpEntity;
@@ -42,16 +41,10 @@
4241
@SuppressWarnings("unchecked")
4342
class MultipartFileArgumentResolverTests {
4443

45-
private final TestHttpClientAdapter clientAdapter = new TestHttpClientAdapter();
44+
private final TestExchangeAdapter client = new TestExchangeAdapter();
4645

47-
private TestClient client;
48-
49-
50-
@BeforeEach
51-
void setUp() {
52-
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(this.clientAdapter).build();
53-
this.client = factory.createClient(TestClient.class);
54-
}
46+
private final MultipartService multipartService =
47+
HttpServiceProxyFactory.builderFor(this.client).build().createClient(MultipartService.class);
5548

5649

5750
@Test
@@ -60,8 +53,8 @@ void multipartFile() {
6053
String originalFileName = "originalTestFileName";
6154
MultipartFile testFile = new MockMultipartFile(fileName, originalFileName, "text/plain", "test".getBytes());
6255

63-
this.client.postMultipartFile(testFile);
64-
Object value = this.clientAdapter.getRequestValues().getBodyValue();
56+
this.multipartService.postMultipartFile(testFile);
57+
Object value = this.client.getRequestValues().getBodyValue();
6558

6659
assertThat(value).isInstanceOf(MultiValueMap.class);
6760
MultiValueMap<String, HttpEntity<?>> map = (MultiValueMap<String, HttpEntity<?>>) value;
@@ -80,8 +73,8 @@ void multipartFile() {
8073

8174
@Test
8275
void optionalMultipartFile() {
83-
this.client.postOptionalMultipartFile(Optional.empty(), "anotherPart");
84-
Object value = clientAdapter.getRequestValues().getBodyValue();
76+
this.multipartService.postOptionalMultipartFile(Optional.empty(), "anotherPart");
77+
Object value = client.getRequestValues().getBodyValue();
8578

8679
assertThat(value).isInstanceOf(MultiValueMap.class);
8780
MultiValueMap<String, HttpEntity<?>> map = (MultiValueMap<String, HttpEntity<?>>) value;
@@ -90,7 +83,7 @@ void optionalMultipartFile() {
9083

9184

9285
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
93-
private interface TestClient {
86+
private interface MultipartService {
9487

9588
@PostExchange
9689
void postMultipartFile(MultipartFile file);

spring-web/src/test/java/org/springframework/web/service/invoker/NamedValueArgumentResolverTests.java

+5-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.Optional;
2828

2929
import org.apache.groovy.util.Maps;
30-
import org.junit.jupiter.api.BeforeEach;
3130
import org.junit.jupiter.api.Test;
3231

3332
import org.springframework.core.MethodParameter;
@@ -52,21 +51,14 @@
5251
*/
5352
class NamedValueArgumentResolverTests {
5453

55-
private final TestHttpClientAdapter client = new TestHttpClientAdapter();
54+
private final TestExchangeAdapter client = new TestExchangeAdapter();
5655

5756
private final TestNamedValueArgumentResolver argumentResolver = new TestNamedValueArgumentResolver();
5857

59-
private Service service;
60-
61-
62-
@BeforeEach
63-
void setUp() throws Exception {
64-
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client)
65-
.customArgumentResolver(this.argumentResolver)
66-
.build();
67-
68-
this.service = proxyFactory.createClient(Service.class);
69-
}
58+
private final Service service = HttpServiceProxyFactory.builderFor(this.client)
59+
.customArgumentResolver(this.argumentResolver)
60+
.build()
61+
.createClient(Service.class);
7062

7163

7264
@Test

spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
*/
3535
class PathVariableArgumentResolverTests {
3636

37-
private final TestHttpClientAdapter client = new TestHttpClientAdapter();
37+
private final TestExchangeAdapter client = new TestExchangeAdapter();
3838

39-
private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class);
39+
private final Service service =
40+
HttpServiceProxyFactory.builderFor(this.client).build().createClient(Service.class);
4041

4142

4243
@Test

spring-web/src/test/java/org/springframework/web/service/invoker/ReactiveHttpServiceMethodTests.java

+16-17
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
/**
3535
* Base class for testing reactive scenarios in {@link HttpServiceMethod} with
36-
* a test {@link TestHttpClientAdapter} and a test {@link TestHttpExchangeAdapter}
37-
* that stub the client invocations.
36+
* a test {@link TestReactorExchangeAdapter} that stub the client invocations.
3837
*
3938
* <p>
4039
* The tests do not create or invoke {@code HttpServiceMethod} directly but rather use
@@ -52,33 +51,33 @@ void reactorService() {
5251

5352
Mono<Void> voidMono = service.execute();
5453
StepVerifier.create(voidMono).verifyComplete();
55-
verifyClientInvocation("void", null);
54+
verifyClientInvocation("exchangeForMono", null);
5655

5756
Mono<HttpHeaders> headersMono = service.getHeaders();
5857
StepVerifier.create(headersMono).expectNextCount(1).verifyComplete();
59-
verifyClientInvocation("headers", null);
58+
verifyClientInvocation("exchangeForHeadersMono", null);
6059

6160
Mono<String> body = service.getBody();
62-
StepVerifier.create(body).expectNext("body").verifyComplete();
63-
verifyClientInvocation("body", BODY_TYPE);
61+
StepVerifier.create(body).expectNext("exchangeForBodyMono").verifyComplete();
62+
verifyClientInvocation("exchangeForBodyMono", BODY_TYPE);
6463

6564
Flux<String> fluxBody = service.getFluxBody();
66-
StepVerifier.create(fluxBody).expectNext("request", "To", "Body", "Flux").verifyComplete();
67-
verifyClientInvocation("bodyFlux", BODY_TYPE);
65+
StepVerifier.create(fluxBody).expectNext("exchange", "For", "Body", "Flux").verifyComplete();
66+
verifyClientInvocation("exchangeForBodyFlux", BODY_TYPE);
6867

6968
Mono<ResponseEntity<Void>> voidEntity = service.getVoidEntity();
7069
StepVerifier.create(voidEntity).expectNext(ResponseEntity.ok().build()).verifyComplete();
71-
verifyClientInvocation("bodilessEntity", null);
70+
verifyClientInvocation("exchangeForBodilessEntityMono", null);
7271

7372
Mono<ResponseEntity<String>> entity = service.getEntity();
74-
StepVerifier.create(entity).expectNext(ResponseEntity.ok("requestToEntity"));
75-
verifyClientInvocation("entity", BODY_TYPE);
73+
StepVerifier.create(entity).expectNext(ResponseEntity.ok("exchangeForEntityMono"));
74+
verifyClientInvocation("exchangeForEntityMono", BODY_TYPE);
7675

7776
Mono<ResponseEntity<Flux<String>>> fluxEntity = service.getFluxEntity();
7877
StepVerifier.create(fluxEntity.flatMapMany(HttpEntity::getBody))
79-
.expectNext("request", "To", "Entity", "Flux")
78+
.expectNext("exchange", "For", "Entity", "Flux")
8079
.verifyComplete();
81-
verifyClientInvocation("entityFlux", BODY_TYPE);
80+
verifyClientInvocation("exchangeForEntityFlux", BODY_TYPE);
8281

8382
assertThat(service.getDefaultMethodValue()).isEqualTo("default value");
8483
}
@@ -93,20 +92,20 @@ void rxJavaService() {
9392
assertThat(headersSingle.blockingGet()).isNotNull();
9493

9594
Single<String> bodySingle = service.getBody();
96-
assertThat(bodySingle.blockingGet()).isEqualTo("body");
95+
assertThat(bodySingle.blockingGet()).isEqualTo("exchangeForBodyMono");
9796

9897
Flowable<String> bodyFlow = service.getFlowableBody();
99-
assertThat(bodyFlow.toList().blockingGet()).asList().containsExactly("request", "To", "Body", "Flux");
98+
assertThat(bodyFlow.toList().blockingGet()).asList().containsExactly("exchange", "For", "Body", "Flux");
10099

101100
Single<ResponseEntity<Void>> voidEntity = service.getVoidEntity();
102101
assertThat(voidEntity.blockingGet().getBody()).isNull();
103102

104103
Single<ResponseEntity<String>> entitySingle = service.getEntity();
105-
assertThat(entitySingle.blockingGet().getBody()).isEqualTo("entity");
104+
assertThat(entitySingle.blockingGet().getBody()).isEqualTo("exchangeForEntityMono");
106105

107106
Single<ResponseEntity<Flowable<String>>> entityFlow = service.getFlowableEntity();
108107
Flowable<String> body = (entityFlow.blockingGet()).getBody();
109-
assertThat(body.toList().blockingGet()).containsExactly("request", "To", "Entity", "Flux");
108+
assertThat(body.toList().blockingGet()).containsExactly("exchange", "For", "Entity", "Flux");
110109
}
111110

112111
private interface ReactorService {

spring-web/src/test/java/org/springframework/web/service/invoker/ReactorExchangeAdapterHttpServiceMethodTests.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/**
2222
* Tests for {@link HttpServiceMethod} with an {@link HttpExchangeAdapter}
23-
* build from a test {@link TestHttpClientAdapter} that stubs the client invocations.
23+
* build from a test {@link TestReactorExchangeAdapter} that stubs the client invocations.
2424
* <p>
2525
* The tests do not create or invoke {@code HttpServiceMethod} directly but rather use
2626
* {@link HttpServiceProxyFactory} to create a service proxy in order to use a strongly
@@ -32,10 +32,8 @@ public class ReactorExchangeAdapterHttpServiceMethodTests extends ReactiveHttpSe
3232

3333
@BeforeEach
3434
void setUp() {
35-
this.client = new TestHttpClientAdapter();
36-
this.proxyFactory = HttpServiceProxyFactory.builder()
37-
.exchangeAdapter(((HttpClientAdapter) this.client).asHttpExchangeAdapter())
38-
.build();
35+
this.client = new TestReactorExchangeAdapter();
36+
this.proxyFactory = HttpServiceProxyFactory.builder().exchangeAdapter(this.client).build();
3937
}
4038

4139
}

spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
*/
3333
class RequestAttributeArgumentResolverTests {
3434

35-
private final TestHttpClientAdapter client = new TestHttpClientAdapter();
35+
private final TestExchangeAdapter client = new TestExchangeAdapter();
3636

37-
private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class);
37+
private final Service service =
38+
HttpServiceProxyFactory.builderFor(this.client).build().createClient(Service.class);
3839

3940

4041
@Test

spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
*/
3838
class RequestBodyArgumentResolverTests {
3939

40-
private final TestHttpClientAdapter client = new TestHttpClientAdapter();
40+
private final TestExchangeAdapter client = new TestExchangeAdapter();
4141

42-
private final Service service = HttpServiceProxyFactory.builder(this.client).build().createClient(Service.class);
42+
private final Service service =
43+
HttpServiceProxyFactory.builderFor(this.client).build().createClient(Service.class);
4344

4445

4546
@Test

0 commit comments

Comments
 (0)