SimpleCatalogUtilsService implements CatalogUtilsService { @Override public <T extends Version> T getVersion(Resource catalogId, Resource recordId, Resource versionId, OrmFactory<T> factory, RepositoryConnection conn) { validateVersion(catalogId, recordId, versionId, conn); return getObject(versionId, factory, 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 getVersionTest() { try (RepositoryConnection conn = repo.getConnection()) { Version version = service.getVersion(CATALOG_IRI, VERSIONED_RECORD_IRI, VERSION_IRI, versionFactory, conn); assertFalse(version.getModel().isEmpty()); assertEquals(VERSION_IRI, version.getResource()); } }
@Test public void getVersionWithMissingCatalogTest() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Catalog " + MISSING_IRI + " could not be found"); try (RepositoryConnection conn = repo.getConnection()) { service.getVersion(MISSING_IRI, VERSIONED_RECORD_IRI, VERSION_IRI, versionFactory, conn); } }
@Test public void getVersionWithMissingRecordTest() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("VersionedRecord " + MISSING_IRI + " could not be found"); try (RepositoryConnection conn = repo.getConnection()) { service.getVersion(CATALOG_IRI, MISSING_IRI, VERSION_IRI, versionFactory, conn); } }
@Test public void getVersionWithWrongCatalogTest() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(String.format("Record %s does not belong to Catalog %s", VERSIONED_RECORD_NO_CATALOG_IRI, CATALOG_IRI)); try (RepositoryConnection conn = repo.getConnection()) { service.getVersion(CATALOG_IRI, VERSIONED_RECORD_NO_CATALOG_IRI, VERSION_IRI, versionFactory, conn); } }
@Test public void getVersionWithWrongRecordTest() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(String.format("Version %s does not belong to VersionedRecord %s", LONE_VERSION_IRI, VERSIONED_RECORD_IRI)); try (RepositoryConnection conn = repo.getConnection()) { service.getVersion(CATALOG_IRI, VERSIONED_RECORD_IRI, LONE_VERSION_IRI, versionFactory, conn); } }
@Test public void getMissingVersionTest() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Version " + RANDOM_IRI + " could not be found"); try (RepositoryConnection conn = repo.getConnection()) { service.getVersion(CATALOG_IRI, VERSIONED_RECORD_MISSING_VERSION_IRI, RANDOM_IRI, versionFactory, conn); } }