Home How do I mock this object with composite id in Grails 2.4.5?
Reply: 0

How do I mock this object with composite id in Grails 2.4.5?

user1108
1#
user1108 Published in May 23, 2018, 10:40 pm
import groovy.transform.EqualsAndHashCode

@EqualsAndHashCode(includes = ['action', 'reason'])
class MyObject implements Serializable {
    String action
    String reason
    String description

    static mapping = {
        table name: "my_object"
        version false
        id composite: ["action", "reason"], generator: 'assigned'

        cache usage: "read-only"

        action column: "prog_action_c"
        reason column: "prog_reason_c"
        description column: "descr_c"
    }
}

I tried to this mock this object in my unit tests as below :

.....
def setup() {
..
    mockDomain(MyObject,[
          [
            action : 'ACT1',
            reason : 'REAS1',
            description : 'First reason'
          ],
          [
            action : 'ACT2',
            reason : 'REAS2',
            description : 'Second reason'
          ]
     ])

     def myObject = MyObject.first()

}
...

When I queried the object with findAll() or first() I get empty list or null

How should this object be mocked?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307898 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO