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