KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3     [see end of file]
4     $Id: TestStatements.java,v 1.13 2005/02/21 12:15:18 andy_seaborne Exp $
5 */

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 JavaDoc name )
17         { super( name ); }
18     
19     public static TestSuite suite()
20         { return new TestSuite( TestStatements.class ); }
21         
22     /**
23         this case came up when Chris was sorting out ReifedStatement and
24         had mishacked Model.createStatement. A resource created in one
25         model and incorporated into a statement asserted constructed by a
26         different model should test equal to the resource extracted from that
27         statement, even if it's a bnode.
28     */

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     /**
102         Feeble test that toString'ing a Statement[Impl] will display the data-type
103         of its object if it has one.
104     */

105     public void testStatementPrintsType()
106         {
107         Model m = ModelFactory.createDefaultModel();
108         String JavaDoc 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 /*
118     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
119     All rights reserved.
120
121     Redistribution and use in source and binary forms, with or without
122     modification, are permitted provided that the following conditions
123     are met:
124
125     1. Redistributions of source code must retain the above copyright
126        notice, this list of conditions and the following disclaimer.
127
128     2. Redistributions in binary form must reproduce the above copyright
129        notice, this list of conditions and the following disclaimer in the
130        documentation and/or other materials provided with the distribution.
131
132     3. The name of the author may not be used to endorse or promote products
133        derived from this software without specific prior written permission.
134
135     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
136     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
137     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
138     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
139     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
140     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
144     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 */

146
147
148
Popular Tags