Permalink
Browse files

first test for LDPS

  • Loading branch information...
1 parent e320ae0 commit ea01c9cfeb2c7a9ae031366b200518db8e87c311 @betehess betehess committed Nov 21, 2012
@@ -37,19 +37,13 @@ trait LDPC[Rdf <: RDF] {
trait LDPS[Rdf <: RDF] {
def baseUri: Rdf#URI
def shutdown(): Unit
- def createLDPC(uri: URI): Future[LDPC[Rdf]]
- def getLDPC(uri: URI): Future[LDPC[Rdf]]
- def deleteLDPC(uri: URI): Future[Unit]
+ def createLDPC(uri: Rdf#URI): Future[LDPC[Rdf]]
+ def getLDPC(uri: Rdf#URI): Future[LDPC[Rdf]]
+ def deleteLDPC(uri: Rdf#URI): Future[Unit]
}
-object PlantainLDPR {
-
-
-
-}
-
/**
* it's important for the uris in the graph to be absolute
* this invariant is assumed by the sparql engine (TripleSource)
@@ -58,13 +52,15 @@ case class PlantainLDPR(uri: URI, graph: Graph) extends LDPR[Plantain] {
/* the graph such that all URIs are relative to $uri */
def relativeGraph: Graph = {
- graph.triples.foldLeft(Graph.empty){ (current, triple) => current + triple.relativize(uri) }
+ graph.triples.foldLeft(Graph.empty){ (current, triple) => current + triple.relativizeAgainst(uri) }
}
}
class PlantainLDPC(val uri: URI, actorRef: ActorRef)(implicit timeout: Timeout) extends LDPC[Plantain] {
+ override def toString: String = uri.toString
+
def execute[A](script: Plantain#Script[A]): Future[A] = {
(actorRef ? Coordinated(Script(script))).asInstanceOf[Future[A]]
}
@@ -97,7 +93,7 @@ class PlantainLDPCActor(baseUri: URI, root: Path) extends Actor {
}
case GetLDPR(uri, k) => {
val ldpr = LDPRs(uri.lastPathSegment)
- run(coordinated, k(ldpr.graph))
+ run(coordinated, k(ldpr.relativeGraph))
}
case DeleteLDPR(uri, a) => {
LDPRs.remove(uri.lastPathSegment)
@@ -188,7 +184,7 @@ class PlantainLDPSActor(baseUri: URI, root: Path, system: ActorSystem)(implicit
val ldpc = new PlantainLDPC(uri, ldpcActorRef)
sender ! ldpc
}
- case coordinated @ Coordinated(GetLDPC(uri)) => coordinated atomic { implicit t =>
+ case coordinated @ Coordinated(DeleteLDPC(uri)) => coordinated atomic { implicit t =>
val ldpcActorRefOpt = LDPCs.remove(uri)
ldpcActorRefOpt foreach { ldpcActorRef => system.stop(ldpcActorRef) }
sender ! ()
@@ -46,6 +46,10 @@ class PlantainURISyntax(val uri: URI) extends AnyVal with syntax.URISyntax[Plant
URI(uri.underlying.relativize(other.underlying))
}
+ def relativizeAgainst(other: Plantain#URI)(implicit ops: RDFOps[Plantain]): Plantain#URI = {
+ URI(other.underlying.relativize(uri.underlying))
+ }
+
def lastPathSegment: String = uri.underlying.toString.replaceFirst(".*/([^/?]+).*", "$1")
}
@@ -239,7 +239,7 @@ sealed trait Node {
} catch {
case iae: IllegalArgumentException =>
new SesameURI {
- override def equals(o: Any): Boolean = o.isInstanceOf[URI] && o.asInstanceOf[URI].toString == uriS
+ override def equals(o: Any): Boolean = o.isInstanceOf[SesameURI] && o.asInstanceOf[SesameURI].toString == uriS
def getLocalName: String = uriS
def getNamespace: String = ""
override def hashCode: Int = uriS.hashCode
@@ -1,8 +1,114 @@
package org.w3.banana.plantain
import org.w3.banana._
+import org.scalatest._
+import org.scalatest.matchers._
import Plantain._
+import LDPCommand._
+import scala.concurrent.ExecutionContext.Implicits.global
-//class PlantainGraphStoreTest extends GraphStoreTest[Plantain]({
-// PlantainStore(null, null)
-//})
+class PlantainLDPSTest extends LDPSTest[Plantain]({
+ PlantainLDPS(null, null)
+})
+
+class LDPSTest[Rdf <: RDF](
+ ldps: LDPS[Rdf])(
+ implicit diesel: Diesel[Rdf],
+ reader: RDFReader[Rdf, RDFXML]) extends WordSpec with MustMatchers with BeforeAndAfterAll {
+
+ import diesel._
+ import ops._
+
+ val foaf = FOAFPrefix[Rdf]
+
+ override def afterAll(): Unit = {
+ ldps.shutdown()
+ }
+
+ val graph: Rdf#Graph = (
+ URI("#me")
+ -- foaf.name ->- "Alexandre".lang("fr")
+ -- foaf.title ->- "Mr"
+ ).graph
+
+ val graph2: Rdf#Graph = (
+ URI("#me")
+ -- foaf.name ->- "Alexandre".lang("fr")
+ -- foaf.knows ->- (
+ URI("http://bblfish.net/#hjs")
+ -- foaf.name ->- "Henry Story"
+ -- foaf.currentProject ->- URI("http://webid.info/")
+ )
+ ).graph
+
+ val foo: Rdf#Graph = (
+ URI("http://example.com/foo")
+ -- rdf("foo") ->- "foo"
+ -- rdf("bar") ->- "bar"
+ ).graph
+
+ "CreateLDPR should create an LDPR with the given graph -- with given uri" in {
+ val ldpcUri = URI("http://example.com/foo")
+ val ldprUri = URI("http://example.com/foo/betehess")
+ val script = for {
+ ldpc <- ldps.createLDPC(ldpcUri)
+ _ <- ldpc.execute(createLDPR(Some(ldprUri), graph))
+ rGraph <- ldpc.execute(getLDPR(ldprUri))
+ _ <- ldps.deleteLDPC(ldpcUri)
+ } yield {
+ assert(rGraph isIsomorphicWith graph)
+ }
+ script.getOrFail(scala.concurrent.duration.Duration.create("10s"))
+ }
+
+// "getNamedGraph should retrieve the graph added with appendToGraph" in {
+// val u1 = URI("http://example.com/foo/betehess")
+// val u2 = URI("http://example.com/foo/alexandre")
+// val r = for {
+// ldpc <- ldps.createLDPC(URI("http://example.com/foo"))
+// _ <- ldpc.execute()
+// _ <- graphStore.appendToGraph(u1, graph)
+// _ <- graphStore.appendToGraph(u2, graph2)
+// rGraph <- graphStore.getGraph(u1)
+// rGraph2 <- graphStore.getGraph(u2)
+// } yield {
+// assert(rGraph isIsomorphicWith graph)
+// assert(rGraph2 isIsomorphicWith graph2)
+// }
+// r.getOrFail()
+// }
+
+// "appendToGraph should be equivalent to graph union" in {
+// val u = URI("http://example.com/graph")
+// val r = for {
+// _ <- graphStore.removeGraph(u)
+// _ <- graphStore.appendToGraph(u, graph)
+// _ <- graphStore.appendToGraph(u, graph2)
+// rGraph <- graphStore.getGraph(u)
+// } yield {
+// assert(rGraph isIsomorphicWith union(List(graph, graph2)))
+// }
+// r.getOrFail()
+// }
+//
+// "patchGraph should delete and insert triples as expected" in {
+// val u = URI("http://example.com/graph")
+// val r = for {
+// _ <- graphStore.removeGraph(u)
+// _ <- graphStore.appendToGraph(u, foo)
+// _ <- graphStore.patchGraph(u,
+// (URI("http://example.com/foo") -- rdf("foo") ->- "foo").graph.toIterable,
+// (URI("http://example.com/foo") -- rdf("baz") ->- "baz").graph)
+// rGraph <- graphStore.getGraph(u)
+// } yield {
+// val expected = (
+// URI("http://example.com/foo")
+// -- rdf("bar") ->- "bar"
+// -- rdf("baz") ->- "baz"
+// ).graph
+// assert(rGraph isIsomorphicWith expected)
+// }
+// r.getOrFail()
+// }
+
+}
@@ -17,4 +17,9 @@ class NodeSyntax[Rdf <: RDF](val node: Rdf#Node) extends AnyVal {
foldNode(node)(_.relativize(baseUri), bn => bn, lit => lit)
}
+ def relativizeAgainst(baseUri: Rdf#URI)(implicit ops: RDFOps[Rdf]): Rdf#Node = {
+ import ops.uriSyntax
+ ops.foldNode(node)(_.relativizeAgainst(baseUri), bn => bn, lit => lit)
+ }
+
}
@@ -16,4 +16,10 @@ class TripleSyntax[Rdf <: RDF](val triple: Rdf#Triple) extends AnyVal {
ops.makeTriple(s.relativize(baseUri), p, o.relativize(baseUri))
}
+ def relativizeAgainst(baseUri: Rdf#URI)(implicit ops: RDFOps[Rdf]): Rdf#Triple = {
+ import ops.nodeSyntax
+ val (s, p, o) = ops.fromTriple(triple)
+ ops.makeTriple(s.relativizeAgainst(baseUri), p, o.relativizeAgainst(baseUri))
+ }
+
}
@@ -25,6 +25,8 @@ trait URISyntax[Rdf <: RDF] extends Any {
def relativize(other: Rdf#URI)(implicit ops: RDFOps[Rdf]): Rdf#URI
+ def relativizeAgainst(other: Rdf#URI)(implicit ops: RDFOps[Rdf]): Rdf#URI
+
def lastPathSegment: String
}
@@ -74,6 +76,8 @@ class URISyntaxDefault[Rdf <: RDF](val uri: Rdf#URI) extends AnyVal with URISynt
def relativize(other: Rdf#URI)(implicit ops: RDFOps[Rdf]): Rdf#URI = URIHelper.relativize(uri, other)(ops)
+ def relativizeAgainst(other: Rdf#URI)(implicit ops: RDFOps[Rdf]): Rdf#URI = URIHelper.relativize(other, uri)(ops)
+
def lastPathSegment: String = uri.toString.replaceFirst(".*/([^/?]+).*", "$1")
}

0 comments on commit ea01c9c

Please sign in to comment.