SimpleCatalogUtilsService implements CatalogUtilsService { @Override public void updateCommit(Commit commit, Model additions, Model deletions, RepositoryConnection conn) { Resource resource = commit.getGenerated_resource().stream().findFirst() .orElseThrow(() -> new IllegalArgumentException("Commit does not have a Revision.")); Revision revision = revisionFactory.getExisting(resource, commit.getModel()) .orElseThrow(() -> new IllegalStateException("Could not retrieve expected Revision.")); updateCommit(commit.getResource(), revision, additions, deletions, conn); }  @Override void validateResource(Resource resource, IRI classId, RepositoryConnection conn); @Override void addObject(T object, RepositoryConnection conn); @Override void updateObject(T object, RepositoryConnection conn); @Override Optional<T> optObject(Resource id, OrmFactory<T> factory, RepositoryConnection conn); @Override T getObject(Resource id, OrmFactory<T> factory, RepositoryConnection conn); @Override T getExpectedObject(Resource id, OrmFactory<T> factory, RepositoryConnection conn); @Override void remove(Resource resourceId, RepositoryConnection conn); @Override void removeObject(T object, RepositoryConnection conn); @Override void removeObjectWithRelationship(Resource objectId, Resource removeFromId, String predicate,
                                             RepositoryConnection conn); @Override void validateRecord(Resource catalogId, Resource recordId, IRI recordType,
                               RepositoryConnection conn); @Override T getRecord(Resource catalogId, Resource recordId,
                                          OrmFactory<T> factory,
                                          RepositoryConnection conn); @Override void validateUnversionedDistribution(Resource catalogId, Resource recordId,
                                                Resource distributionId, RepositoryConnection conn); @Override Distribution getUnversionedDistribution(Resource catalogId, Resource recordId, Resource distributionId,
                                                   RepositoryConnection conn); @Override void validateVersion(Resource catalogId, Resource recordId, Resource versionId, RepositoryConnection conn); @Override T getVersion(Resource catalogId, Resource recordId, Resource versionId,
                                            OrmFactory<T> factory, RepositoryConnection conn); @Override void removeVersion(Resource recordId, Version version, RepositoryConnection conn); @Override void removeVersion(Resource recordId, Resource versionId, RepositoryConnection conn); @Override void validateVersionedDistribution(Resource catalogId, Resource recordId, Resource versionId,
                                              Resource distributionId, RepositoryConnection conn); @Override Distribution getVersionedDistribution(Resource catalogId, Resource recordId, Resource versionId,
                                                 Resource distributionId, RepositoryConnection conn); @Override void validateBranch(Resource catalogId, Resource recordId, Resource branchId, RepositoryConnection conn); @Override T getBranch(Resource catalogId, Resource recordId, Resource branchId,
                                          OrmFactory<T> factory, RepositoryConnection conn); @Override T getBranch(VersionedRDFRecord record, Resource branchId, OrmFactory<T> factory,
                                          RepositoryConnection conn); @Override List<Resource> removeBranch(Resource recordId, Resource branchId, RepositoryConnection conn); @Override void removeBranch(Resource recordId, Resource branchId, List<Resource> deletedCommits,
                             RepositoryConnection conn); @Override List<Resource> removeBranch(Resource recordId, Branch branch, RepositoryConnection conn); @Override Resource getHeadCommitIRI(Branch branch); @Override void validateInProgressCommit(Resource catalogId, Resource recordId, Resource commitId,
                                         RepositoryConnection conn); @Override InProgressCommit getInProgressCommit(Resource recordId, Resource userId, RepositoryConnection conn); @Override InProgressCommit getInProgressCommit(Resource catalogId, Resource recordId, Resource commitId,
                                                RepositoryConnection conn); @Override Optional<Resource> getInProgressCommitIRI(Resource recordId, Resource userId, RepositoryConnection conn); @Override void removeInProgressCommit(InProgressCommit commit, RepositoryConnection conn); @Override void updateCommit(Commit commit, Model additions, Model deletions, RepositoryConnection conn); @Override void updateCommit(Resource commitId, Model additions, Model deletions, RepositoryConnection conn); @Override void addCommit(Branch branch, Commit commit, RepositoryConnection conn); @Override Revision getRevision(Resource commitId, RepositoryConnection conn); @Override Stream<Statement> getAdditions(Resource commitId, RepositoryConnection conn); @Override Stream<Statement> getAdditions(Commit commit, RepositoryConnection conn); @Override Stream<Statement> getDeletions(Resource commitId, RepositoryConnection conn); @Override Stream<Statement> getDeletions(Commit commit, RepositoryConnection conn); @Override void addChanges(Resource targetNamedGraph, Resource oppositeNamedGraph, Model changes,
                           RepositoryConnection conn); @Override void validateCommitPath(Resource catalogId, Resource recordId, Resource branchId, Resource commitId,
                                   RepositoryConnection conn); @Override void validateCommitPath(Resource catalogId, Resource recordId, Resource commitId,
                                   RepositoryConnection conn); @Override boolean commitInBranch(Resource branchId, Resource commitId, RepositoryConnection conn); @Override boolean commitInRecord(Resource recordId, Resource commitId, RepositoryConnection conn); @Override List<Resource> getCommitChain(Resource commitId, boolean asc, RepositoryConnection conn); @Override List<Resource> getCommitChain(Resource commitId, Resource entityId, boolean asc, RepositoryConnection conn); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final RepositoryConnection conn); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final RepositoryConnection conn, boolean asc); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final Resource targetEntityId, final RepositoryConnection conn); @Override List<Resource> getDifferenceChain(final Resource sourceCommitId, final Resource targetCommitId,
                                             final Resource targetEntityId, final RepositoryConnection conn,
                                             boolean asc); @Override Difference getCommitDifference(List<Resource> commits, RepositoryConnection conn); @Override Difference getCommitDifference(Resource commitId, RepositoryConnection conn); @Override Model getCompiledResource(Resource commitId, RepositoryConnection conn); @Override Model getCompiledResource(List<Resource> commits, RepositoryConnection conn); @Override Difference getRevisionChanges(Resource commitId, RepositoryConnection conn); @Override Model applyDifference(Model base, Difference diff); @Override Set<Conflict> getConflicts(Resource sourceCommitId, Resource targetCommitId, RepositoryConnection conn); @Override IllegalArgumentException throwAlreadyExists(Resource id, OrmFactory<T> factory); @Override IllegalArgumentException throwDoesNotBelong(Resource child,
                                                                                          OrmFactory<T> childFactory,
                                                                                          Resource parent,
                                                                                          OrmFactory<S> parentFactory); @Override IllegalStateException throwThingNotFound(Resource id, OrmFactory<T> factory);  }
