Grails
  1. Grails
  2. GRAILS-8493

Domain class with ID that is using UUID generation does not work with @Mock in service class

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-RC3
    • Fix Version/s: 2.0 final
    • Component/s: Testing
    • Labels:
      None
    • Environment:
      Mac OS X 10.6
      Java 6

      Description

      Given a domain class that has an ID with UUID generation turned on:

      class MyDomain {
        String id
        String desc
        static mapping = {
          id generator: 'uuid'
        }
      }
      

      When I attempt to mock multiple instances of the domain class:

      new MyDomain(desc: "One").save(flush: true)
      new MyDomain(desc: "Two").save(flush: true)
      new MyDomain(desc: "Three").save(flush: true)
      new MyDomain(desc: "Four").save(flush: true)
      

      Then when I attempt see the count of domain objects in test I see:

      assert MyDomain.count() == 4
      

      with result: 1 and failed assertion.

      Then I check on each domain object to see what is it's ID and all of them have an ID of 1 after creation. It seems that the domain objects that are created do not have an appropriate generated ID and instead try to update the first domain object created. When I look at the 'desc' attribute after saving all 4 of them:

      assert MyDomain.findAll().get(0).desc == "One"
      

      The result is that the 'desc' attribute actually equals "Four", the last value to be saved.

      The expected behavior is that I save 4 instances of MyDomain and that each has its own ID value even when UUID generation is turned on in the MyDomain mapping.

        Activity

        Hide
        Chris Sterling added a comment -

        Is there an ETA on version 2.0.1 release. Of course, I saw that 2.0 GA just got out today so I am sure it will be a bit. Is there a workaround that I can use in the meantime?

        Show
        Chris Sterling added a comment - Is there an ETA on version 2.0.1 release. Of course, I saw that 2.0 GA just got out today so I am sure it will be a bit. Is there a workaround that I can use in the meantime?
        Hide
        Graeme Rocher added a comment -

        This seems to already work in 2.0 final

        Show
        Graeme Rocher added a comment - This seems to already work in 2.0 final

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Chris Sterling
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development