KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > test > TestContains


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestContains.java,v 1.9 2005/03/14 16:01:53 chris-dollin Exp $
5 */

6
7 package com.hp.hpl.jena.rdf.model.test;
8
9 import com.hp.hpl.jena.rdf.model.*;
10
11 import junit.framework.*;
12
13 /**
14     @author kers
15 */

16 public class TestContains extends ModelTestBase
17     {
18     public TestContains( String JavaDoc name )
19         { super( name ); }
20     
21     public static TestSuite suite()
22         { return new TestSuite( TestContains.class ); }
23         
24     public void testContains( boolean yes, String JavaDoc facts, String JavaDoc resource )
25         {
26         Model m = modelWithStatements( facts );
27         RDFNode r = rdfNode( m, resource );
28         if (modelWithStatements( facts ).containsResource( r ) != yes)
29             fail( "[" + facts + "] should" + (yes ? "" : " not") + " contain " + resource );
30         }
31         
32     public void testContains()
33         {
34         testContains( false, "", "x" );
35         testContains( false, "a R b", "x" );
36         testContains( false, "a R b; c P d", "x" );
37     /* */
38         testContains( false, "a R b", "z" );
39     /* */
40         testContains( true, "x R y", "x" );
41         testContains( true, "a P b", "P" );
42         testContains( true, "i Q j", "j" );
43         testContains( true, "x R y; a P b; i Q j", "y" );
44     /* */
45         testContains( true, "x R y; a P b; i Q j", "y" );
46         testContains( true, "x R y; a P b; i Q j", "R" );
47         testContains( true, "x R y; a P b; i Q j", "a" );
48         }
49     
50     private Resource res( String JavaDoc uri )
51         { return ResourceFactory.createResource( "eh:/" + uri ); }
52     
53     private Property prop( String JavaDoc uri )
54         { return ResourceFactory.createProperty( "eh:/" + uri ); }
55         
56     public void testContainsWithNull()
57         {
58         testCWN( false, "", null, null, null );
59         testCWN( true, "x R y", null, null, null );
60         testCWN( false, "x R y", null, null, res( "z" ) );
61         testCWN( true, "x RR y", res( "x" ), prop( "RR" ), null );
62         testCWN( true, "a BB c", null, prop( "BB" ), res( "c" ) );
63         testCWN( false, "a BB c", null, prop( "ZZ" ), res( "c" ) );
64         }
65     
66     public void testCWN( boolean yes, String JavaDoc facts, Resource S, Property P, RDFNode O )
67         { assertEquals( yes, modelWithStatements( facts ).contains( S, P, O ) ); }
68     }
69
70
71 /*
72     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
73     All rights reserved.
74
75     Redistribution and use in source and binary forms, with or without
76     modification, are permitted provided that the following conditions
77     are met:
78
79     1. Redistributions of source code must retain the above copyright
80        notice, this list of conditions and the following disclaimer.
81
82     2. Redistributions in binary form must reproduce the above copyright
83        notice, this list of conditions and the following disclaimer in the
84        documentation and/or other materials provided with the distribution.
85
86     3. The name of the author may not be used to endorse or promote products
87        derived from this software without specific prior written permission.
88
89     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
90     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
91     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
92     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
93     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
94     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
95     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
96     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
97     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
98     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
99 */
Popular Tags