1 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 16 public class TestContains extends ModelTestBase 17 { 18 public TestContains( String name ) 19 { super( name ); } 20 21 public static TestSuite suite() 22 { return new TestSuite( TestContains.class ); } 23 24 public void testContains( boolean yes, String facts, String 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 uri ) 51 { return ResourceFactory.createResource( "eh:/" + uri ); } 52 53 private Property prop( String 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 facts, Resource S, Property P, RDFNode O ) 67 { assertEquals( yes, modelWithStatements( facts ).contains( S, P, O ) ); } 68 } 69 70 71 | Popular Tags |