Browse Source

Update MockRestServiceServer bufferContent

Connect the existing bufferContent option to the new RestClient and
RestTemplate equivalent feature.

See gh-33785
pull/34242/head
rstoyanchev 1 year ago
parent
commit
2561a60968
  1. 15
      spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java

15
spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@ -244,6 +244,10 @@ public final class MockRestServiceServer { @@ -244,6 +244,10 @@ public final class MockRestServiceServer {
return this;
}
protected boolean shouldBufferContent() {
return this.bufferContent;
}
@Override
public MockRestServiceServer build() {
if (this.ignoreExpectOrder) {
@ -258,9 +262,6 @@ public final class MockRestServiceServer { @@ -258,9 +262,6 @@ public final class MockRestServiceServer {
public MockRestServiceServer build(RequestExpectationManager manager) {
MockRestServiceServer server = new MockRestServiceServer(manager);
ClientHttpRequestFactory factory = server.new MockClientHttpRequestFactory();
if (this.bufferContent) {
factory = new BufferingClientHttpRequestFactory(factory);
}
injectRequestFactory(factory);
return server;
}
@ -281,6 +282,9 @@ public final class MockRestServiceServer { @@ -281,6 +282,9 @@ public final class MockRestServiceServer {
@Override
protected void injectRequestFactory(ClientHttpRequestFactory requestFactory) {
if (shouldBufferContent()) {
this.restClientBuilder.bufferContent((uri, httpMethod) -> true);
}
this.restClientBuilder.requestFactory(requestFactory);
}
}
@ -297,6 +301,9 @@ public final class MockRestServiceServer { @@ -297,6 +301,9 @@ public final class MockRestServiceServer {
@Override
protected void injectRequestFactory(ClientHttpRequestFactory requestFactory) {
if (shouldBufferContent()) {
this.restTemplate.setBufferingPredicate((uri, httpMethod) -> true);
}
this.restTemplate.setRequestFactory(requestFactory);
}
}

Loading…
Cancel
Save