1 6 7 package com.hp.hpl.jena.graph.query.test; 8 9 import java.util.*; 10 11 import junit.framework.*; 12 13 import com.hp.hpl.jena.graph.*; 14 import com.hp.hpl.jena.graph.impl.*; 15 import com.hp.hpl.jena.graph.query.*; 16 import com.hp.hpl.jena.util.iterator.*; 17 18 23 public class TestEarlyConstraints extends QueryTestBase 24 { 25 public TestEarlyConstraints(String name) 26 { super( name ); } 27 28 public static TestSuite suite() 29 { return new TestSuite( TestEarlyConstraints.class ); } 30 31 public void testEarlyConstraint() 32 { 33 final int [] count = {0}; 34 Query q = new Query() 35 .addMatch( Query.S, node( "eg:p1" ), Query.O ) 36 .addMatch( Query.X, node( "eg:p2" ), Query.Y ) 37 .addConstraint( notEqual( Query.S, Query.O ) ) 38 ; 39 Graph gBase = graphWith( "a eg:p1 a; c eg:p1 d; x eg:p2 y" ); 40 Graph g = new WrappedGraph( gBase ) 41 { 42 public QueryHandler queryHandler() 43 { return new SimpleQueryHandler( this ); } 44 45 public ExtendedIterator find( TripleMatch tm ) 46 { 47 if (tm.getMatchPredicate().equals( node( "eg:p2" ) )) count[0] += 1; 48 return super.find( tm ); 49 } 50 }; 51 Set s = iteratorToSet( q.executeBindings( g, new Node[] {Query.S} ) .mapWith ( getFirst ) ); 52 assertEquals( nodeSet( "c" ), s ); 53 assertEquals( 1, count[0] ); 54 } 55 } 56 57 | Popular Tags |