001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email Ian.Dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created 23-May-2003
009: * Filename $RCSfile: OntTestBase.java,v $
010: * Revision $Revision: 1.16 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:08:39 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * (see footer for full conditions)
018: *****************************************************************************/package com.hp.hpl.jena.ontology.impl.test;
019:
020: // Imports
021: ///////////////
022: import java.util.*;
023:
024: import com.hp.hpl.jena.ontology.*;
025: import com.hp.hpl.jena.rdf.model.*;
026: import com.hp.hpl.jena.reasoner.test.TestUtil;
027:
028: import junit.framework.*;
029:
030: /**
031: * <p>
032: * Generic test case for ontology unit testing
033: * </p>
034: *
035: * @author Ian Dickinson, HP Labs
036: * (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
037: * @version CVS $Id: OntTestBase.java,v 1.16 2008/01/02 12:08:39 andy_seaborne Exp $
038: */
039: public abstract class OntTestBase extends TestSuite {
040: // Constants
041: //////////////////////////////////
042:
043: public static final String BASE = "http://jena.hpl.hp.com/testing/ontology";
044: public static final String NS = BASE + "#";
045:
046: // Static variables
047: //////////////////////////////////
048:
049: // Instance variables
050: //////////////////////////////////
051:
052: // Constructors
053: //////////////////////////////////
054:
055: public OntTestBase(String name) {
056: super (name);
057: TestCase[] tc = getTests();
058:
059: for (int i = 0; i < tc.length; i++) {
060: addTest(tc[i]);
061: }
062: }
063:
064: // External signature methods
065: //////////////////////////////////
066:
067: // Internal implementation methods
068: //////////////////////////////////
069:
070: /** Return the array of tests for the suite */
071: protected OntTestCase[] getTests() {
072: return null;
073: }
074:
075: //==============================================================================
076: // Inner class definitions
077: //==============================================================================
078:
079: protected abstract class OntTestCase extends TestCase {
080: protected boolean m_inOWL;
081: protected boolean m_inOWLLite;
082: protected boolean m_inDAML;
083: protected boolean m_inRDFS;
084: protected String m_langElement;
085: protected boolean m_owlLang = true;
086: protected boolean m_owlLiteLang = false;
087: protected boolean m_rdfsLang = false;
088: protected boolean m_damlLang = false;
089:
090: public OntTestCase(String langElement, boolean inOWL,
091: boolean inOWLLite, boolean inDAML, boolean inRDFS) {
092: super ("Ontology API test " + langElement);
093: m_langElement = langElement;
094: m_inOWL = inOWL;
095: m_inOWLLite = inOWLLite;
096: m_inDAML = inDAML;
097: m_inRDFS = inRDFS;
098: }
099:
100: public void runTest() throws Exception {
101: // we don't want inferencing for these unit tests
102: runTest(ModelFactory.createOntologyModel(
103: OntModelSpec.OWL_MEM, null), m_inOWL);
104:
105: m_owlLiteLang = true;
106:
107: runTest(ModelFactory.createOntologyModel(
108: OntModelSpec.OWL_LITE_MEM, null), m_inOWLLite);
109:
110: // now DAML
111: m_owlLang = false;
112: m_owlLiteLang = false;
113: m_damlLang = true;
114:
115: runTest(ModelFactory.createOntologyModel(
116: OntModelSpec.DAML_MEM, null), m_inDAML);
117:
118: // now RDFS
119:
120: m_rdfsLang = true;
121: m_damlLang = false;
122: runTest(ModelFactory.createOntologyModel(
123: OntModelSpec.RDFS_MEM, null), m_inRDFS);
124: }
125:
126: protected void runTest(OntModel m, boolean inModel)
127: throws Exception {
128: boolean profileEx = false;
129:
130: try {
131: ontTest(m);
132: } catch (ProfileException e) {
133: profileEx = true;
134: }
135:
136: assertEquals("language element " + m_langElement + " was "
137: + (inModel ? "" : "not") + " expected in model "
138: + m.getProfile().getLabel(), inModel, !profileEx);
139: }
140:
141: /** Does the work in the test sub-class */
142: protected abstract void ontTest(OntModel m) throws Exception;
143:
144: /** Test that an iterator delivers the expected values */
145: protected void iteratorTest(Iterator i, Object[] expected) {
146: TestUtil.assertIteratorValues(this , i, expected);
147: }
148:
149: public void setUp() {
150: // ensure the ont doc manager is in a consistent state
151: OntDocumentManager.getInstance().reset(true);
152: }
153:
154: protected boolean owlFull() {
155: return m_owlLang && !m_owlLiteLang;
156: }
157:
158: /** Answer true if an iterator contains a given value */
159: protected boolean iteratorContains(Iterator i, Object target) {
160: boolean found = false;
161: while (i.hasNext()) {
162: found = i.next().equals(target) || found;
163: }
164: return found;
165: }
166: }
167: }
168:
169: /*
170: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
171: All rights reserved.
172:
173: Redistribution and use in source and binary forms, with or without
174: modification, are permitted provided that the following conditions
175: are met:
176:
177: 1. Redistributions of source code must retain the above copyright
178: notice, this list of conditions and the following disclaimer.
179:
180: 2. Redistributions in binary form must reproduce the above copyright
181: notice, this list of conditions and the following disclaimer in the
182: documentation and/or other materials provided with the distribution.
183:
184: 3. The name of the author may not be used to endorse or promote products
185: derived from this software without specific prior written permission.
186:
187: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
188: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
190: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
192: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
193: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
194: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
195: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
196: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
197: */
|