Polish
This commit is contained in:
parent
d786635239
commit
f1a335708a
|
@ -37,7 +37,7 @@ import static org.mockito.BDDMockito.when;
|
||||||
/**
|
/**
|
||||||
* Tests for {@link BindingContext}.
|
* Tests for {@link BindingContext}.
|
||||||
*/
|
*/
|
||||||
public class BindingContextTests {
|
class BindingContextTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void jakartaValidatorExcludedWhenMethodValidationApplicable() {
|
void jakartaValidatorExcludedWhenMethodValidationApplicable() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -78,7 +78,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.register(TestConfig.class);
|
context.register(TestConfig.class);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
@ -88,7 +88,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noHandler() {
|
void noHandler() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist"));
|
||||||
Mono<Void> mono = this.dispatcherHandler.handle(exchange);
|
Mono<Void> mono = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noStaticResource() {
|
void noStaticResource() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.register(StaticResourceConfig.class);
|
context.register(StaticResourceConfig.class);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
@ -128,7 +128,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void controllerReturnsMonoError() {
|
void controllerReturnsMonoError() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal"));
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void controllerThrowsException() {
|
void controllerThrowsException() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception"));
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unknownReturnType() {
|
void unknownReturnType() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type"));
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseBodyMessageConversionError() {
|
void responseBodyMessageConversionError() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body"));
|
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body"));
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestBodyError() {
|
void requestBodyError() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION)));
|
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION)));
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void webExceptionHandler() {
|
void webExceptionHandler() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type"));
|
||||||
|
|
||||||
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
|
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
|
||||||
|
|
|
@ -48,7 +48,7 @@ import static org.mockito.Mockito.withSettings;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class DispatcherHandlerTests {
|
class DispatcherHandlerTests {
|
||||||
|
|
||||||
private static final MethodParameter RETURN_TYPE =
|
private static final MethodParameter RETURN_TYPE =
|
||||||
ResolvableMethod.on(DispatcherHandler.class).named("handle").resolveReturnType();
|
ResolvableMethod.on(DispatcherHandler.class).named("handle").resolveReturnType();
|
||||||
|
|
|
@ -33,13 +33,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class HeaderContentTypeResolverTests {
|
class HeaderContentTypeResolverTests {
|
||||||
|
|
||||||
private final HeaderContentTypeResolver resolver = new HeaderContentTypeResolver();
|
private final HeaderContentTypeResolver resolver = new HeaderContentTypeResolver();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveMediaTypes() throws Exception {
|
void resolveMediaTypes() {
|
||||||
String header = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c";
|
String header = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c";
|
||||||
List<MediaType> mediaTypes = this.resolver.resolveMediaTypes(
|
List<MediaType> mediaTypes = this.resolver.resolveMediaTypes(
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.get("/").header("accept", header)));
|
MockServerWebExchange.from(MockServerHttpRequest.get("/").header("accept", header)));
|
||||||
|
@ -52,7 +52,7 @@ public class HeaderContentTypeResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveMediaTypesParseError() throws Exception {
|
void resolveMediaTypesParseError() {
|
||||||
String header = "textplain; q=0.5";
|
String header = "textplain; q=0.5";
|
||||||
assertThatExceptionOfType(NotAcceptableStatusException.class).isThrownBy(() ->
|
assertThatExceptionOfType(NotAcceptableStatusException.class).isThrownBy(() ->
|
||||||
this.resolver.resolveMediaTypes(
|
this.resolver.resolveMediaTypes(
|
||||||
|
|
|
@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ParameterContentTypeResolverTests {
|
class ParameterContentTypeResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noKey() {
|
void noKey() {
|
||||||
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||||
|
@ -48,14 +48,14 @@ public class ParameterContentTypeResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noMatchForKey() {
|
void noMatchForKey() {
|
||||||
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
||||||
assertThatExceptionOfType(NotAcceptableStatusException.class).isThrownBy(() ->
|
assertThatExceptionOfType(NotAcceptableStatusException.class).isThrownBy(() ->
|
||||||
resolver.resolveMediaTypes(createExchange("blah")));
|
resolver.resolveMediaTypes(createExchange("blah")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveKeyFromRegistrations() {
|
void resolveKeyFromRegistrations() {
|
||||||
ServerWebExchange exchange = createExchange("html");
|
ServerWebExchange exchange = createExchange("html");
|
||||||
|
|
||||||
Map<String, MediaType> mapping = Collections.emptyMap();
|
Map<String, MediaType> mapping = Collections.emptyMap();
|
||||||
|
@ -70,7 +70,7 @@ public class ParameterContentTypeResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveKeyThroughMediaTypeFactory() {
|
void resolveKeyThroughMediaTypeFactory() {
|
||||||
ServerWebExchange exchange = createExchange("xls");
|
ServerWebExchange exchange = createExchange("xls");
|
||||||
RequestedContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
RequestedContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||||
|
|
|
@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestedContentTypeResolverBuilderTests {
|
class RequestedContentTypeResolverBuilderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void defaultSettings() {
|
void defaultSettings() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -31,25 +31,25 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class CorsRegistryTests {
|
class CorsRegistryTests {
|
||||||
|
|
||||||
private final CorsRegistry registry = new CorsRegistry();
|
private final CorsRegistry registry = new CorsRegistry();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noMapping() {
|
void noMapping() {
|
||||||
assertThat(this.registry.getCorsConfigurations()).isEmpty();
|
assertThat(this.registry.getCorsConfigurations()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleMappings() {
|
void multipleMappings() {
|
||||||
this.registry.addMapping("/foo");
|
this.registry.addMapping("/foo");
|
||||||
this.registry.addMapping("/bar");
|
this.registry.addMapping("/bar");
|
||||||
assertThat(this.registry.getCorsConfigurations()).hasSize(2);
|
assertThat(this.registry.getCorsConfigurations()).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customizedMapping() {
|
void customizedMapping() {
|
||||||
this.registry.addMapping("/foo").allowedOrigins("https://domain2.com", "https://domain2.com")
|
this.registry.addMapping("/foo").allowedOrigins("https://domain2.com", "https://domain2.com")
|
||||||
.allowedMethods("DELETE").allowCredentials(true).allowPrivateNetwork(true)
|
.allowedMethods("DELETE").allowCredentials(true).allowPrivateNetwork(true)
|
||||||
.allowedHeaders("header1", "header2").exposedHeaders("header3", "header4").maxAge(3600);
|
.allowedHeaders("header1", "header2").exposedHeaders("header3", "header4").maxAge(3600);
|
||||||
|
@ -66,7 +66,7 @@ public class CorsRegistryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allowCredentials() {
|
void allowCredentials() {
|
||||||
this.registry.addMapping("/foo").allowCredentials(true);
|
this.registry.addMapping("/foo").allowCredentials(true);
|
||||||
CorsConfiguration config = this.registry.getCorsConfigurations().get("/foo");
|
CorsConfiguration config = this.registry.getCorsConfigurations().get("/foo");
|
||||||
assertThat(config.getAllowedOrigins())
|
assertThat(config.getAllowedOrigins())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -40,12 +40,12 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class DelegatingWebFluxConfigurationIntegrationTests {
|
class DelegatingWebFluxConfigurationIntegrationTests {
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void closeContext() {
|
void closeContext() {
|
||||||
if (this.context != null) {
|
if (this.context != null) {
|
||||||
this.context.close();
|
this.context.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -71,7 +71,7 @@ public class DelegatingWebFluxConfigurationTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
delegatingConfig = new DelegatingWebFluxConfiguration();
|
delegatingConfig = new DelegatingWebFluxConfiguration();
|
||||||
delegatingConfig.setApplicationContext(new StaticApplicationContext());
|
delegatingConfig.setApplicationContext(new StaticApplicationContext());
|
||||||
given(webFluxConfigurer.getValidator()).willReturn(null);
|
given(webFluxConfigurer.getValidator()).willReturn(null);
|
||||||
|
@ -81,7 +81,7 @@ public class DelegatingWebFluxConfigurationTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestMappingHandlerMapping() {
|
void requestMappingHandlerMapping() {
|
||||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||||
delegatingConfig.requestMappingHandlerMapping(delegatingConfig.webFluxContentTypeResolver());
|
delegatingConfig.requestMappingHandlerMapping(delegatingConfig.webFluxContentTypeResolver());
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class DelegatingWebFluxConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestMappingHandlerAdapter() {
|
void requestMappingHandlerAdapter() {
|
||||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||||
ReactiveAdapterRegistry reactiveAdapterRegistry = delegatingConfig.webFluxAdapterRegistry();
|
ReactiveAdapterRegistry reactiveAdapterRegistry = delegatingConfig.webFluxAdapterRegistry();
|
||||||
ServerCodecConfigurer serverCodecConfigurer = delegatingConfig.serverCodecConfigurer();
|
ServerCodecConfigurer serverCodecConfigurer = delegatingConfig.serverCodecConfigurer();
|
||||||
|
@ -116,7 +116,7 @@ public class DelegatingWebFluxConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerMapping() {
|
void resourceHandlerMapping() {
|
||||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||||
willAnswer(invocation -> {
|
willAnswer(invocation -> {
|
||||||
ResourceHandlerRegistry registry = invocation.getArgument(0);
|
ResourceHandlerRegistry registry = invocation.getArgument(0);
|
||||||
|
@ -142,7 +142,7 @@ public class DelegatingWebFluxConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseBodyResultHandler() {
|
void responseBodyResultHandler() {
|
||||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||||
delegatingConfig.responseBodyResultHandler(
|
delegatingConfig.responseBodyResultHandler(
|
||||||
delegatingConfig.webFluxAdapterRegistry(),
|
delegatingConfig.webFluxAdapterRegistry(),
|
||||||
|
@ -154,7 +154,7 @@ public class DelegatingWebFluxConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void viewResolutionResultHandler() {
|
void viewResolutionResultHandler() {
|
||||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||||
delegatingConfig.viewResolutionResultHandler(delegatingConfig.webFluxAdapterRegistry(),
|
delegatingConfig.viewResolutionResultHandler(delegatingConfig.webFluxAdapterRegistry(),
|
||||||
delegatingConfig.webFluxContentTypeResolver());
|
delegatingConfig.webFluxContentTypeResolver());
|
||||||
|
|
|
@ -149,8 +149,8 @@ class ResourceHandlerRegistryTests {
|
||||||
|
|
||||||
List<ResourceTransformer> transformers = handler.getResourceTransformers();
|
List<ResourceTransformer> transformers = handler.getResourceTransformers();
|
||||||
assertThat(transformers).hasSize(2);
|
assertThat(transformers).hasSize(2);
|
||||||
assertThat(transformers).element(0).isInstanceOf(CachingResourceTransformer.class);
|
assertThat(transformers.get(0)).isInstanceOf(CachingResourceTransformer.class);
|
||||||
assertThat(transformers).element(1).isEqualTo(mockTransformer);
|
assertThat(transformers.get(1)).isEqualTo(mockTransformer);
|
||||||
Mockito.verify(mockTransformer).setResourceUrlProvider(resourceUrlProvider);
|
Mockito.verify(mockTransformer).setResourceUrlProvider(resourceUrlProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,6 @@ class ResourceHandlerRegistryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
void resourceChainWithOverrides() {
|
void resourceChainWithOverrides() {
|
||||||
CachingResourceResolver cachingResolver = mock();
|
CachingResourceResolver cachingResolver = mock();
|
||||||
VersionResourceResolver versionResolver = mock();
|
VersionResourceResolver versionResolver = mock();
|
||||||
|
@ -211,16 +210,11 @@ class ResourceHandlerRegistryTests {
|
||||||
|
|
||||||
ResourceWebHandler handler = getHandler("/resources/**");
|
ResourceWebHandler handler = getHandler("/resources/**");
|
||||||
List<ResourceResolver> resolvers = handler.getResourceResolvers();
|
List<ResourceResolver> resolvers = handler.getResourceResolvers();
|
||||||
assertThat(resolvers).hasSize(4);
|
assertThat(resolvers).containsExactly(
|
||||||
assertThat(resolvers).element(0).isSameAs(cachingResolver);
|
cachingResolver, versionResolver, webjarsResolver, pathResourceResolver);
|
||||||
assertThat(resolvers).element(1).isSameAs(versionResolver);
|
|
||||||
assertThat(resolvers).element(2).isSameAs(webjarsResolver);
|
|
||||||
assertThat(resolvers).element(3).isSameAs(pathResourceResolver);
|
|
||||||
|
|
||||||
List<ResourceTransformer> transformers = handler.getResourceTransformers();
|
List<ResourceTransformer> transformers = handler.getResourceTransformers();
|
||||||
assertThat(transformers).hasSize(2);
|
assertThat(transformers).containsExactly(cachingTransformer, cssLinkTransformer);
|
||||||
assertThat(transformers).element(0).isSameAs(cachingTransformer);
|
|
||||||
assertThat(transformers).element(1).isSameAs(cssLinkTransformer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -41,13 +41,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class ViewResolverRegistryTests {
|
class ViewResolverRegistryTests {
|
||||||
|
|
||||||
private ViewResolverRegistry registry;
|
private ViewResolverRegistry registry;
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
||||||
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
|
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
|
||||||
context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
|
context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
|
||||||
|
@ -56,12 +56,12 @@ public class ViewResolverRegistryTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void order() {
|
void order() {
|
||||||
assertThat(this.registry.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE);
|
assertThat(this.registry.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hasRegistrations() {
|
void hasRegistrations() {
|
||||||
assertThat(this.registry.hasRegistrations()).isFalse();
|
assertThat(this.registry.hasRegistrations()).isFalse();
|
||||||
|
|
||||||
this.registry.freeMarker();
|
this.registry.freeMarker();
|
||||||
|
@ -69,23 +69,22 @@ public class ViewResolverRegistryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noResolvers() {
|
void noResolvers() {
|
||||||
assertThat(this.registry.getViewResolvers()).isNotNull();
|
assertThat(this.registry.getViewResolvers()).isNotNull();
|
||||||
assertThat(this.registry.getViewResolvers()).isEmpty();
|
assertThat(this.registry.getViewResolvers()).isEmpty();
|
||||||
assertThat(this.registry.hasRegistrations()).isFalse();
|
assertThat(this.registry.hasRegistrations()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customViewResolver() {
|
void customViewResolver() {
|
||||||
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
|
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
|
||||||
this.registry.viewResolver(viewResolver);
|
this.registry.viewResolver(viewResolver);
|
||||||
|
|
||||||
assertThat(this.registry.getViewResolvers()).element(0).isSameAs(viewResolver);
|
assertThat(this.registry.getViewResolvers()).containsExactly(viewResolver);
|
||||||
assertThat(this.registry.getViewResolvers()).hasSize(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultViews() throws Exception {
|
void defaultViews() {
|
||||||
View view = new HttpMessageWriterView(new Jackson2JsonEncoder());
|
View view = new HttpMessageWriterView(new Jackson2JsonEncoder());
|
||||||
this.registry.defaultViews(view);
|
this.registry.defaultViews(view);
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||||
import org.springframework.http.codec.xml.Jaxb2XmlDecoder;
|
import org.springframework.http.codec.xml.Jaxb2XmlDecoder;
|
||||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
@ -94,12 +95,13 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class WebFluxConfigurationSupportTests {
|
class WebFluxConfigurationSupportTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestMappingHandlerMapping() {
|
void requestMappingHandlerMapping() {
|
||||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||||
final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
|
Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
|
||||||
|
assertThat(field).isNotNull();
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
|
|
||||||
String name = "requestMappingHandlerMapping";
|
String name = "requestMappingHandlerMapping";
|
||||||
|
@ -109,9 +111,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
assertThat(mapping.getOrder()).isEqualTo(0);
|
assertThat(mapping.getOrder()).isEqualTo(0);
|
||||||
|
|
||||||
PathPatternParser patternParser = mapping.getPathPatternParser();
|
PathPatternParser patternParser = mapping.getPathPatternParser();
|
||||||
assertThat(patternParser).isNotNull();
|
assertThat(patternParser).hasFieldOrPropertyWithValue("matchOptionalTrailingSeparator", false);
|
||||||
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
|
|
||||||
assertThat(matchOptionalTrailingSlash).isFalse();
|
|
||||||
|
|
||||||
name = "webFluxContentTypeResolver";
|
name = "webFluxContentTypeResolver";
|
||||||
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
|
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
|
||||||
|
@ -123,7 +123,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPathMatchConfig() {
|
void customPathMatchConfig() {
|
||||||
ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);
|
ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);
|
||||||
|
|
||||||
String name = "requestMappingHandlerMapping";
|
String name = "requestMappingHandlerMapping";
|
||||||
|
@ -137,7 +137,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestMappingHandlerAdapter() {
|
void requestMappingHandlerAdapter() {
|
||||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||||
|
|
||||||
String name = "requestMappingHandlerAdapter";
|
String name = "requestMappingHandlerAdapter";
|
||||||
|
@ -175,7 +175,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customMessageConverterConfig() {
|
void customMessageConverterConfig() {
|
||||||
ApplicationContext context = loadConfig(CustomMessageConverterConfig.class);
|
ApplicationContext context = loadConfig(CustomMessageConverterConfig.class);
|
||||||
|
|
||||||
String name = "requestMappingHandlerAdapter";
|
String name = "requestMappingHandlerAdapter";
|
||||||
|
@ -190,7 +190,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseEntityResultHandler() {
|
void responseEntityResultHandler() {
|
||||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||||
|
|
||||||
String name = "responseEntityResultHandler";
|
String name = "responseEntityResultHandler";
|
||||||
|
@ -218,7 +218,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseBodyResultHandler() {
|
void responseBodyResultHandler() {
|
||||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||||
|
|
||||||
String name = "responseBodyResultHandler";
|
String name = "responseBodyResultHandler";
|
||||||
|
@ -246,7 +246,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void viewResolutionResultHandler() {
|
void viewResolutionResultHandler() {
|
||||||
ApplicationContext context = loadConfig(CustomViewResolverConfig.class);
|
ApplicationContext context = loadConfig(CustomViewResolverConfig.class);
|
||||||
|
|
||||||
String name = "viewResolutionResultHandler";
|
String name = "viewResolutionResultHandler";
|
||||||
|
@ -267,7 +267,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandler() {
|
void resourceHandler() {
|
||||||
ApplicationContext context = loadConfig(CustomResourceHandlingConfig.class);
|
ApplicationContext context = loadConfig(CustomResourceHandlingConfig.class);
|
||||||
|
|
||||||
String name = "resourceHandlerMapping";
|
String name = "resourceHandlerMapping";
|
||||||
|
@ -282,7 +282,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceUrlProvider() throws Exception {
|
void resourceUrlProvider() {
|
||||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||||
|
|
||||||
String name = "resourceUrlProvider";
|
String name = "resourceUrlProvider";
|
||||||
|
@ -291,11 +291,11 @@ public class WebFluxConfigurationSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void assertHasMessageReader(List<HttpMessageReader<?>> readers, ResolvableType type, MediaType mediaType) {
|
private void assertHasMessageReader(List<HttpMessageReader<?>> readers, ResolvableType type, @Nullable MediaType mediaType) {
|
||||||
assertThat(readers.stream().anyMatch(c -> mediaType == null || c.canRead(type, mediaType))).isTrue();
|
assertThat(readers.stream().anyMatch(c -> mediaType == null || c.canRead(type, mediaType))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertHasMessageWriter(List<HttpMessageWriter<?>> writers, ResolvableType type, MediaType mediaType) {
|
private void assertHasMessageWriter(List<HttpMessageWriter<?>> writers, ResolvableType type, @Nullable MediaType mediaType) {
|
||||||
assertThat(writers.stream().anyMatch(c -> mediaType == null || c.canWrite(type, mediaType))).isTrue();
|
assertThat(writers.stream().anyMatch(c -> mediaType == null || c.canWrite(type, mediaType))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -325,9 +325,7 @@ class BodyExtractorsTests {
|
||||||
assertThat(form).as("Invalid result").hasSize(3);
|
assertThat(form).as("Invalid result").hasSize(3);
|
||||||
assertThat(form.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
|
assertThat(form.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
|
||||||
List<String> values = form.get("name 2");
|
List<String> values = form.get("name 2");
|
||||||
assertThat(values).as("Invalid result").hasSize(2);
|
assertThat(values).as("Invalid result").containsExactly("value 2+1", "value 2+2");
|
||||||
assertThat(values).element(0).as("Invalid result").isEqualTo("value 2+1");
|
|
||||||
assertThat(values).element(1).as("Invalid result").isEqualTo("value 2+2");
|
|
||||||
assertThat(form.getFirst("name 3")).as("Invalid result").isNull();
|
assertThat(form.getFirst("name 3")).as("Invalid result").isNull();
|
||||||
})
|
})
|
||||||
.expectComplete()
|
.expectComplete()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -75,7 +75,7 @@ import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class BodyInsertersTests {
|
class BodyInsertersTests {
|
||||||
|
|
||||||
private BodyInserter.Context context;
|
private BodyInserter.Context context;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class BodyInsertersTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void createContext() {
|
void createContext() {
|
||||||
final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||||
messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
|
messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
|
||||||
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
|
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
|
||||||
|
@ -115,7 +115,7 @@ public class BodyInsertersTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofString() {
|
void ofString() {
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
BodyInserter<String, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
|
BodyInserter<String, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofObject() {
|
void ofObject() {
|
||||||
User body = new User("foo", "bar");
|
User body = new User("foo", "bar");
|
||||||
BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
|
BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
|
||||||
MockServerHttpResponse response = new MockServerHttpResponse();
|
MockServerHttpResponse response = new MockServerHttpResponse();
|
||||||
|
@ -146,7 +146,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofObjectWithHints() {
|
void ofObjectWithHints() {
|
||||||
User body = new User("foo", "bar");
|
User body = new User("foo", "bar");
|
||||||
BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
|
BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
|
||||||
this.hints.put(JSON_VIEW_HINT, SafeToSerialize.class);
|
this.hints.put(JSON_VIEW_HINT, SafeToSerialize.class);
|
||||||
|
@ -161,7 +161,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofProducerWithMono() {
|
void ofProducerWithMono() {
|
||||||
Mono<User> body = Mono.just(new User("foo", "bar"));
|
Mono<User> body = Mono.just(new User("foo", "bar"));
|
||||||
BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, User.class);
|
BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, User.class);
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofProducerWithFlux() {
|
void ofProducerWithFlux() {
|
||||||
Flux<String> body = Flux.just("foo");
|
Flux<String> body = Flux.just("foo");
|
||||||
BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, String.class);
|
BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, String.class);
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofProducerWithSingle() {
|
void ofProducerWithSingle() {
|
||||||
Single<User> body = Single.just(new User("foo", "bar"));
|
Single<User> body = Single.just(new User("foo", "bar"));
|
||||||
BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, User.class);
|
BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, User.class);
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofPublisher() {
|
void ofPublisher() {
|
||||||
Flux<String> body = Flux.just("foo");
|
Flux<String> body = Flux.just("foo");
|
||||||
BodyInserter<Flux<String>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromPublisher(body, String.class);
|
BodyInserter<Flux<String>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromPublisher(body, String.class);
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofResource() throws IOException {
|
void ofResource() throws IOException {
|
||||||
Resource resource = new ClassPathResource("response.txt", getClass());
|
Resource resource = new ClassPathResource("response.txt", getClass());
|
||||||
|
|
||||||
MockServerHttpResponse response = new MockServerHttpResponse();
|
MockServerHttpResponse response = new MockServerHttpResponse();
|
||||||
|
@ -267,7 +267,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofResourceRange() throws IOException {
|
void ofResourceRange() throws IOException {
|
||||||
final int rangeStart = 10;
|
final int rangeStart = 10;
|
||||||
Resource body = new ClassPathResource("response.txt", getClass());
|
Resource body = new ClassPathResource("response.txt", getClass());
|
||||||
BodyInserter<Resource, ReactiveHttpOutputMessage> inserter = BodyInserters.fromResource(body);
|
BodyInserter<Resource, ReactiveHttpOutputMessage> inserter = BodyInserters.fromResource(body);
|
||||||
|
@ -310,7 +310,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofServerSentEventFlux() {
|
void ofServerSentEventFlux() {
|
||||||
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
|
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
|
||||||
Flux<ServerSentEvent<String>> body = Flux.just(event);
|
Flux<ServerSentEvent<String>> body = Flux.just(event);
|
||||||
BodyInserter<Flux<ServerSentEvent<String>>, ServerHttpResponse> inserter =
|
BodyInserter<Flux<ServerSentEvent<String>>, ServerHttpResponse> inserter =
|
||||||
|
@ -322,7 +322,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromFormDataMap() {
|
void fromFormDataMap() {
|
||||||
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
|
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
|
||||||
body.set("name 1", "value 1");
|
body.set("name 1", "value 1");
|
||||||
body.add("name 2", "value 2+1");
|
body.add("name 2", "value 2+1");
|
||||||
|
@ -349,7 +349,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromFormDataWith() {
|
void fromFormDataWith() {
|
||||||
BodyInserter<MultiValueMap<String, String>, ClientHttpRequest>
|
BodyInserter<MultiValueMap<String, String>, ClientHttpRequest>
|
||||||
inserter = BodyInserters.fromFormData("name 1", "value 1")
|
inserter = BodyInserters.fromFormData("name 1", "value 1")
|
||||||
.with("name 2", "value 2+1")
|
.with("name 2", "value 2+1")
|
||||||
|
@ -373,7 +373,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromMultipartData() {
|
void fromMultipartData() {
|
||||||
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
||||||
map.set("name 3", "value 3");
|
map.set("name 3", "value 3");
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ public class BodyInsertersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofDataBuffers() {
|
void ofDataBuffers() {
|
||||||
byte[] bytes = "foo".getBytes(UTF_8);
|
byte[] bytes = "foo".getBytes(UTF_8);
|
||||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -101,7 +101,6 @@ class DefaultClientResponseBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
void mutateWithCustomStatus() {
|
void mutateWithCustomStatus() {
|
||||||
ClientResponse other = ClientResponse.create(499, ExchangeStrategies.withDefaults()).build();
|
ClientResponse other = ClientResponse.create(499, ExchangeStrategies.withDefaults()).build();
|
||||||
ClientResponse result = other.mutate().build();
|
ClientResponse result = other.mutate().build();
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class DefaultWebClientTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
ClientResponse mockResponse = mock();
|
ClientResponse mockResponse = mock();
|
||||||
when(mockResponse.statusCode()).thenReturn(HttpStatus.OK);
|
when(mockResponse.statusCode()).thenReturn(HttpStatus.OK);
|
||||||
when(mockResponse.bodyToMono(Void.class)).thenReturn(Mono.empty());
|
when(mockResponse.bodyToMono(Void.class)).thenReturn(Mono.empty());
|
||||||
|
@ -83,7 +83,7 @@ public class DefaultWebClientTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basic() {
|
void basic() {
|
||||||
this.builder.build().get().uri("/path")
|
this.builder.build().get().uri("/path")
|
||||||
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uriBuilder() {
|
void uriBuilder() {
|
||||||
this.builder.build().get()
|
this.builder.build().get()
|
||||||
.uri(builder -> builder.path("/path").queryParam("q", "12").build())
|
.uri(builder -> builder.path("/path").queryParam("q", "12").build())
|
||||||
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
||||||
|
@ -115,7 +115,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uriBuilderWithPathOverride() {
|
void uriBuilderWithPathOverride() {
|
||||||
this.builder.build().get()
|
this.builder.build().get()
|
||||||
.uri(builder -> builder.replacePath("/path").build())
|
.uri(builder -> builder.replacePath("/path").build())
|
||||||
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
||||||
|
@ -125,7 +125,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestHeaderAndCookie() {
|
void requestHeaderAndCookie() {
|
||||||
this.builder.build().get().uri("/path").accept(MediaType.APPLICATION_JSON)
|
this.builder.build().get().uri("/path").accept(MediaType.APPLICATION_JSON)
|
||||||
.cookies(cookies -> cookies.add("id", "123")) // SPR-16178
|
.cookies(cookies -> cookies.add("id", "123")) // SPR-16178
|
||||||
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
||||||
|
@ -165,7 +165,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpRequest() {
|
void httpRequest() {
|
||||||
this.builder.build().get().uri("/path")
|
this.builder.build().get().uri("/path")
|
||||||
.httpRequest(httpRequest -> {})
|
.httpRequest(httpRequest -> {})
|
||||||
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
.retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
|
||||||
|
@ -175,7 +175,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultHeaderAndCookie() {
|
void defaultHeaderAndCookie() {
|
||||||
WebClient client = this.builder
|
WebClient client = this.builder
|
||||||
.defaultHeader("Accept", "application/json")
|
.defaultHeader("Accept", "application/json")
|
||||||
.defaultCookie("id", "123")
|
.defaultCookie("id", "123")
|
||||||
|
@ -190,7 +190,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultHeaderAndCookieOverrides() {
|
void defaultHeaderAndCookieOverrides() {
|
||||||
WebClient client = this.builder
|
WebClient client = this.builder
|
||||||
.defaultHeader("Accept", "application/json")
|
.defaultHeader("Accept", "application/json")
|
||||||
.defaultCookie("id", "123")
|
.defaultCookie("id", "123")
|
||||||
|
@ -207,7 +207,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultHeaderAndCookieCopies() {
|
void defaultHeaderAndCookieCopies() {
|
||||||
WebClient client1 = this.builder
|
WebClient client1 = this.builder
|
||||||
.defaultHeader("Accept", "application/json")
|
.defaultHeader("Accept", "application/json")
|
||||||
.defaultCookie("id", "123")
|
.defaultCookie("id", "123")
|
||||||
|
@ -234,7 +234,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultRequest() {
|
void defaultRequest() {
|
||||||
ThreadLocal<String> context = new NamedThreadLocal<>("foo");
|
ThreadLocal<String> context = new NamedThreadLocal<>("foo");
|
||||||
|
|
||||||
Map<String, Object> actual = new HashMap<>();
|
Map<String, Object> actual = new HashMap<>();
|
||||||
|
@ -261,7 +261,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bodyObjectPublisher() {
|
void bodyObjectPublisher() {
|
||||||
Mono<Void> mono = Mono.empty();
|
Mono<Void> mono = Mono.empty();
|
||||||
WebClient client = this.builder.build();
|
WebClient client = this.builder.build();
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mutateDoesCopy() {
|
void mutateDoesCopy() {
|
||||||
// First, build the clients
|
// First, build the clients
|
||||||
|
|
||||||
WebClient.Builder builder = WebClient.builder()
|
WebClient.Builder builder = WebClient.builder()
|
||||||
|
@ -327,7 +327,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withStringAttribute() {
|
void withStringAttribute() {
|
||||||
Map<String, Object> actual = new HashMap<>();
|
Map<String, Object> actual = new HashMap<>();
|
||||||
ExchangeFilterFunction filter = (request, next) -> {
|
ExchangeFilterFunction filter = (request, next) -> {
|
||||||
actual.putAll(request.attributes());
|
actual.putAll(request.attributes());
|
||||||
|
@ -346,7 +346,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withNullAttribute() {
|
void withNullAttribute() {
|
||||||
Map<String, Object> actual = new HashMap<>();
|
Map<String, Object> actual = new HashMap<>();
|
||||||
ExchangeFilterFunction filter = (request, next) -> {
|
ExchangeFilterFunction filter = (request, next) -> {
|
||||||
actual.putAll(request.attributes());
|
actual.putAll(request.attributes());
|
||||||
|
@ -365,7 +365,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uriTemplateAttribute() {
|
void uriTemplateAttribute() {
|
||||||
testUriTemplateAttribute(client -> client.get().uri("/{id}", 1), "/base/{id}");
|
testUriTemplateAttribute(client -> client.get().uri("/{id}", 1), "/base/{id}");
|
||||||
testUriTemplateAttribute(client -> client.get().uri("/{id}", Map.of("id", 1)), "/base/{id}");
|
testUriTemplateAttribute(client -> client.get().uri("/{id}", Map.of("id", 1)), "/base/{id}");
|
||||||
testUriTemplateAttribute(client -> client.get().uri("/{id}", builder -> builder.build(1)), "/base/{id}");
|
testUriTemplateAttribute(client -> client.get().uri("/{id}", builder -> builder.build(1)), "/base/{id}");
|
||||||
|
@ -389,7 +389,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void apply() {
|
void apply() {
|
||||||
WebClient client = this.builder
|
WebClient client = this.builder
|
||||||
.apply(builder -> builder
|
.apply(builder -> builder
|
||||||
.defaultHeader("Accept", "application/json")
|
.defaultHeader("Accept", "application/json")
|
||||||
|
@ -404,7 +404,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switchToErrorOnEmptyClientResponseMono() {
|
void switchToErrorOnEmptyClientResponseMono() {
|
||||||
ExchangeFunction exchangeFunction = mock();
|
ExchangeFunction exchangeFunction = mock();
|
||||||
given(exchangeFunction.exchange(any())).willReturn(Mono.empty());
|
given(exchangeFunction.exchange(any())).willReturn(Mono.empty());
|
||||||
WebClient client = WebClient.builder().baseUrl("/base").exchangeFunction(exchangeFunction).build();
|
WebClient client = WebClient.builder().baseUrl("/base").exchangeFunction(exchangeFunction).build();
|
||||||
|
@ -414,7 +414,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldApplyFiltersAtSubscription() {
|
void shouldApplyFiltersAtSubscription() {
|
||||||
WebClient client = this.builder
|
WebClient client = this.builder
|
||||||
.filter((request, next) ->
|
.filter((request, next) ->
|
||||||
next.exchange(ClientRequest
|
next.exchange(ClientRequest
|
||||||
|
@ -449,7 +449,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onStatusHandlerRegisteredGlobally() {
|
void onStatusHandlerRegisteredGlobally() {
|
||||||
|
|
||||||
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
|
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
|
||||||
given(exchangeFunction.exchange(any())).willReturn(Mono.just(response));
|
given(exchangeFunction.exchange(any())).willReturn(Mono.just(response));
|
||||||
|
@ -466,7 +466,7 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onStatusHandlerRegisteredGloballyHaveLowerPrecedence() {
|
void onStatusHandlerRegisteredGloballyHaveLowerPrecedence() {
|
||||||
|
|
||||||
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
|
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
|
||||||
given(exchangeFunction.exchange(any())).willReturn(Mono.just(response));
|
given(exchangeFunction.exchange(any())).willReturn(Mono.just(response));
|
||||||
|
@ -483,7 +483,6 @@ public class DefaultWebClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-23880
|
@Test // gh-23880
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void onStatusHandlersDefaultHandlerIsLast() {
|
public void onStatusHandlersDefaultHandlerIsLast() {
|
||||||
|
|
||||||
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
|
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
|
||||||
|
|
|
@ -44,13 +44,13 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class ExchangeFilterFunctionsTests {
|
class ExchangeFilterFunctionsTests {
|
||||||
|
|
||||||
private static final URI DEFAULT_URL = URI.create("https://example.com");
|
private static final URI DEFAULT_URL = URI.create("https://example.com");
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andThen() {
|
void andThen() {
|
||||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||||
ClientResponse response = mock();
|
ClientResponse response = mock();
|
||||||
ExchangeFunction exchange = r -> Mono.just(response);
|
ExchangeFunction exchange = r -> Mono.just(response);
|
||||||
|
@ -60,7 +60,6 @@ public class ExchangeFilterFunctionsTests {
|
||||||
assertThat(filtersInvoked[0]).isFalse();
|
assertThat(filtersInvoked[0]).isFalse();
|
||||||
assertThat(filtersInvoked[1]).isFalse();
|
assertThat(filtersInvoked[1]).isFalse();
|
||||||
filtersInvoked[0] = true;
|
filtersInvoked[0] = true;
|
||||||
assertThat(filtersInvoked[1]).isFalse();
|
|
||||||
return n.exchange(r);
|
return n.exchange(r);
|
||||||
};
|
};
|
||||||
ExchangeFilterFunction filter2 = (r, n) -> {
|
ExchangeFilterFunction filter2 = (r, n) -> {
|
||||||
|
@ -80,7 +79,7 @@ public class ExchangeFilterFunctionsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void apply() {
|
void apply() {
|
||||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||||
ClientResponse response = mock();
|
ClientResponse response = mock();
|
||||||
ExchangeFunction exchange = r -> Mono.just(response);
|
ExchangeFunction exchange = r -> Mono.just(response);
|
||||||
|
@ -99,7 +98,7 @@ public class ExchangeFilterFunctionsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicAuthenticationUsernamePassword() {
|
void basicAuthenticationUsernamePassword() {
|
||||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||||
ClientResponse response = mock();
|
ClientResponse response = mock();
|
||||||
|
|
||||||
|
@ -116,7 +115,7 @@ public class ExchangeFilterFunctionsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicAuthenticationInvalidCharacters() {
|
void basicAuthenticationInvalidCharacters() {
|
||||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||||
ExchangeFunction exchange = r -> Mono.just(mock());
|
ExchangeFunction exchange = r -> Mono.just(mock());
|
||||||
|
|
||||||
|
@ -163,7 +162,7 @@ public class ExchangeFilterFunctionsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void statusHandlerMatch() {
|
void statusHandlerMatch() {
|
||||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||||
ClientResponse response = mock();
|
ClientResponse response = mock();
|
||||||
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
|
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
|
||||||
|
@ -181,7 +180,7 @@ public class ExchangeFilterFunctionsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void statusHandlerNoMatch() {
|
void statusHandlerNoMatch() {
|
||||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||||
ClientResponse response = mock();
|
ClientResponse response = mock();
|
||||||
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
|
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
|
||||||
|
@ -197,7 +196,7 @@ public class ExchangeFilterFunctionsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void limitResponseSize() {
|
void limitResponseSize() {
|
||||||
DataBuffer b1 = dataBuffer("foo");
|
DataBuffer b1 = dataBuffer("foo");
|
||||||
DataBuffer b2 = dataBuffer("bar");
|
DataBuffer b2 = dataBuffer("bar");
|
||||||
DataBuffer b3 = dataBuffer("baz");
|
DataBuffer b3 = dataBuffer("baz");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,17 +23,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class ExchangeStrategiesTests {
|
class ExchangeStrategiesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void empty() {
|
void empty() {
|
||||||
ExchangeStrategies strategies = ExchangeStrategies.empty().build();
|
ExchangeStrategies strategies = ExchangeStrategies.empty().build();
|
||||||
assertThat(strategies.messageReaders()).isEmpty();
|
assertThat(strategies.messageReaders()).isEmpty();
|
||||||
assertThat(strategies.messageWriters()).isEmpty();
|
assertThat(strategies.messageWriters()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withDefaults() {
|
void withDefaults() {
|
||||||
ExchangeStrategies strategies = ExchangeStrategies.withDefaults();
|
ExchangeStrategies strategies = ExchangeStrategies.withDefaults();
|
||||||
assertThat(strategies.messageReaders()).isNotEmpty();
|
assertThat(strategies.messageReaders()).isNotEmpty();
|
||||||
assertThat(strategies.messageWriters()).isNotEmpty();
|
assertThat(strategies.messageWriters()).isNotEmpty();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -737,7 +737,7 @@ class WebClientIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedWebClientTest // SPR-16246
|
@ParameterizedWebClientTest // SPR-16246
|
||||||
void postLargeTextFile(ClientHttpConnector connector) throws Exception {
|
void postLargeTextFile(ClientHttpConnector connector) {
|
||||||
startServer(connector);
|
startServer(connector);
|
||||||
|
|
||||||
prepareResponse(response -> {});
|
prepareResponse(response -> {});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -135,17 +135,12 @@ class WebClientObservationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setsCurrentObservationInReactorContext() {
|
void setsCurrentObservationInReactorContext() {
|
||||||
ExchangeFilterFunction assertionFilter = new ExchangeFilterFunction() {
|
ExchangeFilterFunction assertionFilter = (request, chain) -> chain.exchange(request).contextWrite(context -> {
|
||||||
@Override
|
|
||||||
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction chain) {
|
|
||||||
return chain.exchange(request).contextWrite(context -> {
|
|
||||||
Observation currentObservation = context.get(ObservationThreadLocalAccessor.KEY);
|
Observation currentObservation = context.get(ObservationThreadLocalAccessor.KEY);
|
||||||
assertThat(currentObservation).isNotNull();
|
assertThat(currentObservation).isNotNull();
|
||||||
assertThat(currentObservation.getContext()).isInstanceOf(ClientRequestObservationContext.class);
|
assertThat(currentObservation.getContext()).isInstanceOf(ClientRequestObservationContext.class);
|
||||||
return context;
|
return context;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
this.builder.filter(assertionFilter).build().get().uri("/resource/{id}", 42)
|
this.builder.filter(assertionFilter).build().get().uri("/resource/{id}", 42)
|
||||||
.retrieve().bodyToMono(Void.class)
|
.retrieve().bodyToMono(Void.class)
|
||||||
.block(Duration.ofSeconds(10));
|
.block(Duration.ofSeconds(10));
|
||||||
|
@ -154,9 +149,7 @@ class WebClientObservationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setsCurrentObservationContextAsRequestAttribute() {
|
void setsCurrentObservationContextAsRequestAttribute() {
|
||||||
ExchangeFilterFunction assertionFilter = new ExchangeFilterFunction() {
|
ExchangeFilterFunction assertionFilter = (request, chain) -> {
|
||||||
@Override
|
|
||||||
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction chain) {
|
|
||||||
Optional<ClientRequestObservationContext> observationContext = ClientRequestObservationContext.findCurrent(request);
|
Optional<ClientRequestObservationContext> observationContext = ClientRequestObservationContext.findCurrent(request);
|
||||||
assertThat(observationContext).isPresent();
|
assertThat(observationContext).isPresent();
|
||||||
return chain.exchange(request).contextWrite(context -> {
|
return chain.exchange(request).contextWrite(context -> {
|
||||||
|
@ -164,7 +157,6 @@ class WebClientObservationTests {
|
||||||
assertThat(currentObservation.getContext()).isEqualTo(observationContext.get());
|
assertThat(currentObservation.getContext()).isEqualTo(observationContext.get());
|
||||||
return context;
|
return context;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
this.builder.filter(assertionFilter).build().get().uri("/resource/{id}", 42)
|
this.builder.filter(assertionFilter).build().get().uri("/resource/{id}", 42)
|
||||||
.retrieve().bodyToMono(Void.class)
|
.retrieve().bodyToMono(Void.class)
|
||||||
|
@ -211,7 +203,7 @@ class WebClientObservationTests {
|
||||||
|
|
||||||
static class MockClientHeaders implements ClientResponse.Headers {
|
static class MockClientHeaders implements ClientResponse.Headers {
|
||||||
|
|
||||||
private HttpHeaders headers = new HttpHeaders();
|
private final HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OptionalLong contentLength() {
|
public OptionalLong contentLength() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -69,7 +69,6 @@ class ClientResponseWrapperTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
void cookies() {
|
void cookies() {
|
||||||
MultiValueMap<String, ResponseCookie> cookies = mock();
|
MultiValueMap<String, ResponseCookie> cookies = mock();
|
||||||
given(mockResponse.cookies()).willReturn(cookies);
|
given(mockResponse.cookies()).willReturn(cookies);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -60,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
public class WebClientAdapterTests {
|
class WebClientAdapterTests {
|
||||||
|
|
||||||
private static final String ANOTHER_SERVER_RESPONSE_BODY = "Hello Spring 2!";
|
private static final String ANOTHER_SERVER_RESPONSE_BODY = "Hello Spring 2!";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,7 +23,6 @@ import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
@ -68,7 +67,7 @@ class AttributesTestVisitor implements RouterFunctions.Visitor {
|
||||||
public void route(RequestPredicate predicate, HandlerFunction<?> handlerFunction) {
|
public void route(RequestPredicate predicate, HandlerFunction<?> handlerFunction) {
|
||||||
Stream<Map<String, Object>> current = Optional.ofNullable(attributes).stream();
|
Stream<Map<String, Object>> current = Optional.ofNullable(attributes).stream();
|
||||||
Stream<Map<String, Object>> nested = nestedAttributes.stream().filter(Objects::nonNull);
|
Stream<Map<String, Object>> nested = nestedAttributes.stream().filter(Objects::nonNull);
|
||||||
routerFunctionsAttributes.add(Stream.concat(current, nested).collect(Collectors.toUnmodifiableList()));
|
routerFunctionsAttributes.add(Stream.concat(current, nested).toList());
|
||||||
attributes = null;
|
attributes = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -190,7 +190,7 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.valueOf(this.foo) + ":" + String.valueOf(this.bar);
|
return this.foo + ":" + this.bar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.foo + ":" + String.valueOf(this.bar);
|
return this.foo + ":" + this.bar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -18,7 +18,6 @@ package org.springframework.web.reactive.function.server;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -254,7 +253,7 @@ class DefaultEntityResponseBuilderTests {
|
||||||
@Test
|
@Test
|
||||||
void notModifiedLastModified() {
|
void notModifiedLastModified() {
|
||||||
ZonedDateTime now = ZonedDateTime.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
|
ZonedDateTime oneMinuteBeforeNow = now.minusMinutes(1);
|
||||||
|
|
||||||
EntityResponse<String> responseMono = EntityResponse.fromObject("bar")
|
EntityResponse<String> responseMono = EntityResponse.fromObject("bar")
|
||||||
.lastModified(oneMinuteBeforeNow)
|
.lastModified(oneMinuteBeforeNow)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -57,10 +57,10 @@ import static org.mockito.Mockito.verify;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class DefaultRenderingResponseTests {
|
class DefaultRenderingResponseTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() {
|
void create() {
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create(name).build();
|
Mono<RenderingResponse> result = RenderingResponse.create(name).build();
|
||||||
StepVerifier.create(result)
|
StepVerifier.create(result)
|
||||||
|
@ -70,7 +70,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headers() {
|
void headers() {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("foo").headers(headers).build();
|
Mono<RenderingResponse> result = RenderingResponse.create("foo").headers(headers).build();
|
||||||
StepVerifier.create(result)
|
StepVerifier.create(result)
|
||||||
|
@ -81,7 +81,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttribute() {
|
void modelAttribute() {
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||||
.modelAttribute("foo", "bar").build();
|
.modelAttribute("foo", "bar").build();
|
||||||
StepVerifier.create(result)
|
StepVerifier.create(result)
|
||||||
|
@ -91,7 +91,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttributeConventions() {
|
void modelAttributeConventions() {
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||||
.modelAttribute("bar").build();
|
.modelAttribute("bar").build();
|
||||||
StepVerifier.create(result)
|
StepVerifier.create(result)
|
||||||
|
@ -101,7 +101,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttributes() {
|
void modelAttributes() {
|
||||||
Map<String, String> model = Collections.singletonMap("foo", "bar");
|
Map<String, String> model = Collections.singletonMap("foo", "bar");
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||||
.modelAttributes(model).build();
|
.modelAttributes(model).build();
|
||||||
|
@ -112,7 +112,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttributesConventions() {
|
void modelAttributesConventions() {
|
||||||
Set<String> model = Collections.singleton("bar");
|
Set<String> model = Collections.singleton("bar");
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||||
.modelAttributes(model).build();
|
.modelAttributes(model).build();
|
||||||
|
@ -123,7 +123,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cookies() {
|
void cookies() {
|
||||||
MultiValueMap<String, ResponseCookie> newCookies = new LinkedMultiValueMap<>();
|
MultiValueMap<String, ResponseCookie> newCookies = new LinkedMultiValueMap<>();
|
||||||
newCookies.add("name", ResponseCookie.from("name", "value").build());
|
newCookies.add("name", ResponseCookie.from("name", "value").build());
|
||||||
Mono<RenderingResponse> result =
|
Mono<RenderingResponse> result =
|
||||||
|
@ -136,7 +136,7 @@ public class DefaultRenderingResponseTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void render() {
|
void render() {
|
||||||
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
|
Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void writeTo() {
|
void writeTo() {
|
||||||
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
||||||
RenderingResponse renderingResponse = RenderingResponse.create("view")
|
RenderingResponse renderingResponse = RenderingResponse.create("view")
|
||||||
.status(HttpStatus.FOUND)
|
.status(HttpStatus.FOUND)
|
||||||
|
@ -195,7 +195,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultContentType() {
|
void defaultContentType() {
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("view").build();
|
Mono<RenderingResponse> result = RenderingResponse.create("view").build();
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||||
|
@ -228,7 +228,7 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notModifiedEtag() {
|
void notModifiedEtag() {
|
||||||
String etag = "\"foo\"";
|
String etag = "\"foo\"";
|
||||||
RenderingResponse responseMono = RenderingResponse.create("bar")
|
RenderingResponse responseMono = RenderingResponse.create("bar")
|
||||||
.header(HttpHeaders.ETAG, etag)
|
.header(HttpHeaders.ETAG, etag)
|
||||||
|
@ -250,9 +250,9 @@ public class DefaultRenderingResponseTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notModifiedLastModified() {
|
void notModifiedLastModified() {
|
||||||
ZonedDateTime now = ZonedDateTime.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
|
ZonedDateTime oneMinuteBeforeNow = now.minusMinutes(1);
|
||||||
|
|
||||||
RenderingResponse responseMono = RenderingResponse.create("bar")
|
RenderingResponse responseMono = RenderingResponse.create("bar")
|
||||||
.header(HttpHeaders.LAST_MODIFIED, DateTimeFormatter.RFC_1123_DATE_TIME.format(oneMinuteBeforeNow))
|
.header(HttpHeaders.LAST_MODIFIED, DateTimeFormatter.RFC_1123_DATE_TIME.format(oneMinuteBeforeNow))
|
||||||
|
|
|
@ -40,10 +40,10 @@ import static org.assertj.core.api.Assertions.entry;
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class DefaultServerRequestBuilderTests {
|
class DefaultServerRequestBuilderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void from() {
|
void from() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.post("https://example.com")
|
MockServerHttpRequest request = MockServerHttpRequest.post("https://example.com")
|
||||||
.header("foo", "bar")
|
.header("foo", "bar")
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -78,7 +78,7 @@ import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
public class DefaultServerRequestTests {
|
class DefaultServerRequestTests {
|
||||||
|
|
||||||
private final List<HttpMessageReader<?>> messageReaders = Arrays.asList(
|
private final List<HttpMessageReader<?>> messageReaders = Arrays.asList(
|
||||||
new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()),
|
new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()),
|
||||||
|
@ -86,7 +86,7 @@ public class DefaultServerRequestTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void method() {
|
void method() {
|
||||||
HttpMethod method = HttpMethod.HEAD;
|
HttpMethod method = HttpMethod.HEAD;
|
||||||
DefaultServerRequest request = new DefaultServerRequest(
|
DefaultServerRequest request = new DefaultServerRequest(
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.method(method, "https://example.com")),
|
MockServerWebExchange.from(MockServerHttpRequest.method(method, "https://example.com")),
|
||||||
|
@ -96,7 +96,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uri() {
|
void uri() {
|
||||||
URI uri = URI.create("https://example.com");
|
URI uri = URI.create("https://example.com");
|
||||||
|
|
||||||
DefaultServerRequest request = new DefaultServerRequest(
|
DefaultServerRequest request = new DefaultServerRequest(
|
||||||
|
@ -107,7 +107,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uriBuilder() throws URISyntaxException {
|
void uriBuilder() throws URISyntaxException {
|
||||||
URI uri = new URI("http", "localhost", "/path", "a=1", null);
|
URI uri = new URI("http", "localhost", "/path", "a=1", null);
|
||||||
DefaultServerRequest request = new DefaultServerRequest(
|
DefaultServerRequest request = new DefaultServerRequest(
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, uri)),
|
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, uri)),
|
||||||
|
@ -123,7 +123,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void attribute() {
|
void attribute() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.method(HttpMethod.GET, "https://example.com"));
|
MockServerHttpRequest.method(HttpMethod.GET, "https://example.com"));
|
||||||
exchange.getAttributes().put("foo", "bar");
|
exchange.getAttributes().put("foo", "bar");
|
||||||
|
@ -134,7 +134,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryParams() {
|
void queryParams() {
|
||||||
DefaultServerRequest request = new DefaultServerRequest(
|
DefaultServerRequest request = new DefaultServerRequest(
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo=bar")),
|
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo=bar")),
|
||||||
this.messageReaders);
|
this.messageReaders);
|
||||||
|
@ -143,7 +143,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyQueryParam() {
|
void emptyQueryParam() {
|
||||||
DefaultServerRequest request = new DefaultServerRequest(
|
DefaultServerRequest request = new DefaultServerRequest(
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
|
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
|
||||||
this.messageReaders);
|
this.messageReaders);
|
||||||
|
@ -152,7 +152,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void absentQueryParam() {
|
void absentQueryParam() {
|
||||||
DefaultServerRequest request = new DefaultServerRequest(
|
DefaultServerRequest request = new DefaultServerRequest(
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
|
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
|
||||||
this.messageReaders);
|
this.messageReaders);
|
||||||
|
@ -161,7 +161,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathVariable() {
|
void pathVariable() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
|
||||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||||
|
@ -173,7 +173,7 @@ public class DefaultServerRequestTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathVariableNotFound() {
|
void pathVariableNotFound() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
|
||||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||||
|
@ -185,7 +185,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathVariables() {
|
void pathVariables() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
|
||||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||||
|
@ -196,7 +196,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void header() {
|
void header() {
|
||||||
HttpHeaders httpHeaders = new HttpHeaders();
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
List<MediaType> accept =
|
List<MediaType> accept =
|
||||||
Collections.singletonList(MediaType.APPLICATION_JSON);
|
Collections.singletonList(MediaType.APPLICATION_JSON);
|
||||||
|
@ -229,7 +229,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cookies() {
|
void cookies() {
|
||||||
HttpCookie cookie = new HttpCookie("foo", "bar");
|
HttpCookie cookie = new HttpCookie("foo", "bar");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.method(HttpMethod.GET, "https://example.com").cookie(cookie));
|
MockServerHttpRequest.method(HttpMethod.GET, "https://example.com").cookie(cookie));
|
||||||
|
@ -386,7 +386,7 @@ public class DefaultServerRequestTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void formData() {
|
void formData() {
|
||||||
byte[] bytes = "foo=bar&baz=qux".getBytes(StandardCharsets.UTF_8);
|
byte[] bytes = "foo=bar&baz=qux".getBytes(StandardCharsets.UTF_8);
|
||||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||||
|
@ -410,7 +410,7 @@ public class DefaultServerRequestTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipartData() {
|
void multipartData() {
|
||||||
String data = """
|
String data = """
|
||||||
--12345
|
--12345
|
||||||
Content-Disposition: form-data; name="foo"
|
Content-Disposition: form-data; name="foo"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -19,7 +19,6 @@ package org.springframework.web.reactive.function.server;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -392,7 +391,7 @@ class DefaultServerResponseBuilderTests {
|
||||||
@Test
|
@Test
|
||||||
void notModifiedLastModified() {
|
void notModifiedLastModified() {
|
||||||
ZonedDateTime now = ZonedDateTime.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
|
ZonedDateTime oneMinuteBeforeNow = now.minusMinutes(1);
|
||||||
|
|
||||||
ServerResponse responseMono = ServerResponse.ok()
|
ServerResponse responseMono = ServerResponse.ok()
|
||||||
.lastModified(oneMinuteBeforeNow)
|
.lastModified(oneMinuteBeforeNow)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,10 +23,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class HandlerStrategiesTests {
|
class HandlerStrategiesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void empty() {
|
void empty() {
|
||||||
HandlerStrategies strategies = HandlerStrategies.empty().build();
|
HandlerStrategies strategies = HandlerStrategies.empty().build();
|
||||||
assertThat(strategies.messageReaders()).isEmpty();
|
assertThat(strategies.messageReaders()).isEmpty();
|
||||||
assertThat(strategies.messageWriters()).isEmpty();
|
assertThat(strategies.messageWriters()).isEmpty();
|
||||||
|
@ -34,7 +34,7 @@ public class HandlerStrategiesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withDefaults() {
|
void withDefaults() {
|
||||||
HandlerStrategies strategies = HandlerStrategies.withDefaults();
|
HandlerStrategies strategies = HandlerStrategies.withDefaults();
|
||||||
assertThat(strategies.messageReaders()).isNotEmpty();
|
assertThat(strategies.messageReaders()).isNotEmpty();
|
||||||
assertThat(strategies.messageWriters()).isNotEmpty();
|
assertThat(strategies.messageWriters()).isNotEmpty();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -33,10 +33,10 @@ import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class PathResourceLookupFunctionTests {
|
class PathResourceLookupFunctionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void normal() throws Exception {
|
void normal() throws Exception {
|
||||||
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
|
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
|
||||||
|
|
||||||
PathResourceLookupFunction
|
PathResourceLookupFunction
|
||||||
|
@ -60,7 +60,7 @@ public class PathResourceLookupFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void subPath() throws Exception {
|
void subPath() throws Exception {
|
||||||
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
|
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
|
||||||
|
|
||||||
PathResourceLookupFunction function = new PathResourceLookupFunction("/resources/**", location);
|
PathResourceLookupFunction function = new PathResourceLookupFunction("/resources/**", location);
|
||||||
|
@ -83,7 +83,7 @@ public class PathResourceLookupFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notFound() throws Exception {
|
void notFound() {
|
||||||
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
|
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
|
||||||
|
|
||||||
PathResourceLookupFunction function = new PathResourceLookupFunction("/resources/**", location);
|
PathResourceLookupFunction function = new PathResourceLookupFunction("/resources/**", location);
|
||||||
|
@ -96,7 +96,7 @@ public class PathResourceLookupFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void composeResourceLookupFunction() throws Exception {
|
void composeResourceLookupFunction() {
|
||||||
ClassPathResource defaultResource = new ClassPathResource("response.txt", getClass());
|
ClassPathResource defaultResource = new ClassPathResource("response.txt", getClass());
|
||||||
|
|
||||||
Function<ServerRequest, Mono<Resource>> lookupFunction =
|
Function<ServerRequest, Mono<Resource>> lookupFunction =
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -31,12 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class RequestPredicateAttributesTests {
|
class RequestPredicateAttributesTests {
|
||||||
|
|
||||||
private DefaultServerRequest request;
|
private DefaultServerRequest request;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void createRequest() {
|
void createRequest() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com/path").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com/path").build();
|
||||||
MockServerWebExchange webExchange = MockServerWebExchange.from(request);
|
MockServerWebExchange webExchange = MockServerWebExchange.from(request);
|
||||||
webExchange.getAttributes().put("exchange", "bar");
|
webExchange.getAttributes().put("exchange", "bar");
|
||||||
|
@ -48,7 +48,7 @@ public class RequestPredicateAttributesTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void negateSucceed() {
|
void negateSucceed() {
|
||||||
RequestPredicate predicate = new AddAttributePredicate(false, "predicate", "baz").negate();
|
RequestPredicate predicate = new AddAttributePredicate(false, "predicate", "baz").negate();
|
||||||
|
|
||||||
boolean result = predicate.test(this.request);
|
boolean result = predicate.test(this.request);
|
||||||
|
@ -59,7 +59,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void negateFail() {
|
void negateFail() {
|
||||||
RequestPredicate predicate = new AddAttributePredicate(true, "predicate", "baz").negate();
|
RequestPredicate predicate = new AddAttributePredicate(true, "predicate", "baz").negate();
|
||||||
|
|
||||||
boolean result = predicate.test(this.request);
|
boolean result = predicate.test(this.request);
|
||||||
|
@ -70,7 +70,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andBothSucceed() {
|
void andBothSucceed() {
|
||||||
RequestPredicate left = new AddAttributePredicate(true, "left", "baz");
|
RequestPredicate left = new AddAttributePredicate(true, "left", "baz");
|
||||||
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
||||||
|
@ -84,7 +84,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andLeftSucceed() {
|
void andLeftSucceed() {
|
||||||
RequestPredicate left = new AddAttributePredicate(true, "left", "bar");
|
RequestPredicate left = new AddAttributePredicate(true, "left", "bar");
|
||||||
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
||||||
|
@ -98,7 +98,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andRightSucceed() {
|
void andRightSucceed() {
|
||||||
RequestPredicate left = new AddAttributePredicate(false, "left", "bar");
|
RequestPredicate left = new AddAttributePredicate(false, "left", "bar");
|
||||||
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
||||||
|
@ -112,7 +112,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andBothFail() {
|
void andBothFail() {
|
||||||
RequestPredicate left = new AddAttributePredicate(false, "left", "bar");
|
RequestPredicate left = new AddAttributePredicate(false, "left", "bar");
|
||||||
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
|
||||||
|
@ -126,7 +126,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orBothSucceed() {
|
void orBothSucceed() {
|
||||||
RequestPredicate left = new AddAttributePredicate(true, "left", "baz");
|
RequestPredicate left = new AddAttributePredicate(true, "left", "baz");
|
||||||
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
||||||
|
@ -140,7 +140,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orLeftSucceed() {
|
void orLeftSucceed() {
|
||||||
RequestPredicate left = new AddAttributePredicate(true, "left", "baz");
|
RequestPredicate left = new AddAttributePredicate(true, "left", "baz");
|
||||||
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
||||||
|
@ -154,7 +154,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orRightSucceed() {
|
void orRightSucceed() {
|
||||||
RequestPredicate left = new AddAttributePredicate(false, "left", "baz");
|
RequestPredicate left = new AddAttributePredicate(false, "left", "baz");
|
||||||
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(true, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
||||||
|
@ -168,7 +168,7 @@ public class RequestPredicateAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orBothFail() {
|
void orBothFail() {
|
||||||
RequestPredicate left = new AddAttributePredicate(false, "left", "baz");
|
RequestPredicate left = new AddAttributePredicate(false, "left", "baz");
|
||||||
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
RequestPredicate right = new AddAttributePredicate(false, "right", "qux");
|
||||||
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -28,10 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class RequestPredicateTests {
|
class RequestPredicateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void and() {
|
void and() {
|
||||||
RequestPredicate predicate1 = request -> true;
|
RequestPredicate predicate1 = request -> true;
|
||||||
RequestPredicate predicate2 = request -> true;
|
RequestPredicate predicate2 = request -> true;
|
||||||
RequestPredicate predicate3 = request -> false;
|
RequestPredicate predicate3 = request -> false;
|
||||||
|
@ -44,7 +44,7 @@ public class RequestPredicateTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void negate() {
|
void negate() {
|
||||||
RequestPredicate predicate = request -> false;
|
RequestPredicate predicate = request -> false;
|
||||||
RequestPredicate negated = predicate.negate();
|
RequestPredicate negated = predicate.negate();
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class RequestPredicateTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void or() {
|
void or() {
|
||||||
RequestPredicate predicate1 = request -> true;
|
RequestPredicate predicate1 = request -> true;
|
||||||
RequestPredicate predicate2 = request -> false;
|
RequestPredicate predicate2 = request -> false;
|
||||||
RequestPredicate predicate3 = request -> false;
|
RequestPredicate predicate3 = request -> false;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -34,11 +34,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class RequestPredicatesTests {
|
class RequestPredicatesTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void all() {
|
void all() {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
||||||
MockServerWebExchange mockExchange = MockServerWebExchange.from(mockRequest);
|
MockServerWebExchange mockExchange = MockServerWebExchange.from(mockRequest);
|
||||||
RequestPredicate predicate = RequestPredicates.all();
|
RequestPredicate predicate = RequestPredicates.all();
|
||||||
|
@ -47,7 +47,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void method() {
|
void method() {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
||||||
|
|
||||||
HttpMethod httpMethod = HttpMethod.GET;
|
HttpMethod httpMethod = HttpMethod.GET;
|
||||||
|
@ -61,7 +61,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void methodCorsPreFlight() {
|
void methodCorsPreFlight() {
|
||||||
RequestPredicate predicate = RequestPredicates.method(HttpMethod.PUT);
|
RequestPredicate predicate = RequestPredicates.method(HttpMethod.PUT);
|
||||||
|
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.options("https://example.com")
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.options("https://example.com")
|
||||||
|
@ -82,7 +82,7 @@ public class RequestPredicatesTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void methods() {
|
void methods() {
|
||||||
RequestPredicate predicate = RequestPredicates.methods(HttpMethod.GET, HttpMethod.HEAD);
|
RequestPredicate predicate = RequestPredicates.methods(HttpMethod.GET, HttpMethod.HEAD);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
||||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||||
|
@ -98,7 +98,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allMethods() {
|
void allMethods() {
|
||||||
RequestPredicate predicate = RequestPredicates.GET("/p*");
|
RequestPredicate predicate = RequestPredicates.GET("/p*");
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com/path").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com/path").build();
|
||||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||||
|
@ -136,7 +136,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void path() {
|
void path() {
|
||||||
URI uri = URI.create("https://localhost/path");
|
URI uri = URI.create("https://localhost/path");
|
||||||
RequestPredicate predicate = RequestPredicates.path("/p*");
|
RequestPredicate predicate = RequestPredicates.path("/p*");
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get(uri.toString()).build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get(uri.toString()).build();
|
||||||
|
@ -149,7 +149,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathNoLeadingSlash() {
|
void pathNoLeadingSlash() {
|
||||||
RequestPredicate predicate = RequestPredicates.path("p*");
|
RequestPredicate predicate = RequestPredicates.path("p*");
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com/path").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com/path").build();
|
||||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||||
|
@ -157,7 +157,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathEncoded() {
|
void pathEncoded() {
|
||||||
URI uri = URI.create("https://localhost/foo%20bar");
|
URI uri = URI.create("https://localhost/foo%20bar");
|
||||||
RequestPredicate predicate = RequestPredicates.path("/foo bar");
|
RequestPredicate predicate = RequestPredicates.path("/foo bar");
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
||||||
|
@ -166,7 +166,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathPredicates() {
|
void pathPredicates() {
|
||||||
PathPatternParser parser = new PathPatternParser();
|
PathPatternParser parser = new PathPatternParser();
|
||||||
parser.setCaseSensitive(false);
|
parser.setCaseSensitive(false);
|
||||||
Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser);
|
Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser);
|
||||||
|
@ -178,7 +178,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathWithContext() {
|
void pathWithContext() {
|
||||||
RequestPredicate predicate = RequestPredicates.path("/p*");
|
RequestPredicate predicate = RequestPredicates.path("/p*");
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://localhost/context/path")
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://localhost/context/path")
|
||||||
.contextPath("/context").build();
|
.contextPath("/context").build();
|
||||||
|
@ -187,7 +187,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headers() {
|
void headers() {
|
||||||
String name = "MyHeader";
|
String name = "MyHeader";
|
||||||
String value = "MyValue";
|
String value = "MyValue";
|
||||||
RequestPredicate predicate =
|
RequestPredicate predicate =
|
||||||
|
@ -207,7 +207,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headersCors() {
|
void headersCors() {
|
||||||
RequestPredicate predicate = RequestPredicates.headers(headers -> false);
|
RequestPredicate predicate = RequestPredicates.headers(headers -> false);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.options("https://example.com")
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.options("https://example.com")
|
||||||
.header("Origin", "https://example.com")
|
.header("Origin", "https://example.com")
|
||||||
|
@ -219,7 +219,7 @@ public class RequestPredicatesTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contentType() {
|
void contentType() {
|
||||||
MediaType json = MediaType.APPLICATION_JSON;
|
MediaType json = MediaType.APPLICATION_JSON;
|
||||||
RequestPredicate predicate = RequestPredicates.contentType(json);
|
RequestPredicate predicate = RequestPredicates.contentType(json);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com")
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com")
|
||||||
|
@ -236,7 +236,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void accept() {
|
void accept() {
|
||||||
MediaType json = MediaType.APPLICATION_JSON;
|
MediaType json = MediaType.APPLICATION_JSON;
|
||||||
RequestPredicate predicate = RequestPredicates.accept(json);
|
RequestPredicate predicate = RequestPredicates.accept(json);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com")
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com")
|
||||||
|
@ -253,7 +253,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathExtension() {
|
void pathExtension() {
|
||||||
RequestPredicate predicate = RequestPredicates.pathExtension("txt");
|
RequestPredicate predicate = RequestPredicates.pathExtension("txt");
|
||||||
|
|
||||||
URI uri = URI.create("https://localhost/file.txt");
|
URI uri = URI.create("https://localhost/file.txt");
|
||||||
|
@ -276,7 +276,7 @@ public class RequestPredicatesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryParam() {
|
void queryParam() {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com")
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com")
|
||||||
.queryParam("foo", "bar").build();
|
.queryParam("foo", "bar").build();
|
||||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class ResourceHandlerFunctionTests {
|
class ResourceHandlerFunctionTests {
|
||||||
|
|
||||||
private final Resource resource = new ClassPathResource("response.txt", getClass());
|
private final Resource resource = new ClassPathResource("response.txt", getClass());
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class ResourceHandlerFunctionTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void createContext() {
|
void createContext() {
|
||||||
HandlerStrategies strategies = HandlerStrategies.withDefaults();
|
HandlerStrategies strategies = HandlerStrategies.withDefaults();
|
||||||
context = new ServerResponse.Context() {
|
context = new ServerResponse.Context() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +69,7 @@ public class ResourceHandlerFunctionTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void get() throws IOException {
|
void get() throws IOException {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class ResourceHandlerFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void head() throws IOException {
|
void head() throws IOException {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head("http://localhost"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head("http://localhost"));
|
||||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ public class ResourceHandlerFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void options() {
|
void options() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("http://localhost"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("http://localhost"));
|
||||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -43,10 +43,10 @@ import static org.springframework.web.reactive.function.server.RequestPredicates
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class RouterFunctionBuilderTests {
|
class RouterFunctionBuilderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void route() {
|
void route() {
|
||||||
RouterFunction<ServerResponse> route = RouterFunctions.route()
|
RouterFunction<ServerResponse> route = RouterFunctions.route()
|
||||||
.GET("/foo", request -> ServerResponse.ok().build())
|
.GET("/foo", request -> ServerResponse.ok().build())
|
||||||
.POST("/", RequestPredicates.contentType(MediaType.TEXT_PLAIN), request -> ServerResponse.noContent().build())
|
.POST("/", RequestPredicates.contentType(MediaType.TEXT_PLAIN), request -> ServerResponse.noContent().build())
|
||||||
|
@ -103,7 +103,7 @@ public class RouterFunctionBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resources() {
|
void resources() {
|
||||||
Resource resource = new ClassPathResource("/org/springframework/web/reactive/function/server/");
|
Resource resource = new ClassPathResource("/org/springframework/web/reactive/function/server/");
|
||||||
assertThat(resource.exists()).isTrue();
|
assertThat(resource.exists()).isTrue();
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ public class RouterFunctionBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourcesCaching() {
|
void resourcesCaching() {
|
||||||
Resource resource = new ClassPathResource("/org/springframework/web/reactive/function/server/");
|
Resource resource = new ClassPathResource("/org/springframework/web/reactive/function/server/");
|
||||||
assertThat(resource.exists()).isTrue();
|
assertThat(resource.exists()).isTrue();
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ public class RouterFunctionBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nest() {
|
void nest() {
|
||||||
RouterFunction<?> route = RouterFunctions.route()
|
RouterFunction<?> route = RouterFunctions.route()
|
||||||
.path("/foo", builder ->
|
.path("/foo", builder ->
|
||||||
builder.path("/bar",
|
builder.path("/bar",
|
||||||
|
@ -178,7 +178,7 @@ public class RouterFunctionBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filters() {
|
void filters() {
|
||||||
AtomicInteger filterCount = new AtomicInteger();
|
AtomicInteger filterCount = new AtomicInteger();
|
||||||
|
|
||||||
RouterFunction<?> route = RouterFunctions.route()
|
RouterFunction<?> route = RouterFunctions.route()
|
||||||
|
@ -232,7 +232,7 @@ public class RouterFunctionBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleOnErrors() {
|
void multipleOnErrors() {
|
||||||
RouterFunction<ServerResponse> route = RouterFunctions.route()
|
RouterFunction<ServerResponse> route = RouterFunctions.route()
|
||||||
.GET("/error", request -> Mono.error(new IOException()))
|
.GET("/error", request -> Mono.error(new IOException()))
|
||||||
.onError(IOException.class, (t, r) -> ServerResponse.status(200).build())
|
.onError(IOException.class, (t, r) -> ServerResponse.status(200).build())
|
||||||
|
@ -253,7 +253,7 @@ public class RouterFunctionBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void attributes() {
|
void attributes() {
|
||||||
RouterFunction<ServerResponse> route = RouterFunctions.route()
|
RouterFunction<ServerResponse> route = RouterFunctions.route()
|
||||||
.GET("/atts/1", request -> ServerResponse.ok().build())
|
.GET("/atts/1", request -> ServerResponse.ok().build())
|
||||||
.withAttribute("foo", "bar")
|
.withAttribute("foo", "bar")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -36,10 +36,10 @@ import static org.springframework.web.reactive.function.server.RequestPredicates
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class RouterFunctionTests {
|
class RouterFunctionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void and() {
|
void and() {
|
||||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
|
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
|
||||||
RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty();
|
RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty();
|
||||||
RouterFunction<ServerResponse> routerFunction2 = request -> Mono.just(handlerFunction);
|
RouterFunction<ServerResponse> routerFunction2 = request -> Mono.just(handlerFunction);
|
||||||
|
@ -58,7 +58,7 @@ public class RouterFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andOther() {
|
void andOther() {
|
||||||
HandlerFunction<ServerResponse> handlerFunction =
|
HandlerFunction<ServerResponse> handlerFunction =
|
||||||
request -> ServerResponse.ok().bodyValue("42");
|
request -> ServerResponse.ok().bodyValue("42");
|
||||||
RouterFunction<?> routerFunction1 = request -> Mono.empty();
|
RouterFunction<?> routerFunction1 = request -> Mono.empty();
|
||||||
|
@ -79,7 +79,7 @@ public class RouterFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andRoute() {
|
void andRoute() {
|
||||||
RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty();
|
RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty();
|
||||||
RequestPredicate requestPredicate = request -> true;
|
RequestPredicate requestPredicate = request -> true;
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class RouterFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filter() {
|
void filter() {
|
||||||
Mono<String> stringMono = Mono.just("42");
|
Mono<String> stringMono = Mono.just("42");
|
||||||
HandlerFunction<EntityResponse<Mono<String>>> handlerFunction =
|
HandlerFunction<EntityResponse<Mono<String>>> handlerFunction =
|
||||||
request -> EntityResponse.fromPublisher(stringMono, String.class).build();
|
request -> EntityResponse.fromPublisher(stringMono, String.class).build();
|
||||||
|
@ -133,7 +133,7 @@ public class RouterFunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void attributes() {
|
void attributes() {
|
||||||
RouterFunction<ServerResponse> route = RouterFunctions.route(
|
RouterFunction<ServerResponse> route = RouterFunctions.route(
|
||||||
GET("/atts/1"), request -> ServerResponse.ok().build())
|
GET("/atts/1"), request -> ServerResponse.ok().build())
|
||||||
.withAttribute("foo", "bar")
|
.withAttribute("foo", "bar")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -223,7 +223,6 @@ class RouterFunctionsTests {
|
||||||
public HttpStatus statusCode() {
|
public HttpStatus statusCode() {
|
||||||
return HttpStatus.OK;
|
return HttpStatus.OK;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public int rawStatusCode() {
|
public int rawStatusCode() {
|
||||||
return 200;
|
return 200;
|
||||||
|
@ -262,7 +261,6 @@ class RouterFunctionsTests {
|
||||||
public HttpStatus statusCode() {
|
public HttpStatus statusCode() {
|
||||||
return HttpStatus.OK;
|
return HttpStatus.OK;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public int rawStatusCode() {
|
public int rawStatusCode() {
|
||||||
return 200;
|
return 200;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -131,7 +131,6 @@ class ServerRequestWrapperTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
void cookies() {
|
void cookies() {
|
||||||
MultiValueMap<String, HttpCookie> cookies = mock();
|
MultiValueMap<String, HttpCookie> cookies = mock();
|
||||||
given(mockRequest.cookies()).willReturn(cookies);
|
given(mockRequest.cookies()).willReturn(cookies);
|
||||||
|
|
|
@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class CorsUrlHandlerMappingTests {
|
class CorsUrlHandlerMappingTests {
|
||||||
|
|
||||||
private AbstractUrlHandlerMapping handlerMapping;
|
private AbstractUrlHandlerMapping handlerMapping;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
this.handlerMapping = new AbstractUrlHandlerMapping() {};
|
this.handlerMapping = new AbstractUrlHandlerMapping() {};
|
||||||
this.handlerMapping.registerHandler("/welcome.html", this.welcomeController);
|
this.handlerMapping.registerHandler("/welcome.html", this.welcomeController);
|
||||||
this.handlerMapping.registerHandler("/cors.html", this.corsController);
|
this.handlerMapping.registerHandler("/cors.html", this.corsController);
|
||||||
|
@ -55,7 +55,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void actualRequestWithoutCorsConfigurationProvider() throws Exception {
|
void actualRequestWithoutCorsConfigurationProvider() {
|
||||||
String origin = "https://domain2.com";
|
String origin = "https://domain2.com";
|
||||||
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/welcome.html", origin);
|
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/welcome.html", origin);
|
||||||
Object actual = this.handlerMapping.getHandler(exchange).block();
|
Object actual = this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -65,7 +65,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestWithoutCorsConfigurationProvider() throws Exception {
|
void preflightRequestWithoutCorsConfigurationProvider() {
|
||||||
String origin = "https://domain2.com";
|
String origin = "https://domain2.com";
|
||||||
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/welcome.html", origin);
|
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/welcome.html", origin);
|
||||||
Object actual = this.handlerMapping.getHandler(exchange).block();
|
Object actual = this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -75,7 +75,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void actualRequestWithCorsAwareHandler() throws Exception {
|
void actualRequestWithCorsAwareHandler() {
|
||||||
String origin = "https://domain2.com";
|
String origin = "https://domain2.com";
|
||||||
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/cors.html", origin);
|
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/cors.html", origin);
|
||||||
Object actual = this.handlerMapping.getHandler(exchange).block();
|
Object actual = this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -86,7 +86,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preFlightWithCorsAwareHandler() throws Exception {
|
void preFlightWithCorsAwareHandler() {
|
||||||
String origin = "https://domain2.com";
|
String origin = "https://domain2.com";
|
||||||
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/cors.html", origin);
|
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/cors.html", origin);
|
||||||
Object actual = this.handlerMapping.getHandler(exchange).block();
|
Object actual = this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -97,7 +97,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void actualRequestWithGlobalCorsConfig() throws Exception {
|
void actualRequestWithGlobalCorsConfig() {
|
||||||
CorsConfiguration mappedConfig = new CorsConfiguration();
|
CorsConfiguration mappedConfig = new CorsConfiguration();
|
||||||
mappedConfig.addAllowedOrigin("*");
|
mappedConfig.addAllowedOrigin("*");
|
||||||
this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/welcome.html", mappedConfig));
|
this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/welcome.html", mappedConfig));
|
||||||
|
@ -112,7 +112,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void actualRequestWithGlobalPatternCorsConfig() throws Exception {
|
void actualRequestWithGlobalPatternCorsConfig() {
|
||||||
CorsConfiguration mappedConfig = new CorsConfiguration();
|
CorsConfiguration mappedConfig = new CorsConfiguration();
|
||||||
mappedConfig.addAllowedOriginPattern("https://*.domain2.com");
|
mappedConfig.addAllowedOriginPattern("https://*.domain2.com");
|
||||||
this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/welcome.html", mappedConfig));
|
this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/welcome.html", mappedConfig));
|
||||||
|
@ -128,7 +128,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preFlightRequestWithGlobalCorsConfig() throws Exception {
|
void preFlightRequestWithGlobalCorsConfig() {
|
||||||
CorsConfiguration mappedConfig = new CorsConfiguration();
|
CorsConfiguration mappedConfig = new CorsConfiguration();
|
||||||
mappedConfig.addAllowedOrigin("*");
|
mappedConfig.addAllowedOrigin("*");
|
||||||
this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/welcome.html", mappedConfig));
|
this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/welcome.html", mappedConfig));
|
||||||
|
@ -143,7 +143,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void actualRequestWithCorsConfigurationSource() throws Exception {
|
void actualRequestWithCorsConfigurationSource() {
|
||||||
this.handlerMapping.setCorsConfigurationSource(new CustomCorsConfigurationSource());
|
this.handlerMapping.setCorsConfigurationSource(new CustomCorsConfigurationSource());
|
||||||
|
|
||||||
String origin = "https://domain2.com";
|
String origin = "https://domain2.com";
|
||||||
|
@ -159,7 +159,7 @@ public class CorsUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preFlightRequestWithCorsConfigurationSource() throws Exception {
|
void preFlightRequestWithCorsConfigurationSource() {
|
||||||
this.handlerMapping.setCorsConfigurationSource(new CustomCorsConfigurationSource());
|
this.handlerMapping.setCorsConfigurationSource(new CustomCorsConfigurationSource());
|
||||||
|
|
||||||
String origin = "https://domain2.com";
|
String origin = "https://domain2.com";
|
||||||
|
|
|
@ -41,10 +41,9 @@ import static org.springframework.web.reactive.HandlerMapping.PATH_WITHIN_HANDLE
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class SimpleUrlHandlerMappingTests {
|
class SimpleUrlHandlerMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("resource")
|
|
||||||
void handlerMappingJavaConfig() {
|
void handlerMappingJavaConfig() {
|
||||||
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
|
||||||
wac.register(WebConfig.class);
|
wac.register(WebConfig.class);
|
||||||
|
@ -61,7 +60,6 @@ public class SimpleUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("resource")
|
|
||||||
void handlerMappingXmlConfig() {
|
void handlerMappingXmlConfig() {
|
||||||
ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext("map.xml", getClass());
|
ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext("map.xml", getClass());
|
||||||
wac.refresh();
|
wac.refresh();
|
||||||
|
@ -106,7 +104,6 @@ public class SimpleUrlHandlerMappingTests {
|
||||||
if (bean != null) {
|
if (bean != null) {
|
||||||
assertThat(actual).isNotNull();
|
assertThat(actual).isNotNull();
|
||||||
assertThat(actual).isSameAs(bean);
|
assertThat(actual).isSameAs(bean);
|
||||||
//noinspection OptionalGetWithoutIsPresent
|
|
||||||
PathContainer path = exchange.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
|
PathContainer path = exchange.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
|
||||||
assertThat(path).isNotNull();
|
assertThat(path).isNotNull();
|
||||||
assertThat(path.value()).isEqualTo(pathWithinMapping);
|
assertThat(path.value()).isEqualTo(pathWithinMapping);
|
||||||
|
|
|
@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class WebFluxResponseStatusExceptionHandlerTests extends AbstractResponseStatusExceptionHandlerTests {
|
class WebFluxResponseStatusExceptionHandlerTests extends AbstractResponseStatusExceptionHandlerTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseStatusExceptionHandler createResponseStatusExceptionHandler() {
|
protected ResponseStatusExceptionHandler createResponseStatusExceptionHandler() {
|
||||||
|
@ -42,14 +42,14 @@ public class WebFluxResponseStatusExceptionHandlerTests extends AbstractResponse
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleAnnotatedException() {
|
void handleAnnotatedException() {
|
||||||
Throwable ex = new CustomException();
|
Throwable ex = new CustomException();
|
||||||
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
|
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
|
||||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
|
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleNestedAnnotatedException() {
|
void handleNestedAnnotatedException() {
|
||||||
Throwable ex = new Exception(new CustomException());
|
Throwable ex = new Exception(new CustomException());
|
||||||
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
|
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
|
||||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
|
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.web.reactive.resource;
|
package org.springframework.web.reactive.resource;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -55,7 +54,7 @@ public class CachingResourceResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
|
|
||||||
this.cache = new ConcurrentMapCache("resourceCache");
|
this.cache = new ConcurrentMapCache("resourceCache");
|
||||||
|
|
||||||
|
@ -70,7 +69,7 @@ public class CachingResourceResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceInternal() {
|
void resolveResourceInternal() {
|
||||||
Resource expected = new ClassPathResource("test/bar.css", getClass());
|
Resource expected = new ClassPathResource("test/bar.css", getClass());
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
||||||
Resource actual = this.chain.resolveResource(exchange, "bar.css", this.locations).block(TIMEOUT);
|
Resource actual = this.chain.resolveResource(exchange, "bar.css", this.locations).block(TIMEOUT);
|
||||||
|
@ -80,7 +79,7 @@ public class CachingResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceInternalFromCache() {
|
void resolveResourceInternalFromCache() {
|
||||||
Resource expected = mock();
|
Resource expected = mock();
|
||||||
this.cache.put(resourceKey("bar.css"), expected);
|
this.cache.put(resourceKey("bar.css"), expected);
|
||||||
|
|
||||||
|
@ -91,13 +90,13 @@ public class CachingResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceInternalNoMatch() {
|
void resolveResourceInternalNoMatch() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
||||||
assertThat(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT)).isNull();
|
assertThat(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolverUrlPath() {
|
void resolverUrlPath() {
|
||||||
String expected = "/foo.css";
|
String expected = "/foo.css";
|
||||||
String actual = this.chain.resolveUrlPath(expected, this.locations).block(TIMEOUT);
|
String actual = this.chain.resolveUrlPath(expected, this.locations).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -105,7 +104,7 @@ public class CachingResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolverUrlPathFromCache() {
|
void resolverUrlPathFromCache() {
|
||||||
String expected = "cached-imaginary.css";
|
String expected = "cached-imaginary.css";
|
||||||
this.cache.put(CachingResourceResolver.RESOLVED_URL_PATH_CACHE_KEY_PREFIX + "imaginary.css", expected);
|
this.cache.put(CachingResourceResolver.RESOLVED_URL_PATH_CACHE_KEY_PREFIX + "imaginary.css", expected);
|
||||||
String actual = this.chain.resolveUrlPath("imaginary.css", this.locations).block(TIMEOUT);
|
String actual = this.chain.resolveUrlPath("imaginary.css", this.locations).block(TIMEOUT);
|
||||||
|
@ -114,12 +113,12 @@ public class CachingResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolverUrlPathNoMatch() {
|
void resolverUrlPathNoMatch() {
|
||||||
assertThat(this.chain.resolveUrlPath("invalid.css", this.locations).block(TIMEOUT)).isNull();
|
assertThat(this.chain.resolveUrlPath("invalid.css", this.locations).block(TIMEOUT)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceAcceptEncodingInCacheKey(GzippedFiles gzippedFiles) throws IOException {
|
void resolveResourceAcceptEncodingInCacheKey(GzippedFiles gzippedFiles) {
|
||||||
|
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
gzippedFiles.create(file);
|
gzippedFiles.create(file);
|
||||||
|
@ -152,7 +151,7 @@ public class CachingResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceNoAcceptEncoding() {
|
void resolveResourceNoAcceptEncoding() {
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get(file));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get(file));
|
||||||
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
|
@ -164,7 +163,7 @@ public class CachingResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceMatchingEncoding() {
|
void resolveResourceMatchingEncoding() {
|
||||||
Resource resource = mock();
|
Resource resource = mock();
|
||||||
Resource gzipped = mock();
|
Resource gzipped = mock();
|
||||||
this.cache.put(resourceKey("bar.css"), resource);
|
this.cache.put(resourceKey("bar.css"), resource);
|
||||||
|
|
|
@ -34,19 +34,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
public class ContentBasedVersionStrategyTests {
|
class ContentBasedVersionStrategyTests {
|
||||||
|
|
||||||
private ContentVersionStrategy strategy = new ContentVersionStrategy();
|
private ContentVersionStrategy strategy = new ContentVersionStrategy();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
VersionResourceResolver versionResourceResolver = new VersionResourceResolver();
|
VersionResourceResolver versionResourceResolver = new VersionResourceResolver();
|
||||||
versionResourceResolver.setStrategyMap(Collections.singletonMap("/**", this.strategy));
|
versionResourceResolver.setStrategyMap(Collections.singletonMap("/**", this.strategy));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extractVersion() {
|
void extractVersion() {
|
||||||
String hash = "7fbe76cdac6093784895bb4989203e5a";
|
String hash = "7fbe76cdac6093784895bb4989203e5a";
|
||||||
String path = "font-awesome/css/font-awesome.min-" + hash + ".css";
|
String path = "font-awesome/css/font-awesome.min-" + hash + ".css";
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class ContentBasedVersionStrategyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeVersion() {
|
void removeVersion() {
|
||||||
String hash = "7fbe76cdac6093784895bb4989203e5a";
|
String hash = "7fbe76cdac6093784895bb4989203e5a";
|
||||||
String path = "font-awesome/css/font-awesome.min%s%s.css";
|
String path = "font-awesome/css/font-awesome.min%s%s.css";
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class ContentBasedVersionStrategyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceVersion() throws Exception {
|
void getResourceVersion() throws Exception {
|
||||||
Resource expected = new ClassPathResource("test/bar.css", getClass());
|
Resource expected = new ClassPathResource("test/bar.css", getClass());
|
||||||
String hash = DigestUtils.md5DigestAsHex(FileCopyUtils.copyToByteArray(expected.getInputStream()));
|
String hash = DigestUtils.md5DigestAsHex(FileCopyUtils.copyToByteArray(expected.getInputStream()));
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class ContentBasedVersionStrategyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addVersionToUrl() {
|
void addVersionToUrl() {
|
||||||
assertThat(this.strategy.addVersion("test/bar.css", "123")).isEqualTo("test/bar-123.css");
|
assertThat(this.strategy.addVersion("test/bar.css", "123")).isEqualTo("test/bar-123.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ class CssLinkResourceTransformerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // https://github.com/spring-projects/spring-framework/issues/22602
|
@Test // https://github.com/spring-projects/spring-framework/issues/22602
|
||||||
void transformEmptyUrlFunction() throws Exception {
|
void transformEmptyUrlFunction() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/empty_url_function.css"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/empty_url_function.css"));
|
||||||
Resource css = getResource("empty_url_function.css");
|
Resource css = getResource("empty_url_function.css");
|
||||||
String expected = """
|
String expected = """
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class EncodedResourceResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
Cache cache = new ConcurrentMapCache("resourceCache");
|
Cache cache = new ConcurrentMapCache("resourceCache");
|
||||||
|
|
||||||
VersionResourceResolver versionResolver = new VersionResourceResolver();
|
VersionResourceResolver versionResolver = new VersionResourceResolver();
|
||||||
|
@ -73,7 +73,7 @@ public class EncodedResourceResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveGzipped(GzippedFiles gzippedFiles) {
|
void resolveGzipped(GzippedFiles gzippedFiles) {
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.get("").header("Accept-Encoding", "gzip"));
|
MockServerHttpRequest.get("").header("Accept-Encoding", "gzip"));
|
||||||
|
@ -93,7 +93,7 @@ public class EncodedResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveGzippedWithVersion(GzippedFiles gzippedFiles) {
|
void resolveGzippedWithVersion(GzippedFiles gzippedFiles) {
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.get("").header("Accept-Encoding", "gzip"));
|
MockServerHttpRequest.get("").header("Accept-Encoding", "gzip"));
|
||||||
|
@ -108,7 +108,7 @@ public class EncodedResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveFromCacheWithEncodingVariants(GzippedFiles gzippedFiles) {
|
void resolveFromCacheWithEncodingVariants(GzippedFiles gzippedFiles) {
|
||||||
|
|
||||||
// 1. Resolve, and cache .gz variant
|
// 1. Resolve, and cache .gz variant
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
public class FixedVersionStrategyTests {
|
class FixedVersionStrategyTests {
|
||||||
|
|
||||||
private static final String VERSION = "1df341f";
|
private static final String VERSION = "1df341f";
|
||||||
|
|
||||||
|
@ -39,30 +39,30 @@ public class FixedVersionStrategyTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
this.strategy = new FixedVersionStrategy(VERSION);
|
this.strategy = new FixedVersionStrategy(VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyPrefixVersion() {
|
void emptyPrefixVersion() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
new FixedVersionStrategy(" "));
|
new FixedVersionStrategy(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extractVersion() {
|
void extractVersion() {
|
||||||
assertThat(this.strategy.extractVersion(VERSION + "/" + PATH)).isEqualTo(VERSION);
|
assertThat(this.strategy.extractVersion(VERSION + "/" + PATH)).isEqualTo(VERSION);
|
||||||
assertThat(this.strategy.extractVersion(PATH)).isNull();
|
assertThat(this.strategy.extractVersion(PATH)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeVersion() {
|
void removeVersion() {
|
||||||
assertThat(this.strategy.removeVersion(VERSION + "/" + PATH, VERSION)).isEqualTo(("/" + PATH));
|
assertThat(this.strategy.removeVersion(VERSION + "/" + PATH, VERSION)).isEqualTo(("/" + PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addVersion() {
|
void addVersion() {
|
||||||
assertThat(this.strategy.addVersion("/" + PATH, VERSION)).isEqualTo((VERSION + "/" + PATH));
|
assertThat(this.strategy.addVersion("/" + PATH, VERSION)).isEqualTo((VERSION + "/" + PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -47,7 +47,7 @@ class GzipSupport implements AfterEachCallback, ParameterResolver {
|
||||||
private static final Namespace namespace = Namespace.create(GzipSupport.class);
|
private static final Namespace namespace = Namespace.create(GzipSupport.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterEach(ExtensionContext context) throws Exception {
|
public void afterEach(ExtensionContext context) {
|
||||||
GzippedFiles gzippedFiles = getStore(context).remove(GzippedFiles.class, GzippedFiles.class);
|
GzippedFiles gzippedFiles = getStore(context).remove(GzippedFiles.class, GzippedFiles.class);
|
||||||
if (gzippedFiles != null) {
|
if (gzippedFiles != null) {
|
||||||
for (File gzippedFile: gzippedFiles.created) {
|
for (File gzippedFile: gzippedFiles.created) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class PathResourceResolverTests {
|
class PathResourceResolverTests {
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class PathResourceResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveFromClasspath() throws IOException {
|
void resolveFromClasspath() throws IOException {
|
||||||
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
|
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
|
||||||
String path = "bar.css";
|
String path = "bar.css";
|
||||||
List<Resource> locations = Collections.singletonList(location);
|
List<Resource> locations = Collections.singletonList(location);
|
||||||
|
@ -54,7 +54,7 @@ public class PathResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveFromClasspathRoot() {
|
void resolveFromClasspathRoot() {
|
||||||
Resource location = new ClassPathResource("/");
|
Resource location = new ClassPathResource("/");
|
||||||
String path = "org/springframework/web/reactive/resource/test/bar.css";
|
String path = "org/springframework/web/reactive/resource/test/bar.css";
|
||||||
List<Resource> locations = Collections.singletonList(location);
|
List<Resource> locations = Collections.singletonList(location);
|
||||||
|
@ -80,7 +80,7 @@ public class PathResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkResource() throws IOException {
|
void checkResource() throws IOException {
|
||||||
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
|
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
|
||||||
testCheckResource(location, "../testsecret/secret.txt");
|
testCheckResource(location, "../testsecret/secret.txt");
|
||||||
testCheckResource(location, "test/../../testsecret/secret.txt");
|
testCheckResource(location, "test/../../testsecret/secret.txt");
|
||||||
|
@ -98,7 +98,7 @@ public class PathResourceResolverTests {
|
||||||
testCheckResource(location, "url:" + secretPath);
|
testCheckResource(location, "url:" + secretPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testCheckResource(Resource location, String requestPath) throws IOException {
|
private void testCheckResource(Resource location, String requestPath) {
|
||||||
List<Resource> locations = Collections.singletonList(location);
|
List<Resource> locations = Collections.singletonList(location);
|
||||||
Resource actual = this.resolver.resolveResource(null, requestPath, locations, null).block(TIMEOUT);
|
Resource actual = this.resolver.resolveResource(null, requestPath, locations, null).block(TIMEOUT);
|
||||||
assertThat(actual).isNull();
|
assertThat(actual).isNull();
|
||||||
|
@ -116,7 +116,7 @@ public class PathResourceResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkResourceWithAllowedLocations() {
|
void checkResourceWithAllowedLocations() {
|
||||||
this.resolver.setAllowedLocations(
|
this.resolver.setAllowedLocations(
|
||||||
new ClassPathResource("test/", PathResourceResolver.class),
|
new ClassPathResource("test/", PathResourceResolver.class),
|
||||||
new ClassPathResource("testalternatepath/", PathResourceResolver.class)
|
new ClassPathResource("testalternatepath/", PathResourceResolver.class)
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
public class ResourceTransformerSupportTests {
|
class ResourceTransformerSupportTests {
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class ResourceTransformerSupportTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
VersionResourceResolver versionResolver = new VersionResourceResolver();
|
VersionResourceResolver versionResolver = new VersionResourceResolver();
|
||||||
versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));
|
versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));
|
||||||
PathResourceResolver pathResolver = new PathResourceResolver();
|
PathResourceResolver pathResolver = new PathResourceResolver();
|
||||||
|
@ -78,7 +78,7 @@ public class ResourceTransformerSupportTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveUrlPath() {
|
void resolveUrlPath() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
|
||||||
String resourcePath = "/resources/bar.css";
|
String resourcePath = "/resources/bar.css";
|
||||||
Resource resource = getResource("main.css");
|
Resource resource = getResource("main.css");
|
||||||
|
@ -89,7 +89,7 @@ public class ResourceTransformerSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveUrlPathWithRelativePath() {
|
void resolveUrlPathWithRelativePath() {
|
||||||
Resource resource = getResource("main.css");
|
Resource resource = getResource("main.css");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||||
String actual = this.transformer.resolveUrlPath("bar.css", exchange, resource, this.chain).block(TIMEOUT);
|
String actual = this.transformer.resolveUrlPath("bar.css", exchange, resource, this.chain).block(TIMEOUT);
|
||||||
|
@ -98,7 +98,7 @@ public class ResourceTransformerSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveUrlPathWithRelativePathInParentDirectory() {
|
void resolveUrlPathWithRelativePathInParentDirectory() {
|
||||||
Resource resource = getResource("images/image.png");
|
Resource resource = getResource("images/image.png");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||||
String actual = this.transformer.resolveUrlPath("../bar.css", exchange, resource, this.chain).block(TIMEOUT);
|
String actual = this.transformer.resolveUrlPath("../bar.css", exchange, resource, this.chain).block(TIMEOUT);
|
||||||
|
@ -107,7 +107,7 @@ public class ResourceTransformerSupportTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toAbsolutePath() {
|
void toAbsolutePath() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
|
||||||
String absolute = this.transformer.toAbsolutePath("img/image.png", exchange);
|
String absolute = this.transformer.toAbsolutePath("img/image.png", exchange);
|
||||||
assertThat(absolute).isEqualTo("/resources/img/image.png");
|
assertThat(absolute).isEqualTo("/resources/img/image.png");
|
||||||
|
|
|
@ -46,7 +46,7 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
public class ResourceUrlProviderTests {
|
class ResourceUrlProviderTests {
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
||||||
|
|
||||||
|
@ -129,7 +129,6 @@ public class ResourceUrlProviderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-12592
|
@Test // SPR-12592
|
||||||
@SuppressWarnings("resource")
|
|
||||||
void initializeOnce() {
|
void initializeOnce() {
|
||||||
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||||
context.setServletContext(new MockServletContext());
|
context.setServletContext(new MockServletContext());
|
||||||
|
|
|
@ -135,7 +135,7 @@ class ResourceWebHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void servesHtmlResources() throws Exception {
|
void servesHtmlResources() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||||
setPathWithinHandlerMapping(exchange, "foo.html");
|
setPathWithinHandlerMapping(exchange, "foo.html");
|
||||||
setBestMachingPattern(exchange, "/**");
|
setBestMachingPattern(exchange, "/**");
|
||||||
|
@ -204,7 +204,7 @@ class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("httpMethods")
|
@MethodSource("httpMethods")
|
||||||
void resourceNotFound(HttpMethod method) throws Exception {
|
void resourceNotFound(HttpMethod method) {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.method(method, "").build();
|
MockServerHttpRequest request = MockServerHttpRequest.method(method, "").build();
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "not-there.css");
|
setPathWithinHandlerMapping(exchange, "not-there.css");
|
||||||
|
@ -579,7 +579,7 @@ class ResourceWebHandlerTests {
|
||||||
private ResourceWebHandler handler;
|
private ResourceWebHandler handler;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() throws Exception {
|
void setup() {
|
||||||
this.handler = new ResourceWebHandler();
|
this.handler = new ResourceWebHandler();
|
||||||
this.handler.setLocations(List.of(testResource, testAlternatePathResource, webjarsResource));
|
this.handler.setLocations(List.of(testResource, testAlternatePathResource, webjarsResource));
|
||||||
}
|
}
|
||||||
|
@ -690,23 +690,23 @@ class ResourceWebHandlerTests {
|
||||||
Resource location = new ClassPathResource("test/", getClass());
|
Resource location = new ClassPathResource("test/", getClass());
|
||||||
this.handler.setLocations(List.of(location));
|
this.handler.setLocations(List.of(location));
|
||||||
|
|
||||||
testResolvePathWithTraversal(method, "../testsecret/secret.txt", location);
|
testResolvePathWithTraversal(method, "../testsecret/secret.txt");
|
||||||
testResolvePathWithTraversal(method, "test/../../testsecret/secret.txt", location);
|
testResolvePathWithTraversal(method, "test/../../testsecret/secret.txt");
|
||||||
testResolvePathWithTraversal(method, ":/../../testsecret/secret.txt", location);
|
testResolvePathWithTraversal(method, ":/../../testsecret/secret.txt");
|
||||||
|
|
||||||
location = new UrlResource(getClass().getResource("./test/"));
|
location = new UrlResource(getClass().getResource("./test/"));
|
||||||
this.handler.setLocations(List.of(location));
|
this.handler.setLocations(List.of(location));
|
||||||
Resource secretResource = new UrlResource(getClass().getResource("testsecret/secret.txt"));
|
Resource secretResource = new UrlResource(getClass().getResource("testsecret/secret.txt"));
|
||||||
String secretPath = secretResource.getURL().getPath();
|
String secretPath = secretResource.getURL().getPath();
|
||||||
|
|
||||||
testResolvePathWithTraversal(method, "file:" + secretPath, location);
|
testResolvePathWithTraversal(method, "file:" + secretPath);
|
||||||
testResolvePathWithTraversal(method, "/file:" + secretPath, location);
|
testResolvePathWithTraversal(method, "/file:" + secretPath);
|
||||||
testResolvePathWithTraversal(method, "url:" + secretPath, location);
|
testResolvePathWithTraversal(method, "url:" + secretPath);
|
||||||
testResolvePathWithTraversal(method, "/url:" + secretPath, location);
|
testResolvePathWithTraversal(method, "/url:" + secretPath);
|
||||||
testResolvePathWithTraversal(method, "////../.." + secretPath, location);
|
testResolvePathWithTraversal(method, "////../.." + secretPath);
|
||||||
testResolvePathWithTraversal(method, "/%2E%2E/testsecret/secret.txt", location);
|
testResolvePathWithTraversal(method, "/%2E%2E/testsecret/secret.txt");
|
||||||
testResolvePathWithTraversal(method, "%2F%2F%2E%2E%2F%2Ftestsecret/secret.txt", location);
|
testResolvePathWithTraversal(method, "%2F%2F%2E%2E%2F%2Ftestsecret/secret.txt");
|
||||||
testResolvePathWithTraversal(method, "url:" + secretPath, location);
|
testResolvePathWithTraversal(method, "url:" + secretPath);
|
||||||
|
|
||||||
// The following tests fail with a MalformedURLException on Windows
|
// The following tests fail with a MalformedURLException on Windows
|
||||||
// testResolvePathWithTraversal(location, "/" + secretPath);
|
// testResolvePathWithTraversal(location, "/" + secretPath);
|
||||||
|
@ -717,7 +717,7 @@ class ResourceWebHandlerTests {
|
||||||
return Arrays.stream(HttpMethod.values());
|
return Arrays.stream(HttpMethod.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testResolvePathWithTraversal(HttpMethod httpMethod, String requestPath, Resource location) {
|
private void testResolvePathWithTraversal(HttpMethod httpMethod, String requestPath) {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.method(httpMethod, ""));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.method(httpMethod, ""));
|
||||||
setPathWithinHandlerMapping(exchange, requestPath);
|
setPathWithinHandlerMapping(exchange, requestPath);
|
||||||
setBestMachingPattern(exchange, "/**");
|
setBestMachingPattern(exchange, "/**");
|
||||||
|
|
|
@ -45,7 +45,7 @@ import static org.springframework.http.MediaType.TEXT_PLAIN;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class HandlerResultHandlerTests {
|
class HandlerResultHandlerTests {
|
||||||
|
|
||||||
private final TestResultHandler resultHandler = new TestResultHandler();
|
private final TestResultHandler resultHandler = new TestResultHandler();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -74,7 +74,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
|
||||||
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
|
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
|
||||||
|
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
assertThat(response.getBody()).isEqualTo("foo".getBytes("UTF-8"));
|
assertThat(response.getBody()).isEqualTo("foo".getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedHttpServerTest
|
@ParameterizedHttpServerTest
|
||||||
|
@ -87,7 +87,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
|
||||||
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
|
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
|
||||||
|
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
assertThat(response.getBody()).isEqualTo("bar".getBytes("UTF-8"));
|
assertThat(response.getBody()).isEqualTo("bar".getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedHttpServerTest
|
@ParameterizedHttpServerTest
|
||||||
|
|
|
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class CompositeRequestConditionTests {
|
class CompositeRequestConditionTests {
|
||||||
|
|
||||||
private ParamsRequestCondition param1;
|
private ParamsRequestCondition param1;
|
||||||
private ParamsRequestCondition param2;
|
private ParamsRequestCondition param2;
|
||||||
|
@ -43,7 +43,7 @@ public class CompositeRequestConditionTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() {
|
||||||
this.param1 = new ParamsRequestCondition("param1");
|
this.param1 = new ParamsRequestCondition("param1");
|
||||||
this.param2 = new ParamsRequestCondition("param2");
|
this.param2 = new ParamsRequestCondition("param2");
|
||||||
this.param3 = this.param1.combine(this.param2);
|
this.param3 = this.param1.combine(this.param2);
|
||||||
|
@ -55,7 +55,7 @@ public class CompositeRequestConditionTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combine() {
|
void combine() {
|
||||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1, this.header1);
|
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1, this.header1);
|
||||||
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param2, this.header2);
|
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param2, this.header2);
|
||||||
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3, this.header3);
|
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3, this.header3);
|
||||||
|
@ -64,7 +64,7 @@ public class CompositeRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineEmpty() {
|
void combineEmpty() {
|
||||||
CompositeRequestCondition empty = new CompositeRequestCondition();
|
CompositeRequestCondition empty = new CompositeRequestCondition();
|
||||||
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class CompositeRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineDifferentLength() {
|
void combineDifferentLength() {
|
||||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
||||||
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
|
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
|
@ -82,7 +82,7 @@ public class CompositeRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void match() {
|
void match() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?param1=paramValue1").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?param1=paramValue1").build();
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
|
@ -96,19 +96,19 @@ public class CompositeRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noMatch() {
|
void noMatch() {
|
||||||
CompositeRequestCondition cond = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition cond = new CompositeRequestCondition(this.param1);
|
||||||
assertThat(cond.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isNull();
|
assertThat(cond.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchEmpty() {
|
void matchEmpty() {
|
||||||
CompositeRequestCondition empty = new CompositeRequestCondition();
|
CompositeRequestCondition empty = new CompositeRequestCondition();
|
||||||
assertThat(empty.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isSameAs(empty);
|
assertThat(empty.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isSameAs(empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compare() {
|
void compare() {
|
||||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
||||||
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3);
|
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3);
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
|
@ -118,7 +118,7 @@ public class CompositeRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareEmpty() {
|
void compareEmpty() {
|
||||||
CompositeRequestCondition empty = new CompositeRequestCondition();
|
CompositeRequestCondition empty = new CompositeRequestCondition();
|
||||||
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
|
@ -129,7 +129,7 @@ public class CompositeRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareDifferentLength() {
|
void compareDifferentLength() {
|
||||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
||||||
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
|
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.fail;
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class ConsumesRequestConditionTests {
|
class ConsumesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void consumesMatch() {
|
void consumesMatch() {
|
||||||
MockServerWebExchange exchange = postExchange("text/plain");
|
MockServerWebExchange exchange = postExchange("text/plain");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void negatedConsumesMatch() {
|
void negatedConsumesMatch() {
|
||||||
MockServerWebExchange exchange = postExchange("text/plain");
|
MockServerWebExchange exchange = postExchange("text/plain");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
|
||||||
|
|
||||||
|
@ -51,13 +51,13 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConsumableMediaTypesNegatedExpression() {
|
void getConsumableMediaTypesNegatedExpression() {
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("!application/xml");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("!application/xml");
|
||||||
assertThat(condition.getConsumableMediaTypes()).isEqualTo(Collections.emptySet());
|
assertThat(condition.getConsumableMediaTypes()).isEqualTo(Collections.emptySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void consumesWildcardMatch() {
|
void consumesWildcardMatch() {
|
||||||
MockServerWebExchange exchange = postExchange("text/plain");
|
MockServerWebExchange exchange = postExchange("text/plain");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/*");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/*");
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void consumesMultipleMatch() {
|
void consumesMultipleMatch() {
|
||||||
MockServerWebExchange exchange = postExchange("text/plain");
|
MockServerWebExchange exchange = postExchange("text/plain");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml");
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void consumesSingleNoMatch() {
|
void consumesSingleNoMatch() {
|
||||||
MockServerWebExchange exchange = postExchange("application/xml");
|
MockServerWebExchange exchange = postExchange("application/xml");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void consumesParseError() {
|
void consumesParseError() {
|
||||||
MockServerWebExchange exchange = postExchange("01");
|
MockServerWebExchange exchange = postExchange("01");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void consumesParseErrorWithNegation() {
|
void consumesParseErrorWithNegation() {
|
||||||
MockServerWebExchange exchange = postExchange("01");
|
MockServerWebExchange exchange = postExchange("01");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToSingle() {
|
void compareToSingle() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
|
|
||||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
||||||
|
@ -153,7 +153,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMultiple() {
|
void compareToMultiple() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
|
|
||||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("*/*", "text/plain");
|
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("*/*", "text/plain");
|
||||||
|
@ -168,7 +168,7 @@ public class ConsumesRequestConditionTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combine() throws Exception {
|
void combine() {
|
||||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
||||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("application/xml");
|
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("application/xml");
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineWithDefault() {
|
void combineWithDefault() {
|
||||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
||||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition();
|
ConsumesRequestCondition condition2 = new ConsumesRequestCondition();
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseConsumesAndHeaders() {
|
void parseConsumesAndHeaders() {
|
||||||
String[] consumes = new String[] {"text/plain"};
|
String[] consumes = new String[] {"text/plain"};
|
||||||
String[] headers = new String[]{"foo=bar", "content-type=application/xml,application/pdf"};
|
String[] headers = new String[]{"foo=bar", "content-type=application/xml,application/pdf"};
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition(consumes, headers);
|
ConsumesRequestCondition condition = new ConsumesRequestCondition(consumes, headers);
|
||||||
|
@ -195,7 +195,7 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingCondition() {
|
void getMatchingCondition() {
|
||||||
MockServerWebExchange exchange = postExchange("text/plain");
|
MockServerWebExchange exchange = postExchange("text/plain");
|
||||||
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml");
|
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml");
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,10 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class HeadersRequestConditionTests {
|
class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerEquals() {
|
void headerEquals() {
|
||||||
assertThat(new HeadersRequestCondition("foo")).isEqualTo(new HeadersRequestCondition("foo"));
|
assertThat(new HeadersRequestCondition("foo")).isEqualTo(new HeadersRequestCondition("foo"));
|
||||||
assertThat(new HeadersRequestCondition("FOO")).isEqualTo(new HeadersRequestCondition("foo"));
|
assertThat(new HeadersRequestCondition("FOO")).isEqualTo(new HeadersRequestCondition("foo"));
|
||||||
assertThat(new HeadersRequestCondition("bar")).isNotEqualTo(new HeadersRequestCondition("foo"));
|
assertThat(new HeadersRequestCondition("bar")).isNotEqualTo(new HeadersRequestCondition("foo"));
|
||||||
|
@ -43,7 +43,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerPresent() {
|
void headerPresent() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", ""));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", ""));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("accept");
|
HeadersRequestCondition condition = new HeadersRequestCondition("accept");
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerPresentNoMatch() {
|
void headerPresentNoMatch() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("bar", ""));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("bar", ""));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerNotPresent() {
|
void headerNotPresent() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
|
HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueMatch() {
|
void headerValueMatch() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueNoMatch() {
|
void headerValueNoMatch() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bazz"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bazz"));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerCaseSensitiveValueMatch() {
|
void headerCaseSensitiveValueMatch() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar");
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueMatchNegated() {
|
void headerValueMatchNegated() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "baz"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "baz"));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueNoMatchNegated() {
|
void headerValueNoMatchNegated() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareTo() {
|
void compareTo() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
||||||
|
|
||||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo", "bar", "baz");
|
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo", "bar", "baz");
|
||||||
|
@ -132,7 +132,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToWithNegatedMatch() {
|
void compareToWithNegatedMatch() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
||||||
|
|
||||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo!=a");
|
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo!=a");
|
||||||
|
@ -142,7 +142,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combine() {
|
void combine() {
|
||||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo=bar");
|
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo=bar");
|
||||||
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo=baz");
|
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo=baz");
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class HeadersRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingCondition() {
|
void getMatchingCondition() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
||||||
|
|
||||||
|
|
|
@ -34,19 +34,19 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class PatternsRequestConditionTests {
|
class PatternsRequestConditionTests {
|
||||||
|
|
||||||
private final PathPatternParser parser = new PathPatternParser();
|
private final PathPatternParser parser = new PathPatternParser();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void prependNonEmptyPatternsOnly() {
|
void prependNonEmptyPatternsOnly() {
|
||||||
PatternsRequestCondition c = createPatternsCondition("");
|
PatternsRequestCondition c = createPatternsCondition("");
|
||||||
assertThat(c.getPatterns().iterator().next().getPatternString())
|
assertThat(c.getPatterns().iterator().next().getPatternString())
|
||||||
.as("Do not prepend empty patterns (SPR-8255)").isEmpty();
|
.as("Do not prepend empty patterns (SPR-8255)").isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineEmptySets() {
|
void combineEmptySets() {
|
||||||
PatternsRequestCondition c1 = new PatternsRequestCondition();
|
PatternsRequestCondition c1 = new PatternsRequestCondition();
|
||||||
PatternsRequestCondition c2 = new PatternsRequestCondition();
|
PatternsRequestCondition c2 = new PatternsRequestCondition();
|
||||||
PatternsRequestCondition c3 = c1.combine(c2);
|
PatternsRequestCondition c3 = c1.combine(c2);
|
||||||
|
@ -56,7 +56,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineOnePatternWithEmptySet() {
|
void combineOnePatternWithEmptySet() {
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/type1", "/type2");
|
PatternsRequestCondition c1 = createPatternsCondition("/type1", "/type2");
|
||||||
PatternsRequestCondition c2 = new PatternsRequestCondition();
|
PatternsRequestCondition c2 = new PatternsRequestCondition();
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineMultiplePatterns() {
|
void combineMultiplePatterns() {
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/t1", "/t2");
|
PatternsRequestCondition c1 = createPatternsCondition("/t1", "/t2");
|
||||||
PatternsRequestCondition c2 = createPatternsCondition("/m1", "/m2");
|
PatternsRequestCondition c2 = createPatternsCondition("/m1", "/m2");
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchDirectPath() {
|
void matchDirectPath() {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
@ -86,7 +86,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchPattern() {
|
void matchPattern() {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/foo/*");
|
PatternsRequestCondition condition = createPatternsCondition("/foo/*");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
@ -95,7 +95,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchSortPatterns() {
|
void matchSortPatterns() {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/*/*", "/foo/bar", "/foo/*");
|
PatternsRequestCondition condition = createPatternsCondition("/*/*", "/foo/bar", "/foo/*");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
@ -137,7 +137,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchPatternContainsExtension() {
|
void matchPatternContainsExtension() {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");
|
PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
@ -157,7 +157,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToConsistentWithEquals() {
|
void compareToConsistentWithEquals() {
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/foo*");
|
PatternsRequestCondition c1 = createPatternsCondition("/foo*");
|
||||||
PatternsRequestCondition c2 = createPatternsCondition("/foo*");
|
PatternsRequestCondition c2 = createPatternsCondition("/foo*");
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equallyMatchingPatternsAreBothPresent() {
|
void equallyMatchingPatternsAreBothPresent() {
|
||||||
PatternsRequestCondition c = createPatternsCondition("/a", "/b");
|
PatternsRequestCondition c = createPatternsCondition("/a", "/b");
|
||||||
assertThat(c.getPatterns()).hasSize(2);
|
assertThat(c.getPatterns()).hasSize(2);
|
||||||
Iterator<PathPattern> itr = c.getPatterns().iterator();
|
Iterator<PathPattern> itr = c.getPatterns().iterator();
|
||||||
|
@ -174,7 +174,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void comparePatternSpecificity() {
|
void comparePatternSpecificity() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
||||||
|
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/fo*");
|
PatternsRequestCondition c1 = createPatternsCondition("/fo*");
|
||||||
|
@ -191,7 +191,7 @@ public class PatternsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareNumberOfMatchingPatterns() {
|
void compareNumberOfMatchingPatterns() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
|
||||||
|
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/foo.*", "/foo.jpeg");
|
PatternsRequestCondition c1 = createPatternsCondition("/foo.*", "/foo.jpeg");
|
||||||
|
|
|
@ -36,10 +36,10 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ProducesRequestConditionTests {
|
class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void match() {
|
void match() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchNegated() {
|
void matchNegated() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
||||||
|
|
||||||
|
@ -55,13 +55,13 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProducibleMediaTypes() {
|
void getProducibleMediaTypes() {
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("!application/xml");
|
ProducesRequestCondition condition = new ProducesRequestCondition("!application/xml");
|
||||||
assertThat(condition.getProducibleMediaTypes()).isEqualTo(Collections.emptySet());
|
assertThat(condition.getProducibleMediaTypes()).isEqualTo(Collections.emptySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchWildcard() {
|
void matchWildcard() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/*");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/*");
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchMultiple() {
|
void matchMultiple() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchSingle() {
|
void matchSingle() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "application/xml"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "application/xml"));
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchParseError() {
|
void matchParseError() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "bogus"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "bogus"));
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchParseErrorWithNegation() {
|
void matchParseErrorWithNegation() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "bogus"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "bogus"));
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareTo() {
|
void compareTo() {
|
||||||
ProducesRequestCondition html = new ProducesRequestCondition("text/html");
|
ProducesRequestCondition html = new ProducesRequestCondition("text/html");
|
||||||
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
|
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
|
||||||
ProducesRequestCondition none = new ProducesRequestCondition();
|
ProducesRequestCondition none = new ProducesRequestCondition();
|
||||||
|
@ -185,7 +185,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToWithSingleExpression() {
|
void compareToWithSingleExpression() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||||
|
@ -199,7 +199,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMultipleExpressions() {
|
void compareToMultipleExpressions() {
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("*/*", "text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("*/*", "text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*", "text/plain;q=0.7");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*", "text/plain;q=0.7");
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMultipleExpressionsAndMultipleAcceptHeaderValues() {
|
void compareToMultipleExpressionsAndMultipleAcceptHeaderValues() {
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/*", "text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/*", "text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/*", "application/xml");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/*", "application/xml");
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ public class ProducesRequestConditionTests {
|
||||||
// SPR-8536
|
// SPR-8536
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMediaTypeAll() {
|
void compareToMediaTypeAll() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
||||||
|
@ -275,7 +275,7 @@ public class ProducesRequestConditionTests {
|
||||||
// SPR-9021
|
// SPR-9021
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMediaTypeAllWithParameter() {
|
void compareToMediaTypeAllWithParameter() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "*/*;q=0.9"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "*/*;q=0.9"));
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
||||||
|
@ -286,7 +286,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToEqualMatch() {
|
void compareToEqualMatch() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/*"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/*"));
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||||
|
@ -300,7 +300,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareEmptyInvalidAccept() {
|
void compareEmptyInvalidAccept() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "foo"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "foo"));
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
||||||
|
@ -312,7 +312,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combine() {
|
void combine() {
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/xml");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/xml");
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineWithDefault() {
|
void combineWithDefault() {
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition();
|
ProducesRequestCondition condition2 = new ProducesRequestCondition();
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void instantiateWithProducesAndHeaderConditions() {
|
void instantiateWithProducesAndHeaderConditions() {
|
||||||
String[] produces = new String[] {"text/plain"};
|
String[] produces = new String[] {"text/plain"};
|
||||||
String[] headers = new String[]{"foo=bar", "accept=application/xml,application/pdf"};
|
String[] headers = new String[]{"foo=bar", "accept=application/xml,application/pdf"};
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition(produces, headers);
|
ProducesRequestCondition condition = new ProducesRequestCondition(produces, headers);
|
||||||
|
@ -339,7 +339,7 @@ public class ProducesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingCondition() {
|
void getMatchingCondition() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
|
||||||
|
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
||||||
|
|
|
@ -30,13 +30,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestConditionHolderTests {
|
class RequestConditionHolderTests {
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combine() {
|
void combine() {
|
||||||
RequestConditionHolder params1 = new RequestConditionHolder(new ParamsRequestCondition("name1"));
|
RequestConditionHolder params1 = new RequestConditionHolder(new ParamsRequestCondition("name1"));
|
||||||
RequestConditionHolder params2 = new RequestConditionHolder(new ParamsRequestCondition("name2"));
|
RequestConditionHolder params2 = new RequestConditionHolder(new ParamsRequestCondition("name2"));
|
||||||
RequestConditionHolder expected = new RequestConditionHolder(new ParamsRequestCondition("name1", "name2"));
|
RequestConditionHolder expected = new RequestConditionHolder(new ParamsRequestCondition("name1", "name2"));
|
||||||
|
@ -45,7 +45,7 @@ public class RequestConditionHolderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineEmpty() {
|
void combineEmpty() {
|
||||||
RequestConditionHolder empty = new RequestConditionHolder(null);
|
RequestConditionHolder empty = new RequestConditionHolder(null);
|
||||||
RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class RequestConditionHolderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineIncompatible() {
|
void combineIncompatible() {
|
||||||
RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
||||||
RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name"));
|
RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name"));
|
||||||
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() ->
|
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() ->
|
||||||
|
@ -63,7 +63,7 @@ public class RequestConditionHolderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void match() {
|
void match() {
|
||||||
RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
|
RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
|
||||||
RequestConditionHolder custom = new RequestConditionHolder(rm);
|
RequestConditionHolder custom = new RequestConditionHolder(rm);
|
||||||
RequestMethodsRequestCondition expected = new RequestMethodsRequestCondition(RequestMethod.GET);
|
RequestMethodsRequestCondition expected = new RequestMethodsRequestCondition(RequestMethod.GET);
|
||||||
|
@ -74,7 +74,7 @@ public class RequestConditionHolderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noMatch() {
|
void noMatch() {
|
||||||
RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.POST);
|
RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.POST);
|
||||||
RequestConditionHolder custom = new RequestConditionHolder(rm);
|
RequestConditionHolder custom = new RequestConditionHolder(rm);
|
||||||
|
|
||||||
|
@ -82,13 +82,13 @@ public class RequestConditionHolderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchEmpty() {
|
void matchEmpty() {
|
||||||
RequestConditionHolder empty = new RequestConditionHolder(null);
|
RequestConditionHolder empty = new RequestConditionHolder(null);
|
||||||
assertThat(empty.getMatchingCondition(this.exchange)).isSameAs(empty);
|
assertThat(empty.getMatchingCondition(this.exchange)).isSameAs(empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compare() {
|
void compare() {
|
||||||
RequestConditionHolder params11 = new RequestConditionHolder(new ParamsRequestCondition("1"));
|
RequestConditionHolder params11 = new RequestConditionHolder(new ParamsRequestCondition("1"));
|
||||||
RequestConditionHolder params12 = new RequestConditionHolder(new ParamsRequestCondition("1", "2"));
|
RequestConditionHolder params12 = new RequestConditionHolder(new ParamsRequestCondition("1", "2"));
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class RequestConditionHolderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareEmpty() {
|
void compareEmpty() {
|
||||||
RequestConditionHolder empty = new RequestConditionHolder(null);
|
RequestConditionHolder empty = new RequestConditionHolder(null);
|
||||||
RequestConditionHolder empty2 = new RequestConditionHolder(null);
|
RequestConditionHolder empty2 = new RequestConditionHolder(null);
|
||||||
RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
||||||
|
@ -108,7 +108,7 @@ public class RequestConditionHolderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareIncompatible() {
|
void compareIncompatible() {
|
||||||
RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name"));
|
||||||
RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name"));
|
RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name"));
|
||||||
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() ->
|
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() ->
|
||||||
|
|
|
@ -46,12 +46,12 @@ import static org.springframework.web.reactive.result.method.RequestMappingInfo.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestMappingInfoTests {
|
class RequestMappingInfoTests {
|
||||||
|
|
||||||
// TODO: CORS pre-flight (see @Disabled)
|
// TODO: CORS pre-flight (see @Disabled)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createEmpty() {
|
void createEmpty() {
|
||||||
RequestMappingInfo info = paths().build();
|
RequestMappingInfo info = paths().build();
|
||||||
|
|
||||||
PathPattern emptyPattern = (new PathPatternParser()).parse("");
|
PathPattern emptyPattern = (new PathPatternParser()).parse("");
|
||||||
|
@ -83,14 +83,14 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void throwWhenInvalidPattern() {
|
void throwWhenInvalidPattern() {
|
||||||
assertThatExceptionOfType(PatternParseException.class).isThrownBy(() ->
|
assertThatExceptionOfType(PatternParseException.class).isThrownBy(() ->
|
||||||
paths("/{foo").build())
|
paths("/{foo").build())
|
||||||
.withMessageContaining("Expected close capture character after variable name }");
|
.withMessageContaining("Expected close capture character after variable name }");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void prependPatternWithSlash() {
|
void prependPatternWithSlash() {
|
||||||
RequestMappingInfo actual = paths("foo").build();
|
RequestMappingInfo actual = paths("foo").build();
|
||||||
List<PathPattern> patterns = new ArrayList<>(actual.getPatternsCondition().getPatterns());
|
List<PathPattern> patterns = new ArrayList<>(actual.getPatternsCondition().getPatterns());
|
||||||
assertThat(patterns).hasSize(1);
|
assertThat(patterns).hasSize(1);
|
||||||
|
@ -98,7 +98,7 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchPatternsCondition() {
|
void matchPatternsCondition() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo*", "/bar").build();
|
RequestMappingInfo info = paths("/foo*", "/bar").build();
|
||||||
|
@ -113,7 +113,7 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchParamsCondition() {
|
void matchParamsCondition() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo?foo=bar"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo?foo=bar"));
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
||||||
|
@ -128,7 +128,7 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchHeadersCondition() {
|
void matchHeadersCondition() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/foo").header("foo", "bar").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/foo").header("foo", "bar").build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchConsumesCondition() {
|
void matchConsumesCondition() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.post("/foo").contentType(MediaType.TEXT_PLAIN).build();
|
MockServerHttpRequest request = MockServerHttpRequest.post("/foo").contentType(MediaType.TEXT_PLAIN).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchProducesCondition() {
|
void matchProducesCondition() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/foo").accept(MediaType.TEXT_PLAIN).build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/foo").accept(MediaType.TEXT_PLAIN).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchCustomCondition() {
|
void matchCustomCondition() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo?foo=bar"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo?foo=bar"));
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
||||||
|
@ -193,7 +193,7 @@ public class RequestMappingInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareTwoHttpMethodsOneParam() {
|
void compareTwoHttpMethodsOneParam() {
|
||||||
RequestMappingInfo none = paths().build();
|
RequestMappingInfo none = paths().build();
|
||||||
RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
|
RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
|
||||||
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
|
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
|
||||||
|
@ -205,13 +205,11 @@ public class RequestMappingInfoTests {
|
||||||
Collections.shuffle(list);
|
Collections.shuffle(list);
|
||||||
list.sort(comparator);
|
list.sort(comparator);
|
||||||
|
|
||||||
assertThat(list).element(0).isEqualTo(oneMethodOneParam);
|
assertThat(list).containsExactly(oneMethodOneParam, oneMethod, none);
|
||||||
assertThat(list).element(1).isEqualTo(oneMethod);
|
|
||||||
assertThat(list).element(2).isEqualTo(none);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equals() {
|
void equals() {
|
||||||
RequestMappingInfo info1 = paths("/foo").methods(RequestMethod.GET)
|
RequestMappingInfo info1 = paths("/foo").methods(RequestMethod.GET)
|
||||||
.params("foo=bar").headers("foo=bar")
|
.params("foo=bar").headers("foo=bar")
|
||||||
.consumes("text/plain").produces("text/plain")
|
.consumes("text/plain").produces("text/plain")
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.web.reactive.result.condition;
|
package org.springframework.web.reactive.result.condition;
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -41,24 +40,24 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestMethodsRequestConditionTests {
|
class RequestMethodsRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingCondition() throws Exception {
|
void getMatchingCondition() {
|
||||||
testMatch(new RequestMethodsRequestCondition(GET), GET);
|
testMatch(new RequestMethodsRequestCondition(GET), GET);
|
||||||
testMatch(new RequestMethodsRequestCondition(GET, POST), GET);
|
testMatch(new RequestMethodsRequestCondition(GET, POST), GET);
|
||||||
testNoMatch(new RequestMethodsRequestCondition(GET), POST);
|
testNoMatch(new RequestMethodsRequestCondition(GET), POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingConditionWithHttpHead() throws Exception {
|
void getMatchingConditionWithHttpHead() {
|
||||||
testMatch(new RequestMethodsRequestCondition(HEAD), HEAD);
|
testMatch(new RequestMethodsRequestCondition(HEAD), HEAD);
|
||||||
testMatch(new RequestMethodsRequestCondition(GET), GET);
|
testMatch(new RequestMethodsRequestCondition(GET), GET);
|
||||||
testNoMatch(new RequestMethodsRequestCondition(POST), HEAD);
|
testNoMatch(new RequestMethodsRequestCondition(POST), HEAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingConditionWithEmptyConditions() throws Exception {
|
void getMatchingConditionWithEmptyConditions() {
|
||||||
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
|
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
|
||||||
for (RequestMethod method : RequestMethod.values()) {
|
for (RequestMethod method : RequestMethod.values()) {
|
||||||
if (method != OPTIONS) {
|
if (method != OPTIONS) {
|
||||||
|
@ -70,14 +69,14 @@ public class RequestMethodsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingConditionWithCustomMethod() throws Exception {
|
void getMatchingConditionWithCustomMethod() {
|
||||||
ServerWebExchange exchange = getExchange("PROPFIND");
|
ServerWebExchange exchange = getExchange("PROPFIND");
|
||||||
assertThat(new RequestMethodsRequestCondition().getMatchingCondition(exchange)).isNotNull();
|
assertThat(new RequestMethodsRequestCondition().getMatchingCondition(exchange)).isNotNull();
|
||||||
assertThat(new RequestMethodsRequestCondition(GET, POST).getMatchingCondition(exchange)).isNull();
|
assertThat(new RequestMethodsRequestCondition(GET, POST).getMatchingCondition(exchange)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingConditionWithCorsPreFlight() {
|
void getMatchingConditionWithCorsPreFlight() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.valueOf("OPTIONS"), "/")
|
MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.valueOf("OPTIONS"), "/")
|
||||||
.header("Origin", "https://example.com")
|
.header("Origin", "https://example.com")
|
||||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PUT")
|
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PUT")
|
||||||
|
@ -90,7 +89,7 @@ public class RequestMethodsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareTo() throws Exception {
|
void compareTo() {
|
||||||
RequestMethodsRequestCondition c1 = new RequestMethodsRequestCondition(GET, HEAD);
|
RequestMethodsRequestCondition c1 = new RequestMethodsRequestCondition(GET, HEAD);
|
||||||
RequestMethodsRequestCondition c2 = new RequestMethodsRequestCondition(POST);
|
RequestMethodsRequestCondition c2 = new RequestMethodsRequestCondition(POST);
|
||||||
RequestMethodsRequestCondition c3 = new RequestMethodsRequestCondition();
|
RequestMethodsRequestCondition c3 = new RequestMethodsRequestCondition();
|
||||||
|
@ -111,7 +110,7 @@ public class RequestMethodsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combine() {
|
void combine() {
|
||||||
RequestMethodsRequestCondition condition1 = new RequestMethodsRequestCondition(GET);
|
RequestMethodsRequestCondition condition1 = new RequestMethodsRequestCondition(GET);
|
||||||
RequestMethodsRequestCondition condition2 = new RequestMethodsRequestCondition(POST);
|
RequestMethodsRequestCondition condition2 = new RequestMethodsRequestCondition(POST);
|
||||||
|
|
||||||
|
@ -120,19 +119,19 @@ public class RequestMethodsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
|
private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
|
||||||
ServerWebExchange exchange = getExchange(method.name());
|
ServerWebExchange exchange = getExchange(method.name());
|
||||||
RequestMethodsRequestCondition actual = condition.getMatchingCondition(exchange);
|
RequestMethodsRequestCondition actual = condition.getMatchingCondition(exchange);
|
||||||
assertThat(actual).isNotNull();
|
assertThat(actual).isNotNull();
|
||||||
assertThat(actual.getContent()).isEqualTo(Collections.singleton(method));
|
assertThat(actual.getContent()).isEqualTo(Collections.singleton(method));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
|
private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
|
||||||
ServerWebExchange exchange = getExchange(method.name());
|
ServerWebExchange exchange = getExchange(method.name());
|
||||||
assertThat(condition.getMatchingCondition(exchange)).isNull();
|
assertThat(condition.getMatchingCondition(exchange)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerWebExchange getExchange(String method) throws URISyntaxException {
|
private ServerWebExchange getExchange(String method) {
|
||||||
return MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.valueOf(method), "/"));
|
return MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.valueOf(method), "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class HandlerMethodMappingTests {
|
class HandlerMethodMappingTests {
|
||||||
|
|
||||||
private MyHandlerMethodMapping mapping;
|
private MyHandlerMethodMapping mapping;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public class HandlerMethodMappingTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
this.mapping = new MyHandlerMethodMapping();
|
this.mapping = new MyHandlerMethodMapping();
|
||||||
this.handler = new MyHandler();
|
this.handler = new MyHandler();
|
||||||
this.method1 = handler.getClass().getMethod("handlerMethod1");
|
this.method1 = handler.getClass().getMethod("handlerMethod1");
|
||||||
|
@ -75,14 +75,14 @@ public class HandlerMethodMappingTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerDuplicates() {
|
void registerDuplicates() {
|
||||||
this.mapping.registerMapping("foo", this.handler, this.method1);
|
this.mapping.registerMapping("foo", this.handler, this.method1);
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
this.mapping.registerMapping("foo", this.handler, this.method2));
|
this.mapping.registerMapping("foo", this.handler, this.method2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void directMatch() {
|
void directMatch() {
|
||||||
this.mapping.registerMapping("/foo", this.handler, this.method1);
|
this.mapping.registerMapping("/foo", this.handler, this.method1);
|
||||||
this.mapping.registerMapping("/fo*", this.handler, this.method2);
|
this.mapping.registerMapping("/fo*", this.handler, this.method2);
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
||||||
|
@ -93,7 +93,7 @@ public class HandlerMethodMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void patternMatch() {
|
void patternMatch() {
|
||||||
this.mapping.registerMapping("/fo*", this.handler, this.method1);
|
this.mapping.registerMapping("/fo*", this.handler, this.method1);
|
||||||
this.mapping.registerMapping("/f*", this.handler, this.method2);
|
this.mapping.registerMapping("/f*", this.handler, this.method2);
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public class HandlerMethodMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ambiguousMatch() {
|
void ambiguousMatch() {
|
||||||
this.mapping.registerMapping("/f?o", this.handler, this.method1);
|
this.mapping.registerMapping("/f?o", this.handler, this.method1);
|
||||||
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
||||||
|
@ -113,7 +113,7 @@ public class HandlerMethodMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-26490
|
@Test // gh-26490
|
||||||
public void ambiguousMatchOnPreFlightRequestWithoutCorsConfig() throws Exception {
|
public void ambiguousMatchOnPreFlightRequestWithoutCorsConfig() {
|
||||||
this.mapping.registerMapping("/f?o", this.handler, this.method1);
|
this.mapping.registerMapping("/f?o", this.handler, this.method1);
|
||||||
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public class HandlerMethodMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerMapping() {
|
void registerMapping() {
|
||||||
String key1 = "/foo";
|
String key1 = "/foo";
|
||||||
String key2 = "/foo*";
|
String key2 = "/foo*";
|
||||||
this.mapping.registerMapping(key1, this.handler, this.method1);
|
this.mapping.registerMapping(key1, this.handler, this.method1);
|
||||||
|
@ -156,7 +156,7 @@ public class HandlerMethodMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerMappingWithSameMethodAndTwoHandlerInstances() {
|
void registerMappingWithSameMethodAndTwoHandlerInstances() {
|
||||||
String key1 = "foo";
|
String key1 = "foo";
|
||||||
String key2 = "bar";
|
String key2 = "bar";
|
||||||
MyHandler handler1 = new MyHandler();
|
MyHandler handler1 = new MyHandler();
|
||||||
|
@ -168,7 +168,7 @@ public class HandlerMethodMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unregisterMapping() {
|
void unregisterMapping() {
|
||||||
String key = "foo";
|
String key = "foo";
|
||||||
this.mapping.registerMapping(key, this.handler, this.method1);
|
this.mapping.registerMapping(key, this.handler, this.method1);
|
||||||
Mono<Object> result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key)));
|
Mono<Object> result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key)));
|
||||||
|
|
|
@ -56,7 +56,7 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class InvocableHandlerMethodTests {
|
class InvocableHandlerMethodTests {
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class InvocableHandlerMethodTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArg() {
|
void resolveArg() {
|
||||||
this.resolvers.add(stubResolver("value1"));
|
this.resolvers.add(stubResolver("value1"));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
|
@ -76,7 +76,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNoArgValue() {
|
void resolveNoArgValue() {
|
||||||
this.resolvers.add(stubResolver(Mono.empty()));
|
this.resolvers.add(stubResolver(Mono.empty()));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
|
@ -85,14 +85,14 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNoArgs() {
|
void resolveNoArgs() {
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::noArgs).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::noArgs).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
assertHandlerResultValue(mono, "success");
|
assertHandlerResultValue(mono, "success");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cannotResolveArg() {
|
void cannotResolveArg() {
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
assertThatIllegalStateException().isThrownBy(
|
assertThatIllegalStateException().isThrownBy(
|
||||||
|
@ -101,7 +101,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveProvidedArg() {
|
void resolveProvidedArg() {
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method, "value1");
|
Mono<HandlerResult> mono = invoke(new TestController(), method, "value1");
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveProvidedArgFirst() {
|
void resolveProvidedArgFirst() {
|
||||||
this.resolvers.add(stubResolver("value1"));
|
this.resolvers.add(stubResolver("value1"));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method, "value2");
|
Mono<HandlerResult> mono = invoke(new TestController(), method, "value2");
|
||||||
|
@ -118,7 +118,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exceptionInResolvingArg() {
|
void exceptionInResolvingArg() {
|
||||||
this.resolvers.add(stubResolver(Mono.error(new UnsupportedMediaTypeStatusException("boo"))));
|
this.resolvers.add(stubResolver(Mono.error(new UnsupportedMediaTypeStatusException("boo"))));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
|
@ -129,7 +129,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void illegalArgumentException() {
|
void illegalArgumentException() {
|
||||||
this.resolvers.add(stubResolver(1));
|
this.resolvers.add(stubResolver(1));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
|
@ -143,7 +143,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invocationTargetException() {
|
void invocationTargetException() {
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::exceptionMethod).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::exceptionMethod).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseStatusAnnotation() {
|
void responseStatusAnnotation() {
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::created).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::created).method();
|
||||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voidMethodWithResponseArg() {
|
void voidMethodWithResponseArg() {
|
||||||
ServerHttpResponse response = this.exchange.getResponse();
|
ServerHttpResponse response = this.exchange.getResponse();
|
||||||
this.resolvers.add(stubResolver(response));
|
this.resolvers.add(stubResolver(response));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.response(response)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.response(response)).method();
|
||||||
|
@ -173,7 +173,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voidMonoMethodWithResponseArg() {
|
void voidMonoMethodWithResponseArg() {
|
||||||
ServerHttpResponse response = this.exchange.getResponse();
|
ServerHttpResponse response = this.exchange.getResponse();
|
||||||
this.resolvers.add(stubResolver(response));
|
this.resolvers.add(stubResolver(response));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.responseMonoVoid(response)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.responseMonoVoid(response)).method();
|
||||||
|
@ -184,7 +184,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voidMethodWithExchangeArg() {
|
void voidMethodWithExchangeArg() {
|
||||||
this.resolvers.add(stubResolver(this.exchange));
|
this.resolvers.add(stubResolver(this.exchange));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.exchange(exchange)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.exchange(exchange)).method();
|
||||||
HandlerResult result = invokeForResult(new TestController(), method);
|
HandlerResult result = invokeForResult(new TestController(), method);
|
||||||
|
@ -194,7 +194,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voidMonoMethodWithExchangeArg() {
|
void voidMonoMethodWithExchangeArg() {
|
||||||
this.resolvers.add(stubResolver(this.exchange));
|
this.resolvers.add(stubResolver(this.exchange));
|
||||||
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.exchangeMonoVoid(exchange)).method();
|
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.exchangeMonoVoid(exchange)).method();
|
||||||
HandlerResult result = invokeForResult(new TestController(), method);
|
HandlerResult result = invokeForResult(new TestController(), method);
|
||||||
|
@ -204,7 +204,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModified() {
|
void checkNotModified() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").ifModifiedSince(10 * 1000 * 1000).build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").ifModifiedSince(10 * 1000 * 1000).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.resolvers.add(stubResolver(exchange));
|
this.resolvers.add(stubResolver(exchange));
|
||||||
|
@ -226,11 +226,11 @@ public class InvocableHandlerMethodTests {
|
||||||
return invocable.invoke(this.exchange, new BindingContext(), providedArgs);
|
return invocable.invoke(this.exchange, new BindingContext(), providedArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> HandlerMethodArgumentResolver stubResolver(Object stubValue) {
|
private HandlerMethodArgumentResolver stubResolver(Object stubValue) {
|
||||||
return stubResolver(Mono.just(stubValue));
|
return stubResolver(Mono.just(stubValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> HandlerMethodArgumentResolver stubResolver(Mono<Object> stubValue) {
|
private HandlerMethodArgumentResolver stubResolver(Mono<Object> stubValue) {
|
||||||
HandlerMethodArgumentResolver resolver = mock();
|
HandlerMethodArgumentResolver resolver = mock();
|
||||||
given(resolver.supportsParameter(any())).willReturn(true);
|
given(resolver.supportsParameter(any())).willReturn(true);
|
||||||
given(resolver.resolveArgument(any(), any(), any())).willReturn(stubValue);
|
given(resolver.resolveArgument(any(), any(), any())).willReturn(stubValue);
|
||||||
|
|
|
@ -82,7 +82,7 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class RequestMappingInfoHandlerMappingTests {
|
class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
private static final HandlerMethod handlerMethod = new HandlerMethod(new TestController(),
|
private static final HandlerMethod handlerMethod = new HandlerMethod(new TestController(),
|
||||||
ClassUtils.getMethod(TestController.class, "dummy"));
|
ClassUtils.getMethod(TestController.class, "dummy"));
|
||||||
|
@ -91,14 +91,14 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
this.handlerMapping = new TestRequestMappingInfoHandlerMapping();
|
this.handlerMapping = new TestRequestMappingInfoHandlerMapping();
|
||||||
this.handlerMapping.registerHandler(new TestController());
|
this.handlerMapping.registerHandler(new TestController());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerDirectMatch() {
|
void getHandlerDirectMatch() {
|
||||||
Method expected = on(TestController.class).annot(getMapping("/foo").params()).resolveMethod();
|
Method expected = on(TestController.class).annot(getMapping("/foo").params()).resolveMethod();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -107,7 +107,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerGlobMatch() {
|
void getHandlerGlobMatch() {
|
||||||
Method expected = on(TestController.class).annot(requestMapping("/ba*").method(GET, HEAD)).resolveMethod();
|
Method expected = on(TestController.class).annot(requestMapping("/ba*").method(GET, HEAD)).resolveMethod();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/bar"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/bar"));
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -116,7 +116,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerEmptyPathMatch() {
|
void getHandlerEmptyPathMatch() {
|
||||||
Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
|
Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
ServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -124,7 +124,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerBestMatch() {
|
void getHandlerBestMatch() {
|
||||||
Method expected = on(TestController.class).annot(getMapping("/foo").params("p")).resolveMethod();
|
Method expected = on(TestController.class).annot(getMapping("/foo").params("p")).resolveMethod();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo?p=anything"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo?p=anything"));
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
@ -133,7 +133,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerRequestMethodNotAllowed() {
|
void getHandlerRequestMethodNotAllowed() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(post("/bar"));
|
ServerWebExchange exchange = MockServerWebExchange.from(post("/bar"));
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerTestInvalidContentType() {
|
void getHandlerTestInvalidContentType() {
|
||||||
MockServerHttpRequest request = put("/person/1").header("content-type", "bogus").build();
|
MockServerHttpRequest request = put("/person/1").header("content-type", "bogus").build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
|
@ -185,7 +185,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerHttpOptions() {
|
void getHandlerHttpOptions() {
|
||||||
List<HttpMethod> allMethodExceptTrace = new ArrayList<>(Arrays.asList(HttpMethod.values()));
|
List<HttpMethod> allMethodExceptTrace = new ArrayList<>(Arrays.asList(HttpMethod.values()));
|
||||||
allMethodExceptTrace.remove(HttpMethod.TRACE);
|
allMethodExceptTrace.remove(HttpMethod.TRACE);
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerProducibleMediaTypesAttribute() {
|
void getHandlerProducibleMediaTypesAttribute() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_XML));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_XML));
|
||||||
this.handlerMapping.getHandler(exchange).block();
|
this.handlerMapping.getHandler(exchange).block();
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleMatchBestMatchingPatternAttribute() {
|
void handleMatchBestMatchingPatternAttribute() {
|
||||||
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
|
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));
|
||||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||||
|
@ -260,7 +260,6 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public void handleMatchBestMatchingPatternAttributeInObservationContext() {
|
public void handleMatchBestMatchingPatternAttributeInObservationContext() {
|
||||||
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
|
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));
|
||||||
|
@ -280,7 +279,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleMatchMatrixVariables() {
|
void handleMatchMatrixVariables() {
|
||||||
MultiValueMap<String, String> matrixVariables;
|
MultiValueMap<String, String> matrixVariables;
|
||||||
Map<String, String> uriVariables;
|
Map<String, String> uriVariables;
|
||||||
|
|
||||||
|
@ -313,7 +312,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleMatchMatrixVariablesDecoding() {
|
void handleMatchMatrixVariablesDecoding() {
|
||||||
MockServerHttpRequest request = method(HttpMethod.GET, URI.create("/cars;mvar=a%2Fb")).build();
|
MockServerHttpRequest request = method(HttpMethod.GET, URI.create("/cars;mvar=a%2Fb")).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
handleMatch(exchange, "/{cars}");
|
handleMatch(exchange, "/{cars}");
|
||||||
|
@ -327,7 +326,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePatchUnsupportedMediaType() {
|
void handlePatchUnsupportedMediaType() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.patch("/qux")
|
MockServerHttpRequest request = MockServerHttpRequest.patch("/qux")
|
||||||
.header("content-type", "application/xml")
|
.header("content-type", "application/xml")
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -55,7 +55,6 @@ class ContextPathIntegrationTests {
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("resource")
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
String actual;
|
String actual;
|
||||||
|
|
||||||
|
@ -88,7 +87,6 @@ class ContextPathIntegrationTests {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String url = "http://localhost:" + server.getPort() + "/app/api/test";
|
String url = "http://localhost:" + server.getPort() + "/app/api/test";
|
||||||
@SuppressWarnings("resource")
|
|
||||||
String actual = new RestTemplate().getForObject(url, String.class);
|
String actual = new RestTemplate().getForObject(url, String.class);
|
||||||
assertThat(actual).isEqualTo("Tested in /app/api");
|
assertThat(actual).isEqualTo("Tested in /app/api");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -53,19 +53,19 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ControllerAdviceTests {
|
class ControllerAdviceTests {
|
||||||
|
|
||||||
private final MockServerWebExchange exchange =
|
private final MockServerWebExchange exchange =
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveExceptionGlobalHandler() throws Exception {
|
void resolveExceptionGlobalHandler() throws Exception {
|
||||||
testException(new IllegalAccessException(), "SecondControllerAdvice: IllegalAccessException");
|
testException(new IllegalAccessException(), "SecondControllerAdvice: IllegalAccessException");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveExceptionGlobalHandlerOrdered() throws Exception {
|
void resolveExceptionGlobalHandlerOrdered() throws Exception {
|
||||||
testException(new IllegalStateException(), "OneControllerAdvice: IllegalStateException");
|
testException(new IllegalStateException(), "OneControllerAdvice: IllegalStateException");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,13 +75,13 @@ public class ControllerAdviceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveExceptionWithAssertionError() throws Exception {
|
void resolveExceptionWithAssertionError() throws Exception {
|
||||||
AssertionError error = new AssertionError("argh");
|
AssertionError error = new AssertionError("argh");
|
||||||
testException(error, error.toString());
|
testException(error, error.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveExceptionWithAssertionErrorAsRootCause() throws Exception {
|
void resolveExceptionWithAssertionErrorAsRootCause() throws Exception {
|
||||||
AssertionError rootCause = new AssertionError("argh");
|
AssertionError rootCause = new AssertionError("argh");
|
||||||
FatalBeanException cause = new FatalBeanException("wrapped", rootCause);
|
FatalBeanException cause = new FatalBeanException("wrapped", rootCause);
|
||||||
Exception exception = new Exception(cause);
|
Exception exception = new Exception(cause);
|
||||||
|
@ -100,7 +100,7 @@ public class ControllerAdviceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttributeAdvice() throws Exception {
|
void modelAttributeAdvice() throws Exception {
|
||||||
ApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
|
ApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
|
||||||
RequestMappingHandlerAdapter adapter = createAdapter(context);
|
RequestMappingHandlerAdapter adapter = createAdapter(context);
|
||||||
TestController controller = context.getBean(TestController.class);
|
TestController controller = context.getBean(TestController.class);
|
||||||
|
@ -113,7 +113,7 @@ public class ControllerAdviceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void initBinderAdvice() throws Exception {
|
void initBinderAdvice() throws Exception {
|
||||||
ApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
|
ApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
|
||||||
RequestMappingHandlerAdapter adapter = createAdapter(context);
|
RequestMappingHandlerAdapter adapter = createAdapter(context);
|
||||||
TestController controller = context.getBean(TestController.class);
|
TestController controller = context.getBean(TestController.class);
|
||||||
|
|
|
@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ControllerMethodResolverTests {
|
class ControllerMethodResolverTests {
|
||||||
|
|
||||||
private ControllerMethodResolver methodResolver;
|
private ControllerMethodResolver methodResolver;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class ControllerMethodResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
|
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
|
||||||
resolvers.addCustomResolver(new CustomArgumentResolver());
|
resolvers.addCustomResolver(new CustomArgumentResolver());
|
||||||
resolvers.addCustomResolver(new CustomSyncArgumentResolver());
|
resolvers.addCustomResolver(new CustomSyncArgumentResolver());
|
||||||
|
@ -85,7 +85,7 @@ public class ControllerMethodResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestMappingArgumentResolvers() {
|
void requestMappingArgumentResolvers() {
|
||||||
InvocableHandlerMethod invocable = this.methodResolver.getRequestMappingMethod(this.handlerMethod);
|
InvocableHandlerMethod invocable = this.methodResolver.getRequestMappingMethod(this.handlerMethod);
|
||||||
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
|
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public class ControllerMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttributeArgumentResolvers() {
|
void modelAttributeArgumentResolvers() {
|
||||||
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod);
|
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod);
|
||||||
|
|
||||||
assertThat(methods).as("Expected one each from Controller + ControllerAdvice").hasSize(2);
|
assertThat(methods).as("Expected one each from Controller + ControllerAdvice").hasSize(2);
|
||||||
|
@ -160,7 +160,7 @@ public class ControllerMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void initBinderArgumentResolvers() {
|
void initBinderArgumentResolvers() {
|
||||||
List<SyncInvocableHandlerMethod> methods =
|
List<SyncInvocableHandlerMethod> methods =
|
||||||
this.methodResolver.getInitBinderMethods(this.handlerMethod);
|
this.methodResolver.getInitBinderMethods(this.handlerMethod);
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ public class ControllerMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exceptionHandlerArgumentResolvers() {
|
void exceptionHandlerArgumentResolvers() {
|
||||||
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
|
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
|
||||||
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod);
|
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod);
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ public class ControllerMethodResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exceptionHandlerFromControllerAdvice() {
|
void exceptionHandlerFromControllerAdvice() {
|
||||||
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
|
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
|
||||||
new IllegalStateException("reason"), this.handlerMethod);
|
new IllegalStateException("reason"), this.handlerMethod);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class CookieValueMethodArgumentResolverTests {
|
class CookieValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
private CookieValueMethodArgumentResolver resolver;
|
private CookieValueMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -56,8 +56,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@SuppressWarnings("resource")
|
void setup() throws Exception {
|
||||||
public void setup() throws Exception {
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
|
||||||
|
@ -74,13 +73,13 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.cookieParameter)).isTrue();
|
assertThat(this.resolver.supportsParameter(this.cookieParameter)).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.cookieStringParameter)).isTrue();
|
assertThat(this.resolver.supportsParameter(this.cookieStringParameter)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotSupportParameter() {
|
void doesNotSupportParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.stringParameter)).isFalse();
|
assertThat(this.resolver.supportsParameter(this.stringParameter)).isFalse();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
this.resolver.supportsParameter(this.cookieMonoParameter))
|
this.resolver.supportsParameter(this.cookieMonoParameter))
|
||||||
|
@ -88,7 +87,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveCookieArgument() {
|
void resolveCookieArgument() {
|
||||||
HttpCookie expected = new HttpCookie("name", "foo");
|
HttpCookie expected = new HttpCookie("name", "foo");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(expected));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(expected));
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveCookieStringArgument() {
|
void resolveCookieStringArgument() {
|
||||||
HttpCookie cookie = new HttpCookie("name", "foo");
|
HttpCookie cookie = new HttpCookie("name", "foo");
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(cookie));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(cookie));
|
||||||
|
|
||||||
|
@ -110,7 +109,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveCookieDefaultValue() {
|
void resolveCookieDefaultValue() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
Object result = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange).block();
|
Object result = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange).block();
|
||||||
|
|
||||||
|
@ -120,7 +119,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notFound() {
|
void notFound() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
Mono<Object> mono = resolver.resolveArgument(this.cookieParameter, this.bindingContext, exchange);
|
Mono<Object> mono = resolver.resolveArgument(this.cookieParameter, this.bindingContext, exchange);
|
||||||
StepVerifier.create(mono)
|
StepVerifier.create(mono)
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ExpressionValueMethodArgumentResolverTests {
|
class ExpressionValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
private ExpressionValueMethodArgumentResolver resolver;
|
private ExpressionValueMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -51,8 +51,7 @@ public class ExpressionValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@SuppressWarnings("resource")
|
void setup() throws Exception {
|
||||||
public void setup() throws Exception {
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.refresh();
|
context.refresh();
|
||||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
|
@ -66,12 +65,12 @@ public class ExpressionValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.paramSystemProperty)).isTrue();
|
assertThat(this.resolver.supportsParameter(this.paramSystemProperty)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotSupport() {
|
void doesNotSupport() {
|
||||||
assertThat(this.resolver.supportsParameter(this.paramNotSupported)).isFalse();
|
assertThat(this.resolver.supportsParameter(this.paramNotSupported)).isFalse();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
this.resolver.supportsParameter(this.paramAlsoNotSupported))
|
this.resolver.supportsParameter(this.paramAlsoNotSupported))
|
||||||
|
@ -79,7 +78,7 @@ public class ExpressionValueMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveSystemProperty() {
|
void resolveSystemProperty() {
|
||||||
System.setProperty("systemProperty", "22");
|
System.setProperty("systemProperty", "22");
|
||||||
try {
|
try {
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
|
|
|
@ -60,7 +60,7 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class HttpEntityMethodArgumentResolverTests {
|
class HttpEntityMethodArgumentResolverTests {
|
||||||
|
|
||||||
private final HttpEntityMethodArgumentResolver resolver = createResolver();
|
private final HttpEntityMethodArgumentResolver resolver = createResolver();
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supports() throws Exception {
|
void supports() {
|
||||||
testSupports(this.testMethod.arg(httpEntityType(String.class)));
|
testSupports(this.testMethod.arg(httpEntityType(String.class)));
|
||||||
testSupports(this.testMethod.arg(httpEntityType(Mono.class, String.class)));
|
testSupports(this.testMethod.arg(httpEntityType(Mono.class, String.class)));
|
||||||
testSupports(this.testMethod.arg(httpEntityType(Single.class, String.class)));
|
testSupports(this.testMethod.arg(httpEntityType(Single.class, String.class)));
|
||||||
|
@ -92,7 +92,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotSupport() {
|
void doesNotSupport() {
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, String.class))).isFalse();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, String.class))).isFalse();
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
|
@ -101,7 +101,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithString() {
|
void emptyBodyWithString() {
|
||||||
ResolvableType type = httpEntityType(String.class);
|
ResolvableType type = httpEntityType(String.class);
|
||||||
HttpEntity<Object> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<Object> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithMono() {
|
void emptyBodyWithMono() {
|
||||||
ResolvableType type = httpEntityType(Mono.class, String.class);
|
ResolvableType type = httpEntityType(Mono.class, String.class);
|
||||||
HttpEntity<Mono<String>> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<Mono<String>> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithFlux() {
|
void emptyBodyWithFlux() {
|
||||||
ResolvableType type = httpEntityType(Flux.class, String.class);
|
ResolvableType type = httpEntityType(Flux.class, String.class);
|
||||||
HttpEntity<Flux<String>> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<Flux<String>> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithSingle() {
|
void emptyBodyWithSingle() {
|
||||||
ResolvableType type = httpEntityType(Single.class, String.class);
|
ResolvableType type = httpEntityType(Single.class, String.class);
|
||||||
HttpEntity<Single<String>> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<Single<String>> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithMaybe() {
|
void emptyBodyWithMaybe() {
|
||||||
ResolvableType type = httpEntityType(Maybe.class, String.class);
|
ResolvableType type = httpEntityType(Maybe.class, String.class);
|
||||||
HttpEntity<Maybe<String>> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<Maybe<String>> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithObservable() {
|
void emptyBodyWithObservable() {
|
||||||
ResolvableType type = httpEntityType(Observable.class, String.class);
|
ResolvableType type = httpEntityType(Observable.class, String.class);
|
||||||
HttpEntity<Observable<String>> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<Observable<String>> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithFlowable() {
|
void emptyBodyWithFlowable() {
|
||||||
ResolvableType type = httpEntityType(Flowable.class, String.class);
|
ResolvableType type = httpEntityType(Flowable.class, String.class);
|
||||||
HttpEntity<Flowable<String>> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<Flowable<String>> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithCompletableFuture() {
|
void emptyBodyWithCompletableFuture() {
|
||||||
ResolvableType type = httpEntityType(CompletableFuture.class, String.class);
|
ResolvableType type = httpEntityType(CompletableFuture.class, String.class);
|
||||||
HttpEntity<CompletableFuture<String>> entity = resolveValueWithEmptyBody(type);
|
HttpEntity<CompletableFuture<String>> entity = resolveValueWithEmptyBody(type);
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpEntityWithStringBody() {
|
void httpEntityWithStringBody() {
|
||||||
ServerWebExchange exchange = postExchange("line1");
|
ServerWebExchange exchange = postExchange("line1");
|
||||||
ResolvableType type = httpEntityType(String.class);
|
ResolvableType type = httpEntityType(String.class);
|
||||||
HttpEntity<String> httpEntity = resolveValue(exchange, type);
|
HttpEntity<String> httpEntity = resolveValue(exchange, type);
|
||||||
|
@ -190,7 +190,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpEntityWithMonoBody() {
|
void httpEntityWithMonoBody() {
|
||||||
ServerWebExchange exchange = postExchange("line1");
|
ServerWebExchange exchange = postExchange("line1");
|
||||||
ResolvableType type = httpEntityType(Mono.class, String.class);
|
ResolvableType type = httpEntityType(Mono.class, String.class);
|
||||||
HttpEntity<Mono<String>> httpEntity = resolveValue(exchange, type);
|
HttpEntity<Mono<String>> httpEntity = resolveValue(exchange, type);
|
||||||
|
@ -200,7 +200,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpEntityWithSingleBody() {
|
void httpEntityWithSingleBody() {
|
||||||
ServerWebExchange exchange = postExchange("line1");
|
ServerWebExchange exchange = postExchange("line1");
|
||||||
ResolvableType type = httpEntityType(Single.class, String.class);
|
ResolvableType type = httpEntityType(Single.class, String.class);
|
||||||
HttpEntity<Single<String>> httpEntity = resolveValue(exchange, type);
|
HttpEntity<Single<String>> httpEntity = resolveValue(exchange, type);
|
||||||
|
@ -210,7 +210,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpEntityWithMaybeBody() {
|
void httpEntityWithMaybeBody() {
|
||||||
ServerWebExchange exchange = postExchange("line1");
|
ServerWebExchange exchange = postExchange("line1");
|
||||||
ResolvableType type = httpEntityType(Maybe.class, String.class);
|
ResolvableType type = httpEntityType(Maybe.class, String.class);
|
||||||
HttpEntity<Maybe<String>> httpEntity = resolveValue(exchange, type);
|
HttpEntity<Maybe<String>> httpEntity = resolveValue(exchange, type);
|
||||||
|
@ -220,7 +220,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpEntityWithCompletableFutureBody() throws Exception {
|
void httpEntityWithCompletableFutureBody() throws Exception {
|
||||||
ServerWebExchange exchange = postExchange("line1");
|
ServerWebExchange exchange = postExchange("line1");
|
||||||
ResolvableType type = httpEntityType(CompletableFuture.class, String.class);
|
ResolvableType type = httpEntityType(CompletableFuture.class, String.class);
|
||||||
HttpEntity<CompletableFuture<String>> httpEntity = resolveValue(exchange, type);
|
HttpEntity<CompletableFuture<String>> httpEntity = resolveValue(exchange, type);
|
||||||
|
@ -230,7 +230,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpEntityWithFluxBody() {
|
void httpEntityWithFluxBody() {
|
||||||
ServerWebExchange exchange = postExchange("line1\nline2\nline3\n");
|
ServerWebExchange exchange = postExchange("line1\nline2\nline3\n");
|
||||||
ResolvableType type = httpEntityType(Flux.class, String.class);
|
ResolvableType type = httpEntityType(Flux.class, String.class);
|
||||||
HttpEntity<Flux<String>> httpEntity = resolveValue(exchange, type);
|
HttpEntity<Flux<String>> httpEntity = resolveValue(exchange, type);
|
||||||
|
@ -245,7 +245,7 @@ public class HttpEntityMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestEntity() {
|
void requestEntity() {
|
||||||
ServerWebExchange exchange = postExchange("line1");
|
ServerWebExchange exchange = postExchange("line1");
|
||||||
ResolvableType type = forClassWithGenerics(RequestEntity.class, String.class);
|
ResolvableType type = forClassWithGenerics(RequestEntity.class, String.class);
|
||||||
RequestEntity<String> requestEntity = resolveValue(exchange, type);
|
RequestEntity<String> requestEntity = resolveValue(exchange, type);
|
||||||
|
|
|
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class InitBinderBindingContextTests {
|
class InitBinderBindingContextTests {
|
||||||
|
|
||||||
private final ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
|
private final ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class InitBinderBindingContextTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinder() throws Exception {
|
void createBinder() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null);
|
WebDataBinder dataBinder = context.createDataBinder(exchange, null);
|
||||||
|
@ -63,7 +63,7 @@ public class InitBinderBindingContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderWithGlobalInitialization() throws Exception {
|
void createBinderWithGlobalInitialization() throws Exception {
|
||||||
ConversionService conversionService = new DefaultFormattingConversionService();
|
ConversionService conversionService = new DefaultFormattingConversionService();
|
||||||
bindingInitializer.setConversionService(conversionService);
|
bindingInitializer.setConversionService(conversionService);
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class InitBinderBindingContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderWithAttrName() throws Exception {
|
void createBinderWithAttrName() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, "foo");
|
WebDataBinder dataBinder = context.createDataBinder(exchange, "foo");
|
||||||
|
@ -85,7 +85,7 @@ public class InitBinderBindingContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderWithAttrNameNoMatch() throws Exception {
|
void createBinderWithAttrNameNoMatch() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, "invalidName");
|
WebDataBinder dataBinder = context.createDataBinder(exchange, "invalidName");
|
||||||
|
@ -94,7 +94,7 @@ public class InitBinderBindingContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderNullAttrName() throws Exception {
|
void createBinderNullAttrName() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null);
|
WebDataBinder dataBinder = context.createDataBinder(exchange, null);
|
||||||
|
@ -103,14 +103,14 @@ public class InitBinderBindingContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnValueNotExpected() throws Exception {
|
void returnValueNotExpected() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
|
||||||
assertThatIllegalStateException().isThrownBy(() -> context.createDataBinder(exchange, "invalidName"));
|
assertThatIllegalStateException().isThrownBy(() -> context.createDataBinder(exchange, "invalidName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderTypeConversion() throws Exception {
|
void createBinderTypeConversion() throws Exception {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build();
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
|
|
|
@ -45,7 +45,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class MatrixVariablesMapMethodArgumentResolverTests {
|
class MatrixVariablesMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
private final MatrixVariableMapMethodArgumentResolver resolver =
|
private final MatrixVariableMapMethodArgumentResolver resolver =
|
||||||
new MatrixVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
new MatrixVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -56,13 +56,13 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
|
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
|
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgument() throws Exception {
|
void resolveArgument() throws Exception {
|
||||||
MultiValueMap<String, String> params = getMatrixVariables("cars");
|
MultiValueMap<String, String> params = getMatrixVariables("cars");
|
||||||
params.add("colors", "red");
|
params.add("colors", "red");
|
||||||
params.add("colors", "green");
|
params.add("colors", "green");
|
||||||
|
@ -111,7 +111,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentPathVariable() throws Exception {
|
void resolveArgumentPathVariable() {
|
||||||
MultiValueMap<String, String> params1 = getMatrixVariables("cars");
|
MultiValueMap<String, String> params1 = getMatrixVariables("cars");
|
||||||
params1.add("colors", "red");
|
params1.add("colors", "red");
|
||||||
params1.add("colors", "purple");
|
params1.add("colors", "purple");
|
||||||
|
@ -141,7 +141,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveMultiValueMapArgumentNoParams() {
|
void resolveMultiValueMapArgumentNoParams() {
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noPathVar())
|
MethodParameter param = this.testMethod.annot(matrixAttribute().noPathVar())
|
||||||
.arg(MultiValueMap.class, String.class, String.class);
|
.arg(MultiValueMap.class, String.class, String.class);
|
||||||
|
@ -154,7 +154,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentNoParams() throws Exception {
|
void resolveArgumentNoParams() {
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noName())
|
MethodParameter param = this.testMethod.annot(matrixAttribute().noName())
|
||||||
.arg(Map.class, String.class, String.class);
|
.arg(Map.class, String.class, String.class);
|
||||||
|
@ -167,7 +167,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentNoMatch() throws Exception {
|
void resolveArgumentNoMatch() {
|
||||||
MultiValueMap<String, String> params2 = getMatrixVariables("planes");
|
MultiValueMap<String, String> params2 = getMatrixVariables("planes");
|
||||||
params2.add("colors", "yellow");
|
params2.add("colors", "yellow");
|
||||||
params2.add("colors", "orange");
|
params2.add("colors", "orange");
|
||||||
|
|
|
@ -47,7 +47,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class MatrixVariablesMethodArgumentResolverTests {
|
class MatrixVariablesMethodArgumentResolverTests {
|
||||||
|
|
||||||
private MatrixVariableMethodArgumentResolver resolver =
|
private MatrixVariableMethodArgumentResolver resolver =
|
||||||
new MatrixVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance());
|
new MatrixVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -58,13 +58,13 @@ public class MatrixVariablesMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
|
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
|
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class MatrixVariablesMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgument() throws Exception {
|
void resolveArgument() throws Exception {
|
||||||
MultiValueMap<String, String> params = getVariablesFor("cars");
|
MultiValueMap<String, String> params = getVariablesFor("cars");
|
||||||
params.add("colors", "red");
|
params.add("colors", "red");
|
||||||
params.add("colors", "green");
|
params.add("colors", "green");
|
||||||
|
@ -87,7 +87,7 @@ public class MatrixVariablesMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentPathVariable() throws Exception {
|
void resolveArgumentPathVariable() {
|
||||||
getVariablesFor("cars").add("year", "2006");
|
getVariablesFor("cars").add("year", "2006");
|
||||||
getVariablesFor("bikes").add("year", "2005");
|
getVariablesFor("bikes").add("year", "2005");
|
||||||
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
||||||
|
@ -97,14 +97,14 @@ public class MatrixVariablesMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentDefaultValue() throws Exception {
|
void resolveArgumentDefaultValue() {
|
||||||
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
||||||
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
|
||||||
assertThat(actual).isEqualTo(2013);
|
assertThat(actual).isEqualTo(2013);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentMultipleMatches() throws Exception {
|
void resolveArgumentMultipleMatches() {
|
||||||
getVariablesFor("var1").add("colors", "red");
|
getVariablesFor("var1").add("colors", "red");
|
||||||
getVariablesFor("var2").add("colors", "green");
|
getVariablesFor("var2").add("colors", "green");
|
||||||
|
|
||||||
|
@ -114,14 +114,14 @@ public class MatrixVariablesMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentRequired() throws Exception {
|
void resolveArgumentRequired() {
|
||||||
MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class);
|
MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class);
|
||||||
assertThatExceptionOfType(ServerWebInputException.class).isThrownBy(() ->
|
assertThatExceptionOfType(ServerWebInputException.class).isThrownBy(() ->
|
||||||
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO));
|
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentNoMatch() throws Exception {
|
void resolveArgumentNoMatch() {
|
||||||
MultiValueMap<String, String> params = getVariablesFor("cars");
|
MultiValueMap<String, String> params = getVariablesFor("cars");
|
||||||
params.add("anotherYear", "2012");
|
params.add("anotherYear", "2012");
|
||||||
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
|
||||||
|
|
|
@ -68,7 +68,7 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class MessageReaderArgumentResolverTests {
|
class MessageReaderArgumentResolverTests {
|
||||||
|
|
||||||
private AbstractMessageReaderArgumentResolver resolver = resolver(new Jackson2JsonDecoder());
|
private AbstractMessageReaderArgumentResolver resolver = resolver(new Jackson2JsonDecoder());
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
|
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
|
||||||
initializer.setValidator(new TestBeanValidator());
|
initializer.setValidator(new TestBeanValidator());
|
||||||
this.bindingContext = new BindingContext(initializer);
|
this.bindingContext = new BindingContext(initializer);
|
||||||
|
@ -87,7 +87,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void missingContentType() throws Exception {
|
void missingContentType() {
|
||||||
MockServerHttpRequest request = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}");
|
MockServerHttpRequest request = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}");
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
||||||
|
@ -101,7 +101,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
// More extensive "empty body" tests in RequestBody- and HttpEntityArgumentResolverTests
|
// More extensive "empty body" tests in RequestBody- and HttpEntityArgumentResolverTests
|
||||||
|
|
||||||
@Test @SuppressWarnings("unchecked") // SPR-9942
|
@Test @SuppressWarnings("unchecked") // SPR-9942
|
||||||
public void emptyBody() throws Exception {
|
public void emptyBody() {
|
||||||
MockServerHttpRequest request = post("/path").contentType(MediaType.APPLICATION_JSON).build();
|
MockServerHttpRequest request = post("/path").contentType(MediaType.APPLICATION_JSON).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
||||||
|
@ -113,7 +113,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void monoTestBean() throws Exception {
|
void monoTestBean() {
|
||||||
String body = "{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}";
|
String body = "{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}";
|
||||||
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -123,7 +123,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fluxTestBean() throws Exception {
|
void fluxTestBean() {
|
||||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||||
ResolvableType type = forClassWithGenerics(Flux.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Flux.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -133,7 +133,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleTestBean() throws Exception {
|
void singleTestBean() {
|
||||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||||
ResolvableType type = forClassWithGenerics(Single.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Single.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -143,7 +143,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void maybeTestBean() throws Exception {
|
void maybeTestBean() {
|
||||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||||
ResolvableType type = forClassWithGenerics(Maybe.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Maybe.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -153,7 +153,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void observableTestBean() throws Exception {
|
void observableTestBean() {
|
||||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||||
ResolvableType type = forClassWithGenerics(Observable.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Observable.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -163,7 +163,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void flowableTestBean() throws Exception {
|
void flowableTestBean() {
|
||||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||||
ResolvableType type = forClassWithGenerics(Flowable.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Flowable.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -173,7 +173,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void futureTestBean() throws Exception {
|
void futureTestBean() throws Exception {
|
||||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||||
ResolvableType type = forClassWithGenerics(CompletableFuture.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(CompletableFuture.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -183,7 +183,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBean() throws Exception {
|
void testBean() {
|
||||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||||
MethodParameter param = this.testMethod.arg(TestBean.class);
|
MethodParameter param = this.testMethod.arg(TestBean.class);
|
||||||
TestBean value = resolveValue(param, body);
|
TestBean value = resolveValue(param, body);
|
||||||
|
@ -192,7 +192,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void map() throws Exception {
|
void map() throws Exception {
|
||||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("foo", "f1");
|
map.put("foo", "f1");
|
||||||
|
@ -205,7 +205,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void list() throws Exception {
|
void list() throws Exception {
|
||||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||||
ResolvableType type = forClassWithGenerics(List.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(List.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -215,7 +215,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void monoList() throws Exception {
|
void monoList() {
|
||||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||||
ResolvableType type = forClassWithGenerics(Mono.class, forClassWithGenerics(List.class, TestBean.class));
|
ResolvableType type = forClassWithGenerics(Mono.class, forClassWithGenerics(List.class, TestBean.class));
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -226,7 +226,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void array() throws Exception {
|
void array() {
|
||||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||||
MethodParameter param = this.testMethod.arg(TestBean[].class);
|
MethodParameter param = this.testMethod.arg(TestBean[].class);
|
||||||
TestBean[] value = resolveValue(param, body);
|
TestBean[] value = resolveValue(param, body);
|
||||||
|
@ -235,7 +235,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateMonoTestBean() throws Exception {
|
void validateMonoTestBean() {
|
||||||
String body = "{\"bar\":\"b1\"}";
|
String body = "{\"bar\":\"b1\"}";
|
||||||
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
@ -245,7 +245,7 @@ public class MessageReaderArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateFluxTestBean() throws Exception {
|
void validateFluxTestBean() {
|
||||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\"}]";
|
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\"}]";
|
||||||
ResolvableType type = forClassWithGenerics(Flux.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Flux.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
|
|
|
@ -64,7 +64,7 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class MessageWriterResultHandlerTests {
|
class MessageWriterResultHandlerTests {
|
||||||
|
|
||||||
private final AbstractMessageWriterResultHandler resultHandler = initResultHandler();
|
private final AbstractMessageWriterResultHandler resultHandler = initResultHandler();
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
|
|
||||||
|
|
||||||
@Test // SPR-12894
|
@Test // SPR-12894
|
||||||
public void useDefaultContentType() throws Exception {
|
public void useDefaultContentType() {
|
||||||
Resource body = new ClassPathResource("logo.png", getClass());
|
Resource body = new ClassPathResource("logo.png", getClass());
|
||||||
MethodParameter type = on(TestController.class).resolveReturnType(Resource.class);
|
MethodParameter type = on(TestController.class).resolveReturnType(Resource.class);
|
||||||
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
|
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
|
||||||
|
@ -99,7 +99,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-13631
|
@Test // SPR-13631
|
||||||
public void useDefaultCharset() throws Exception {
|
public void useDefaultCharset() {
|
||||||
this.exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE,
|
this.exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE,
|
||||||
Collections.singleton(APPLICATION_JSON));
|
Collections.singleton(APPLICATION_JSON));
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void voidReturnType() throws Exception {
|
void voidReturnType() {
|
||||||
testVoid(null, on(TestController.class).resolveReturnType(void.class));
|
testVoid(null, on(TestController.class).resolveReturnType(void.class));
|
||||||
testVoid(Mono.empty(), on(TestController.class).resolveReturnType(Mono.class, Void.class));
|
testVoid(Mono.empty(), on(TestController.class).resolveReturnType(Mono.class, Void.class));
|
||||||
testVoid(Flux.empty(), on(TestController.class).resolveReturnType(Flux.class, Void.class));
|
testVoid(Flux.empty(), on(TestController.class).resolveReturnType(Flux.class, Void.class));
|
||||||
|
@ -137,7 +137,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-13135
|
@Test // SPR-13135
|
||||||
public void unsupportedReturnType() throws Exception {
|
public void unsupportedReturnType() {
|
||||||
ByteArrayOutputStream body = new ByteArrayOutputStream();
|
ByteArrayOutputStream body = new ByteArrayOutputStream();
|
||||||
MethodParameter type = on(TestController.class).resolveReturnType(OutputStream.class);
|
MethodParameter type = on(TestController.class).resolveReturnType(OutputStream.class);
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-12811
|
@Test // SPR-12811
|
||||||
public void jacksonTypeOfListElement() throws Exception {
|
public void jacksonTypeOfListElement() {
|
||||||
|
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(List.class, ParentClass.class);
|
MethodParameter returnType = on(TestController.class).resolveReturnType(List.class, ParentClass.class);
|
||||||
List<ParentClass> body = Arrays.asList(new Foo("foo"), new Bar("bar"));
|
List<ParentClass> body = Arrays.asList(new Foo("foo"), new Bar("bar"));
|
||||||
|
@ -160,7 +160,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-13318
|
@Test // SPR-13318
|
||||||
public void jacksonTypeWithSubType() throws Exception {
|
public void jacksonTypeWithSubType() {
|
||||||
SimpleBean body = new SimpleBean(123L, "foo");
|
SimpleBean body = new SimpleBean(123L, "foo");
|
||||||
MethodParameter type = on(TestController.class).resolveReturnType(Identifiable.class);
|
MethodParameter type = on(TestController.class).resolveReturnType(Identifiable.class);
|
||||||
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
|
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
|
||||||
|
@ -170,7 +170,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-13318
|
@Test // SPR-13318
|
||||||
public void jacksonTypeWithSubTypeOfListElement() throws Exception {
|
public void jacksonTypeWithSubTypeOfListElement() {
|
||||||
|
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(List.class, Identifiable.class);
|
MethodParameter returnType = on(TestController.class).resolveReturnType(List.class, Identifiable.class);
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ public class MessageWriterResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jacksonTypeWithSubTypeAndObjectReturnValue() {
|
void jacksonTypeWithSubTypeAndObjectReturnValue() {
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(Object.class);
|
MethodParameter returnType = on(TestController.class).resolveReturnType(Object.class);
|
||||||
|
|
||||||
SimpleBean body = new SimpleBean(123L, "foo");
|
SimpleBean body = new SimpleBean(123L, "foo");
|
||||||
|
|
|
@ -77,7 +77,7 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class MethodValidationTests {
|
class MethodValidationTests {
|
||||||
|
|
||||||
private static final Person mockPerson = mock(Person.class);
|
private static final Person mockPerson = mock(Person.class);
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ class ModelAttributeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void validationErrorWithoutBindingForSingle() throws Exception {
|
void validationErrorWithoutBindingForSingle() {
|
||||||
MethodParameter parameter = this.testMethod.annotPresent(ModelAttribute.class).arg(Single.class, ValidatedPojo.class);
|
MethodParameter parameter = this.testMethod.annotPresent(ModelAttribute.class).arg(Single.class, ValidatedPojo.class);
|
||||||
|
|
||||||
testValidationErrorWithoutBinding(parameter, resolvedArgumentMono -> {
|
testValidationErrorWithoutBinding(parameter, resolvedArgumentMono -> {
|
||||||
|
|
|
@ -61,7 +61,7 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ModelInitializerTests {
|
class ModelInitializerTests {
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofMillis(5000);
|
private static final Duration TIMEOUT = Duration.ofMillis(5000);
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class ModelInitializerTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
|
|
||||||
ArgumentResolverConfigurer resolverConfigurer = new ArgumentResolverConfigurer();
|
ArgumentResolverConfigurer resolverConfigurer = new ArgumentResolverConfigurer();
|
||||||
|
@ -87,7 +87,7 @@ public class ModelInitializerTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void initBinderMethod() {
|
void initBinderMethod() {
|
||||||
Validator validator = mock();
|
Validator validator = mock();
|
||||||
|
|
||||||
TestController controller = new TestController();
|
TestController controller = new TestController();
|
||||||
|
@ -104,7 +104,7 @@ public class ModelInitializerTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void modelAttributeMethods() {
|
void modelAttributeMethods() {
|
||||||
TestController controller = new TestController();
|
TestController controller = new TestController();
|
||||||
InitBinderBindingContext context = getBindingContext(controller);
|
InitBinderBindingContext context = getBindingContext(controller);
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ public class ModelInitializerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void saveModelAttributeToSession() {
|
void saveModelAttributeToSession() {
|
||||||
TestController controller = new TestController();
|
TestController controller = new TestController();
|
||||||
InitBinderBindingContext context = getBindingContext(controller);
|
InitBinderBindingContext context = getBindingContext(controller);
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ public class ModelInitializerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retrieveModelAttributeFromSession() {
|
void retrieveModelAttributeFromSession() {
|
||||||
WebSession session = this.exchange.getSession().block(TIMEOUT);
|
WebSession session = this.exchange.getSession().block(TIMEOUT);
|
||||||
assertThat(session).isNotNull();
|
assertThat(session).isNotNull();
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ public class ModelInitializerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requiredSessionAttributeMissing() {
|
void requiredSessionAttributeMissing() {
|
||||||
TestController controller = new TestController();
|
TestController controller = new TestController();
|
||||||
InitBinderBindingContext context = getBindingContext(controller);
|
InitBinderBindingContext context = getBindingContext(controller);
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ public class ModelInitializerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clearModelAttributeFromSession() {
|
void clearModelAttributeFromSession() {
|
||||||
WebSession session = this.exchange.getSession().block(TIMEOUT);
|
WebSession session = this.exchange.getSession().block(TIMEOUT);
|
||||||
assertThat(session).isNotNull();
|
assertThat(session).isNotNull();
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ModelMethodArgumentResolverTests {
|
class ModelMethodArgumentResolverTests {
|
||||||
|
|
||||||
private final ModelMethodArgumentResolver resolver =
|
private final ModelMethodArgumentResolver resolver =
|
||||||
new ModelMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
new ModelMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -50,7 +50,7 @@ public class ModelMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.resolvable.arg(Model.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.resolvable.arg(Model.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.resolvable.arg(ModelMap.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.resolvable.arg(ModelMap.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(
|
assertThat(this.resolver.supportsParameter(
|
||||||
|
@ -62,7 +62,7 @@ public class ModelMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgument() {
|
void resolveArgument() {
|
||||||
testResolveArgument(this.resolvable.arg(Model.class));
|
testResolveArgument(this.resolvable.arg(Model.class));
|
||||||
testResolveArgument(this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class));
|
testResolveArgument(this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class));
|
||||||
testResolveArgument(this.resolvable.arg(ModelMap.class));
|
testResolveArgument(this.resolvable.arg(ModelMap.class));
|
||||||
|
|
|
@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class PathVariableMapMethodArgumentResolverTests {
|
class PathVariableMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
private PathVariableMapMethodArgumentResolver resolver;
|
private PathVariableMapMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class PathVariableMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
this.resolver = new PathVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
this.resolver = new PathVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
|
||||||
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
|
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
|
||||||
|
@ -67,7 +67,7 @@ public class PathVariableMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(resolver.supportsParameter(paramMap)).isTrue();
|
assertThat(resolver.supportsParameter(paramMap)).isTrue();
|
||||||
assertThat(resolver.supportsParameter(paramNamedMap)).isFalse();
|
assertThat(resolver.supportsParameter(paramNamedMap)).isFalse();
|
||||||
assertThat(resolver.supportsParameter(paramMapNoAnnot)).isFalse();
|
assertThat(resolver.supportsParameter(paramMapNoAnnot)).isFalse();
|
||||||
|
@ -77,7 +77,7 @@ public class PathVariableMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgument() throws Exception {
|
void resolveArgument() throws Exception {
|
||||||
Map<String, String> uriTemplateVars = new HashMap<>();
|
Map<String, String> uriTemplateVars = new HashMap<>();
|
||||||
uriTemplateVars.put("name1", "value1");
|
uriTemplateVars.put("name1", "value1");
|
||||||
uriTemplateVars.put("name2", "value2");
|
uriTemplateVars.put("name2", "value2");
|
||||||
|
@ -90,7 +90,7 @@ public class PathVariableMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentNoUriVars() throws Exception {
|
void resolveArgumentNoUriVars() {
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramMap, new BindingContext(), this.exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(this.paramMap, new BindingContext(), this.exchange);
|
||||||
Object result = mono.block();
|
Object result = mono.block();
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class PathVariableMethodArgumentResolverTests {
|
class PathVariableMethodArgumentResolverTests {
|
||||||
|
|
||||||
private PathVariableMethodArgumentResolver resolver;
|
private PathVariableMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
this.resolver = new PathVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance());
|
this.resolver = new PathVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
|
||||||
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
|
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
|
||||||
|
@ -75,7 +75,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.paramNamedString)).isTrue();
|
assertThat(this.resolver.supportsParameter(this.paramNamedString)).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.paramString)).isFalse();
|
assertThat(this.resolver.supportsParameter(this.paramString)).isFalse();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
|
@ -84,7 +84,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgument() {
|
void resolveArgument() {
|
||||||
Map<String, String> uriTemplateVars = new HashMap<>();
|
Map<String, String> uriTemplateVars = new HashMap<>();
|
||||||
uriTemplateVars.put("name", "value");
|
uriTemplateVars.put("name", "value");
|
||||||
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
||||||
|
@ -96,7 +96,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentNotRequired() {
|
void resolveArgumentNotRequired() {
|
||||||
Map<String, String> uriTemplateVars = new HashMap<>();
|
Map<String, String> uriTemplateVars = new HashMap<>();
|
||||||
uriTemplateVars.put("name", "value");
|
uriTemplateVars.put("name", "value");
|
||||||
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
||||||
|
@ -108,7 +108,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgumentWrappedAsOptional() {
|
void resolveArgumentWrappedAsOptional() {
|
||||||
Map<String, String> uriTemplateVars = new HashMap<>();
|
Map<String, String> uriTemplateVars = new HashMap<>();
|
||||||
uriTemplateVars.put("name", "value");
|
uriTemplateVars.put("name", "value");
|
||||||
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
||||||
|
@ -123,7 +123,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleMissingValue() {
|
void handleMissingValue() {
|
||||||
BindingContext bindingContext = new BindingContext();
|
BindingContext bindingContext = new BindingContext();
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange);
|
||||||
StepVerifier.create(mono)
|
StepVerifier.create(mono)
|
||||||
|
@ -133,7 +133,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullIfNotRequired() {
|
void nullIfNotRequired() {
|
||||||
BindingContext bindingContext = new BindingContext();
|
BindingContext bindingContext = new BindingContext();
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange);
|
||||||
StepVerifier.create(mono)
|
StepVerifier.create(mono)
|
||||||
|
@ -143,7 +143,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void wrapEmptyWithOptional() {
|
void wrapEmptyWithOptional() {
|
||||||
BindingContext bindingContext = new BindingContext();
|
BindingContext bindingContext = new BindingContext();
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class PrincipalMethodArgumentResolverTests {
|
class PrincipalMethodArgumentResolverTests {
|
||||||
|
|
||||||
private final PrincipalMethodArgumentResolver resolver =
|
private final PrincipalMethodArgumentResolver resolver =
|
||||||
new PrincipalMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
new PrincipalMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -46,7 +46,7 @@ public class PrincipalMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Principal.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Principal.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, Principal.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, Principal.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Single.class, Principal.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Single.class, Principal.class))).isTrue();
|
||||||
|
@ -54,7 +54,7 @@ public class PrincipalMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolverArgument() {
|
void resolverArgument() {
|
||||||
Principal user = () -> "Joe";
|
Principal user = () -> "Joe";
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
||||||
.mutate().principal(Mono.just(user)).build();
|
.mutate().principal(Mono.just(user)).build();
|
||||||
|
|
|
@ -45,7 +45,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestAttributeMethodArgumentResolverTests {
|
class RequestAttributeMethodArgumentResolverTests {
|
||||||
|
|
||||||
private RequestAttributeMethodArgumentResolver resolver;
|
private RequestAttributeMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -56,8 +56,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@SuppressWarnings("resource")
|
void setup() throws Exception {
|
||||||
public void setup() throws Exception {
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.refresh();
|
context.refresh();
|
||||||
ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
|
@ -66,7 +65,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(
|
assertThat(this.resolver.supportsParameter(
|
||||||
this.testMethod.annot(requestAttribute().noName()).arg(Foo.class))).isTrue();
|
this.testMethod.annot(requestAttribute().noName()).arg(Foo.class))).isTrue();
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolve() {
|
void resolve() {
|
||||||
MethodParameter param = this.testMethod.annot(requestAttribute().noName()).arg(Foo.class);
|
MethodParameter param = this.testMethod.annot(requestAttribute().noName()).arg(Foo.class);
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||||
StepVerifier.create(mono)
|
StepVerifier.create(mono)
|
||||||
|
@ -94,7 +93,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveWithName() {
|
void resolveWithName() {
|
||||||
MethodParameter param = this.testMethod.annot(requestAttribute().name("specialFoo")).arg();
|
MethodParameter param = this.testMethod.annot(requestAttribute().name("specialFoo")).arg();
|
||||||
Foo foo = new Foo();
|
Foo foo = new Foo();
|
||||||
this.exchange.getAttributes().put("specialFoo", foo);
|
this.exchange.getAttributes().put("specialFoo", foo);
|
||||||
|
@ -103,7 +102,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNotRequired() {
|
void resolveNotRequired() {
|
||||||
MethodParameter param = this.testMethod.annot(requestAttribute().name("foo").notRequired()).arg();
|
MethodParameter param = this.testMethod.annot(requestAttribute().name("foo").notRequired()).arg();
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||||
assertThat(mono.block()).isNull();
|
assertThat(mono.block()).isNull();
|
||||||
|
@ -115,7 +114,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveOptional() {
|
void resolveOptional() {
|
||||||
MethodParameter param = this.testMethod.annot(requestAttribute().name("foo")).arg(Optional.class, Foo.class);
|
MethodParameter param = this.testMethod.annot(requestAttribute().name("foo")).arg(Optional.class, Foo.class);
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestBodyMethodArgumentResolverTests {
|
class RequestBodyMethodArgumentResolverTests {
|
||||||
|
|
||||||
private RequestBodyMethodArgumentResolver resolver;
|
private RequestBodyMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
List<HttpMessageReader<?>> readers = new ArrayList<>();
|
List<HttpMessageReader<?>> readers = new ArrayList<>();
|
||||||
readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
|
readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
|
||||||
this.resolver = new RequestBodyMethodArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
|
this.resolver = new RequestBodyMethodArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -74,7 +74,7 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supports() {
|
void supports() {
|
||||||
MethodParameter param;
|
MethodParameter param;
|
||||||
|
|
||||||
param = this.testMethod.annot(requestBody()).arg(Mono.class, String.class);
|
param = this.testMethod.annot(requestBody()).arg(Mono.class, String.class);
|
||||||
|
@ -85,7 +85,7 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stringBody() {
|
void stringBody() {
|
||||||
String body = "line1";
|
String body = "line1";
|
||||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class);
|
||||||
String value = resolveValue(param, body);
|
String value = resolveValue(param, body);
|
||||||
|
@ -94,14 +94,14 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithString() {
|
void emptyBodyWithString() {
|
||||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class);
|
||||||
assertThatExceptionOfType(ServerWebInputException.class).isThrownBy(() ->
|
assertThatExceptionOfType(ServerWebInputException.class).isThrownBy(() ->
|
||||||
resolveValueWithEmptyBody(param));
|
resolveValueWithEmptyBody(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithStringNotRequired() {
|
void emptyBodyWithStringNotRequired() {
|
||||||
MethodParameter param = this.testMethod.annot(requestBody().notRequired()).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestBody().notRequired()).arg(String.class);
|
||||||
String body = resolveValueWithEmptyBody(param);
|
String body = resolveValueWithEmptyBody(param);
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithSingle() {
|
void emptyBodyWithSingle() {
|
||||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Single.class, String.class);
|
MethodParameter param = this.testMethod.annot(requestBody()).arg(Single.class, String.class);
|
||||||
Single<String> single = resolveValueWithEmptyBody(param);
|
Single<String> single = resolveValueWithEmptyBody(param);
|
||||||
StepVerifier.create(single.toFlowable())
|
StepVerifier.create(single.toFlowable())
|
||||||
|
@ -166,7 +166,7 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithMaybe() {
|
void emptyBodyWithMaybe() {
|
||||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Maybe.class, String.class);
|
MethodParameter param = this.testMethod.annot(requestBody()).arg(Maybe.class, String.class);
|
||||||
Maybe<String> maybe = resolveValueWithEmptyBody(param);
|
Maybe<String> maybe = resolveValueWithEmptyBody(param);
|
||||||
StepVerifier.create(maybe.toFlowable())
|
StepVerifier.create(maybe.toFlowable())
|
||||||
|
@ -183,7 +183,7 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithObservable() {
|
void emptyBodyWithObservable() {
|
||||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(Observable.class, String.class);
|
MethodParameter param = this.testMethod.annot(requestBody()).arg(Observable.class, String.class);
|
||||||
Observable<String> observable = resolveValueWithEmptyBody(param);
|
Observable<String> observable = resolveValueWithEmptyBody(param);
|
||||||
StepVerifier.create(observable.toFlowable(BackpressureStrategy.BUFFER))
|
StepVerifier.create(observable.toFlowable(BackpressureStrategy.BUFFER))
|
||||||
|
@ -200,7 +200,7 @@ public class RequestBodyMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyWithCompletableFuture() {
|
void emptyBodyWithCompletableFuture() {
|
||||||
MethodParameter param = this.testMethod.annot(requestBody()).arg(CompletableFuture.class, String.class);
|
MethodParameter param = this.testMethod.annot(requestBody()).arg(CompletableFuture.class, String.class);
|
||||||
CompletableFuture<String> future = resolveValueWithEmptyBody(param);
|
CompletableFuture<String> future = resolveValueWithEmptyBody(param);
|
||||||
future.whenComplete((text, ex) -> {
|
future.whenComplete((text, ex) -> {
|
||||||
|
|
|
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestHeaderMapMethodArgumentResolverTests {
|
class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
private RequestHeaderMapMethodArgumentResolver resolver;
|
private RequestHeaderMapMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
resolver = new RequestHeaderMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
resolver = new RequestHeaderMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
|
||||||
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
|
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
|
||||||
|
@ -69,7 +69,7 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(resolver.supportsParameter(paramMap)).as("Map parameter not supported").isTrue();
|
assertThat(resolver.supportsParameter(paramMap)).as("Map parameter not supported").isTrue();
|
||||||
assertThat(resolver.supportsParameter(paramMultiValueMap)).as("MultiValueMap parameter not supported").isTrue();
|
assertThat(resolver.supportsParameter(paramMultiValueMap)).as("MultiValueMap parameter not supported").isTrue();
|
||||||
assertThat(resolver.supportsParameter(paramHttpHeaders)).as("HttpHeaders parameter not supported").isTrue();
|
assertThat(resolver.supportsParameter(paramHttpHeaders)).as("HttpHeaders parameter not supported").isTrue();
|
||||||
|
@ -80,7 +80,7 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveMapArgument() {
|
void resolveMapArgument() {
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
String value = "bar";
|
String value = "bar";
|
||||||
Map<String, String> expected = Collections.singletonMap(name, value);
|
Map<String, String> expected = Collections.singletonMap(name, value);
|
||||||
|
@ -116,7 +116,7 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveHttpHeadersArgument() {
|
void resolveHttpHeadersArgument() {
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
String value1 = "bar";
|
String value1 = "bar";
|
||||||
String value2 = "baz";
|
String value2 = "baz";
|
||||||
|
|
|
@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestHeaderMethodArgumentResolverTests {
|
class RequestHeaderMethodArgumentResolverTests {
|
||||||
|
|
||||||
private RequestHeaderMethodArgumentResolver resolver;
|
private RequestHeaderMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -67,8 +67,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@SuppressWarnings("resource")
|
void setup() throws Exception {
|
||||||
public void setup() throws Exception {
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.refresh();
|
context.refresh();
|
||||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
|
@ -92,7 +91,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(resolver.supportsParameter(paramNamedDefaultValueStringHeader)).as("String parameter not supported").isTrue();
|
assertThat(resolver.supportsParameter(paramNamedDefaultValueStringHeader)).as("String parameter not supported").isTrue();
|
||||||
assertThat(resolver.supportsParameter(paramNamedValueStringArray)).as("String array parameter not supported").isTrue();
|
assertThat(resolver.supportsParameter(paramNamedValueStringArray)).as("String array parameter not supported").isTrue();
|
||||||
assertThat(resolver.supportsParameter(paramNamedValueMap)).as("non-@RequestParam parameter supported").isFalse();
|
assertThat(resolver.supportsParameter(paramNamedValueMap)).as("non-@RequestParam parameter supported").isFalse();
|
||||||
|
@ -102,7 +101,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveStringArgument() {
|
void resolveStringArgument() {
|
||||||
String expected = "foo";
|
String expected = "foo";
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("name", expected));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("name", expected));
|
||||||
|
|
||||||
|
@ -116,7 +115,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveStringArrayArgument() {
|
void resolveStringArrayArgument() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", "foo", "bar").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", "foo", "bar").build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
|
@ -130,7 +129,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveDefaultValue() {
|
void resolveDefaultValue() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
||||||
|
@ -142,7 +141,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveDefaultValueFromSystemProperty() {
|
void resolveDefaultValueFromSystemProperty() {
|
||||||
System.setProperty("systemProperty", "bar");
|
System.setProperty("systemProperty", "bar");
|
||||||
try {
|
try {
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
|
@ -160,7 +159,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNameFromSystemPropertyThroughExpression() {
|
void resolveNameFromSystemPropertyThroughExpression() {
|
||||||
String expected = "foo";
|
String expected = "foo";
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
@ -181,7 +180,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNameFromSystemPropertyThroughPlaceholder() {
|
void resolveNameFromSystemPropertyThroughPlaceholder() {
|
||||||
String expected = "foo";
|
String expected = "foo";
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
@ -202,7 +201,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notFound() {
|
void notFound() {
|
||||||
Mono<Object> mono = resolver.resolveArgument(
|
Mono<Object> mono = resolver.resolveArgument(
|
||||||
this.paramNamedValueStringArray, this.bindingContext,
|
this.paramNamedValueStringArray, this.bindingContext,
|
||||||
MockServerWebExchange.from(MockServerHttpRequest.get("/")));
|
MockServerWebExchange.from(MockServerHttpRequest.get("/")));
|
||||||
|
@ -229,7 +228,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void instantConversion() {
|
void instantConversion() {
|
||||||
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", rfc1123val).build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", rfc1123val).build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class RequestMappingExceptionHandlingIntegrationTests extends AbstractRequestMappingIntegrationTests {
|
class RequestMappingExceptionHandlingIntegrationTests extends AbstractRequestMappingIntegrationTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ApplicationContext initApplicationContext() {
|
protected ApplicationContext initApplicationContext() {
|
||||||
|
@ -86,7 +86,7 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq
|
||||||
doTest("/mono-error", "Recovered from error: Argument");
|
doTest("/mono-error", "Recovered from error: Argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(String url, String expected) throws Exception {
|
private void doTest(String url, String expected) {
|
||||||
assertThat(performGet(url, new HttpHeaders(), String.class).getBody()).isEqualTo(expected);
|
assertThat(performGet(url, new HttpHeaders(), String.class).getBody()).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,14 +115,14 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void globalExceptionHandlerWithHandlerNotFound() throws Exception {
|
void globalExceptionHandlerWithHandlerNotFound() throws Exception {
|
||||||
startServer(new ReactorHttpServer());
|
startServer(new ReactorHttpServer());
|
||||||
|
|
||||||
assertThatExceptionOfType(HttpStatusCodeException.class)
|
assertThatExceptionOfType(HttpStatusCodeException.class)
|
||||||
.isThrownBy(() -> performGet("/no-such-handler", new HttpHeaders(), String.class))
|
.isThrownBy(() -> performGet("/no-such-handler", new HttpHeaders(), String.class))
|
||||||
.satisfies(ex -> {
|
.satisfies(ex -> {
|
||||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||||
assertThat(ex.getResponseBodyAsString()).isEqualTo("" +
|
assertThat(ex.getResponseBodyAsString()).isEqualTo(
|
||||||
"{\"type\":\"about:blank\"," +
|
"{\"type\":\"about:blank\"," +
|
||||||
"\"title\":\"Not Found\"," +
|
"\"title\":\"Not Found\"," +
|
||||||
"\"status\":404," +
|
"\"status\":404," +
|
||||||
|
@ -131,7 +131,7 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void globalExceptionHandlerWithMissingRequestParameter() throws Exception {
|
void globalExceptionHandlerWithMissingRequestParameter() throws Exception {
|
||||||
startServer(new ReactorHttpServer());
|
startServer(new ReactorHttpServer());
|
||||||
|
|
||||||
assertThatExceptionOfType(HttpStatusCodeException.class)
|
assertThatExceptionOfType(HttpStatusCodeException.class)
|
||||||
|
@ -198,7 +198,7 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path = "/SPR-16318", produces = "text/plain")
|
@GetMapping(path = "/SPR-16318", produces = "text/plain")
|
||||||
public Mono<String> handleTextPlain() throws Exception {
|
public Mono<String> handleTextPlain() {
|
||||||
return Mono.error(new Spr16318Exception());
|
return Mono.error(new Spr16318Exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,8 +224,7 @@ class RequestMappingHandlerMappingTests {
|
||||||
assertThat(paths.iterator().next().getPatternString()).isEqualTo(path);
|
assertThat(paths.iterator().next().getPatternString()).isEqualTo(path);
|
||||||
|
|
||||||
Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
|
Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
|
||||||
assertThat(methods).hasSize(1);
|
assertThat(methods).containsExactly(requestMethod);
|
||||||
assertThat(methods).element(0).isEqualTo(requestMethod);
|
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -91,7 +91,6 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin
|
||||||
|
|
||||||
URI uri = URI.create("http://localhost:" + this.port + "/redirect");
|
URI uri = URI.create("http://localhost:" + this.port + "/redirect");
|
||||||
RequestEntity<Void> request = RequestEntity.get(uri).accept(MediaType.ALL).build();
|
RequestEntity<Void> request = RequestEntity.get(uri).accept(MediaType.ALL).build();
|
||||||
@SuppressWarnings("resource")
|
|
||||||
ResponseEntity<Void> response = new RestTemplate(factory).exchange(request, Void.class);
|
ResponseEntity<Void> response = new RestTemplate(factory).exchange(request, Void.class);
|
||||||
|
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SEE_OTHER);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SEE_OTHER);
|
||||||
|
|
|
@ -42,7 +42,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestParamMapMethodArgumentResolverTests {
|
class RequestParamMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
private final RequestParamMapMethodArgumentResolver resolver =
|
private final RequestParamMapMethodArgumentResolver resolver =
|
||||||
new RequestParamMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
new RequestParamMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -51,7 +51,7 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
||||||
assertThat(this.resolver.supportsParameter(param)).isTrue();
|
assertThat(this.resolver.supportsParameter(param)).isTrue();
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveMapArgumentWithQueryString() {
|
void resolveMapArgumentWithQueryString() {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
||||||
Object result= resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar")));
|
Object result= resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar")));
|
||||||
boolean condition = result instanceof Map;
|
boolean condition = result instanceof Map;
|
||||||
|
@ -79,7 +79,7 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveMultiValueMapArgument() {
|
void resolveMultiValueMapArgument() {
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar&foo=baz"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar&foo=baz"));
|
||||||
Object result= resolve(param, exchange);
|
Object result= resolve(param, exchange);
|
||||||
|
|
|
@ -47,7 +47,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class RequestParamMethodArgumentResolverTests {
|
class RequestParamMethodArgumentResolverTests {
|
||||||
|
|
||||||
private RequestParamMethodArgumentResolver resolver;
|
private RequestParamMethodArgumentResolver resolver;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
|
|
||||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, true);
|
this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, true);
|
||||||
|
@ -69,7 +69,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
assertThat(this.resolver.supportsParameter(param)).isTrue();
|
assertThat(this.resolver.supportsParameter(param)).isTrue();
|
||||||
|
@ -95,7 +95,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotSupportParameterWithDefaultResolutionTurnedOff() {
|
void doesNotSupportParameterWithDefaultResolutionTurnedOff() {
|
||||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, false);
|
this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, false);
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotSupportReactiveWrapper() {
|
void doesNotSupportReactiveWrapper() {
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
this.resolver.supportsParameter(this.testMethod.annot(requestParam()).arg(Mono.class, String.class)))
|
this.resolver.supportsParameter(this.testMethod.annot(requestParam()).arg(Mono.class, String.class)))
|
||||||
.withMessageStartingWith("RequestParamMethodArgumentResolver does not support reactive type wrapper");
|
.withMessageStartingWith("RequestParamMethodArgumentResolver does not support reactive type wrapper");
|
||||||
|
@ -114,14 +114,14 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveWithQueryString() {
|
void resolveWithQueryString() {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=foo"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=foo"));
|
||||||
assertThat(resolve(param, exchange)).isEqualTo("foo");
|
assertThat(resolve(param, exchange)).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveStringArray() {
|
void resolveStringArray() {
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=foo&name=bar").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=foo&name=bar").build();
|
||||||
Object result = resolve(param, MockServerWebExchange.from(request));
|
Object result = resolve(param, MockServerWebExchange.from(request));
|
||||||
|
@ -131,7 +131,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveDefaultValue() {
|
void resolveDefaultValue() {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
assertThat(resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isEqualTo("bar");
|
assertThat(resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void missingRequestParam() {
|
void missingRequestParam() {
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
|
@ -158,7 +158,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveSimpleTypeParam() {
|
void resolveSimpleTypeParam() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=plainValue").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=plainValue").build();
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||||
|
@ -181,21 +181,21 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveEmptyValueWithoutDefault() {
|
void resolveEmptyValueWithoutDefault() {
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=").build();
|
||||||
assertThat(resolve(param, MockServerWebExchange.from(request))).isEqualTo("");
|
assertThat(resolve(param, MockServerWebExchange.from(request))).isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveEmptyValueRequiredWithoutDefault() {
|
void resolveEmptyValueRequiredWithoutDefault() {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam()).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam()).arg(String.class);
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name="));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name="));
|
||||||
assertThat(resolve(param, exchange)).isEqualTo("");
|
assertThat(resolve(param, exchange)).isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveOptionalParamValue() {
|
void resolveOptionalParamValue() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
MethodParameter param = this.testMethod.arg(forClassWithGenerics(Optional.class, Integer.class));
|
MethodParameter param = this.testMethod.arg(forClassWithGenerics(Optional.class, Integer.class));
|
||||||
Object result = resolve(param, exchange);
|
Object result = resolve(param, exchange);
|
||||||
|
|
|
@ -64,13 +64,13 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on;
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ResponseBodyResultHandlerTests {
|
class ResponseBodyResultHandlerTests {
|
||||||
|
|
||||||
private ResponseBodyResultHandler resultHandler;
|
private ResponseBodyResultHandler resultHandler;
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
List<HttpMessageWriter<?>> writerList = new ArrayList<>(5);
|
List<HttpMessageWriter<?>> writerList = new ArrayList<>(5);
|
||||||
writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
|
writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
|
||||||
writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
||||||
|
@ -83,7 +83,7 @@ public class ResponseBodyResultHandlerTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supports() {
|
void supports() {
|
||||||
Object controller = new TestController();
|
Object controller = new TestController();
|
||||||
Method method;
|
Method method;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class ResponseBodyResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsRestController() {
|
void supportsRestController() {
|
||||||
Object controller = new TestRestController();
|
Object controller = new TestRestController();
|
||||||
Method method;
|
Method method;
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ public class ResponseBodyResultHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultOrder() {
|
void defaultOrder() {
|
||||||
assertThat(this.resultHandler.getOrder()).isEqualTo(100);
|
assertThat(this.resultHandler.getOrder()).isEqualTo(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ import static org.mockito.BDDMockito.mock;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ResponseEntityExceptionHandlerTests {
|
class ResponseEntityExceptionHandlerTests {
|
||||||
|
|
||||||
private final GlobalExceptionHandler exceptionHandler = new GlobalExceptionHandler();
|
private final GlobalExceptionHandler exceptionHandler = new GlobalExceptionHandler();
|
||||||
|
|
||||||
|
@ -110,12 +110,12 @@ public class ResponseEntityExceptionHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlerMethodValidationException() {
|
void handlerMethodValidationException() {
|
||||||
testException(new HandlerMethodValidationException(mock(MethodValidationResult.class)));
|
testException(new HandlerMethodValidationException(mock(MethodValidationResult.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void methodValidationException() {
|
void methodValidationException() {
|
||||||
MethodValidationException ex = new MethodValidationException(mock(MethodValidationResult.class));
|
MethodValidationException ex = new MethodValidationException(mock(MethodValidationResult.class));
|
||||||
ResponseEntity<?> entity = this.exceptionHandler.handleException(ex, this.exchange).block();
|
ResponseEntity<?> entity = this.exceptionHandler.handleException(ex, this.exchange).block();
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ServerWebExchangeMethodArgumentResolverTests {
|
class ServerWebExchangeMethodArgumentResolverTests {
|
||||||
|
|
||||||
private final ServerWebExchangeMethodArgumentResolver resolver =
|
private final ServerWebExchangeMethodArgumentResolver resolver =
|
||||||
new ServerWebExchangeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
new ServerWebExchangeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -57,7 +57,7 @@ public class ServerWebExchangeMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(ServerWebExchange.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(ServerWebExchange.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpRequest.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpRequest.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpResponse.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpResponse.class))).isTrue();
|
||||||
|
@ -76,7 +76,7 @@ public class ServerWebExchangeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArgument() {
|
void resolveArgument() {
|
||||||
testResolveArgument(this.testMethod.arg(ServerWebExchange.class), this.exchange);
|
testResolveArgument(this.testMethod.arg(ServerWebExchange.class), this.exchange);
|
||||||
testResolveArgument(this.testMethod.arg(ServerHttpRequest.class), this.exchange.getRequest());
|
testResolveArgument(this.testMethod.arg(ServerHttpRequest.class), this.exchange.getRequest());
|
||||||
testResolveArgument(this.testMethod.arg(ServerHttpResponse.class), this.exchange.getResponse());
|
testResolveArgument(this.testMethod.arg(ServerHttpResponse.class), this.exchange.getResponse());
|
||||||
|
@ -91,7 +91,7 @@ public class ServerWebExchangeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveUriComponentsBuilder() {
|
void resolveUriComponentsBuilder() {
|
||||||
MethodParameter param = this.testMethod.arg(UriComponentsBuilder.class);
|
MethodParameter param = this.testMethod.arg(UriComponentsBuilder.class);
|
||||||
Object value = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block();
|
Object value = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block();
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ class SessionAttributeMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@SuppressWarnings("resource")
|
|
||||||
void setup() {
|
void setup() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -34,14 +34,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* Test fixture with {@link SessionAttributesHandler}.
|
* Test fixture with {@link SessionAttributesHandler}.
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class SessionAttributesHandlerTests {
|
class SessionAttributesHandlerTests {
|
||||||
|
|
||||||
private final SessionAttributesHandler sessionAttributesHandler =
|
private final SessionAttributesHandler sessionAttributesHandler =
|
||||||
new SessionAttributesHandler(TestController.class);
|
new SessionAttributesHandler(TestController.class);
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSessionAttribute() {
|
void isSessionAttribute() {
|
||||||
assertThat(this.sessionAttributesHandler.isHandlerSessionAttribute("attr1", String.class)).isTrue();
|
assertThat(this.sessionAttributesHandler.isHandlerSessionAttribute("attr1", String.class)).isTrue();
|
||||||
assertThat(this.sessionAttributesHandler.isHandlerSessionAttribute("attr2", String.class)).isTrue();
|
assertThat(this.sessionAttributesHandler.isHandlerSessionAttribute("attr2", String.class)).isTrue();
|
||||||
assertThat(this.sessionAttributesHandler.isHandlerSessionAttribute("simple", TestBean.class)).isTrue();
|
assertThat(this.sessionAttributesHandler.isHandlerSessionAttribute("simple", TestBean.class)).isTrue();
|
||||||
|
@ -49,7 +49,7 @@ public class SessionAttributesHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retrieveAttributes() {
|
void retrieveAttributes() {
|
||||||
WebSession session = new MockWebSession();
|
WebSession session = new MockWebSession();
|
||||||
session.getAttributes().put("attr1", "value1");
|
session.getAttributes().put("attr1", "value1");
|
||||||
session.getAttributes().put("attr2", "value2");
|
session.getAttributes().put("attr2", "value2");
|
||||||
|
@ -65,7 +65,7 @@ public class SessionAttributesHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cleanupAttributes() {
|
void cleanupAttributes() {
|
||||||
WebSession session = new MockWebSession();
|
WebSession session = new MockWebSession();
|
||||||
session.getAttributes().put("attr1", "value1");
|
session.getAttributes().put("attr1", "value1");
|
||||||
session.getAttributes().put("attr2", "value2");
|
session.getAttributes().put("attr2", "value2");
|
||||||
|
@ -85,7 +85,7 @@ public class SessionAttributesHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void storeAttributes() {
|
void storeAttributes() {
|
||||||
|
|
||||||
ModelMap model = new ModelMap();
|
ModelMap model = new ModelMap();
|
||||||
model.put("attr1", "value1");
|
model.put("attr1", "value1");
|
||||||
|
|
|
@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class WebSessionMethodArgumentResolverTests {
|
class WebSessionMethodArgumentResolverTests {
|
||||||
|
|
||||||
private final WebSessionMethodArgumentResolver resolver =
|
private final WebSessionMethodArgumentResolver resolver =
|
||||||
new WebSessionMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
new WebSessionMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
|
||||||
|
@ -46,7 +46,7 @@ public class WebSessionMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsParameter() {
|
void supportsParameter() {
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(WebSession.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(WebSession.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, WebSession.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, WebSession.class))).isTrue();
|
||||||
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Single.class, WebSession.class))).isTrue();
|
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Single.class, WebSession.class))).isTrue();
|
||||||
|
@ -54,7 +54,7 @@ public class WebSessionMethodArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolverArgument() {
|
void resolverArgument() {
|
||||||
|
|
||||||
BindingContext context = new BindingContext();
|
BindingContext context = new BindingContext();
|
||||||
WebSession session = mock();
|
WebSession session = mock();
|
||||||
|
|
|
@ -44,13 +44,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class AbstractViewTests {
|
class AbstractViewTests {
|
||||||
|
|
||||||
private MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
private MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveAsyncAttributes() {
|
void resolveAsyncAttributes() {
|
||||||
|
|
||||||
TestBean testBean1 = new TestBean("Bean1");
|
TestBean testBean1 = new TestBean("Bean1");
|
||||||
TestBean testBean2 = new TestBean("Bean2");
|
TestBean testBean2 = new TestBean("Bean2");
|
||||||
|
|
|
@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class DefaultRenderingBuilderTests {
|
class DefaultRenderingBuilderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultValues() {
|
void defaultValues() {
|
||||||
Rendering rendering = Rendering.view("abc").build();
|
Rendering rendering = Rendering.view("abc").build();
|
||||||
|
|
||||||
assertThat(rendering.view()).isEqualTo("abc");
|
assertThat(rendering.view()).isEqualTo("abc");
|
||||||
|
@ -44,7 +44,7 @@ public class DefaultRenderingBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultValuesForRedirect() throws Exception {
|
void defaultValuesForRedirect() {
|
||||||
Rendering rendering = Rendering.redirectTo("abc").build();
|
Rendering rendering = Rendering.redirectTo("abc").build();
|
||||||
|
|
||||||
Object view = rendering.view();
|
Object view = rendering.view();
|
||||||
|
@ -56,13 +56,13 @@ public class DefaultRenderingBuilderTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void viewName() {
|
void viewName() {
|
||||||
Rendering rendering = Rendering.view("foo").build();
|
Rendering rendering = Rendering.view("foo").build();
|
||||||
assertThat(rendering.view()).isEqualTo("foo");
|
assertThat(rendering.view()).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttribute() throws Exception {
|
void modelAttribute() {
|
||||||
Foo foo = new Foo();
|
Foo foo = new Foo();
|
||||||
Rendering rendering = Rendering.view("foo").modelAttribute(foo).build();
|
Rendering rendering = Rendering.view("foo").modelAttribute(foo).build();
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class DefaultRenderingBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modelAttributes() throws Exception {
|
void modelAttributes() {
|
||||||
Foo foo = new Foo();
|
Foo foo = new Foo();
|
||||||
Bar bar = new Bar();
|
Bar bar = new Bar();
|
||||||
Rendering rendering = Rendering.view("foo").modelAttributes(foo, bar).build();
|
Rendering rendering = Rendering.view("foo").modelAttributes(foo, bar).build();
|
||||||
|
@ -82,7 +82,7 @@ public class DefaultRenderingBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void model() throws Exception {
|
void model() {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("foo", new Foo());
|
map.put("foo", new Foo());
|
||||||
map.put("bar", new Bar());
|
map.put("bar", new Bar());
|
||||||
|
@ -92,7 +92,7 @@ public class DefaultRenderingBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void header() throws Exception {
|
void header() {
|
||||||
Rendering rendering = Rendering.view("foo").header("foo", "bar").build();
|
Rendering rendering = Rendering.view("foo").header("foo", "bar").build();
|
||||||
|
|
||||||
assertThat(rendering.headers()).hasSize(1);
|
assertThat(rendering.headers()).hasSize(1);
|
||||||
|
@ -100,7 +100,7 @@ public class DefaultRenderingBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpHeaders() throws Exception {
|
void httpHeaders() {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.add("foo", "bar");
|
headers.add("foo", "bar");
|
||||||
Rendering rendering = Rendering.view("foo").headers(headers).build();
|
Rendering rendering = Rendering.view("foo").headers(headers).build();
|
||||||
|
@ -109,7 +109,7 @@ public class DefaultRenderingBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void redirectWithAbsoluteUrl() throws Exception {
|
void redirectWithAbsoluteUrl() {
|
||||||
Rendering rendering = Rendering.redirectTo("foo").contextRelative(false).build();
|
Rendering rendering = Rendering.redirectTo("foo").contextRelative(false).build();
|
||||||
|
|
||||||
Object view = rendering.view();
|
Object view = rendering.view();
|
||||||
|
@ -118,7 +118,7 @@ public class DefaultRenderingBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void redirectWithPropagateQuery() throws Exception {
|
void redirectWithPropagateQuery() {
|
||||||
Rendering rendering = Rendering.redirectTo("foo").propagateQuery(true).build();
|
Rendering rendering = Rendering.redirectTo("foo").propagateQuery(true).build();
|
||||||
|
|
||||||
Object view = rendering.view();
|
Object view = rendering.view();
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue