First and foremost, that test is in the wrong class, resource tests need to be separated from controller tests, resource tests test structure of a resource i.e the representation where as controller tests test behavior i.e CRUD operations and they should extend different base classes, please take a look at resource and controller tests in the web services module for examples and try to follow the same.
The tests fails because of the call that fetches the GP on line 167 and that’s in core so you can’t really fix it, it triggers a premature hibernate flush that tries to save the changes on the Obs to the DB which leads to the exception you’re running into, this is when hibernate can frustrate you but that’s how it works, I believe this will be addressed as part of the efforts to support saving a complex obs via rest so that we turn off auto commit when saving an Obs.
You are correct about the unit tests. Please note that they represented an intermediate commit to highlight (and reproduce) the issue, and were not meant to stay.
I have got rid of my custom resource extending ObsResource* in exchange of another completely custom resource to work on and around complex obs in the context of VDUI: VisitDocumentResource. This was necessary for reasons outside of this thread and makes more sense from a design standpoint.
Although the 2.x-related parts of my module now depend on the latest EMR API (1.9-SNAPSHOT) in order to include the fix for EA-107, “Editing some fields on Obs is not allowed” Error because of hibernate auto flush due to other hibernate call ; the problem still does not go away.
I just pulled again the latest distro 2.5 and upgraded EMR API to 1.19-SNAPSHOT (in order to benefit from DbSessionUtil), and, despite having the above fix implemented on my 2.0-compatible resource, the problem came back!
… with a more precise error message though:
Editing some fields [comment] on Obs is not allowed
I mean a post like in postVisitDocument_shouldUpdateObsComment but dealing with a complex obs in the exact way like what you are doing in the running app.
The test helper class just reproduces what is actually done when you run the app.
There is no REST end point to post a complex obs within VDUI, for instance this is the actual line that does it in the controller that is used to create them:
Switching module versions in the reference application can be very problematic since module dependencies can get complex, why do you have to do it? If you wish to use a snapshot version of any module in the RA, in most cases it is easier to take a snapshot build of the distro itself instead of just replacing a single module with a snapshot version.
The snapshot build that I used yesterday depends on EMR API 1.18 that does not contain DbSessionUtil. Hence the need to swap it for EMR API 1.19-SNAPSHOT.
@dkayiwa, have you had a chance to look into this?
Because they are about to release a new version of the RA, the module versions are not snapshots but in most cases they are, so this is kind of an awkward situation.