KickJava   Java API By Example, From Geeks To Geeks.

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


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

6
7 package com.hp.hpl.jena.rdf.model.test;
8
9 /**
10     @author bwm out of kers
11 */

12
13 import com.hp.hpl.jena.rdf.model.*;
14 import com.hp.hpl.jena.vocabulary.*;
15
16 import junit.framework.*;
17
18 public class TestSimpleSelector extends TestCase
19     {
20         
21     public TestSimpleSelector( String JavaDoc name )
22         { super( name ); }
23     
24     public static TestSuite suite()
25         { return new TestSuite( TestSimpleSelector.class ); }
26     
27     Model model = null;
28         
29     protected void setUp() throws java.lang.Exception JavaDoc {
30         model = ModelFactory.createDefaultModel();
31         model.createResource()
32              .addProperty(RDF.type, RDFS.Resource)
33              .addProperty(RDFS.label, "foo")
34              .addProperty(RDF.value, "123");
35         model.createResource()
36              .addProperty(RDF.type, RDFS.Resource)
37              .addProperty(RDFS.label, "bar")
38              .addProperty(RDF.value, "123");
39         
40     }
41     
42     protected void tearDown() throws java.lang.Exception JavaDoc {
43         model = null;
44     }
45     
46     /**
47         A plain SimpleSelector must be simple.
48     */

49     public void testSimpleIsSimple()
50         { assertTrue( new SimpleSelector( null, null, (RDFNode) null ).isSimple() ); }
51         
52     /**
53         A random sub-class of SimpleSelector must not be simple.
54     */

55     public void testSimpleSubclassIsntSimple()
56         { assertFalse( new SimpleSelector( null, null, (RDFNode) null ){}.isSimple() ); }
57         
58     public void testAll() {
59         StmtIterator iter = model.listStatements(
60           new SimpleSelector(null, null, (RDFNode) null));
61         int i =0;
62         while (iter.hasNext()) {
63             i++;
64             iter.next();
65         }
66         assertEquals(6, i);
67     }
68     
69     public void testFindProperty() {
70         StmtIterator iter = model.listStatements(
71           new SimpleSelector(null, RDFS.label, (RDFNode) null));
72         int i =0;
73         while (iter.hasNext()) {
74             i++;
75             Statement stmt = iter.nextStatement();
76             assertEquals(RDFS.label, stmt.getPredicate());
77         }
78         assertEquals(2, i);
79     }
80     
81     public void testFindObject() {
82         StmtIterator iter = model.listStatements(
83           new SimpleSelector(null, null, RDFS.Resource));
84         int i =0;
85         while (iter.hasNext()) {
86             i++;
87             Statement stmt = iter.nextStatement();
88             assertEquals(RDFS.Resource, stmt.getObject());
89         }
90         assertEquals(2, i);
91     }
92     
93     public void testFindSubject() {
94         StmtIterator iter = model.listStatements(
95           new SimpleSelector(null, null, RDFS.Resource));
96         assertTrue(iter.hasNext());
97         Resource subject = iter.nextStatement()
98                                .getSubject();
99         iter = model.listStatements(
100           new SimpleSelector(subject, null, (RDFNode) null));
101         int i =0;
102         while (iter.hasNext()) {
103             i++;
104             Statement stmt = iter.nextStatement();
105             assertEquals(subject, stmt.getSubject());
106         }
107         assertEquals(3, i);
108     }
109     
110     public void testFindPropertyAndObject() {
111         StmtIterator iter = model.listStatements(
112           new SimpleSelector(null, RDF.value, 123));
113         int i =0;
114         while (iter.hasNext()) {
115             i++;
116             Statement stmt = iter.nextStatement();
117             assertEquals(RDF.value, stmt.getPredicate());
118             assertEquals(123, stmt.getInt());
119         }
120         assertEquals(2, i);
121     }
122     
123 }
124         
125
126 /*
127     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
128     All rights reserved.
129
130     Redistribution and use in source and binary forms, with or without
131     modification, are permitted provided that the following conditions
132     are met:
133
134     1. Redistributions of source code must retain the above copyright
135        notice, this list of conditions and the following disclaimer.
136
137     2. Redistributions in binary form must reproduce the above copyright
138        notice, this list of conditions and the following disclaimer in the
139        documentation and/or other materials provided with the distribution.
140
141     3. The name of the author may not be used to endorse or promote products
142        derived from this software without specific prior written permission.
143
144     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
145     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
146     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
147     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
148     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
149     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
150     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
151     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
152     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
153     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
154 */

155
Popular Tags