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

        Robert Fletcher created issue -
        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
        Robert Fletcher made changes -
        Field Original Value New Value
        Attachment validation-cascade.tar.gz [ 16617 ]
        Robert Fletcher made changes -
        Attachment validation-cascade.tar.gz [ 16616 ]
        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.
        Burt Beckwith made changes -
        Workflow jira [ 39784 ] Grails [ 41514 ]
        Burt Beckwith made changes -
        Workflow Grails [ 41514 ] Copy of Grails [ 48939 ]
        Burt Beckwith made changes -
        Workflow Copy of Grails [ 48939 ] Grails [ 56349 ]
        Burt Beckwith made changes -
        Workflow Grails [ 56349 ] Grails2 [ 63883 ]
        Burt Beckwith made changes -
        Workflow Grails2 [ 63883 ] jira [ 77777 ]
        Burt Beckwith made changes -
        Workflow jira [ 77777 ] Grails2 [ 86105 ]
        Peter Ledbrook made changes -
        Last Reviewed 01/Jan/10
        Peter Ledbrook made changes -
        Workflow Grails2 [ 86105 ] jira [ 94487 ]
        Peter Ledbrook made changes -
        Workflow jira [ 94487 ] Grails2 [ 102633 ]
        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.
        Graeme Rocher made changes -
        Fix Version/s 2.0.2 [ 13064 ]
        Priority Major [ 3 ] Critical [ 2 ]
        Graeme Rocher made changes -
        Assignee Graeme Rocher [ graemerocher ]
        Graeme Rocher made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Graeme Rocher made changes -
        Fix Version/s 2.0.3 [ 13094 ]
        Fix Version/s 2.0.2 [ 13064 ]
        Graeme Rocher made changes -
        Fix Version/s 2.0.4 [ 13099 ]
        Fix Version/s 2.0.3 [ 13094 ]
        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
        Jeff Scott Brown made changes -
        Fix Version/s 2.2 [ 13093 ]
        Fix Version/s 2.0.4 [ 13099 ]
        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.
        Graeme Rocher made changes -
        Fix Version/s 2.3 [ 13311 ]
        Fix Version/s 2.2-RC1 [ 13093 ]
        Graeme Rocher made changes -
        Fix Version/s 2.3-M2 [ 13457 ]
        Fix Version/s 2.3-M1 [ 13311 ]
        Graeme Rocher made changes -
        Fix Version/s 2.3-RC1 [ 13458 ]
        Fix Version/s 2.3-M2 [ 13457 ]
        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.
        Graeme Rocher made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]

          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