Skip to content

Commit 45401d1

Browse files
authored
Migrates to Framework RestTestClient (#3872)
This removes the local TestRestClient.java
1 parent 18c5990 commit 45401d1

24 files changed

+59
-2845
lines changed

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import org.springframework.cloud.gateway.server.mvc.test.LocalServerPortUriResolver;
6262
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
6363
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
64-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
6564
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
6665
import org.springframework.context.annotation.Bean;
6766
import org.springframework.context.annotation.Import;
@@ -77,6 +76,7 @@
7776
import org.springframework.http.ResponseEntity;
7877
import org.springframework.http.client.MultipartBodyBuilder;
7978
import org.springframework.test.context.ContextConfiguration;
79+
import org.springframework.test.web.servlet.client.RestTestClient;
8080
import org.springframework.util.LinkedMultiValueMap;
8181
import org.springframework.util.MultiValueMap;
8282
import org.springframework.util.StreamUtils;
@@ -162,7 +162,7 @@ public class ServerMvcIntegrationTests {
162162
TestRestTemplate restTemplate;
163163

164164
@Autowired
165-
TestRestClient restClient;
165+
RestTestClient restClient;
166166

167167
@Test
168168
public void nonGatewayRouterFunctionWorks() {
@@ -227,7 +227,7 @@ public void setPathWorks() {
227227
public void setPathPostWorks() {
228228
restClient.post()
229229
.uri("/mycustompathpost")
230-
.bodyValue("hello")
230+
.body("hello")
231231
.header("Host", "www.setpathpost.org")
232232
.exchange()
233233
.expectStatus()
@@ -266,7 +266,7 @@ public void stripPrefixWorks() {
266266
public void stripPrefixPostWorks() {
267267
restClient.post()
268268
.uri("/long/path/to/post")
269-
.bodyValue("hello")
269+
.body("hello")
270270
.header("Host", "www.stripprefixpost.org")
271271
.exchange()
272272
.expectStatus()
@@ -343,7 +343,7 @@ public void addResponseHeaderWorks() {
343343
public void postWorks() {
344344
restClient.post()
345345
.uri("/post")
346-
.bodyValue("Post Value")
346+
.body("Post Value")
347347
.header("test", "post")
348348
.exchange()
349349
.expectStatus()
@@ -494,7 +494,7 @@ public void rewritePathWorks() {
494494
public void rewritePathPostWorks() {
495495
restClient.post()
496496
.uri("/baz/post")
497-
.bodyValue("hello")
497+
.body("hello")
498498
.header("Host", "www.rewritepathpost.org")
499499
.exchange()
500500
.expectStatus()
@@ -512,7 +512,7 @@ public void rewritePathPostWorks() {
512512
public void rewritePathPostLocalWorks() {
513513
restClient.post()
514514
.uri("/baz/localpost")
515-
.bodyValue("hello")
515+
.body("hello")
516516
.header("Host", "www.rewritepathpostlocal.org")
517517
.exchange()
518518
.expectStatus()
@@ -560,7 +560,7 @@ public void forwardedHeadersWork() {
560560
public void requestSizeWorks() {
561561
restClient.post()
562562
.uri("/post")
563-
.bodyValue("123456")
563+
.body("123456")
564564
.header("test", "requestsize")
565565
.exchange()
566566
.expectStatus()
@@ -602,7 +602,7 @@ void formUrlencodedWorks() {
602602

603603
// @formatter:off
604604
restClient.post().uri("/post?foo=fooquery").header("test", "formurlencoded").contentType(FORM_URL_ENCODED_CONTENT_TYPE)
605-
.bodyValue(formData)
605+
.body(formData)
606606
.exchange()
607607
.expectStatus().isOk()
608608
.expectBody(Map.class).consumeWith(result -> {
@@ -622,7 +622,7 @@ void multipartFormDataWorks() {
622622
// @formatter:off
623623
restClient.post().uri("/post").contentType(MULTIPART_FORM_DATA)
624624
.header("Host", "www.testform.org")
625-
.bodyValue(formData)
625+
.body(formData)
626626
.exchange()
627627
.expectStatus().isOk()
628628
.expectBody(Map.class)
@@ -783,7 +783,7 @@ public void removeRequestParameterWorks() {
783783
public void removeRequestParameterPostWorks() {
784784
restClient.post()
785785
.uri("/post?foo=bar")
786-
.bodyValue("hello")
786+
.body("hello")
787787
.header("Host", "www.removerequestparampost.org")
788788
.exchange()
789789
.expectStatus()
@@ -903,7 +903,7 @@ public void readBodyWorks() {
903903

904904
restClient.post()
905905
.uri("/events")
906-
.bodyValue(messageEvent)
906+
.body(messageEvent)
907907
.exchange()
908908
.expectStatus()
909909
.isOk()
@@ -916,7 +916,7 @@ public void readBodyWorks() {
916916

917917
restClient.post()
918918
.uri("/events")
919-
.bodyValue(messageChannelEvent)
919+
.body(messageChannelEvent)
920920
.exchange()
921921
.expectStatus()
922922
.isOk()
@@ -933,7 +933,7 @@ public void rewriteRequestBodyStringWorks() {
933933
restClient.post()
934934
.uri("/post")
935935
.header("Host", "www.modifyrequestbodystring.org")
936-
.bodyValue("hello")
936+
.body("hello")
937937
.exchange()
938938
.expectStatus()
939939
.isOk()
@@ -947,7 +947,7 @@ public void rewriteRequestBodyObjectWorks() {
947947
restClient.post()
948948
.uri("/post")
949949
.header("Host", "www.modifyrequestbodyobject.org")
950-
.bodyValue("hello world")
950+
.body("hello world")
951951
.exchange()
952952
.expectStatus()
953953
.isOk()

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcLoadBalancerIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import org.springframework.cloud.gateway.server.mvc.filter.FilterAutoConfiguration;
2626
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
2727
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
28-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
2928
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
3029
import org.springframework.test.context.ActiveProfiles;
3130
import org.springframework.test.context.ContextConfiguration;
31+
import org.springframework.test.web.servlet.client.RestTestClient;
3232

3333
/**
3434
* Integration tests for {@link FilterAutoConfiguration.LoadBalancerHandlerConfiguration}.
@@ -46,11 +46,11 @@ public class ServerMvcLoadBalancerIntegrationTests {
4646
int port;
4747

4848
@Autowired
49-
TestRestClient testRestClient;
49+
RestTestClient restClient;
5050

5151
@Test
5252
void shouldUseLbHandlerFunctionDefinitionToResolveHost() {
53-
testRestClient.get().uri("http://localhost:" + port + "/test").exchange().expectStatus().isOk();
53+
restClient.get().uri("http://localhost:" + port + "/test").exchange().expectStatus().isOk();
5454
}
5555

5656
@SpringBootApplication

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/VanillaRouterFunctionTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import org.springframework.cloud.gateway.server.mvc.test.HttpbinUriResolver;
3232
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
3333
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
34-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
3534
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
3635
import org.springframework.context.annotation.Bean;
3736
import org.springframework.context.annotation.Import;
3837
import org.springframework.test.context.ContextConfiguration;
38+
import org.springframework.test.web.servlet.client.RestTestClient;
3939
import org.springframework.web.servlet.function.RouterFunction;
4040
import org.springframework.web.servlet.function.RouterFunctions;
4141
import org.springframework.web.servlet.function.ServerResponse;
@@ -53,15 +53,15 @@ public class VanillaRouterFunctionTests {
5353
int port;
5454

5555
@Autowired
56-
TestRestClient restClient;
56+
RestTestClient restClient;
5757

5858
@SuppressWarnings("rawtypes")
5959
@Test
6060
public void routerFunctionsRouteWorks() {
6161
restClient.post()
6262
.uri("/anything/routerfunctionsroute")
6363
.header("Host", "www.routerfunctionsroute.org")
64-
.bodyValue("hello")
64+
.body("hello")
6565
.exchange()
6666
.expectStatus()
6767
.isOk()

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/config/FunctionHandlerConfigTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@
2727
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2828
import org.springframework.boot.test.context.SpringBootTest;
2929
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
30-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
3130
import org.springframework.context.annotation.Bean;
3231
import org.springframework.context.annotation.Import;
3332
import org.springframework.http.MediaType;
3433
import org.springframework.test.context.ActiveProfiles;
34+
import org.springframework.test.web.servlet.client.RestTestClient;
3535

3636
@SpringBootTest(properties = {}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
3737
@ActiveProfiles("functionhandlerconfigtests")
3838
public class FunctionHandlerConfigTests {
3939

4040
@Autowired
41-
private TestRestClient restClient;
41+
private RestTestClient restClient;
4242

4343
@Test
4444
public void testSimpleFunctionWorks() {
4545
restClient.post()
4646
.uri("/simplefunction")
4747
.accept(MediaType.TEXT_PLAIN)
48-
.bodyValue("hello")
48+
.body("hello")
4949
.exchange()
5050
.expectStatus()
5151
.isOk()
@@ -58,7 +58,7 @@ public void testTemplatedFunctionWorks() {
5858
restClient.post()
5959
.uri("/templatedfunction/upper")
6060
.accept(MediaType.TEXT_PLAIN)
61-
.bodyValue("hello")
61+
.body("hello")
6262
.exchange()
6363
.expectStatus()
6464
.isOk()

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/config/GatewayMvcPropertiesBeanDefinitionRegistrarTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
3737
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
3838
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
39-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
4039
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
4140
import org.springframework.context.ApplicationContext;
4241
import org.springframework.context.ConfigurableApplicationContext;
@@ -45,6 +44,7 @@
4544
import org.springframework.http.HttpMethod;
4645
import org.springframework.test.context.ActiveProfiles;
4746
import org.springframework.test.context.ContextConfiguration;
47+
import org.springframework.test.web.servlet.client.RestTestClient;
4848
import org.springframework.web.servlet.function.HandlerFunction;
4949
import org.springframework.web.servlet.function.RequestPredicate;
5050
import org.springframework.web.servlet.function.RequestPredicates;
@@ -62,7 +62,7 @@
6262
public class GatewayMvcPropertiesBeanDefinitionRegistrarTests {
6363

6464
@Autowired
65-
TestRestClient restClient;
65+
RestTestClient restClient;
6666

6767
@Test
6868
void contextLoads(ApplicationContext context) {

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/config/StreamHandlerConfigTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
import org.springframework.boot.test.context.SpringBootTest;
3333
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
3434
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
35-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
3635
import org.springframework.context.annotation.Bean;
3736
import org.springframework.context.annotation.Import;
3837
import org.springframework.http.MediaType;
3938
import org.springframework.test.context.ActiveProfiles;
39+
import org.springframework.test.web.servlet.client.RestTestClient;
4040

4141
import static org.assertj.core.api.Assertions.assertThat;
4242

@@ -53,7 +53,7 @@ public class StreamHandlerConfigTests {
5353
public static RabbitMQContainer rabbitmq = new RabbitMQContainer("rabbitmq:3.7.25-management-alpine");
5454

5555
@Autowired
56-
private TestRestClient restClient;
56+
private RestTestClient restClient;
5757

5858
@Autowired
5959
private AtomicBoolean helloConsumed;
@@ -64,7 +64,7 @@ public void testSimpleStreamWorks() {
6464
restClient.post()
6565
.uri("/simplestream")
6666
.accept(MediaType.TEXT_PLAIN)
67-
.bodyValue("hello")
67+
.body("hello")
6868
.exchange()
6969
.expectStatus()
7070
.isAccepted();
@@ -79,7 +79,7 @@ public void testTemplatedStreamWorks() {
7979
restClient.post()
8080
.uri("/templatedstream/hello")
8181
.accept(MediaType.TEXT_PLAIN)
82-
.bodyValue("hello")
82+
.body("hello")
8383
.exchange()
8484
.expectStatus()
8585
.isAccepted();

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/AfterFilterFunctionsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
import org.springframework.cloud.gateway.server.mvc.test.HttpbinUriResolver;
3030
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
3131
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
32-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
3332
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
3433
import org.springframework.context.annotation.Bean;
3534
import org.springframework.context.annotation.Import;
3635
import org.springframework.http.HttpStatus;
3736
import org.springframework.http.MediaType;
3837
import org.springframework.http.ResponseEntity;
3938
import org.springframework.test.context.ContextConfiguration;
39+
import org.springframework.test.web.servlet.client.RestTestClient;
4040
import org.springframework.web.bind.annotation.ControllerAdvice;
4141
import org.springframework.web.bind.annotation.ExceptionHandler;
4242
import org.springframework.web.servlet.function.RouterFunction;
@@ -57,7 +57,7 @@
5757
class AfterFilterFunctionsTests {
5858

5959
@Autowired
60-
TestRestClient restClient;
60+
RestTestClient restClient;
6161

6262
@Test
6363
void doesNotRemoveJsonAttributes() {

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/BodyFilterFunctionsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
import org.springframework.cloud.gateway.server.mvc.test.HttpbinUriResolver;
2929
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
3030
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
31-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
3231
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
3332
import org.springframework.context.annotation.Bean;
3433
import org.springframework.context.annotation.Import;
3534
import org.springframework.http.MediaType;
3635
import org.springframework.test.context.ContextConfiguration;
36+
import org.springframework.test.web.servlet.client.RestTestClient;
3737
import org.springframework.web.servlet.function.RouterFunction;
3838
import org.springframework.web.servlet.function.ServerResponse;
3939

@@ -49,7 +49,7 @@
4949
public class BodyFilterFunctionsTests {
5050

5151
@Autowired
52-
TestRestClient restClient;
52+
RestTestClient restClient;
5353

5454
@Test
5555
public void modifyResponseBodySimple() {

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/RetryFilterFunctionTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.cloud.gateway.server.mvc.test.LocalServerPortUriResolver;
3535
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
3636
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
37-
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
3837
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
3938
import org.springframework.context.annotation.Bean;
4039
import org.springframework.context.annotation.Import;
@@ -43,6 +42,7 @@
4342
import org.springframework.http.HttpStatus;
4443
import org.springframework.http.ResponseEntity;
4544
import org.springframework.test.context.ContextConfiguration;
45+
import org.springframework.test.web.servlet.client.RestTestClient;
4646
import org.springframework.util.StringUtils;
4747
import org.springframework.web.bind.annotation.GetMapping;
4848
import org.springframework.web.bind.annotation.PostMapping;
@@ -67,7 +67,7 @@ public class RetryFilterFunctionTests {
6767
int port;
6868

6969
@Autowired
70-
TestRestClient restClient;
70+
RestTestClient restClient;
7171

7272
@Test
7373
public void retryWorks() {
@@ -87,7 +87,7 @@ public void retryWorks() {
8787
public void retryBodyWorks() {
8888
restClient.post()
8989
.uri("/retrybody?key=post")
90-
.bodyValue("thebody")
90+
.body("thebody")
9191
.exchange()
9292
.expectStatus()
9393
.isOk()

0 commit comments

Comments
 (0)