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 CDF76E500
for ;
Mon, 14 Jan 2013 22:39:17 +0000 (UTC)
Received: (qmail 1273 invoked by uid 500); 14 Jan 2013 22:39:17 -0000
Delivered-To: apmail-jena-commits-archive@jena.apache.org
Received: (qmail 1248 invoked by uid 500); 14 Jan 2013 22:39:17 -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 1235 invoked by uid 99); 14 Jan 2013 22:39:17 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jan 2013 22:39:17 +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; Mon, 14 Jan 2013 22:39:03 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id 14B792388C27;
Mon, 14 Jan 2013 22:38:42 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1433184 [3/9] - in /jena/trunk/jena-core/src:
main/java/com/hp/hpl/jena/graph/compose/
test/java/com/hp/hpl/jena/graph/compose/test/
test/java/com/hp/hpl/jena/graph/test/ test/java/com/hp/hpl/jena/mem/test/
test/java/com/hp/hpl/jena/rdf/ar...
Date: Mon, 14 Jan 2013 22:38:37 -0000
To: commits@jena.apache.org
From: andy@apache.org
X-Mailer: svnmailer-1.0.8-patched
Message-Id: <20130114223842.14B792388C27@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Modified: jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestIterators.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestIterators.java?rev=1433184&r1=1433183&r2=1433184&view=diff
==============================================================================
--- jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestIterators.java (original)
+++ jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestIterators.java Mon Jan 14 22:38:35 2013
@@ -1,14 +1,14 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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.
@@ -18,37 +18,290 @@
package com.hp.hpl.jena.rdf.model.test;
-import com.hp.hpl.jena.graph.test.*;
-import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.NodeIterator;
+import com.hp.hpl.jena.rdf.model.NsIterator;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.ResIterator;
+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.rdf.model.test.helpers.TestingModelFactory;
+import com.hp.hpl.jena.vocabulary.RDF;
-import junit.framework.TestSuite;
+import junit.framework.Assert;
-/**
- @author kers
-*/
-public class TestIterators extends GraphTestBase
- {
- public static TestSuite suite()
- { return new TestSuite( TestIterators.class ); }
-
- public TestIterators(String name)
- { super(name); }
-
- /**
- bug detected in StatementIteratorImpl - next does not
- advance current, so remove doesn't work with next;
- this test should expose the bug.
- */
- public void testIterators()
- {
- Model m = ModelFactory.createDefaultModel();
- Resource S = m.createResource( "S" );
- Property P = m.createProperty( "P" );
- RDFNode O = m.createResource( "O " );
- m.add( S, P, O );
- StmtIterator it = m.listStatements();
- it.next();
- it.remove();
- assertEquals( "", 0, m.size() );
- }
- }
+public class TestIterators extends AbstractModelTestBase
+{
+ int num = 5;
+ Resource subject[] = new Resource[num];
+ Property predicate[] = new Property[num];
+ Statement stmts[] = new Statement[num * num];
+
+ String suri = "http://aldabaran/test6/s";
+ String puri = "http://aldabaran/test6/";
+
+ public TestIterators( final TestingModelFactory modelFactory,
+ final String name )
+ {
+ super(modelFactory, name);
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ for (int i = 0; i < num; i++)
+ {
+ subject[i] = model.createResource(suri + Integer.toString(i));
+ predicate[i] = model
+ .createProperty(puri + Integer.toString(i), "p");
+ }
+
+ for (int i = 0; i < num; i++)
+ {
+ for (int j = 0; j < num; j++)
+ {
+ final Statement stmt = model.createStatement(subject[i],
+ predicate[j], model.createTypedLiteral((i * num) + j));
+ model.add(stmt);
+ model.add(stmt);
+ stmts[(i * num) + j] = stmt;
+ }
+ }
+ }
+
+ /**
+ * bug detected in StatementIteratorImpl - next does not
+ * advance current, so remove doesn't work with next;
+ * this test should expose the bug.
+ */
+ public void testIteratorRemove()
+ {
+ final StmtIterator it = model.listStatements();
+ try
+ {
+ while (it.hasNext())
+ {
+ it.next();
+ it.remove();
+ }
+ Assert.assertEquals("Remove failed", 0, model.size());
+ }
+ finally
+ {
+ it.close();
+ }
+
+ }
+
+ public void testListObjects()
+ {
+ int count = 0;
+ NodeIterator iter;
+ iter = model.listObjects();
+ while (iter.hasNext())
+ {
+ iter.nextNode();
+ count++;
+ }
+ Assert.assertEquals(num * num, count);
+ }
+
+ public void testNamespaceIterator()
+ {
+ final boolean predf[] = new boolean[num];
+ for (int i = 0; i < num; i++)
+ {
+ predf[i] = false;
+ }
+ final NsIterator nIter = model.listNameSpaces();
+ while (nIter.hasNext())
+ {
+ final String ns = nIter.nextNs();
+ boolean found = false;
+ for (int i = 0; i < num; i++)
+ {
+ if (ns.equals(predicate[i].getNameSpace()))
+ {
+ found = true;
+ Assert.assertFalse("Should not have found " + predicate[i]
+ + " already.", predf[i]);
+ predf[i] = true;
+ }
+ }
+ Assert.assertTrue("Should have found " + ns, found);
+ }
+ for (int i = 0; i < num; i++)
+ {
+ Assert.assertTrue("Should have found " + predicate[i], predf[i]);
+ }
+ }
+
+ public void testObjectsOfProperty()
+ {
+
+ NodeIterator iter;
+ final boolean[] object = new boolean[num * num];
+ for (int i = 0; i < (num * num); i++)
+ {
+ object[i] = false;
+ }
+ iter = model.listObjectsOfProperty(predicate[0]);
+ while (iter.hasNext())
+ {
+ final Literal l = (Literal) iter.nextNode();
+ final int i = l.getInt();
+ object[i] = true;
+ }
+ for (int i = 0; i < (num * num); i++)
+ {
+ if ((i % num) == 0)
+ {
+ Assert.assertTrue(object[i]);
+ }
+ else
+ {
+ Assert.assertFalse(object[i]);
+ }
+ }
+
+ }
+
+ public void testObjectsOfPropertyAndValue()
+ {
+ NodeIterator iter;
+ final boolean[] object = new boolean[num];
+ final Resource subj = model.createResource();
+ for (int i = 0; i < num; i++)
+ {
+ model.addLiteral(subj, RDF.value, i);
+ object[i] = false;
+ }
+
+ iter = model.listObjectsOfProperty(subj, RDF.value);
+ while (iter.hasNext())
+ {
+ final int i = ((Literal) iter.nextNode()).getInt();
+ object[i] = true;
+ }
+ for (int i = 0; i < (num); i++)
+ {
+ Assert.assertTrue(object[i]);
+ }
+ }
+
+ public void testResourceIterator()
+ {
+
+ final boolean subjf[] = new boolean[num];
+
+ for (int i = 0; i < num; i++)
+ {
+ subjf[i] = false;
+ }
+
+ boolean found = false;
+ final ResIterator rIter = model.listSubjects();
+ while (rIter.hasNext())
+ {
+ final Resource subj = rIter.nextResource();
+ found = false;
+ for (int i = 0; i < num; i++)
+ {
+ if (subj.equals(subject[i]))
+ {
+ found = true;
+ Assert.assertFalse("Should not have found " + subject[i]
+ + " already.", subjf[i]);
+ subjf[i] = true;
+ }
+ }
+ Assert.assertTrue("Should have found " + subj, found);
+ }
+ for (int i = 0; i < num; i++)
+ {
+ Assert.assertTrue("Should have found " + subject[i], subjf[i]);
+ }
+
+ // System.err.println(
+ // "WARNING: listNameSpace testing wonky for the moment" );
+ // NsIterator nIter = model.listNameSpaces();
+ // HashSet fromIterator = new HashSet();
+ // HashSet fromPredicates = new HashSet();
+ // while (nIter.hasNext()) fromIterator.add( nIter.next() );
+ // for (int i = 0; i < num; i += 1) fromPredicates.add(
+ // predicate[i].getNameSpace() );
+ // if (fromIterator.equals( fromPredicates ))
+ // {}
+ // else
+ // {
+ // System.err.println( "| oh dear." );
+ // System.err.println( "| predicate namespaces: " + fromPredicates );
+ // System.err.println( "| iterator namespaces: " + fromIterator );
+ // }
+
+ }
+
+ public void testStatementIter()
+ {
+ final int numStmts = num * num;
+ final boolean stmtf[] = new boolean[numStmts];
+ Assert.assertEquals(numStmts, model.size());
+ for (int i = 0; i < numStmts; i++)
+ {
+ stmtf[i] = false;
+ }
+
+ final StmtIterator sIter = model.listStatements();
+ while (sIter.hasNext())
+ {
+ final Statement stmt = sIter.nextStatement();
+ boolean found = false;
+ for (int i = 0; i < numStmts; i++)
+ {
+ if (stmt.equals(stmts[i]))
+ {
+ found = true;
+ Assert.assertFalse("Should not have found " + stmts[i]
+ + " already.", stmtf[i]);
+ stmtf[i] = true;
+ }
+ }
+ Assert.assertTrue("Should have found " + stmt, found);
+ }
+ for (int i = 0; i < numStmts; i++)
+ {
+ Assert.assertTrue("Should have found " + stmts[i], stmtf[i]);
+ }
+ }
+ // SEE the tests in model.test: TestReifiedStatements and
+ // TestStatementResources
+ // {
+ // System.err.println(
+ // "WARNING: reification testing suppressed for the moment" );
+ // /* Reification is not working properly
+ //
+ // for (int i=0; i
- * A collection of unit tests for the standard implementation of
- * {@link RDFList}.
+ * A collection of unit tests for the standard implementation of {@link RDFList}
+ * .
*
*
- * @author Ian Dickinson, HP Labs
- * (email)
- * @version CVS $Id: TestList.java,v 1.3 2010-01-11 09:17:05 chris-dollin Exp $
+ *
*/
-public class TestList
- extends TestCase
+public class TestList extends AbstractModelTestBase
{
- // Constants
- //////////////////////////////////
-
- public static final String NS = "uri:urn:x-rdf:test#";
-
+ // Constants
+ // ////////////////////////////////
- // Static variables
- //////////////////////////////////
+ public static final String NS = "uri:urn:x-rdf:test#";
-
- // Instance variables
- //////////////////////////////////
-
-
- // Constructors
- //////////////////////////////////
-
- public TestList( String name ) {
- super( name );
- }
-
- // External signature methods
- //////////////////////////////////
-
- public static TestSuite suite() {
- TestSuite s = new TestSuite( "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() );
- s.addTest( new CopyTest() );
- return s;
- }
-
-
-
- // Internal implementation methods
- //////////////////////////////////
-
- /** Test that an iterator delivers the expected values */
- protected static void iteratorTest( Iterator> i, Object[] expected ) {
- Logger logger = LoggerFactory.getLogger( TestList.class );
- List