Return-Path: X-Original-To: apmail-jena-commits-archive@www.apache.org Delivered-To: apmail-jena-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DAE0810DE0 for ; Sat, 21 Sep 2013 20:12:36 +0000 (UTC) Received: (qmail 36373 invoked by uid 500); 21 Sep 2013 20:12:34 -0000 Delivered-To: apmail-jena-commits-archive@jena.apache.org Received: (qmail 36304 invoked by uid 500); 21 Sep 2013 20:12:31 -0000 Mailing-List: contact commits-help@jena.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jena.apache.org Delivered-To: mailing list commits@jena.apache.org Received: (qmail 36188 invoked by uid 99); 21 Sep 2013 20:12:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Sep 2013 20:12:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Sep 2013 20:12:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 45B962388B3A; Sat, 21 Sep 2013 20:12:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1525287 [2/6] - in /jena/Experimental/new-test/src/test: java/com/hp/hpl/jena/rdf/model/ java/com/hp/hpl/jena/rdf/model/temp/ java/com/hp/hpl/jena/testing_framework/ resources/ resources/com/hp/hpl/jena/rdf/ resources/com/hp/hpl/jena/rdf/m... Date: Sat, 21 Sep 2013 20:12:00 -0000 To: commits@jena.apache.org From: claude@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130921201202.45B962388B3A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelConContractTests.java URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelConContractTests.java?rev=1525287&view=auto ============================================================================== --- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelConContractTests.java (added) +++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelConContractTests.java Sat Sep 21 20:11:59 2013 @@ -0,0 +1,3676 @@ +/* + * 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 com.hp.hpl.jena.rdf.model; + +import static com.hp.hpl.jena.testing_framework.ModelHelper.*; +import static org.junit.Assert.*; +import java.util.Arrays; +import java.util.Calendar; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.datatypes.BaseDatatype; +import com.hp.hpl.jena.datatypes.RDFDatatype; +import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; +import com.hp.hpl.jena.datatypes.xsd.XSDDateTime; +import com.hp.hpl.jena.graph.Node; +import com.hp.hpl.jena.graph.NodeFactory; +import com.hp.hpl.jena.graph.impl.AdhocDatatype; +import com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl; +import com.hp.hpl.jena.testing_framework.AbstractModelProducerUser; +import com.hp.hpl.jena.testing_framework.ModelHelper; +import com.hp.hpl.jena.testing_framework.NodeCreateUtils; +import com.hp.hpl.jena.vocabulary.RDF; + +/** + * An abstract class that tests the implementation of the Model contract. + * + * NOTE: does not test independent as only derived classes know if they are + * independent or not. + * + */ +public abstract class AbstractModelConContractTests extends + AbstractModelProducerUser { + private Model model; + private RecordingModelListener SL; + + private static Logger log = LoggerFactory + .getLogger(AbstractModelConContractTests.class); + + @Before + public final void setupAbstractModelConTest() { + model = getModelProducer().newModel(); + SL = new RecordingModelListener(); + } + + @Test + public void testAdd_Resource_Property_RDFNode() { + Statement s = statement("S P O"); + model.register(SL); + txnBegin(model); + assertTrue("add( S, P, O ) must return model for cascading", + model == model.add(resource("S"), property("P"), rdfNode("O"))); + txnCommit(model); + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + } + + @Test + public void testAdd_Resource_Property_String() { + Statement s = statement("S P 'foo'"); + model.register(SL); + txnBegin(model); + assertTrue("add( S, P, O ) must return model for cascading", + model == model.add(resource("S"), property("P"), "foo")); + txnCommit(model); + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + } + + @Test + public void testAdd_Resource_Property_String_Boolean() { + RDFDatatype dt = new BaseDatatype( + "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"); + Resource S = resource("S"); + Property P = property("P"); + Literal O = ResourceFactory.createTypedLiteral("foo", dt); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertTrue("add( S, P, O ) must return model for cascading", + model == model.add(S, P, "foo", true)); + txnCommit(model); + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + } + + @Test + public void testAdd_Resource_Property_String_RDFDataType() { + Literal lit = ResourceFactory.createTypedLiteral("foo", + XSDDatatype.XSDstring); + Statement s = statement(resource("S"), property("P"), lit); + model.register(SL); + txnBegin(model); + assertTrue("add( S, P, O ) must return model for cascading", + model == model.add(resource("S"), property("P"), "foo", + XSDDatatype.XSDstring)); + txnCommit(model); + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + } + + @Test + public void testAdd_Resource_Property_String_String() { + + Resource S = resource("S"); + Property P = property("P"); + Literal O = ResourceFactory.createLangLiteral("foo", "fr"); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertTrue("add( S, P, O ) must return model for cascading", + model == model.add(S, P, "foo", "fr")); + txnCommit(model); + + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + Assert.assertFalse(model.contains(S, P, "foo")); + assertTrue("add( S, P, O ) must return model for cascading", + model == model.add(resource("S"), property("P"), "foo", + XSDDatatype.XSDstring)); + // final Resource S = + // model.createResource("http://nowhere.man/subject"); + // final Property P = + // model.createProperty("http://nowhere.man/predicate"); + // model.add(S, P, "test string", "en"); + // Assert.assertFalse(model.contains(S, P, "test string")); + // Assert.assertTrue(model.contains(S, P, "test string", "en")); + } + + @Test + public void testAddLiteral_Resource_Property_boolean() { + Resource S = resource("S"); + Property P = property("P"); + Literal lit = ResourceFactory.createTypedLiteral(tvBoolean); + Statement s = statement(S, P, lit); + model.register(SL); + txnBegin(model); + assertTrue("addLiteral( S, P, O ) must return model for cascading", + model == model.addLiteral(S, P, tvBoolean)); + txnCommit(model); + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + + } + + @Test + public void testAddLiteral_Resource_Property_char() { + Resource S = resource("S"); + Property P = property("P"); + Literal O = ResourceFactory.createTypedLiteral(tvChar); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertSame("addLiteral() should return the model", model, + model.addLiteral(S, P, tvChar)); + txnCommit(model); + + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + Assert.assertFalse(model.contains(S, P, "foo")); + Assert.assertTrue(model.containsLiteral(S, P, tvChar)); + } + + @Test + public void testAddLiteral_Resource_Property_double() { + Resource S = resource("S"); + Property P = property("P"); + Literal O = ResourceFactory.createTypedLiteral(tvDouble); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertSame("addLiteral() should return the model", model, + model.addLiteral(S, P, tvDouble)); + txnCommit(model); + + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + Assert.assertFalse(model.contains(S, P, "foo")); + Assert.assertTrue(model.containsLiteral(S, P, tvDouble)); + } + + @Test + public void testAddLiteral_Resource_Property_float() { + Resource S = resource("S"); + Property P = property("P"); + Literal O = ResourceFactory.createTypedLiteral(tvFloat); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertSame("addLiteral() should return the model", model, + model.addLiteral(S, P, tvFloat)); + txnCommit(model); + + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + Assert.assertFalse(model.contains(S, P, "foo")); + Assert.assertTrue(model.containsLiteral(S, P, tvFloat)); + } + + @Test + public void testAddLiteral_Resource_Property_int() { + Resource S = resource("S"); + Property P = property("P"); + Literal O = ResourceFactory.createTypedLiteral(tvInt); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertSame("addLiteral() should return the model", model, + model.addLiteral(S, P, tvInt)); + txnCommit(model); + + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + Assert.assertFalse(model.contains(S, P, "foo")); + Assert.assertTrue(model.containsLiteral(S, P, tvInt)); + } + + @Test + public void testAddLiteral_Resource_Property_Literal() { + Resource S = resource("S"); + Property P = property("P"); + Literal O = literal("foo", "fr"); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertSame("addLiteral() should return the model", model, + model.addLiteral(S, P, O)); + txnCommit(model); + + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + Assert.assertFalse(model.contains(S, P, "foo")); + Assert.assertTrue(model.containsLiteral(S, P, O)); + } + + @Test + public void testAddLiteral_Resource_Property_long() { + Resource S = resource("S"); + Property P = property("P"); + Literal O = ResourceFactory.createTypedLiteral(tvLong); + Statement s = statement(S, P, O); + model.register(SL); + txnBegin(model); + assertSame("addLiteral() should return the model", model, + model.addLiteral(S, P, tvLong)); + txnCommit(model); + + SL.assertHas(new Object[] { "add", s }); + assertTrue("Statement not found in model", model.contains(s)); + Assert.assertTrue(model.contains(s)); + Assert.assertFalse(model.contains(S, P, "foo")); + Assert.assertTrue(model.containsLiteral(S, P, tvLong)); + } + + @Test + public void testContains_Resource_Property_String() { + Resource S = resource("S"); + Property P = property("P"); + RDFNode O = rdfNode("O"); + + txnBegin(model); + model.add(S, P, O); + txnCommit(model); + + assertTrue("missing resource", model.contains(S, P, O)); + assertTrue("missing resource", model.contains(S, P, (RDFNode) null)); + assertTrue("missing resource", model.contains(S, null, O)); + assertTrue("missing resource", model.contains(null, P, O)); + assertTrue("missing resource", model.contains(S, null, (RDFNode) null)); + assertTrue("missing resource", model.contains(null, null, O)); + assertTrue("missing resource", + model.contains(null, null, (RDFNode) null)); + assertFalse("Extra resource", + model.contains(null, property("P2"), (RDFNode) null)); + } + + @Test + public void testContains_Resource_Property_String_String() { + Resource S = resource("S"); + Property P = property("P"); + RDFNode O = literal("foo", "fr"); + + txnBegin(model); + model.add(S, P, O); + txnCommit(model); + + assertTrue("missing resource", model.contains(S, P, "foo", "fr")); + assertFalse("found resource", model.contains(S, P, "foo", null)); + try { + assertFalse("found resource", model.contains(S, P, null, "fr")); + fail("Should have trhown NullPointerException"); + } catch (NullPointerException expected) { + // expected + } + assertTrue("missing resource", model.contains(S, null, "foo", "fr")); + assertTrue("missing resource", model.contains(null, P, "foo", "fr")); + try { + assertTrue("missing resource", model.contains(S, P, null, null)); + fail("Should have trhown NullPointerException"); + } catch (NullPointerException expected) { + // expected + } + assertFalse("found resource", model.contains(S, P, "foo", null)); + assertFalse("found resource", model.contains(S, null, "foo", null)); + assertFalse("found resource", model.contains(null, P, "foo", null)); + + assertFalse("Extra resource", model.contains(null, null, "foo", "en")); + } + + @Test + public void testContainsLiteral_Resource_Property_boolean() { + Resource S = resource("S"); + Property P = property("P"); + + txnBegin(model); + model.addLiteral(S, P, true); + txnCommit(model); + + assertTrue("missing resource", model.containsLiteral(S, P, true)); + assertTrue("missing resource", model.containsLiteral(S, null, true)); + assertTrue("missing resource", model.containsLiteral(null, P, true)); + assertTrue("missing resource", model.containsLiteral(null, null, true)); + assertFalse("extra resource", model.containsLiteral(S, P, false)); + } + + @Test + public void testContainsLiteral_Resource_Property_char() { + Resource S = resource("S"); + Property P = property("P"); + char c = 'c'; + txnBegin(model); + model.addLiteral(S, P, c); + txnCommit(model); + + assertTrue("missing resource", model.containsLiteral(S, P, c)); + assertTrue("missing resource", model.containsLiteral(S, null, c)); + assertTrue("missing resource", model.containsLiteral(null, P, c)); + assertTrue("missing resource", model.containsLiteral(null, null, c)); + assertFalse("extra resource", model.containsLiteral(S, P, 'b')); + } + + @Test + public void testContainsLiteral_Resource_Property_double() { + Resource S = resource("S"); + Property P = property("P"); + double d = 4.5d; + + txnBegin(model); + model.addLiteral(S, P, d); + txnCommit(model); + + assertTrue("missing resource", model.containsLiteral(S, P, d)); + assertTrue("missing resource", model.containsLiteral(S, null, d)); + assertTrue("missing resource", model.containsLiteral(null, P, d)); + assertTrue("missing resource", model.containsLiteral(null, null, d)); + assertFalse("extra resource", model.containsLiteral(S, P, 8.5d)); + } + + @Test + public void testContainsLiteral_Resource_Property_float() { + Resource S = resource("S"); + Property P = property("P"); + float f = 4.5f; + + txnBegin(model); + model.addLiteral(S, P, f); + txnCommit(model); + + assertTrue("missing resource", model.containsLiteral(S, P, f)); + assertTrue("missing resource", model.containsLiteral(S, null, f)); + assertTrue("missing resource", model.containsLiteral(null, P, f)); + assertTrue("missing resource", model.containsLiteral(null, null, f)); + assertFalse("extra resource", model.containsLiteral(S, P, 8.5f)); + } + + @Test + public void testContainsLiteral_Resource_Property_int() { + Resource S = resource("S"); + Property P = property("P"); + int i = 5; + + txnBegin(model); + model.addLiteral(S, P, i); + txnCommit(model); + + assertTrue("missing resource", model.containsLiteral(S, P, i)); + assertTrue("missing resource", model.containsLiteral(S, null, i)); + assertTrue("missing resource", model.containsLiteral(null, P, i)); + assertTrue("missing resource", model.containsLiteral(null, null, i)); + assertFalse("extra resource", model.containsLiteral(S, P, 10)); + } + + @Test + public void testContainsLiteral_Resource_Property_long() { + Resource S = resource("S"); + Property P = property("P"); + long l = 15L; + + txnBegin(model); + model.addLiteral(S, P, l); + txnCommit(model); + + assertTrue("missing resource", model.containsLiteral(S, P, l)); + assertTrue("missing resource", model.containsLiteral(S, null, l)); + assertTrue("missing resource", model.containsLiteral(null, P, l)); + assertTrue("missing resource", model.containsLiteral(null, null, l)); + assertFalse("extra resource", model.containsLiteral(S, P, 100L)); + } + + @Test + public void testContainsLiteral_Resource_Property_Object() { + Resource S = resource("S"); + Property P = property("P"); + + txnBegin(model); + model.addLiteral(S, P, tvObject); + txnCommit(model); + + assertTrue("missing resource", model.containsLiteral(S, P, tvObject)); + assertTrue("missing resource", model.containsLiteral(S, null, tvObject)); + assertTrue("missing resource", model.containsLiteral(null, P, tvObject)); + assertTrue("missing resource", + model.containsLiteral(null, null, tvObject)); + assertFalse("extra resource", model.containsLiteral(S, P, tvLitObj)); + } + + /** + * create Alt will + */ + @Test + public void testCreateAlt() { + + model.register(SL); + txnBegin(model); + final Alt tvAlt = model.createAlt(); + txnCommit(model); + + List stmts = model.listStatements().toList(); + assertEquals("found too many statements", 1, stmts.size()); + assertEquals("Wrong predicate", RDF.type, stmts.get(0).getPredicate()); + assertEquals("Wrong object", RDF.Alt, stmts.get(0).getObject()); + Assert.assertEquals("Wrong subject", tvAlt, stmts.get(0).getSubject()); + SL.assertHas("add", stmts.get(0)); + Assert.assertTrue("Alt should be anonymous", tvAlt.isAnon()); + Assert.assertTrue("Alt should be alt", tvAlt.isAlt()); + assertEquals("must be associated with model", model, tvAlt.getModel()); + + } + + @Test + public void testCreateAlt_String() { + model.register(SL); + txnBegin(model); + final Alt tvAlt = model.createAlt("http://exmple.com/A"); + txnCommit(model); + + List stmts = model.listStatements().toList(); + assertEquals("found too many statements", 1, stmts.size()); + assertEquals("Wrong predicate", RDF.type, stmts.get(0).getPredicate()); + assertEquals("Wrong object", RDF.Alt, stmts.get(0).getObject()); + Assert.assertEquals("Wrong subject", tvAlt, stmts.get(0).getSubject()); + SL.assertHas("add", stmts.get(0)); + Assert.assertEquals("http://exmple.com/A", tvAlt.getURI()); + Assert.assertTrue("Alt should be alt", tvAlt.isAlt()); + assertEquals("must be associated with model", model, tvAlt.getModel()); + + } + + @Test + public void testCreateBag() { + + model.register(SL); + txnBegin(model); + final Bag tvBag = model.createBag(); + txnCommit(model); + + List stmts = model.listStatements().toList(); + assertEquals("found too many statements", 1, stmts.size()); + assertEquals("Wrong predicate", RDF.type, stmts.get(0).getPredicate()); + assertEquals("Wrong object", RDF.Bag, stmts.get(0).getObject()); + Assert.assertEquals("Wrong subject", tvBag, stmts.get(0).getSubject()); + SL.assertHas("add", stmts.get(0)); + Assert.assertTrue("bag should be anonymous", tvBag.isAnon()); + Assert.assertTrue("bag should be bag", tvBag.isBag()); + assertEquals("must be associated with model", model, tvBag.getModel()); + } + + @Test + public void testCreateBag_String() { + model.register(SL); + txnBegin(model); + final Bag tvBag = model.createBag("http://exmple.com/B"); + txnCommit(model); + + List stmts = model.listStatements().toList(); + assertEquals("found too many statements", 1, stmts.size()); + assertEquals("Wrong predicate", RDF.type, stmts.get(0).getPredicate()); + assertEquals("Wrong object", RDF.Bag, stmts.get(0).getObject()); + Assert.assertEquals("Wrong subject", tvBag, stmts.get(0).getSubject()); + SL.assertHas("add", stmts.get(0)); + Assert.assertEquals("http://exmple.com/B", tvBag.getURI()); + Assert.assertTrue("bag should be bag", tvBag.isBag()); + + assertEquals("must be associated with model", model, tvBag.getModel()); + + } + + @Test + public void testLiteral_String() { + model.register(SL); + txnBegin(model); + Literal l = model.createLiteral("foo"); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Should not be in model", model.contains(null, null, l)); + } + + @Test + public void testCreateLiteralStatement_Resource_Property_boolean() { + model.register(SL); + txnBegin(model); + Statement s = model.createLiteralStatement(resource("S"), + property("P"), true); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, s.getModel()); + assertFalse("Should not be in model", model.contains(s)); + } + + @Test + public void testCreateLiteralStatement_Resource_Property_char() { + model.register(SL); + txnBegin(model); + Statement s = model.createLiteralStatement(resource("S"), + property("P"), 'c'); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, s.getModel()); + assertFalse("Should not be in model", model.contains(s)); + } + + @Test + public void testCreateLiteralStatement_Resource_Property_double() { + model.register(SL); + txnBegin(model); + Statement s = model.createLiteralStatement(resource("S"), + property("P"), 4.5d); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, s.getModel()); + assertFalse("Should not be in model", model.contains(s)); + } + + @Test + public void testCreateLiteralStatement_Resource_Property_float() { + model.register(SL); + txnBegin(model); + Statement s = model.createLiteralStatement(resource("S"), + property("P"), 4.5f); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, s.getModel()); + assertFalse("Should not be in model", model.contains(s)); + } + + @Test + public void testCreateLiteralStatement_Resource_Property_int() { + model.register(SL); + txnBegin(model); + Statement s = model.createLiteralStatement(resource("S"), + property("P"), 4); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, s.getModel()); + assertFalse("Should not be in model", model.contains(s)); + } + + @Test + public void testCreateLiteralStatement_Resource_Property_long() { + model.register(SL); + txnBegin(model); + Statement s = model.createLiteralStatement(resource("S"), + property("P"), 4L); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, s.getModel()); + assertFalse("Should not be in model", model.contains(s)); + } + + @Test + public void testCreateLiteralStatement_Resource_Property_Object() { + model.register(SL); + txnBegin(model); + Statement s = model.createLiteralStatement(resource("S"), + property("P"), tvObject); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, s.getModel()); + assertFalse("Should not be in model", model.contains(s)); + } + + @Test + public void testCreateProperty_String() { + model.register(SL); + txnBegin(model); + Property p = model.createProperty("ex:/test"); + txnCommit(model); + SL.assertEmpty(); + assertEquals("must be associated with model", model, p.getModel()); + assertFalse("Should not be in model", + model.contains(null, p, (RDFNode) null)); + assertEquals("ex:/test", p.getURI()); + } + + @Test + public void testCreateResource_Resource() { + Resource typ = resource("ex:/type"); + model.register(SL); + txnBegin(model); + Resource r = model.createResource(typ); + txnCommit(model); + SL.has("add", statement(r, RDF.type, typ)); + assertEquals("must be associated with model", model, r.getModel()); + assertTrue("Should be anonymous type", r.isAnon()); + assertTrue("Should be in model", model.contains(r, RDF.type, typ)); + } + + @Test + public void testCreateResource_String_Resource() { + Resource typ = resource("ex:/type"); + model.register(SL); + txnBegin(model); + Resource r = model.createResource("A", typ); + txnCommit(model); + SL.assertHas("add", statement(r, RDF.type, typ)); + assertEquals("must be associated with model", model, r.getModel()); + assertEquals("Wrong URI", "A", r.getURI()); + assertTrue("Should be in model", model.contains(r, RDF.type, typ)); + } + + @Test + public void testCreateSeq() { + + model.register(SL); + txnBegin(model); + final Seq tvSeq = model.createSeq(); + txnCommit(model); + + List stmts = model.listStatements().toList(); + assertEquals("found too many statements", 1, stmts.size()); + assertEquals("Wrong predicate", RDF.type, stmts.get(0).getPredicate()); + assertEquals("Wrong object", RDF.Seq, stmts.get(0).getObject()); + Assert.assertEquals("Wrong subject", tvSeq, stmts.get(0).getSubject()); + SL.assertHas("add", stmts.get(0)); + Assert.assertTrue("seq should be anonymous", tvSeq.isAnon()); + Assert.assertTrue("seq should be seq", tvSeq.isSeq()); + assertEquals("must be associated with model", model, tvSeq.getModel()); + } + + @Test + public void testCreateSeq_String() { + model.register(SL); + txnBegin(model); + final Seq tvSeq = model.createSeq("http://exmple.com/B"); + txnCommit(model); + + List stmts = model.listStatements().toList(); + assertEquals("found too many statements", 1, stmts.size()); + assertEquals("Wrong predicate", RDF.type, stmts.get(0).getPredicate()); + assertEquals("Wrong object", RDF.Seq, stmts.get(0).getObject()); + assertEquals("Wrong subject", tvSeq, stmts.get(0).getSubject()); + SL.assertHas("add", stmts.get(0)); + Assert.assertEquals("http://exmple.com/B", tvSeq.getURI()); + Assert.assertTrue("seq should be seq", tvSeq.isSeq()); + + assertEquals("must be associated with model", model, tvSeq.getModel()); + + } + + @Test + public void testCreateStatement_Resource_Property_String() { + Literal lit = ResourceFactory.createPlainLiteral("foo"); + model.register(SL); + txnBegin(model); + final Statement s = model.createStatement(resource("S"), property("P"), + "foo"); + txnCommit(model); + + assertFalse("found statements", model.listStatements().hasNext()); + SL.assertEmpty(); + assertSame("must be associated with model", model, s.getModel()); + assertFalse("must not be in model", model.contains(s)); + + assertEquals("Wrong subject", resource("S"), s.getSubject()); + assertEquals("Wrong predicate", property("P"), s.getPredicate()); + assertEquals("Wrong object", lit, s.getObject()); + } + + @Test + public void testCreateStatement_Resource_Property_String_boolean() { + RDFDatatype dt = new BaseDatatype( + "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"); + Literal lit = ResourceFactory.createTypedLiteral("foo", dt); + model.register(SL); + txnBegin(model); + final Statement s = model.createStatement(resource("S"), property("P"), + "foo", true); + txnCommit(model); + + assertFalse("found statements", model.listStatements().hasNext()); + SL.assertEmpty(); + assertSame("must be associated with model", model, s.getModel()); + assertFalse("must not be in model", model.contains(s)); + + assertEquals("Wrong subject", resource("S"), s.getSubject()); + assertEquals("Wrong predicate", property("P"), s.getPredicate()); + assertEquals("Wrong object", lit, s.getObject()); + } + + @Test + public void testCreateStatement_Resource_Property_String_String() { + Literal lit = literal("foo", "fr"); + model.register(SL); + txnBegin(model); + final Statement s = model.createStatement(resource("S"), property("P"), + "foo", "fr"); + txnCommit(model); + + assertFalse("found statements", model.listStatements().hasNext()); + SL.assertEmpty(); + assertSame("must be associated with model", model, s.getModel()); + assertFalse("must not be in model", model.contains(s)); + + assertEquals("Wrong subject", resource("S"), s.getSubject()); + assertEquals("Wrong predicate", property("P"), s.getPredicate()); + assertEquals("Wrong object", lit, s.getObject()); + + } + + /** + * statement is not in model + */ + @Test + public void testCreateStatement_Resource_Property_String_String_boolean() { + RDFDatatype dt = new BaseDatatype( + "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"); + Node n = NodeFactory.createLiteral("foo", "fr", true); + Literal lit = ResourceFactory.createTypedLiteral( + n.getLiteralLexicalForm(), n.getLiteralDatatype()); + model.register(SL); + txnBegin(model); + final Statement s = model.createStatement(resource("S"), property("P"), + "foo", "fr", true); + txnCommit(model); + + assertFalse("found statements", model.listStatements().hasNext()); + SL.assertEmpty(); + assertSame("must be associated with model", model, s.getModel()); + assertFalse("must not be in model", model.contains(s)); + assertEquals("Wrong subject", resource("S"), s.getSubject()); + assertEquals("Wrong predicate", property("P"), s.getPredicate()); + assertEquals(lit.getLexicalForm(), s.getObject().asLiteral() + .getLexicalForm()); + assertEquals("fr", s.getObject().asLiteral().getLanguage()); + // FIXME equality does not seem ot work with Datatype assertEquals( dt, + // s.getObject().asLiteral().getDatatype()); + assertEquals("Wrong object", lit, s.getObject()); + } + + @Test + public void testCreateTypedLiteral_boolean() { + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(true); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDboolean, + l.getDatatype()); + assertEquals("wrong value", true, l.getBoolean()); + } + + @Test + public void testCreateTypedLiteral_Calendar() { + Calendar c = Calendar.getInstance(); + XSDDateTime dt = new XSDDateTime(c); + + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(c); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDdateTime, + l.getDatatype()); + assertEquals("wrong value", dt, l.getValue()); + } + + @Test + public void testCreateTypedLiteral_char() { + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral('c'); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDstring, + l.getDatatype()); + assertEquals("wrong value", 'c', l.getChar()); + } + + @Test + public void testCreateTypedLiteral_double() { + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(4.5d); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDdouble, + l.getDatatype()); + assertEquals("wrong value", 4.5d, l.getDouble(), 0); + } + + @Test + public void testCreateTypedLiteral_float() { + float f = 4.5f; + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(f); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDfloat, + l.getDatatype()); + assertEquals("wrong value", f, l.getFloat(), 0); + } + + @Test + public void testCreateTypedLiteral_int() { + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(5); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDint, + l.getDatatype()); + assertEquals("wrong value", 5, l.getInt()); + } + + @Test + public void testCreateTypedLiteral_long() { + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(5L); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDlong, + l.getDatatype()); + assertEquals("wrong value", 5L, l.getLong()); + } + + @Test + public void testCreateTypedLiteral_Object() { + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(tvObject); + txnCommit(model); + + BaseDatatype dt = new AdhocDatatype(ModelHelper.LitTestObj.class); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", dt, l.getDatatype()); + assertEquals("wrong value", tvObject, l.getValue()); + } + + @Test + public void testCreateTypedLiteral_Object_String() { + RDFDatatype dt = new BaseDatatype("http://example.com/objType"); + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral(tvObject, + "http://example.com/objType"); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", dt.getURI(), l.getDatatype() + .getURI()); + assertEquals("wrong value", tvObject, l.getValue()); + } + + @Test + public void testCreateTypedLiteral_String() { + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral("foo"); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", XSDDatatype.XSDstring, + l.getDatatype()); + assertEquals("wrong value", "foo", l.getValue()); + } + + @Test + public void testCreateTypedLiteral_String_String() { + RDFDatatype dt = new BaseDatatype("http://example.com/strType"); + model.register(SL); + txnBegin(model); + final Literal l = model.createTypedLiteral("foo", + "http://example.com/strType"); + txnCommit(model); + + SL.assertEmpty(); + assertEquals("must be associated with model", model, l.getModel()); + assertFalse("Found literal in model", model.contains(null, null, l)); + assertEquals("wrong type of literal", dt.getURI(), l.getDatatype() + .getURI()); + assertEquals("wrong value", "foo", l.getString()); + assertEquals("wrong value", "foo^^http://example.com/strType", + l.getValue()); + } + + @Test + public void testGetAlt_Resource() { + model.register(SL); + + // test with no alt in the model + // should create alt in a different model + // should not add anything to the model + + // Does not require a transaction + Resource r = resource("O"); + + // get a non existant alt + Alt alt = model.getAlt(r); + + // verify alt settings + assertSame("must be of the model", model, alt.getModel()); + assertEquals("must be uri", r.getURI(), alt.getURI()); + assertFalse("model must not contain statement", model.listStatements() + .hasNext()); + assertTrue("must be an alt", alt.isAlt()); + SL.assertEmpty(); + + // add the alt to the model + txnBegin(model); + model.add(alt, RDF.type, RDF.Alt); + txnCommit(model); + SL.clear(); + + Alt alt2 = model.getAlt(r); + SL.assertEmpty(); + assertSame("must be of the model", model, alt2.getModel()); + assertEquals("must be uri", r, alt2.getURI()); + assertTrue("must be an alt", alt2.isAlt()); + } + + @Test + public void testGetAlt_String() { + model.register(SL); + + // test with no alt in the model + // should create alt in a different model + // should not add anything to the model + + // get a non existant bag + Alt alt = model.getAlt("O"); + + // verify alt settings + assertSame("must be of the model", model, alt.getModel()); + assertEquals("must be uri", "O", alt.getURI()); + assertFalse("model must not contain statement", model.listStatements() + .hasNext()); + assertTrue("must be an alt", alt.isAlt()); + SL.assertEmpty(); + + // add the alt to the model + txnBegin(model); + model.add(alt, RDF.type, RDF.Alt); + txnCommit(model); + SL.clear(); + + Alt alt2 = model.getAlt("O"); + SL.assertEmpty(); + assertSame("must be of the model", model, alt2.getModel()); + assertEquals("must be uri", "O", alt2.getURI()); + assertTrue("must be an alt", alt2.isAlt()); + } + + @Test + public void testGetBag_Resource() { + model.register(SL); + + // test whith no bag in the model + // should create bag in a different model + // should not add anything to the model + + // Does not require a transaction + Resource r = resource("O"); + + // get a non existant bag + Bag bag = model.getBag(r); + + // verify bag settings + assertSame("test", r.getModel(), bag.getModel()); + assertSame("must be of the model", model, bag.getModel()); + assertEquals("must be uri", r.getURI(), bag.getURI()); + assertFalse("model must not contain statement", model.listStatements() + .hasNext()); + assertTrue("must be a bag", bag.isBag()); + SL.assertEmpty(); + + // add the bag to the model + txnBegin(model); + model.add(bag, RDF.type, RDF.Bag); + // bag.add(false); + txnCommit(model); + // SL.clear(); + + r.getModel().write(System.out, "TURTLE"); + + Bag bag2 = model.getBag(r); + // SL.assertEmpty(); + assertSame("must be of the model", model, bag2.getModel()); + assertEquals("must be uri", r.getURI(), bag2.getURI()); + assertTrue("must be a bag", bag2.isBag()); + + } + + @Test + public void testGetBag_String() { + model.register(SL); + + // get a non-existant bag + Bag bag = model.getBag("O"); + + // verify bag settings + assertSame("must not be of the model", model, bag.getModel()); + assertEquals("must be uri", "O", bag.getURI()); + assertFalse("model must not contain statement", model.listStatements() + .hasNext()); + assertTrue("must be a bag", bag.isBag()); + SL.assertEmpty(); + + // add the bag to the model + txnBegin(model); + model.add(bag, RDF.type, RDF.Bag); + txnCommit(model); + SL.clear(); + + // read it back + Bag bag2 = model.getBag("O"); + SL.assertEmpty(); + assertSame("must be of the model", model, bag2.getModel()); + assertEquals("must be uri", "O", bag2.getURI()); + assertTrue("must be a bag", bag2.isBag()); + } + + @Test + public void testGetProperty_String() { + model.register(SL); + + // get a non-existant property + Property p = model.getProperty("P"); + + // verify bag settings + assertSame("must be of the model", model, p.getModel()); + assertEquals("must be uri", "P", p.getURI()); + assertFalse("model must not contain statement", model.listStatements() + .hasNext()); + SL.assertEmpty(); + + // add the bag to the model + txnBegin(model); + model.add(p, RDF.type, RDF.Property); + txnCommit(model); + SL.clear(); + + // read it back + Property p2 = model.getProperty("P"); + SL.assertEmpty(); + assertSame("must be of the model", model, p2.getModel()); + assertEquals("must be uri", "P", p2.getURI()); + } + + @Test + public void testGetRDFNode_Node() { + + // create the node + txnBegin(model); + RDFNode o = model.getRDFNode(NodeCreateUtils.create("O")); + txnCommit(model); + + assertEquals("must be of the model", model, o.getModel()); + assertFalse("model must not contain the resource", model + .listStatements().hasNext()); + } + + @Test + public void testGetSeq_Resource() { + model.register(SL); + + // test with no alt in the model + // should create alt in a different model + // should not add anything to the model + + // Does not require a transaction + Resource r = resource("O"); + + // get a non existant seq + Seq seq = model.getSeq(r); + + // verify bag settings + assertSame("must be of the model", model, seq.getModel()); + assertEquals("must be uri", r.getURI(), seq.getURI()); + assertFalse("model must not contain statement", model.listStatements() + .hasNext()); + assertTrue("must be a seq", seq.isSeq()); + SL.assertEmpty(); + + // add the seq to the model + txnBegin(model); + model.add(seq, RDF.type, RDF.Bag); + txnCommit(model); + SL.clear(); + + Seq seq2 = model.getSeq(r); + SL.assertEmpty(); + assertSame("must be of the model", model, seq2.getModel()); + assertEquals("must be uri", r, seq2.getURI()); + assertTrue("must be a seq", seq2.isSeq()); + + } + + @Test + public void testGetSeq_String() { + model.register(SL); + + // test with no alt in the model + // should create alt in a different model + // should not add anything to the model + + // get a non existant bag + Seq seq = model.getSeq("O"); + + // verify seq settings + assertSame("must be of the model", model, seq.getModel()); + assertEquals("must be uri", "O", seq.getURI()); + assertFalse("model must not contain statement", model.listStatements() + .hasNext()); + assertTrue("must be a seq", seq.isSeq()); + SL.assertEmpty(); + + // add the seq to the model + txnBegin(model); + model.add(seq, RDF.type, RDF.Bag); + txnCommit(model); + SL.clear(); + + Seq seq2 = model.getSeq("O"); + SL.assertEmpty(); + assertSame("must be of the model", model, seq2.getModel()); + assertEquals("must be uri", "O", seq2.getURI()); + assertTrue("must be a seq", seq2.isSeq()); + + } + + @Test + public void testListLiteralStatements_Resource_Property_boolean() { + boolean v1 = true; + boolean v2 = false; + Property p = property("P"); + txnBegin(model); + modelAdd(model, "S P O; S P2 O2"); + model.addLiteral(resource("S"), p, v1); + model.addLiteral(resource("S2"), p, v2); + txnCommit(model); + + assertEquals(1, model.listLiteralStatements(null, null, v1).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S2"), null, v1) + .toList().size()); + + assertEquals(1, model.listLiteralStatements(null, null, v2).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S"), null, v2) + .toList().size()); + + } + + @Test + public void testListLiteralStatements_Resource_Property_char() { + char v1 = 'c'; + char v2 = 'd'; + Property p = property("P"); + txnBegin(model); + modelAdd(model, "S P O; S P2 O2"); + model.addLiteral(resource("S"), p, v1); + model.addLiteral(resource("S2"), p, v2); + txnCommit(model); + + assertEquals(1, model.listLiteralStatements(null, null, v1).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S2"), null, v1) + .toList().size()); + + assertEquals(1, model.listLiteralStatements(null, null, v2).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S"), null, v2) + .toList().size()); + + } + + @Test + public void testListLiteralStatements_Resource_Property_double() { + double v1 = 4.5; + double v2 = 5.4; + Property p = property("P"); + txnBegin(model); + modelAdd(model, "S P O; S P2 O2"); + model.addLiteral(resource("S"), p, v1); + model.addLiteral(resource("S2"), p, v2); + txnCommit(model); + + assertEquals(1, model.listLiteralStatements(null, null, v1).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S2"), null, v1) + .toList().size()); + + assertEquals(1, model.listLiteralStatements(null, null, v2).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S"), null, v2) + .toList().size()); + + } + + @Test + public void testListLiteralStatements_Resource_Property_float() { + float v1 = 4.5f; + float v2 = 5.4f; + Property p = property("P"); + txnBegin(model); + modelAdd(model, "S P O; S P2 O2"); + model.addLiteral(resource("S"), p, v1); + model.addLiteral(resource("S2"), p, v2); + txnCommit(model); + + assertEquals(1, model.listLiteralStatements(null, null, v1).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S2"), null, v1) + .toList().size()); + + assertEquals(1, model.listLiteralStatements(null, null, v2).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S"), null, v2) + .toList().size()); + + } + + @Test + public void testListLiteralStatements_Resource_Property_long() { + long v1 = 4L; + long v2 = 5L; + Property p = property("P"); + txnBegin(model); + modelAdd(model, "S P O; S P2 O2"); + model.addLiteral(resource("S"), p, v1); + model.addLiteral(resource("S2"), p, v2); + txnCommit(model); + + assertEquals(1, model.listLiteralStatements(null, null, v1).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S2"), null, v1) + .toList().size()); + + assertEquals(1, model.listLiteralStatements(null, null, v2).toList() + .size()); + assertEquals(0, model.listLiteralStatements(resource("S"), null, v2) + .toList().size()); + + } + + @Test + public void testListResourcesWithProperty_Property_boolean() { + boolean v1 = true; + boolean v2 = false; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + txnBegin(model); + model.addLiteral(r1, p, v1); + model.addLiteral(r1, p, v2); + model.addLiteral(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listResourcesWithProperty(p, v1).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v1).toList().size()); + + assertEquals(1, model.listResourcesWithProperty(p, v2).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v2).toList().size()); + + } + + @Test + public void testListResourcesWithProperty_Property_char() { + char v1 = 'c'; + char v2 = 'd'; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + txnBegin(model); + model.addLiteral(r1, p, v1); + model.addLiteral(r1, p, v2); + model.addLiteral(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listResourcesWithProperty(p, v1).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v1).toList().size()); + + assertEquals(1, model.listResourcesWithProperty(p, v2).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v2).toList().size()); + + } + + @Test + public void testListResourcesWithProperty_Property_double() { + double v1 = 4.5; + double v2 = 5.4; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + txnBegin(model); + model.addLiteral(r1, p, v1); + model.addLiteral(r1, p, v2); + model.addLiteral(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listResourcesWithProperty(p, v1).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v1).toList().size()); + + assertEquals(1, model.listResourcesWithProperty(p, v2).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v2).toList().size()); + + } + + @Test + public void testListResourcesWithProperty_Property_float() { + float v1 = 4.5f; + float v2 = 5.4f; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + txnBegin(model); + model.addLiteral(r1, p, v1); + model.addLiteral(r1, p, v2); + model.addLiteral(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listResourcesWithProperty(p, v1).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v1).toList().size()); + + assertEquals(1, model.listResourcesWithProperty(p, v2).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v2).toList().size()); + + } + + @Test + public void testListResourcesWithProperty_Property_long() { + long v1 = 4l; + long v2 = 5l; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + txnBegin(model); + model.addLiteral(r1, p, v1); + model.addLiteral(r1, p, v2); + model.addLiteral(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listResourcesWithProperty(p, v1).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v1).toList().size()); + + assertEquals(1, model.listResourcesWithProperty(p, v2).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v2).toList().size()); + + } + + @Test + public void testListResourcesWithProperty_Property_Object() { + Object v1 = tvObject; + Object v2 = tvLitObj; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + txnBegin(model); + model.addLiteral(r1, p, v1); + model.addLiteral(r1, p, v2); + model.addLiteral(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listResourcesWithProperty(p, v1).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v1).toList().size()); + + assertEquals(1, model.listResourcesWithProperty(p, v2).toList().size()); + assertEquals(0, model.listResourcesWithProperty(p2, v2).toList().size()); + + } + + @Test + public void testListStatements_Resource_Property_String() { + String v1 = "foo"; + String v2 = "bar"; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + txnBegin(model); + model.add(r1, p, v1); + model.add(r1, p, v2); + model.add(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listStatements(null, p, v1).toList().size()); + assertEquals(1, model.listStatements(r1, p, v1).toList().size()); + assertEquals(1, model.listStatements(r2, p, v1).toList().size()); + + assertEquals(0, model.listStatements(null, p2, v2).toList().size()); + assertEquals(0, model.listStatements(r1, p2, v2).toList().size()); + assertEquals(0, model.listStatements(r2, p2, v2).toList().size()); + + } + + @Test + public void testListStatements_Resource_Property_String_String() { + String v = "foo"; + + Property p = property("P"); + + Resource r = resource("S"); + + txnBegin(model); + model.add(r, p, v, "en"); + model.add(r, p, v, "fr"); + txnCommit(model); + + assertEquals(1, model.listStatements(r, p, v, "en").toList().size()); + assertEquals(1, model.listStatements(r, p, v, "fr").toList().size()); + assertEquals(2, model.listStatements(r, p, v, null).toList().size()); + assertEquals(1, model.listStatements(r, p, null, "en").toList().size()); + assertEquals(1, model.listStatements(r, null, v, "en").toList().size()); + assertEquals(1, model.listStatements(null, p, v, "fr").toList().size()); + assertEquals(2, model.listStatements(null, null, null, null).toList() + .size()); + } + + @Test + public void testListSubjectsWithProperty_Property_String() { + String v1 = "foo"; + String v2 = "bar"; + Property p = property("P"); + Property p2 = property("P2"); + + Resource r1 = resource("S"); + Resource r2 = resource("S1"); + + txnBegin(model); + model.add(r1, p, v1); + model.add(r1, p, v2); + model.add(r2, p, v1); + txnCommit(model); + + assertEquals(2, model.listSubjectsWithProperty(p, v1).toList().size()); + assertEquals(0, model.listSubjectsWithProperty(p2, v1).toList().size()); + + assertEquals(1, model.listSubjectsWithProperty(p, v2).toList().size()); + assertEquals(0, model.listSubjectsWithProperty(p2, v2).toList().size()); + + } + + @Test + public void testListSubjectsWithProperty_Property_String_String() { + String v = "foo"; + + Property p = property("P"); + + Resource r = resource("S"); + + txnBegin(model); + model.add(r, p, v, "en"); + model.add(r, p, v, "fr"); + model.add(r, p, v, (String) null); + model.add(r, p, v); + txnCommit(model); + + assertEquals(1, model.listSubjectsWithProperty(p, v, "en").toList() + .size()); + assertEquals(1, model.listSubjectsWithProperty(p, v, "fr").toList() + .size()); + assertEquals(0, model.listSubjectsWithProperty(p, v, "es").toList() + .size()); + assertEquals(1, model.listSubjectsWithProperty(p, v, null).toList() + .size()); + } + + @Test + public void testRemove_Model() { + + txnBegin(model); + modelAdd(model, "S P O; S2 P2 O2; S P2 O"); + txnCommit(model); + + Model model2 = memModel("S P O; S2 P2 O2"); + + model.register(SL); + txnBegin(model); + assertEquals("Remove model should return model", model, + model.remove(model2)); + txnCommit(model); + + SL.assertHas("removeModel", model2); + List lst = model.listStatements().toList(); + assertEquals("Wrong statement count", 1, lst.size()); + assertEquals("incorrect statemnt remains", statement("S P2 O"), + lst.get(0)); + } + + @Test + public void testRemove_Resource_Property_RDFNode() { + + txnBegin(model); + modelAdd(model, "S P O; S2 P2 O2; S P2 O"); + txnCommit(model); + + model.register(SL); + txnBegin(model); + assertEquals("Remove model should return model", model, + model.remove(resource("S"), property("P"), rdfNode("O"))); + txnCommit(model); + + SL.assertHas("remove", statement("S P O")); + + List lst = model.listStatements().toList(); + assertEquals("Wrong statement count", 2, lst.size()); + assertTrue("statement (S2 P2 O2) missing", + lst.contains(statement("S2 P2 O2"))); + assertTrue("statement (S P2 O) missing", + lst.contains(statement("S P2 O"))); + + } + + @Test + public void testRemove_StmtIterator() { + + txnBegin(model); + modelAdd(model, "S P O; S2 P2 O2; S P2 O"); + txnCommit(model); + + Statement[] stmts = { statement("S2 P2 O2"), statement("S P O") }; + StmtIterator si = new StmtIteratorImpl(Arrays.asList(stmts).iterator()); + + model.register(SL); + txnBegin(model); + assertEquals("Remove model should return model", model, + model.remove(si)); + txnCommit(model); + + SL.assertContains("removeIterator"); + @SuppressWarnings("unchecked") + List lst = (List) SL.from("removeIterator") + .next(); + assertTrue("missing S P O", lst.contains(statement("S P O"))); + assertTrue("missing S2 P2 O2", lst.contains(statement("S2 P2 O2"))); + + lst = model.listStatements().toList(); + assertEquals("Wrong statement count", 1, lst.size()); + assertTrue("statement (S P2 O) missing", + lst.contains(statement("S P2 O"))); + + } +// @Test +// public void testChangedListener() { +// final ChangedListener CL = new ChangedListener(); +// model.register(CL); +// Assert.assertFalse(CL.hasChanged()); +// model.add(statement("S P O")); +// Assert.assertTrue(CL.hasChanged()); +// Assert.assertFalse(CL.hasChanged()); +// model.remove(statement("ab CD ef")); +// Assert.assertTrue(CL.hasChanged()); +// model.add(statements("gh IJ kl")); +// Assert.assertTrue(CL.hasChanged()); +// model.remove(statements("mn OP qr")); +// Assert.assertTrue(CL.hasChanged()); +// model.add(asIterator(statements("st UV wx"))); +// Assert.assertTrue(CL.hasChanged()); +// Assert.assertFalse(CL.hasChanged()); +// model.remove(asIterator(statements("yz AB cd"))); +// Assert.assertTrue(CL.hasChanged()); +// model.add(modelWithStatements(getModelProducer(), "ef GH ij")); +// Assert.assertTrue(CL.hasChanged()); +// model.remove(modelWithStatements(getModelProducer(), "kl MN op")); +// Assert.assertTrue(CL.hasChanged()); +// model.add(Arrays.asList(statements("rs TU vw"))); +// Assert.assertTrue(CL.hasChanged()); +// model.remove(Arrays.asList(statements("xy wh q"))); +// Assert.assertTrue(CL.hasChanged()); +// } + + + + // / FIXME END OF EDIT + +// @Test +// public void testContains() { +// testContains(false, "", "x"); +// testContains(false, "a R b", "x"); +// testContains(false, "a R b; c P d", "x"); +// /* */ +// testContains(false, "a R b", "z"); +// /* */ +// testContains(true, "x R y", "x"); +// testContains(true, "a P b", "P"); +// testContains(true, "i Q j", "j"); +// testContains(true, "x R y; a P b; i Q j", "y"); +// /* */ +// testContains(true, "x R y; a P b; i Q j", "y"); +// testContains(true, "x R y; a P b; i Q j", "R"); +// testContains(true, "x R y; a P b; i Q j", "a"); +// } +// +// @Test +// public void testCreateResourceFromNode() { +// RDFNode S = model.getRDFNode(NodeCreateUtils.create("spoo:S")); +// assertInstanceOf(Resource.class, S); +// assertEquals("spoo:S", ((Resource) S).getURI()); +// } +// +// @Test +// public void testCreateLiteralFromNode() { +// RDFNode S = model.getRDFNode(NodeCreateUtils.create("42")); +// assertInstanceOf(Literal.class, S); +// assertEquals("42", ((Literal) S).getLexicalForm()); +// } +// +// @Test +// public void testCreateBlankFromNode() { +// RDFNode S = model.getRDFNode(NodeCreateUtils.create("_Blank")); +// assertInstanceOf(Resource.class, S); +// assertEquals(new AnonId("_Blank"), ((Resource) S).getId()); +// } +// +// /** +// * Always retuns a value even if the property is no in the model. +// */ +// @Test +// public void testGetPropertyURI() { +// modelAdd(model, "x P a; x P b; x R c"); +// Assert.assertNotNull(model.getProperty(resource("P").getURI())); +// Assert.assertNotNull(model.getProperty(resource("R").getURI())); +// Assert.assertNotNull(model.getProperty(resource("x").getURI())); +// } +// +// @Test +// public void testToStatement() { +// Triple t = triple("a P b"); +// Statement s = model.asStatement(t); +// assertEquals(node("a"), s.getSubject().asNode()); +// assertEquals(node("P"), s.getPredicate().asNode()); +// assertEquals(node("b"), s.getObject().asNode()); +// } +// +// @Test +// public void testAsRDF() { +// verifyPresentAsRDFNode(node("a"), Resource.class); +// verifyPresentAsRDFNode(node("17"), Literal.class); +// verifyPresentAsRDFNode(node("_b"), Resource.class); +// } +// +// private void verifyPresentAsRDFNode(Node n, +// Class nodeClass) { +// RDFNode r = model.asRDFNode(n); +// assertSame(n, r.asNode()); +// assertInstanceOf(nodeClass, r); +// } +// +// @Test +// public void testURINodeAsResource() { +// Node n = node("a"); +// Resource r = model.wrapAsResource(n); +// assertSame(n, r.asNode()); +// } +// +// @Test +// public void testLiteralNodeAsResourceFails() { +// try { +// model.wrapAsResource(node("17")); +// fail("should fail to convert literal to Resource"); +// } catch (UnsupportedOperationException e) { +// // expected +// } +// } +// +// /** +// * Test cases for RemoveSPO(); each entry is a triple (add, remove, result). +// *
    +// *
  • add - the triples to add to the graph to start with +// *
  • remove - the pattern to use in the removal +// *
  • result - the triples that should remain in the graph +// *
+// */ +// protected String[][] cases = { { "x R y", "x R y", "" }, +// { "x R y; a P b", "x R y", "a P b" }, +// { "x R y; a P b", "?? R y", "a P b" }, +// { "x R y; a P b", "x R ??", "a P b" }, +// { "x R y; a P b", "x ?? y", "a P b" }, +// { "x R y; a P b", "?? ?? ??", "" }, +// { "x R y; a P b; c P d", "?? P ??", "x R y" }, +// { "x R y; a P b; x S y", "x ?? ??", "a P b" }, }; +// +// /** +// * Test that remove(s, p, o) works, in the presence of inferencing graphs +// * that mean emptyness isn't available. This is why we go round the houses +// * and test that expected ~= initialContent + addedStuff - removed - +// * initialContent. +// */ +// @Test +// public void testRemoveSPO() { +// ModelCom mc = (ModelCom) ModelFactory.createDefaultModel(); +// for (int i = 0; i < cases.length; i += 1) +// for (int j = 0; j < 3; j += 1) { +// Model content = getModelProducer().newModel(); +// Model baseContent = copy(content); +// modelAdd(content, cases[i][0]); +// Triple remove = triple(cases[i][1]); +// Node s = remove.getSubject(), p = remove.getPredicate(), o = remove +// .getObject(); +// Resource S = (Resource) (s.equals(Node.ANY) ? null : mc +// .getRDFNode(s)); +// Property P = ((p.equals(Node.ANY) ? null : mc.getRDFNode(p).as( +// Property.class))); +// RDFNode O = o.equals(Node.ANY) ? null : mc.getRDFNode(o); +// Model expected = modelWithStatements(getModelProducer(), +// cases[i][2]); +// content.removeAll(S, P, O); +// Model finalContent = copy(content).remove(baseContent); +// assertIsoModels(cases[i][1], expected, finalContent); +// } +// } +// +// protected Model copy(Model m) { +// return getModelProducer().newModel().add(m); +// } +// +// @Test +// public void testAddLiteralByStatement() { +// final Literal L = model.createTypedLiteral(210); +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Statement s = model.createStatement(S, RDF.value, L); +// Assert.assertTrue(model.add(s).contains(s)); +// Assert.assertTrue(model.contains(S, RDF.value)); +// } +// +// +// @Test +// public void testAddLiteralByte() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// model.addLiteral(S, P, tvByte); +// Assert.assertTrue(model.containsLiteral(S, P, tvByte)); +// } +// +// @Test +// public void testAddLiteralChar() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// model.addLiteral(S, P, tvChar); +// Assert.assertTrue(model.containsLiteral(S, P, tvChar)); +// } +// +// @Test +// public void testAddLiteralDouble() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// model.addLiteral(S, P, tvDouble); +// Assert.assertTrue(model.containsLiteral(S, P, tvDouble)); +// } +// +// @Test +// public void testAddLiteralFloat() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// model.addLiteral(S, P, tvFloat); +// Assert.assertTrue(model.containsLiteral(S, P, tvFloat)); +// } +// +// @Test +// public void testAddLiteralInt() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// model.addLiteral(S, P, tvInt); +// Assert.assertTrue(model.containsLiteral(S, P, tvInt)); +// } +// +// +// @Test +// public void testAddLiteralLong() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// model.addLiteral(S, P, tvLong); +// Assert.assertTrue(model.containsLiteral(S, P, tvLong)); +// } +// + +// // public void testAddContainsObject() +// // { +// // LitTestObj O = new LitTestObj( 12345 ); +// // model.addLiteral( S, P, O ); +// // assertTrue( model.containsLiteral( S, P, O ) ); +// // } +// + +// +// @Test +// public void testAddLiteralShort() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// model.addLiteral(S, P, tvShort); +// Assert.assertTrue(model.containsLiteral(S, P, tvShort)); +// } +// +// @Test +// public void testAddDuplicateStatementLeavesSizeSame() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// final Statement s = model.createStatement(S, RDF.value, "something"); +// model.add(s); +// final long size = model.size(); +// model.add(s); +// Assert.assertEquals(size, model.size()); +// } +// +// @Test +// public void testEmpty() { +// final Resource S = model.createResource("http://nowhere.man/subject"); +// final Property P = model.createProperty("http://nowhere.man/predicate"); +// Assert.assertTrue("Model should be empty", model.isEmpty()); +// Assert.assertFalse(model.containsLiteral(S, P, tvBoolean)); +// Assert.assertFalse(model.contains(S, P, model.createResource())); +// Assert.assertFalse(model.containsLiteral(S, P, tvByte)); +// Assert.assertFalse(model.containsLiteral(S, P, tvShort)); +// Assert.assertFalse(model.containsLiteral(S, P, tvInt)); +// Assert.assertFalse(model.containsLiteral(S, P, tvLong)); +// Assert.assertFalse(model.containsLiteral(S, P, tvChar)); +// Assert.assertFalse(model.containsLiteral(S, P, tvFloat)); +// Assert.assertFalse(model.containsLiteral(S, P, tvDouble)); +// Assert.assertFalse(model.containsLiteral(S, P, new LitTestObj(12345))); +// Assert.assertFalse(model.contains(S, P, "test string")); +// Assert.assertFalse(model.contains(S, P, "test string", "en")); +// } +// +// @Test +// public void testRemoveStatementByIterator() { +// Statement[] stmts = statements("moon orbits earth; earth orbits sun"); +// StmtIterator iter = new StmtIteratorImpl(Arrays.asList(stmts) +// .iterator()); +// model.remove(iter); +// for (Statement s : stmts) { +// assertFalse(String.format("%s is still in model", s), +// model.contains(s)); +// } +// assertEquals(0, model.size()); +// } +// +// @Test +// public void testRemoveModel() { +// final Model model2 = getModelProducer().newModel(); +// modelAdd(model, "a P b; c P d; x Q 1; y Q 2"); +// model2.add(model).remove(model); +// Assert.assertEquals(0, model2.size()); +// Assert.assertFalse(model2.listStatements().hasNext()); +// } +// +// @Test +// public void testRemoveModelPartial() { +// Assert.assertEquals("precondition: model must be empty", 0, +// model.size()); +// final Model A = modelWithStatements(getModelProducer(), +// "clouds offer rain; trees offer shelter"); +// final Model B = modelWithStatements(getModelProducer(), +// "x R y; y Q z; z P x"); +// model.add(A); +// assertIsoModels(A, model); +// model.add(B); +// model.remove(A); +// assertIsoModels(B, model); +// model.remove(B); +// assertEquals(0, model.size()); +// } +// +// private void testContains(final boolean yes, final String facts, +// final String resource) { +// final Model m = modelWithStatements(getModelProducer(), facts); +// final RDFNode r = rdfNode(resource); +// if (m.containsResource(r) != yes) { +// Assert.fail(String.format("[%s] should%s contain %s", facts, +// (yes ? "" : " not"), resource)); +// } +// } +// +// @Test +// public void testContainsWithNull() { +// testCWN(false, "", null, null, null); +// testCWN(true, "x R y", null, null, null); +// testCWN(false, "x R y", null, null, res("z")); +// testCWN(true, "x RR y", res("x"), prop("RR"), null); +// testCWN(true, "a BB c", null, prop("BB"), res("c")); +// testCWN(false, "a BB c", null, prop("ZZ"), res("c")); +// } +// +// private void testCWN(final boolean yes, final String facts, +// final Resource S, final Property P, final RDFNode O) { +// Model m = modelWithStatements(getModelProducer(), facts); +// if (m.contains(S, P, O) != yes) { +// Assert.fail(String.format("[%s] should%s contain [%s, %s, %s]", +// facts, (yes ? "" : " not"), S, P, O)); +// } +// Assert.assertEquals(yes, modelWithStatements(getModelProducer(), facts) +// .contains(S, P, O)); +// } +// +// // FIXME move this to modelCon specific test +// @Test +// public void testModelComContainsSPcallsContainsSPO() { +// final Graph g = Factory.createDefaultGraph(); +// final boolean[] wasCalled = { false }; +// // FIXME change to dynamic proxy +// final Model m = new ModelCom(g) { +// @Override +// public boolean contains(final Resource s, final Property p, +// final RDFNode o) { +// wasCalled[0] = true; +// return super.contains(s, p, o); +// } +// }; +// Assert.assertFalse(m.contains(resource("r"), property("p"))); +// Assert.assertTrue("contains(S,P) should call contains(S,P,O)", +// wasCalled[0]); +// } +// +// /** +// * test moving things between models +// */ +// @Test +// public void testAddingStatementsChangesModel() { +// final Resource S = ResourceFactory.createResource(); +// final Property P = ResourceFactory +// .createProperty("http://example.com/property"); +// final Resource O = ResourceFactory.createResource(); +// final Model model2 = getModelProducer().newModel(); +// final Statement stmt = model.createStatement(S, P, O); +// Assert.assertEquals(model, stmt.getModel()); +// Assert.assertEquals(0, model.size()); +// Assert.assertEquals(model, stmt.getSubject().getModel()); +// Assert.assertEquals(model, stmt.getPredicate().getModel()); +// Assert.assertEquals(model, stmt.getObject().getModel()); +// model.add(stmt); +// Assert.assertEquals(1, model.size()); +// Assert.assertEquals(model, stmt.getSubject().getModel()); +// Assert.assertEquals(model, stmt.getPredicate().getModel()); +// Assert.assertEquals(model, stmt.getObject().getModel()); +// model2.add(stmt); +// Assert.assertEquals(1, model.size()); +// Assert.assertEquals(model, stmt.getSubject().getModel()); +// Assert.assertEquals(model, stmt.getPredicate().getModel()); +// Assert.assertEquals(model, stmt.getObject().getModel()); +// Assert.assertEquals(1, model2.size()); +// final Statement stmt2 = model2.listStatements().next(); +// Assert.assertEquals(model2, stmt2.getSubject().getModel()); +// Assert.assertEquals(model2, stmt2.getPredicate().getModel()); +// Assert.assertEquals(model2, stmt2.getObject().getModel()); +// } +// +// /* +// * try { Statement stmt; StmtIterator sIter; // +// * System.out.println("Beginning " + test); +// * +// * try { n=100; Resource r11 = m1.createResource(); // Resource r12 = +// * m2.createResource(new ResTestObjF()); long size1 = m1.size(); long size2 +// * = m2.size(); +// * +// * r11.addLiteral(RDF.value, 1); n++; if (! (m1.size() == ++size1)) +// * error(test, n); n++; if (! (m2.size() == size2)) error(test,n); +// * +// * // stmt = m2.createStatement(r11, RDF.value, r12); // n++; if (! +// * (stmt.getSubject().getModel() == m2)) error(test,n); // n++; if (! +// * (stmt.getResource().getModel() == m2)) error(test,n); // // m1.add(stmt); +// * // n++; if (! (m1.size() == ++size1)) error(test, n); // n++; if (! +// * (m2.size() == size2)) error(test,n); // // sIter = m1.listStatements( new +// * SimpleSelector( r11, RDF.value, r12 ) ); // n++; if (! sIter.hasNext()) +// * error(test, n); // n++; stmt = sIter.nextStatement(); // n++; if (! +// * (stmt.getSubject().getModel() == m1)) error(test,n); // n++; if (! +// * (stmt.getResource().getModel() == m1)) error(test,n); // sIter.close(); +// * +// * +// * } catch (Exception e) { error(test, n, e); } } catch (Exception e) { +// * logger.error( "test " + test + "[" + n + "]", e ); errors = true; } // +// * System.out.println("End of " + test); } +// */ +// +// @Test +// public void testGetAlt() { +// final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 160; +// model.createAlt(uri); +// final Alt a = model.getAlt(uri); +// Assert.assertEquals(uri, a.getURI()); +// Assert.assertTrue(model.contains(a, RDF.type, RDF.Alt)); +// } +// +// // FIXME move to resourec factory test +// // public void testGetResourceFactory() +// // { +// // String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a" + 120; +// // Resource r = model.getResource( uri, new ResTestObjF() ); +// // assertEquals( uri, r.getURI() ); +// // } +// +// @Test +// public void testGetBag() { +// final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 150; +// model.createBag(uri); +// final Bag b = model.getBag(uri); +// Assert.assertEquals(uri, b.getURI()); +// Assert.assertTrue(model.contains(b, RDF.type, RDF.Bag)); +// } +// +// @Test +// public void testGetPropertyOneArg() { +// final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a" + 130; +// final Property p = model.getProperty(uri); +// Assert.assertEquals(uri, p.getURI()); +// } +// +// @Test +// public void testGetPropertyTwoArgs() { +// final String ns = "http://aldabaran.hpl.hp.com/rdf/test4/a" + 140 + "/"; +// final Property p = model.getProperty(ns, "foo"); +// Assert.assertEquals(ns + "foo", p.getURI()); +// } +// +// @Test +// public void testGetSeq() { +// final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 170; +// model.createSeq(uri); +// final Seq s = model.getSeq(uri); +// Assert.assertEquals(uri, s.getURI()); +// Assert.assertTrue(model.contains(s, RDF.type, RDF.Seq)); +// } +// +// @Test +// public void testRemoveModelWithReifications() { +// // final Model target = getModelProducer().newModel(); +// // addReification(target, "x", "S P O"); +// // addReification(target, "y", "A P B"); +// // final Model remove = getModelProducer().newModel(); +// // addReification(remove, "y", "A P B"); +// // final Model answer = getModelProducer().newModel(); +// // addReification(answer, "x", "S P O"); +// // target.remove(remove); +// // assertIsoModels(answer, target); +// } +// +// @Test +// public void testRemoveModelSelf() { +// final Model m = modelWithStatements(getModelProducer(), +// "they sing together; he sings alone"); +// m.remove(m); +// assertEquals("", 0, m.size()); +// } +// +// private void testContains(final Model m, final Statement[] statements) { +// for (final Statement statement : statements) { +// Assert.assertTrue(String.format("%s should be here", statement), +// m.contains(statement)); +// } +// } +// +// @Test +// public void testRemoveStatementArray() { +// Statement[] remove = statements("moon orbits earth; earth orbits sun"); +// Statement[] keep = statements("I drink tea; you drink coffee"); +// model.add(remove).add(keep); +// testContains(model, remove); +// testContains(model, keep); +// +// model.remove(remove); +// testOmits(model, remove); +// testContains(model, keep); +// } +// +// @Test +// public void testCreatingStatementDoesNotAddToModel() { +// assertEquals("Model should be empty", 0, model.size()); +// model.createStatement(resource("a"), property("b"), resource("c")); +// assertEquals("Model should be empty", 0, model.size()); +// } +// +// @Test +// public void testRemoveStatementList() { +// Statement[] remove = statements("moon orbits earth; earth orbits sun"); +// Statement[] keep = statements("I drink tea; you drink coffee"); +// model.add(remove).add(keep); +// testContains(model, remove); +// testContains(model, keep); +// +// model.remove(Arrays.asList(remove)); +// testOmits(model, remove); +// testContains(model, keep); +// } +// +// private void testOmits(final Model m, final Statement[] statements) { +// for (final Statement statement : statements) { +// Assert.assertFalse("it should not be here", m.contains(statement)); +// } +// } +// +// @Test +// public void testRemoveSPOCallsGraphDeleteTriple() { +// modelAdd(model, "a P b; c P d; x Q 1; y Q 2"); +// final List deleted = new ArrayList(); +// RecordingListener listener = new RecordingListener(); +// model.getGraph().getEventManager().register(listener); +// Model model2 = model.remove(resource("c"), property("P"), rdfNode("d")); +// listener.assertHas(new Object[] { "delete", model.getGraph(), +// triple("c P d") }); +// Assert.assertSame(model, model2); +// } +// +// private void checkNumericContent(final Container cont2, final int num) { +// final NodeIterator nit = cont2.iterator(); +// for (int i = 0; i < num; i += 1) { +// Assert.assertEquals(i, ((Literal) nit.nextNode()).getInt()); +// } +// Assert.assertFalse(nit.hasNext()); +// } +// +// private void retainOnlySpecified(final Container cont2, final int num, +// final boolean[] retain) { +// final NodeIterator nit = cont2.iterator(); +// for (int i = 0; i < num; i++) { +// nit.nextNode(); +// if (retain[i] == false) { +// nit.remove(); +// } +// } +// Assert.assertFalse(nit.hasNext()); +// } +// +// private void seeWhatsThere(final Container cont2, final boolean[] found) { +// final NodeIterator nit = cont2.iterator(); +// while (nit.hasNext()) { +// final int v = ((Literal) nit.nextNode()).getInt(); +// Assert.assertFalse(found[v]); +// found[v] = true; +// } +// } +// +// private Set setOf(final Object x) { +// final Set result = new HashSet(); +// result.add(x); +// return result; +// } +// +// private void testContainer(final Model model, final Container cont1, +// final Container cont2) { +// final Literal tvLiteral = model.createLiteral("test 12 string 2"); +// // Resource tvResObj = model.createResource( new ResTestObjF() ); +// final Object tvLitObj = new LitTestObj(1234); +// model.createBag(); +// model.createAlt(); +// model.createSeq(); +// final String lang = "en"; +// // +// Assert.assertEquals(0, cont1.size()); +// Assert.assertEquals(0, cont2.size()); +// // +// Assert.assertTrue(cont1.add(tvBoolean).contains(tvBoolean)); +// Assert.assertTrue(cont1.add(tvByte).contains(tvByte)); +// Assert.assertTrue(cont1.add(tvShort).contains(tvShort)); +// Assert.assertTrue(cont1.add(tvInt).contains(tvInt)); +// Assert.assertTrue(cont1.add(tvLong).contains(tvLong)); +// Assert.assertTrue(cont1.add(tvFloat).contains(tvFloat)); +// Assert.assertTrue(cont1.add(tvDouble).contains(tvDouble)); +// Assert.assertTrue(cont1.add(tvChar).contains(tvChar)); +// Assert.assertTrue(cont1.add(tvString).contains(tvString)); +// Assert.assertFalse(cont1.contains(tvString, lang)); +// Assert.assertTrue(cont1.add(tvString, lang).contains(tvString, lang)); +// Assert.assertTrue(cont1.add(tvLiteral).contains(tvLiteral)); +// // assertTrue( cont1.add( tvResObj ).contains( tvResObj ) ); +// Assert.assertTrue(cont1.add(tvLitObj).contains(tvLitObj)); +// Assert.assertEquals(12, cont1.size()); +// // +// final int num = 10; +// for (int i = 0; i < num; i += 1) { +// cont2.add(i); +// } +// Assert.assertEquals(num, cont2.size()); +// checkNumericContent(cont2, num); +// // +// final boolean[] found = new boolean[num]; +// final boolean[] retain = { true, true, true, false, false, false, +// false, false, true, true }; +// retainOnlySpecified(cont2, num, retain); +// seeWhatsThere(cont2, found); +// for (int i = 0; i < num; i += 1) { +// Assert.assertEquals(i + "th element of array", retain[i], found[i]); +// } +// } +// +// // public void testCreateAnonByFactory() +// // { +// // assertTrue( model.createResource( new ResTestObjF() ).isAnon() ); +// // } +// +// // public void testCreateResourceByFactory() +// // { +// // String uri = "http://aldabaran.hpl.hp.com/foo"; +// // assertEquals( uri, model.createResource( uri, new ResTestObjF() +// // ).getURI() ); +// // } +// @Test +// public void testCreateAnonResource() { +// final Resource r = model.createResource(); +// Assert.assertTrue(r.isAnon()); +// Assert.assertNull(r.getURI()); +// Assert.assertNull(r.getNameSpace()); +// Assert.assertNull(r.getLocalName()); +// } +// +// @Test +// public void testCreateAnonResourceWithNull() { +// final Resource r = model.createResource((String) null); +// Assert.assertTrue(r.isAnon()); +// Assert.assertNull(r.getURI()); +// Assert.assertNull(r.getNameSpace()); +// Assert.assertNull(r.getLocalName()); +// } +// +// @Test +// public void testCreateNamedResource() { +// final String uri = "http://aldabaran.hpl.hp.com/foo"; +// Assert.assertEquals(uri, model.createResource(uri).getURI()); +// } +// +// @Test +// public void testCreateNullPropertyFails() { +// try { +// model.createProperty(null); +// Assert.fail("should not create null property"); +// } catch (final InvalidPropertyURIException e) { +// // expected +// } +// } +// +// @Test +// public void testCreatePropertyOneArg() { +// final Property p = model.createProperty("abc/def"); +// Assert.assertEquals("abc/", p.getNameSpace()); +// Assert.assertEquals("def", p.getLocalName()); +// Assert.assertEquals("abc/def", p.getURI()); +// } +// +// @Test +// public void testCreatePropertyStrangeURI() { +// final String uri = RDF.getURI() + "_345"; +// final Property p = model.createProperty(uri); +// Assert.assertEquals(RDF.getURI(), p.getNameSpace()); +// Assert.assertEquals("_345", p.getLocalName()); +// Assert.assertEquals(uri, p.getURI()); +// } +// +// @Test +// public void testCreatePropertyStrangeURITwoArgs() { +// final String local = "_345"; +// final Property p = model.createProperty(RDF.getURI(), local); +// Assert.assertEquals(RDF.getURI(), p.getNameSpace()); +// Assert.assertEquals(local, p.getLocalName()); +// Assert.assertEquals(RDF.getURI() + local, p.getURI()); +// } +// +// @Test +// public void testCreateTypedAnonResource() { +// final Resource r = model.createResource(RDF.Property); +// Assert.assertTrue(r.isAnon()); +// Assert.assertTrue(model.contains(r, RDF.type, RDF.Property)); +// } +// +// @Test +// public void testCreateTypedNamedresource() { +// final String uri = "http://aldabaran.hpl.hp.com/foo"; +// final Resource r = model.createResource(uri, RDF.Property); +// Assert.assertEquals(uri, r.getURI()); +// Assert.assertTrue(model.contains(r, RDF.type, RDF.Property)); +// } +// +// @Test +// public void testEnhancedResources() { +// final Resource r = model.createResource(); +// testResource(model, r, 0); +// +// testResource(model, model.createBag(), 1); +// testContainer(model, model.createBag(), model.createBag()); +// +// testResource(model, model.createAlt(), 1); +// testContainer(model, model.createAlt(), model.createAlt()); +// +// testResource(model, model.createSeq(), 1); +// testContainer(model, model.createSeq(), model.createSeq()); +// // testSeq( model, model.createSeq(), model.createSeq(), +// // model.createSeq(), +// // model.createSeq(), model.createSeq(), model.createSeq(), +// // model.createSeq() ); +// } +// +// private void testResource(final Model model, final Resource r, +// final int numProps) { +// final Literal tvLiteral = model.createLiteral("test 12 string 2"); +// final Resource tvResource = model.createResource(); +// final String lang = "fr"; +// // +// Assert.assertTrue(r.addLiteral(RDF.value, tvBoolean).hasLiteral( +// RDF.value, tvBoolean)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvByte).hasLiteral(RDF.value, +// tvByte)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvShort).hasLiteral( +// RDF.value, tvShort)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvInt).hasLiteral(RDF.value, +// tvInt)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvLong).hasLiteral(RDF.value, +// tvLong)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvChar).hasLiteral(RDF.value, +// tvChar)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvFloat).hasLiteral( +// RDF.value, tvFloat)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvDouble).hasLiteral( +// RDF.value, tvDouble)); +// Assert.assertTrue(r.addProperty(RDF.value, tvString).hasProperty( +// RDF.value, tvString)); +// Assert.assertTrue(r.addProperty(RDF.value, tvString, lang).hasProperty( +// RDF.value, tvString, lang)); +// Assert.assertTrue(r.addLiteral(RDF.value, tvObject).hasLiteral( +// RDF.value, tvObject)); +// Assert.assertTrue(r.addProperty(RDF.value, tvLiteral).hasProperty( +// RDF.value, tvLiteral)); +// Assert.assertTrue(r.addProperty(RDF.value, tvResource).hasProperty( +// RDF.value, tvResource)); +// Assert.assertTrue(r.getRequiredProperty(RDF.value).getSubject() +// .equals(r)); +// // +// final Property p = model.createProperty("foo/", "bar"); +// try { +// r.getRequiredProperty(p); +// Assert.fail("should detect missing property"); +// } catch (final PropertyNotFoundException e) { +// // expected +// } +// // +// Assert.assertEquals(13, iteratorToSet(r.listProperties(RDF.value)) +// .size()); +// Assert.assertEquals(setOf(r), iteratorToSet(r.listProperties(RDF.value) +// .mapWith(Statement.Util.getSubject))); +// // +// Assert.assertEquals(0, iteratorToSet(r.listProperties(p)).size()); +// Assert.assertEquals(new HashSet(), iteratorToSet(r +// .listProperties(p).mapWith(Statement.Util.getSubject))); +// // +// Assert.assertEquals(13 + numProps, iteratorToSet(r.listProperties()) +// .size()); +// Assert.assertEquals( +// setOf(r), +// iteratorToSet(r.listProperties().mapWith( +// Statement.Util.getSubject))); +// // +// r.removeProperties(); +// Assert.assertEquals(0, +// model.query(new SimpleSelector(r, null, (RDFNode) null)).size()); +// } +// +// static final String subjURI = "http://aldabaran.hpl.hp.com/foo"; +// static final String predURI = "http://aldabaran.hpl.hp.com/bar"; +// +// public void testCreateStatementByteMax() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createLiteralStatement(r, p, Byte.MAX_VALUE); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(Byte.MAX_VALUE, s.getByte()); +// } +// +// public void testCreateStatementChar() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createLiteralStatement(r, p, '$'); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals('$', s.getChar()); +// } +// +// public void testCreateStatementDouble() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createStatement(r, p, +// model.createTypedLiteral(12345.67890d)); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(12345.67890d, s.getDouble(), 0.0000005); +// } +// +// public void testCreateStatementFactory() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final LitTestObj tv = new LitTestObj(Long.MIN_VALUE); +// final Statement s = model.createLiteralStatement(r, p, tv); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// // assertEquals( tv, s.getObject( new LitTestObjF() ) ); +// } +// +// public void testCreateStatementFloat() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createStatement(r, p, +// model.createTypedLiteral(123.456f)); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(123.456f, s.getFloat(), 0.0005); +// } +// +// public void testCreateStatementIntMax() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createLiteralStatement(r, p, +// Integer.MAX_VALUE); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(Integer.MAX_VALUE, s.getInt()); +// } +// +// public void testCreateStatementLongMax() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createLiteralStatement(r, p, Long.MAX_VALUE); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(Long.MAX_VALUE, s.getLong()); +// } +// +// public void testCreateStatementResource() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Resource tv = resource(); +// final Statement s = model.createStatement(r, p, tv); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(tv, s.getResource()); +// } +// +// public void testCreateStatementShortMax() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createLiteralStatement(r, p, Short.MAX_VALUE); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(Short.MAX_VALUE, s.getShort()); +// } +// +// public void testCreateStatementString() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final String string = "this is a plain string"; +// final Statement s = model.createStatement(r, p, string); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(string, s.getString()); +// Assert.assertNull(s.getLanguage()); +// Assert.assertEquals("en", model.createStatement(r, p, string, "en") +// .getLanguage()); +// Assert.assertEquals("fr", model.createStatement(r, p, string, "fr") +// .getLanguage()); +// } +// +// public void testCreateStatementTrue() { +// final Resource r = resource(subjURI); +// final Property p = property(predURI); +// final Statement s = model.createLiteralStatement(r, p, true); +// Assert.assertEquals(r, s.getSubject()); +// Assert.assertEquals(p, s.getPredicate()); +// Assert.assertEquals(true, s.getBoolean()); +// } +// +// public void testCreateStatementTypeLiteral() { +// final Model model = ModelFactory.createDefaultModel(); +// final Resource R = model.createResource("http://example/r"); +// final Property P = model.createProperty("http://example/p"); +// model.add(R, P, "2", XSDDatatype.XSDinteger); +// final Literal L = ResourceFactory.createTypedLiteral("2", +// XSDDatatype.XSDinteger); +// Assert.assertTrue(model.contains(R, P, L)); +// Assert.assertFalse(model.contains(R, P, "2")); +// } +// +// public void testNotReified() { +// Statement s1 = model.createStatement(model.createResource(), RDF.type, +// RDFS.Class); +// +// Assert.assertFalse("Should not be reified", s1.isReified()); +// model.add(s1); +// Assert.assertFalse("Should not be reified", s1.isReified()); +// +// Statement s2 = model.createStatement(model.createResource(), RDF.type, +// RDFS.Class); [... 1090 lines stripped ...]