You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Okay I finally found some time to look into this.
You're indeed correct that the error seems to stem from the MockMvcWebClientBuilder from Spring. To be honest I'm not to familiar with the MockMvcWebClientBuilder. The problem seems to be what we're seeing here:
The FormData / RequestBody is not correctly put in to the @RequestParam parameters in the Controller.
Therefore the request fails with 400 Bad Request.
I'm having some difficulties debugging the Spring test code ... however I think the issue comes from HtmlUnitRequestBuilder.content():
This one takes the request body without any escaping and passes it to the controller:
private void content(MockHttpServletRequest request, Charset charset) {
String requestBody = this.webRequest.getRequestBody();
if (requestBody == null) {
return;
}
request.setContent(requestBody.getBytes(charset)); //requestBody = 'subject test message test'
//requestBody should be: 'subject=subject+test&message=message+test' since it's form encoded.
}
To get to the results I've transformed the project to use SpringBoot since it was easier for me to find out what's actually happening and where the error potentially is. I hope that it's running with gradle ... since I needed to convert it to a maven project because of my gradle issue 👼
Okay I finally found some time to look into this.
You're indeed correct that the error seems to stem from the
MockMvcWebClientBuilder
from Spring. To be honest I'm not to familiar with theMockMvcWebClientBuilder
. The problem seems to be what we're seeing here:The FormData / RequestBody is not correctly put in to the
@RequestParam
parameters in the Controller.Therefore the request fails with
400 Bad Request
.I'm having some difficulties debugging the Spring test code ... however I think the issue comes from
HtmlUnitRequestBuilder.content()
:This one takes the request body without any escaping and passes it to the controller:
To get to the results I've transformed the project to use SpringBoot since it was easier for me to find out what's actually happening and where the error potentially is. I hope that it's running with gradle ... since I needed to convert it to a maven project because of my gradle issue 👼
The project is here: https://github.com/twendelmuth/spring-test-htmlunit
Added tests that should illustrate what's wrong: https://github.com/twendelmuth/spring-test-htmlunit/tree/master/src/test/java/spring/test/htmlunit/controller
And more specific: https://github.com/twendelmuth/spring-test-htmlunit/blob/master/src/test/java/spring/test/htmlunit/controller/WelcomeControllerMockMvc.java#L37 - this is what's happening in the end in your test.
I hope this helps :-)
Originally posted by @twendelmuth in #223 (comment)
The text was updated successfully, but these errors were encountered: