Grails
  1. Grails
  2. GRAILS-7713

Cascading validation does not work in unit tests using @Mock

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.4-M1
    • Fix Version/s: 2.3-RC1
    • Component/s: Persistence, Testing
    • Labels:
      None
    • Testcase included:
      yes

      Description

      The validate() method on a mocked domain class instance does not fail when there is an invalid property on an embedded or associated object.

      See attached project.

        Activity

        Hide
        Robert Fletcher added a comment -

        Updated test app showing working integration test w/hibernate for comparison with failing unit test

        Show
        Robert Fletcher added a comment - Updated test app showing working integration test w/hibernate for comparison with failing unit test
        Hide
        Tomasz Kalkosinski added a comment -

        You should add @Mock([Person,Address]) annotation in unit tests, but it still fails.

        Show
        Tomasz Kalkosinski added a comment - You should add @Mock( [Person,Address] ) annotation in unit tests, but it still fails.
        Hide
        Damir Murat added a comment -

        Any chance this one can be taken into account? It still doesn't work with grails 2.0.0, 2.0.1 and 2.1.0.

        Show
        Damir Murat added a comment - Any chance this one can be taken into account? It still doesn't work with grails 2.0.0, 2.0.1 and 2.1.0.
        Hide
        Damir Murat added a comment -

        If it is of any help, it seems that problem is in org.grails.datastore.gorm.GormValidationApi which calls a validator without checking if it is a cascading validator and, consequently, without setting cascade parameter to true.

        Show
        Damir Murat added a comment - If it is of any help, it seems that problem is in org.grails.datastore.gorm.GormValidationApi which calls a validator without checking if it is a cascading validator and, consequently, without setting cascade parameter to true.
        Hide
        Marcin Erdmann added a comment -

        Pull request with a fix is available in grails-data-mapping: https://github.com/SpringSource/grails-data-mapping/pull/42

        Show
        Marcin Erdmann added a comment - Pull request with a fix is available in grails-data-mapping: https://github.com/SpringSource/grails-data-mapping/pull/42
        Hide
        John Murdoch added a comment - - edited

        As a workaround: it works for me if I add mockForConstraintsTests(DomainClass) to my test method.

        Show
        John Murdoch added a comment - - edited As a workaround: it works for me if I add mockForConstraintsTests(DomainClass) to my test method.
        Hide
        Graeme Rocher added a comment -

        the pull request has been merged some time ago.

        Show
        Graeme Rocher added a comment - the pull request has been merged some time ago.

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Robert Fletcher
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development