@Test public void updateCommitWithCommitWithoutAdditionsSetTest() { try (RepositoryConnection conn = repo.getConnection()) { Commit commit = getThing(COMMIT_NO_ADDITIONS_IRI, commitFactory, conn); thrown.expect(IllegalStateException.class); thrown.expectMessage("Additions not set on Commit " + COMMIT_NO_ADDITIONS_IRI); service.updateCommit(commit, MODEL_FACTORY.createModel(), MODEL_FACTORY.createModel(), conn); } }
@Test public void updateCommitWithCommitWithoutDeletionsSetTest() { try (RepositoryConnection conn = repo.getConnection()) { Commit commit = getThing(COMMIT_NO_DELETIONS_IRI, commitFactory, conn); thrown.expect(IllegalStateException.class); thrown.expectMessage("Deletions not set on Commit " + COMMIT_NO_DELETIONS_IRI); service.updateCommit(commit, MODEL_FACTORY.createModel(), MODEL_FACTORY.createModel(), conn); } }
@Test public void updateCommitWithCommitAndQuadsTest() { try (RepositoryConnection conn = repo.getConnection()) { Commit commit = getThing(VALUE_FACTORY.createIRI(COMMITS + "quad-test1"), commitFactory, conn); Resource graph1 = VALUE_FACTORY.createIRI(GRAPHS + "quad-graph1"); Resource graphTest = VALUE_FACTORY.createIRI(GRAPHS + "quad-graph-test"); Statement addQuad = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("https: Statement addAndDeleteQuad = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("https: Statement deleteQuad = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("https: Statement existingAddQuad = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("http: Model additions = MODEL_FACTORY.createModel(Stream.of(addQuad, addAndDeleteQuad).collect(Collectors.toSet())); Model deletions = MODEL_FACTORY.createModel(Stream.of(addAndDeleteQuad, deleteQuad, existingAddQuad).collect(Collectors.toSet())); Resource additionsGraph = VALUE_FACTORY.createIRI(Catalogs.ADDITIONS_NAMESPACE + "quad-test1"); Resource deletionsGraph = VALUE_FACTORY.createIRI(Catalogs.DELETIONS_NAMESPACE + "quad-test1"); Statement expAdd1 = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("http: Statement expDel1 = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("http: Resource additionsGraph1 = VALUE_FACTORY.createIRI(Catalogs.ADDITIONS_NAMESPACE + "quad-test1%00http%3A%2F%2Fmobi.com%2Ftest%2Fgraphs%23quad-graph1"); Resource deletionsGraph1 = VALUE_FACTORY.createIRI(Catalogs.DELETIONS_NAMESPACE + "quad-test1%00http%3A%2F%2Fmobi.com%2Ftest%2Fgraphs%23quad-graph1"); Statement expAddGraph1 = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("http: Statement expDelGraph1 = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("https: Resource additionsGraphTest = VALUE_FACTORY.createIRI(Catalogs.ADDITIONS_NAMESPACE + "quad-test1%00http%3A%2F%2Fmobi.com%2Ftest%2Fgraphs%23quad-graph-test"); Resource deletionsGraphTest = VALUE_FACTORY.createIRI(Catalogs.DELETIONS_NAMESPACE + "quad-test1%00http%3A%2F%2Fmobi.com%2Ftest%2Fgraphs%23quad-graph-test"); Statement expAddGraphTest = VALUE_FACTORY.createStatement(VALUE_FACTORY.createIRI("https: service.updateCommit(commit, additions, deletions, conn); List<Statement> adds = RepositoryResults.asList(conn.getStatements(null, null, null, additionsGraph)); assertEquals(1, adds.size()); assertTrue(adds.contains(expAdd1)); List<Statement> dels = RepositoryResults.asList(conn.getStatements(null, null, null, deletionsGraph)); assertEquals(1, dels.size()); assertTrue(dels.contains(expDel1)); List<Statement> addsGraph1 = RepositoryResults.asList(conn.getStatements(null, null, null, additionsGraph1)); assertEquals(1, addsGraph1.size()); assertTrue(addsGraph1.contains(expAddGraph1)); List<Statement> delsGraph1 = RepositoryResults.asList(conn.getStatements(null, null, null, deletionsGraph1)); assertEquals(1, delsGraph1.size()); assertTrue(delsGraph1.contains(expDelGraph1)); List<Statement> addsGraphTest = RepositoryResults.asList(conn.getStatements(null, null, null, additionsGraphTest)); assertEquals(1, addsGraphTest.size()); assertTrue(addsGraphTest.contains(expAddGraphTest)); List<Statement> delsGraphTest = RepositoryResults.asList(conn.getStatements(null, null, null, deletionsGraphTest)); assertEquals(0, delsGraphTest.size()); } }
@Test public void updateCommitWithResourceWithoutAdditionsSetTest() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Additions not set on Commit " + COMMIT_NO_ADDITIONS_IRI); try (RepositoryConnection conn = repo.getConnection()) { service.updateCommit(COMMIT_NO_ADDITIONS_IRI, MODEL_FACTORY.createModel(), MODEL_FACTORY.createModel(), conn); } }
@Test public void updateCommitWithResourceWithoutDeletionsSetTest() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Deletions not set on Commit " + COMMIT_NO_DELETIONS_IRI); try (RepositoryConnection conn = repo.getConnection()) { service.updateCommit(COMMIT_NO_DELETIONS_IRI, MODEL_FACTORY.createModel(), MODEL_FACTORY.createModel(), conn); } }