You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/01/08 20:07:29 UTC
svn commit: r1430447 [6/10] - in /jena/branches/streaming-update: ./
apache-jena/ apache-jena/bat/ apache-jena/bin/ jena-arq/
jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/ jena-core/
jena-core/src/main/java/com/hp/hpl/jena/assembler/ jena-core/s...
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java?rev=1430447&r1=1430446&r2=1430447&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java Tue Jan 8 19:07:23 2013
@@ -18,69 +18,69 @@
package com.hp.hpl.jena.graph.test;
-import com.hp.hpl.jena.util.CollectionFactory;
-import com.hp.hpl.jena.util.iterator.*;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.query.*;
-import com.hp.hpl.jena.mem.TrackingTripleIterator;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.shared.*;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.util.*;
+import java.io.FileInputStream ;
+import java.io.FileNotFoundException ;
+import java.util.* ;
+
+import com.hp.hpl.jena.graph.* ;
+import com.hp.hpl.jena.mem.TrackingTripleIterator ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.impl.ReifierStd ;
+import com.hp.hpl.jena.shared.Command ;
+import com.hp.hpl.jena.shared.JenaException ;
+import com.hp.hpl.jena.util.CollectionFactory ;
+import com.hp.hpl.jena.util.iterator.ClosableIterator ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
/**
AbstractTestGraph provides a bunch of basic tests for something that
purports to be a Graph. The abstract method getGraph must be overridden
in subclasses to deliver a Graph of interest.
-
- @author kers
-*/
-public/* abstract */class AbstractTestGraph extends GraphTestBase
- {
+ */
+public abstract class AbstractTestGraph extends GraphTestBase
+{
public AbstractTestGraph( String name )
- { super( name ); }
-
+ { super( name ); }
+
/**
Returns a Graph to take part in the test. Must be overridden in
a subclass.
- */
- // public abstract Graph getGraph();
-
- public Graph getGraph() { return Factory.createGraphMem(); }
-
+ */
+ public abstract Graph getGraph();
+
+ //public Graph getGraph() { return Factory.createGraphMem(); }
+
public Graph getGraphWith( String facts )
- {
+ {
Graph g = getGraph();
graphAdd( g, facts );
return g;
- }
-
+ }
+
public void testCloseSetsIsClosed()
- {
+ {
Graph g = getGraph();
assertFalse( "unclosed Graph shouild not be isClosed()", g.isClosed() );
g.close();
assertTrue( "closed Graph should be isClosed()", g.isClosed() );
- }
-
+ }
+
/**
This test case was generated by Ian and was caused by GraphMem
not keeping up with changes to the find interface.
- */
+ */
public void testFindAndContains()
- {
+ {
Graph g = getGraph();
Node r = NodeCreateUtils.create( "r" ), s = NodeCreateUtils.create( "s" ), p = NodeCreateUtils.create( "P" );
g.add( Triple.create( r, p, s ) );
assertTrue( g.contains( r, p, Node.ANY ) );
assertEquals( 1, g.find( r, p, Node.ANY ).toList().size() );
- }
-
+ }
+
public void testRepeatedSubjectDoesNotConceal()
- {
+ {
Graph g = getGraphWith( "s P o; s Q r" );
assertTrue( g.contains( triple( "s P o" ) ) );
assertTrue( g.contains( triple( "s Q r" ) ) );
@@ -88,33 +88,33 @@ public/* abstract */class AbstractTestGr
assertTrue( g.contains( triple( "?? Q r" ) ) );
assertTrue( g.contains( triple( "?? P ??" ) ) );
assertTrue( g.contains( triple( "?? Q ??" ) ) );
- }
-
+ }
+
public void testFindByFluidTriple()
- {
+ {
Graph g = getGraphWith( "x y z " );
Set<Triple> expect = tripleSet( "x y z" );
assertEquals( expect, g.find( triple( "?? y z" ) ).toSet() );
assertEquals( expect, g.find( triple( "x ?? z" ) ).toSet() );
assertEquals( expect, g.find( triple( "x y ??" ) ).toSet() );
- }
-
+ }
+
public void testContainsConcrete()
- {
+ {
Graph g = getGraphWith( "s P o; _x _R _y; x S 0" );
assertTrue( g.contains( triple( "s P o" ) ) );
assertTrue( g.contains( triple( "_x _R _y" ) ) );
assertTrue( g.contains( triple( "x S 0" ) ) );
- /* */
+ /* */
assertFalse( g.contains( triple( "s P Oh" ) ) );
assertFalse( g.contains( triple( "S P O" ) ) );
assertFalse( g.contains( triple( "s p o" ) ) );
assertFalse( g.contains( triple( "_x _r _y" ) ) );
assertFalse( g.contains( triple( "x S 1" ) ) );
- }
-
+ }
+
public void testContainsFluid()
- {
+ {
Graph g = getGraphWith( "x R y; a P b" );
assertTrue( g.contains( triple( "?? R y" ) ) );
assertTrue( g.contains( triple( "x ?? y" ) ) );
@@ -123,88 +123,83 @@ public/* abstract */class AbstractTestGr
assertTrue( g.contains( triple( "a ?? b" ) ) );
assertTrue( g.contains( triple( "a P ??" ) ) );
assertTrue( g.contains( triple( "?? R y" ) ) );
- /* */
+ /* */
assertFalse( g.contains( triple( "?? R b" ) ) );
assertFalse( g.contains( triple( "a ?? y" ) ) );
assertFalse( g.contains( triple( "x P ??" ) ) );
assertFalse( g.contains( triple( "?? R x" ) ) );
assertFalse( g.contains( triple( "x ?? R" ) ) );
assertFalse( g.contains( triple( "a S ??" ) ) );
- }
-
+ }
+
/**
Check that contains respects by-value semantics.
- */
+ */
public void testContainsByValue()
- {
+ {
if (getGraph().getCapabilities().handlesLiteralTyping())
- { // TODO fix the adhocness of this
+ {
Graph g1 = getGraphWith( "x P '1'xsd:integer" );
assertTrue( g1.contains( triple( "x P '01'xsd:int" ) ) );
- //
+ //
Graph g2 = getGraphWith( "x P '1'xsd:int" );
assertTrue( g2.contains( triple( "x P '1'xsd:integer" ) ) );
- //
+ //
Graph g3 = getGraphWith( "x P '123'xsd:string" );
assertTrue( g3.contains( triple( "x P '123'" ) ) );
- }
}
-
+ }
+
public void testMatchLanguagedLiteralCaseInsensitive()
- {
+ {
Graph m = graphWith( "a p 'chat'en" );
-
- // TODO: should be Graph m = getGraphWith( "a p 'chat'en" );
if (m.getCapabilities().handlesLiteralTyping())
- {
+ {
Node chaten = node( "'chat'en" ), chatEN = node( "'chat'EN" );
assertDiffer( chaten, chatEN );
assertTrue( chaten.sameValueAs( chatEN ) );
assertEquals( chaten.getIndexingValue(), chatEN.getIndexingValue() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chaten ).toList().size() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chatEN ).toList().size() );
- }
}
-
+ }
+
public void testMatchBothLanguagedLiteralsCaseInsensitive()
- {
+ {
Graph m = graphWith( "a p 'chat'en; a p 'chat'EN" );
-
- // TODO: should be Graph m = getGraphWith( "a p 'chat'en; a p 'chat'EN" );
if (m.getCapabilities().handlesLiteralTyping())
- {
+ {
Node chaten = node( "'chat'en" ), chatEN = node( "'chat'EN" );
assertDiffer( chaten, chatEN );
assertTrue( chaten.sameValueAs( chatEN ) );
assertEquals( chaten.getIndexingValue(), chatEN.getIndexingValue() );
assertEquals( 2, m.find( Node.ANY, Node.ANY, chaten ).toList().size() );
assertEquals( 2, m.find( Node.ANY, Node.ANY, chatEN ).toList().size() );
- }
}
-
+ }
+
public void testNoMatchAgainstUnlanguagesLiteral()
- {
+ {
Graph m = graphWith( "a p 'chat'en; a p 'chat'" );
- // TODO: should be Graph m = getGraphWith( "a p 'chat'en; a p 'chat'" );
if (m.getCapabilities().handlesLiteralTyping())
- {
+ {
Node chaten = node( "'chat'en" ), chatEN = node( "'chat'EN" );
assertDiffer( chaten, chatEN );
assertTrue( chaten.sameValueAs( chatEN ) );
assertEquals( chaten.getIndexingValue(), chatEN.getIndexingValue() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chaten ).toList().size() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chatEN ).toList().size() );
- }
}
-
+ }
+
/**
test isEmpty - moved from the QueryHandler code.
- */
+ */
public void testIsEmpty()
- {
+ {
Graph g = getGraph();
if (canBeEmpty( g ))
- {
+ {
assertTrue( g.isEmpty() );
g.add( NodeCreateUtils.createTriple( "S P O" ) );
assertFalse( g.isEmpty() );
@@ -216,17 +211,17 @@ public/* abstract */class AbstractTestGr
assertFalse( g.isEmpty() );
g.delete( NodeCreateUtils.createTriple( "A B C" ) );
assertTrue( g.isEmpty() );
- }
}
-
+ }
+
public void testAGraph()
- {
+ {
String title = this.getClass().getName();
Graph g = getGraph();
int baseSize = g.size();
graphAdd( g, "x R y; p S q; a T b" );
- /* */
+ /* */
assertContainsAll( title + ": simple graph", g, "x R y; p S q; a T b" );
assertEquals( title + ": size", baseSize + 3, g.size() );
graphAdd( g, "spindizzies lift cities; Diracs communicate instantaneously" );
@@ -236,162 +231,139 @@ public/* abstract */class AbstractTestGr
assertEquals( title + ": size after deleting", baseSize + 3, g.size() );
assertContainsAll( title + ": modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously" );
assertOmitsAll( title + ": modified simple graph", g, "x R y; a T b" );
- /* */
+ /* */
ClosableIterator<Triple> it = g.find( Node.ANY, node("lift"), Node.ANY );
assertTrue( title + ": finds some triple(s)", it.hasNext() );
assertEquals( title + ": finds a 'lift' triple", triple("spindizzies lift cities"), it.next() );
assertFalse( title + ": finds exactly one triple", it.hasNext() );
it.close();
- }
+ }
+
+ // public void testStuff()
+ // {
+ //// testAGraph( "StoreMem", new GraphMem() );
+ //// testAGraph( "StoreMemBySubject", new GraphMem() );
+ //// String [] empty = new String [] {};
+ //// Graph g = graphWith( "x R y; p S q; a T b" );
+ //// /* */
+ //// assertContainsAll( "simple graph", g, "x R y; p S q; a T b" );
+ //// graphAdd( g, "spindizzies lift cities; Diracs communicate instantaneously" );
+ //// g.delete( triple( "x R y" ) );
+ //// g.delete( triple( "a T b" ) );
+ //// assertContainsAll( "modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously" );
+ //// assertOmitsAll( "modified simple graph", g, "x R y; a T b" );
+ // }
-// public void testStuff()
-// {
-//// testAGraph( "StoreMem", new GraphMem() );
-//// testAGraph( "StoreMemBySubject", new GraphMem() );
-//// String [] empty = new String [] {};
-//// Graph g = graphWith( "x R y; p S q; a T b" );
-//// /* */
-//// assertContainsAll( "simple graph", g, "x R y; p S q; a T b" );
-//// graphAdd( g, "spindizzies lift cities; Diracs communicate instantaneously" );
-//// g.delete( triple( "x R y" ) );
-//// g.delete( triple( "a T b" ) );
-//// assertContainsAll( "modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously" );
-//// assertOmitsAll( "modified simple graph", g, "x R y; a T b" );
-// }
-
/**
Test that Graphs have transaction support methods, and that if they fail
on some g they fail because they do not support the operation.
- */
+ */
public void testHasTransactions()
- {
+ {
Graph g = getGraph();
TransactionHandler th = g.getTransactionHandler();
th.transactionsSupported();
try { th.begin(); } catch (UnsupportedOperationException x) {}
try { th.abort(); } catch (UnsupportedOperationException x) {}
try { th.begin(); th.commit(); } catch (UnsupportedOperationException x) {}
- /* */
+ /* */
Command cmd = new Command()
- { @Override
+ { @Override
public Object execute() { return null; } };
- try { th.executeInTransaction( cmd ); }
- catch (UnsupportedOperationException x) {}
- }
-
+ try { th.executeInTransaction( cmd ); }
+ catch (UnsupportedOperationException x) {}
+ }
+
public void testExecuteInTransactionCatchesThrowable()
- {Graph g = getGraph();
- TransactionHandler th = g.getTransactionHandler();
- if (th.transactionsSupported())
- {
- Command cmd = new Command()
- { @Override
- public Object execute() throws Error { throw new Error(); } };
+ {Graph g = getGraph();
+ TransactionHandler th = g.getTransactionHandler();
+ if (th.transactionsSupported())
+ {
+ Command cmd = new Command()
+ { @Override
+ public Object execute() throws Error { throw new Error(); } };
try { th.executeInTransaction( cmd ); }
catch (JenaException x) {}
- }
- }
+ }
+ }
static final Triple [] tripleArray = tripleArray( "S P O; A R B; X Q Y" );
static final List<Triple> tripleList = Arrays.asList( tripleArray( "i lt j; p equals q" ) );
-
+
static final Triple [] setTriples = tripleArray
( "scissors cut paper; paper wraps stone; stone breaks scissors" );
-
+
static final Set<Triple> tripleSet = CollectionFactory.createHashedSet( Arrays.asList( setTriples ) );
-
+
public void testBulkUpdate()
- {
+ {
Graph g = getGraph();
- BulkUpdateHandler bu = g.getBulkUpdateHandler();
Graph items = graphWith( "pigs might fly; dead can dance" );
int initialSize = g.size();
- /* */
- bu.add( tripleArray );
+ /* */
+ GraphUtil.add( g, tripleArray );
testContains( g, tripleArray );
testOmits( g, tripleList );
- /* */
- bu.add( tripleList );
+ /* */
+ GraphUtil.add( g, tripleList );
testContains( g, tripleList );
testContains( g, tripleArray );
- /* */
- bu.add( tripleSet.iterator() );
+ /* */
+ GraphUtil.add( g, tripleSet.iterator() );
testContains( g, tripleSet.iterator() );
testContains( g, tripleList );
testContains( g, tripleArray );
- /* */
- bu.add( items );
+ /* */
+ GraphUtil.addInto( g, items );
testContains( g, items );
testContains( g, tripleSet.iterator() );
testContains( g, tripleArray );
testContains( g, tripleList );
- /* */
- bu.delete( tripleArray );
+ /* */
+ GraphUtil.delete( g, tripleArray );
testOmits( g, tripleArray );
testContains( g, tripleList );
testContains( g, tripleSet.iterator() );
testContains( g, items );
- /* */
- bu.delete( tripleSet.iterator() );
+ /* */
+ GraphUtil.delete( g, tripleSet.iterator() );
testOmits( g, tripleSet.iterator() );
testOmits( g, tripleArray );
testContains( g, tripleList );
testContains( g, items );
- /* */
- bu.delete( items );
+ /* */
+ GraphUtil.deleteFrom( g, items );
testOmits( g, tripleSet.iterator() );
testOmits( g, tripleArray );
testContains( g, tripleList );
testOmits( g, items );
- /* */
- bu.delete( tripleList );
+ /* */
+ GraphUtil.delete( g, tripleList );
assertEquals( "graph has original size", initialSize, g.size() );
- }
-
- public void testBulkAddWithReification()
- {
- testBulkAddWithReification( false );
- testBulkAddWithReification( true );
- }
-
- public void testBulkAddWithReificationPreamble()
- {
+ }
+
+ public void testAddWithReificationPreamble()
+ {
Graph g = getGraph();
- xSPO( g.getReifier() );
- assertFalse( getReificationTriples( g.getReifier() ).isEmpty() );
- }
-
- public void testBulkAddWithReification( boolean withReifications )
- {
- Graph graphToUpdate = getGraph();
- BulkUpdateHandler bu = graphToUpdate.getBulkUpdateHandler();
- Graph graphToAdd = graphWith( "pigs might fly; dead can dance" );
- Reifier updatedReifier = graphToUpdate.getReifier();
- Reifier addedReifier = graphToAdd.getReifier();
- xSPOyXYZ( addedReifier );
- bu.add( graphToAdd, withReifications );
- assertIsomorphic
- (
- withReifications ? getReificationTriples( addedReifier ) : graphWith( "" ),
- getReificationTriples( updatedReifier )
- );
- }
-
- protected void xSPOyXYZ( Reifier r )
- {
- xSPO( r );
- r.reifyAs( NodeCreateUtils.create( "y" ), NodeCreateUtils.createTriple( "X Y Z" ) );
- }
+ xSPO( g );
+ assertFalse( g.isEmpty() );
+ }
+
+ protected void xSPOyXYZ( Graph g)
+ {
+ xSPO( g );
+ ReifierStd.reifyAs( g, NodeCreateUtils.create( "y" ), NodeCreateUtils.createTriple( "X Y Z" ) );
+ }
+
+ protected void aABC( Graph g )
+ { ReifierStd.reifyAs( g , NodeCreateUtils.create( "a" ), NodeCreateUtils.createTriple( "A B C" ) ); }
+
+ protected void xSPO( Graph g )
+ { ReifierStd.reifyAs( g , NodeCreateUtils.create( "x" ), NodeCreateUtils.createTriple( "S P O" ) ); }
- protected void aABC( Reifier r )
- { r.reifyAs( NodeCreateUtils.create( "a" ), NodeCreateUtils.createTriple( "A B C" ) ); }
-
- protected void xSPO( Reifier r )
- { r.reifyAs( NodeCreateUtils.create( "x" ), NodeCreateUtils.createTriple( "S P O" ) ); }
-
public void testRemove()
- {
+ {
testRemove( "?? ?? ??", "?? ?? ??" );
testRemove( "S ?? ??", "S ?? ??" );
testRemove( "S ?? ??", "?? P ??" );
@@ -402,54 +374,27 @@ public/* abstract */class AbstractTestGr
testRemove( "?? ?? O", "S ?? ??" );
testRemove( "?? ?? O", "?? P ??" );
testRemove( "?? ?? O", "?? ?? O" );
- }
-
+ }
+
public void testRemove( String findRemove, String findCheck )
- {
+ {
Graph g = getGraphWith( "S P O" );
ExtendedIterator<Triple> it = g.find( NodeCreateUtils.createTriple( findRemove ) );
try
- {
+ {
it.next(); it.remove(); it.close();
assertEquals( "remove with " + findRemove + ":", 0, g.size() );
assertFalse( g.contains( NodeCreateUtils.createTriple( findCheck ) ) );
- }
+ }
catch (UnsupportedOperationException e) {
it.close();
assertFalse( g.getCapabilities().iteratorRemoveAllowed() );
}
it.close();
- }
-
- public void testBulkRemoveWithReification()
- {
- testBulkUpdateRemoveWithReification( true );
- testBulkUpdateRemoveWithReification( false );
- }
-
- public void testBulkUpdateRemoveWithReification( boolean withReifications )
- {
- Graph g = getGraph();
- BulkUpdateHandler bu = g.getBulkUpdateHandler();
- Graph items = graphWith( "pigs might fly; dead can dance" );
- Reifier gr = g.getReifier(), ir = items.getReifier();
- xSPOyXYZ( ir );
- xSPO( gr ); aABC( gr );
- bu.delete( items, withReifications );
- Graph answer = graphWith( "" );
- Reifier ar = answer.getReifier();
- if (withReifications)
- aABC( ar );
- else
- {
- xSPO( ar );
- aABC( ar );
- }
- assertIsomorphic( getReificationTriples( ar ), getReificationTriples( gr ) );
- }
-
+ }
+
public void testHasCapabilities()
- {
+ {
Graph g = getGraph();
Capabilities c = g.getCapabilities();
boolean sa = c.sizeAccurate();
@@ -458,137 +403,137 @@ public/* abstract */class AbstractTestGr
boolean daSome = c.deleteAllowed();
boolean daAll = c.deleteAllowed( true );
boolean cbe = c.canBeEmpty();
- }
-
+ }
+
public void testFind()
- {
+ {
Graph g = getGraph();
graphAdd( g, "S P O" );
assertDiffer( new HashSet<Triple>(), g.find( Node.ANY, Node.ANY, Node.ANY ).toSet() );
assertDiffer( new HashSet<Triple>(), g.find( Triple.ANY ).toSet() );
- }
+ }
protected boolean canBeEmpty( Graph g )
- { return g.isEmpty(); }
-
+ { return g.isEmpty(); }
+
public void testEventRegister()
- {
+ {
Graph g = getGraph();
GraphEventManager gem = g.getEventManager();
assertSame( gem, gem.register( new RecordingListener() ) );
- }
-
+ }
+
/**
Test that we can safely unregister a listener that isn't registered.
- */
+ */
public void testEventUnregister()
- {
+ {
getGraph().getEventManager().unregister( L );
- }
-
+ }
+
/**
Handy triple for test purposes.
- */
+ */
protected Triple SPO = NodeCreateUtils.createTriple( "S P O" );
protected RecordingListener L = new RecordingListener();
-
+
/**
Utility: get a graph, register L with its manager, return the graph.
- */
+ */
protected Graph getAndRegister( GraphListener gl )
- {
+ {
Graph g = getGraph();
g.getEventManager().register( gl );
return g;
- }
-
+ }
+
public void testAddTriple()
- {
+ {
Graph g = getAndRegister( L );
g.add( SPO );
L.assertHas( new Object[] {"add", g, SPO} );
- }
-
+ }
+
public void testDeleteTriple()
- {
+ {
Graph g = getAndRegister( L );
g.delete( SPO );
L.assertHas( new Object[] { "delete", g, SPO} );
- }
-
+ }
+
public void testListSubjects()
- {
+ {
Set<Node> emptySubjects = listSubjects( getGraphWith( "" ) );
Graph g = getGraphWith( "x P y; y Q z" );
assertEquals( nodeSet( "x y" ), remove( listSubjects( g ), emptySubjects ) );
g.delete( triple( "x P y" ) );
assertEquals( nodeSet( "y" ), remove( listSubjects( g ), emptySubjects ) );
- }
+ }
protected Set<Node> listSubjects( Graph g )
- {
- return g.queryHandler().subjectsFor( Node.ANY, Node.ANY ).toSet();
- }
-
+ {
+ return GraphUtil.listSubjects( g, Node.ANY, Node.ANY ).toSet();
+ }
+
public void testListPredicates()
- {
+ {
Set<Node> emptyPredicates = listPredicates( getGraphWith( "" ) );
Graph g = getGraphWith( "x P y; y Q z" );
assertEquals( nodeSet( "P Q" ), remove( listPredicates( g ), emptyPredicates ) );
g.delete( triple( "x P y" ) );
assertEquals( nodeSet( "Q" ), remove( listPredicates( g ), emptyPredicates ) );
- }
+ }
protected Set<Node> listPredicates( Graph g )
- {
- return g.queryHandler().predicatesFor( Node.ANY, Node.ANY ).toSet();
- }
-
+ {
+ return GraphUtil.listPredicates( g, Node.ANY, Node.ANY ).toSet();
+ }
+
public void testListObjects()
- {
+ {
Set<Node> emptyObjects = listObjects( getGraphWith( "" ) );
Graph g = getGraphWith( "x P y; y Q z" );
assertEquals( nodeSet( "y z" ), remove( listObjects( g ), emptyObjects ) );
g.delete( triple( "x P y" ) );
assertEquals( nodeSet( "z" ), remove( listObjects( g ), emptyObjects ) );
- }
+ }
protected Set<Node> listObjects( Graph g )
- {
- return g.queryHandler().objectsFor( Node.ANY, Node.ANY ).toSet();
- }
+ {
+ return GraphUtil.listObjects( g, Node.ANY, Node.ANY ).toSet();
+ }
/**
Answer a set with all the elements of <code>A</code> except those
in <code>B</code>.
- */
+ */
private <T> Set<T> remove( Set<T> A, Set<T> B )
- {
+ {
Set<T> result = new HashSet<T>( A );
result.removeAll( B );
return result;
- }
-
+ }
+
/**
Ensure that triples removed by calling .remove() on the iterator returned by
a find() will generate deletion notifications.
- */
+ */
public void testEventDeleteByFind()
- {
+ {
Graph g = getAndRegister( L );
if (g.getCapabilities().iteratorRemoveAllowed())
- {
+ {
Triple toRemove = triple( "remove this triple" );
g.add( toRemove );
ExtendedIterator<Triple> rtr = g.find( toRemove );
assertTrue( "ensure a(t least) one triple", rtr.hasNext() );
rtr.next(); rtr.remove(); rtr.close();
L.assertHas( new Object[] { "add", g, toRemove, "delete", g, toRemove} );
- }
}
-
+ }
+
public void testTwoListeners()
- {
+ {
RecordingListener L1 = new RecordingListener();
RecordingListener L2 = new RecordingListener();
Graph g = getGraph();
@@ -597,124 +542,124 @@ public/* abstract */class AbstractTestGr
g.add( SPO );
L2.assertHas( new Object[] {"add", g, SPO} );
L1.assertHas( new Object[] {"add", g, SPO} );
- }
-
+ }
+
public void testUnregisterWorks()
- {
+ {
Graph g = getGraph();
GraphEventManager gem = g.getEventManager();
gem.register( L ).unregister( L );
g.add( SPO );
L.assertHas( new Object[] {} );
- }
-
+ }
+
public void testRegisterTwice()
- {
+ {
Graph g = getAndRegister( L );
g.getEventManager().register( L );
g.add( SPO );
L.assertHas( new Object[] {"add", g, SPO, "add", g, SPO} );
- }
-
+ }
+
public void testUnregisterOnce()
- {
+ {
Graph g = getAndRegister( L );
g.getEventManager().register( L ).unregister( L );
g.delete( SPO );
L.assertHas( new Object[] {"delete", g, SPO} );
- }
-
+ }
+
public void testBulkAddArrayEvent()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "x R y; a P b" );
- g.getBulkUpdateHandler().add( triples );
+ GraphUtil.add(g, triples );
L.assertHas( new Object[] {"add[]", g, triples} );
- }
-
+ }
+
public void testBulkAddList()
- {
+ {
Graph g = getAndRegister( L );
List<Triple> elems = Arrays.asList( tripleArray( "bells ring loudly; pigs might fly" ) );
- g.getBulkUpdateHandler().add( elems );
+ GraphUtil.add(g, elems) ;
L.assertHas( new Object[] {"addList", g, elems} );
- }
-
+ }
+
public void testBulkDeleteArray()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "x R y; a P b" );
- g.getBulkUpdateHandler().delete( triples );
+ GraphUtil.delete( g, triples );
L.assertHas( new Object[] {"delete[]", g, triples} );
- }
-
+ }
+
public void testBulkDeleteList()
- {
+ {
Graph g = getAndRegister( L );
List<Triple> elems = Arrays.asList( tripleArray( "bells ring loudly; pigs might fly" ) );
- g.getBulkUpdateHandler().delete( elems );
+ GraphUtil.delete( g, elems );
L.assertHas( new Object[] {"deleteList", g, elems} );
- }
-
+ }
+
public void testBulkAddIterator()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "I wrote this; you read that; I wrote this" );
- g.getBulkUpdateHandler().add( asIterator( triples ) );
+ GraphUtil.add(g, asIterator( triples ) );
L.assertHas( new Object[] {"addIterator", g, Arrays.asList( triples )} );
- }
-
+ }
+
public void testBulkDeleteIterator()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "I wrote this; you read that; I wrote this" );
- g.getBulkUpdateHandler().delete( asIterator( triples ) );
+ GraphUtil.delete( g, asIterator( triples ) );
L.assertHas( new Object[] {"deleteIterator", g, Arrays.asList( triples )} );
- }
-
+ }
+
public Iterator<Triple> asIterator( Triple [] triples )
- { return Arrays.asList( triples ).iterator(); }
-
+ { return Arrays.asList( triples ).iterator(); }
+
public void testBulkAddGraph()
- {
+ {
Graph g = getAndRegister( L );
Graph triples = graphWith( "this type graph; I type slowly" );
- g.getBulkUpdateHandler().add( triples );
+ GraphUtil.addInto( g, triples );
L.assertHas( new Object[] {"addGraph", g, triples} );
- }
-
+ }
+
public void testBulkDeleteGraph()
- {
+ {
Graph g = getAndRegister( L );
Graph triples = graphWith( "this type graph; I type slowly" );
- g.getBulkUpdateHandler().delete( triples );
+ GraphUtil.deleteFrom( g, triples );
L.assertHas( new Object[] {"deleteGraph", g, triples} );
- }
-
+ }
+
public void testGeneralEvent()
- {
+ {
Graph g = getAndRegister( L );
Object value = new int[]{};
g.getEventManager().notifyEvent( g, value );
L.assertHas( new Object[] { "someEvent", g, value } );
- }
-
+ }
+
public void testRemoveAllEvent()
- {
+ {
Graph g = getAndRegister( L );
- g.getBulkUpdateHandler().removeAll();
+ g.clear();
L.assertHas( new Object[] { "someEvent", g, GraphEvents.removeAll } );
- }
-
+ }
+
public void testRemoveSomeEvent()
- {
+ {
Graph g = getAndRegister( L );
Node S = node( "S" ), P = node( "??" ), O = node( "??" );
- g.getBulkUpdateHandler().remove( S, P, O );
+ g.remove( S, P, O );
Object event = GraphEvents.remove( S, P, O );
L.assertHas( new Object[] { "someEvent", g, event } );
- }
-
+ }
+
/**
* Test that nodes can be found in all triple positions.
* However, testing for literals in subject positions is suppressed
@@ -722,151 +667,185 @@ public/* abstract */class AbstractTestGr
* such constructs leaking out to the RDF layer.
*/
public void testContainsNode()
- {
+ {
Graph g = getGraph();
graphAdd( g, "a P b; _c _Q _d; a 11 12" );
- QueryHandler qh = g.queryHandler();
- assertTrue( qh.containsNode( node( "a" ) ) );
- assertTrue( qh.containsNode( node( "P" ) ) );
- assertTrue( qh.containsNode( node( "b" ) ) );
- assertTrue( qh.containsNode( node( "_c" ) ) );
- assertTrue( qh.containsNode( node( "_Q" ) ) );
- assertTrue( qh.containsNode( node( "_d" ) ) );
-// assertTrue( qh.containsNode( node( "10" ) ) );
- assertTrue( qh.containsNode( node( "11" ) ) );
- assertTrue( qh.containsNode( node( "12" ) ) );
- /* */
- assertFalse( qh.containsNode( node( "x" ) ) );
- assertFalse( qh.containsNode( node( "_y" ) ) );
- assertFalse( qh.containsNode( node( "99" ) ) );
- }
-
+ assertTrue( containsNode( g, node( "a" ) ) );
+ assertTrue( containsNode( g, node( "P" ) ) );
+ assertTrue( containsNode( g, node( "b" ) ) );
+ assertTrue( containsNode( g, node( "_c" ) ) );
+ assertTrue( containsNode( g, node( "_Q" ) ) );
+ assertTrue( containsNode( g, node( "_d" ) ) );
+ // assertTrue( qh.containsNode( node( "10" ) ) );
+ assertTrue( containsNode( g, node( "11" ) ) );
+ assertTrue( containsNode( g, node( "12" ) ) );
+ /* */
+ assertFalse( containsNode( g, node( "x" ) ) );
+ assertFalse( containsNode( g, node( "_y" ) ) );
+ assertFalse( containsNode( g, node( "99" ) ) );
+ }
+
+
+
+ private boolean containsNode(Graph g, Node node)
+ {
+ return GraphUtil.containsNode(g, node) ;
+ }
+
public void testSubjectsFor()
- {
+ {
+ // First get the answer from the empty graph (not empty for an inf graph)
+ Graph b = getGraphWith( "" );
+ Set<Node> B = GraphUtil.listSubjects( b, Node.ANY, Node.ANY ).toSet();
+
Graph g = getGraphWith( "a P b; a Q c; a P d; b P x; c Q y" );
- testSameSubjects( g, Node.ANY, Node.ANY );
- testSameSubjects( g, node( "P" ), Node.ANY );
- testSameSubjects( g, node( "Q" ), node( "c" ) );
- }
-
- protected void testSameSubjects( Graph g, Node p, Node o )
- {
- Set<Node> bis = SimpleQueryHandler.subjectsFor( g, p, o ).toSet();
- Set<Node> qhs = g.queryHandler().subjectsFor( p, o ).toSet();
- assertEquals( bis, qhs );
- }
-
+
+ testSubjects( g, B, Node.ANY, Node.ANY, node("a"), node("b"), node("c") );
+ testSubjects( g, B, node( "P" ), Node.ANY, node("a"), node("b"));
+ testSubjects( g, B, node( "Q" ), node( "c" ), node("a") );
+ testSubjects( g, B, node( "Q" ), node( "y" ), node("c") );
+ testSubjects( g, B, node( "Q" ), node( "a" ));
+ testSubjects( g, B, node( "Q" ), node( "z" ));
+ }
+
+ protected void testSubjects( Graph g, Collection<Node> exclude, Node p, Node o, Node... expected )
+ {
+ List<Node> R = GraphUtil.listSubjects( g, p, o ).toList();
+ R.removeAll(exclude) ;
+ assertSameUnordered(R, exclude, expected) ;
+ }
+
+ // Same - except for order
+ private void assertSameUnordered(List<Node> x1, Collection<Node>exclude, Node[] expected)
+ {
+ List<Node> x = new ArrayList<Node>() ;
+ x.addAll(x1) ;
+ x.removeAll(exclude) ;
+
+ assertEquals(expected.length, x.size()) ;
+ Set<Node> X = new HashSet<Node>() ;
+ X.addAll(x) ;
+
+ Set<Node> R = new HashSet<Node>() ;
+ R.addAll(Arrays.asList(expected)) ;
+
+ assertEquals( R, X);
+
+ }
+
public void testListSubjectsNoRemove()
- {
+ {
Graph g = getGraphWith( "a P b; b Q c; c R a" );
- Iterator<Node> it = g.queryHandler().subjectsFor( Node.ANY, Node.ANY );
+ Iterator<Node> it = GraphUtil.listSubjects( g, Node.ANY, Node.ANY );
it.next();
try { it.remove(); fail( "listSubjects for " + g.getClass() + " should not support .remove()" ); }
catch (UnsupportedOperationException e) { pass(); }
- }
-
+ }
+
public void testObjectsFor()
- {
+ {
+ // First get the answer from the empty graph (not empty for an inf graph)
+ Graph b = getGraphWith( "" );
+ Set<Node> B = GraphUtil.listObjects( b, Node.ANY, Node.ANY ).toSet();
+
Graph g = getGraphWith( "b P a; c Q a; d P a; x P b; y Q c" );
- testSameObjects( g, Node.ANY, Node.ANY );
- testSameObjects( g, node( "P" ), Node.ANY );
- testSameObjects( g, node( "Q" ), node( "c" ) );
- }
-
- protected void testSameObjects( Graph g, Node s, Node p )
- {
- Set<Node> bis = SimpleQueryHandler.objectsFor( g, s, p ).toSet();
- Set<Node> qhs = g.queryHandler().objectsFor( s, p ).toSet();
- assertEquals( bis, qhs );
- }
+ testObjects( g, B, Node.ANY, Node.ANY, node("a"), node("b"), node("c") );
+ testObjects( g, B, Node.ANY, node( "P" ), node("a"), node("b") );
+ testObjects( g, B, node( "c" ), node( "Q" ), node("a") );
+ testObjects( g, B, node( "y" ), node( "Q" ), node("c") );
+ testObjects( g, B, node( "a" ), node( "Q" ));
+ testObjects( g, B, node( "z" ), node( "Q" ));
+ }
+
+ protected void testObjects( Graph g, Collection<Node> exclude, Node s, Node p, Node... expected )
+ {
+ List<Node> X = GraphUtil.listObjects( g, s, p ).toList();
+ assertSameUnordered(X, exclude, expected) ;
+ }
+
+ public void testPredicatesFor()
+ {
+ // First get the answer from the empty graph (not empty for an inf graph)
+ Graph b = getGraphWith( "" );
+ Set<Node> B = GraphUtil.listPredicates( b, Node.ANY, Node.ANY ).toSet();
+
+ Graph g = getGraphWith( "a P b; z P b; c Q d; e R f; g P b; h Q i" );
+ testPredicates( g, B, Node.ANY, Node.ANY, node("P"), node("Q"), node("R") );
+ testPredicates( g, B, Node.ANY, node( "b" ), node("P") );
+ testPredicates( g, B, node( "g" ), Node.ANY, node("P")) ;
+ testPredicates( g, B, node( "c" ), node( "d" ), node("Q") );
+ testPredicates( g, B, node( "e" ), node( "f" ), node("R") );
+ testPredicates( g, B, node( "e" ), node( "a" ));
+ testPredicates( g, B, node( "z" ), node( "y" ));
+ }
+
+ protected void testPredicates( Graph g, Collection<Node> exclude, Node s, Node o, Node... expected )
+ {
+ List<Node> X = GraphUtil.listPredicates( g, s, o ).toList();
+ assertSameUnordered(X, exclude, expected) ;
+ }
public void testListObjectsNoRemove()
- {
+ {
Graph g = getGraphWith( "a P b; b Q c; c R a" );
- Iterator<Node> it = g.queryHandler().objectsFor( Node.ANY, Node.ANY );
+ Iterator<Node> it = GraphUtil.listObjects( g, Node.ANY, Node.ANY );
it.next();
try { it.remove(); fail( "listObjects for " + g.getClass() + " should not support .remove()" ); }
catch (UnsupportedOperationException e) { pass(); }
- }
-
- public void testListObjectNoDuplicates()
- {
- Graph g = getGraphWith( "a P 1; b P 1" );
- int count = 0;
- Node one = node( "1" );
- Iterator<Node> it = g.queryHandler().objectsFor( Node.ANY, Node.ANY );
- while (it.hasNext()) if (it.next().equals( one )) count += 1;
- assertEquals( 1, count );
- }
-
- public void testPredicatesFor()
- {
- Graph g = getGraphWith( "a P b; c Q d; e R f; g P b; h Q i" );
- testSamePredicates( g, Node.ANY, Node.ANY );
- testSamePredicates( g, Node.ANY, node( "b" ) );
- testSamePredicates( g, node( "g" ), Node.ANY );
- testSamePredicates( g, node( "e" ), node( "f" ) );
- }
-
- protected void testSamePredicates( Graph g, Node s, Node o )
- {
- Set<Node> bis = SimpleQueryHandler.predicatesFor( g, s, o ).toSet();
- Set<Node> qhs = g.queryHandler().predicatesFor( s, o ).toSet();
- assertEquals( bis, qhs );
- }
+ }
public void testListPredicatesNoRemove()
- {
+ {
Graph g = getGraphWith( "a P b; b Q c; c R a" );
- Iterator<Node> it = g.queryHandler().predicatesFor( Node.ANY, Node.ANY );
+ Iterator<Node> it = GraphUtil.listPredicates( g, Node.ANY, Node.ANY );
it.next();
try { it.remove(); fail( "listPredicates for " + g.getClass() + " should not support .remove()" ); }
catch (UnsupportedOperationException e) { pass(); }
- }
-
+ }
+
public void testRemoveAll()
- {
+ {
testRemoveAll( "" );
testRemoveAll( "a R b" );
testRemoveAll( "c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'" );
- }
+ }
+
+
-
-
public void testRemoveAll( String triples )
- {
+ {
Graph g = getGraph();
graphAdd( g, triples );
- g.getBulkUpdateHandler().removeAll();
+ g.clear();
assertTrue( g.isEmpty() );
- }
-
+ }
+
public void failingTestDoubleRemoveAll() {
- final Graph g = getGraph();
- if (g.getCapabilities().iteratorRemoveAllowed() ) {
- graphAdd(g,"c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'" );
- Iterator<Triple> it = new TrackingTripleIterator(g.find(Triple.ANY)){
- @Override
- public void remove() {
- super.remove(); // removes current
- g.delete(current); // no-op.
- }
- };
- while (it.hasNext()) {
- it.next();
- it.remove();
- }
- assertTrue( g.isEmpty() );
- }
+ final Graph g = getGraph();
+ if (g.getCapabilities().iteratorRemoveAllowed() ) {
+ graphAdd(g,"c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'" );
+ Iterator<Triple> it = new TrackingTripleIterator(g.find(Triple.ANY)){
+ @Override
+ public void remove() {
+ super.remove(); // removes current
+ g.delete(current); // no-op.
+ }
+ };
+ while (it.hasNext()) {
+ it.next();
+ it.remove();
+ }
+ assertTrue( g.isEmpty() );
+ }
}
-
+
public void testGetStatisticsHandler()
- {
+ {
Graph g = getGraph();
GraphStatisticsHandler h = g.getStatisticsHandler();
assertSame( h, g.getStatisticsHandler() );
- }
-
+ }
+
/**
Test cases for RemoveSPO(); each entry is a triple (add, remove, result).
<ul>
@@ -874,155 +853,155 @@ public/* abstract */class AbstractTestGr
<li>remove - the pattern to use in the removal
<li>result - the triples that should remain in the graph
</ul>
- */
+ */
protected String[][] cases =
- {
- { "x R y", "x R y", "" },
- { "x R y; a P b", "x R y", "a P b" },
- { "x R y; a P b", "?? R y", "a P b" },
- { "x R y; a P b", "x R ??", "a P b" },
- { "x R y; a P b", "x ?? y", "a P b" },
- { "x R y; a P b", "?? ?? ??", "" },
- { "x R y; a P b; c P d", "?? P ??", "x R y" },
- { "x R y; a P b; x S y", "x ?? ??", "a P b" },
- };
-
+ {
+ { "x R y", "x R y", "" },
+ { "x R y; a P b", "x R y", "a P b" },
+ { "x R y; a P b", "?? R y", "a P b" },
+ { "x R y; a P b", "x R ??", "a P b" },
+ { "x R y; a P b", "x ?? y", "a P b" },
+ { "x R y; a P b", "?? ?? ??", "" },
+ { "x R y; a P b; c P d", "?? P ??", "x R y" },
+ { "x R y; a P b; x S y", "x ?? ??", "a P b" },
+ };
+
/**
Test that remove(s, p, o) works, in the presence of inferencing graphs that
mean emptyness isn't available. This is why we go round the houses and
test that expected ~= initialContent + addedStuff - removed - initialContent.
- */
+ */
public void testRemoveSPO()
- {
+ {
for (int i = 0; i < cases.length; i += 1)
for (int j = 0; j < 3; j += 1)
- {
+ {
Graph content = getGraph();
Graph baseContent = copy( content );
graphAdd( content, cases[i][0] );
Triple remove = triple( cases[i][1] );
Graph expected = graphWith( cases[i][2] );
- content.getBulkUpdateHandler().remove( remove.getSubject(), remove.getPredicate(), remove.getObject() );
+ content.remove( remove.getSubject(), remove.getPredicate(), remove.getObject() );
Graph finalContent = remove( copy( content ), baseContent );
assertIsomorphic( cases[i][1], expected, finalContent );
- }
- }
-
+ }
+ }
+
/** testIsomorphism from file data
* @throws FileNotFoundException */
public void testIsomorphismFile() throws FileNotFoundException {
- testIsomorphismXMLFile(1,true);
- testIsomorphismXMLFile(2,true);
- testIsomorphismXMLFile(3,true);
- testIsomorphismXMLFile(4,true);
- testIsomorphismXMLFile(5,false);
- testIsomorphismXMLFile(6,false);
- testIsomorphismNTripleFile(7,true);
- testIsomorphismNTripleFile(8,false);
-
+ testIsomorphismXMLFile(1,true);
+ testIsomorphismXMLFile(2,true);
+ testIsomorphismXMLFile(3,true);
+ testIsomorphismXMLFile(4,true);
+ testIsomorphismXMLFile(5,false);
+ testIsomorphismXMLFile(6,false);
+ testIsomorphismNTripleFile(7,true);
+ testIsomorphismNTripleFile(8,false);
+
}
private void testIsomorphismNTripleFile(int i, boolean result) throws FileNotFoundException {
- testIsomorphismFile(i,"N-TRIPLE","nt",result);
- }
+ testIsomorphismFile(i,"N-TRIPLE","nt",result);
+ }
+
+ private void testIsomorphismXMLFile(int i, boolean result) throws FileNotFoundException {
+ testIsomorphismFile(i,"RDF/XML","rdf",result);
- private void testIsomorphismXMLFile(int i, boolean result) throws FileNotFoundException {
- testIsomorphismFile(i,"RDF/XML","rdf",result);
-
- }
+ }
String filebase = "testing/regression/testModelEquals/";
- private void testIsomorphismFile(int n, String lang, String suffix, boolean result) throws FileNotFoundException {
+ private void testIsomorphismFile(int n, String lang, String suffix, boolean result) throws FileNotFoundException {
- Graph g1 = getGraph();
- Graph g2 = getGraph();
- Model m1 = ModelFactory.createModelForGraph(g1);
- Model m2 = ModelFactory.createModelForGraph(g2);
-
- m1.read(
- new FileInputStream(filebase + Integer.toString(n) + "-1."+suffix),
- "http://www.example.org/",lang);
- m2.read(
- new FileInputStream(filebase + Integer.toString(n) + "-2."+suffix),
- "http://www.example.org/",lang);
+ Graph g1 = getGraph();
+ Graph g2 = getGraph();
+ Model m1 = ModelFactory.createModelForGraph(g1);
+ Model m2 = ModelFactory.createModelForGraph(g2);
+
+ m1.read(
+ new FileInputStream(filebase + Integer.toString(n) + "-1."+suffix),
+ "http://www.example.org/",lang);
+ m2.read(
+ new FileInputStream(filebase + Integer.toString(n) + "-2."+suffix),
+ "http://www.example.org/",lang);
- boolean rslt = g1.isIsomorphicWith(g2) == result;
- if (!rslt) {
+ boolean rslt = g1.isIsomorphicWith(g2) == result;
+ if (!rslt) {
System.out.println("g1:");
m1.write(System.out, "N-TRIPLE");
System.out.println("g2:");
m2.write(System.out, "N-TRIPLE");
}
assertTrue("Isomorphism test failed",rslt);
- }
+ }
+
+ protected void add( Graph toUpdate, Graph toAdd )
+ {
+ GraphUtil.addInto( toUpdate, toAdd) ;
+ }
- protected void add( Graph toUpdate, Graph toAdd )
- {
- toUpdate.getBulkUpdateHandler().add( toAdd );
- }
-
protected Graph remove( Graph toUpdate, Graph toRemove )
- {
- toUpdate.getBulkUpdateHandler().delete( toRemove );
+ {
+ GraphUtil.deleteFrom(toUpdate, toRemove) ;
return toUpdate;
- }
-
-
+ }
+
+
protected Graph copy( Graph g )
- {
+ {
Graph result = Factory.createDefaultGraph();
- result.getBulkUpdateHandler().add( g );
+ GraphUtil.addInto(result, g) ;
return result;
- }
-
+ }
+
protected Graph getClosed()
- {
+ {
Graph result = getGraph();
result.close();
return result;
- }
-
-// public void testClosedDelete()
-// {
-// try { getClosed().delete( triple( "x R y" ) ); fail( "delete when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedAdd()
-// {
-// try { getClosed().add( triple( "x R y" ) ); fail( "add when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedContainsTriple()
-// {
-// try { getClosed().contains( triple( "x R y" ) ); fail( "contains[triple] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedContainsSPO()
-// {
-// Node a = Node.ANY;
-// try { getClosed().contains( a, a, a ); fail( "contains[SPO] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedFindTriple()
-// {
-// try { getClosed().find( triple( "x R y" ) ); fail( "find [triple] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedFindSPO()
-// {
-// Node a = Node.ANY;
-// try { getClosed().find( a, a, a ); fail( "find[SPO] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedSize()
-// {
-// try { getClosed().size(); fail( "size when closed (" + this.getClass() + ")" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-
}
+
+ // public void testClosedDelete()
+ // {
+ // try { getClosed().delete( triple( "x R y" ) ); fail( "delete when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedAdd()
+ // {
+ // try { getClosed().add( triple( "x R y" ) ); fail( "add when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedContainsTriple()
+ // {
+ // try { getClosed().contains( triple( "x R y" ) ); fail( "contains[triple] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedContainsSPO()
+ // {
+ // Node a = Node.ANY;
+ // try { getClosed().contains( a, a, a ); fail( "contains[SPO] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedFindTriple()
+ // {
+ // try { getClosed().find( triple( "x R y" ) ); fail( "find [triple] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedFindSPO()
+ // {
+ // Node a = Node.ANY;
+ // try { getClosed().find( a, a, a ); fail( "find[SPO] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedSize()
+ // {
+ // try { getClosed().size(); fail( "size when closed (" + this.getClass() + ")" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraphMaker.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraphMaker.java?rev=1430447&r1=1430446&r2=1430447&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraphMaker.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraphMaker.java Tue Jan 8 19:07:23 2013
@@ -32,8 +32,6 @@ import com.hp.hpl.jena.shared.*;
This bunch of tests is not remotely exhaustive, but it was sufficent to
drive the development of the first full graph factory. (Although at the time
it wasn't abstract.)
-
- @author hedgehog
*/
public abstract class AbstractTestGraphMaker extends GraphTestBase
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestReifier.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestReifier.java?rev=1430447&r1=1430446&r2=1430447&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestReifier.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestReifier.java Tue Jan 8 19:07:23 2013
@@ -18,121 +18,53 @@
package com.hp.hpl.jena.graph.test;
-import java.util.Collections;
-
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.impl.GraphBase;
-import com.hp.hpl.jena.shared.*;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator;
-import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.graph.Factory ;
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.rdf.model.impl.ReifierStd ;
+import com.hp.hpl.jena.shared.AlreadyReifiedException ;
+import com.hp.hpl.jena.shared.CannotReifyException ;
+import com.hp.hpl.jena.vocabulary.RDF ;
/**
Abstract base class for reification tests.
- @author kers
-*/
+ */
public abstract class AbstractTestReifier extends GraphTestBase
- {
- protected static final ReificationStyle Minimal = ReificationStyle.Minimal;
- protected static final ReificationStyle Standard = ReificationStyle.Standard;
- protected static final ReificationStyle Convenient = ReificationStyle.Convenient;
-
+{
protected static final Triple ALL = Triple.ANY;
-
+
public AbstractTestReifier( String name )
- { super( name ); }
-
+ { super( name ); }
+
public abstract Graph getGraph();
-
- public abstract Graph getGraph( ReificationStyle style );
protected final Graph getGraphWith( String facts )
- {
+ {
Graph result = getGraph();
graphAdd( result, facts );
return result;
- }
+ }
/**
- Answer true iff g's reifier has style Standard.
- */
- private boolean isStandard( Graph g )
- { return g.getReifier().getStyle() == Standard; }
-
- /**
Answer the empty graph if cond is false, otherwise the graph with the given facts.
- */
+ */
protected final Graph graphWithUnless( boolean cond, String facts )
- { return graphWith( cond ? "" : facts ); }
-
+ { return graphWith( cond ? "" : facts ); }
+
protected final Graph graphWithIf( boolean cond, String facts )
- { return graphWithUnless( !cond, facts ); }
-
+ { return graphWithUnless( !cond, facts ); }
+
public void testGetGraphNotNull()
- { assertNotNull( getGraph() ); }
-
- public void testGotGraphReifierNotNull()
- { assertNotNull( getGraph().getReifier() ); }
-
- public void testGotGraphReifierStyleNotNull()
- { assertNotNull( getGraph().getReifier().getStyle() ); }
-
- public void testStyle()
- {
- assertSame( Minimal, getGraph( Minimal ).getReifier().getStyle() );
- assertSame( Standard, getGraph( Standard ).getReifier().getStyle() );
- assertSame( Convenient, getGraph( Convenient ).getReifier().getStyle() );
- }
-
- public void testEmptyReifiers()
- {
- assertFalse( getGraphWith( "x R y" ).getReifier().findExposed( ALL ).hasNext() );
- assertFalse( getGraphWith( "x R y; p S q" ).getReifier().findExposed( ALL ).hasNext() );
- }
-
- public void testSameReifier()
- {
- Graph G = getGraph();
- Reifier R1 = G.getReifier();
- G.add( triple( "x R y" ) );
- assertTrue( "same reifier", R1 == G.getReifier() );
- }
-
- public void testReifierClosed()
- {
- Graph g = getGraph();
- Reifier r = g.getReifier();
- g.close();
- }
-
- public void testParent()
- {
- Graph G = getGraph(), H = getGraph();
- assertTrue( "correct reifier (G)", G == G.getReifier().getParentGraph() );
- assertTrue( "correct reifier (H)", H == H.getReifier().getParentGraph() );
- }
-
- public void testIntercept()
- {
- Graph g = getGraph( Convenient );
- Reifier r = g.getReifier();
- Node S = node( "sub" ), O = node( "obj" );
- Node RS = node( "http://example.org/type" );
- /* */
- assertFalse( "reifier must not intercept quadlet", r.handledAdd( Triple.create( S, RDF.Nodes.type, RS ) ) );
- assertFalse( "reifier must not intercept quadlet", r.handledAdd( Triple.create( S, S, RDF.Nodes.subject ) ) );
- assertFalse( "reifier must not intercept quadlet", r.handledAdd( Triple.create( S, S, RDF.Nodes.type ) ) );
- /* */
- assertTrue( "reifier must intercept quadlet", r.handledAdd( Triple.create( S, RDF.Nodes.predicate, O ) ) );
- assertTrue( "reifier must intercept quadlet", r.handledAdd( Triple.create( S, RDF.Nodes.type, RDF.Nodes.Statement ) ) );
- }
+ { assertNotNull( getGraph() ); }
/**
Check that the standard reifier will note, but not hide, reification quads.
- */
+ */
public void testStandard()
- {
- Graph g = getGraph( Standard );
- assertFalse( g.getReifier().hasTriple( triple( "s p o" ) ) );
+ {
+ Graph g = getGraph( );
+ assertFalse( ReifierStd.hasTriple(g, triple( "s p o" ) ) );
g.add( NodeCreateUtils.createTriple( "x rdf:subject s" ) );
assertEquals( 1, g.size() );
g.add( NodeCreateUtils.createTriple( "x rdf:predicate p" ) );
@@ -141,419 +73,229 @@ public abstract class AbstractTestReifie
assertEquals( 3, g.size() );
g.add( NodeCreateUtils.createTriple( "x rdf:type rdf:Statement" ) );
assertEquals( 4, g.size() );
- assertTrue( g.getReifier().hasTriple( triple( "s p o" ) ) );
- }
-
+ assertTrue( ReifierStd.hasTriple(g, triple( "s p o" ) ) );
+ }
+
/**
Test that the Standard reifier will expose implicit quads arising from reifyAs().
- */
+ */
public void testStandardExplode()
- {
- Graph g = getGraph( Standard );
- g.getReifier().reifyAs( node( "a" ), triple( "p Q r" ) );
- Graph r = Factory.createDefaultGraph( Minimal );
+ {
+ Graph g = getGraph( );
+ ReifierStd.reifyAs( g, node( "a" ), triple( "p Q r" ) );
+ Graph r = Factory.createDefaultGraph( );
graphAdd( r, "a rdf:type rdf:Statement; a rdf:subject p; a rdf:predicate Q; a rdf:object r" );
assertEquals( 4, g.size() );
assertIsomorphic( r, g );
- }
-
- public void testMinimalExplode()
- {
- Graph g = getGraph( Minimal );
- g.getReifier().reifyAs( node( "a" ), triple( "p Q r" ) );
- assertEquals( 0, g.size() );
- }
-
- /**
- test that a reifier with the given style sees [or not, if it's minimal] the reification quads
- that are inserted through its graph.
- */
- public void testReificationTriples()
- {
- Graph g = getGraph();
- ReificationStyle style = g.getReifier().getStyle();
- Graph quadlets = getReificationTriples( g.getReifier() );
- String S1 = "SSS rdf:predicate PPP", S2 = "SSS rdf:subject SSS";
- g.add( triple( S1 ) );
- assertIsomorphic( graphWithUnless( style == Minimal, S1 ), quadlets );
- g.add( triple( S2 ) );
- assertIsomorphic( graphWithUnless( style == Minimal, S1 + "; " + S2 ), quadlets );
- assertEquals( "convenient hides quadlets", style == Convenient, g.size() == 0 );
- }
-
+ }
+
/**
Ensure that over-specifying a reification means that we don't get a triple
back. Goodness knows why this test wasn't in right from the beginning.
- */
+ */
public void testOverspecificationSuppressesReification()
- {
+ {
Graph g = getGraph();
- if (isStandard( g ))
- {
- Reifier r = g.getReifier();
- graphAdd( g, "x rdf:subject A; x rdf:predicate P; x rdf:object O; x rdf:type rdf:Statement" );
- assertEquals( triple( "A P O" ), r.getTriple( node( "x" ) ) );
- graphAdd( g, "x rdf:subject BOOM" );
- assertEquals( null, r.getTriple( node( "x" ) ) );
- }
- }
-
+ graphAdd( g, "x rdf:subject A; x rdf:predicate P; x rdf:object O; x rdf:type rdf:Statement" );
+ assertEquals( triple( "A P O" ), ReifierStd.getTriple(g, node( "x" ) ) );
+ graphAdd( g, "x rdf:subject BOOM" );
+ assertEquals( null, ReifierStd.getTriple( g, node( "x" ) ) );
+ }
+
public void testReificationSubjectClash()
- {
+ {
testReificationClash( "x rdf:subject SS" );
- }
-
+ }
+
public void testReificationPredicateClash()
- {
+ {
testReificationClash( "x rdf:predicate PP" );
- }
-
+ }
+
public void testReificationObjectClash()
- {
+ {
testReificationClash( "x rdf:object OO" );
- }
-
+ }
+
protected void testReificationClash( String clashingStatement )
- {
+ {
Graph g = getGraph();
- if (isStandard( g ))
- {
- Triple SPO = NodeCreateUtils.createTriple( "S P O" );
- g.getReifier().reifyAs( node( "x" ), SPO );
- assertTrue( g.getReifier().hasTriple( SPO ) );
- graphAdd( g, clashingStatement );
- assertEquals( null, g.getReifier().getTriple( node( "x" ) ) );
- // System.err.println( ">> tRC: clashing = " + clashingStatement );
- assertFalse( g.getReifier().hasTriple( SPO ) );
- }
- }
+ Triple SPO = NodeCreateUtils.createTriple( "S P O" );
+ ReifierStd.reifyAs(g, node( "x" ), SPO );
+ assertTrue( ReifierStd.hasTriple( g , SPO ) );
+ graphAdd( g, clashingStatement );
+ assertEquals( null, ReifierStd.getTriple( g , node( "x" ) ) );
+ // System.err.println( ">> tRC: clashing = " + clashingStatement );
+ assertFalse( ReifierStd.hasTriple(g, SPO ) );
+ }
-// public void testManifestQuadsStandard()
-// { testManifestQuads( Standard ); }
-//
-// public void testManifestQuadsConvenient()
-// { testManifestQuads( Convenient ); }
-//
-// public void testManifestQuadsMinimal()
-// { testManifestQuads( Minimal ); }
-
/**
Test that reifying a triple explicitly has some effect on the graph only for Standard
reifiers.
*/
public void testManifestQuads()
- {
+ {
Graph g = getGraph();
- Reifier r = g.getReifier();
- ReificationStyle style = r.getStyle();
- r.reifyAs( node( "A" ), triple( "S P O" ) );
+ ReifierStd.reifyAs(g, node( "A" ), triple( "S P O" ) ) ;
String reified = "A rdf:type rdf:Statement; A rdf:subject S; A rdf:predicate P; A rdf:object O";
- assertIsomorphic( graphWithIf( style == Standard, reified ), g );
- }
-
-// public void testHiddenVsReificationMinimal()
-// { testHiddenVsReification( Minimal ); }
-//
-// public void testHiddenVsStandard()
-// { testHiddenVsReification( Standard ); }
-//
-// public void testHiddenVsReificationConvenient()
-// { testHiddenVsReification( Convenient ); }
-
+ assertIsomorphic( graphWith( reified ), g );
+ }
+
public void testHiddenVsReification()
- {
+ {
Graph g = getGraph();
- ReificationStyle style = g.getReifier().getStyle();
- Reifier r = g.getReifier();
- r.reifyAs( node( "A" ), triple( "S P O" ) );
- assertEquals( style == Standard, r.findEither( ALL, false ).hasNext() );
- }
-
+ ReifierStd.reifyAs( g, node( "A" ), triple( "S P O" ) );
+ assertTrue( ReifierStd.findEither( g , ALL, false ).hasNext() );
+ }
+
public void testRetrieveTriplesByNode()
- {
+ {
Graph G = getGraph();
- Reifier R = G.getReifier();
Node N = Node.createAnon(), M = Node.createAnon();
- R.reifyAs( N, triple( "x R y" ) );
- assertEquals( "gets correct triple", triple( "x R y" ), R.getTriple( N ) );
- R.reifyAs( M, triple( "p S q" ) );
+ ReifierStd.reifyAs( G , N, triple( "x R y" ) );
+ assertEquals( "gets correct triple", triple( "x R y" ), ReifierStd.getTriple( G , N ) );
+ ReifierStd.reifyAs( G, M, triple( "p S q" ) );
assertDiffer( "the anon nodes must be distinct", N, M );
- assertEquals( "gets correct triple", triple( "p S q" ), R.getTriple( M ) );
- /* */
- assertTrue( "node is known bound", R.hasTriple( M ) );
- assertTrue( "node is known bound", R.hasTriple( N ) );
- assertFalse( "node is known unbound", R.hasTriple( Node.createURI( "any:thing" ) ) );
- /* */
-// Graph GR = R.getReifiedTriples();
-// assertTrue( "reified triples", getGraphWith( "x R y; p S q" ).isIsomorphicWith(GR) );
-// assertTrue( "untouched graph", getGraph().isIsomorphicWith(G) );
- }
-
+ assertEquals( "gets correct triple", triple( "p S q" ), ReifierStd.getTriple( G , M ) );
+
+ assertTrue( "node is known bound", ReifierStd.hasTriple( G, M ) );
+ assertTrue( "node is known bound", ReifierStd.hasTriple( G, N ) );
+ assertFalse( "node is known unbound", ReifierStd.hasTriple( G, Node.createURI( "any:thing" ) ) );
+ }
+
public void testRetrieveTriplesByTriple()
- {
+ {
Graph G = getGraph();
- Reifier R = G.getReifier();
Triple T = triple( "x R y" ), T2 = triple( "y R x" );
Node N = node( "someNode" );
- R.reifyAs( N, T );
- assertTrue( "R must have T", R.hasTriple( T ) );
- assertFalse( "R must not have T2", R.hasTriple( T2 ) );
- }
-
+ ReifierStd.reifyAs( G, N, T );
+ assertTrue( "R must have T", ReifierStd.hasTriple( G, T ) );
+ assertFalse( "R must not have T2", ReifierStd.hasTriple( G, T2 ) );
+ }
+
public void testReifyAs()
- {
+ {
Graph G = getGraph();
- Reifier R = G.getReifier();
Node X = Node.createURI( "some:uri" );
- assertEquals( "node used", X, R.reifyAs( X, triple( "x R y" ) ) );
- assertEquals( "retrieves correctly", triple( "x R y" ), R.getTriple( X ) );
- }
-
+ assertEquals( "node used", X, ReifierStd.reifyAs( G, X, triple( "x R y" ) ) );
+ assertEquals( "retrieves correctly", triple( "x R y" ), ReifierStd.getTriple( G, X ) );
+ }
+
public void testAllNodes()
- {
- Reifier R = getGraph().getReifier();
- R.reifyAs( node("x"), triple( "cows eat grass" ) );
- R.reifyAs( node("y"), triple( "pigs can fly" ) );
- R.reifyAs( node("z"), triple( "dogs may bark" ) );
- assertEquals( "", nodeSet( "z y x" ), iteratorToSet( R.allNodes() ) );
- }
-
+ {
+ Graph G = getGraph();
+ ReifierStd.reifyAs( G, node("x"), triple( "cows eat grass" ) );
+ ReifierStd.reifyAs( G, node("y"), triple( "pigs can fly" ) );
+ ReifierStd.reifyAs( G, node("z"), triple( "dogs may bark" ) );
+ assertEquals( "", nodeSet( "z y x" ), iteratorToSet( ReifierStd.allNodes(G) ) );
+ }
+
public void testRemoveByNode()
- {
+ {
Graph G = getGraph();
- Reifier R = G.getReifier();
Node X = node( "x" ), Y = node( "y" );
- R.reifyAs( X, triple( "x R a" ) );
- R.reifyAs( Y, triple( "y R a" ) );
- R.remove( X, triple( "x R a" ) );
- assertFalse( "triple X has gone", R.hasTriple( X ) );
- assertEquals( "triple Y still there", triple( "y R a" ), R.getTriple( Y ) );
- }
-
+ ReifierStd.reifyAs( G, X, triple( "x R a" ) );
+ ReifierStd.reifyAs( G, Y, triple( "y R a" ) );
+ ReifierStd.remove( G, X, triple( "x R a" ) );
+ assertFalse( "triple X has gone", ReifierStd.hasTriple( G, X ) );
+ assertEquals( "triple Y still there", triple( "y R a" ), ReifierStd.getTriple( G, Y ) );
+ }
+
public void testRemoveFromNothing()
- {
+ {
Graph G = getGraph();
- Reifier R = G.getReifier();
G.delete( triple( "quint rdf:subject S" ) );
- }
-
-// public void testRemoveByTriple()
-// {
-// Graph G = getGraph();
-// Reifier R = G.getReifier();
-// Node X = node( "x" ), Y = node( "y" );
-// R.reifyAs( X, triple( "x R a" ) );
-// R.reifyAs( Y, triple( "y R a" ) );
-// R.remove( triple( "x R a" ) );
-// assertFalse( "triple X has gone", R.hasTriple( X ) );
-// assertEquals( "triple Y still there", triple( "y R a" ), R.getTriple( Y ) );
-// }
-
+ }
+
public void testException()
- {
+ {
Graph G = getGraph();
- Reifier R = G.getReifier();
Node X = node( "x" );
- R.reifyAs( X, triple( "x R y" ) );
- R.reifyAs( X, triple( "x R y" ) );
- try { R.reifyAs( X, triple( "x R z" ) ); fail( "did not detect already reified node" ); }
+ ReifierStd.reifyAs( G, X, triple( "x R y" ) );
+ ReifierStd.reifyAs( G, X, triple( "x R y" ) );
+ try { ReifierStd.reifyAs( G, X, triple( "x R z" ) ); fail( "did not detect already reified node" ); }
catch (AlreadyReifiedException e) { }
- }
-
+ }
+
public void testKevinCaseA()
- {
+ {
Graph G = getGraph();
- if (isStandard( G ))
- {
- Node X = node( "x" ), a = node( "a" ), b = node( "b" ), c = node( "c" );
- G.add( Triple.create( X, RDF.Nodes.type, RDF.Nodes.Statement ) );
- G.getReifier().reifyAs( X, Triple.create( a, b, c ) );
- }
- }
-
+ Node X = node( "x" ), a = node( "a" ), b = node( "b" ), c = node( "c" );
+ G.add( Triple.create( X, RDF.Nodes.type, RDF.Nodes.Statement ) );
+ ReifierStd.reifyAs( G, X, Triple.create( a, b, c ) );
+ }
+
public void testKevinCaseB()
- {
+ {
Graph G = getGraph();
- if (isStandard( G ))
- {
- Node X = node( "x" ), Y = node( "y" );
- Node a = node( "a" ), b = node( "b" ), c = node( "c" );
- G.add( Triple.create( X, RDF.Nodes.subject, Y ) );
- try
- {
- G.getReifier().reifyAs( X, Triple.create( a, b, c ) );
- fail( "X already has subject Y: cannot make it a" );
- }
- catch (CannotReifyException e)
- { pass(); }
- }
- }
-
- /**
- Test that the hidden triples graph is dynamic, not static.
- */
- public void testDynamicHiddenTriples()
- {
- Graph g = getGraph( Minimal );
- Reifier r = g.getReifier();
- Graph h = getHiddenTriples( r );
- Graph wanted = graphWith
- (
- "x rdf:type rdf:Statement"
- + "; x rdf:subject a"
- + "; x rdf:predicate B"
- + "; x rdf:object c"
- );
- assertTrue( h.isEmpty() );
- r.reifyAs( node( "x" ), triple( "a B c" ) );
- assertIsomorphic( wanted, h );
- }
-
- protected Graph getHiddenTriples( final Reifier r )
+ Node X = node( "x" ), Y = node( "y" );
+ Node a = node( "a" ), b = node( "b" ), c = node( "c" );
+ G.add( Triple.create( X, RDF.Nodes.subject, Y ) );
+ try
{
- return new GraphBase()
- {
- @Override public ExtendedIterator<Triple> graphBaseFind( TripleMatch m )
- { return r.findEither( m, true ); }
- };
+ ReifierStd.reifyAs( G, X, Triple.create( a, b, c ) );
+ fail( "X already has subject Y: cannot make it a" );
}
-
- public void testQuadRemove()
- {
- Graph g = getGraph();
- if (isStandard( g ))
- {
- assertEquals( 0, g.size() );
- Triple s = NodeCreateUtils.createTriple( "x rdf:subject s" );
- Triple p = NodeCreateUtils.createTriple( "x rdf:predicate p" );
- Triple o = NodeCreateUtils.createTriple( "x rdf:object o" );
- Triple t = NodeCreateUtils.createTriple( "x rdf:type rdf:Statement");
- g.add(s); g.add(p); g.add(o); g.add(t);
- assertEquals( 4, g.size() );
- g.delete(s); g.delete(p); g.delete(o); g.delete(t);
- assertEquals( 0, g.size() );
- }
- }
+ catch (CannotReifyException e)
+ { pass(); }
+ }
+
+ public void testQuadRemove()
+ {
+ Graph g = getGraph();
+ assertEquals( 0, g.size() );
+ Triple s = NodeCreateUtils.createTriple( "x rdf:subject s" );
+ Triple p = NodeCreateUtils.createTriple( "x rdf:predicate p" );
+ Triple o = NodeCreateUtils.createTriple( "x rdf:object o" );
+ Triple t = NodeCreateUtils.createTriple( "x rdf:type rdf:Statement");
+ g.add(s); g.add(p); g.add(o); g.add(t);
+ assertEquals( 4, g.size() );
+ g.delete(s); g.delete(p); g.delete(o); g.delete(t);
+ assertEquals( 0, g.size() );
+ }
- public void testReifierSize()
- {
- assertEquals( 0, getGraph().getReifier().size() );
- }
-
public void testEmpty()
- {
+ {
Graph g = getGraph();
- if (g.getReifier().getStyle() != Convenient)
- {
- assertTrue( g.isEmpty() );
- graphAdd( g, "x rdf:type rdf:Statement" ); assertFalse( g.isEmpty() );
- graphAdd( g, "x rdf:subject Deconstruction" ); assertFalse( g.isEmpty() );
- graphAdd( g, "x rdf:predicate rdfs:subTypeOf" ); assertFalse( g.isEmpty() );
- graphAdd( g, "x rdf:object LiteraryCriticism" ); assertFalse( g.isEmpty() );
- }
- }
-
+ assertTrue( g.isEmpty() );
+ graphAdd( g, "x rdf:type rdf:Statement" ); assertFalse( g.isEmpty() );
+ graphAdd( g, "x rdf:subject Deconstruction" ); assertFalse( g.isEmpty() );
+ graphAdd( g, "x rdf:predicate rdfs:subTypeOf" ); assertFalse( g.isEmpty() );
+ graphAdd( g, "x rdf:object LiteraryCriticism" ); assertFalse( g.isEmpty() );
+ }
+
public void testReifierEmptyFind()
- {
+ {
Graph g = getGraph();
- Reifier r = g.getReifier();
- assertEquals( tripleSet( "" ), r.findExposed( Triple.ANY ).toSet() );
- }
+ assertEquals( tripleSet( "" ), ReifierStd.findExposed( g , Triple.ANY ).toSet() );
+ }
public void testReifierFindSubject()
- { testReifierFind( "x rdf:subject S" ); }
-
+ { testReifierFind( "x rdf:subject S" ); }
+
public void testReifierFindObject()
- { testReifierFind( "x rdf:object O" ); }
-
+ { testReifierFind( "x rdf:object O" ); }
+
public void testReifierFindPredicate()
- { testReifierFind( "x rdf:predicate P" ); }
-
+ { testReifierFind( "x rdf:predicate P" ); }
+
public void testReifierFindComplete()
- { testReifierFind( "x rdf:predicate P; x rdf:subject S; x rdf:object O; x rdf:type rdf:Statement" ); }
-
+ { testReifierFind( "x rdf:predicate P; x rdf:subject S; x rdf:object O; x rdf:type rdf:Statement" ); }
+
public void testReifierFindFilter()
- {
+ {
Graph g = getGraph();
- Reifier r = g.getReifier();
graphAdd( g, "s rdf:subject S" );
- assertEquals( tripleSet( "" ), r.findExposed( triple( "s otherPredicate S" ) ).toSet() );
- }
+ assertEquals( tripleSet( "" ), ReifierStd.findExposed( g, triple( "s otherPredicate S" ) ).toSet() );
+ }
protected void testReifierFind( String triples )
- { testReifierFind( triples, "?? ?? ??" ); }
+ { testReifierFind( triples, "?? ?? ??" ); }
- /**
- Only applies to style Standard.
- */
protected void testReifierFind( String triples, String pattern )
- {
+ {
Graph g = getGraph();
- Reifier r = g.getReifier();
graphAdd( g, triples );
- if (r.getStyle() == Standard)
- assertEquals( tripleSet( triples ), r.findExposed( triple( pattern ) ).toSet() );
- }
-
- public void testQuintetBug()
- {
- String spec = "rs rdf:type rdf:Statement; foo rdf:value rs; rs rdf:subject X; rs rdf:predicate P; rs rdf:object O1; rs rdf:object O2";
- Graph g = getGraph( Standard );
- Reifier r = g.getReifier();
- graphAdd( g, spec );
- Graph wanted = getGraph( Minimal );
- graphAdd( wanted, spec );
- assertIsomorphic( wanted, g );
- }
-
- public void testBulkClearReificationTriples()
- {
- Graph g = getGraphWith( "x rdf:subject S" );
- g.getBulkUpdateHandler().removeAll();
- assertEquals( "oops: " + g.getClass(), Collections.EMPTY_SET, g.find( Node.ANY, Node.ANY, Node.ANY ).toSet() );
- }
-
- public void testBulkClearReificationTriples2()
- {
- Graph g = getGraphWith( "x rdf:subject S; x rdf:predicate P; x rdf:object O; x rdf:type rdf:Statement" );
- g.getBulkUpdateHandler().removeAll();
- assertEquals( Collections.EMPTY_SET, g.find( Node.ANY, Node.ANY, Node.ANY ).toSet() );
- }
-
-// public void testKevinCaseC()
-// {
-// Graph G = GraphBase.withReification( getGraph() );
-// Node X = node( "x" ), Y = node( "y" );
-// Node a = node( "a" ), b = node( "b" ), c = node( "c" );
-// G.getReifier().reifyAs( X, Triple.create( a, b, c ) );
-// try
-// {
-// G.add( Triple.create( X, Reifier.subject, Y ) );
-// fail( "X already reifies (a, b, c): cannot give it subject Y" );
-// }
-// catch (Reifier.CannotReifyException e)
-// { /* as requried */ }
-// }
-
-// public void testQuads()
-// {
-// Node A = node( "a" ), B = node( "b" );
-// Graph G = getGraph();
-// Graph quads = getGraphWith
-// (
-// "a " + RDF.type + " " + RDF.Statement
-// + "; a " + RDF.subject + " x"
-// + "; a " + RDF.predicate + " R"
-// + "; a " + RDF.object + " y"
-// + "; b " + RDF.type + " " + RDF.Statement
-// + "; b " + RDF.subject + " p"
-// + "; b " + RDF.predicate + " S"
-// + "; b " + RDF.object + " q"
-// );
-// Reifier R = G.getReifier();
-// R.reifyAs( A, triple( "x R y") );
-// R.reifyAs( B, triple( "p S q" ) );
-// assertEquals( "same", quads, R.getReificationQuads() );
-// }
-
+ assertEquals( tripleSet( triples ), ReifierStd.findExposed( g, triple( pattern ) ).toSet() );
}
+}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestTripleStore.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestTripleStore.java?rev=1430447&r1=1430446&r2=1430447&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestTripleStore.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestTripleStore.java Tue Jan 8 19:07:23 2013
@@ -22,7 +22,6 @@ import com.hp.hpl.jena.graph.impl.Triple
/**
AbstractTestTripleStore - post-hoc tests for TripleStores.
- @author kers
*/
public abstract class AbstractTestTripleStore extends GraphTestBase
{
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/GraphTestBase.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/GraphTestBase.java?rev=1430447&r1=1430446&r2=1430447&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/GraphTestBase.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/GraphTestBase.java Tue Jan 8 19:07:23 2013
@@ -20,18 +20,18 @@ package com.hp.hpl.jena.graph.test;
/**
An extension of JenaTestBase (which see) with Graph-specific methods.
- @author kers
*/
-import com.hp.hpl.jena.util.*;
-import com.hp.hpl.jena.util.iterator.*;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.impl.GraphBase;
-import com.hp.hpl.jena.shared.*;
-import com.hp.hpl.jena.test.*;
+import java.lang.reflect.Constructor ;
+import java.util.* ;
-import java.lang.reflect.Constructor;
-import java.util.*;
+import com.hp.hpl.jena.graph.* ;
+import com.hp.hpl.jena.shared.JenaException ;
+import com.hp.hpl.jena.shared.PrefixMapping ;
+import com.hp.hpl.jena.test.JenaTestBase ;
+import com.hp.hpl.jena.util.CollectionFactory ;
+import com.hp.hpl.jena.util.IteratorCollection ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
public class GraphTestBase extends JenaTestBase
{
@@ -383,18 +383,17 @@ public class GraphTestBase extends JenaT
@param wrap the outer class instance if graphClass is an inner class
@param graphClass a class implementing Graph
- @param style the reification style to use
@return an instance of graphClass with the given style
@throws RuntimeException or JenaException if construction fails
*/
- public static Graph getGraph( Object wrap, Class<? extends Graph> graphClass, ReificationStyle style )
+ public static Graph getGraph( Object wrap, Class<? extends Graph> graphClass)
{
try
{
- Constructor<?> cons = getConstructor( graphClass, new Class[] {ReificationStyle.class} );
- if (cons != null) return (Graph) cons.newInstance( new Object[] { style } );
- Constructor<?> cons2 = getConstructor( graphClass, new Class [] {wrap.getClass(), ReificationStyle.class} );
- if (cons2 != null) return (Graph) cons2.newInstance( new Object[] { wrap, style } );
+ Constructor<?> cons = getConstructor( graphClass, new Class[] {} );
+ if (cons != null) return (Graph) cons.newInstance( new Object[] { } );
+ Constructor<?> cons2 = getConstructor( graphClass, new Class [] {wrap.getClass()} );
+ if (cons2 != null) return (Graph) cons2.newInstance( new Object[] { wrap} );
throw new JenaException( "no suitable graph constructor found for " + graphClass );
}
catch (RuntimeException e)
@@ -402,15 +401,4 @@ public class GraphTestBase extends JenaT
catch (Exception e)
{ throw new JenaException( e ); }
}
-
- protected static Graph getReificationTriples( final Reifier r )
- {
- return new GraphBase( ReificationStyle.Minimal )
- {
- @Override public ExtendedIterator<Triple> graphBaseFind( TripleMatch m )
- { return r.find( m ); }
- };
- }
-
-
}
Modified: jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/MetaTestGraph.java
URL: http://svn.apache.org/viewvc/jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/MetaTestGraph.java?rev=1430447&r1=1430446&r2=1430447&view=diff
==============================================================================
--- jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/MetaTestGraph.java (original)
+++ jena/branches/streaming-update/jena-core/src/test/java/com/hp/hpl/jena/graph/test/MetaTestGraph.java Tue Jan 8 19:07:23 2013
@@ -31,17 +31,15 @@ import com.hp.hpl.jena.shared.*;
public class MetaTestGraph extends AbstractTestGraph
{
protected final Class<? extends Graph> graphClass;
- protected final ReificationStyle style;
- public MetaTestGraph( Class<? extends Graph> graphClass, String name, ReificationStyle style )
+ public MetaTestGraph( Class<? extends Graph> graphClass, String name)
{
super( name );
this.graphClass = graphClass;
- this.style = style;
}
public MetaTestGraph( String name )
- { super( name ); graphClass = null; style = null; }
+ { super( name ); graphClass = null; }
/**
Construct a suite of tests from the test class <code>testClass</code>
@@ -51,42 +49,40 @@ public class MetaTestGraph extends Abstr
public static TestSuite suite( Class<? extends Test> testClass, Class<? extends Graph> graphClass )
{
TestSuite result = new TestSuite();
- result.addTest( suite( testClass, graphClass, ReificationStyle.Minimal ) );
- result.addTest( suite( testClass, graphClass, ReificationStyle.Standard ) );
- result.addTest( suite( testClass, graphClass, ReificationStyle.Convenient ) );
+ result.addTest( suiteX( testClass, graphClass));
result.setName("Meta "+testClass.getName());
return result;
}
- public static TestSuite suite( Class<? extends Test> testClass, Class<? extends Graph> graphClass, ReificationStyle style )
+ public static TestSuite suiteX( Class<? extends Test> testClass, Class<? extends Graph> graphClass)
{
TestSuite result = new TestSuite();
for (Class<?> c = testClass; Test.class.isAssignableFrom( c ); c = c.getSuperclass())
{
Method [] methods = c.getDeclaredMethods();
- addTestMethods( result, testClass, methods, graphClass, style );
+ addTestMethods( result, testClass, methods, graphClass );
}
- result.setName(testClass.getName()+" "+style.toString());
+ result.setName(testClass.getName());
return result;
}
public static void addTestMethods
- ( TestSuite result, Class<? extends Test> testClass, Method [] methods, Class<? extends Graph> graphClass, ReificationStyle style )
+ ( TestSuite result, Class<? extends Test> testClass, Method [] methods, Class<? extends Graph> graphClass)
{
for (int i = 0; i < methods.length; i += 1)
if (isPublicTestMethod( methods[i] ))
- result.addTest( makeTest( testClass, graphClass, methods[i].getName(), style ) );
+ result.addTest( makeTest( testClass, graphClass, methods[i].getName()) );
}
- public static TestCase makeTest( Class<? extends Test> testClass, Class<? extends Graph> graphClass, String name, ReificationStyle style )
+ public static TestCase makeTest( Class<? extends Test> testClass, Class<? extends Graph> graphClass, String name)
{
- Constructor<?> cons = getConstructor( testClass, new Class[] {Class.class, String.class, ReificationStyle.class} );
+ Constructor<?> cons = getConstructor( testClass, new Class[] {Class.class, String.class} );
if (cons == null) throw new JenaException( "cannot find MetaTestGraph constructor" );
- try { return (TestCase) cons.newInstance( new Object [] {graphClass, name, style} ); }
+ try { return (TestCase) cons.newInstance( new Object [] {graphClass, name} ); }
catch (Exception e) { throw new JenaException( e ); }
}
@Override public Graph getGraph()
- { return getGraph( this, graphClass, style ); }
+ { return getGraph( this, graphClass); }
}