You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2013/09/14 00:32:06 UTC

svn commit: r1523135 [4/6] - in /jena/Experimental/new-test/src/test/java/com/hp/hpl/jena: graph/ graph/compose/ graph/impl/ mem/ rdf/ rdf/model/ rdf/model/impl/ rdf/model/temp/ shared/ testing_framework/

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractPropertyTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractPropertyTest.java?rev=1523135&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractPropertyTest.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractPropertyTest.java Fri Sep 13 22:32:05 2013
@@ -0,0 +1,87 @@
+/*
+ * 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 com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
+import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.vocabulary.RDFS;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class AbstractPropertyTest 
+{
+	
+
+	abstract protected Property createProperty( final String uri );
+//	{
+//		return new PropertyImpl(uri);
+//	}
+
+	@Test
+	public void testNonOrdinalRDFURIs()
+	{
+		testRDFOrdinalValue(0, "x");
+		testRDFOrdinalValue(0, "x1");
+		testRDFOrdinalValue(0, "_x");
+		testRDFOrdinalValue(0, "x123");
+		testRDFOrdinalValue(0, "0xff");
+		testRDFOrdinalValue(0, "_xff");
+	}
+
+	@Test
+	public void testNonRDFElementURIsHaveOrdinal0()
+	{
+		testOrdinalValue(0, "foo:bar");
+		testOrdinalValue(0, "foo:bar1");
+		testOrdinalValue(0, "foo:bar2");
+		testOrdinalValue(0, RDFS.getURI() + "_17");
+	}
+
+	private void testOrdinalValue( final int i, final String URI )
+	{
+		final String message = "property should have expected ordinal value for "
+				+ URI;
+		Assert.assertEquals(message, i, createProperty(URI).getOrdinal());
+	}
+
+	@Test
+	public void testOrdinalValues()
+	{
+		testRDFOrdinalValue(1, "_1");
+		testRDFOrdinalValue(2, "_2");
+		testRDFOrdinalValue(3, "_3");
+		testRDFOrdinalValue(4, "_4");
+		testRDFOrdinalValue(5, "_5");
+		testRDFOrdinalValue(6, "_6");
+		testRDFOrdinalValue(7, "_7");
+		testRDFOrdinalValue(8, "_8");
+		testRDFOrdinalValue(9, "_9");
+		testRDFOrdinalValue(10, "_10");
+		testRDFOrdinalValue(100, "_100");
+		testRDFOrdinalValue(1234, "_1234");
+		testRDFOrdinalValue(67890, "_67890");
+	}
+
+	private void testRDFOrdinalValue( final int i, final String local )
+	{
+		testOrdinalValue(i, RDF.getURI() + local);
+	}
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractPropertyTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFListTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFListTest.java?rev=1523135&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFListTest.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFListTest.java Fri Sep 13 22:32:05 2013
@@ -0,0 +1,960 @@
+/*
+ * 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
+// /////////////
+package com.hp.hpl.jena.rdf.model;
+
+// Imports
+// /////////////
+
+import static com.hp.hpl.jena.testing_framework.ModelHelper.*;
+
+import com.hp.hpl.jena.rdf.model.ListIndexException;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFList;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.testing_framework.AbstractModelProducerUser;
+import com.hp.hpl.jena.testing_framework.ModelProducerInterface;
+
+import com.hp.hpl.jena.util.iterator.Map1;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>
+ * A collection of unit tests for the standard implementation of {@link RDFList}
+ * .
+ * </p>
+ * 
+ * 
+ */
+public class AbstractRDFListTest extends
+AbstractModelProducerUser  {
+	
+	@Override
+	public ModelProducerInterface getModelProducer() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+	
+	private Model model;
+	
+	@Before
+	public void setupAbstractRDFListTest()
+	{
+		model = getModelProducer().newModel();	
+	}
+	
+	// Constants
+	// ////////////////////////////////
+
+	public static final String NS = "uri:urn:x-rdf:test#";
+
+	/** Test that an iterator delivers the expected values */
+	protected static void iteratorTest( final Iterator<?> i,
+			final Object[] expected )
+	{
+		final Logger logger = LoggerFactory.getLogger(AbstractRDFListTest.class);
+		final List<Object> expList = new ArrayList<Object>();
+		for (final Object element : expected)
+		{
+			expList.add(element);
+		}
+
+		while (i.hasNext())
+		{
+			final Object next = i.next();
+
+			// debugging
+			if (!expList.contains(next))
+			{
+				logger.debug("TestList - Unexpected iterator result: " + next);
+			}
+
+			Assert.assertTrue("Value " + next
+					+ " was not expected as a result from this iterator ",
+					expList.contains(next));
+			Assert.assertTrue("Value " + next
+					+ " was not removed from the list ", expList.remove(next));
+		}
+
+		if (!(expList.size() == 0))
+		{
+			logger.debug("TestList - Expected iterator results not found");
+			for (final Object object : expList)
+			{
+				logger.debug("TestList - missing: " + object);
+			}
+		}
+		Assert.assertEquals(
+				"There were expected elements from the iterator that were not found",
+				0, expList.size());
+	}
+
+	// Static variables
+	// ////////////////////////////////
+
+	// Instance variables
+	// ////////////////////////////////
+
+	// Constructors
+	// ////////////////////////////////
+
+	// public TestList( String name ) {
+	// super( name );
+	// }
+
+	// External signature methods
+	// ////////////////////////////////
+	/*
+	 * public static TestSuite suite() {
+	 * TestSuite s = new TestSuite( "TestList" );
+	 * TestList tl = new TestList();
+	 * for (int i = 0; i <= 5; i++) {
+	 * s.addTest( new CountTest( i ) );
+	 * s.addTest( new TailTest( i ) );
+	 * }
+	 * 
+	 * s.addTest( new ValidityTest() );
+	 * s.addTest( new HeadTest() );
+	 * s.addTest( new SetHeadTest() );
+	 * s.addTest( new SetTailTest() );
+	 * s.addTest( new ConsTest() );
+	 * s.addTest( new AddTest() );
+	 * s.addTest( new TestListGet() );
+	 * s.addTest( new ReplaceTest() );
+	 * s.addTest( new IndexTest1() );
+	 * s.addTest( new IndexTest2() );
+	 * s.addTest( new AppendTest() );
+	 * s.addTest( new ConcatenateTest() );
+	 * s.addTest( new ConcatenateTest2() );
+	 * s.addTest( new ApplyTest() );
+	 * s.addTest( new ReduceTest() );
+	 * s.addTest( new RemoveTest() );
+	 * s.addTest( new Map1Test() );
+	 * s.addTest( new ListEqualsTest() );
+	 * s.addTest( new ListSubclassTest() );
+	 * s.addTest( new UserDefinedListTest() );
+	 * 
+	 * return s;
+	 * }
+	 */
+
+	protected void checkValid( final String testName, final RDFList l,
+			final boolean validExpected )
+	{
+		l.setStrict(true);
+		final boolean valid = l.isValid();
+		// for debugging ... String s = l.getValidityErrorMessage();
+		Assert.assertEquals("Validity test " + testName
+				+ " returned wrong isValid() result", validExpected, valid);
+	}
+
+	// Internal implementation methods
+	// ////////////////////////////////
+
+	protected RDFList getListRoot( final Model m )
+	{
+		final Resource root = m.getResource(AbstractRDFListTest.NS + "root");
+		Assert.assertNotNull("Root resource should not be null", root);
+
+		final Resource listHead = root.getRequiredProperty(
+				m.getProperty(AbstractRDFListTest.NS + "p")).getResource();
+
+		final RDFList l = listHead.as(RDFList.class);
+		Assert.assertNotNull("as(RDFList) should not return null for root", l);
+
+		return l;
+	}
+
+	@Test
+	public void testAdd()
+	{
+
+		final Resource root = model.createResource(AbstractRDFListTest.NS + "root");
+		final Property p = model.createProperty(AbstractRDFListTest.NS, "p");
+
+		final Resource nil = model.getResource(RDF.nil.getURI());
+		RDFList list = nil.as(RDFList.class);
+
+		final Resource[] toAdd = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"),
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "e"), };
+
+		// add each of these resources onto the end of the list
+		for (final Resource element : toAdd)
+		{
+			final RDFList list0 = list.with(element);
+
+			checkValid("addTest0", list0, true);
+			Assert.assertTrue("added'ed lists should be equal",
+					list.equals(nil) || list0.equals(list));
+
+			list = list0;
+		}
+
+		// relate the root to the list
+		model.add(root, p, list);
+
+		// should be isomorphic with list 5
+		final Model m0 = ModelFactory.createDefaultModel();
+		m0.read( getFileName( "ontology/list5.rdf"));
+
+		Assert.assertTrue("Add'ed and read models should be the same",
+				m0.isIsomorphicWith(model));
+
+	}
+
+	@Test
+	public void testAppend()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final Resource nil = model.getResource(RDF.nil.getURI());
+		RDFList list = nil.as(RDFList.class);
+
+		final Resource r = model.createResource(AbstractRDFListTest.NS + "foo");
+
+		// create a list of foos
+		for (int i = 0; i < 5; i++)
+		{
+			list = list.cons(r);
+		}
+
+		final int listLen = list.size();
+
+		// now append foos to the root list
+		final RDFList root = getListRoot(model);
+		final int rootLen = root.size();
+
+		final RDFList appended = root.append(list);
+
+		// original list should be unchanged
+		checkValid("appendTest0", root, true);
+		Assert.assertEquals("Original list should be unchanged", rootLen,
+				root.size());
+
+		checkValid("appendTest1", list, true);
+		Assert.assertEquals("Original list should be unchanged", listLen,
+				list.size());
+
+		// new list should be length of combined
+		checkValid("appendTest2", appended, true);
+		Assert.assertEquals("Appended list not correct length", rootLen
+				+ listLen, appended.size());
+	}
+
+	@Test
+	public void testApply()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final RDFList root = getListRoot(model);
+
+		class MyApply implements RDFList.ApplyFn
+		{
+			String collect = "";
+
+			@Override
+			public void apply( final RDFNode n )
+			{
+				collect = collect + ((Resource) n).getLocalName();
+			}
+		}
+
+		final MyApply f = new MyApply();
+		root.apply(f);
+
+		Assert.assertEquals(
+				"Result of apply should be concatentation of local names",
+				"abcde", f.collect);
+
+	}
+
+	@Test
+	public void testConcatenate()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final Resource nil = model.getResource(RDF.nil.getURI());
+		RDFList list = nil.as(RDFList.class);
+
+		final Resource r = model.createResource(AbstractRDFListTest.NS + "foo");
+
+		// create a list of foos
+		for (int i = 0; i < 5; i++)
+		{
+			list = list.cons(r);
+		}
+
+		final int listLen = list.size();
+
+		// now append foos to the root list
+		final RDFList root = getListRoot(model);
+		final int rootLen = root.size();
+		root.concatenate(list);
+
+		// original list should be unchanged
+		checkValid("concatTest0", list, true);
+		Assert.assertEquals("Original list should be unchanged", listLen,
+				list.size());
+
+		// but lhs list has changed
+		checkValid("concatTest1", root, true);
+		Assert.assertEquals("Root list should be new length",
+				rootLen + listLen, root.size());
+	}
+
+	@Test
+	public void testConcatenate2()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final Resource a = model.createResource(AbstractRDFListTest.NS + "a");
+
+		// create a list of foos
+		final Resource[] rs = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "e") };
+
+		final RDFList aList = model.createList().cons(a);
+		final RDFList rsList = model.createList(rs);
+
+		// concatenate the above resources onto the empty list
+		aList.concatenate(rsList);
+		checkValid("concatTest3", aList, true);
+
+		final RDFList root = getListRoot(model);
+		Assert.assertTrue("Constructed and loaded lists should be the same",
+				aList.sameListAs(root));
+	}
+
+	@Test
+	public void testCons()
+	{
+		final Resource root = model.createResource(AbstractRDFListTest.NS + "root");
+		final Property p = model.createProperty(AbstractRDFListTest.NS, "p");
+
+		final Resource nil = model.getResource(RDF.nil.getURI());
+		RDFList list = nil.as(RDFList.class);
+
+		final Resource[] toAdd = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "e"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "a"), };
+
+		// cons each of these resources onto the front of the list
+		for (final Resource element : toAdd)
+		{
+			final RDFList list0 = list.cons(element);
+
+			checkValid("constest1", list0, true);
+			Assert.assertTrue("cons'ed lists should not be equal",
+					!list0.equals(list));
+
+			list = list0;
+		}
+
+		// relate the root to the list
+		model.add(root, p, list);
+
+		// should be isomorphic with list 5
+		final Model m0 = ModelFactory.createDefaultModel();
+		m0.read(getFileName("ontology/list5.rdf"));
+
+		Assert.assertTrue("Cons'ed and read models should be the same",
+				m0.isIsomorphicWith(model));
+	}
+
+	@Test
+	public void testCount()
+	{
+		for (int i = 0; i <= 5; i++)
+		{
+			model.removeAll();
+			model.read( getFileName("ontology/list" + i + ".rdf"));
+
+			final RDFList l0 = getListRoot(model);
+			Assert.assertEquals("List size should be " + i, i, l0.size());
+		}
+
+	}
+
+	@Test
+	public void testHead()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		RDFList l0 = getListRoot(model);
+
+		final String[] names = { "a", "b", "c", "d", "e" };
+		for (final String name : names)
+		{
+			Assert.assertEquals("head of list has incorrect URI", AbstractRDFListTest.NS
+					+ name, ((Resource) l0.getHead()).getURI());
+			l0 = l0.getTail();
+		}
+	}
+
+	@Test
+	public void testIndex1()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final Resource[] toGet = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"),
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "e"), };
+
+		final RDFList l1 = getListRoot(model);
+
+		// check the indexes are correct
+		for (int i = 0; i < toGet.length; i++)
+		{
+			Assert.assertTrue("list should contain element " + i,
+					l1.contains(toGet[i]));
+			Assert.assertEquals("list element " + i + " is not correct", i,
+					l1.indexOf(toGet[i]));
+		}
+	}
+
+	@Test
+	public void testIndex2()
+	{
+
+		final Resource nil = model.getResource(RDF.nil.getURI());
+		RDFList list = nil.as(RDFList.class);
+
+		final Resource r = model.createResource(AbstractRDFListTest.NS + "a");
+
+		// cons each a's onto the front of the list
+		for (int i = 0; i < 10; i++)
+		{
+			list = list.cons(r);
+		}
+
+		// now index them back again
+		for (int j = 0; j < 10; j++)
+		{
+			Assert.assertEquals("index of j'th item should be j", j,
+					list.indexOf(r, j));
+		}
+
+	}
+
+	@Test
+	public void testListEquals()
+	{
+		final Resource nil = model.getResource(RDF.nil.getURI());
+		final RDFList nilList = nil.as(RDFList.class);
+
+		// create a list of foos
+		final Resource[] r0 = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"), // canonical
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "e") };
+		final Resource[] r1 = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"), // same
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "e") };
+		final Resource[] r2 = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"), // one shorter
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "d") };
+		final Resource[] r3 = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"), // elements
+				// swapped
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "e") };
+		final Resource[] r4 = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"), // different
+				// name
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "D"),
+				model.createResource(AbstractRDFListTest.NS + "e") };
+
+		final Object[][] testSpec = new Object[][] { { r0, r1, Boolean.TRUE },
+				{ r0, r2, Boolean.FALSE }, { r0, r3, Boolean.FALSE },
+				{ r0, r4, Boolean.FALSE }, { r1, r2, Boolean.FALSE },
+				{ r1, r3, Boolean.FALSE }, { r1, r4, Boolean.FALSE },
+				{ r2, r3, Boolean.FALSE }, { r2, r4, Boolean.FALSE }, };
+
+		for (int i = 0; i < testSpec.length; i++)
+		{
+			final RDFList l0 = nilList.append(Arrays.asList(
+					(Resource[]) testSpec[i][0]).iterator());
+			final RDFList l1 = nilList.append(Arrays.asList(
+					(Resource[]) testSpec[i][1]).iterator());
+			final boolean expected = ((Boolean) testSpec[i][2]).booleanValue();
+
+			Assert.assertEquals("sameListAs testSpec[" + i + "] incorrect",
+					expected, l0.sameListAs(l1));
+			Assert.assertEquals("sameListAs testSpec[" + i
+					+ "] (swapped) incorrect", expected, l1.sameListAs(l0));
+		}
+	}
+
+	@Test
+	public void testListGet()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final Resource[] toGet = new Resource[] {
+				model.createResource(AbstractRDFListTest.NS + "a"),
+				model.createResource(AbstractRDFListTest.NS + "b"),
+				model.createResource(AbstractRDFListTest.NS + "c"),
+				model.createResource(AbstractRDFListTest.NS + "d"),
+				model.createResource(AbstractRDFListTest.NS + "e"), };
+
+		final RDFList l1 = getListRoot(model);
+
+		// test normal gets
+		for (int i = 0; i < toGet.length; i++)
+		{
+			Assert.assertEquals("list element " + i + " is not correct",
+					toGet[i], l1.get(i));
+		}
+
+		// now test we get an exception for going beyong the end of the list
+		boolean gotEx = false;
+		try
+		{
+			l1.get(toGet.length + 1);
+		}
+		catch (final ListIndexException e)
+		{
+			gotEx = true;
+		}
+
+		Assert.assertTrue(
+				"Should see exception raised by accessing beyond end of list",
+				gotEx);
+	}
+
+	@Test
+	public void testMap1()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final RDFList root = getListRoot(model);
+		AbstractRDFListTest.iteratorTest(root.mapWith(new Map1<RDFNode, String>() {
+			@Override
+			public String map1( final RDFNode x )
+			{
+				return ((Resource) x).getLocalName();
+			}
+		}), new Object[] { "a", "b", "c", "d", "e" });
+
+	}
+
+	@Test
+	public void testReduce()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final RDFList root = getListRoot(model);
+
+		final RDFList.ReduceFn f = new RDFList.ReduceFn() {
+			@Override
+			public Object reduce( final RDFNode n, final Object acc )
+			{
+				return ((String) acc) + ((Resource) n).getLocalName();
+			}
+		};
+
+		Assert.assertEquals(
+				"Result of reduce should be concatentation of local names",
+				"abcde", root.reduce(f, ""));
+	}
+
+	@Test
+	public void testRemove()
+	{
+
+		final Resource nil = model.getResource(RDF.nil.getURI());
+		RDFList list0 = nil.as(RDFList.class);
+		RDFList list1 = nil.as(RDFList.class);
+
+		final Resource r0 = model.createResource(AbstractRDFListTest.NS + "x");
+		final Resource r1 = model.createResource(AbstractRDFListTest.NS + "y");
+		final Resource r2 = model.createResource(AbstractRDFListTest.NS + "z");
+
+		for (int i = 0; i < 10; i++)
+		{
+			list0 = list0.cons(r0);
+			list1 = list1.cons(r1);
+		}
+
+		// delete the elements of list0 one at a time
+		while (!list0.isEmpty())
+		{
+			list0 = list0.removeHead();
+			checkValid("removeTest0", list0, true);
+		}
+
+		// delete all of list1 in one go
+		list1.removeList();
+
+		// model should now be empty
+		Assert.assertEquals("Model should be empty after deleting two lists",
+				0, model.size());
+
+		// selective remove
+		RDFList list2 = (nil.as(RDFList.class)).cons(r2).cons(r1).cons(r0);
+
+		Assert.assertTrue("list should contain x ", list2.contains(r0));
+		Assert.assertTrue("list should contain y ", list2.contains(r1));
+		Assert.assertTrue("list should contain z ", list2.contains(r2));
+
+		list2 = list2.remove(r1);
+		Assert.assertTrue("list should contain x ", list2.contains(r0));
+		Assert.assertTrue("list should contain y ", !list2.contains(r1));
+		Assert.assertTrue("list should contain z ", list2.contains(r2));
+
+		list2 = list2.remove(r0);
+		Assert.assertTrue("list should contain x ", !list2.contains(r0));
+		Assert.assertTrue("list should contain y ", !list2.contains(r1));
+		Assert.assertTrue("list should contain z ", list2.contains(r2));
+
+		list2 = list2.remove(r2);
+		Assert.assertTrue("list should contain x ", !list2.contains(r0));
+		Assert.assertTrue("list should contain y ", !list2.contains(r1));
+		Assert.assertTrue("list should contain z ", !list2.contains(r2));
+		Assert.assertTrue("list should be empty", list2.isEmpty());
+	}
+
+	@Test
+	public void testReplace()
+	{
+		model.read(getFileName("ontology/list5.rdf"));
+
+		final Literal[] toSet = new Literal[] { model.createLiteral("a"),
+				model.createLiteral("b"), model.createLiteral("c"),
+				model.createLiteral("d"), model.createLiteral("e"), };
+
+		final RDFList l1 = getListRoot(model);
+
+		// change all the values
+		for (int i = 0; i < toSet.length; i++)
+		{
+			l1.replace(i, toSet[i]);
+		}
+
+		// then check them
+		for (int i = 0; i < toSet.length; i++)
+		{
+			Assert.assertEquals("list element " + i + " is not correct",
+					toSet[i], l1.get(i));
+		}
+
+		// now test we get an exception for going beyong the end of the list
+		boolean gotEx = false;
+		try
+		{
+			l1.replace(toSet.length + 1, toSet[0]);
+		}
+		catch (final ListIndexException e)
+		{
+			gotEx = true;
+		}
+
+		Assert.assertTrue(
+				"Should see exception raised by accessing beyond end of list",
+				gotEx);
+
+	}
+
+	@Test
+	public void testSetHead()
+	{
+
+		final Resource root = model.createResource(AbstractRDFListTest.NS + "root");
+		final Property p = model.createProperty(AbstractRDFListTest.NS, "p");
+
+		// a list of the nil object, but not typed
+		final Resource nil = RDF.nil;
+		model.add(nil, RDF.type, RDF.List);
+
+		final Resource list = model.createResource();
+		model.add(list, RDF.type, RDF.List);
+		model.add(list, RDF.first, "fred");
+		model.add(list, RDF.rest, nil);
+
+		model.add(root, p, list);
+		final RDFList l1 = getListRoot(model);
+		checkValid("sethead1", l1, true);
+
+		Assert.assertEquals("List head should be 'fred'", "fred",
+				((Literal) l1.getHead()).getString());
+
+		l1.setHead(model.createTypedLiteral(42));
+		checkValid("sethead2", l1, true);
+		Assert.assertEquals("List head should be '42'", 42,
+				((Literal) l1.getHead()).getInt());
+
+	}
+
+	@Test
+	public void testSetTail()
+	{
+		final Model m = ModelFactory.createDefaultModel();
+
+		final Resource root = m.createResource(AbstractRDFListTest.NS + "root");
+		final Property p = m.createProperty(AbstractRDFListTest.NS, "p");
+
+		final Resource nil = RDF.nil;
+		m.add(nil, RDF.type, RDF.List);
+
+		final Resource list0 = m.createResource();
+		m.add(list0, RDF.type, RDF.List);
+		m.add(list0, RDF.first, "fred");
+		m.add(list0, RDF.rest, nil);
+
+		m.add(root, p, list0);
+		final RDFList l1 = getListRoot(m);
+		checkValid("settail1", l1, true);
+
+		final Resource list1 = m.createResource();
+		m.add(list1, RDF.type, RDF.List);
+		m.add(list1, RDF.first, "george");
+		m.add(list1, RDF.rest, nil);
+
+		final RDFList l2 = list1.as(RDFList.class);
+		Assert.assertNotNull("as(RDFList) should not return null for root", l2);
+		checkValid("settail2", l2, true);
+
+		Assert.assertEquals("l1 should have length 1", 1, l1.size());
+		Assert.assertEquals("l2 should have length 1", 1, l2.size());
+
+		// use set tail to join the lists together
+		l1.setTail(l2);
+
+		checkValid("settail3", l1, true);
+		checkValid("settail4", l2, true);
+
+		Assert.assertEquals("l1 should have length 2", 2, l1.size());
+		Assert.assertEquals("l2 should have length 1", 1, l2.size());
+
+	}
+
+	@Test
+	public void testTail()
+	{
+		for (int i = 0; i <= 5; i++)
+		{
+			model.read( getFileName("ontology/list" + i + ".rdf"));
+
+			RDFList l0 = getListRoot(model);
+
+			// get the tail n times, should be nil at the end
+			for (int j = 0; j < i; j++)
+			{
+				l0 = l0.getTail();
+			}
+
+			Assert.assertTrue("Should have reached the end of the list after "
+					+ i + " getTail()'s", l0.isEmpty());
+		}
+	}
+
+	@Test
+	public void testValidity()
+	{
+
+		final Resource root = model.createResource(AbstractRDFListTest.NS + "root");
+		final Property p = model.createProperty(AbstractRDFListTest.NS, "p");
+
+		// a list of the nil object, but not typed
+		final Resource nil = RDF.nil;
+		model.add(root, p, nil);
+		final RDFList l0 = getListRoot(model);
+		checkValid("valid1", l0, true);
+
+		// add another node to the head of the list
+		final Resource badList = model.createResource();
+		model.getRequiredProperty(root, p).remove();
+		model.add(root, p, badList);
+		model.add(badList, RDF.type, RDF.List);
+
+		final RDFList l1 = getListRoot(model);
+		checkValid("valid2", l1, false);
+
+		// checkValid( "valid3", l1, false );
+
+		model.add(badList, RDF.first, "fred");
+		checkValid("valid4", l1, false);
+
+		model.add(badList, RDF.rest, nil);
+		checkValid("valid5", l1, true);
+
+	}
+
+	
+
+	// public void testListSubclass() {
+	// String NS = "http://example.org/test#";
+	// Resource a = model.createResource( NS + "a" );
+	// Resource b = model.createResource( NS + "b" );
+	//
+	// Resource cell0 = model.createResource();
+	// Resource cell1 = model.createResource();
+	// cell0.addProperty( RDF.first, a );
+	// cell0.addProperty( RDF.rest, cell1 );
+	// cell1.addProperty( RDF.first, b );
+	// cell1.addProperty( RDF.rest, RDF.nil );
+	//
+	// UserList ul = getUserListInstance(cell0);
+	//
+	// assertEquals( "User list length ", 2, ul.size() );
+	// assertEquals( "head of user list ", a, ul.getHead() );
+	//
+	// RDFList l = ul.as( RDFList.class );
+	// assertNotNull( "RDFList facet of user-defined list subclass", l );
+	//
+	// }
+	//
+	// /** A simple extension to RDFList to test user-subclassing of RDFList */
+	// protected static interface UserList extends RDFList {
+	// }
+	//
+	// /** Impl of a simple extension to RDFList to test user-subclassing of
+	// RDFList */
+	// protected static class UserListImpl extends RDFListImpl implements
+	// UserList {
+	// public UserListImpl( Node n, EnhGraph g ) {
+	// super( n, g );
+	// }
+	// }
+	//
+	// public UserList getUserListInstance( Resource r )
+	// {
+	// return new UserListImpl( r.asNode(), (EnhGraph) model );
+	// }
+	//
+	// public void testUserDefinedList() {
+	// BuiltinPersonalities.model.add( UserDefList.class,
+	// UserDefListImpl.factoryForTests );
+	//
+	// String NS = "http://example.org/test#";
+	// Resource a = model.createResource( NS + "a" );
+	// Resource b = model.createResource( NS + "b" );
+	//
+	// Resource empty = model.createResource( UserDefListImpl.NIL.getURI() );
+	// UserDefList ul = empty.as( UserDefList.class );
+	// assertNotNull( "UserList facet of empty list", ul );
+	//
+	// UserDefList ul0 = (UserDefList) ul.cons( b );
+	// ul0 = (UserDefList) ul0.cons( a );
+	// assertEquals( "should be length 2", 2, ul0.size() );
+	// assertTrue( "first statement", model.contains( ul0,
+	// UserDefListImpl.FIRST, a ) );
+	// }
+	//
+	// protected static interface UserDefList extends RDFList {}
+	//
+	// protected static class UserDefListImpl extends RDFListImpl implements
+	// UserDefList {
+	// @SuppressWarnings("hiding") public static final String NS =
+	// "http://example.org/testlist#";
+	// public static final Property FIRST = ResourceFactory.createProperty(
+	// NS+"first" );
+	// public static final Property REST = ResourceFactory.createProperty(
+	// NS+"rest" );
+	// public static final Resource NIL = ResourceFactory.createResource(
+	// NS+"nil" );
+	// public static final Resource LIST = ResourceFactory.createResource(
+	// NS+"List" );
+	//
+	// /**
+	// * A factory for generating UserDefList facets from nodes in enhanced
+	// graphs.
+	// */
+	// public static Implementation factoryForTests = new Implementation() {
+	// @Override public EnhNode wrap( Node n, EnhGraph eg ) {
+	// if (canWrap( n, eg )) {
+	// UserDefListImpl impl = new UserDefListImpl( n, eg );
+	//
+	// Model model = impl.getModel();
+	// impl.m_listFirst = FIRST.inModel( model );
+	// impl.m_listRest = REST.inModel( model );
+	// impl.m_listNil = NIL.inModel( model );
+	// impl.m_listType = LIST.inModel( model );
+	//
+	// return impl;
+	// }
+	// else {
+	// throw new JenaException( "Cannot convert node " + n + " to UserDefList");
+	// }
+	// }
+	//
+	// @Override public boolean canWrap( Node node, EnhGraph eg ) {
+	// Graph g = eg.asGraph();
+	//
+	// return node.equals( NIL.asNode() ) ||
+	// g.contains( node, FIRST.asNode(), Node.ANY ) ||
+	// g.contains( node, REST.asNode(), Node.ANY ) ||
+	// g.contains( node, RDF.type.asNode(), LIST.asNode() );
+	// }
+	// };
+	//
+	// /** This method returns the Java class object that defines which
+	// abstraction facet is presented */
+	// @Override public Class<? extends RDFList> listAbstractionClass() {
+	// return UserDefList.class;
+	// }
+	//
+	// public UserDefListImpl( Node n, EnhGraph g ) {
+	// super( n, g );
+	// }
+	//
+	// }
+
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFListTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFNodeTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFNodeTest.java?rev=1523135&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFNodeTest.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFNodeTest.java Fri Sep 13 22:32:05 2013
@@ -0,0 +1,212 @@
+/*
+ * 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 com.hp.hpl.jena.rdf.model.AnonId;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.LiteralRequiredException;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.RDFVisitor;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceRequiredException;
+
+import com.hp.hpl.jena.test.JenaTestBase;
+import com.hp.hpl.jena.testing_framework.AbstractModelProducerUser;
+import static com.hp.hpl.jena.testing_framework.ModelHelper.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This class tests various properties of RDFNodes.
+ */
+public abstract class AbstractRDFNodeTest extends AbstractModelProducerUser {
+
+	@Test
+	public void testInModel() {
+		final Model m1 = modelWithStatements(getModelProducer(), "");
+		final Model m2 = modelWithStatements(getModelProducer(), "");
+		final Resource r1 = resource("r1");
+		final Resource r2 = resource("_r2");
+		/* */
+		Assert.assertEquals(r1.getModel(), m1);
+		Assert.assertEquals(r2.getModel(), m1);
+		Assert.assertFalse(r1.isAnon());
+		Assert.assertTrue(r2.isAnon());
+		/* */
+		Assert.assertEquals(r1.inModel(m2).getModel(), m2);
+		Assert.assertEquals(r2.inModel(m2).getModel(), m2);
+		/* */
+		Assert.assertEquals(r1, r1.inModel(m2));
+		Assert.assertEquals(r2, r2.inModel(m2));
+	}
+
+	@Test
+	public void testIsAnon() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(false, m.createResource("eh:/foo").isAnon());
+		Assert.assertEquals(true, m.createResource().isAnon());
+		Assert.assertEquals(false, m.createTypedLiteral(17).isAnon());
+		Assert.assertEquals(false, m.createTypedLiteral("hello").isAnon());
+	}
+
+	@Test
+	public void testIsLiteral() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(false, m.createResource("eh:/foo").isLiteral());
+		Assert.assertEquals(false, m.createResource().isLiteral());
+		Assert.assertEquals(true, m.createTypedLiteral(17).isLiteral());
+		Assert.assertEquals(true, m.createTypedLiteral("hello").isLiteral());
+	}
+
+	@Test
+	public void testIsResource() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(true, m.createResource("eh:/foo").isResource());
+		Assert.assertEquals(true, m.createResource().isResource());
+		Assert.assertEquals(false, m.createTypedLiteral(17).isResource());
+		Assert.assertEquals(false, m.createTypedLiteral("hello").isResource());
+	}
+
+	@Test
+	public void testIsURIResource() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(true, m.createResource("eh:/foo").isURIResource());
+		Assert.assertEquals(false, m.createResource().isURIResource());
+		Assert.assertEquals(false, m.createTypedLiteral(17).isURIResource());
+		Assert.assertEquals(false, m.createTypedLiteral("hello")
+				.isURIResource());
+	}
+
+	@Test
+	public void testLiteralAsResourceThrows() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Resource r = m.createResource("eh:/spoo");
+		try {
+			r.asLiteral();
+			Assert.fail("should not be able to do Resource.asLiteral()");
+		} catch (final LiteralRequiredException e) {
+		}
+	}
+
+	@Test
+	public void testRDFNodeAsLiteral() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Literal l = m.createLiteral("hello, world");
+		Assert.assertSame(l, ((RDFNode) l).asLiteral());
+	}
+
+	@Test
+	public void testRDFNodeAsResource() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Resource r = m.createResource("eh:/spoo");
+		Assert.assertSame(r, ((RDFNode) r).asResource());
+	}
+
+	@Test
+	public void testRDFVisitor() {
+		final List<String> history = new ArrayList<String>();
+		final Model m = ModelFactory.createDefaultModel();
+		final RDFNode S = m.createResource();
+		final RDFNode P = m.createProperty("eh:PP");
+		final RDFNode O = m.createLiteral("LL");
+		/* */
+		final RDFVisitor rv = new RDFVisitor() {
+			@Override
+			public Object visitBlank(final Resource R, final AnonId id) {
+				history.add("blank");
+				Assert.assertTrue("must visit correct node", R == S);
+				Assert.assertEquals("must have correct field", R.getId(), id);
+				return "blank result";
+			}
+
+			@Override
+			public Object visitLiteral(final Literal L) {
+				history.add("literal");
+				Assert.assertTrue("must visit correct node", L == O);
+				return "literal result";
+			}
+
+			@Override
+			public Object visitURI(final Resource R, final String uri) {
+				history.add("uri");
+				Assert.assertTrue("must visit correct node", R == P);
+				Assert.assertEquals("must have correct field", R.getURI(), uri);
+				return "uri result";
+			}
+		};
+		/* */
+		Assert.assertEquals("blank result", S.visitWith(rv));
+		Assert.assertEquals("uri result", P.visitWith(rv));
+		Assert.assertEquals("literal result", O.visitWith(rv));
+		Assert.assertEquals(JenaTestBase.listOfStrings("blank uri literal"),
+				history);
+	}
+
+	@Test
+	public void testRemoveAllBoring() {
+		final Model m1 = modelWithStatements(getModelProducer(),
+				"x P a; y Q b");
+		final Model m2 = modelWithStatements(getModelProducer(),
+				"x P a; y Q b");
+		resource("x").removeAll(property("Z"));
+		assertIsoModels("m2 should be unchanged", m1, m2);
+	}
+
+	@Test
+	public void testRemoveAllRemoves() {
+		final String ps = "x P a; x P b", rest = "x Q c; y P a; y Q b";
+		final Model m = modelWithStatements(getModelProducer(), ps
+				+ "; " + rest);
+		final Resource r = resource("x");
+		final Resource r2 = r.removeAll(property("P"));
+		Assert.assertSame("removeAll should deliver its receiver", r, r2);
+		assertIsoModels("x's P-values should go",
+				modelWithStatements(getModelProducer(), rest), m);
+	}
+
+	@Test
+	public void testResourceAsLiteralThrows() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Literal l = m.createLiteral("hello, world");
+		try {
+			l.asResource();
+			Assert.fail("should not be able to do Literal.asResource()");
+		} catch (final ResourceRequiredException e) {
+		}
+	}
+	
+	@Test
+	public void testPortingBlankNodes()
+	{
+		final Model B = getModelProducer().newModel();
+		final Model model = getModelProducer().newModel();
+		final Resource anon = model.createResource();
+		final Resource bAnon = anon.inModel(B);
+		Assert.assertTrue("moved resource should still be blank",
+				bAnon.isAnon());
+		Assert.assertEquals("move resource should equal original", anon, bAnon);
+	}
+
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractRDFNodeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractReifiedStatementsTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractReifiedStatementsTest.java?rev=1523135&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractReifiedStatementsTest.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractReifiedStatementsTest.java Fri Sep 13 22:32:05 2013
@@ -0,0 +1,427 @@
+/*
+ * 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 com.hp.hpl.jena.rdf.model.DoesNotReifyException;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.ReifiedStatement;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.testing_framework.AbstractModelProducerUser;
+import com.hp.hpl.jena.util.CollectionFactory;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+import java.util.Set;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class AbstractReifiedStatementsTest extends
+		AbstractModelProducerUser {
+	private Model model;
+
+	private Resource S;
+
+	private Property P;
+	private RDFNode O;
+	private Statement SPO;
+	private Statement SPO2;
+	private static final String aURI = "jena:test/reifying#someURI";
+	private static final String anotherURI = "jena:test/reifying#anotherURI";
+
+	private static final String anchor = "jena:test/Reifying#";
+	protected static Set<ReifiedStatement> noStatements = CollectionFactory
+			.createHashedSet();
+
+	/**
+	 * utility method: get a set of all the elements delivered by
+	 * _m.listReifiedStatements_.
+	 */
+	public Set<ReifiedStatement> getSetRS(final Model m) {
+		return m.listReifiedStatements().toSet();
+	}
+
+	public Set<ReifiedStatement> getSetRS(final Model m, final Statement st) {
+		return m.listReifiedStatements(st).toSet();
+	}
+
+	@Before
+	public void setupAbstractTestReifiedStatements() {
+		model = getModelProducer().newModel();
+		final Resource S2 = model
+				.createResource(AbstractReifiedStatementsTest.anchor
+						+ "subject2");
+		S = model.createResource(AbstractReifiedStatementsTest.anchor
+				+ "subject");
+		P = model.createProperty(AbstractReifiedStatementsTest.anchor
+				+ "predicate");
+		O = model
+				.createLiteral(AbstractReifiedStatementsTest.anchor + "object");
+		SPO = model.createStatement(S, P, O);
+		SPO2 = model.createStatement(S2, P, O);
+	}
+
+	/**
+	 * the simplest case: if we assert all the components of a reification quad,
+	 * we can get a ReifiedStatement that represents the reified statement.
+	 */
+	@Test
+	public void testBasicReification() {
+		final Resource R = model
+				.createResource(AbstractReifiedStatementsTest.aURI);
+		model.add(R, RDF.type, RDF.Statement);
+		model.add(R, RDF.subject, S);
+		model.add(R, RDF.predicate, P);
+		model.add(R, RDF.object, O);
+		final RDFNode rs = R.as(ReifiedStatement.class);
+		assertEquals("can recover statement", SPO,
+				((ReifiedStatement) rs).getStatement());
+	}
+
+	/**
+	 * walk down the set of statements (represented as an array), recursing with
+	 * and without each statement being present. The mask bits record those
+	 * statements that are in the model. At the bottom of the recursion (n ==
+	 * 0), check that R can be reified exactly when all four quad components are
+	 * present; the other statements don't matter.
+	 */
+	private void testCombinations(final Model m, final Resource R,
+			final int mask, final Object[][] statements, final int n) {
+		if (n == 0) {
+			try {
+				// System.err.println( "| hello. mask = " + mask );
+				final ReifiedStatement rs = R.as(ReifiedStatement.class);
+				// System.err.println( "+  we constructed " + rs );
+
+				if ((mask & 15) != 15) {
+					m.write(System.out, "TTL");
+				}
+
+				assertTrue("should not reify: not all components present ["
+						+ mask + "]: " + rs, (mask & 15) == 15);
+				// System.err.println( "+  and we passed the assertion." );
+			} catch (final DoesNotReifyException e) { // System.err.println(
+														// "+  we exploded" );
+				assertFalse("should reify: all components present", mask == 15);
+			}
+		} else {
+			final int i = n - 1;
+			final Statement s = (Statement) statements[i][0];
+			final int bits = ((Integer) statements[i][1]).intValue();
+			testCombinations(m, R, mask, statements, i);
+			m.add(s);
+			testCombinations(m, R, mask + bits, statements, i);
+			m.remove(s);
+		}
+	}
+
+	@Test
+	public void testConstructionByURI() {
+		final ReifiedStatement rs = model.createReifiedStatement("spoo:handle",
+				SPO);
+		final ReifiedStatement rs2 = SPO.createReifiedStatement("spoo:gripper");
+		assertEquals("recover statement (URI)", SPO, rs.getStatement());
+		assertEquals("recover URI", "spoo:handle", rs.getURI());
+		assertEquals("recover URI", "spoo:gripper", rs2.getURI());
+	}
+
+	@Test
+	public void testConstructionFromModels() {
+		testStatementAndModel("fromModel", model.createReifiedStatement(SPO),
+				model, SPO);
+	}
+
+	@Test
+	public void testConstructionFromStatements() {
+		testStatementAndModel("fromStatement", SPO.createReifiedStatement(),
+				model, SPO);
+	}
+
+	@Test
+	public void testConversion() {
+		final String uri = "spoo:handle";
+		model.createReifiedStatement(uri, SPO);
+		final ReifiedStatement rs2 = model.createResource(uri).as(
+				ReifiedStatement.class);
+		assertEquals("recover statement", SPO, rs2.getStatement());
+	}
+
+	/**
+	 * "dirty" reifications - those with conflicting quadlets - should fail.
+	 */
+	@Test
+	public void testDirtyReification() {
+		final Resource R = model
+				.createResource(AbstractReifiedStatementsTest.aURI);
+		model.add(R, RDF.type, RDF.Statement);
+		model.add(R, RDF.subject, S);
+		model.add(R, RDF.subject, P);
+		testDoesNotReify("boo", R);
+	}
+
+	private void testDoesNotReify(final String title, final Resource r) {
+		try {
+			r.as(ReifiedStatement.class);
+			fail(title + " (" + r + ")");
+		} catch (final DoesNotReifyException e) { /* that's what we expect */
+		}
+	}
+
+	@Test
+	public void testDoesNotReifyElsewhere() {
+		final String uri = "spoo:rubbish";
+		final Model m2 = getModelProducer().newModel();
+		model.createReifiedStatement(uri, SPO);
+		testDoesNotReify("blue model should not reify rubbish",
+				m2.createResource(uri));
+	}
+
+	// public void testXXX()
+	// {
+	// String root = "http://root/root#";
+	// Model m = ModelFactory.createDefaultModel();
+	// Model r = ModelFactory.createRDFSModel( m );
+	// Resource S = r.createResource( root + "S" );
+	// Property P = r.createProperty( root + "P" );
+	// RDFNode O = r.createResource( root + "O" );
+	// Statement st = r.createStatement( S, P, O );
+	// ReifiedStatement rs = st.createReifiedStatement( root + "RS" );
+	// }
+
+	@Test
+	public void testDoesNotReifyUnknown() {
+		testDoesNotReify("model should not reify rubbish",
+				model.createResource("spoo:rubbish"));
+	}
+
+	@Test
+	public void testGetAny() {
+		final Resource r = model.getAnyReifiedStatement(SPO);
+		assertInstanceOf(ReifiedStatement.class, r);
+		assertEquals("should get me the statement", SPO,
+				((ReifiedStatement) r).getStatement());
+	}
+
+	@Test
+	public void testIsReified() {
+		final ReifiedStatement rs = model.createReifiedStatement(
+				AbstractReifiedStatementsTest.aURI, SPO);
+		final Resource BS = model
+				.createResource(AbstractReifiedStatementsTest.anchor + "BS");
+		final Property BP = model
+				.createProperty(AbstractReifiedStatementsTest.anchor + "BP");
+		final RDFNode BO = model
+				.createProperty(AbstractReifiedStatementsTest.anchor + "BO");
+		model.add(rs, P, O);
+		assertTrue("st should be reified now", SPO.isReified());
+		assertTrue("m should have st reified now", model.isReified(SPO));
+		assertFalse("this new statement should not be reified", model
+				.createStatement(BS, BP, BO).isReified());
+	}
+
+	/**
+	 * Leo Bard spotted a problem whereby removing a reified statement from a
+	 * model with style Standard didn't leave the model empty. Here's a test for
+	 * it.
+	 */
+	@Test
+	public void testLeosBug() {
+		final Statement st = statement( "pigs fly south");
+		final ReifiedStatement rst = st.createReifiedStatement("eh:pointer");
+		model.removeReification(rst);
+		assertIsoModels(ModelFactory.createDefaultModel(), model);
+	}
+
+	/**
+	 * this test appeared when TestStatementResources crashed using reified
+	 * statements as a step-0 implementation for asSubject()/asObject(). Looks
+	 * like there was a problem in modelReifier().getRS(), which we're fixing
+	 * ...
+	 */
+	@Test
+	public void testListDoesntCrash() {
+		model.createReifiedStatement(SPO);
+		model.createReifiedStatement(SPO2);
+		assertTrue("should be non-empty", model.listReifiedStatements()
+				.hasNext());
+	}
+
+	@Test
+	public void testListReifiedSpecificStatements() {
+		assertEquals("no statements should match st",
+				AbstractReifiedStatementsTest.noStatements,
+				getSetRS(model, SPO));
+		/* */
+		final ReifiedStatement rs = model.createReifiedStatement(
+				AbstractReifiedStatementsTest.aURI, SPO);
+		final ReifiedStatement rs2 = model.createReifiedStatement(
+				AbstractReifiedStatementsTest.anotherURI, SPO2);
+		model.add(rs, P, O);
+		// assertEquals( "still no matching statement", empty, getSetRS( m,
+		// stOther ) );
+		/* */
+		final Set<ReifiedStatement> justRS2 = arrayToSet(new ReifiedStatement[] { rs2 });
+		model.add(rs2, P, O);
+		assertEquals("now one matching statement", justRS2,
+				getSetRS(model, SPO2));
+	}
+
+	/**
+	 * test that listReifiedStatements produces an iterator that contains the
+	 * right reified statements. We *don't* test that they're not duplicated,
+	 * because they might be; disallowing duplicates could be expensive.
+	 */
+	@Test
+	public void testListReifiedStatements() {
+		assertEquals("initially: no reified statements",
+				AbstractReifiedStatementsTest.noStatements, getSetRS(model));
+		final ReifiedStatement rs = model.createReifiedStatement(
+				AbstractReifiedStatementsTest.aURI, SPO);
+		// assertEquals( "still: no reified statements", empty, getSetRS( m ) );
+		/* */
+		model.add(rs, P, O);
+		final Set<ReifiedStatement> justRS = arrayToSet(new ReifiedStatement[] { rs });
+		assertEquals("post-add: one reified statement", justRS, getSetRS(model));
+		model.add(S, P, rs);
+		assertEquals("post-add: still one reified statement", justRS,
+				getSetRS(model));
+		/* */
+		final ReifiedStatement rs2 = model.createReifiedStatement(
+				AbstractReifiedStatementsTest.anotherURI, SPO2);
+		final Set<ReifiedStatement> bothRS = arrayToSet(new ReifiedStatement[] {
+				rs, rs2 });
+		model.add(rs2, P, O);
+		assertEquals("post-add: still one reified statement", bothRS,
+				getSetRS(model));
+	}
+
+	private void testNotReifying(final Model m, final String uri) {
+		try {
+			m.createResource(uri).as(ReifiedStatement.class);
+			fail("there should be no reifiedStatement for " + uri);
+		} catch (final DoesNotReifyException e) { /* that's what we require */
+		}
+	}
+
+	@Test
+	public void testQuintetOfQuadlets() {
+		final Resource rs = model.createResource();
+		rs.addProperty(RDF.type, RDF.Statement);
+		model.createResource().addProperty(RDF.value, rs);
+		rs.addProperty(RDF.subject, model.createResource());
+		rs.addProperty(RDF.predicate,
+				model.createProperty("http://example.org/foo"));
+		rs.addProperty(RDF.object, model.createResource());
+		rs.addProperty(RDF.object, model.createResource());
+		final StmtIterator it = model.listStatements();
+		while (it.hasNext()) {
+			final Statement s = it.nextStatement();
+			assertFalse(s.getObject().equals(s.getSubject()));
+		}
+	}
+
+	/**
+	 * check that, from a model with any combination of the statements given, we
+	 * can convert R into a ReifiedStatement iff the four components of the quad
+	 * are in the model.
+	 */
+	@Test
+	public void testReificationCombinations() {
+		final Resource RR = model
+				.createResource(AbstractReifiedStatementsTest.aURI), SS = model
+				.createResource(AbstractReifiedStatementsTest.anotherURI);
+		final Property PP = RR.as(Property.class);
+		final Object[][] statements = {
+				{ model.createStatement(RR, RDF.type, RDF.Statement),
+						new Integer(1) },
+				{ model.createStatement(RR, RDF.subject, SS), new Integer(2) },
+				{ model.createStatement(RR, RDF.predicate, PP), new Integer(4) },
+				{ model.createStatement(RR, RDF.object, O), new Integer(8) },
+				{ model.createStatement(SS, PP, O), new Integer(16) },
+				{ model.createStatement(RR, PP, O), new Integer(32) },
+				{ model.createStatement(SS, RDF.subject, SS), new Integer(64) },
+				{ model.createStatement(SS, RDF.predicate, PP),
+						new Integer(128) },
+				{ model.createStatement(SS, RDF.object, O), new Integer(256) },
+				{ model.createStatement(SS, RDF.type, RDF.Statement),
+						new Integer(512) } };
+		testCombinations(model, RR, 0, statements, statements.length);
+	}
+
+	@Test
+	public void testRemoveReificationWorks() {
+		final Statement st = SPO;
+		final Model m = model;
+		m.createReifiedStatement(AbstractReifiedStatementsTest.aURI, st);
+		assertTrue("st is now reified", st.isReified());
+		m.removeAllReifications(st);
+		assertFalse("st is no longer reified", st.isReified());
+	}
+
+	@Test
+	public void testRR() {
+		final Statement st = SPO;
+		final Model m = model;
+		final ReifiedStatement rs1 = m.createReifiedStatement(
+				AbstractReifiedStatementsTest.aURI, st);
+		final ReifiedStatement rs2 = m.createReifiedStatement(
+				AbstractReifiedStatementsTest.anotherURI, st);
+		m.removeReification(rs1);
+		testNotReifying(m, AbstractReifiedStatementsTest.aURI);
+		assertTrue("st is still reified", st.isReified());
+		m.removeReification(rs2);
+		assertFalse("st should no longer be reified", st.isReified());
+	}
+
+	public void testStatementAndModel(final String title,
+			final ReifiedStatement rs, final Model m, final Statement st) {
+		assertEquals(title + ": recover statement", st, rs.getStatement());
+		assertEquals(title + ": recover model", m, rs.getModel());
+	}
+
+	@Test
+	public void testStatementListReifiedStatements() {
+		final Statement st = SPO;
+		final Model m = model;
+		assertEquals("it's not there yet",
+				AbstractReifiedStatementsTest.noStatements,
+				iteratorToSet(st.listReifiedStatements()));
+		final ReifiedStatement rs = m.createReifiedStatement(
+				AbstractReifiedStatementsTest.aURI, st);
+		final Set<ReifiedStatement> justRS = arrayToSet(new ReifiedStatement[] { rs });
+		m.add(rs, P, O);
+		assertEquals("it's here now", justRS,
+				iteratorToSet(st.listReifiedStatements()));
+	}
+
+	@Test
+	public void testThisWillBreak() {
+		final Resource R = model
+				.createResource(AbstractReifiedStatementsTest.aURI);
+		SPO.createReifiedStatement(AbstractReifiedStatementsTest.aURI);
+		model.add(R, RDF.subject, R);
+	}
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractReifiedStatementsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractResourceTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractResourceTest.java?rev=1523135&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractResourceTest.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractResourceTest.java Fri Sep 13 22:32:05 2013
@@ -0,0 +1,643 @@
+/*
+ * 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 com.hp.hpl.jena.graph.test.GraphTestBase;
+import com.hp.hpl.jena.rdf.model.AnonId;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.LiteralRequiredException;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.RDFVisitor;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceRequiredException;
+import com.hp.hpl.jena.rdf.model.test.helpers.ModelHelper;
+import com.hp.hpl.jena.shared.PropertyNotFoundException;
+
+import com.hp.hpl.jena.test.JenaTestBase;
+import com.hp.hpl.jena.testing_framework.AbstractModelProducerUser;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+import static com.hp.hpl.jena.testing_framework.ModelHelper.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This class tests various properties of RDFNodes.
+ */
+public abstract class AbstractResourceTest extends AbstractRDFNodeTest {
+
+	@Test
+	public void testInModel() {
+		final Model m1 = modelWithStatements(getModelProducer(), "");
+		final Model m2 = modelWithStatements(getModelProducer(), "");
+		final Resource r1 = resource("r1");
+		final Resource r2 = resource("_r2");
+		/* */
+		Assert.assertEquals(r1.getModel(), m1);
+		Assert.assertEquals(r2.getModel(), m1);
+		Assert.assertFalse(r1.isAnon());
+		Assert.assertTrue(r2.isAnon());
+		/* */
+		Assert.assertEquals(r1.inModel(m2).getModel(), m2);
+		Assert.assertEquals(r2.inModel(m2).getModel(), m2);
+		/* */
+		Assert.assertEquals(r1, r1.inModel(m2));
+		Assert.assertEquals(r2, r2.inModel(m2));
+	}
+
+	@Test
+	public void testIsAnon() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(false, m.createResource("eh:/foo").isAnon());
+		Assert.assertEquals(true, m.createResource().isAnon());
+		Assert.assertEquals(false, m.createTypedLiteral(17).isAnon());
+		Assert.assertEquals(false, m.createTypedLiteral("hello").isAnon());
+	}
+
+	@Test
+	public void testIsLiteral() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(false, m.createResource("eh:/foo").isLiteral());
+		Assert.assertEquals(false, m.createResource().isLiteral());
+		Assert.assertEquals(true, m.createTypedLiteral(17).isLiteral());
+		Assert.assertEquals(true, m.createTypedLiteral("hello").isLiteral());
+	}
+
+	@Test
+	public void testIsResource() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(true, m.createResource("eh:/foo").isResource());
+		Assert.assertEquals(true, m.createResource().isResource());
+		Assert.assertEquals(false, m.createTypedLiteral(17).isResource());
+		Assert.assertEquals(false, m.createTypedLiteral("hello").isResource());
+	}
+
+	@Test
+	public void testIsURIResource() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		Assert.assertEquals(true, m.createResource("eh:/foo").isURIResource());
+		Assert.assertEquals(false, m.createResource().isURIResource());
+		Assert.assertEquals(false, m.createTypedLiteral(17).isURIResource());
+		Assert.assertEquals(false, m.createTypedLiteral("hello")
+				.isURIResource());
+	}
+
+	@Test
+	public void testLiteralAsResourceThrows() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Resource r = m.createResource("eh:/spoo");
+		try {
+			r.asLiteral();
+			Assert.fail("should not be able to do Resource.asLiteral()");
+		} catch (final LiteralRequiredException e) {
+		}
+	}
+
+	@Test
+	public void testRDFNodeAsLiteral() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Literal l = m.createLiteral("hello, world");
+		Assert.assertSame(l, ((RDFNode) l).asLiteral());
+	}
+
+	@Test
+	public void testRDFNodeAsResource() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Resource r = m.createResource("eh:/spoo");
+		Assert.assertSame(r, ((RDFNode) r).asResource());
+	}
+
+	@Test
+	public void testRemoveAllBoring() {
+		final Model m1 = modelWithStatements(getModelProducer(),
+				"x P a; y Q b");
+		final Model m2 = modelWithStatements(getModelProducer(),
+				"x P a; y Q b");
+		resource("x").removeAll(property("Z"));
+		assertIsoModels("m2 should be unchanged", m1, m2);
+	}
+
+	@Test
+	public void testRemoveAllRemoves() {
+		final String ps = "x P a; x P b", rest = "x Q c; y P a; y Q b";
+		final Model m = modelWithStatements(getModelProducer(), ps
+				+ "; " + rest);
+		final Resource r = resource("x");
+		final Resource r2 = r.removeAll(property("P"));
+		Assert.assertSame("removeAll should deliver its receiver", r, r2);
+		assertIsoModels("x's P-values should go",
+				modelWithStatements(getModelProducer(), rest), m);
+	}
+
+	@Test
+	public void testResourceAsLiteralThrows() {
+		final Model m = modelWithStatements(getModelProducer(), "");
+		final Literal l = m.createLiteral("hello, world");
+		try {
+			l.asResource();
+			Assert.fail("should not be able to do Literal.asResource()");
+		} catch (final ResourceRequiredException e) {
+		}
+	}
+	
+	@Test
+	public void testPortingBlankNodes()
+	{
+		final Model B = getModelProducer().newModel();
+		final Model model = getModelProducer().newModel();
+		final Resource anon = model.createResource();
+		final Resource bAnon = anon.inModel(B);
+		Assert.assertTrue("moved resource should still be blank",
+				bAnon.isAnon());
+		Assert.assertEquals("move resource should equal original", anon, bAnon);
+	}
+	
+	@Test
+	public void testAddLiteralPassesLiteralUnmodified()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		final Literal lit = model.createLiteral("spoo");
+		r.addLiteral(RDF.value, lit);
+		Assert.assertTrue("model should contain unmodified literal",
+				model.contains(null, RDF.value, lit));
+	}
+
+	@Test
+	public void testAddTypedPropertyBoolean()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, true);
+		Assert.assertEquals(model.createTypedLiteral(true),
+				r.getProperty(RDF.value).getLiteral());
+	}
+
+	@Test
+	public void testAddTypedPropertyChar()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 'x');
+		Assert.assertEquals(model.createTypedLiteral('x'),
+				r.getProperty(RDF.value).getLiteral());
+	}
+
+	@Test
+	public void testAddTypedPropertyDouble()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 1.0d);
+		Assert.assertEquals(model.createTypedLiteral(1.0d),
+				r.getProperty(RDF.value).getLiteral());
+	}
+
+	@Test
+	public void testAddTypedPropertyFloat()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 1.0f);
+		Assert.assertEquals(model.createTypedLiteral(1.0f),
+				r.getProperty(RDF.value).getLiteral());
+	}
+
+	@Test
+	public void testAddTypedPropertyInt()
+	{
+		//Model model = getModelProducer().newModel();
+		// Model model = ModelFactory.createDefaultModel();
+		// Resource r = model.createResource();
+		// r.addLiteral( RDF.value, 1 );
+		// assertEquals( model.createTypedLiteral( 1 ), r.getProperty( RDF.value
+		// ).getLiteral() );
+	}
+
+	@Test
+	public void testAddTypedPropertyLong()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 1L);
+		Assert.assertEquals(model.createTypedLiteral(1L),
+				r.getProperty(RDF.value).getLiteral());
+	}
+
+	@Test
+	public void testAddTypedPropertyObject()
+	{
+		Model model = getModelProducer().newModel();
+		final Object z = new Object();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, z);
+		Assert.assertEquals(model.createTypedLiteral(z),
+				r.getProperty(RDF.value).getLiteral());
+	}
+
+	@Test
+	public void testAddTypedPropertyString()
+	{
+
+	}
+
+	/**
+	 * Test that a literal node cannot be as'ed into a resource.
+	 */
+	@Test
+	public void testAsLiteral()
+	{
+		Model model = getModelProducer().newModel();
+		try
+		{
+			ModelHelper.literal(model, "17").as(Resource.class);
+			Assert.fail("literals cannot be resources");
+		}
+		catch (final ResourceRequiredException e)
+		{
+			JenaTestBase.pass();
+		}
+	}
+
+	/**
+	 * Test that a non-literal node can be as'ed into a resource
+	 */
+	@Test
+	public void testCannotAsNonLiteral()
+	{
+		Model model = getModelProducer().newModel();
+		ModelHelper.resource(model, "plumPie").as(Resource.class);
+	}
+
+	@Test
+	public void testGetLocalNameReturnsLocalName()
+	{
+		Model model = getModelProducer().newModel();
+		Assert.assertEquals("xyz", model.createResource("eh:xyz")
+				.getLocalName());
+	}
+
+	@Test
+	public void testGetModel()
+	{
+		Model model = getModelProducer().newModel();
+		Assert.assertSame(model, model.createResource("eh:/wossname")
+				.getModel());
+	}
+
+	@Test
+	public void testGetPropertyResourceValueReturnsNull()
+	{
+		final Model model = modelWithStatements(getModelProducer(), "x p 17");
+		final Resource r = model.createResource("eh:/x");
+		Assert.assertNull(r.getPropertyResourceValue(ModelHelper.property("q")));
+		Assert.assertNull(r.getPropertyResourceValue(ModelHelper.property("p")));
+	}
+
+	@Test
+	public void testGetPropertyResourceValueReturnsResource()
+	{
+		final Model model = modelWithStatements(getModelProducer(),
+				"x p 17; x p y");
+		final Resource r = model.createResource("eh:/x");
+		final Resource value = r.getPropertyResourceValue(ModelHelper
+				.property("p"));
+		Assert.assertEquals(ModelHelper.resource("y"), value);
+	}
+
+	@Test
+	public void testHasTypedPropertyBoolean()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, false);
+		Assert.assertTrue(r.hasLiteral(RDF.value, false));
+	}
+
+	@Test
+	public void testHasTypedPropertyChar()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 'x');
+		Assert.assertTrue(r.hasLiteral(RDF.value, 'x'));
+	}
+
+	@Test
+	public void testHasTypedPropertyDouble()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 1.0d);
+		Assert.assertTrue(r.hasLiteral(RDF.value, 1.0d));
+	}
+
+	@Test
+	public void testHasTypedPropertyFloat()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 1.0f);
+		Assert.assertTrue(r.hasLiteral(RDF.value, 1.0f));
+	}
+
+	@Test
+	public void testHasTypedPropertyInt()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 1);
+		Assert.assertTrue(r.hasLiteral(RDF.value, 1));
+	}
+
+	@Test
+	public void testHasTypedPropertyLong()
+	{
+		Model model = getModelProducer().newModel();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, 1L);
+		Assert.assertTrue(r.hasLiteral(RDF.value, 1L));
+	}
+
+	@Test
+	public void testHasTypedPropertyObject()
+	{
+		Model model = getModelProducer().newModel();
+			final Object z = new Object();
+		final Resource r = model.createResource();
+		r.addLiteral(RDF.value, z);
+		Assert.assertTrue(r.hasLiteral(RDF.value, z));
+	}
+
+	@Test
+	public void testHasTypedPropertyString()
+	{
+// FIXME implement this
+	}
+
+	@Test
+	public void testHasURI()
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = model.createResource("eh:xyz" );
+		Assert.assertTrue(r.hasURI("eh:xyz"));
+		Assert.assertFalse(r.hasURI("eh:1yz"));
+		r = model.createResource();
+		Assert.assertFalse(r.hasURI("42"));
+	}
+
+	@Test
+	public void testNameSpace()
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = model.createResource("eh:xyz" );
+		Assert.assertEquals("eh:", r.getNameSpace());
+		r = model.createResource("http://d/stuff");
+		Assert.assertEquals("http://d/", r.getNameSpace());
+		r = model.createResource("ftp://dd.com/12345");
+		Assert.assertEquals("ftp://dd.com/12345",
+				r.getNameSpace());
+		r = model.createResource("http://domain/spoo#anchor");
+		Assert.assertEquals("http://domain/spoo#",
+				r.getNameSpace());
+		r = model.createResource("ftp://abd/def#ghi#e11-2");
+		Assert.assertEquals("ftp://abd/def#ghi#",
+				r.getNameSpace());
+	}
+
+	// FIXME 
+	
+	protected final String lang = "en";
+	protected Literal tvLiteral;
+
+	protected Resource tvResource;
+
+	private Resource setUp(Model model) throws Exception
+	{
+		
+		tvLiteral = model.createLiteral("test 12 string 2");
+		tvResource = model.createResource();
+		Resource r = model.createResource()
+				.addLiteral(RDF.value, tvBoolean)
+				.addLiteral(RDF.value, tvByte)
+				.addLiteral(RDF.value, tvShort)
+				.addLiteral(RDF.value, tvInt)
+				.addLiteral(RDF.value, tvLong)
+				.addLiteral(RDF.value, tvChar)
+				.addLiteral(RDF.value, tvFloat)
+				.addLiteral(RDF.value, tvDouble)
+				.addProperty(RDF.value, tvString)
+				.addProperty(RDF.value, tvString, lang)
+				.addLiteral(RDF.value, tvObject)
+				.addProperty(RDF.value, tvLiteral)
+				.addProperty(RDF.value, tvResource);
+		return r;
+	}
+	
+	@Test
+	public void testAllSubjectsCorrect() throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		testHasSubjectR(r, model.listStatements());
+		testHasSubjectR(r, r.listProperties());
+	}
+
+	@Test
+	public void testBoolean()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasLiteral(RDF.value,
+				tvBoolean));
+	}
+
+	@Test
+	public void testByte()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasLiteral(RDF.value, tvByte));
+	}
+
+	@Test
+	public void testChar()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasLiteral(RDF.value, tvChar));
+	}
+
+	@Test
+	public void testCorrectSubject()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertEquals(r, r.getRequiredProperty(RDF.value).getSubject());
+	}
+
+	@Test
+	public void testCountsCorrect()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertEquals(13,
+				GraphTestBase.iteratorToList(model.listStatements()).size());
+		Assert.assertEquals(13,
+				GraphTestBase.iteratorToList(r.listProperties(RDF.value))
+						.size());
+		Assert.assertEquals(0,
+				GraphTestBase.iteratorToList(r.listProperties(RDF.type)).size());
+	}
+
+	@Test
+	public void testDouble()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasLiteral(RDF.value,
+				tvDouble));
+	}
+
+	@Test
+	public void testFloat()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r
+				.hasLiteral(RDF.value, tvFloat));
+	}
+
+	@Test
+	protected void testHasSubjectR( Resource r, final StmtIterator it )
+	{
+		while (it.hasNext())
+		{
+			Assert.assertEquals(r, it.nextStatement().getSubject());
+		}
+	}
+
+	@Test
+	public void testInt()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasLiteral(RDF.value, tvInt));
+	}
+
+	@Test
+	public void testLiteral()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasProperty(RDF.value, tvLiteral));
+	}
+
+	@Test
+	public void testLong()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasLiteral(RDF.value, tvLong));
+	}
+
+	@Test
+	public void testNoSuchPropertyException()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		try
+		{
+			r.getRequiredProperty(RDF.type);
+			Assert.fail("missing property should throw exception");
+		}
+		catch (final PropertyNotFoundException e)
+		{
+			JenaTestBase.pass();
+		}
+	}
+
+	@Test
+	public void testNoSuchPropertyNull()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertNull(r.getProperty(RDF.type));
+	}
+
+	@Test
+	public void testObject()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasLiteral(RDF.value,
+				tvObject));
+	}
+
+	@Test
+	public void testRemoveProperties()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		r.removeProperties();
+		Assert.assertEquals(false, model
+				.listStatements(r, null, (RDFNode) null).hasNext());
+	}
+
+	@Test
+	public void testResource()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasProperty(RDF.value, tvResource));
+	}
+
+	@Test
+	public void testShort()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r
+				.hasLiteral(RDF.value, tvShort));
+	}
+
+	@Test
+	public void testString()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasProperty(RDF.value,
+				tvString));
+	}
+
+	@Test
+	public void testStringWithLanguage()throws Exception
+	{
+		Model model = getModelProducer().newModel();
+		Resource r = setUp( model );
+		Assert.assertTrue(r.hasProperty(RDF.value,
+				tvString, lang));
+	}
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractResourceTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain