static Subjects substituteSubjects(final Subjects subjects, final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm, final DittoHeaders dittoHeaders) { Subjects newSubjects = subjects; for (final Subject subject : subjects) { final String subjectId = subject.getId().toString(); final String substitutedSubjectId = substitutionAlgorithm.substitute(subjectId, dittoHeaders); if (!subjectId.equals(substitutedSubjectId)) { final Subject newSubject = Subject.newInstance(substitutedSubjectId, subject.getType()); newSubjects = newSubjects.removeSubject(subjectId).setSubject(newSubject); } } return newSubjects; }
public PolicyAssert hasSubjectTypeFor(final Label label, final SubjectId subjectId, final SubjectType expectedSubjectType) { isNotNull(); hasSubjectFor(label, subjectId); final Subject subject = actual.getEntryFor(label).get().getSubjects().getSubject(subjectId).get(); assertThat(subject.getType()).isEqualTo(expectedSubjectType) // .overridingErrorMessage( "Expected Label <%s> to contain for SubjectId <%s> SubjectType " + "\n<%s> but did not: \n<%s>", label, subjectId, expectedSubjectType, subject.getType()); return this; }
@Override public WithDittoHeaders apply(final ModifySubject modifySubject, final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm) { requireNonNull(modifySubject); requireNonNull(substitutionAlgorithm); final String subjectId = modifySubject.getSubject().getId().toString(); final String substitutedSubjectId = substitutionAlgorithm.substitute(subjectId, modifySubject); if (subjectId.equals(substitutedSubjectId)) { return modifySubject; } else { final Subject newSubject = Subject.newInstance(substitutedSubjectId, modifySubject.getSubject().getType()); return ModifySubject.of(modifySubject.getId(), modifySubject.getLabel(), newSubject, modifySubject.getDittoHeaders()); } } }