I'm trying to test a controller for a subclass in Grails 2.4.3. domain model is like this:
abstract class Task { ... }
class SubTask extends Task { ... }
When trying to run generated tests for class SubTaskController, 3 of 7 tests fail:
- save
- update
- delete
It seems that (at least) the id of the domain class is not initialized, though I defined this in the populateValidParams() method. The debugger shows two (!) generated id attributes on the subTaskInstance object, both null. When I set the id's to some long value in the debugger, the error at least comes a few lines later. Is there a bug in mocking subclasses or am I doing something fundamentally wrong?
I also tried it without "abstract" in the base class, but got same errors. The generated tests work fine for objects not in an inheritance hierarchy.
When I additionally set the id attribute directly in the test code, tests fail at the
SubTask.count() == 1 assertion. Seems that the persistence layer mock does not handle subclasses.
populateValidParamsis not adding necessary request parameters. See the project linked in my answer below. - Jeff Scott Brown