-1
您好,我在测试期间以及在集成测试期间遇到问题。如何避免找到同一集合的两个表示
找到相同集合的两种表示形式:ClientPasswordPolicy.userCategoriesForProxyDuration;
在我的领域之一,我有以下的事情:
Map<String, String> userCategoriesForProxyDuration
由像映射:
userCategoriesForProxyDuration joinTable:
我的测试看起来像:
Client client0 = Client.findByName('client0')
UserCategory userCategory = UserCategory.build(value:'TEST_GUILHERME')
Client client = Client.build(name: 'Monkey')
ClientPasswordPolicy policy = ClientPasswordPolicy.build(client:client)
client.save(flush:true)
policy.userCategoriesForProxyDuration = ["TEST_GUILHERME":"36"]
policy.addToUserCategoriesNeedApproval(userCategory)
policy.proxyEnabled = true
policy.save(flush:true,failOnError:true,insert:true)
User user = User.build(username: "Test1", password: "password", client: client0)
Team team = Team.build(name: 'myTeamMonkey', client: client, members: [user])
ClientPasswordPolicy policy1 = ClientPasswordPolicy.build(client:Client.build(name:'Maria'),proxyApproverEmailAddress:'[email protected]')
Client client1 = Client.findByName('Maria')
Team team1 = Team.build(name: 'myTeamMaria1', client: client1, members: [user])
但在我制定第二条政策的路线是,我收到了错误,我做了一些尝试和考试如果我喜欢:
ClientPasswordPolicy.findAll()
两次在第二次将无论如何会得到错误,同样的错误。所以我害怕我不知道为什么策略没有被刷新到事务中并且事务正在持有,这就是为什么我在保存后使用刷新,即使我正在使用构建来创建我的域。
我发现有些事情就像我们做这样的事情的ClientPasswordPolicy的验证过程:
userCategoriesForProxyDuration nullable: true, validator: { approvals, object ->
if(object.proxyEnabled && !approvals) {
return ['invalid.proxy.user.category.required']
}
for (approval in approvals) {
if (!(approval.key in UserCategory.list().value)) {
return ['invalid.proxy.approval.userType']
}
try {
Integer.parseInt(approval.value)
} catch (NumberFormatException e) {
return ['invalid.proxy.approval.duration']
}
}
如果我注释掉不会有任何问题,这恐怕UserCategory.list的()是造成麻烦,但我不知道该怎么做,我试图在保存(验证:假)使用将无法正常工作。
尝试.withNewTransaction引起问题的所有位 - 所以保存并可能列出 – Vahid
我做到了这一点,工作,但减慢了我的应用很多,因为这是验证的一部分,并且通常您在保存之前验证,所以您打开一个新的事务有时GB不会在同一时间删除该事务,因此将保留在内存中 – Galeixo