Skip to content

Add test for resolving RequestParam through SpEL #35303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,14 @@ void supportsParameter() {
param = this.testMethod.annotPresent(RequestPart.class).arg(MultipartFile.class);
assertThat(resolver.supportsParameter(param)).isFalse();

param = this.testMethod.annotPresent(RequestParam.class).arg(Integer.class);
param = this.testMethod.annot(requestParam().name("${systemProperty}")).arg(Integer.class);
assertThat(resolver.supportsParameter(param)).isTrue();

param = this.testMethod.annotPresent(RequestParam.class).arg(int.class);
assertThat(resolver.supportsParameter(param)).isTrue();

param = this.testMethod.annot(requestParam().name("#{'na'.concat('me')}")).arg(Integer.class);
assertThat(resolver.supportsParameter(param)).isTrue();
}

@Test
Expand Down Expand Up @@ -715,6 +718,21 @@ void notNullablePrimitiveParameterFromSystemPropertyThroughPlaceholder() {
System.clearProperty("systemProperty");
}

@Test
void resolveNameThroughSpEL() throws Exception{
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);

Integer expected = 100;
request.addParameter("name", expected.toString());

MethodParameter param = this.testMethod.annot(requestParam().name("#{'na'.concat('me')}")).arg(Integer.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result).isEqualTo(100);

}

@SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"})
public void handle(
@RequestParam(name = "name", defaultValue = "bar") String param1,
Expand All @@ -740,7 +758,9 @@ public void handle(
@RequestParam("mfile") Optional<MultipartFile> multipartFileOptional,
@RequestParam(defaultValue = "false") Boolean booleanParam,
@RequestParam("${systemProperty}") Integer placeholderParam,
@RequestParam(name = "${systemProperty}", required = false) int primitivePlaceholderParam) {
@RequestParam(name = "${systemProperty}", required = false) int primitivePlaceholderParam,
@RequestParam("#{'na'.concat('me')}") Integer spelParam
) {
}

}