Skip to content
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

MockRestRequestMatchers should have matchers for form data [SPR-13044] #17636

Closed
spring-projects-issues opened this issue May 18, 2015 · 3 comments
Assignees
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 18, 2015

John Mark opened SPR-13044 and commented

RestTemplate makes it easy to POST application/x-www-form-urlencoded data using a MultiValueMap. The problem I am having is that there is no easy way to test this.

MockRestRequestMatchers has jsonPath and xpath matchers, but nothing to match form data. Currently, the only way to verify the form data would be to manually assemble the expected string, but that is clumsy and can be error prone, and can break if the order of parameters changes.


Affects: 4.2.4

Issue Links:

Referenced from: commits 1416c2a

2 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

In the end those end up as request parameters on the server side. Have you considered or tried simply adding parameters via MockHttpServletRequestBuilder#param?

@spring-projects-issues
Copy link
Collaborator Author

John Mark commented

This ticket is referring to client-side REST testing. MockHttpServletRequestBuilder is for server-side testing. MockRestRequestMatchers is used for client-side testing and does have any functionality for testing request parameters.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Okay, right. A formData(MultiValueMap) method in ContentRequestMatchers would be nice to have. It might be as simple as using FromHttpMessageConverter to read the body into an MultiValueMap and comparing against the expected MultiValueMap. If you have any inclination to experiment, feel free to send a PR. We are just ahead of 4.2 RC1 in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants