Browse Source

Resolve TODO: Add test for expression resolution with ServerWebExchange

Add resolveWithServerWebExchange() test method to verify that @Value
expression resolution works correctly when a ServerWebExchange is provided.
The test creates a custom MockServerWebExchange with request headers and
attributes, then confirms that expressions are properly resolved in the
presence of the exchange context.

This resolves the TODO at line 96 and ensures the resolver functions
correctly in reactive WebFlux contexts with ServerWebExchange instances.

Signed-off-by: albonidrizi <albonidrizi@gmail.com>
pull/36016/head
albonidrizi 5 days ago
parent
commit
de3483c5aa
  1. 28
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java

28
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java

@ -48,6 +48,7 @@ class ExpressionValueMethodArgumentResolverTests { @@ -48,6 +48,7 @@ class ExpressionValueMethodArgumentResolverTests {
private MethodParameter paramSystemProperty;
private MethodParameter paramNotSupported;
private MethodParameter paramAlsoNotSupported;
private MethodParameter paramWithExchange;
@BeforeEach
@ -61,6 +62,7 @@ class ExpressionValueMethodArgumentResolverTests { @@ -61,6 +62,7 @@ class ExpressionValueMethodArgumentResolverTests {
this.paramSystemProperty = new MethodParameter(method, 0);
this.paramNotSupported = new MethodParameter(method, 1);
this.paramAlsoNotSupported = new MethodParameter(method, 2);
this.paramWithExchange = new MethodParameter(method, 3);
}
@ -93,14 +95,36 @@ class ExpressionValueMethodArgumentResolverTests { @@ -93,14 +95,36 @@ class ExpressionValueMethodArgumentResolverTests {
}
// TODO: test with expression for ServerWebExchange
@Test
void resolveWithServerWebExchange() {
System.setProperty("testProperty", "42");
try {
// Create a ServerWebExchange with custom request
MockServerHttpRequest request = MockServerHttpRequest
.get("/test-path")
.header("X-Test-Header", "test-value")
.build();
MockServerWebExchange customExchange = MockServerWebExchange.from(request);
customExchange.getAttributes().put("testAttribute", "attributeValue");
Mono<Object> mono = this.resolver.resolveArgument(
this.paramWithExchange, new BindingContext(), customExchange);
Object value = mono.block();
assertThat(value).isEqualTo(42);
}
finally {
System.clearProperty("testProperty");
}
}
@SuppressWarnings("unused")
public void params(
@Value("#{systemProperties.systemProperty}") int param1,
String notSupported,
@Value("#{systemProperties.foo}") Mono<String> alsoNotSupported) {
@Value("#{systemProperties.foo}") Mono<String> alsoNotSupported,
@Value("#{systemProperties.testProperty}") int param4) {
}
}

Loading…
Cancel
Save