Grails
  1. Grails
  2. GRAILS-5886

Cannot mockDomain 3rd party classes that do not have a version property

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2 final
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Patch attached:
      Yes

      Description

      If I try and mock a domain class that's being imported through hibernate, (ie not using groovy/GORM to define the class), grails will throw an error if I didn't define a version property in the hibernate mapping (either annotation or xml):

      "Version property not found, but required in domain class "

      This way it's impossible to mock domain classes that are shared with another Java projects.
      A possible solution would be allowing mappings override with a Domain***Mappings.groovy (just like we define the GORM constraints).

        Activity

        Hide
        Ales Smodis added a comment -

        I have exactly the same problem (using Grails 1.3.5) with JPA-annotated Java classes instead of using native Grails domain classes. The problem essentially lies in mocking the domain classes with the org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass which throws an exception in the constructor if version or identifier properties are missing. The reason for requiring these fields is not clear to me, so I modified the source and removed the said part in the constructor. All tests pass upon rebuilding Grails, as do tests in my application now with Grails modified in this way. I'll be attaching the relevant patch.

        Show
        Ales Smodis added a comment - I have exactly the same problem (using Grails 1.3.5) with JPA-annotated Java classes instead of using native Grails domain classes. The problem essentially lies in mocking the domain classes with the org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass which throws an exception in the constructor if version or identifier properties are missing. The reason for requiring these fields is not clear to me, so I modified the source and removed the said part in the constructor. All tests pass upon rebuilding Grails, as do tests in my application now with Grails modified in this way. I'll be attaching the relevant patch.
        Hide
        Ales Smodis added a comment -

        Attached is the patch that removes from the constructor of DefaultGrailsDomainClass the requirement for the presence of version and identifier fields in domain classes. Without this externally defined domain classes (e.g. JPA-annotated classes for working with Hibernate in another Java project) that don't define the version property create problems in unit testing.

        Show
        Ales Smodis added a comment - Attached is the patch that removes from the constructor of DefaultGrailsDomainClass the requirement for the presence of version and identifier fields in domain classes. Without this externally defined domain classes (e.g. JPA-annotated classes for working with Hibernate in another Java project) that don't define the version property create problems in unit testing.
        Hide
        François Terrier added a comment -

        I can confirm that this is still the case for 1.3.7. Patch works great.

        Show
        François Terrier added a comment - I can confirm that this is still the case for 1.3.7. Patch works great.
        Hide
        James Cook added a comment -

        Is this still relevant as mockDomain has been removed in Grails 2?

        Show
        James Cook added a comment - Is this still relevant as mockDomain has been removed in Grails 2?
        Hide
        Peter Ledbrook added a comment -

        @James Since a patch has been attached and we are keeping the old testing regime to help people migrate, I think it's still relevant.

        Show
        Peter Ledbrook added a comment - @James Since a patch has been attached and we are keeping the old testing regime to help people migrate, I think it's still relevant.

          People

          • Assignee:
            Unassigned
            Reporter:
            Miguel Ping
          • Votes:
            10 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated:
              Last Reviewed:

              Development