📄 abstracttestgraph.java
字号:
Graph g = getAndRegister( L );
Graph triples = graphWith( "this type graph; I type slowly" );
g.getBulkUpdateHandler().add( 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 );
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();
L.assertHas( new Object[] { "someEvent", g, GraphEvents.removeAll } );
}
public void testRemoveSomeEvent()
{
Graph g = getAndRegister( L );
Node S = node( "S" ), P = node( "?P" ), O = node( "??" );
g.getBulkUpdateHandler().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
* at present to avoid problems with InfGraphs which try to prevent
* 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" ) ) );
}
public void testSubjectsFor()
{
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 bis = iteratorToSet( SimpleQueryHandler.subjectsFor( g, p, o ) );
Set qhs = iteratorToSet( g.queryHandler().subjectsFor( p, o ) );
assertEquals( bis, qhs );
}
public void testListSubjectsNoRemove()
{
Graph g = getGraphWith( "a P b; b Q c; c R a" );
Iterator it = g.queryHandler().subjectsFor( 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()
{
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 bis = iteratorToSet( SimpleQueryHandler.objectsFor( g, s, p ) );
Set qhs = iteratorToSet( g.queryHandler().objectsFor( s, p ) );
assertEquals( bis, qhs );
}
public void testListObjectsNoRemove()
{
Graph g = getGraphWith( "a P b; b Q c; c R a" );
Iterator it = g.queryHandler().objectsFor( 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 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 bis = iteratorToSet( SimpleQueryHandler.predicatesFor( g, s, o ) );
Set qhs = iteratorToSet( g.queryHandler().predicatesFor( s, o ) );
assertEquals( bis, qhs );
}
public void testListPredicatesNoRemove()
{
Graph g = getGraphWith( "a P b; b Q c; c R a" );
Iterator it = g.queryHandler().predicatesFor( 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();
assertTrue( g.isEmpty() );
}
/**
Test cases for RemoveSPO(); each entry is a triple (add, remove, result).
<ul>
<li>add - the triples to add to the graph to start with
<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" },
};
/**
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() );
Graph finalContent = remove( copy( content ), baseContent );
assertIsomorphic( cases[i][1], expected, finalContent );
}
}
protected void add( Graph toUpdate, Graph toAdd )
{
toUpdate.getBulkUpdateHandler().add( toAdd );
}
protected Graph remove( Graph toUpdate, Graph toRemove )
{
toUpdate.getBulkUpdateHandler().delete( toRemove );
return toUpdate;
}
protected Graph copy( Graph g )
{
Graph result = Factory.createDefaultGraph();
result.getBulkUpdateHandler().add( 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 */ }
// }
}
/*
(c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -