OntologyRecordVersioningService extends BaseVersioningService<OntologyRecord> { @Override public void addCommit(Branch branch, Commit commit, RepositoryConnection conn) { Optional<com.mobi.rdf.api.Resource> recordOpt = getRecordIriIfMaster(branch, conn); recordOpt.ifPresent(recordId -> commit.getBaseCommit_resource().ifPresent(baseCommit -> updateOntologyIRI(recordId, commit, conn))); catalogUtils.addCommit(branch, commit, conn); }  @Override String getTypeIRI(); @Override void addCommit(Branch branch, Commit commit, RepositoryConnection conn); @Override com.mobi.rdf.api.Resource addCommit(Branch branch, User user, String message, Model additions, Model deletions,
                                               Commit baseCommit, Commit auxCommit, RepositoryConnection conn);  }
@Test public void addCommitToOtherBranchWithCommitTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { Branch newBranch = branchFactory.createNew(VALUE_FACTORY.createIRI("http: service.addCommit(newBranch, commit, conn); verify(catalogUtils).addCommit(newBranch, commit, conn); verify(catalogUtils, times(0)).getObject(record.getResource(), ontologyRecordFactory, conn); verify(catalogUtils, times(0)).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager, times(0)).ontologyIriExists(newIRI); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(record, conn); verify(ontologyCache, times(0)).clearCacheImports(any(com.mobi.rdf.api.Resource.class)); } }
@Test public void addCommitToMasterWithCommitWithNoBaseTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { service.addCommit(branch, commit, conn); verify(catalogUtils).addCommit(branch, commit, conn); verify(catalogUtils, times(0)).getAdditions(commit, conn); verify(catalogUtils, times(0)).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager, times(0)).ontologyIriExists(newIRI); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(record, conn); verify(ontologyCache, times(0)).clearCacheImports(any(com.mobi.rdf.api.Resource.class)); } }
@Test public void addCommitToMasterWithCommitWithBaseAndNewOntologyIRITest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { commit.setBaseCommit(commitFactory.createNew(VALUE_FACTORY.createIRI("http: service.addCommit(branch, commit, conn); verify(catalogUtils).addCommit(branch, commit, conn); verify(catalogUtils).getAdditions(commit, conn); verify(catalogUtils).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager).ontologyIriExists(newIRI); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(newIRI, record.getOntologyIRI().get()); verify(catalogUtils).updateObject(record, conn); verify(ontologyCache).clearCacheImports(originalIRI); verify(ontologyCache).clearCacheImports(newIRI); } }
@Test public void addCommitToMasterOfRecordWithoutIRIWithCommitWithBaseTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { commit.setBaseCommit(commitFactory.createNew(VALUE_FACTORY.createIRI("http: OntologyRecord newRecord = ontologyRecordFactory.createNew(VALUE_FACTORY.createIRI("http: when(catalogUtils.getObject(any(com.mobi.rdf.api.Resource.class), eq(ontologyRecordFactory), eq(conn))).thenReturn(newRecord); service.addCommit(branch, commit, conn); verify(catalogUtils).addCommit(branch, commit, conn); verify(catalogUtils).getAdditions(commit, conn); verify(catalogUtils).getObject(any(com.mobi.rdf.api.Resource.class), eq(ontologyRecordFactory), eq(conn)); verify(ontologyManager).ontologyIriExists(newIRI); assertTrue(newRecord.getOntologyIRI().isPresent()); assertEquals(newIRI, newRecord.getOntologyIRI().get()); verify(catalogUtils).updateObject(newRecord, conn); verify(ontologyCache).clearCacheImports(newIRI); } }
@Test public void addCommitToMasterWithCommitWithBaseAndUsedOntologyIRITest() throws Exception { commit.setBaseCommit(commitFactory.createNew(VALUE_FACTORY.createIRI("http: when(catalogUtils.getAdditions(eq(commit), any(RepositoryConnection.class))).thenReturn(additionsUsed); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Ontology already exists with IRI " + usedIRI); try (RepositoryConnection conn = repo.getConnection()) { service.addCommit(branch, commit, conn); } finally { verify(catalogUtils).getAdditions(eq(commit), any(RepositoryConnection.class)); verify(catalogUtils).getObject(eq(record.getResource()), eq(ontologyRecordFactory), any(RepositoryConnection.class)); verify(catalogUtils, times(0)).addCommit(eq(branch), eq(commit), any(RepositoryConnection.class)); verify(ontologyManager).ontologyIriExists(usedIRI); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(eq(record), any(RepositoryConnection.class)); verify(ontologyCache).clearCacheImports(originalIRI); } }
@Test public void addCommitToMasterWithCommitWithBaseAndNoIRITest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { commit.setBaseCommit(commitFactory.createNew(VALUE_FACTORY.createIRI("http: when(catalogUtils.getAdditions(commit, conn)).thenReturn(additionsNoIRI); service.addCommit(branch, commit, conn); verify(catalogUtils).addCommit(branch, commit, conn); verify(catalogUtils).getAdditions(commit, conn); verify(catalogUtils).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager, times(0)).ontologyIriExists(any(IRI.class)); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(record, conn); verify(ontologyCache).clearCacheImports(originalIRI); } }
@Test public void addCommitToOtherBranchWithChangesTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { Branch newBranch = branchFactory.createNew(VALUE_FACTORY.createIRI("http: Model additions = MODEL_FACTORY.createModel(); Model deletions = MODEL_FACTORY.createModel(); service.addCommit(newBranch, user, "Message", additions, deletions, commit, null, conn); verify(catalogManager).createInProgressCommit(user); verify(catalogManager).createCommit(inProgressCommit, "Message", commit, null); verify(catalogUtils, times(0)).getCommitChain(any(com.mobi.rdf.api.Resource.class), eq(false), eq(conn)); verify(catalogUtils, times(0)).getCompiledResource(anyListOf(com.mobi.rdf.api.Resource.class), eq(conn)); verify(catalogUtils, times(0)).applyDifference(any(Model.class), any(Difference.class)); verify(catalogUtils, times(0)).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager, times(0)).ontologyIriExists(newIRI); verify(catalogUtils).updateCommit(commit, additions, deletions, conn); verify(catalogUtils).addCommit(newBranch, commit, conn); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(record, conn); verify(ontologyCache, times(0)).clearCacheImports(any(com.mobi.rdf.api.Resource.class)); } }
@Test public void addCommitToMasterWithChangesAndNoBaseTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { Model additions = MODEL_FACTORY.createModel(); Model deletions = MODEL_FACTORY.createModel(); service.addCommit(branch, user, "Message", additions, deletions, null, null, conn); verify(catalogManager).createInProgressCommit(user); verify(catalogManager).createCommit(inProgressCommit, "Message", null, null); verify(catalogUtils, times(0)).getCommitChain(any(com.mobi.rdf.api.Resource.class), eq(false), eq(conn)); verify(catalogUtils, times(0)).getCompiledResource(anyListOf(com.mobi.rdf.api.Resource.class), eq(conn)); verify(catalogUtils, times(0)).applyDifference(any(Model.class), any(Difference.class)); verify(catalogUtils, times(0)).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager, times(0)).ontologyIriExists(newIRI); verify(catalogUtils).updateCommit(commit, additions, deletions, conn); verify(catalogUtils).addCommit(branch, commit, conn); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(record, conn); verify(ontologyCache, times(0)).clearCacheImports(any(com.mobi.rdf.api.Resource.class)); } }
@Test public void addCommitToMasterWithChangesAndBaseAndNoAuxTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { Model additionsModel = MODEL_FACTORY.createModel(additions.collect(Collectors.toSet())); Model deletions = MODEL_FACTORY.createModel(); service.addCommit(branch, user, "Message", additionsModel, deletions, commit, null, conn); verify(catalogManager).createInProgressCommit(user); verify(catalogManager).createCommit(inProgressCommit, "Message", commit, null); verify(catalogUtils, times(0)).getCommitChain(any(com.mobi.rdf.api.Resource.class), eq(false), eq(conn)); verify(catalogUtils, times(0)).getCompiledResource(anyListOf(com.mobi.rdf.api.Resource.class), eq(conn)); verify(catalogUtils).applyDifference(any(Model.class), any(Difference.class)); verify(catalogUtils).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager).ontologyIriExists(newIRI); verify(catalogUtils).updateCommit(commit, additionsModel, deletions, conn); verify(catalogUtils).addCommit(branch, commit, conn); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(newIRI, record.getOntologyIRI().get()); verify(catalogUtils).updateObject(record, conn); verify(ontologyCache).clearCacheImports(originalIRI); verify(ontologyCache).clearCacheImports(newIRI); } }
@Test public void addCommitToMasterWithChangesAndBaseAndAuxTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { Model additionsModel = MODEL_FACTORY.createModel(additions.collect(Collectors.toSet())); Model deletions = MODEL_FACTORY.createModel(); service.addCommit(branch, user, "Message", additionsModel, deletions, commit, commit, conn); verify(catalogManager).createInProgressCommit(user); verify(catalogManager).createCommit(inProgressCommit, "Message", commit, commit); verify(catalogUtils, times(2)).getCommitChain(commit.getResource(), false, conn); verify(catalogUtils).getCompiledResource(anyListOf(com.mobi.rdf.api.Resource.class), eq(conn)); verify(catalogUtils).applyDifference(any(Model.class), any(Difference.class)); verify(catalogUtils).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager).ontologyIriExists(newIRI); verify(catalogUtils).updateCommit(commit, additionsModel, deletions, conn); verify(catalogUtils).addCommit(branch, commit, conn); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(newIRI, record.getOntologyIRI().get()); verify(catalogUtils).updateObject(record, conn); verify(ontologyCache).clearCacheImports(originalIRI); verify(ontologyCache).clearCacheImports(newIRI); } }
@Test public void addCommitToMasterOfRecordWithoutIRIWithChangesAndBaseTest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { OntologyRecord newRecord = ontologyRecordFactory.createNew(VALUE_FACTORY.createIRI("http: when(catalogUtils.getObject(any(com.mobi.rdf.api.Resource.class), eq(ontologyRecordFactory), eq(conn))).thenReturn(newRecord); Model additionsModel = MODEL_FACTORY.createModel(additions.collect(Collectors.toSet())); Model deletions = MODEL_FACTORY.createModel(); service.addCommit(branch, user, "Message", additionsModel, deletions, commit, null, conn); verify(catalogManager).createInProgressCommit(user); verify(catalogManager).createCommit(inProgressCommit, "Message", commit, null); verify(catalogUtils, times(0)).getCommitChain(any(com.mobi.rdf.api.Resource.class), eq(false), eq(conn)); verify(catalogUtils, times(0)).getCompiledResource(anyListOf(com.mobi.rdf.api.Resource.class), eq(conn)); verify(catalogUtils).applyDifference(any(Model.class), any(Difference.class)); verify(catalogUtils).getObject(any(com.mobi.rdf.api.Resource.class), eq(ontologyRecordFactory), eq(conn)); verify(ontologyManager).ontologyIriExists(newIRI); verify(catalogUtils).updateCommit(commit, additionsModel, deletions, conn); verify(catalogUtils).addCommit(branch, commit, conn); assertTrue(newRecord.getOntologyIRI().isPresent()); assertEquals(newIRI, newRecord.getOntologyIRI().get()); verify(catalogUtils).updateObject(newRecord, conn); verify(ontologyCache).clearCacheImports(newIRI); } }
@Test public void addCommitToMasterWithChangesWithBaseAndUsedOntologyIRITest() throws Exception { Model additionsModel = MODEL_FACTORY.createModel(additionsUsed.collect(Collectors.toSet())); Model deletions = MODEL_FACTORY.createModel(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Ontology already exists with IRI " + usedIRI); try (RepositoryConnection conn = repo.getConnection()) { service.addCommit(branch, user, "Message", additionsModel, deletions, commit, null, conn); } finally { verify(catalogManager).createInProgressCommit(user); verify(catalogManager).createCommit(inProgressCommit, "Message", commit, null); verify(catalogUtils, times(0)).getCommitChain(any(com.mobi.rdf.api.Resource.class), eq(false), any(RepositoryConnection.class)); verify(catalogUtils, times(0)).getCompiledResource(anyListOf(com.mobi.rdf.api.Resource.class), any(RepositoryConnection.class)); verify(catalogUtils).applyDifference(any(Model.class), any(Difference.class)); verify(catalogUtils).getObject(eq(record.getResource()), eq(ontologyRecordFactory), any(RepositoryConnection.class)); verify(ontologyManager).ontologyIriExists(usedIRI); verify(catalogUtils, times(0)).updateCommit(eq(commit), eq(additionsModel), eq(deletions), any(RepositoryConnection.class)); verify(catalogUtils, times(0)).addCommit(eq(branch), eq(commit), any(RepositoryConnection.class)); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(eq(record), any(RepositoryConnection.class)); verify(ontologyCache).clearCacheImports(originalIRI); } }
@Test public void addCommitToMasterWithChangesWithBaseAndNoIRITest() throws Exception { try (RepositoryConnection conn = repo.getConnection()) { Model additionsModel = MODEL_FACTORY.createModel(additionsNoIRI.collect(Collectors.toSet())); Model deletions = MODEL_FACTORY.createModel(); service.addCommit(branch, user, "Message", additionsModel, deletions, commit, null, conn); verify(catalogManager).createInProgressCommit(user); verify(catalogManager).createCommit(inProgressCommit, "Message", commit, null); verify(catalogUtils, times(0)).getCommitChain(any(com.mobi.rdf.api.Resource.class), eq(false), eq(conn)); verify(catalogUtils, times(0)).getCompiledResource(anyListOf(com.mobi.rdf.api.Resource.class), eq(conn)); verify(catalogUtils).applyDifference(any(Model.class), any(Difference.class)); verify(catalogUtils).getObject(record.getResource(), ontologyRecordFactory, conn); verify(ontologyManager, times(0)).ontologyIriExists(newIRI); verify(catalogUtils).updateCommit(commit, additionsModel, deletions, conn); verify(catalogUtils).addCommit(branch, commit, conn); verify(ontologyManager, times(0)).ontologyIriExists(any(IRI.class)); assertTrue(record.getOntologyIRI().isPresent()); assertEquals(originalIRI, record.getOntologyIRI().get()); verify(catalogUtils, times(0)).updateObject(record, conn); verify(ontologyCache).clearCacheImports(originalIRI); } }