GraphResourceRepository extends GraphGenericRepository<ResourceEntity> implements ResourceRepository, ResourceHierarchicalRepository { @Override public <S extends ResourceEntity> long count(final Example<S> example) { throw new UnsupportedOperationException(MESSAGE); }  @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 public void testCount() { dropAllResources(); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(0)); persistRandomResourcetoZone1AndAssert(); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(1)); persistResource2toZone1AndAssert(); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(2)); assertThat(this.resourceRepository.count(), equalTo(2L)); dropAllResources(); }
@Test public void testPreventEntityParentCyclicReference() { dropAllResources(); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(0)); ResourceEntity resource1 = persistResource0toZone1AndAssert(); ResourceEntity resource2 = new ResourceEntity(TEST_ZONE_1, DRIVE_ID); resource2.setAttributes(DRIVE_ATTRIBUTES); resource2.setAttributesAsJson(JSON_UTILS.serialize(resource2.getAttributes())); resource2.setParents(new HashSet<>(Collections.singletonList(new Parent(resource1.getResourceIdentifier())))); this.resourceRepository.save(resource2); ResourceEntity resource3 = new ResourceEntity(TEST_ZONE_1, EVIDENCE_IMPLANT_ID); resource3.setAttributes(EVIDENCE_IMPLANT_ATTRIBUTES); resource3.setAttributesAsJson(JSON_UTILS.serialize(resource3.getAttributes())); resource3.setParents(new HashSet<>(Collections.singletonList(new Parent(resource2.getResourceIdentifier())))); this.resourceRepository.save(resource3); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(3)); resource1.setParents(new HashSet<>(Collections.singletonList(new Parent(resource3.getResourceIdentifier())))); try { this.resourceRepository.save(resource1); } catch (SchemaViolationException ex) { assertThat(ex.getMessage(), equalTo("Updating entity '/site/basement' with parent '/evidence/implant' introduces a cyclic " + "reference.")); return; } Assert.fail("save() did not throw the expected exception."); dropAllResources(); }
@Test public void testSaveResourceWithNonexistentParent() { this.dropAllResources(); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(0)); ResourceEntity resource = new ResourceEntity(TEST_ZONE_1, DRIVE_ID); resource.setParents(new HashSet<>(Collections.singletonList(new Parent(BASEMENT_SITE_ID)))); try { this.resourceRepository.save(resource); } catch (IllegalStateException ex) { assertThat(ex.getMessage(), equalTo("No parent exists in zone 'testzone1' with 'resourceId' value of '/site/basement'.")); return; } Assert.fail("save() did not throw the expected IllegalStateException exception."); }
@Test public void testVersion() { this.dropAllResources(); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(0)); assertThat(this.resourceRepository.checkVersionVertexExists(1), equalTo(false)); this.resourceRepository.createVersionVertex(1); assertThat(this.resourceRepository.checkVersionVertexExists(1), equalTo(true)); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(1)); this.resourceRepository.createVersionVertex(2); assertThat(this.graphTraversalSource.V().count().next().intValue(), equalTo(2)); dropAllResources(); }