From 1055beea9208624ce98981645fa2e1c2fa4a8ddb Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Sat, 31 Oct 2020 22:34:11 +0100 Subject: [PATCH] test: Add SPARQL endpoint integration test. --- .travis.yml | 18 +++++++++++----- test/assets/person.ttl | 6 ++++++ test/configs/DataAccessorBasedConfig.ts | 3 ++- test/configs/Util.ts | 9 ++++++-- test/integration/SparqlStorage.test.ts | 28 +++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 test/assets/person.ttl create mode 100644 test/integration/SparqlStorage.test.ts diff --git a/.travis.yml b/.travis.yml index 3eb70b8b1..d52a60549 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,18 @@ language: node_js node_js: - - "10" - - "12" - - "14" - - "lts/*" - - "node" + - "10" + - "12" + - "14" + - "lts/*" + - "node" + +services: + - docker + +before_install: + # Set up SPARQL endpoint + - docker pull tenforce/virtuoso + - docker run -d -p 4000:8890 -e SPARQL_UPDATE=true tenforce/virtuoso script: - npm run lint diff --git a/test/assets/person.ttl b/test/assets/person.ttl new file mode 100644 index 000000000..5a0c53e34 --- /dev/null +++ b/test/assets/person.ttl @@ -0,0 +1,6 @@ +PREFIX : +PREFIX foaf: + +:me a foaf:Person; + foaf:name "Ruben Verborgh"@en; + foaf:homepage . diff --git a/test/configs/DataAccessorBasedConfig.ts b/test/configs/DataAccessorBasedConfig.ts index 3de1f0182..36e982188 100644 --- a/test/configs/DataAccessorBasedConfig.ts +++ b/test/configs/DataAccessorBasedConfig.ts @@ -31,10 +31,11 @@ import { export class DataAccessorBasedConfig implements ServerConfig { public store: ResourceStore; - public constructor(base: string, dataAccessor: DataAccessor) { + public constructor(base: string, dataAccessor: DataAccessor, inType?: string) { this.store = getConvertingStore( getDataAccessorStore(base, dataAccessor), [ new QuadToRdfConverter(), new RdfToQuadConverter() ], + inType, ); } diff --git a/test/configs/Util.ts b/test/configs/Util.ts index cf58a6bc3..529c2259a 100644 --- a/test/configs/Util.ts +++ b/test/configs/Util.ts @@ -75,8 +75,13 @@ export const getInMemoryResourceStore = (base = BASE): DataAccessorBasedStore => * @returns The converting store. */ export const getConvertingStore = -(store: ResourceStore, converters: RepresentationConverter[]): RepresentationConvertingStore => - new RepresentationConvertingStore(store, { outConverter: new CompositeAsyncHandler(converters) }); +(store: ResourceStore, converters: RepresentationConverter[], inType?: string): +RepresentationConvertingStore => + new RepresentationConvertingStore(store, { + inConverter: new CompositeAsyncHandler(converters), + outConverter: new CompositeAsyncHandler(converters), + inType, + }); /** * Gives a patching store based on initial store. diff --git a/test/integration/SparqlStorage.test.ts b/test/integration/SparqlStorage.test.ts new file mode 100644 index 000000000..f06e92b50 --- /dev/null +++ b/test/integration/SparqlStorage.test.ts @@ -0,0 +1,28 @@ +import { SparqlDataAccessor } from '../../src/storage/accessors/SparqlDataAccessor'; +import { UrlContainerManager } from '../../src/storage/UrlContainerManager'; +import { INTERNAL_QUADS } from '../../src/util/ContentTypes'; +import { MetadataController } from '../../src/util/MetadataController'; +import { DataAccessorBasedConfig } from '../configs/DataAccessorBasedConfig'; +import { BASE } from '../configs/Util'; +import { FileTestHelper } from '../util/TestHelpers'; + +describe('A server with a SPARQL endpoint as storage', (): void => { + describe('without acl', (): void => { + const config = new DataAccessorBasedConfig(BASE, + new SparqlDataAccessor('http://localhost:4000/sparql', + BASE, + new UrlContainerManager(BASE), + new MetadataController()), + INTERNAL_QUADS); + const handler = config.getHttpHandler(); + const fileHelper = new FileTestHelper(handler, new URL(BASE)); + + it('can add a Turtle file to the store.', async(): + Promise => { + // POST + const response = await fileHelper.createFile('../assets/person.ttl', 'person', 'text/turtle'); + const id = response._getHeaders().location; + expect(id).toBeTruthy(); + }); + }); +});