-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not instantiate Rdf4jInstanceServer
- Loading branch information
Showing
1 changed file
with
26 additions
and
16 deletions.
There are no files selected for viewing
42 changes: 26 additions & 16 deletions
42
src/test/scala/se/lu/nateko/cp/meta/test/services/sparql/index/IndexDataTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,50 @@ | ||
package se.lu.nateko.cp.meta.test.services.sparql.index | ||
|
||
import org.eclipse.rdf4j.model.IRI | ||
import org.eclipse.rdf4j.model.{IRI, Statement, Value, ValueFactory} | ||
import org.scalatest.funspec.AnyFunSpec | ||
import se.lu.nateko.cp.meta.instanceserver.{Rdf4jInstanceServer, TriplestoreConnection} | ||
import se.lu.nateko.cp.meta.services.CpmetaVocab | ||
import se.lu.nateko.cp.meta.api.CloseableIterator | ||
import se.lu.nateko.cp.meta.core.crypto.Sha256Sum | ||
import se.lu.nateko.cp.meta.instanceserver.TriplestoreConnection | ||
import se.lu.nateko.cp.meta.services.sparql.magic.index.IndexData | ||
import se.lu.nateko.cp.meta.services.{CpVocab, CpmetaVocab} | ||
import se.lu.nateko.cp.meta.utils.rdf4j.Loading | ||
import se.lu.nateko.cp.meta.core.crypto.Sha256Sum | ||
import se.lu.nateko.cp.meta.services.CpVocab | ||
|
||
// IndexData requires a TriplestoreConnection but in current tests it is not actually used. | ||
private class DummyTSC extends TriplestoreConnection { | ||
override def close(): Unit = ??? | ||
override def primaryContext: IRI = ??? | ||
override def readContexts: Seq[IRI] = ??? | ||
override def factory: ValueFactory = ??? | ||
override def getStatements(subject: IRI | Null, predicate: IRI | Null, obj: Value | Null): CloseableIterator[Statement] = ??? | ||
override def hasStatement(subject: IRI | Null, predicate: IRI | Null, obj: Value | Null): Boolean = ??? | ||
override def withContexts(primary: IRI, read: Seq[IRI]): TriplestoreConnection = ??? | ||
} | ||
|
||
class IndexDataTest extends AnyFunSpec { | ||
describe("processTriple") { | ||
it("clears fName of ObjEntry when hasName tuple is deleted") { | ||
val repo = Loading.emptyInMemory | ||
val server = new Rdf4jInstanceServer(repo) | ||
val factory = repo.getValueFactory | ||
val vocab = CpmetaVocab(factory) | ||
|
||
val subject: IRI = factory.createIRI("https://meta.icos-cp.eu/objects/oAzNtfjXddcnG_irI8fJT7W6") | ||
|
||
// Make sure we insert a DataObject | ||
val hash : Sha256Sum = | ||
val hash: Sha256Sum = | ||
subject match { | ||
case CpVocab.DataObject(hash, _prefix) => hash | ||
} | ||
|
||
val data = IndexData(100)() | ||
server.access { | ||
// Insert hasName triple | ||
data.processTriple(subject, vocab.hasName, factory.createIRI("test:name"), true, vocab) | ||
assert(data.objs.length == 1) | ||
assert(data.getObjEntry(hash).fileName == Some("test:name")) | ||
// Remove it | ||
data.processTriple(subject, vocab.hasName, factory.createIRI("test:name"), false, vocab) | ||
assert(data.getObjEntry(hash).fileName == None) | ||
} | ||
given TriplestoreConnection = DummyTSC() | ||
|
||
// Insert hasName triple | ||
data.processTriple(subject, vocab.hasName, factory.createIRI("test:name"), true, vocab) | ||
assert(data.objs.length == 1) | ||
assert(data.getObjEntry(hash).fileName == Some("test:name")) | ||
// Remove it | ||
data.processTriple(subject, vocab.hasName, factory.createIRI("test:name"), false, vocab) | ||
assert(data.getObjEntry(hash).fileName == None) | ||
} | ||
} | ||
} |