1 6 7 package com.hp.hpl.jena.rdf.model.test; 8 9 import com.hp.hpl.jena.graph.FrontsTriple; 10 import com.hp.hpl.jena.rdf.model.*; 11 import junit.framework.*; 12 import com.hp.hpl.jena.vocabulary.RDF; 13 14 public class TestStatements extends ModelTestBase 15 { 16 public TestStatements( String name ) 17 { super( name ); } 18 19 public static TestSuite suite() 20 { return new TestSuite( TestStatements.class ); } 21 22 29 public void testStuff() 30 { 31 Model red = ModelFactory.createDefaultModel(); 32 Model blue = ModelFactory.createDefaultModel(); 33 Resource r = red.createResource(); 34 Property p = red.createProperty( "" ); 35 Statement s = blue.createStatement( r, p, r ); 36 assertEquals( "subject preserved", r, s.getSubject() ); 37 assertEquals( "object preserved", r, s.getObject() ); 38 } 39 40 public void testOtherStuff() 41 { 42 Model A = ModelFactory.createDefaultModel(); 43 Model B = ModelFactory.createDefaultModel(); 44 Resource S = A.createResource( "jena:S" ); 45 Resource R = A.createResource( "jena:R" ); 46 Property P = A.createProperty( "jena:P" ); 47 RDFNode O = A.createResource( "jena:O" ); 48 A.add( S, P, O ); 49 B.add( S, P, O ); 50 assertTrue( "X1", A.isIsomorphicWith( B ) ); 51 52 A.add( R, RDF.subject, S ); 53 B.add( R, RDF.predicate, P ); 54 assertFalse( "X2", A.isIsomorphicWith( B ) ); 55 56 A.add( R, RDF.predicate, P ); 57 B.add( R, RDF.subject, S ); 58 assertTrue( "X3", A.isIsomorphicWith( B ) ); 59 60 A.add( R, RDF.object, O ); 61 B.add( R, RDF.type, RDF.Statement ); 62 assertFalse( "X4", A.isIsomorphicWith( B ) ); 63 64 A.add( R, RDF.type, RDF.Statement ); 65 B.add( R, RDF.object, O ); 66 assertTrue( "X5", A.isIsomorphicWith( B ) ); 67 } 68 69 public void testSet() 70 { 71 Model A = ModelFactory.createDefaultModel(); 72 Model B = ModelFactory.createDefaultModel(); 73 Resource S = A.createResource( "jena:S" ); 74 Resource R = A.createResource( "jena:R" ); 75 Property P = A.createProperty( "jena:P" ); 76 RDFNode O = A.createResource( "jena:O" ); 77 Statement spo = A.createStatement( S, P, O ); 78 A.add( spo ); 79 Statement sps = A.createStatement( S, P, S ); 80 assertEquals( sps, spo.changeObject( S ) ); 81 assertFalse( A.contains( spo ) ); 82 assertTrue( A.contains( sps ) ); 83 } 84 85 public void testPortingBlankNodes() 86 { 87 Model A = ModelFactory.createDefaultModel(); 88 Model B = ModelFactory.createDefaultModel(); 89 Resource anon = A.createResource(); 90 Resource bAnon = (Resource) anon.inModel( B ); 91 assertTrue( "moved resource should still be blank", bAnon.isAnon() ); 92 assertEquals( "move resource should equal original", anon, bAnon ); 93 } 94 95 public void testTripleWrapper() 96 { 97 Model A = ModelFactory.createDefaultModel(); 98 assertTrue( statement( A, "s p o" ) instanceof FrontsTriple ); 99 } 100 101 105 public void testStatementPrintsType() 106 { 107 Model m = ModelFactory.createDefaultModel(); 108 String fakeURI = "fake:URI"; 109 Resource S = m.createResource( ) ; 110 Property P = property( m, "PP" ); 111 RDFNode O = m.createTypedLiteral( "42", fakeURI); 112 Statement st = m.createStatement( S, P, O ); 113 assertTrue( st.toString().indexOf( fakeURI ) > 0 ); 114 } 115 } 116 117 146 147 148 | Popular Tags |