Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
digibib
ls.ext
Commits
946d8c23
Commit
946d8c23
authored
Oct 25, 2018
by
Petter Goksøyr Åsen
Browse files
services: fix most tests
parent
c313f6dd
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
redef/services/src/main/java/no/deichman/services/entity/repository/InMemoryRepository.java
View file @
946d8c23
...
...
@@ -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
.
get
DefaultModel
(
).
add
(
newData
);
model
.
get
NamedModel
(
DEFAULT_GRAPH
).
add
(
newData
);
}
public
Model
getModel
()
{
return
model
.
get
DefaultModel
(
);
return
model
.
get
NamedModel
(
DEFAULT_GRAPH
);
}
@Override
protected
QueryExecution
getQueryExecution
(
Query
query
)
{
return
QueryExecutionFactory
.
create
(
query
,
m
odel
);
return
QueryExecutionFactory
.
create
(
query
,
getM
odel
()
);
}
@Override
...
...
redef/services/src/main/java/no/deichman/services/entity/repository/RemoteRepository.java
View file @
946d8c23
...
...
@@ -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
...
...
redef/services/src/test/java/no/deichman/services/entity/EntityResourceTest.java
View file @
946d8c23
...
...
@@ -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
;
...
...
redef/services/src/test/java/no/deichman/services/entity/repository/SPARQLQueryBuilderTest.java
View file @
946d8c23
...
...
@@ -62,7 +62,7 @@ public class SPARQLQueryBuilderTest {
m
.
add
(
s
);
SPARQLQueryBuilder
sqb
=
new
SPARQLQueryBuilder
();
String
query
=
sqb
.
getUpdateWorkQueryString
(
m
);
String
expected
=
"INSERT { GRAPH <https://
d
ata.deichman.no> {\n"
String
expected
=
"INSERT { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
String
expected
=
"INSERT { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
String
expected
=
"INSERT { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
String
expected
=
"DELETE { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
String
expected
=
"DELETE { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
+
"INSERT { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
String
expected
=
"DELETE { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
+
"INSERT { GRAPH <https://
k
ata
log
.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://
d
ata.deichman.no> {\n"
String
expected
=
"INSERT { GRAPH <https://
k
ata
log
.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"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment