KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > query > test > TestEarlyConstraints


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: TestEarlyConstraints.java,v 1.4 2005/02/21 11:52:33 andy_seaborne Exp $
5 */

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 /**
19     TestEarlyConstraints
20
21     @author kers
22 */

23 public class TestEarlyConstraints extends QueryTestBase
24     {
25     public TestEarlyConstraints(String JavaDoc 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 /*
58     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
59     All rights reserved.
60
61     Redistribution and use in source and binary forms, with or without
62     modification, are permitted provided that the following conditions
63     are met:
64
65     1. Redistributions of source code must retain the above copyright
66        notice, this list of conditions and the following disclaimer.
67
68     2. Redistributions in binary form must reproduce the above copyright
69        notice, this list of conditions and the following disclaimer in the
70        documentation and/or other materials provided with the distribution.
71
72     3. The name of the author may not be used to endorse or promote products
73        derived from this software without specific prior written permission.
74
75     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
76     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
77     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
78     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
79     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
80     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
81     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
82     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
83     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
84     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85 */
Popular Tags