开发者

Grails/GORM: inconsistent behavior for inherited domain classes (Testing VS Bootstrap)

开发者 https://www.devze.com 2023-04-11 16:49 出处:网络
I am seeing an inconsistency in the behavior of my application VS the outcome of a test-case that I have for an inherited domain class. Here are the classes involved in the issue (only part of code pr

I am seeing an inconsistency in the behavior of my application VS the outcome of a test-case that I have for an inherited domain class. Here are the classes involved in the issue (only part of code provided).

class Ticket {
    String title
    String description
    Date dateCreated
    Date lastUpdated
    User postedBy
}

class FacebookTicket extends Ticket {
    FacebookPost facebookPost
}

class FacebookPost {
    String postId
    String message
    String postedById
    String postedByName
    Date createdOnFacebook
    Date lastUpdatedOnFacebook
}

Relevant test code:

def facebookPost1 = new FacebookPost(postId:"12345", message:"This post should become a ticket", postedById:"09876",postedByName:"Rowz Roller", createdOnFacebook: new Date(), lastUpdatedOnFacebook: new Date())

facebookPost1.save(flush:true)

def facebookTicket1 = new FacebookTicket (title:"Facebook Ticket1",description:"First FACEBOOK ticket here",postedBy:user1,facebookPost: facebookPost1)

mockForConstraintsTests(FacebookTicket, [facebookTicket1])

assertTrue facebookTicket1.validate() //Succeeds

assertNotNull(facebookTicket1.save()) //Succeeds

def instances = FacebookTicket.list()
assertEquals 1,instances.size() //Fails

The assertEquals fails with junit.framework.AssertionFailedError: expected:<1> but was:<0>

However, the same piece of code works fine in Bootstrap and the relevant entity even shows up in the list view for FacebookTicket.

Is this due to some limitation for GORM testing w.r.t. inherited domain classes or am I doing something wrong here? (The Ticket and FacebookPost tests work fine.)

Thank you.

PS: Please let me know if I shoul开发者_Python百科d provide more code.


... had a similar problem and was advised to to handle it as an integration test as opposed to unit test. Problems went away.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号