@Test public void shouldReturnTrueIfRnrStatusIsAuthorizedAndUserHasApproveRightForSupervisoryNode() { RequisitionPermissionService requisitionPermissionServiceSpy = spy(requisitionPermissionService); final RoleAssignment approverRoleAssignment = new RoleAssignment(userId, 2l, 3l, new SupervisoryNode(5l)); when(roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, userId)).thenReturn(new ArrayList<RoleAssignment>() {{ add(approverRoleAssignment); }}); Rnr rnr = make(a(RequisitionBuilder.defaultRequisition, with(status, AUTHORIZED))); rnr.setSupervisoryNodeId(5l); assertThat(requisitionPermissionServiceSpy.hasPermissionToSave(userId, rnr), is(true)); }
public boolean hasPermissionToSave(Long userId, Rnr rnr) { return (rnr.getStatus() == INITIATED && hasPermission(userId, rnr, CREATE_REQUISITION)) || (rnr.getStatus() == SUBMITTED && hasPermission(userId, rnr, AUTHORIZE_REQUISITION)) || (rnr.getStatus() == AUTHORIZED && hasPermissionToApprove(userId, rnr)) || (rnr.getStatus() == IN_APPROVAL && hasPermissionToApprove(userId, rnr)); }
RequisitionPermissionService { public boolean hasPermissionToSave(Long userId, Rnr rnr) { return (rnr.getStatus() == INITIATED && hasPermission(userId, rnr, CREATE_REQUISITION)) || (rnr.getStatus() == SUBMITTED && hasPermission(userId, rnr, AUTHORIZE_REQUISITION)) || (rnr.getStatus() == AUTHORIZED && hasPermissionToApprove(userId, rnr)) || (rnr.getStatus() == IN_APPROVAL && hasPermissionToApprove(userId, rnr)); } }
RequisitionPermissionService { public boolean hasPermissionToSave(Long userId, Rnr rnr) { return (rnr.getStatus() == INITIATED && hasPermission(userId, rnr, CREATE_REQUISITION)) || (rnr.getStatus() == SUBMITTED && hasPermission(userId, rnr, AUTHORIZE_REQUISITION)) || (rnr.getStatus() == AUTHORIZED && hasPermissionToApprove(userId, rnr)) || (rnr.getStatus() == IN_APPROVAL && hasPermissionToApprove(userId, rnr)); }  }
RequisitionPermissionService { public boolean hasPermissionToSave(Long userId, Rnr rnr) { return (rnr.getStatus() == INITIATED && hasPermission(userId, rnr, CREATE_REQUISITION)) || (rnr.getStatus() == SUBMITTED && hasPermission(userId, rnr, AUTHORIZE_REQUISITION)) || (rnr.getStatus() == AUTHORIZED && hasPermissionToApprove(userId, rnr)) || (rnr.getStatus() == IN_APPROVAL && hasPermissionToApprove(userId, rnr)); }  Boolean hasPermission(Long userId, Facility facility, Program program, String rightName); Boolean hasPermission(Long userId, Rnr rnr, String rightName); boolean hasPermissionToSave(Long userId, Rnr rnr); boolean hasPermission(Long userId, String rightName); }
RequisitionPermissionService { public boolean hasPermissionToSave(Long userId, Rnr rnr) { return (rnr.getStatus() == INITIATED && hasPermission(userId, rnr, CREATE_REQUISITION)) || (rnr.getStatus() == SUBMITTED && hasPermission(userId, rnr, AUTHORIZE_REQUISITION)) || (rnr.getStatus() == AUTHORIZED && hasPermissionToApprove(userId, rnr)) || (rnr.getStatus() == IN_APPROVAL && hasPermissionToApprove(userId, rnr)); }  Boolean hasPermission(Long userId, Facility facility, Program program, String rightName); Boolean hasPermission(Long userId, Rnr rnr, String rightName); boolean hasPermissionToSave(Long userId, Rnr rnr); boolean hasPermission(Long userId, String rightName);  }