0
我要写一个JUnit来检查版本是否被维护(在一个事件上)。下面是我使用的是什么JUnit的:如何为使用envers的代码创建Junit?
@Test
Public void testAudit() {
try {
//create Dao code
dao.save(); //This will create entry in AUD- and REVINFO-tables perfectly
SomeObject obj = SomeHelper.getAuditData(dao));
/*Method to be tested which generates audit message using envers i.e(dao created)*/
//Some logic to check if output is as expected
}
catch(Exception e) {
Assert.fail();
}
finally {
dao.delete(); //delete the data saved by JUnit (Problem starts here)
}
}
调用删除DAO将导致
UnsupportedOperationException异常:无法写入只读对象
我使用了Ehcache缓存。我搜索了这个问题,并且知道这可能是因为CacheConcurrencyStrategy
错误地为我想要删除的域对象设置的。我检查了。
对于域对象,没有CacheConcurrencyStrategy
。但嵌套对象有CacheConcurrencyStrategy
设为READ_WRITE
(这可能是真正的罪魁祸首)。
但我不想更改现有的域和现有的代码。对于JUnit,有什么办法可以绕过CacheConcurrencyStrategy
?如果没有,有没有可能的出路而不改变现有的代码?
您应该向我们展示引发异常的位置,删除操作是什么?为什么ch是你的堆栈跟踪? – Matteo 2012-07-30 21:54:55
你是否尝试删除Envers条目?如果您想删除审计数据,也许只是试图清空修订表。 – adamw 2012-08-01 06:07:10