@Test(expected = VisalloAccessDeniedException.class) public void testExceptionWhenDeletingPublicConcepts() throws Exception { createSampleOntology(); getOntologyRepository().deleteConcept(PUBLIC_CONCEPT_IRI, user, null); }
@Test(expected = VisalloAccessDeniedException.class) public void testExceptionWhenDeletingSandboxedConceptsAsNonAdmin() throws Exception { createSampleOntology(); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, user, workspaceId); }
@Test public void testExceptionDeletingSandboxedConceptsWithRelationshipsRange() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); // Add an edge type List<Concept> things = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, things, Arrays.asList(concept), "sandboxed-relationship-withsandboxed-concepts", true, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete concept that is used in domain/range of relationship"); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); }
@Test public void testExceptionDeletingSandboxedConceptsWithRelationshipsDomain() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); // Add an edge type List<Concept> things = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, Arrays.asList(concept), things, "sandboxed-relationship-withsandboxed-concepts", true, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete concept that is used in domain/range of relationship"); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); }
@Test public void testDeletingSandboxedConcepts() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); assertTrue("Concept exists", concept != null && concept.getIRI().equals(SANDBOX_CONCEPT_IRI)); OntologyProperty property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT, workspaceId); assertTrue("Property exists", property != null && property.getIri().equals(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT)); assertTrue("Concept has property", concept.getProperties().stream().anyMatch(ontologyProperty -> ontologyProperty.getIri().equals(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT))); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); assertTrue("Concept should have been deleted", concept == null); property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT, workspaceId); assertTrue("Property only used in this concept is deleted", property == null); property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI, workspaceId); assertTrue("Property used in other concepts is updated", property != null); assertEquals(1, property.getConceptIris().size()); assertEquals(PUBLIC_CONCEPT_IRI, property.getConceptIris().get(0)); }
@Test public void testExceptionDeletingSandboxedConceptsWithDescendants() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); // Add a descendant getOntologyRepository().getOrCreateConcept(concept, SANDBOX_CONCEPT_IRI + "child", SANDBOX_DISPLAY_NAME, null, systemUser, workspaceId); getOntologyRepository().clearCache(workspaceId); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete concept that have children"); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); }
@Test public void testExceptionDeletingSandboxedConceptsWithVertices() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); assertTrue("Concept exists", concept != null && concept.getIRI().equals(SANDBOX_CONCEPT_IRI)); VisibilityJson json = VisibilityJson.updateVisibilitySourceAndAddWorkspaceId(new VisibilityJson(), "", workspaceId); Visibility visibility = getVisibilityTranslator().toVisibility(json).getVisibility(); VertexBuilder vb = getGraph().prepareVertex(visibility); vb.setProperty(VisalloProperties.CONCEPT_TYPE.getPropertyName(), SANDBOX_CONCEPT_IRI, visibility); vb.save(authorizations); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete concept that have vertices assigned to it"); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); }