Skip to content

Unit testing a controller with gson views no longer includes the json response after grails 4.0.5. #11791

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
tircnf opened this issue Apr 28, 2021 · 2 comments

Comments

@tircnf
Copy link

tircnf commented Apr 28, 2021

When unit testing a controller using grails 4.0.4 and 4.0.5, the result of a controller that renders a gson view shows up in the response object.
That is no longer the case for versions 4.0.6 through 4.0.10.

The unit testing framework also has different behavior of how the model object is populated in a unit test.
In grails 4.0.4 and 4.0.5, the model object is not filled out when the controller action uses "respond".
in grails 4.0.10, the model object is populated.

I think that grails 4.0.4 has an issue where the model object is populated incorrectly, and that grails 4.0.10 has an issue where the gson view isn't rendered properly. (and maybe these are related).

Task List

  • [*] Steps to reproduce provided
  • [*] Stacktrace (if present) provided
  • [*] Example that reproduces the problem uploaded to Github
  • [*] Full description of the issue provided (see below)

Steps to Reproduce

  1. create a grails 4.0.4 app: curl -O https://start.grails.org/gson.zip -d version=4.0.4 -d profile=rest-api
  2. add a simple controller that responds with a map. (twiddle UrlMappings to you can call this method).
  3. Create a simple gson view for the controller action.
  4. Add a unit test that examines the model and the response.json.
  5. upgrade to grails 4.0.10 (modify gradle.properties to use grails 4.0.10 and gorm 7.0.8-release).
  6. run your tests again.

Expected Behaviour

That both the response.json (and response.text) get populated, as well as the model variable.

Actual Behaviour

response.text and response.json don't get populated for grails 4.0.10.
model doesn't get populated in grails 4.0.4.

Environment Information

  • Operating System: windows
  • Grails Version: 4.0.4 vs 4.0.10
  • JDK Version: 1.8
  • Container Version (If Applicable): NA

Example Application

[email protected]:tircnf/gsonTesting.git

This example application has two branches. the "main" branch is grails 4.0.4 and contains 6 unit tests.
3 that pass and 3 that fail.

The "grails4010" branch was upgraded to grails 4.0.10. Running the tests on that branch cause the failing tests to pass and the passing tests to fail.

@puneetbehl
Copy link
Contributor

Relates to grails/grails-testing-support/issues/65

@tircnf
Copy link
Author

tircnf commented Jul 26, 2021

@puneetbehl --the unit tests I describe are running, the result data just isn't getting set properly.
Any chance you marked this "relates to" on the wrong ticket?

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

No branches or pull requests

2 participants