test: Add SPARQL endpoint integration test.

This commit is contained in:
Ruben Verborgh 2020-10-31 22:34:11 +01:00 committed by Joachim Van Herwegen
parent 17d774fc18
commit 1055beea92
5 changed files with 56 additions and 8 deletions

View File

@ -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

6
test/assets/person.ttl Normal file
View File

@ -0,0 +1,6 @@
PREFIX : <https://ruben.verborgh.org/profile/#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
:me a foaf:Person;
foaf:name "Ruben Verborgh"@en;
foaf:homepage <https://ruben.verborgh.org/>.

View File

@ -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,
);
}

View File

@ -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.

View File

@ -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<void> => {
// POST
const response = await fileHelper.createFile('../assets/person.ttl', 'person', 'text/turtle');
const id = response._getHeaders().location;
expect(id).toBeTruthy();
});
});
});