Correct package for MockServerWebExchange
Discovered late, but not too late. MockServerWebExchange is now in the proper package matching to the location of ServerWebExchange.
This commit is contained in:
@@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -45,10 +46,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
* Mock extension of {@link AbstractServerHttpRequest} for use in tests without
|
||||
* an actual server.
|
||||
*
|
||||
* <p>Use the static builder methods in this class to create an instance possibly
|
||||
* further creating a {@link MockServerWebExchange} via {@link #toExchange()}.
|
||||
* an actual server. Use the static methods to obtain a builder.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
@@ -108,13 +106,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
throw new IllegalStateException("This is a mock. No running server, no native request.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to wrap the request with a {@code MockServerWebExchange}.
|
||||
*/
|
||||
public MockServerWebExchange toExchange() {
|
||||
return new MockServerWebExchange(this);
|
||||
}
|
||||
|
||||
|
||||
// Static builder methods
|
||||
|
||||
@@ -266,6 +257,13 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
*/
|
||||
B acceptCharset(Charset... acceptableCharsets);
|
||||
|
||||
/**
|
||||
* Set the list of acceptable {@linkplain Locale locales}, as specified
|
||||
* by the {@code Accept-Languages} header.
|
||||
* @param acceptableLocales the acceptable locales
|
||||
*/
|
||||
B acceptLanguageAsLocales(Locale... acceptableLocales);
|
||||
|
||||
/**
|
||||
* Set the value of the {@code If-Modified-Since} header.
|
||||
* <p>The date should be specified as the number of milliseconds since
|
||||
@@ -304,11 +302,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
*/
|
||||
MockServerHttpRequest build();
|
||||
|
||||
/**
|
||||
* Shortcut for:<br>
|
||||
* {@code build().toExchange()}
|
||||
*/
|
||||
MockServerWebExchange toExchange();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,6 +350,7 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
private final HttpMethod method;
|
||||
|
||||
private final URI url;
|
||||
@@ -371,6 +365,7 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
@Nullable
|
||||
private InetSocketAddress remoteAddress;
|
||||
|
||||
|
||||
public DefaultBodyBuilder(HttpMethod method, URI url) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
@@ -426,6 +421,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BodyBuilder acceptLanguageAsLocales(Locale... acceptableLocales) {
|
||||
this.headers.setAcceptLanguageAsLocales(Arrays.asList(acceptableLocales));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BodyBuilder contentLength(long contentLength) {
|
||||
this.headers.setContentLength(contentLength);
|
||||
@@ -467,11 +468,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
return body(Flux.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockServerWebExchange toExchange() {
|
||||
return build().toExchange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockServerHttpRequest body(String body) {
|
||||
return body(Flux.just(BUFFER_FACTORY.wrap(body.getBytes(getCharset()))));
|
||||
|
||||
@@ -13,32 +13,30 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.mock.http.server.reactive;
|
||||
package org.springframework.mock.web.server;
|
||||
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.web.server.ServerWebExchangeDecorator;
|
||||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
|
||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
||||
import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||
|
||||
/**
|
||||
* {@code ServerWebExchange} for use in tests.
|
||||
* Variant of {@link DefaultServerWebExchange} for use in tests with
|
||||
* {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
|
||||
*
|
||||
* <p>Effectively a wrapper around {@link DefaultServerWebExchange} plugged in
|
||||
* with {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
|
||||
*
|
||||
* <p>Typically used via {@link MockServerHttpRequest#toExchange()}.
|
||||
* <p>See static factory methods to create an instance.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
*/
|
||||
public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
||||
public final class MockServerWebExchange extends DefaultServerWebExchange {
|
||||
|
||||
|
||||
public MockServerWebExchange(MockServerHttpRequest request) {
|
||||
super(new DefaultServerWebExchange(
|
||||
request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
||||
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver()));
|
||||
private MockServerWebExchange(MockServerHttpRequest request) {
|
||||
super(request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
||||
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
|
||||
}
|
||||
|
||||
|
||||
@@ -47,4 +45,14 @@ public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
||||
return (MockServerHttpResponse) super.getResponse();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a {@link MockServerWebExchange} from the given request.
|
||||
* @param request the request to use.
|
||||
* @return the exchange
|
||||
*/
|
||||
public static MockServerWebExchange from(MockServerHttpRequest request) {
|
||||
return new MockServerWebExchange(request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Mock implementations of Spring's reactive server web API abtsractions.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.mock.web.server;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
Reference in New Issue
Block a user