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

Add JSON content and JsonPath options to WebTestClient [SPR-15420] #19981

Closed
spring-projects-issues opened this issue Apr 7, 2017 · 5 comments
Closed

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

Logan Mauzaize opened SPR-15420 and commented

When using WebFlux, Spring Boot doesn't support natively MockMvc autoconfiguration with SpringBootTest.

Thus, you need to test against WebTestClient but it doesn't provide all features of MockMvc API. As example, JSON support :


Affects: 5.0 M5

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

Rossen Stoyanchev commented

Unlike MockMvc which is a server-side testing API, the WebTestClient is an actual client and has the same features as WebClient including deserialization. It's easy to convert the output to a specific Object, a List of Object's, a Map of Object's, or a stream/Flux of Object's. This makes the JSON content and JsonPath options less crucial than they are with MockMvc.

That said the plan is to support JsonPath still, so I will turn this into a request to add JSON content and JsonPath support.

Loading

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

Logan Mauzaize commented

So WebFlux have lost test features as it doesn't have equivalence for MockMvc ...

Can you suggest a "standard" way to use JsonExpectationsHelper with WebTestClient ?

Loading

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

Rossen Stoyanchev commented

I don't know what you mean by "standard" but for the time being you can get the response body as a String:

EntityExchangeResult<String> result = client.get().uri("/path")
		.exchange()
		.expectStatus().isOk()
		.expectBody(String.class).value().returnResult();

// Use JsonExpectationsHelper directly on result.getResponseBody()

Loading

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

Logan Mauzaize commented

by "standard" I mean convenient, or least weird :)

I was wondering the best way to deal with body content.

Loading

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

Rossen Stoyanchev commented

Okay that's what I thought but wasn't sure .. :)

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants