GraphResourceRepository extends GraphGenericRepository<ResourceEntity> implements ResourceRepository, ResourceHierarchicalRepository { @Override public Set<String> getResourceEntityAndDescendantsIds(final ResourceEntity entity) { return getEntityAndDescendantsIds(entity); }  @Override ResourceEntity getByZoneAndResourceIdentifier(final ZoneEntity zone, final String resourceIdentifier); @Override ResourceEntity getResourceWithInheritedAttributes(final ZoneEntity zone, final String resourceIdentifier); @Override Set<String> getResourceEntityAndDescendantsIds(final ResourceEntity 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 RESOURCE_LABEL; static final String RESOURCE_ID_KEY; }
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT, invocationCount = CONCURRENT_TEST_INVOCATIONS) public void testGetResourceEntityAndDescendantsIds() { ResourceEntity basement = persistResourceToZoneAndAssert(TEST_ZONE_1, BASEMENT_SITE_ID + getRandomNumber(), BASEMENT_ATTRIBUTES); ResourceEntity drive = persistResourceWithParentsToZoneAndAssert(TEST_ZONE_1, DRIVE_ID + getRandomNumber(), DRIVE_ATTRIBUTES, new HashSet<>(Collections.singletonList(new Parent(basement.getResourceIdentifier())))); ResourceEntity ascension = persistResourceWithParentsToZoneAndAssert(TEST_ZONE_1, ASCENSION_ID + getRandomNumber(), ASCENSION_ATTRIBUTES, new HashSet<>(Collections.singletonList(new Parent(basement.getResourceIdentifier())))); ResourceEntity implant = persistResourceWithParentsToZoneAndAssert(TEST_ZONE_1, EVIDENCE_IMPLANT_ID + getRandomNumber(), EVIDENCE_IMPLANT_ATTRIBUTES, new HashSet<>( Arrays.asList(new Parent(drive.getResourceIdentifier()), new Parent(ascension.getResourceIdentifier())))); ResourceEntity scullysTestimony = persistResourceWithParentsToZoneAndAssert(TEST_ZONE_1, EVIDENCE_SCULLYS_TESTIMONY_ID + getRandomNumber(), SCULLYS_TESTIMONY_ATTRIBUTES, new HashSet<>(Collections.singletonList(new Parent(ascension.getResourceIdentifier())))); Set<String> descendantsIds = this.resourceRepository.getResourceEntityAndDescendantsIds(basement); assertThat(descendantsIds, hasSize(5)); assertThat(descendantsIds, hasItems(basement.getResourceIdentifier(), drive. getResourceIdentifier(), ascension.getResourceIdentifier(), implant.getResourceIdentifier(), scullysTestimony.getResourceIdentifier())); descendantsIds = this.resourceRepository.getResourceEntityAndDescendantsIds(ascension); assertThat(descendantsIds, hasSize(3)); assertThat(descendantsIds, hasItems(ascension.getResourceIdentifier(), implant. getResourceIdentifier(), scullysTestimony.getResourceIdentifier())); descendantsIds = this.resourceRepository.getResourceEntityAndDescendantsIds(drive); assertThat(descendantsIds, hasSize(2)); assertThat(descendantsIds, hasItems(drive.getResourceIdentifier(), implant. getResourceIdentifier())); descendantsIds = this.resourceRepository.getResourceEntityAndDescendantsIds(implant); assertThat(descendantsIds, hasSize(1)); assertThat(descendantsIds, hasItems(implant.getResourceIdentifier())); descendantsIds = this.resourceRepository.getResourceEntityAndDescendantsIds(scullysTestimony); assertThat(descendantsIds, hasSize(1)); assertThat(descendantsIds, hasItems(scullysTestimony.getResourceIdentifier())); descendantsIds = this.resourceRepository.getResourceEntityAndDescendantsIds(null); assertThat(descendantsIds, empty()); descendantsIds = this.resourceRepository.getResourceEntityAndDescendantsIds(new ResourceEntity(TEST_ZONE_1, "/nonexistent-resource")); assertThat(descendantsIds, empty()); deleteThreeLevelEntityAndParents(basement, TEST_ZONE_1, this.resourceRepository); }