001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestSimpleSelector.java,v 1.13 2008/01/02 12:04:41 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.test;
008:
009: /**
010: @author bwm out of kers
011: */
012:
013: import com.hp.hpl.jena.rdf.model.*;
014: import com.hp.hpl.jena.vocabulary.*;
015:
016: import junit.framework.*;
017:
018: public class TestSimpleSelector extends TestCase {
019:
020: public TestSimpleSelector(String name) {
021: super (name);
022: }
023:
024: public static TestSuite suite() {
025: return new TestSuite(TestSimpleSelector.class);
026: }
027:
028: Model model = null;
029:
030: protected void setUp() throws java.lang.Exception {
031: model = ModelFactory.createDefaultModel();
032: model.createResource().addProperty(RDF.type, RDFS.Resource)
033: .addProperty(RDFS.label, "foo").addProperty(RDF.value,
034: "123");
035: model.createResource().addProperty(RDF.type, RDFS.Resource)
036: .addProperty(RDFS.label, "bar").addProperty(RDF.value,
037: "123");
038:
039: }
040:
041: protected void tearDown() throws java.lang.Exception {
042: model = null;
043: }
044:
045: /**
046: A plain SimpleSelector must be simple.
047: */
048: public void testSimpleIsSimple() {
049: assertTrue(new SimpleSelector(null, null, (RDFNode) null)
050: .isSimple());
051: }
052:
053: /**
054: A random sub-class of SimpleSelector must not be simple.
055: */
056: public void testSimpleSubclassIsntSimple() {
057: assertFalse(new SimpleSelector(null, null, (RDFNode) null) {
058: }.isSimple());
059: }
060:
061: public void testAll() {
062: StmtIterator iter = model.listStatements(new SimpleSelector(
063: null, null, (RDFNode) null));
064: int i = 0;
065: while (iter.hasNext()) {
066: i++;
067: iter.next();
068: }
069: assertEquals(6, i);
070: }
071:
072: public void testFindProperty() {
073: StmtIterator iter = model.listStatements(new SimpleSelector(
074: null, RDFS.label, (RDFNode) null));
075: int i = 0;
076: while (iter.hasNext()) {
077: i++;
078: Statement stmt = iter.nextStatement();
079: assertEquals(RDFS.label, stmt.getPredicate());
080: }
081: assertEquals(2, i);
082: }
083:
084: public void testFindObject() {
085: StmtIterator iter = model.listStatements(new SimpleSelector(
086: null, null, RDFS.Resource));
087: int i = 0;
088: while (iter.hasNext()) {
089: i++;
090: Statement stmt = iter.nextStatement();
091: assertEquals(RDFS.Resource, stmt.getObject());
092: }
093: assertEquals(2, i);
094: }
095:
096: public void testFindSubject() {
097: StmtIterator iter = model.listStatements(new SimpleSelector(
098: null, null, RDFS.Resource));
099: assertTrue(iter.hasNext());
100: Resource subject = iter.nextStatement().getSubject();
101: iter = model.listStatements(new SimpleSelector(subject, null,
102: (RDFNode) null));
103: int i = 0;
104: while (iter.hasNext()) {
105: i++;
106: Statement stmt = iter.nextStatement();
107: assertEquals(subject, stmt.getSubject());
108: }
109: assertEquals(3, i);
110: }
111:
112: public void testFindPropertyAndObject() {
113: StmtIterator iter = model.listStatements(new SimpleSelector(
114: null, RDF.value, 123));
115: int i = 0;
116: while (iter.hasNext()) {
117: i++;
118: Statement stmt = iter.nextStatement();
119: assertEquals(RDF.value, stmt.getPredicate());
120: assertEquals(123, stmt.getInt());
121: }
122: assertEquals(2, i);
123: }
124:
125: }
126:
127: /*
128: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
129: All rights reserved.
130:
131: Redistribution and use in source and binary forms, with or without
132: modification, are permitted provided that the following conditions
133: are met:
134:
135: 1. Redistributions of source code must retain the above copyright
136: notice, this list of conditions and the following disclaimer.
137:
138: 2. Redistributions in binary form must reproduce the above copyright
139: notice, this list of conditions and the following disclaimer in the
140: documentation and/or other materials provided with the distribution.
141:
142: 3. The name of the author may not be used to endorse or promote products
143: derived from this software without specific prior written permission.
144:
145: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
146: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
147: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
148: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
149: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
150: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
151: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
152: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
153: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
154: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155: */
|