@Test
public void testDeletingSandboxedRelationships() throws Exception {
createSampleOntology();
Relationship relationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId);
String propertyThatShouldBeDeleted = SANDBOX_PROPERTY_IRI + ".relationship";
createProperty(propertyThatShouldBeDeleted, SANDBOX_DISPLAY_NAME, Arrays.asList(), Arrays.asList(relationship), workspaceId);
getOntologyRepository().clearCache(workspaceId);
relationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId);
OntologyProperty property = getOntologyRepository().getPropertyByIRI(propertyThatShouldBeDeleted, workspaceId);
assertTrue("Property exists", property != null && property.getIri().equals(propertyThatShouldBeDeleted));
assertTrue("Relationship has property", relationship.getProperties().stream().anyMatch(ontologyProperty -> ontologyProperty.getIri().equals(propertyThatShouldBeDeleted)));
getOntologyRepository().deleteRelationship(SANDBOX_RELATIONSHIP_IRI, adminUser, workspaceId);
getOntologyRepository().clearCache(workspaceId);
relationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId);
assertTrue("Relationship should have been deleted", relationship == null);
property = getOntologyRepository().getPropertyByIRI(propertyThatShouldBeDeleted, workspaceId);
assertTrue("Property only used in this relationship is deleted", property == null);
property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI, workspaceId);
assertTrue("Property used in other relationships is updated", property != null);
assertEquals(1, property.getRelationshipIris().size());
assertEquals(PUBLIC_RELATIONSHIP_IRI, property.getRelationshipIris().get(0));
}