From 8b59d543383581bf4ddb18d2fb70a6877a87b378 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:50:30 +0100 Subject: [PATCH] test: Enable Default Union Graph in TriplestoreServiceInMemory (DEV-3295) (#3052) --- .../webapi/store/triplestore/TestDatasetBuilder.scala | 8 ++++---- .../triplestore/api/TriplestoreServiceInMemory.scala | 6 +++++- .../triplestore/api/TriplestoreServiceInMemorySpec.scala | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/webapi/src/test/scala/org/knora/webapi/store/triplestore/TestDatasetBuilder.scala b/webapi/src/test/scala/org/knora/webapi/store/triplestore/TestDatasetBuilder.scala index def646712f..f8f53b3ca8 100644 --- a/webapi/src/test/scala/org/knora/webapi/store/triplestore/TestDatasetBuilder.scala +++ b/webapi/src/test/scala/org/knora/webapi/store/triplestore/TestDatasetBuilder.scala @@ -21,10 +21,10 @@ object TestDatasetBuilder { private def readToModel(turtle: String)(model: Model): Model = model.read(new StringReader(turtle), null, "TTL") - private def transactionalWrite(change: Model => Model)(ds: Dataset): Task[Dataset] = ZIO.attempt { + private def transactionalWrite(change: Model => Model, graph: String)(ds: Dataset): Task[Dataset] = ZIO.attempt { ds.begin(ReadWrite.WRITE) try { - change apply ds.getDefaultModel + change apply ds.getNamedModel(graph) ds.commit() } finally { ds.end() @@ -32,8 +32,8 @@ object TestDatasetBuilder { ds } - private def datasetFromTurtle(turtle: String): Task[Dataset] = - createEmptyDataset.flatMap(transactionalWrite(readToModel(turtle))) + private def datasetFromTurtle(turtle: String, graph: String = "http://www.example.org/graph"): Task[Dataset] = + createEmptyDataset.flatMap(transactionalWrite(readToModel(turtle), graph)) def datasetFromTriG(trig: String): Task[Dataset] = for { diff --git a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala index 2676e7221f..e84fe83675 100644 --- a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala +++ b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemory.scala @@ -8,6 +8,7 @@ import org.apache.jena.query.* import org.apache.jena.rdf.model.Model import org.apache.jena.rdf.model.ModelFactory import org.apache.jena.riot.RDFDataMgr +import org.apache.jena.tdb.TDB import org.apache.jena.tdb2.TDB2Factory import org.apache.jena.update.UpdateExecutionFactory import org.apache.jena.update.UpdateFactory @@ -302,7 +303,10 @@ object TriplestoreServiceInMemory { * Currently does not (yet) support create a [[Dataset]] which supports Lucene indexing. * TODO: https://jena.apache.org/documentation/query/text-query.html#configuration-by-code */ - val createEmptyDataset: UIO[Dataset] = ZIO.succeed(TDB2Factory.createDataset()) + val createEmptyDataset: UIO[Dataset] = + ZIO + .succeed(TDB.getContext.set(TDB.symUnionDefaultGraph, true)) + .as(TDB2Factory.createDataset()) val emptyDatasetRefLayer: ULayer[Ref[Dataset]] = ZLayer.fromZIO(createEmptyDataset.flatMap(Ref.make(_))) diff --git a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala index cf40998306..ce6b4472f9 100644 --- a/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/store/triplestore/api/TriplestoreServiceInMemorySpec.scala @@ -127,8 +127,11 @@ object TriplestoreServiceInMemorySpec extends ZIOSpecDefault { val updateQuery = s""" |PREFIX rdf: | - |INSERT { a <${Biblio.Class.Article.value}> } - |WHERE { ?s ?p ?o } + |INSERT DATA { + | GRAPH { + | a <${Biblio.Class.Article.value}> + | } + |} |""".stripMargin val askQuery = s""" |PREFIX rdf: