-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Unable to test simple Controller with JSON Body #7877
Comments
Thanks for the report. I'll take a look at this now. |
Hi @Abrasha, if you add type annotations into your test you can sort of see what's happening: val request: Request[AnyContentAsJson] = FakeRequest()
.withJsonBody(Json.toJson(person))
.withHeaders(CONTENT_TYPE -> JSON)
val acceptAction: Action[JsValue] = homeController.accept
val response: Accumulator[ByteString, Result] = acceptAction.apply(request)
assert(status(response) === CREATED) The problem is that When you call The fix is to make a val request: Request[AnyContentAsJson] = FakeRequest()
.withBody(Json.toJson(person)) // <--- change here
.withHeaders(CONTENT_TYPE -> JSON)
val acceptAction: Action[JsValue] = homeController.accept
val response: Future[Result] = acceptAction.apply(request) // <-- different type here
assert(status(response) === CREATED) The alternative fix is to use an By the way, I realise this is very confusing but unfortunately it's too hard to change Play to make it less confusing. There are several design issues coming together here:
I'm going to close this ticket now because it works as designed and we unfortunately can't change the design! |
@richdougherty Thank you for your explanation, you save me a lot of time :) |
This is one of my pet hates about Play, the overloading semantics are insane and poorly documented. |
I'm having a similar problem, but I'm intentionally using a custom parser. I need the body to be the exact string literal that came in because I have to sign the body, and so the content must be string identical to what the source sent so it can be signed and match the original signature. I would like to test, but I'm also getting the empty message. How do I send the write ByteString to the Accumulator? |
Are you looking for help?
No
Play Version
2.6.5
API
Scala
Operating System
MacOS:
JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)
Library Dependencies
Expected Behavior
Actual Behavior
Reproducible Test Case
Please, find the following repository to reproduce the issue:
https://github.com/Abrasha/playframework-issue-example
The text was updated successfully, but these errors were encountered: