import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase; //导入依赖的package包/类
@Test public void testHasApplicationRole() throws Exception {
WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "ActionRequestDerivedRoleTypeServiceImplTest");
// let's send an adhoc request to rkirkend
document.adHocToPrincipal(ActionRequestType.APPROVE, "", getPrincipalIdForName("rkirkend"), "", true);
document.route("");
DerivedRoleTypeServiceBase roleTypeService = new ActionRequestDerivedRoleTypeServiceImpl();
Map<String, String> qualifications = Collections
.singletonMap(KimConstants.AttributeConstants.DOCUMENT_NUMBER, "" + document.getDocumentId());
// rkirkend should have role as an approver
assertTrue("rkirkend should have role.", roleTypeService.hasDerivedRole(getPrincipalIdForName("rkirkend"), null, null, APPROVE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
// now verify it returns false for the non-adhoc case since we created request to rkirkend as an adhoc request
assertFalse("rkirkend should not have role for non-adhoc (since this was an adhoc request)", roleTypeService.hasDerivedRole(getPrincipalIdForName("rkirkend"), null, null, NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
// switch to bmcgough and send an acknowledge
document = TestUtilities.switchByPrincipalName("bmcgough", document);
document.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "", getPrincipalIdForName("bmcgough"), "", true);
assertTrue("bmcgough should have ack", document.isAcknowledgeRequested());
// bmcgough should not have role as an approver
assertFalse("bmcgough should not have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("bmcgough"), null, null, APPROVE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
// bmcgough should have role as an ack
assertTrue("bmcgough should have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("bmcgough"), null, null, ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
// bmcgough should not have role as an fyi
assertFalse("bmcgough should not have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("bmcgough"), null, null, FYI_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
// now approve as "rkirkend", should generate a requeest to jhopf
document = TestUtilities.switchByPrincipalName("rkirkend", document);
assertTrue(document.isApprovalRequested());
document.approve("");
// jhopf should now have approve request, not as the result of an adhoc request
document = TestUtilities.switchByPrincipalName("jhopf", document);
assertTrue(document.isApprovalRequested());
assertTrue("jhopf should have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("jhopf"), null, null, APPROVE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
assertTrue("jhopf should have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("jhopf"), null, null, NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
// send an fyi to "pmckown"
document.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("pmckown"), "", true);
document = TestUtilities.switchByPrincipalName("pmckown", document);
assertTrue(document.isFYIRequested());
assertTrue("pmckown should have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("pmckown"), null, null, FYI_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
// create a new doc and "save" as ewestfal, this should generate a "complete" request to ewestfal
document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "ActionRequestDerivedRoleTypeServiceImplTest");
document.saveDocument("");
assertTrue(document.isSaved());
assertTrue(document.isCompletionRequested());
assertTrue(document.isApprovalRequested());
// the ActionRequestDerivedRoleTypeService does not consider COMPLETE and APPROVE to be the same, let's verify that's the case
assertFalse("ewestfal should not have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("ewestfal"), null, null, APPROVE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
assertFalse("ewestfal should not have role", roleTypeService.hasDerivedRole(getPrincipalIdForName("ewestfal"), null, null, NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME, qualifications));
}
请发表评论