You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by sa...@apache.org on 2013/01/29 21:27:39 UTC
svn commit: r1440101 [12/16] - in /jena/branches/streaming-update: ./
apache-jena-libs/ apache-jena/ apache-jena/bat/ apache-jena/bin/ jena-arq/
jena-arq/src-examples/arq/examples/riot/ jena-arq/src/main/java/arq/
jena-arq/src/main/java/arq/cmdline/ je...
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestLiteralsInModel.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestLiteralsInModel.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestLiteralsInModel.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestLiteralsInModel.java Tue Jan 29 20:27:24 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,78 +18,89 @@
package com.hp.hpl.jena.rdf.model.test;
-import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.test.helpers.ModelHelper;
+import com.hp.hpl.jena.rdf.model.test.helpers.TestingModelFactory;
-public class TestLiteralsInModel extends ModelTestBase
- {
- public TestLiteralsInModel( String name )
- { super( name ); }
-
- protected final Model m = getModel();
-
- protected Model getModel()
- { return ModelFactory.createDefaultModel(); }
-
- static final Resource X = resource( "X" );
-
- static final Property P = property( "P" );
-
- public void testAddWithFloatObject()
- {
- m.addLiteral( X, P, 14.0f );
- assertTrue( m.contains( X, P, m.createTypedLiteral( 14.0f ) ) );
- assertTrue( m.containsLiteral( X, P, 14.0f ) );
- }
-
- public void testAddWithDoubleObject()
- {
- m.addLiteral( X, P, 14.0d );
- assertTrue( m.contains( X, P, m.createTypedLiteral( 14.0d ) ) );
- assertTrue( m.containsLiteral( X, P, 14.0d ) );
- }
-
- public void testAddWithBooleanObject()
- {
- m.addLiteral( X, P, true );
- assertTrue( m.contains( X, P, m.createTypedLiteral( true ) ) );
- assertTrue( m.containsLiteral( X, P, true ) );
- }
-
- public void testAddWithCharObject()
- {
- m.addLiteral( X, P, 'x' );
- assertTrue( m.contains( X, P, m.createTypedLiteral( 'x' ) ) );
- assertTrue( m.containsLiteral( X, P, 'x' ) );
- }
-
- public void testAddWithLongObject()
- {
- m.addLiteral( X, P, 99L );
- assertTrue( m.contains( X, P, m.createTypedLiteral( 99L ) ) );
- assertTrue( m.containsLiteral( X, P, 99L ) );
- }
-
- public void testAddWithLiteralObject()
- {
- Literal lit = m.createLiteral( "spoo" );
- m.addLiteral( X, P, lit );
- assertTrue( m.contains( X, P, lit ) );
- assertTrue( m.containsLiteral( X, P, lit ) );
- }
-
- public void testAddWithIntObject()
- {
- m.addLiteral( X, P, 99 );
- assertTrue( m.contains( X, P, m.createTypedLiteral( 99 ) ) );
- assertTrue( m.containsLiteral( X, P, 99 ) );
- }
-
-// that version of addLiteral is deprecated; test removed.
-// public void testAddWithAnObject()
-// {
-// Object z = new Date();
-// m.addLiteral( X, P, z );
-// assertTrue( m.contains( X, P, m.createTypedLiteral( z ) ) );
-// assertTrue( m.containsLiteral( X, P, z ) );
-// }
- }
+import junit.framework.Assert;
+
+public class TestLiteralsInModel extends AbstractModelTestBase
+{
+ private Resource X;
+ private Property P;
+
+ public TestLiteralsInModel( final TestingModelFactory modelFactory,
+ final String name )
+ {
+ super(modelFactory, name);
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ X = ModelHelper.resource("X");
+ P = ModelHelper.property("P");
+ }
+
+ public void testAddWithBooleanObject()
+ {
+ model.addLiteral(X, P, true);
+ Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(true)));
+ Assert.assertTrue(model.containsLiteral(X, P, true));
+ }
+
+ public void testAddWithCharObject()
+ {
+ model.addLiteral(X, P, 'x');
+ Assert.assertTrue(model.contains(X, P, model.createTypedLiteral('x')));
+ Assert.assertTrue(model.containsLiteral(X, P, 'x'));
+ }
+
+ public void testAddWithDoubleObject()
+ {
+ model.addLiteral(X, P, 14.0d);
+ Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(14.0d)));
+ Assert.assertTrue(model.containsLiteral(X, P, 14.0d));
+ }
+
+ public void testAddWithFloatObject()
+ {
+ model.addLiteral(X, P, 14.0f);
+ Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(14.0f)));
+ Assert.assertTrue(model.containsLiteral(X, P, 14.0f));
+ }
+
+ public void testAddWithIntObject()
+ {
+ model.addLiteral(X, P, 99);
+ Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(99)));
+ Assert.assertTrue(model.containsLiteral(X, P, 99));
+ }
+
+ public void testAddWithLiteralObject()
+ {
+ final Literal lit = model.createLiteral("spoo");
+ model.addLiteral(X, P, lit);
+ Assert.assertTrue(model.contains(X, P, lit));
+ Assert.assertTrue(model.containsLiteral(X, P, lit));
+ }
+
+ public void testAddWithLongObject()
+ {
+ model.addLiteral(X, P, 99L);
+ Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(99L)));
+ Assert.assertTrue(model.containsLiteral(X, P, 99L));
+ }
+
+ // that version of addLiteral is deprecated; test removed.
+ // public void testAddWithAnObject()
+ // {
+ // Object z = new Date();
+ // model.addLiteral( X, P, z );
+ // assertTrue( model.contains( X, P, model.createTypedLiteral( z ) ) );
+ // assertTrue( model.containsLiteral( X, P, z ) );
+ // }
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelBulkUpdate.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelBulkUpdate.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelBulkUpdate.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelBulkUpdate.java Tue Jan 29 20:27:24 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,100 +18,136 @@
package com.hp.hpl.jena.rdf.model.test;
-import java.util.Arrays ;
-import java.util.List ;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.test.helpers.ModelHelper;
+import com.hp.hpl.jena.rdf.model.test.helpers.TestingModelFactory;
+import com.hp.hpl.jena.shared.PrefixMapping;
-import junit.framework.TestSuite ;
+import java.util.Arrays;
+import java.util.List;
-import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.rdf.model.ModelFactory ;
-import com.hp.hpl.jena.rdf.model.Statement ;
+import junit.framework.Assert;
/**
- Tests of the Model-level bulk update API.
-
- @author kers
+ * Tests of the Model-level bulk update API.
*/
-public class TestModelBulkUpdate extends ModelTestBase
+public class TestModelBulkUpdate extends AbstractModelTestBase
{
- public TestModelBulkUpdate( String name )
- { super( name ); }
-
- public static TestSuite suite()
- { return new TestSuite( TestModelBulkUpdate.class ); }
-
- public void testMBU()
- { testMBU( ModelFactory.createDefaultModel() ); }
-
- public void testContains( Model m, Statement [] statements )
- {
- for (int i = 0; i < statements.length; i += 1)
- assertTrue( "it should be here", m.contains( statements[i] ) );
- }
-
- public void testContains( Model m, List<Statement> statements )
- {
- for (int i = 0; i < statements.size(); i += 1)
- assertTrue( "it should be here", m.contains( statements.get(i) ) );
- }
-
- public void testOmits( Model m, Statement [] statements )
- {
- for (int i = 0; i < statements.length; i += 1)
- assertFalse( "it should not be here", m.contains( statements[i] ) );
- }
-
- public void testOmits( Model m, List<Statement> statements )
- {
- for (int i = 0; i < statements.size(); i += 1)
- assertFalse( "it should not be here", m.contains( statements.get(i) ) );
- }
-
- public void testMBU( Model m )
- {
- Statement [] sArray = statements( m, "moon orbits earth; earth orbits sun" );
- List<Statement> sList = Arrays.asList( statements( m, "I drink tea; you drink coffee" ) );
- m.add( sArray );
- testContains( m, sArray );
- m.add( sList );
- testContains( m, sList );
- testContains( m, sArray );
- /* */
- m.remove( sArray );
- testOmits( m, sArray );
- testContains( m, sList );
- m.remove( sList );
- testOmits( m, sArray );
- testOmits( m, sList );
- }
-
- public void testBulkByModel()
- { testBulkByModel( ModelFactory.createDefaultModel() ); }
-
- public void testBulkByModel( Model m )
- {
- assertEquals( "precondition: model must be empty", 0, m.size() );
- Model A = modelWithStatements( "clouds offer rain; trees offer shelter" );
- Model B = modelWithStatements( "x R y; y Q z; z P x" );
- m.add( A );
- assertIsoModels( A, m );
- m.add( B );
- m.remove( A );
- assertIsoModels( B, m );
- m.remove( B );
- assertEquals( "", 0, m.size() );
- }
-
- public void testBulkRemoveSelf()
- {
- Model m = modelWithStatements( "they sing together; he sings alone" );
- m.remove( m );
- assertEquals( "", 0, m.size() );
- }
-
- public void addReification( Model m, String tag, String statement )
- {
- m.createReifiedStatement( tag, statement( m, statement ) );
- }
+ public TestModelBulkUpdate( final TestingModelFactory modelFactory,
+ final String name )
+ {
+ super(modelFactory, name);
+ }
+
+ public void addReification( final Model m, final String tag,
+ final String statement )
+ {
+ m.createReifiedStatement(tag, ModelHelper.statement(m, statement));
+ }
+
+ public void testBulkByModel()
+ {
+ Assert.assertEquals("precondition: model must be empty", 0,
+ model.size());
+ final Model A = ModelHelper.modelWithStatements(this,
+ "clouds offer rain; trees offer shelter");
+ final Model B = ModelHelper.modelWithStatements(this,
+ "x R y; y Q z; z P x");
+ model.add(A);
+ ModelHelper.assertIsoModels(A, model);
+ model.add(B);
+ model.remove(A);
+ ModelHelper.assertIsoModels(B, model);
+ model.remove(B);
+ Assert.assertEquals("", 0, model.size());
+ }
+
+ public void testBulkByModelReifying()
+ {
+ final Model m = ModelHelper.modelWithStatements(this, "a P b");
+ addReification(m, "x", "S P O");
+ addReification(m, "a", "x R y");
+ final Model target = ModelHelper.modelWithStatements(this, "");
+ target.add(m);
+ target.setNsPrefixes(PrefixMapping.Standard);
+ ModelHelper.assertIsoModels(m, target);
+ }
+
+ public void testBulkDeleteByModelReifying()
+ {
+
+ final Model target = ModelHelper.modelWithStatements(this, "");
+ addReification(target, "x", "S P O");
+ addReification(target, "y", "A P B");
+ final Model remove = ModelHelper.modelWithStatements(this, "");
+ addReification(remove, "y", "A P B");
+ final Model answer = ModelHelper.modelWithStatements(this, "");
+ addReification(answer, "x", "S P O");
+ target.remove(remove);
+ ModelHelper.assertIsoModels(answer, target);
+ }
+
+ public void testBulkRemoveSelf()
+ {
+ final Model m = ModelHelper.modelWithStatements(this,
+ "they sing together; he sings alone");
+ m.remove(m);
+ Assert.assertEquals("", 0, m.size());
+ }
+
+ public void testContains( final Model m, final List<Statement> statements )
+ {
+ for (int i = 0; i < statements.size(); i += 1)
+ {
+ Assert.assertTrue("it should be here",
+ m.contains(statements.get(i)));
+ }
+ }
+
+ public void testContains( final Model m, final Statement[] statements )
+ {
+ for (final Statement statement : statements)
+ {
+ Assert.assertTrue("it should be here", m.contains(statement));
+ }
+ }
+
+ public void testMBU()
+ {
+ final Statement[] sArray = ModelHelper.statements(model,
+ "moon orbits earth; earth orbits sun");
+ final List<Statement> sList = Arrays.asList(ModelHelper.statements(
+ model, "I drink tea; you drink coffee"));
+ model.add(sArray);
+ testContains(model, sArray);
+ model.add(sList);
+ testContains(model, sList);
+ testContains(model, sArray);
+ /* */
+ model.remove(sArray);
+ testOmits(model, sArray);
+ testContains(model, sList);
+ model.remove(sList);
+ testOmits(model, sArray);
+ testOmits(model, sList);
+ }
+
+ public void testOmits( final Model m, final List<Statement> statements )
+ {
+ for (int i = 0; i < statements.size(); i += 1)
+ {
+ Assert.assertFalse("it should not be here",
+ m.contains(statements.get(i)));
+ }
+ }
+
+ public void testOmits( final Model m, final Statement[] statements )
+ {
+ for (final Statement statement : statements)
+ {
+ Assert.assertFalse("it should not be here", m.contains(statement));
+ }
+ }
}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelEvents.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelEvents.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelEvents.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelEvents.java Tue Jan 29 20:27:24 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,362 +18,440 @@
package com.hp.hpl.jena.rdf.model.test;
-import com.hp.hpl.jena.rdf.listeners.*;
-import com.hp.hpl.jena.rdf.model.*;
-import com.hp.hpl.jena.rdf.model.impl.*;
+import com.hp.hpl.jena.graph.test.GraphTestBase;
+import com.hp.hpl.jena.rdf.listeners.ChangedListener;
+import com.hp.hpl.jena.rdf.listeners.NullListener;
+import com.hp.hpl.jena.rdf.listeners.ObjectListener;
+import com.hp.hpl.jena.rdf.listeners.StatementListener;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelChangedListener;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl;
+import com.hp.hpl.jena.rdf.model.test.helpers.ModelHelper;
+import com.hp.hpl.jena.rdf.model.test.helpers.RecordingModelListener;
+import com.hp.hpl.jena.rdf.model.test.helpers.TestingModelFactory;
-import java.util.*;
-import junit.framework.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
/**
- Tests for model events and listeners.
- @author kers
-*/
-public class TestModelEvents extends ModelTestBase
- {
- public TestModelEvents(String name)
- { super(name); }
-
- public static TestSuite suite()
- { return new TestSuite( TestModelEvents.class ); }
-
- protected Model model;
- protected RecordingModelListener SL;
-
- @Override public void setUp()
- {
- model = ModelFactory.createDefaultModel();
- SL = new RecordingModelListener();
- }
-
- public void testRegistrationCompiles()
- {
- assertSame( model, model.register( new RecordingModelListener() ) );
- }
-
- public void testUnregistrationCompiles()
- {
- model.unregister( new RecordingModelListener() );
- }
-
- public void testAddSingleStatements()
- {
- Statement S1 = statement( model, "S P O" );
- Statement S2 = statement( model, "A B C" );
- assertFalse( SL.has( new Object [] { "add", S1 } ) );
- model.register( SL );
- model.add( S1 );
- SL.assertHas( new Object[] { "add", S1 } );
- model.add( S2 );
- SL.assertHas( new Object[] { "add", S1, "add", S2 } );
- model.add( S1 );
- SL.assertHas( new Object[] { "add", S1, "add", S2, "add", S1 } );
- }
-
- public void testTwoListeners()
- {
- Statement S = statement( model, "S P O" );
- RecordingModelListener SL1 = new RecordingModelListener();
- RecordingModelListener SL2 = new RecordingModelListener();
- model.register( SL1 ).register( SL2 );
- model.add( S );
- SL2.assertHas( new Object[] { "add", S } );
- SL1.assertHas( new Object[] { "add", S } );
- }
-
- public void testUnregisterWorks()
- {
- model.register( SL );
- model.unregister( SL );
- model.add( statement( model, "X R Y" ) );
- SL.assertHas( new Object[] {} );
- }
-
- public void testRemoveSingleStatements()
- {
- Statement S = statement( model, "D E F" );
- model.register( SL );
- model.add( S );
- model.remove( S );
- SL.assertHas( new Object[] { "add", S, "remove", S } );
- }
-
- public void testAddInPieces()
- {
- model.register( SL );
- model.add( resource( model, "S" ), property( model, "P" ), resource( model, "O" ) );
- SL.assertHas( new Object[] { "add", statement( model, "S P O") } );
- }
-
- public void testAddStatementArray()
- {
- model.register( SL );
- Statement [] s = statements( model, "a P b; c Q d" );
- model.add( s );
- SL.assertHas( new Object[] {"add[]", Arrays.asList( s )} );
- }
-
- public void testDeleteStatementArray()
- {
- model.register( SL );
- Statement [] s = statements( model, "a P b; c Q d" );
- model.remove( s );
- SL.assertHas( new Object[] {"remove[]", Arrays.asList( s )} );
- }
-
- public void testAddStatementList()
- {
- model.register( SL );
- List<Statement> L = Arrays.asList( statements( model, "b I g; m U g" ) );
- model.add( L );
- SL.assertHas( new Object[] {"addList", L} );
- }
-
- public void testDeleteStatementList()
- {
- model.register( SL );
- List<Statement> L = Arrays.asList( statements( model, "b I g; m U g" ) );
- model.remove( L );
- SL.assertHas( new Object[] {"removeList", L} );
- }
-
- public void testAddStatementIterator()
- {
- model.register( SL );
- Statement [] sa = statements( model, "x R y; a P b; x R y" );
- StmtIterator it = asIterator( sa );
- model.add( it );
- SL.assertHas( new Object[] {"addIterator", Arrays.asList( sa )} );
- }
-
- public void testDeleteStatementIterator()
- {
- model.register( SL );
- Statement [] sa = statements( model, "x R y; a P b; x R y" );
- StmtIterator it = asIterator( sa );
- model.remove( it );
- SL.assertHas( new Object[] {"removeIterator", Arrays.asList( sa )} );
- }
-
- protected StmtIterator asIterator( Statement [] statements )
- { return new StmtIteratorImpl( Arrays.asList( statements ).iterator() ); }
-
- public void testAddModel()
- {
- model.register( SL );
- Model m = modelWithStatements( "NT beats S; S beats H; H beats D" );
- model.add( m );
- SL.assertHas( new Object[] {"addModel", m} );
- }
-
- public void testDeleteModel()
- {
- model.register( SL );
- Model m = modelWithStatements( "NT beats S; S beats H; H beats D" );
- model.remove( m );
- SL.assertHas( new Object[] {"removeModel", m} );
- }
-
- /**
- Test that the null listener doesn't appear to do anything. Or at least
- doesn't crash ....
- */
- public void testNullListener()
- {
- ModelChangedListener NL = new NullListener();
- model.register( NL );
- model.add( statement( model, "S P O " ) );
- model.remove( statement( model, "X Y Z" ) );
- model.add( statements( model, "a B c; d E f" ) );
- model.remove( statements( model, "g H i; j K l" ) );
- model.add( asIterator( statements( model, "m N o; p Q r" ) ) );
- model.remove( asIterator( statements( model, "s T u; v W x" ) ) );
- model.add( modelWithStatements( "leaves fall softly" ) );
- model.remove( modelWithStatements( "water drips endlessly" ) );
- model.add( Arrays.asList( statements( model, "xx RR yy" ) ) );
- model.remove( Arrays.asList( statements( model, "aa VV rr" ) ) );
- }
-
- public void testChangedListener()
- {
- ChangedListener CL = new ChangedListener();
- model.register( CL );
- assertFalse( CL.hasChanged() );
- model.add( statement( model, "S P O" ) );
- assertTrue( CL.hasChanged() );
- assertFalse( CL.hasChanged() );
- model.remove( statement( model, "ab CD ef" ) );
- assertTrue( CL.hasChanged() );
- model.add( statements( model, "gh IJ kl" ) );
- assertTrue( CL.hasChanged() );
- model.remove( statements( model, "mn OP qr" ) );
- assertTrue( CL.hasChanged() );
- model.add( asIterator( statements( model, "st UV wx" ) ) );
- assertTrue( CL.hasChanged() );
- assertFalse( CL.hasChanged() );
- model.remove( asIterator( statements( model, "yz AB cd" ) ) );
- assertTrue( CL.hasChanged() );
- model.add( modelWithStatements( "ef GH ij" ) );
- assertTrue( CL.hasChanged() );
- model.remove( modelWithStatements( "kl MN op" ) );
- assertTrue( CL.hasChanged() );
- model.add( Arrays.asList( statements( model, "rs TU vw" ) ) );
- assertTrue( CL.hasChanged() );
- model.remove( Arrays.asList( statements( model, "xy wh q" ) ) );
- assertTrue( CL.hasChanged() );
- }
-
- public void testGeneralEvent()
- {
- model.register( SL );
- Object e = new int [] {};
- model.notifyEvent( e );
- SL.assertHas( new Object[] {"someEvent", model, e} );
- }
-
- /**
- Local test class to see that a StatementListener funnels all the changes through
- add/remove a single statement
- */
- public static class WatchStatementListener extends StatementListener
- {
- List<Statement> statements = new ArrayList<Statement>();
- String addOrRem = "<unset>";
-
- public List<Statement> contents()
- { try { return statements; } finally { statements = new ArrayList<Statement>(); } }
-
- public String getAddOrRem()
- { return addOrRem; }
-
- @Override
- public void addedStatement( Statement s )
- { statements.add( s ); addOrRem = "add"; }
-
- @Override
- public void removedStatement( Statement s )
- { statements.add( s ); addOrRem = "rem"; }
- }
-
- public void another( Map<Object, Integer> m, Object x )
- {
- Integer n = m.get( x );
- if (n == null) n = new Integer(0);
- m.put( x, new Integer( n.intValue() + 1 ) );
- }
-
- public Map<Object, Integer> asBag( List<Statement> l )
- {
- Map<Object, Integer> result = new HashMap<Object, Integer>();
- for (int i = 0; i < l.size(); i += 1) another( result, l.get(i) );
- return result;
- }
-
- public void assertSameBag( List<Statement> wanted, List<Statement> got )
- { assertEquals( asBag( wanted ), asBag( got ) ); }
-
- public void testGot( WatchStatementListener sl, String how, String template )
- {
- assertSameBag( Arrays.asList( statements( model, template ) ), sl.contents() );
- assertEquals( how, sl.getAddOrRem() );
- assertTrue( sl.contents().size() == 0 );
- }
-
- public void testTripleListener()
- {
- WatchStatementListener sl = new WatchStatementListener();
- model.register( sl );
- model.add( statement( model, "b C d" ) );
- testGot( sl, "add", "b C d" );
- model.remove( statement( model, "e F g" ) );
- testGot( sl, "rem", "e F g" );
- /* */
- model.add( statements( model, "h I j; k L m" ) );
- testGot( sl, "add", "h I j; k L m" );
- model.remove( statements( model, "n O p; q R s" ) );
- testGot( sl, "rem", "n O p; q R s" );
- /* */
- model.add( Arrays.asList( statements( model, "t U v; w X y" ) ) );
- testGot( sl, "add", "t U v; w X y" );
- model.remove( Arrays.asList( statements( model, "z A b; c D e" ) ) );
- testGot( sl, "rem", "z A b; c D e" );
- /* */
- model.add( asIterator( statements( model, "f G h; i J k" ) ) );
- testGot( sl, "add", "f G h; i J k" );
- model.remove( asIterator( statements( model, "l M n; o P q" ) ) );
- testGot( sl, "rem", "l M n; o P q" );
- /* */
- model.add( modelWithStatements( "r S t; u V w; x Y z" ) );
- testGot( sl, "add", "r S t; u V w; x Y z" );
- model.remove( modelWithStatements( "a E i; o U y" ) );
- testGot( sl, "rem", "a E i; o U y" );
- }
-
-
- static class OL extends ObjectListener
- {
- private Object recorded;
- private String how;
-
- @Override
- public void added( Object x )
- { recorded = x; how = "add"; }
-
- @Override
- public void removed( Object x )
- { recorded = x; how = "rem"; }
-
- private Object comparable( Object x )
- {
- if (x instanceof Statement []) return Arrays.asList( (Statement []) x );
- if (x instanceof Iterator<?>) return iteratorToList( (Iterator<?>) x );
- return x;
- }
-
- public void recent( String wantHow, Object value )
- {
- assertEquals( comparable( value ), comparable( recorded ) );
- assertEquals( wantHow, how );
- recorded = how = null;
- }
- }
-
- public void testObjectListener()
- {
- OL ll = new OL();
- model.register( ll );
- Statement s = statement( model, "aa BB cc" ), s2 = statement( model, "dd EE ff" );
- model.add( s );
- ll.recent( "add", s );
- model.remove( s2 );
- ll.recent( "rem", s2 );
- /* */
- List<Statement> sList = Arrays.asList( statements( model, "gg HH ii; jj KK ll" ) );
- model.add( sList );
- ll.recent( "add", sList );
- List<Statement> sList2 = Arrays.asList( statements( model, "mm NN oo; pp QQ rr; ss TT uu" ) );
- model.remove( sList2 );
- ll.recent( "rem", sList2 );
- /* */
- Model m1 = modelWithStatements( "vv WW xx; yy ZZ aa" );
- model.add( m1 );
- ll.recent( "add", m1 );
- Model m2 = modelWithStatements( "a B g; d E z" );
- model.remove( m2 );
- ll.recent( "rem", m2 );
- /* */
- Statement [] sa1 = statements( model, "th i k; l m n" );
- model.add( sa1 );
- ll.recent( "add", sa1 );
- Statement [] sa2 = statements( model, "x o p; r u ch" );
- model.remove( sa2 );
- ll.recent( "rem", sa2 );
- /* */
- Statement [] si1 = statements( model, "u ph ch; psi om eh" );
- model.add( asIterator( si1 ) );
- ll.recent( "add", asIterator( si1 ) );
- Statement [] si2 = statements( model, "at last the; end of these; tests ok guv" );
- model.remove( asIterator( si2 ) );
- ll.recent( "rem", asIterator( si2 ) );
- }
- }
+ * Tests for model events and listeners.
+ */
+public class TestModelEvents extends AbstractModelTestBase
+{
+ static class OL extends ObjectListener
+ {
+ private Object recorded;
+ private String how;
+
+ @Override
+ public void added( final Object x )
+ {
+ recorded = x;
+ how = "add";
+ }
+
+ private Object comparable( final Object x )
+ {
+ if (x instanceof Statement[])
+ {
+ return Arrays.asList((Statement[]) x);
+ }
+ if (x instanceof Iterator<?>)
+ {
+ return GraphTestBase.iteratorToList((Iterator<?>) x);
+ }
+ return x;
+ }
+
+ public void recent( final String wantHow, final Object value )
+ {
+ Assert.assertTrue(RecordingModelListener.checkEquality(
+ comparable(value), comparable(recorded)));
+ // Assert.assertEquals(comparable(value), comparable(recorded));
+ Assert.assertEquals(wantHow, how);
+ recorded = how = null;
+ }
+
+ @Override
+ public void removed( final Object x )
+ {
+ recorded = x;
+ how = "rem";
+ }
+ }
+
+ /**
+ * Local test class to see that a StatementListener funnels all the changes
+ * through
+ * add/remove a single ModelHelper.statement
+ */
+ public static class WatchStatementListener extends StatementListener
+ {
+ List<Statement> statements = new ArrayList<Statement>();
+ String addOrRem = "<unset>";
+
+ @Override
+ public void addedStatement( final Statement s )
+ {
+ statements.add(s);
+ addOrRem = "add";
+ }
+
+ public List<Statement> contents()
+ {
+ try
+ {
+ return statements;
+ }
+ finally
+ {
+ statements = new ArrayList<Statement>();
+ }
+ }
+
+ public String getAddOrRem()
+ {
+ return addOrRem;
+ }
+
+ @Override
+ public void removedStatement( final Statement s )
+ {
+ statements.add(s);
+ addOrRem = "rem";
+ }
+ }
+
+ protected RecordingModelListener SL;
+
+ public TestModelEvents( final TestingModelFactory modelFactory,
+ final String name )
+ {
+ super(modelFactory, name);
+ }
+
+ public void another( final Map<Object, Integer> m, final Object x )
+ {
+ Integer n = m.get(x);
+ if (n == null)
+ {
+ n = new Integer(0);
+ }
+ m.put(x, new Integer(n.intValue() + 1));
+ }
+
+ public Map<Object, Integer> asBag( final List<Statement> l )
+ {
+ final Map<Object, Integer> result = new HashMap<Object, Integer>();
+ for (int i = 0; i < l.size(); i += 1)
+ {
+ another(result, l.get(i).asTriple());
+ }
+ return result;
+ }
+
+ protected StmtIterator asIterator( final Statement[] statements )
+ {
+ return new StmtIteratorImpl(Arrays.asList(statements).iterator());
+ }
+
+ public void assertSameBag( final List<Statement> wanted,
+ final List<Statement> got )
+ {
+
+ Assert.assertEquals(asBag(wanted), asBag(got));
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ SL = new RecordingModelListener();
+ }
+
+ public void testAddInPieces()
+ {
+ model.register(SL);
+ model.add(ModelHelper.resource(model, "S"),
+ ModelHelper.property(model, "P"),
+ ModelHelper.resource(model, "O"));
+ SL.assertHas(new Object[] { "add",
+ ModelHelper.statement(model, "S P O") });
+ }
+
+ public void testAddModel()
+ {
+ model.register(SL);
+ final Model m = ModelHelper.modelWithStatements(this,
+ "NT beats S; S beats H; H beats D");
+ model.add(m);
+ SL.assertHas(new Object[] { "addModel", m });
+ }
+
+ public void testAddSingleStatements()
+ {
+ final Statement S1 = ModelHelper.statement(model, "S P O");
+ final Statement S2 = ModelHelper.statement(model, "A B C");
+ Assert.assertFalse(SL.has(new Object[] { "add", S1 }));
+ model.register(SL);
+ model.add(S1);
+ SL.assertHas(new Object[] { "add", S1 });
+ model.add(S2);
+ SL.assertHas(new Object[] { "add", S1, "add", S2 });
+ model.add(S1);
+ SL.assertHas(new Object[] { "add", S1, "add", S2, "add", S1 });
+ }
+
+ public void testAddStatementArray()
+ {
+ model.register(SL);
+ final Statement[] s = ModelHelper.statements(model, "a P b; c Q d");
+ model.add(s);
+ SL.assertHas(new Object[] { "add[]", Arrays.asList(s) });
+ }
+
+ public void testAddStatementIterator()
+ {
+ model.register(SL);
+ final Statement[] sa = ModelHelper.statements(model,
+ "x R y; a P b; x R y");
+ final StmtIterator it = asIterator(sa);
+ model.add(it);
+ SL.assertHas(new Object[] { "addIterator", Arrays.asList(sa) });
+ }
+
+ public void testAddStatementList()
+ {
+ model.register(SL);
+ final List<Statement> L = Arrays.asList(ModelHelper.statements(model,
+ "b I g; model U g"));
+ model.add(L);
+ SL.assertHas(new Object[] { "addList", L });
+ }
+
+ public void testChangedListener()
+ {
+ final ChangedListener CL = new ChangedListener();
+ model.register(CL);
+ Assert.assertFalse(CL.hasChanged());
+ model.add(ModelHelper.statement(model, "S P O"));
+ Assert.assertTrue(CL.hasChanged());
+ Assert.assertFalse(CL.hasChanged());
+ model.remove(ModelHelper.statement(model, "ab CD ef"));
+ Assert.assertTrue(CL.hasChanged());
+ model.add(ModelHelper.statements(model, "gh IJ kl"));
+ Assert.assertTrue(CL.hasChanged());
+ model.remove(ModelHelper.statements(model, "mn OP qr"));
+ Assert.assertTrue(CL.hasChanged());
+ model.add(asIterator(ModelHelper.statements(model, "st UV wx")));
+ Assert.assertTrue(CL.hasChanged());
+ Assert.assertFalse(CL.hasChanged());
+ model.remove(asIterator(ModelHelper.statements(model, "yz AB cd")));
+ Assert.assertTrue(CL.hasChanged());
+ model.add(ModelHelper.modelWithStatements(this, "ef GH ij"));
+ Assert.assertTrue(CL.hasChanged());
+ model.remove(ModelHelper.modelWithStatements(this, "kl MN op"));
+ Assert.assertTrue(CL.hasChanged());
+ model.add(Arrays.asList(ModelHelper.statements(model, "rs TU vw")));
+ Assert.assertTrue(CL.hasChanged());
+ model.remove(Arrays.asList(ModelHelper.statements(model, "xy wh q")));
+ Assert.assertTrue(CL.hasChanged());
+ }
+
+ public void testDeleteModel()
+ {
+ model.register(SL);
+ final Model m = ModelHelper.modelWithStatements(this,
+ "NT beats S; S beats H; H beats D");
+ model.remove(m);
+ SL.assertHas(new Object[] { "removeModel", m });
+ }
+
+ public void testDeleteStatementArray()
+ {
+ model.register(SL);
+ final Statement[] s = ModelHelper.statements(model, "a P b; c Q d");
+ model.remove(s);
+ SL.assertHas(new Object[] { "remove[]", Arrays.asList(s) });
+ }
+
+ public void testDeleteStatementIterator()
+ {
+ model.register(SL);
+ final Statement[] sa = ModelHelper.statements(model,
+ "x R y; a P b; x R y");
+ final StmtIterator it = asIterator(sa);
+ model.remove(it);
+ SL.assertHas(new Object[] { "removeIterator", Arrays.asList(sa) });
+ }
+
+ public void testDeleteStatementList()
+ {
+ model.register(SL);
+ final List<Statement> lst = Arrays.asList(ModelHelper.statements(model,
+ "b I g; model U g"));
+ model.remove(lst);
+ SL.assertHas(new Object[] { "removeList", lst });
+ }
+
+ public void testGeneralEvent()
+ {
+ model.register(SL);
+ final Object e = new int[] {};
+ model.notifyEvent(e);
+ SL.assertHas(new Object[] { "someEvent", model, e });
+ }
+
+ public void testGot( final WatchStatementListener sl, final String how,
+ final String template )
+ {
+ assertSameBag(Arrays.asList(ModelHelper.statements(model, template)),
+ sl.contents());
+ Assert.assertEquals(how, sl.getAddOrRem());
+ Assert.assertTrue(sl.contents().size() == 0);
+ }
+
+ /**
+ * Test that the null listener doesn't appear to do anything. Or at least
+ * doesn't crash ....
+ */
+ public void testNullListener()
+ {
+ final ModelChangedListener NL = new NullListener();
+ model.register(NL);
+ model.add(ModelHelper.statement(model, "S P O "));
+ model.remove(ModelHelper.statement(model, "X Y Z"));
+ model.add(ModelHelper.statements(model, "a B c; d E f"));
+ model.remove(ModelHelper.statements(model, "g H i; j K l"));
+ model.add(asIterator(ModelHelper.statements(model, "model N o; p Q r")));
+ model.remove(asIterator(ModelHelper.statements(model, "s T u; v W x")));
+ model.add(ModelHelper.modelWithStatements(this, "leaves fall softly"));
+ model.remove(ModelHelper.modelWithStatements(this,
+ "water drips endlessly"));
+ model.add(Arrays.asList(ModelHelper.statements(model, "xx RR yy")));
+ model.remove(Arrays.asList(ModelHelper.statements(model, "aa VV rr")));
+ }
+
+ public void testObjectListener()
+ {
+ final OL ll = new OL();
+ model.register(ll);
+ final Statement s = ModelHelper.statement(model, "aa BB cc"), s2 = ModelHelper
+ .statement(model, "dd EE ff");
+ model.add(s);
+ ll.recent("add", s);
+ model.remove(s2);
+ ll.recent("rem", s2);
+ /* */
+ final List<Statement> sList = Arrays.asList(ModelHelper.statements(
+ model, "gg HH ii; jj KK ll"));
+ model.add(sList);
+ ll.recent("add", sList);
+ final List<Statement> sList2 = Arrays.asList(ModelHelper.statements(
+ model, "mm NN oo; pp QQ rr; ss TT uu"));
+ model.remove(sList2);
+ ll.recent("rem", sList2);
+ /* */
+ final Model m1 = ModelHelper.modelWithStatements(this,
+ "vv WW xx; yy ZZ aa");
+ model.add(m1);
+ ll.recent("add", m1);
+ final Model m2 = ModelHelper.modelWithStatements(this, "a B g; d E z");
+ model.remove(m2);
+ ll.recent("rem", m2);
+ /* */
+ final Statement[] sa1 = ModelHelper.statements(model,
+ "th i k; l model n");
+ model.add(sa1);
+ ll.recent("add", sa1);
+ final Statement[] sa2 = ModelHelper.statements(model, "x o p; r u ch");
+ model.remove(sa2);
+ ll.recent("rem", sa2);
+ /* */
+ final Statement[] si1 = ModelHelper.statements(model,
+ "u ph ch; psi om eh");
+ model.add(asIterator(si1));
+ ll.recent("add", asIterator(si1));
+ final Statement[] si2 = ModelHelper.statements(model,
+ "at last the; end of these; tests ok guv");
+ model.remove(asIterator(si2));
+ ll.recent("rem", asIterator(si2));
+ }
+
+ public void testRegistrationCompiles()
+ {
+ Assert.assertSame(model, model.register(new RecordingModelListener()));
+ }
+
+ public void testRemoveSingleStatements()
+ {
+ final Statement S = ModelHelper.statement(model, "D E F");
+ model.register(SL);
+ model.add(S);
+ model.remove(S);
+ SL.assertHas(new Object[] { "add", S, "remove", S });
+ }
+
+ public void testTripleListener()
+ {
+ final WatchStatementListener sl = new WatchStatementListener();
+ model.register(sl);
+ model.add(ModelHelper.statement(model, "b C d"));
+ testGot(sl, "add", "b C d");
+ model.remove(ModelHelper.statement(model, "e F g"));
+ testGot(sl, "rem", "e F g");
+ /* */
+ model.add(ModelHelper.statements(model, "h I j; k L model"));
+ testGot(sl, "add", "h I j; k L model");
+ model.remove(ModelHelper.statements(model, "n O p; q R s"));
+ testGot(sl, "rem", "n O p; q R s");
+ /* */
+ model.add(Arrays.asList(ModelHelper.statements(model, "t U v; w X y")));
+ testGot(sl, "add", "t U v; w X y");
+ model.remove(Arrays.asList(ModelHelper
+ .statements(model, "z A b; c D e")));
+ testGot(sl, "rem", "z A b; c D e");
+ /* */
+ model.add(asIterator(ModelHelper.statements(model, "f G h; i J k")));
+ testGot(sl, "add", "f G h; i J k");
+ model.remove(asIterator(ModelHelper.statements(model, "l M n; o P q")));
+ testGot(sl, "rem", "l M n; o P q");
+ /* */
+ model.add(ModelHelper.modelWithStatements(this, "r S t; u V w; x Y z"));
+ testGot(sl, "add", "r S t; u V w; x Y z");
+ model.remove(ModelHelper.modelWithStatements(this, "a E i; o U y"));
+ testGot(sl, "rem", "a E i; o U y");
+ }
+
+ public void testTwoListeners()
+ {
+ final Statement S = ModelHelper.statement(model, "S P O");
+ final RecordingModelListener SL1 = new RecordingModelListener();
+ final RecordingModelListener SL2 = new RecordingModelListener();
+ model.register(SL1).register(SL2);
+ model.add(S);
+ SL2.assertHas(new Object[] { "add", S });
+ SL1.assertHas(new Object[] { "add", S });
+ }
+
+ public void testUnregisterWorks()
+ {
+ model.register(SL);
+ model.unregister(SL);
+ model.add(ModelHelper.statement(model, "X R Y"));
+ SL.assertHas(new Object[] {});
+ }
+
+ public void testUnregistrationCompiles()
+ {
+ model.unregister(new RecordingModelListener());
+ }
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelExtract.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelExtract.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelExtract.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelExtract.java Tue Jan 29 20:27:24 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,122 +18,164 @@
package com.hp.hpl.jena.rdf.model.test;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.rdf.model.*;
-
-import junit.framework.TestSuite;
-
-/**
- @author hedgehog
-*/
-public class TestModelExtract extends ModelTestBase
- {
- protected static final StatementBoundary sbTrue = new StatementBoundaryBase()
- {
- @Override
- public boolean stopAt( Statement s ) { return true; }
- };
-
- protected static final StatementBoundary sbFalse = new StatementBoundaryBase()
- {
- @Override
- public boolean stopAt( Statement s ) { return false; }
- };
-
- public TestModelExtract( String name )
- { super( name ); }
-
- public static TestSuite suite()
- { return new TestSuite( TestModelExtract.class ); }
-
- static class MockModelExtract extends ModelExtract
- {
- Node root;
- Graph result;
- Graph subject;
-
- public MockModelExtract( StatementBoundary b )
- { super( b ); }
-
- public StatementBoundary getStatementBoundary()
- { return boundary; }
-
- @Override
- protected GraphExtract getGraphExtract( TripleBoundary b )
- {
- return new GraphExtract( b )
- {
- @Override
- public Graph extractInto( Graph toUpdate, Node n, Graph source )
- {
- root = n;
- return result = super.extractInto( toUpdate, n, subject = source );
- }
- };
- }
- }
-
- public void testAsTripleBoundary()
- {
- Model m = ModelFactory.createDefaultModel();
- assertTrue( sbTrue.asTripleBoundary( m ).stopAt( triple( "x R y" ) ) );
- assertFalse( sbFalse.asTripleBoundary( m ).stopAt( triple( "x R y" ) ) );
- }
-
- public void testStatementTripleBoundaryAnon()
- {
- TripleBoundary anon = TripleBoundary.stopAtAnonObject;
- assertSame( anon, new StatementTripleBoundary( anon ).asTripleBoundary( null ) );
- assertFalse( new StatementTripleBoundary( anon ).stopAt( statement( "s P o" ) ) );
- assertTrue( new StatementTripleBoundary( anon ).stopAt( statement( "s P _o" ) ) );
- }
-
- public void testStatementContinueWith()
- {
- StatementBoundary sb = new StatementBoundaryBase()
- { @Override
- public boolean continueWith( Statement s ) { return false; } };
- assertTrue( sb.stopAt( statement( "x pings y" ) ) );
- }
-
- public void testStatementTripleBoundaryNowhere()
- {
- TripleBoundary nowhere = TripleBoundary.stopNowhere;
- assertSame( nowhere, new StatementTripleBoundary( nowhere ).asTripleBoundary( null ) );
- assertFalse( new StatementTripleBoundary( nowhere ).stopAt( statement( "s P _o" ) ) );
- assertFalse( new StatementTripleBoundary( nowhere ).stopAt( statement( "s P o" ) ) );
- }
- public void testRemembersBoundary()
- {
- assertSame( sbTrue, new MockModelExtract( sbTrue ).getStatementBoundary() );
- assertSame( sbFalse, new MockModelExtract( sbFalse ).getStatementBoundary() );
- }
-
- public void testInvokesExtract()
- {
- MockModelExtract mock = new MockModelExtract( sbTrue );
- Model source = modelWithStatements( "a R b" );
- Model m = mock.extract( resource( "a" ), source );
- assertEquals( node( "a" ), mock.root );
- assertSame( mock.result, m.getGraph() );
- assertSame( mock.subject, source.getGraph() );
- }
-
- /* (non-Javadoc)
- * @see com.hp.hpl.jena.rdf.model.StatementBoundary#stopAt(com.hp.hpl.jena.rdf.model.Statement)
- */
- public boolean stopAt( Statement s )
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- /* (non-Javadoc)
- * @see com.hp.hpl.jena.rdf.model.StatementBoundary#asTripleBoundary(com.hp.hpl.jena.rdf.model.Model)
- */
- public TripleBoundary asTripleBoundary( Model m )
- {
- // TODO Auto-generated method stub
- return null;
- }
- }
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.GraphExtract;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.TripleBoundary;
+import com.hp.hpl.jena.graph.test.GraphTestBase;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelExtract;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StatementBoundary;
+import com.hp.hpl.jena.rdf.model.StatementBoundaryBase;
+import com.hp.hpl.jena.rdf.model.StatementTripleBoundary;
+import com.hp.hpl.jena.rdf.model.test.helpers.ModelHelper;
+import com.hp.hpl.jena.rdf.model.test.helpers.TestingModelFactory;
+
+import junit.framework.Assert;
+
+public class TestModelExtract extends AbstractModelTestBase
+{
+ static class MockModelExtract extends ModelExtract
+ {
+ Node root;
+ Graph result;
+ Graph subject;
+
+ public MockModelExtract( final StatementBoundary b )
+ {
+ super(b);
+ }
+
+ @Override
+ protected GraphExtract getGraphExtract( final TripleBoundary b )
+ {
+ return new GraphExtract(b) {
+ @Override
+ public Graph extractInto( final Graph toUpdate, final Node n,
+ final Graph source )
+ {
+ root = n;
+ return result = super.extractInto(toUpdate, n,
+ subject = source);
+ }
+ };
+ }
+
+ public StatementBoundary getStatementBoundary()
+ {
+ return boundary;
+ }
+ }
+
+ protected static final StatementBoundary sbTrue = new StatementBoundaryBase() {
+ @Override
+ public boolean stopAt( final Statement s )
+ {
+ return true;
+ }
+ };
+
+ protected static final StatementBoundary sbFalse = new StatementBoundaryBase() {
+ @Override
+ public boolean stopAt( final Statement s )
+ {
+ return false;
+ }
+ };
+
+ public TestModelExtract( final TestingModelFactory modelFactory,
+ final String name )
+ {
+ super(modelFactory, name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.hp.hpl.jena.rdf.model.StatementBoundary#asTripleBoundary(com.hp.hpl
+ * .jena.rdf.model.Model)
+ */
+ public TripleBoundary asTripleBoundary( final Model m )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.hp.hpl.jena.rdf.model.StatementBoundary#stopAt(com.hp.hpl.jena.rdf
+ * .model.Statement)
+ */
+ public boolean stopAt( final Statement s )
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void testAsTripleBoundary()
+ {
+ final Model m = ModelFactory.createDefaultModel();
+ Assert.assertTrue(TestModelExtract.sbTrue.asTripleBoundary(m).stopAt(
+ GraphTestBase.triple("x R y")));
+ Assert.assertFalse(TestModelExtract.sbFalse.asTripleBoundary(m).stopAt(
+ GraphTestBase.triple("x R y")));
+ }
+
+ public void testInvokesExtract()
+ {
+ final MockModelExtract mock = new MockModelExtract(
+ TestModelExtract.sbTrue);
+ final Model source = ModelHelper.modelWithStatements(this, "a R b");
+ final Model m = mock.extract(ModelHelper.resource("a"), source);
+ Assert.assertEquals(GraphTestBase.node("a"), mock.root);
+ Assert.assertSame(mock.result, m.getGraph());
+ Assert.assertSame(mock.subject, source.getGraph());
+ }
+
+ public void testRemembersBoundary()
+ {
+ Assert.assertSame(TestModelExtract.sbTrue, new MockModelExtract(
+ TestModelExtract.sbTrue).getStatementBoundary());
+ Assert.assertSame(TestModelExtract.sbFalse, new MockModelExtract(
+ TestModelExtract.sbFalse).getStatementBoundary());
+ }
+
+ public void testStatementContinueWith()
+ {
+ final StatementBoundary sb = new StatementBoundaryBase() {
+ @Override
+ public boolean continueWith( final Statement s )
+ {
+ return false;
+ }
+ };
+ Assert.assertTrue(sb.stopAt(ModelHelper.statement("x pings y")));
+ }
+
+ public void testStatementTripleBoundaryAnon()
+ {
+ final TripleBoundary anon = TripleBoundary.stopAtAnonObject;
+ Assert.assertSame(anon,
+ new StatementTripleBoundary(anon).asTripleBoundary(null));
+ Assert.assertFalse(new StatementTripleBoundary(anon).stopAt(ModelHelper
+ .statement("s P o")));
+ Assert.assertTrue(new StatementTripleBoundary(anon).stopAt(ModelHelper
+ .statement("s P _o")));
+ }
+
+ public void testStatementTripleBoundaryNowhere()
+ {
+ final TripleBoundary nowhere = TripleBoundary.stopNowhere;
+ Assert.assertSame(nowhere,
+ new StatementTripleBoundary(nowhere).asTripleBoundary(null));
+ Assert.assertFalse(new StatementTripleBoundary(nowhere)
+ .stopAt(ModelHelper.statement("s P _o")));
+ Assert.assertFalse(new StatementTripleBoundary(nowhere)
+ .stopAt(ModelHelper.statement("s P o")));
+ }
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelFactory.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelFactory.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelFactory.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelFactory.java Tue Jan 29 20:27:24 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,92 +18,100 @@
package com.hp.hpl.jena.rdf.model.test;
-import junit.framework.TestSuite ;
+import com.hp.hpl.jena.graph.compose.Union;
+import com.hp.hpl.jena.rdf.model.InfModel;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.impl.ModelCom;
+import com.hp.hpl.jena.reasoner.InfGraph;
+import com.hp.hpl.jena.reasoner.Reasoner;
+import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+import com.hp.hpl.jena.shared.PrefixMapping;
+import com.hp.hpl.jena.test.JenaTestBase;
-import com.hp.hpl.jena.graph.compose.Union ;
-import com.hp.hpl.jena.rdf.model.InfModel ;
-import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.rdf.model.ModelFactory ;
-import com.hp.hpl.jena.rdf.model.impl.ModelCom ;
-import com.hp.hpl.jena.reasoner.InfGraph ;
-import com.hp.hpl.jena.reasoner.Reasoner ;
-import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner ;
-import com.hp.hpl.jena.reasoner.rulesys.Rule ;
-import com.hp.hpl.jena.shared.PrefixMapping ;
+import junit.framework.Assert;
+import junit.framework.TestCase;
/**
- Tests the ModelFactory code. Very skeletal at the moment. It's really
- testing that the methods actually exists, but it doesn't check much in
- the way of behaviour.
-*/
-
-public class TestModelFactory extends ModelTestBase
- {
- public TestModelFactory(String name)
- { super(name); }
-
- public static TestSuite suite()
- { return new TestSuite( TestModelFactory.class ); }
-
- /**
- Test that ModelFactory.createDefaultModel() exists. [Should check that the Model
- is truly a "default" model.]
- */
- public void testCreateDefaultModel()
- { ModelFactory.createDefaultModel().close(); }
-
- public void testGetDefaultPrefixMapping()
- {
- assertSame( ModelCom.getDefaultModelPrefixes(), ModelFactory.getDefaultModelPrefixes() );
- }
-
- public void testSetDefaultPrefixMapping()
- {
- PrefixMapping original = ModelCom.getDefaultModelPrefixes();
- PrefixMapping pm = PrefixMapping.Factory.create();
- ModelFactory.setDefaultModelPrefixes( pm );
- assertSame( pm, ModelCom.getDefaultModelPrefixes() );
- assertSame( pm, ModelFactory.getDefaultModelPrefixes() );
- ModelCom.setDefaultModelPrefixes( original );
- }
-
- public void testCreateInfModel()
- {
- String rule = "-> (eg:r eg:p eg:v).";
- Reasoner r = new GenericRuleReasoner( Rule.parseRules(rule) );
- InfGraph ig = r.bind( ModelFactory.createDefaultModel().getGraph() );
- InfModel im = ModelFactory.createInfModel(ig);
- assertInstanceOf( InfModel.class, im );
- assertEquals( 1, im.size() );
- }
-
- /**
- test that a union model is a model over the union of the two underlying
- graphs. (We don't check that Union works - that's done in the Union
- tests, we hope.)
- */
- public void testCreateUnion()
- {
- Model m1 = ModelFactory.createDefaultModel();
- Model m2 = ModelFactory.createDefaultModel();
- Model m = ModelFactory.createUnion( m1, m2 );
- assertInstanceOf( Union.class, m.getGraph() );
- assertSame( m1.getGraph(), ((Union) m.getGraph()).getL() );
- assertSame( m2.getGraph(), ((Union) m.getGraph()).getR() );
- }
-
- public void testAssembleModelFromModel()
- {
- // TODO Model ModelFactory.assembleModelFrom( Model singleRoot )
- }
-
- public void testFindAssemblerRoots()
- {
- // TODO Set ModelFactory.findAssemblerRoots( Model m )
- }
-
- public void testAssmbleModelFromRoot()
- {
- // TODO Model assembleModelFrom( Resource root )
- }
- }
+ * Tests the ModelFactory code. Very skeletal at the moment. It's really
+ * testing that the methods actually exists, but it doesn't check much in
+ * the way of behaviour.
+ *
+ */
+
+public class TestModelFactory extends TestCase
+{
+
+ public TestModelFactory( final String name )
+ {
+ super(name);
+ }
+
+ public void testAssembleModelFromModel()
+ {
+ // TODO Model ModelFactory.assembleModelFrom( Model singleRoot )
+ }
+
+ public void testAssmbleModelFromRoot()
+ {
+ // TODO Model assembleModelFrom( Resource root )
+ }
+
+ /**
+ * Test that ModelFactory.createDefaultModel() exists. [Should check that
+ * the Model
+ * is truly a "default" model.]
+ */
+ public void testCreateDefaultModel()
+ {
+ ModelFactory.createDefaultModel().close();
+ }
+
+ public void testCreateInfModel()
+ {
+ final String rule = "-> (eg:r eg:p eg:v).";
+ final Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule));
+ final InfGraph ig = r
+ .bind(ModelFactory.createDefaultModel().getGraph());
+ final InfModel im = ModelFactory.createInfModel(ig);
+ JenaTestBase.assertInstanceOf(InfModel.class, im);
+ Assert.assertEquals(1, im.size());
+ }
+
+ /**
+ * test that a union model is a model over the union of the two underlying
+ * graphs. (We don't check that Union works - that's done in the Union
+ * tests, we hope.)
+ */
+ public void testCreateUnion()
+ {
+ final Model m1 = ModelFactory.createDefaultModel();
+ final Model m2 = ModelFactory.createDefaultModel();
+ final Model m = ModelFactory.createUnion(m1, m2);
+ JenaTestBase.assertInstanceOf(Union.class, m.getGraph());
+ Assert.assertSame(m1.getGraph(), ((Union) m.getGraph()).getL());
+ Assert.assertSame(m2.getGraph(), ((Union) m.getGraph()).getR());
+ }
+
+ public void testFindAssemblerRoots()
+ {
+ // TODO Set ModelFactory.findAssemblerRoots( Model model )
+ }
+
+ public void testGetDefaultPrefixMapping()
+ {
+ Assert.assertSame(ModelCom.getDefaultModelPrefixes(),
+ ModelFactory.getDefaultModelPrefixes());
+ }
+
+ public void testSetDefaultPrefixMapping()
+ {
+ final PrefixMapping original = ModelCom.getDefaultModelPrefixes();
+ final PrefixMapping pm = PrefixMapping.Factory.create();
+ ModelFactory.setDefaultModelPrefixes(pm);
+ Assert.assertSame(pm, ModelCom.getDefaultModelPrefixes());
+ Assert.assertSame(pm, ModelFactory.getDefaultModelPrefixes());
+ ModelCom.setDefaultModelPrefixes(original);
+ }
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelMakerImpl.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelMakerImpl.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelMakerImpl.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelMakerImpl.java Tue Jan 29 20:27:24 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,237 +18,243 @@
package com.hp.hpl.jena.rdf.model.test;
-import java.util.ArrayList ;
-import java.util.List ;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.GraphMaker;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.test.GraphTestBase;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelMaker;
+import com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl;
+import com.hp.hpl.jena.shared.ReificationStyle;
+import com.hp.hpl.jena.test.JenaTestBase;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.NullIterator;
-import junit.framework.TestSuite ;
+import java.util.ArrayList;
+import java.util.List;
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.GraphMaker ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.test.GraphTestBase ;
-import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.rdf.model.ModelMaker ;
-import com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl ;
-import com.hp.hpl.jena.shared.ReificationStyle ;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
-import com.hp.hpl.jena.util.iterator.NullIterator ;
+import junit.framework.Assert;
+import junit.framework.TestCase;
/**
- Test ModelMakerImpl using a mock GraphMaker. This is as much an
- exercise in learning testing technique as it is in actually doing the test ....
-*/
+ * Test ModelMakerImpl using a mock GraphMaker.
+ */
@SuppressWarnings("deprecation")
-public class TestModelMakerImpl extends ModelTestBase
- {
- public TestModelMakerImpl(String name)
- { super(name); }
-
- public static TestSuite suite()
- { return new TestSuite( TestModelMakerImpl.class ); }
-
- private ModelMaker maker;
- private Graph graph;
- private GraphMaker graphMaker;
-
- @Override
- public void setUp()
- {
- graph = GraphTestBase.graphWith( "" );
- graphMaker = new MockGraphMaker( graph );
- maker = new ModelMakerImpl( graphMaker );
- }
-
- public void testClose()
- {
- maker.close();
- checkHistory( listOfOne( "close()") );
- }
-
- public void testRemove()
- {
- maker.removeModel( "London" );
- checkHistory( listOfOne( "remove(London)" ) );
- }
-
- public void testCreateFreshModel()
- {
- maker.createFreshModel();
- checkHistory( listOfOne( "create()" ) );
- }
-
- public void testCreateDefaultModel()
- {
- maker.createDefaultModel();
- checkHistory( listOfOne( "get()" ) );
- }
-
- public void testCreateNamed()
- {
- Model m = maker.createModel( "petal" );
- checkHistory( listOfOne("create(petal,false)" ) );
- assertTrue( m.getGraph() == graph );
- }
-
- public void testCreateTrue()
- {
- Model m = maker.createModel( "stem", true );
- checkHistory( listOfOne("create(stem,true)" ) );
- assertTrue( m.getGraph() == graph );
- }
-
- public void testCreateFalse()
- {
- Model m = maker.createModel( "leaf", false );
- checkHistory( listOfOne("create(leaf,false)" ) );
- assertTrue( m.getGraph() == graph );
- }
-
- public void testOpen()
- {
- Model m = maker.openModel( "trunk" );
- checkHistory( listOfOne("open(trunk,false)" ) );
- assertTrue( m.getGraph() == graph );
- }
-
- public void testOpenFalse()
- {
- Model m = maker.openModel( "branch", false );
- checkHistory( listOfOne("open(branch,false)" ) );
- assertTrue( m.getGraph() == graph );
- }
-
- public void testOpenTrue()
- {
- Model m = maker.openModel( "bark", true );
- checkHistory( listOfOne("open(bark,true)" ) );
- assertTrue( m.getGraph() == graph );
- }
-
- public void testListGraphs()
- {
- maker.listModels().close();
- checkHistory( listOfOne("listModels()" ) );
- }
-
- public void testGetGraphMaker()
- {
- assertTrue( maker.getGraphMaker() == graphMaker );
- }
-
- private void checkHistory( List<String> expected )
- { assertEquals( expected, history() ); }
-
- private List<String> history()
- { return ((MockGraphMaker) maker.getGraphMaker()).history; }
-
- static class MockGraphMaker implements GraphMaker
- {
- List<String> history = new ArrayList<String>();
- Graph graph;
-
- public MockGraphMaker( Graph graph )
- { this.graph = graph; }
-
- @Override
- @Deprecated
- public ReificationStyle getReificationStyle()
- {
- history.add( "getReificationStyle()" );
- return null;
- }
-
- @Override
- public Graph getGraph()
- {
- history.add( "get()" );
- return graph;
- }
-
- @Override
- public Graph createGraph()
- {
- history.add( "create()" );
- return graph;
- }
-
- @Override
- public Graph createGraph( String name, boolean strict )
- {
- history.add( "create(" + name + "," + strict + ")" );
- return graph;
- }
-
- @Override
- public Graph createGraph( String name )
- {
- history.add( "create(" + name + ")" );
- return graph;
- }
-
- @Override
- public Graph openGraph( String name, boolean strict )
- {
- history.add( "open(" + name + "," + strict + ")" );
- return graph;
- }
-
- @Override
- public Graph openGraph( String name )
- {
- history.add( "open(" + name + ")" );
- return graph;
- }
-
- @Override
- public void removeGraph( String name )
- {
- history.add( "remove(" + name + ")" );
- }
-
- @Override
- public boolean hasGraph( String name )
- {
- history.add( "has(" + name + ")" );
- return false;
- }
-
- public Graph getDescription()
- {
- history.add( "getDescription()" );
- return graphWith( "" );
- }
-
- public Graph getDescription( Node root )
- {
- history.add( "getDescription(Node)" );
- return graphWith( "" );
- }
-
- public Graph addDescription( Graph desc, Node self )
- {
- history.add( "addDescription()" );
- return desc;
- }
-
- @Override
- public void close()
- {
- history.add( "close()" );
- }
-
- @Override
- public ExtendedIterator<String> listGraphs()
- {
- history.add( "listModels()" );
- return NullIterator.instance();
- }
-
- @Override
- public Graph openGraph()
- {
-
- return null;
- }
- }
- }
+public class TestModelMakerImpl extends TestCase
+{
+ static class MockGraphMaker implements GraphMaker
+ {
+ List<String> history = new ArrayList<String>();
+ Graph graph;
+
+ public MockGraphMaker( final Graph graph )
+ {
+ this.graph = graph;
+ }
+
+ public Graph addDescription( final Graph desc, final Node self )
+ {
+ history.add("addDescription()");
+ return desc;
+ }
+
+ @Override
+ public void close()
+ {
+ history.add("close()");
+ }
+
+ @Override
+ public Graph createGraph()
+ {
+ history.add("create()");
+ return graph;
+ }
+
+ @Override
+ public Graph createGraph( final String name )
+ {
+ history.add("create(" + name + ")");
+ return graph;
+ }
+
+ @Override
+ public Graph createGraph( final String name, final boolean strict )
+ {
+ history.add("create(" + name + "," + strict + ")");
+ return graph;
+ }
+
+ public Graph getDescription()
+ {
+ history.add("getDescription()");
+ return GraphTestBase.graphWith("");
+ }
+
+ public Graph getDescription( final Node root )
+ {
+ history.add("getDescription(Node)");
+ return GraphTestBase.graphWith("");
+ }
+
+ @Override
+ public Graph getGraph()
+ {
+ history.add("get()");
+ return graph;
+ }
+
+ @Override
+ @Deprecated
+ public ReificationStyle getReificationStyle()
+ {
+ history.add("getReificationStyle()");
+ return null;
+ }
+
+ @Override
+ public boolean hasGraph( final String name )
+ {
+ history.add("has(" + name + ")");
+ return false;
+ }
+
+ @Override
+ public ExtendedIterator<String> listGraphs()
+ {
+ history.add("listModels()");
+ return NullIterator.instance();
+ }
+
+ @Override
+ public Graph openGraph()
+ {
+
+ return null;
+ }
+
+ @Override
+ public Graph openGraph( final String name )
+ {
+ history.add("open(" + name + ")");
+ return graph;
+ }
+
+ @Override
+ public Graph openGraph( final String name, final boolean strict )
+ {
+ history.add("open(" + name + "," + strict + ")");
+ return graph;
+ }
+
+ @Override
+ public void removeGraph( final String name )
+ {
+ history.add("remove(" + name + ")");
+ }
+ }
+
+ private ModelMaker maker;
+ private Graph graph;
+ private GraphMaker graphMaker;
+
+ public TestModelMakerImpl( final String name )
+ {
+ super(name);
+ }
+
+ private void checkHistory( final List<String> expected )
+ {
+ Assert.assertEquals(expected, history());
+ }
+
+ private List<String> history()
+ {
+ return ((MockGraphMaker) maker.getGraphMaker()).history;
+ }
+
+ @Override
+ public void setUp()
+ {
+ graph = GraphTestBase.graphWith("");
+ graphMaker = new MockGraphMaker(graph);
+ maker = new ModelMakerImpl(graphMaker);
+ }
+
+ public void testClose()
+ {
+ maker.close();
+ checkHistory(JenaTestBase.listOfOne("close()"));
+ }
+
+ public void testCreateDefaultModel()
+ {
+ maker.createDefaultModel();
+ checkHistory(JenaTestBase.listOfOne("get()"));
+ }
+
+ public void testCreateFalse()
+ {
+ final Model m = maker.createModel("leaf", false);
+ checkHistory(JenaTestBase.listOfOne("create(leaf,false)"));
+ Assert.assertTrue(m.getGraph() == graph);
+ }
+
+ public void testCreateFreshModel()
+ {
+ maker.createFreshModel();
+ checkHistory(JenaTestBase.listOfOne("create()"));
+ }
+
+ public void testCreateNamed()
+ {
+ final Model m = maker.createModel("petal");
+ checkHistory(JenaTestBase.listOfOne("create(petal,false)"));
+ Assert.assertTrue(m.getGraph() == graph);
+ }
+
+ public void testCreateTrue()
+ {
+ final Model m = maker.createModel("stem", true);
+ checkHistory(JenaTestBase.listOfOne("create(stem,true)"));
+ Assert.assertTrue(m.getGraph() == graph);
+ }
+
+ public void testGetGraphMaker()
+ {
+ Assert.assertTrue(maker.getGraphMaker() == graphMaker);
+ }
+
+ public void testListGraphs()
+ {
+ maker.listModels().close();
+ checkHistory(JenaTestBase.listOfOne("listModels()"));
+ }
+
+ public void testOpen()
+ {
+ final Model m = maker.openModel("trunk");
+ checkHistory(JenaTestBase.listOfOne("open(trunk,false)"));
+ Assert.assertTrue(m.getGraph() == graph);
+ }
+
+ public void testOpenFalse()
+ {
+ final Model m = maker.openModel("branch", false);
+ checkHistory(JenaTestBase.listOfOne("open(branch,false)"));
+ Assert.assertTrue(m.getGraph() == graph);
+ }
+
+ public void testOpenTrue()
+ {
+ final Model m = maker.openModel("bark", true);
+ checkHistory(JenaTestBase.listOfOne("open(bark,true)"));
+ Assert.assertTrue(m.getGraph() == graph);
+ }
+
+ public void testRemove()
+ {
+ maker.removeModel("London");
+ checkHistory(JenaTestBase.listOfOne("remove(London)"));
+ }
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPolymorphism.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPolymorphism.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPolymorphism.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPolymorphism.java Tue Jan 29 20:27:24 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,28 +18,31 @@
package com.hp.hpl.jena.rdf.model.test;
-import com.hp.hpl.jena.graph.test.GraphTestBase;
-import com.hp.hpl.jena.rdf.model.*;
-import junit.framework.*;
-
-public class TestModelPolymorphism extends GraphTestBase
- {
- public static TestSuite suite()
- { return new TestSuite( TestModelPolymorphism.class ); }
-
- public TestModelPolymorphism(String name)
- {
- super(name);
- }
-
- public void testPoly()
- {
- Model m = ModelFactory.createDefaultModel();
- Resource r = m.createResource( "http://www.electric-hedgehog.net/a-o-s.html" );
- assertFalse( "the Resouce should not be null", r == null );
- assertTrue( "the Resource can be a Property", r.canAs( Property.class ) );
- Property p = r.as( Property.class );
- assertFalse( "the Property should not be null", p == null );
- assertFalse( "the Resource and Property should not be identical", r == p );
- }
- }
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.test.helpers.TestingModelFactory;
+
+import junit.framework.Assert;
+
+public class TestModelPolymorphism extends AbstractModelTestBase
+{
+
+ public TestModelPolymorphism( final TestingModelFactory modelFactory,
+ final String name )
+ {
+ super(modelFactory, name);
+ }
+
+ public void testPoly()
+ {
+ final Resource r = model
+ .createResource("http://www.electric-hedgehog.net/a-o-s.html");
+ Assert.assertFalse("the Resouce should not be null", r == null);
+ Assert.assertTrue("the Resource can be a Property",
+ r.canAs(Property.class));
+ final Property p = r.as(Property.class);
+ Assert.assertFalse("the Property should not be null", p == null);
+ Assert.assertFalse("the Resource and Property should not be identical",
+ r == p);
+ }
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPrefixMapping.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPrefixMapping.java?rev=1440101&r1=1440100&r2=1440101&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPrefixMapping.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestModelPrefixMapping.java Tue Jan 29 20:27:24 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,86 +18,112 @@
package com.hp.hpl.jena.rdf.model.test;
-import junit.framework.TestSuite;
-
import com.hp.hpl.jena.graph.Factory;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.impl.ModelCom;
+import com.hp.hpl.jena.rdf.model.test.helpers.TestingModelFactory;
import com.hp.hpl.jena.shared.AbstractTestPrefixMapping;
import com.hp.hpl.jena.shared.PrefixMapping;
+import junit.framework.Assert;
+
/**
- Test that a model is a prefix mapping.
- @author kers
-*/
+ * Test that a model is a prefix mapping.
+ *
+ */
public class TestModelPrefixMapping extends AbstractTestPrefixMapping
- {
- public TestModelPrefixMapping( String name )
- { super( name ); }
-
- public static TestSuite suite()
- { return new TestSuite( TestModelPrefixMapping.class ); }
-
- @Override
- protected PrefixMapping getMapping()
- { return ModelFactory.createDefaultModel(); }
-
- protected static final String alphaPrefix = "alpha";
- protected static final String betaPrefix = "beta";
- protected static final String alphaURI = "http://testing.jena.hpl.hp.com/alpha#";
- protected static final String betaURI = "http://testing.jena.hpl.hp.com/beta#";
-
- protected PrefixMapping baseMap = PrefixMapping.Factory.create()
- .setNsPrefix( alphaPrefix, alphaURI )
- .setNsPrefix( betaPrefix, betaURI );
-
- private PrefixMapping prevMap;
-
- public void setPrefixes()
- {
- prevMap = ModelCom.setDefaultModelPrefixes( baseMap );
- }
-
- public void restorePrefixes()
- {
- ModelCom.setDefaultModelPrefixes( prevMap );
- }
-
- /**
- Test that a freshly-created Model has the prefixes established by the
- default in ModelCom.
- */
- public void testDefaultPrefixes()
- {
- setPrefixes();
- Model m = ModelFactory.createDefaultModel();
- assertEquals( baseMap.getNsPrefixMap(), m.getNsPrefixMap() );
- restorePrefixes();
- }
-
- public void testOnlyFreshPrefixes()
- {
- setPrefixes();
- try { doOnlyFreshPrefixes(); } finally { restorePrefixes(); }
- }
-
- /**
- Test that existing prefixes are not over-ridden by the default ones.
- */
- private void doOnlyFreshPrefixes()
- {
- String newURI = "abc:def/";
- Graph g = Factory.createDefaultGraph();
- PrefixMapping pm = g.getPrefixMapping();
- pm.setNsPrefix( alphaPrefix, newURI );
- Model m = ModelFactory.createModelForGraph( g );
- assertEquals( newURI, m.getNsPrefixURI( alphaPrefix ) );
- assertEquals( betaURI, m.getNsPrefixURI( betaPrefix ) ); }
-
- public void testGetDefault()
- { setPrefixes();
- try { assertSame( baseMap, ModelCom.getDefaultModelPrefixes() ); }
- finally { restorePrefixes(); } }
- }
+{
+ private final TestingModelFactory modelFactory;
+ protected static final String alphaPrefix = "alpha";
+
+ protected static final String betaPrefix = "beta";
+ protected static final String alphaURI = "http://testing.jena.hpl.hp.com/alpha#";
+ protected static final String betaURI = "http://testing.jena.hpl.hp.com/beta#";
+ protected PrefixMapping baseMap = PrefixMapping.Factory
+ .create()
+ .setNsPrefix(TestModelPrefixMapping.alphaPrefix,
+ TestModelPrefixMapping.alphaURI)
+ .setNsPrefix(TestModelPrefixMapping.betaPrefix,
+ TestModelPrefixMapping.betaURI);
+
+ private PrefixMapping prevMap;
+
+ public TestModelPrefixMapping( final TestingModelFactory modelFactory,
+ final String name )
+ {
+ super(name);
+ this.modelFactory = modelFactory;
+ }
+
+ /**
+ * Test that existing prefixes are not over-ridden by the default ones.
+ */
+ private void doOnlyFreshPrefixes()
+ {
+ final String newURI = "abc:def/";
+ final Graph g = Factory.createDefaultGraph();
+ final PrefixMapping pm = g.getPrefixMapping();
+ pm.setNsPrefix(TestModelPrefixMapping.alphaPrefix, newURI);
+ final Model m = ModelFactory.createModelForGraph(g);
+ Assert.assertEquals(newURI,
+ m.getNsPrefixURI(TestModelPrefixMapping.alphaPrefix));
+ Assert.assertEquals(TestModelPrefixMapping.betaURI,
+ m.getNsPrefixURI(TestModelPrefixMapping.betaPrefix));
+ }
+
+ @Override
+ protected PrefixMapping getMapping()
+ {
+ return modelFactory.getPrefixMapping();
+ }
+
+ public void restorePrefixes()
+ {
+ ModelCom.setDefaultModelPrefixes(prevMap);
+ }
+
+ public void setPrefixes()
+ {
+ prevMap = ModelCom.setDefaultModelPrefixes(baseMap);
+ }
+
+ /**
+ * Test that a freshly-created Model has the prefixes established by the
+ * default in ModelCom.
+ */
+ public void testDefaultPrefixes()
+ {
+ setPrefixes();
+ final Model m = ModelFactory.createDefaultModel();
+ Assert.assertEquals(baseMap.getNsPrefixMap(), m.getNsPrefixMap());
+ restorePrefixes();
+ }
+
+ public void testGetDefault()
+ {
+ setPrefixes();
+ try
+ {
+ Assert.assertSame(baseMap, ModelCom.getDefaultModelPrefixes());
+ }
+ finally
+ {
+ restorePrefixes();
+ }
+ }
+
+ public void testOnlyFreshPrefixes()
+ {
+ setPrefixes();
+ try
+ {
+ doOnlyFreshPrefixes();
+ }
+ finally
+ {
+ restorePrefixes();
+ }
+ }
+}