approvalSessionRemote.removeApprovalRequest(admin1, next.getId());
}
public void testApprove() throws Exception {
DummyApprovalRequest nonExecutableRequest = new DummyApprovalRequest(reqadmin, null, caid, SecConst.EMPTY_ENDENTITYPROFILE, false);
approvalSessionRemote.addApprovalRequest(admin1, nonExecutableRequest, gc);
Approval approval1 = new Approval("ap1test");
approvalExecutionSessionRemote.approve(admin1, nonExecutableRequest.generateApprovalId(), approval1, gc);
Collection<ApprovalDataVO> result = approvalSessionRemote.findApprovalDataVO(admin1, nonExecutableRequest.generateApprovalId());
assertTrue(result.size() == 1);
ApprovalDataVO next = result.iterator().next();
assertTrue("Status = " + next.getStatus(), next.getStatus() == ApprovalDataVO.STATUS_WAITINGFORAPPROVAL);
assertTrue(next.getRemainingApprovals() == 1);
Approval approvalAgain = new Approval("apAgaintest");
try {
approvalExecutionSessionRemote.approve(admin1, nonExecutableRequest.generateApprovalId(), approvalAgain, gc);
fail("The same admin shouldn't be able to approve a request twice");
} catch (AdminAlreadyApprovedRequestException e) {
}
Approval approval2 = new Approval("ap2test");
approvalExecutionSessionRemote.approve(admin2, nonExecutableRequest.generateApprovalId(), approval2, gc);
result = approvalSessionRemote.findApprovalDataVO(admin1, nonExecutableRequest.generateApprovalId());
assertTrue(result.size() == 1);
next = (ApprovalDataVO) result.iterator().next();
assertTrue("Status = " + next.getStatus(), next.getStatus() == ApprovalDataVO.STATUS_APPROVED);
assertTrue(next.getRemainingApprovals() == 0);
// Test that the approval exipres as it should
Thread.sleep(5000);
result = approvalSessionRemote.findApprovalDataVO(admin1, nonExecutableRequest.generateApprovalId());
assertTrue(result.size() == 1);
next = (ApprovalDataVO) result.iterator().next();
assertTrue("Status = " + next.getStatus(), next.getStatus() == ApprovalDataVO.STATUS_EXPIRED);
approvalSessionRemote.removeApprovalRequest(admin1, next.getId());
// Test using an executable Dummy, different behaviour
DummyApprovalRequest executableRequest = new DummyApprovalRequest(reqadmin, null, caid, SecConst.EMPTY_ENDENTITYPROFILE, true);
approvalSessionRemote.addApprovalRequest(admin1, executableRequest, gc);
approvalExecutionSessionRemote.approve(admin1, nonExecutableRequest.generateApprovalId(), approval1, gc);
approvalExecutionSessionRemote.approve(admin2, nonExecutableRequest.generateApprovalId(), approval2, gc);
result = approvalSessionRemote.findApprovalDataVO(admin1, executableRequest.generateApprovalId());
assertTrue(result.size() == 1);
next = (ApprovalDataVO) result.iterator().next();
assertTrue("Status = " + next.getStatus(), next.getStatus() == ApprovalDataVO.STATUS_EXECUTED);
// Make sure that the approval still have status executed after
// exiration
Thread.sleep(5000);
result = approvalSessionRemote.findApprovalDataVO(admin1, executableRequest.generateApprovalId());
assertTrue(result.size() == 1);
next = (ApprovalDataVO) result.iterator().next();
assertTrue("Status = " + next.getStatus(), next.getStatus() == ApprovalDataVO.STATUS_EXECUTED);
approvalSessionRemote.removeApprovalRequest(admin1, next.getId());
// Test to request and to approve with the same admin
nonExecutableRequest = new DummyApprovalRequest(reqadmin, null, caid, SecConst.EMPTY_ENDENTITYPROFILE, false);
approvalSessionRemote.addApprovalRequest(admin1, nonExecutableRequest, gc);
Approval approvalUsingReqAdmin = new Approval("approvalUsingReqAdmin");
try {
approvalExecutionSessionRemote.approve(reqadmin, nonExecutableRequest.generateApprovalId(), approvalUsingReqAdmin, gc);
fail("Request admin shouln't be able to approve their own request");
} catch (AdminAlreadyApprovedRequestException e) {
}
result = approvalSessionRemote.findApprovalDataVO(admin1, executableRequest.generateApprovalId());
assertTrue(result.size() == 1);
next = (ApprovalDataVO) result.iterator().next();
approvalSessionRemote.removeApprovalRequest(admin1, next.getId());
}