Commit 946d8c23 authored by Petter Goksøyr Åsen's avatar Petter Goksøyr Åsen
Browse files

services: fix most tests

parent c313f6dd
......@@ -6,10 +6,12 @@ import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.update.UpdateAction;
import org.apache.jena.update.UpdateRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static no.deichman.services.entity.repository.SPARQLQueryBuilder.DEFAULT_GRAPH;
/**
* Responsibility: Implement an in-memory RDF-repository.
......@@ -25,20 +27,21 @@ public final class InMemoryRepository extends RDFRepositoryBase {
private InMemoryRepository(SPARQLQueryBuilder sqb, UniqueURIGenerator uriGenerator) {
super(sqb, uriGenerator);
model = DatasetFactory.create();
model.addNamedModel(DEFAULT_GRAPH, ModelFactory.createDefaultModel());
LOG.info("In-memory repository started.");
}
public void addData(Model newData){
model.getDefaultModel().add(newData);
model.getNamedModel(DEFAULT_GRAPH).add(newData);
}
public Model getModel() {
return model.getDefaultModel();
return model.getNamedModel(DEFAULT_GRAPH);
}
@Override
protected QueryExecution getQueryExecution(Query query) {
return QueryExecutionFactory.create(query, model);
return QueryExecutionFactory.create(query, getModel());
}
@Override
......
......@@ -13,6 +13,11 @@ import org.apache.jena.update.UpdateRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Arrays.*;
import static no.deichman.services.entity.repository.SPARQLQueryBuilder.DEFAULT_GRAPH;
import java.util.Arrays;
import java.util.List;
/**
* Responsibility: Remotely calling a sparql endpoint to do queries and updates.
*/
......@@ -22,6 +27,7 @@ public final class RemoteRepository extends RDFRepositoryBase {
//private static final String TRIPLESTORE_PORT = "http://fuseki:3030";
private static final String TRIPLESTORE_PORT = "http://virtuoso:8890";
private final String triplestorePort;
private static final List<String> graphs = Arrays.asList(DEFAULT_GRAPH);
RemoteRepository(String triplestorePort, UniqueURIGenerator uriGenerator, SPARQLQueryBuilder sparqlQueryBuilder) {
super(sparqlQueryBuilder, uriGenerator);
......@@ -39,7 +45,7 @@ public final class RemoteRepository extends RDFRepositoryBase {
@Override
protected QueryExecution getQueryExecution(Query query) {
//return QueryExecutionFactory.sparqlService(triplestorePort + "/ds/sparql", query);
return QueryExecutionFactory.sparqlService(triplestorePort + "/sparql", query);
return QueryExecutionFactory.sparqlService(triplestorePort + "/sparql", query, graphs, null);
}
@Override
......
......@@ -43,6 +43,7 @@ import static no.deichman.services.entity.EntityServiceImplTest.modelForBiblio;
import static no.deichman.services.entity.EntityType.SUBJECT;
import static no.deichman.services.entity.repository.InMemoryRepositoryTest.repositoryWithDataFrom;
import static no.deichman.services.entity.repository.InMemoryRepositoryTest.repositoryWithDataFromString;
import static no.deichman.services.entity.repository.SPARQLQueryBuilder.DEFAULT_GRAPH;
import static no.deichman.services.rdf.RDFModelUtil.modelFrom;
import static no.deichman.services.testutil.TestJSON.assertValidJSON;
import static org.apache.jena.query.QueryExecutionFactory.create;
......
......@@ -62,7 +62,7 @@ public class SPARQLQueryBuilderTest {
m.add(s);
SPARQLQueryBuilder sqb = new SPARQLQueryBuilder();
String query = sqb.getUpdateWorkQueryString(m);
String expected = "INSERT { GRAPH <https://data.deichman.no> {\n"
String expected = "INSERT { GRAPH <https://katalog.deichman.no> {\n"
+ "<http://example.com/a> <http://example.com/b> <http://example.com/c> .\n"
+ "}\n}\n"
+ "WHERE { SELECT * { OPTIONAL { ?s ?p ?o . } } LIMIT 1 }\n";
......@@ -96,7 +96,7 @@ public class SPARQLQueryBuilderTest {
UpdateAction.parseExecute(sqb.getReplaceSubjectQueryString(newSubject), m);
String query = sqb.getCreateQueryString(m);
String expected = "INSERT { GRAPH <https://data.deichman.no> {\n"
String expected = "INSERT { GRAPH <https://katalog.deichman.no> {\n"
+ "<http://example.com/z> <http://example.com/b> <http://example.com/c> .\n"
+ "}\n}\n"
+ "WHERE { SELECT * { OPTIONAL { ?s ?p ?o . } } LIMIT 1 }\n";
......@@ -158,7 +158,7 @@ public class SPARQLQueryBuilderTest {
Patch patch = new Patch("add", s, null);
patches.add(patch);
SPARQLQueryBuilder sqb = new SPARQLQueryBuilder();
String expected = "INSERT { GRAPH <https://data.deichman.no> {\n"
String expected = "INSERT { GRAPH <https://katalog.deichman.no> {\n"
+ " <http://example.com/a> <http://example.com/ontology/name> \"json\" .\n"
+ "}\n}\n"
+ "WHERE { SELECT * { OPTIONAL { ?s ?p ?o . } } LIMIT 1 };\n";
......@@ -172,7 +172,7 @@ public class SPARQLQueryBuilderTest {
Patch patch = new Patch("del", s, null);
patches.add(patch);
SPARQLQueryBuilder sqb = new SPARQLQueryBuilder();
String expected = "DELETE { GRAPH <https://data.deichman.no> {\n"
String expected = "DELETE { GRAPH <https://katalog.deichman.no> {\n"
+ " <http://example.com/a> <http://example.com/ontology/name> \"json\" .\n"
+ "}\n}\n"
+ "WHERE { SELECT * { OPTIONAL { ?s ?p ?o . } } LIMIT 1 };\n";
......@@ -192,12 +192,12 @@ public class SPARQLQueryBuilderTest {
Patch patch3 = new Patch("add", s3, null);
patches.add(patch3);
SPARQLQueryBuilder sqb = new SPARQLQueryBuilder();
String expected = "DELETE { GRAPH <https://data.deichman.no> {\n"
String expected = "DELETE { GRAPH <https://katalog.deichman.no> {\n"
+ " <http://example.com/a> <http://example.com/ontology/name> \"json\" .\n"
+ " <http://example.com/a> <http://example.com/ontology/test> \"json\" .\n"
+ "}\n}\n"
+ "WHERE { SELECT * { OPTIONAL { ?s ?p ?o . } } LIMIT 1 };\n"
+ "INSERT { GRAPH <https://data.deichman.no> {\n"
+ "INSERT { GRAPH <https://katalog.deichman.no> {\n"
+ " <http://example.com/a> <http://example.com/ontology/cress> \"false fish\" .\n"
+ "}\n}\n"
+ "WHERE { SELECT * { OPTIONAL { ?s ?p ?o . } } LIMIT 1 };\n";
......@@ -220,12 +220,12 @@ public class SPARQLQueryBuilderTest {
Patch patch3 = new Patch("add", s3, null);
patches.add(patch3);
SPARQLQueryBuilder sqb = new SPARQLQueryBuilder();
String expected = "DELETE { GRAPH <https://data.deichman.no> {\n"
String expected = "DELETE { GRAPH <https://katalog.deichman.no> {\n"
+ " <http://example.com/a> <http://example.com/ontology/name> \"json\" .\n"
+ " <http://example.com/a> <http://example.com/ontology/test> \"json\" .\n"
+ "}\n}\n"
+ "WHERE { SELECT * { OPTIONAL { ?s ?p ?o . } } LIMIT 1 };\n"
+ "INSERT { GRAPH <https://data.deichman.no> {\n"
+ "INSERT { GRAPH <https://katalog.deichman.no> {\n"
+ " <http://example.com/a> <http://example.com/ontology/farmhouse> \"Fiffle\" .\n"
+ " <http://example.com/a> <http://example.com/ontology/cress> \"false fish\" .\n"
+ "}\n}\n"
......@@ -248,7 +248,7 @@ public class SPARQLQueryBuilderTest {
Patch patch2 = new Patch("add", s2, null);
patches.add(patch2);
SPARQLQueryBuilder sqb = new SPARQLQueryBuilder();
String expected = "INSERT { GRAPH <https://data.deichman.no> {\n"
String expected = "INSERT { GRAPH <https://katalog.deichman.no> {\n"
+ " <http://example.org/a> <http://example.org/prop#a> <_:b0> .\n"
+ " <_:b0> <http://example.com/ontology/name> \"json\" .\n"
+ " <_:b0> <http://example.com/ontology/test> \"json\" .\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment