SubjectAttributeResolver { public Set<Attribute> getResult(final Set<Attribute> scopes) { Set<Attribute> subjectAttributes = this.subjectAttributeMap.get(this.subjectIdentifier); if (null == subjectAttributes) { subjectAttributes = new HashSet<>( this.subjectAttributeReader.getAttributesByScope(this.subjectIdentifier, scopes)); subjectAttributes.addAll(this.supplementalSubjectAttributes); this.subjectAttributeMap.put(this.subjectIdentifier, subjectAttributes); } return subjectAttributes; } SubjectAttributeResolver(final SubjectAttributeReader subjectAttributeReader, final String subjectIdentifier,
            final Set<Attribute> supplementalSubjectAttributes); Set<Attribute> getResult(final Set<Attribute> scopes);  }
@Test public void testGetSubjectAttributesNoSubjectFoundAndNoSupplementalAttributes() { SubjectAttributeResolver resolver = new SubjectAttributeResolver(this.defaultSubjectAttributeReader, "NonExistingURI", null); Set<Attribute> combinedSubjectAttributes = resolver.getResult(null); Assert.assertTrue(combinedSubjectAttributes.isEmpty()); }
@Test public void testGetSubjectAttributesSubjectFoundWithNoAttributesAndNoSupplementalAttributes() { SubjectAttributeResolver resolver = new SubjectAttributeResolver(this.defaultSubjectAttributeReader, this.testSubject.getSubjectIdentifier(), null); Set<Attribute> combinedSubjectAttributes = resolver.getResult(null); Assert.assertTrue(combinedSubjectAttributes.isEmpty()); }
@Test public void testGetSubjectAttributesSubjectFoundWithAttributesAndNoSupplementalAttributes() { Set<Attribute> subjectAttributes = new HashSet<>(); subjectAttributes.add(new Attribute("https: this.testSubject.setAttributes(subjectAttributes); when(this.defaultSubjectAttributeReader.getAttributesByScope(eq(this.testSubject.getSubjectIdentifier()), anySetOf(Attribute.class))).thenReturn(subjectAttributes); SubjectAttributeResolver resolver = new SubjectAttributeResolver(this.defaultSubjectAttributeReader, this.testSubject.getSubjectIdentifier(), null); Set<Attribute> combinedSubjectAttributes = resolver.getResult(null); Assert.assertNotNull(combinedSubjectAttributes); Assert.assertTrue(combinedSubjectAttributes.containsAll(subjectAttributes)); }
@Test public void testGetSubjectAttributesSupplementalAttributesOnly() { Set<Attribute> supplementalSubjectAttributes = new HashSet<>(); supplementalSubjectAttributes.add(new Attribute("https: SubjectAttributeResolver resolver = new SubjectAttributeResolver(this.defaultSubjectAttributeReader, this.testSubject.getSubjectIdentifier(), supplementalSubjectAttributes); Set<Attribute> combinedSubjectAttributes = resolver.getResult(null); Assert.assertNotNull(combinedSubjectAttributes); Assert.assertTrue(combinedSubjectAttributes.containsAll(supplementalSubjectAttributes)); }
@Test public void testGetSubjectAttributes() { Set<Attribute> subjectAttributes = new HashSet<>(); subjectAttributes.add(new Attribute("https: this.testSubject.setAttributes(subjectAttributes); Set<Attribute> supplementalSubjectAttributes = new HashSet<>(); supplementalSubjectAttributes.add(new Attribute("https: when(this.defaultSubjectAttributeReader.getAttributesByScope(eq(this.testSubject.getSubjectIdentifier()), anySetOf(Attribute.class))).thenReturn(subjectAttributes); SubjectAttributeResolver resolver = new SubjectAttributeResolver(this.defaultSubjectAttributeReader, this.testSubject.getSubjectIdentifier(), supplementalSubjectAttributes); Set<Attribute> combinedSubjectAttributes = resolver.getResult(null); Assert.assertNotNull(combinedSubjectAttributes); Assert.assertTrue(combinedSubjectAttributes.containsAll(subjectAttributes)); Assert.assertTrue(combinedSubjectAttributes.containsAll(supplementalSubjectAttributes)); }