Grails/GORM:继承域类的行为不一致(测试 VS Bootstrap)
我发现我的应用程序的行为与继承域类的测试用例的结果不一致。以下是该问题涉及的类(仅提供部分代码)。
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
}
相关测试代码:
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
assertEquals 失败,并显示 junit.framework.AssertionFailedError: Expected:<1>;但是是:<0>
然而,同一段代码在 Bootstrap 中运行良好,相关实体甚至显示在 FacebookTicket 的列表视图中。
这是由于 GORM 测试继承域类的一些限制还是我在这里做错了什么? (Ticket 和 FacebookPost 测试工作正常。)
谢谢。
PS:请告诉我是否应该提供更多代码。
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 should provide more code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
...有类似的问题,建议将其作为集成测试而不是单元测试来处理。问题就消失了。
... had a similar problem and was advised to to handle it as an integration test as opposed to unit test. Problems went away.