GraphSubjectRepository extends GraphGenericRepository<SubjectEntity> implements SubjectRepository, SubjectHierarchicalRepository { @Override public SubjectEntity getSubjectWithInheritedAttributesForScopes(final ZoneEntity zone, final String subjectIdentifier, final Set<Attribute> scopes) { return getEntityWithInheritedAttributes(zone, subjectIdentifier, scopes); }  @Override SubjectEntity getByZoneAndSubjectIdentifier(final ZoneEntity zone, final String subjectIdentifier); @Override SubjectEntity getSubjectWithInheritedAttributes(final ZoneEntity zone, final String subjectIdentifier); @Override SubjectEntity getSubjectWithInheritedAttributesForScopes(final ZoneEntity zone,
            final String subjectIdentifier, final Set<Attribute> scopes); @Override Set<String> getSubjectEntityAndDescendantsIds(final SubjectEntity entity); @Override List<S> findAll(final Example<S> example); @Override List<S> findAll(final Example<S> example, final Sort sort); @Override S findOne(final Example<S> example); @Override Page<S> findAll(final Example<S> example, final Pageable pageable); @Override long count(final Example<S> example); @Override boolean exists(final Example<S> example); static final String SUBJECT_LABEL; static final String SUBJECT_ID_KEY; }
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT, invocationCount = CONCURRENT_TEST_INVOCATIONS) public void testGetByZoneAndSubjectIdentifierAndScopes() { SubjectEntity expectedSubject = persistScopedHierarchy(AGENT_MULDER + getRandomNumber(), SITE_BASEMENT); String subjectIdentifier = expectedSubject.getSubjectIdentifier(); HashSet<Attribute> expectedAttributes = new HashSet<>( Arrays.asList(SECRET_CLASSIFICATION, TOP_SECRET_CLASSIFICATION, SITE_BASEMENT)); expectedSubject.setAttributes(expectedAttributes); expectedSubject.setAttributesAsJson(JSON_UTILS.serialize(expectedAttributes)); SubjectEntity actualSubject = this.subjectRepository .getSubjectWithInheritedAttributesForScopes(TEST_ZONE_1, subjectIdentifier, new HashSet<>(Collections.singletonList(SITE_BASEMENT))); assertThat(actualSubject, equalTo(expectedSubject)); expectedAttributes = new HashSet<>(Arrays.asList(SECRET_CLASSIFICATION, SITE_BASEMENT)); expectedSubject.setAttributes(expectedAttributes); expectedSubject.setAttributesAsJson(JSON_UTILS.serialize(expectedAttributes)); actualSubject = this.subjectRepository .getSubjectWithInheritedAttributesForScopes(TEST_ZONE_1, subjectIdentifier, new HashSet<>(Collections.singletonList(SITE_PENTAGON))); assertThat(actualSubject, equalTo(expectedSubject)); GraphResourceRepositoryTest .deleteTwoLevelEntityAndParents(expectedSubject, TEST_ZONE_1, this.subjectRepository); }
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT, invocationCount = CONCURRENT_TEST_INVOCATIONS) public void testParentAndChildSameAttribute() { SubjectEntity agentScully = new SubjectEntity(TEST_ZONE_1, AGENT_SCULLY + getRandomNumber()); agentScully.setAttributes(MULDERS_ATTRIBUTES); agentScully.setAttributesAsJson(JSON_UTILS.serialize(agentScully.getAttributes())); saveWithRetry(agentScully, 3); SubjectEntity agentMulder = new SubjectEntity(TEST_ZONE_1, AGENT_MULDER + getRandomNumber()); agentMulder.setAttributes(MULDERS_ATTRIBUTES); agentMulder.setAttributesAsJson(JSON_UTILS.serialize(agentMulder.getAttributes())); agentMulder .setParents(new HashSet<>(Collections.singletonList(new Parent(agentScully.getSubjectIdentifier())))); saveWithRetry(agentMulder, 3); SubjectEntity actualAgentMulder = this.subjectRepository .getSubjectWithInheritedAttributesForScopes(TEST_ZONE_1, agentMulder.getSubjectIdentifier(), null); assertThat(actualAgentMulder.getAttributesAsJson(), equalTo("[{\"issuer\":\"acs.example.org\",\"name\":\"site\",\"value\":\"basement\"}]")); GraphResourceRepositoryTest.deleteTwoLevelEntityAndParents(agentScully, TEST_ZONE_1, this.subjectRepository); }
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT, invocationCount = CONCURRENT_TEST_INVOCATIONS) public void testParentAndChildAttributeSameNameDifferentValues() { SubjectEntity agentScully = new SubjectEntity(TEST_ZONE_1, AGENT_SCULLY + getRandomNumber()); agentScully.setAttributes(PENTAGON_ATTRIBUTES); agentScully.setAttributesAsJson(JSON_UTILS.serialize(agentScully.getAttributes())); saveWithRetry(agentScully, 3); SubjectEntity agentMulder = new SubjectEntity(TEST_ZONE_1, AGENT_MULDER + getRandomNumber()); agentMulder.setAttributes(MULDERS_ATTRIBUTES); agentMulder.setAttributesAsJson(JSON_UTILS.serialize(agentMulder.getAttributes())); agentMulder .setParents(new HashSet<>(Collections.singletonList(new Parent(agentScully.getSubjectIdentifier())))); saveWithRetry(agentMulder, 3); SubjectEntity actualAgentMulder = this.subjectRepository .getSubjectWithInheritedAttributesForScopes(TEST_ZONE_1, agentMulder.getSubjectIdentifier(), null); assertThat(actualAgentMulder.getAttributesAsJson(), equalTo("[{\"issuer\":\"acs.example.org\",\"name\":\"site\",\"value\":\"basement\"}," + "{\"issuer\":\"acs.example.org\",\"name\":\"site\",\"value\":\"pentagon\"}]")); GraphResourceRepositoryTest.deleteTwoLevelEntityAndParents(agentScully, TEST_ZONE_1, this.subjectRepository); }