private void executeDeputyLimitationsTest(String TEST_NAME, List<OtherPrivilegesLimitationType> expectedLimitations,
Consumer<AssignmentType> assignmentModifier) throws CommonException {
TestUtil.displayTestTitle(this, TEST_NAME);
AssignmentType assignment = new AssignmentType()
.targetRef(USER_JACK_OID, UserType.COMPLEX_TYPE, SchemaConstants.ORG_DEPUTY);
if (assignmentModifier != null) {
assignmentModifier.accept(assignment);
}
UserType deputy = prismContext.createObjectable(UserType.class)
.name("deputy")
.oid("deputy")
.assignment(assignment);
TestUtil.displayWhen(TEST_NAME);
display("Logging in as", deputy);
login(deputy.asPrismObject());
TestUtil.displayThen(TEST_NAME);
MidPointPrincipal principal = securityContextManager.getPrincipal();
Collection<DelegatorWithOtherPrivilegesLimitations> delegators = principal.getDelegatorWithOtherPrivilegesLimitationsCollection();
display("delegators with other privileges limitations", delegators);
if (expectedLimitations == null) {
assertEquals("Wrong # of delegator records: " + DebugUtil.debugDump(delegators), 0, delegators.size());
} else {
assertEquals("Wrong # of delegator records: " + DebugUtil.debugDump(delegators), 1, delegators.size());
DelegatorWithOtherPrivilegesLimitations record = delegators.iterator().next();
assertEquals("Unexpected limitations: " + DebugUtil.debugDump(delegators), new HashSet<>(expectedLimitations), new HashSet<>(record.getLimitations()));
}
}