GraphSubjectRepository extends GraphGenericRepository<SubjectEntity> implements SubjectRepository, SubjectHierarchicalRepository { @Override public Set<String> getSubjectEntityAndDescendantsIds(final SubjectEntity entity) { return getEntityAndDescendantsIds(entity); }  @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 testGetSubjectEntityAndDescendantsIds() { SubjectEntity fbi = persistSubjectToZoneAndAssert(TEST_ZONE_1, FBI + getRandomNumber(), FBI_ATTRIBUTES); SubjectEntity specialAgentsGroup = persistSubjectWithParentsToZoneAndAssert(TEST_ZONE_1, SPECIAL_AGENTS_GROUP + getRandomNumber(), SPECIAL_AGENTS_GROUP_ATTRIBUTES, new HashSet<>(Collections.singletonList(new Parent(fbi.getSubjectIdentifier())))); SubjectEntity topSecretGroup = persistSubjectToZoneAndAssert(TEST_ZONE_1, TOP_SECRET_GROUP + getRandomNumber(), TOP_SECRET_GROUP_ATTRIBUTES); SubjectEntity agentMulder = persistSubjectWithParentsToZoneAndAssert(TEST_ZONE_1, AGENT_MULDER + getRandomNumber(), MULDERS_ATTRIBUTES, new HashSet<>( Arrays.asList(new Parent(specialAgentsGroup.getSubjectIdentifier()), new Parent(topSecretGroup.getSubjectIdentifier())))); Set<String> descendantsIds = this.subjectRepository.getSubjectEntityAndDescendantsIds(fbi); assertThat(descendantsIds, hasSize(3)); assertThat(descendantsIds, hasItems(fbi.getSubjectIdentifier(), specialAgentsGroup.getSubjectIdentifier(), agentMulder.getSubjectIdentifier())); descendantsIds = this.subjectRepository.getSubjectEntityAndDescendantsIds(specialAgentsGroup); assertThat(descendantsIds, hasSize(2)); assertThat(descendantsIds, hasItems(specialAgentsGroup.getSubjectIdentifier(), agentMulder.getSubjectIdentifier())); descendantsIds = this.subjectRepository.getSubjectEntityAndDescendantsIds(topSecretGroup); assertThat(descendantsIds, hasSize(2)); assertThat(descendantsIds, hasItems(topSecretGroup.getSubjectIdentifier(), agentMulder.getSubjectIdentifier())); descendantsIds = this.subjectRepository.getSubjectEntityAndDescendantsIds(agentMulder); assertThat(descendantsIds, hasSize(1)); assertThat(descendantsIds, hasItems(agentMulder.getSubjectIdentifier())); descendantsIds = this.subjectRepository.getSubjectEntityAndDescendantsIds(null); assertThat(descendantsIds, empty()); descendantsIds = this.subjectRepository .getSubjectEntityAndDescendantsIds(new SubjectEntity(TEST_ZONE_1, "/nonexistent-subject")); assertThat(descendantsIds, empty()); GraphResourceRepositoryTest.deleteTwoLevelEntityAndParents(agentMulder, TEST_ZONE_1, this.subjectRepository); }