You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2011/07/06 16:07:10 UTC
svn commit: r1143423 -
/incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzMGraphTest.scala
Author: reto
Date: Wed Jul 6 14:07:10 2011
New Revision: 1143423
URL: http://svn.apache.org/viewvc?rev=1143423&view=rev
Log:
CLEREZZA-510: added test class
Added:
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzMGraphTest.scala
Added: incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzMGraphTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzMGraphTest.scala?rev=1143423&view=auto
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzMGraphTest.scala (added)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzMGraphTest.scala Wed Jul 6 14:07:10 2011
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.scala.utils
+
+import org.apache.clerezza.rdf.ontologies._
+import org.junit._
+import org.apache.clerezza.rdf.core._
+import impl._
+import Preamble._
+
+class EzMGraphTest {
+
+ val bblfishModulus = """
+ 9D â® 79 â® BF â® E2 â® F4 â® 98 â® BC â® 79 â® 6D â® AB â® 73 â® E2 â® 8B â® 39 â® 4D â® B5 26 â 68 â 49 â EE â 71 â 87 â
+ 06 â 32 â C9 â 9F â 3F â 94 â E5 â CB â 4D â B5 12 â® 35 â® 13 â® 69 â® 60 â® 81 â® 58 â® 79 â® 66 â® F3 â® 79 â® 20 â®
+ 91 â® 6A â® 3F â® 42 5A â F6 â 54 â 42 â 88 â B2 â E9 â 19 â 4A â 79 â 87 â 2E â 62 â 44 â 2D â 7C 06 â½ 78 â½ F8
+ â½ FD â½ 52 â½ 92 â½ 6D â½ CD â½ D6 â½ F3 â½ 28 â½ 6B â½ 1F â½ DB â½ CB â½ D3 F2 â® 08 â® 34 â® 72 â® A2 â® 12 â® 75 â® AE â® D1
+ â® 09 â® 17 â® D0 â® 88 â® 4C â® 04 â® 8E 04 â¾ E5 â¾ BF â¾ D1 â¾ 41 â¾ 64 â¾ D1 â¾ F7 â¾ 89 â¾ 6D â¾ 8B â¾ B2 â¾ F2 â¾ 46 â¾ C0
+ â¾ 56 87 â® 8D â® B8 â® 7C â® C6 â® FE â® E9 â® 61 â® 88 â® 08 â® 61 â® DD â® E3 â® B8 â® B5 â® 47 â¥
+ """
+
+ /** import some references in order to reduce dependencies */
+
+ final val hex: UriRef = new UriRef("http://www.w3.org/ns/auth/cert#hex")
+ final val identity: UriRef = new UriRef("http://www.w3.org/ns/auth/cert#identity")
+ final val RSAPublicKey: UriRef = new UriRef("http://www.w3.org/ns/auth/rsa#RSAPublicKey")
+ final val modulus: UriRef = new UriRef("http://www.w3.org/ns/auth/rsa#modulus")
+ final val public_exponent: UriRef = new UriRef("http://www.w3.org/ns/auth/rsa#public_exponent")
+
+ val henryUri: String = "http://bblfish.net/#hjs"
+ val retoUri: String = "http://farewellutopia.com/reto/#me"
+ val danbriUri: String = "http://danbri.org/foaf.rdf#danbri"
+
+
+ private val tinyGraph: Graph = {
+ val gr = new SimpleMGraph
+ val reto= new BNode()
+ val danny = new BNode()
+ val henry = new UriRef(henryUri)
+
+ gr.add(new TripleImpl(reto,RDF.`type`, FOAF.Person))
+ gr.add(new TripleImpl(reto,FOAF.name, new PlainLiteralImpl("Reto Bachman-Gmür", new Language("rm"))))
+ //it is difficult to remember that one needs to put a string literal if one does not want to specify a language
+ gr.add(new TripleImpl(reto,FOAF.title, new TypedLiteralImpl("Mr",XSD.string)))
+ gr.add(new TripleImpl(reto,FOAF.currentProject, new UriRef("http://clerezza.org/")))
+ gr.add(new TripleImpl(reto,FOAF.knows, henry))
+ gr.add(new TripleImpl(reto,FOAF.knows, danny))
+
+ gr.add(new TripleImpl(danny,FOAF.name,new PlainLiteralImpl("Danny Ayers", new Language("en"))))
+ gr.add(new TripleImpl(danny,RDF.`type`, FOAF.Person))
+ gr.add(new TripleImpl(danny,FOAF.knows, henry))
+ gr.add(new TripleImpl(danny,FOAF.knows, reto))
+
+ gr.add(new TripleImpl(henry,FOAF.name,new TypedLiteralImpl("Henry Story",XSD.string))) //It is tricky to remember that one needs this for pure strings
+ gr.add(new TripleImpl(henry,FOAF.currentProject,new UriRef("http://webid.info/")))
+ gr.add(new TripleImpl(henry,RDF.`type`, FOAF.Person))
+ gr.add(new TripleImpl(henry,FOAF.knows, danny))
+ gr.add(new TripleImpl(henry,FOAF.knows, reto))
+
+ val pk = new BNode()
+ gr.add(new TripleImpl(pk,RDF.`type`,RSAPublicKey))
+ gr.add(new TripleImpl(pk,identity,henry))
+ gr.add(new TripleImpl(pk,modulus,LiteralFactory.getInstance().createTypedLiteral(65537)))
+ gr.add(new TripleImpl(pk,public_exponent,new TypedLiteralImpl(bblfishModulus,hex)))
+ gr.getGraph
+ }
+
+
+ @Test
+ def singleTriple {
+ val expected = {
+ val s = new SimpleMGraph
+ s.add(new TripleImpl(henryUri.uri, FOAF.knows, retoUri.uri))
+ s.getGraph
+ }
+ val ez = new EzMGraph() {
+ henryUri.uri -- FOAF.knows --> retoUri.uri
+ }
+ Assert.assertEquals("The two graphs should be equals", expected, ez.getGraph)
+ }
+
+ @Test
+ def inverseTriple {
+ val expected = {
+ val s = new SimpleMGraph
+ s.add(new TripleImpl(retoUri.uri, FOAF.knows, henryUri.uri))
+ s.getGraph
+ }
+ val ez = new EzMGraph() {
+ henryUri.uri <-- FOAF.knows -- retoUri.uri
+ }
+ Assert.assertEquals("The two graphs should be equals", expected, ez.getGraph)
+ }
+
+ @Test
+ def usingAsciiArrows {
+ val ez = new EzMGraph() {
+ b_("reto").a(FOAF.Person) --
+ FOAF.name --> "Reto Bachman-Gmür".lang('rm) --
+ FOAF.title --> "Mr" --
+ FOAF.currentProject --> "http://clerezza.org/".uri --
+ FOAF.knows --> (
+ "http://bblfish.net/#hjs".uri.a(FOAF.Person)
+ -- FOAF.name --> "Henry Story"
+ -- FOAF.currentProject --> "http://webid.info/".uri
+ -- FOAF.knows -->> List(b_("reto"), b_("danny"))
+ //one need to list properties before inverse properties, or use brackets
+ <-- identity -- (
+ bnode.a(RSAPublicKey) //. notation because of precedence of operators
+ -- modulus --> 65537
+ -- public_exponent --> (bblfishModulus^^hex) // brackets needed due to precedence
+ )
+ ) --
+ FOAF.knows --> (b_("danny").a(FOAF.Person) --
+ FOAF.name --> "Danny Ayers".lang('en)
+ -- FOAF.knows --> "http://bblfish.net/#hjs".uri //knows
+ -- FOAF.knows --> b_("reto")
+ )
+ }
+ Assert.assertEquals("the two graphs should be of same size",tinyGraph.size(),ez.size())
+ Assert.assertEquals("Both graphs should contain exactly the same triples",tinyGraph,ez.getGraph)
+ //We can add triples by creating a new anonymous instance
+ new EzMGraph(ez) {(
+ "http://bblfish.net/#hjs".uri -- FOAF.name --> "William"
+ -- FOAF.name --> "Bill"
+ )}
+ Assert.assertEquals("the triple colletion has grown by one",tinyGraph.size()+2,ez.size())
+ //or by just importing it
+ import ez._
+ ez.b_("danny") -- FOAF.name --> "George"
+ Assert.assertEquals("the triple colletion has grown by one",tinyGraph.size()+3,ez.size())
+ }
+
+}