01: /*
02: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
03: [See end of file]
04: $Id: TestEarlyConstraints.java,v 1.8 2008/01/02 12:08:54 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.graph.query.test;
08:
09: 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: public TestEarlyConstraints(String name) {
25: super (name);
26: }
27:
28: public static TestSuite suite() {
29: return new TestSuite(TestEarlyConstraints.class);
30: }
31:
32: public void testEarlyConstraint() {
33: final int[] count = { 0 };
34: Query q = new Query().addMatch(Query.S, node("eg:p1"), Query.O)
35: .addMatch(Query.X, node("eg:p2"), Query.Y)
36: .addConstraint(notEqual(Query.S, Query.O));
37: Graph gBase = graphWith("a eg:p1 a; c eg:p1 d; x eg:p2 y");
38: Graph g = new WrappedGraph(gBase) {
39: public QueryHandler queryHandler() {
40: return new SimpleQueryHandler(this );
41: }
42:
43: public ExtendedIterator find(Node S, Node P, Node O) {
44: if (P.equals(node("eg:p2")))
45: count[0] += 1;
46: return super .find(S, P, O);
47: }
48:
49: public ExtendedIterator find(TripleMatch tm) {
50: if (tm.getMatchPredicate().equals(node("eg:p2")))
51: count[0] += 1;
52: return super .find(tm);
53: }
54: };
55: Set s = iteratorToSet(q.executeBindings(g,
56: new Node[] { Query.S }).mapWith(getFirst));
57: assertEquals(nodeSet("c"), s);
58: assertEquals(1, count[0]);
59: }
60: }
61:
62: /*
63: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
64: All rights reserved.
65:
66: Redistribution and use in source and binary forms, with or without
67: modification, are permitted provided that the following conditions
68: are met:
69:
70: 1. Redistributions of source code must retain the above copyright
71: notice, this list of conditions and the following disclaimer.
72:
73: 2. Redistributions in binary form must reproduce the above copyright
74: notice, this list of conditions and the following disclaimer in the
75: documentation and/or other materials provided with the distribution.
76:
77: 3. The name of the author may not be used to endorse or promote products
78: derived from this software without specific prior written permission.
79:
80: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
81: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
82: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
83: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
84: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
85: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
86: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
87: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
88: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
89: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90: */
|