KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > impl > test > OntTestBase


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created 23-May-2003
9  * Filename $RCSfile: OntTestBase.java,v $
10  * Revision $Revision: 1.12 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:07:12 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * (see footer for full conditions)
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.ontology.impl.test;
23
24
25 // Imports
26
///////////////
27
import java.util.*;
28
29 import com.hp.hpl.jena.ontology.*;
30 import com.hp.hpl.jena.rdf.model.*;
31 import com.hp.hpl.jena.reasoner.test.TestUtil;
32
33 import junit.framework.*;
34
35
36 /**
37  * <p>
38  * Generic test case for ontology unit testing
39  * </p>
40  *
41  * @author Ian Dickinson, HP Labs
42  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
43  * @version CVS $Id: OntTestBase.java,v 1.12 2005/02/21 12:07:12 andy_seaborne Exp $
44  */

45 public abstract class OntTestBase
46     extends TestSuite
47 {
48     // Constants
49
//////////////////////////////////
50

51     public static final String JavaDoc BASE = "http://jena.hpl.hp.com/testing/ontology";
52     public static final String JavaDoc NS = BASE + "#";
53     
54     
55     // Static variables
56
//////////////////////////////////
57

58     // Instance variables
59
//////////////////////////////////
60

61     
62     // Constructors
63
//////////////////////////////////
64

65     public OntTestBase( String JavaDoc name ) {
66         super( name );
67         TestCase[] tc = getTests();
68         
69         for (int i = 0; i < tc.length; i++) {
70             addTest( tc[i] );
71         }
72     }
73     
74     // External signature methods
75
//////////////////////////////////
76

77
78     // Internal implementation methods
79
//////////////////////////////////
80

81     /** Return the array of tests for the suite */
82     protected OntTestCase[] getTests() {
83         return null;
84     }
85     
86     
87     //==============================================================================
88
// Inner class definitions
89
//==============================================================================
90

91     protected abstract class OntTestCase
92         extends TestCase
93     {
94         protected boolean m_inOWL;
95         protected boolean m_inOWLLite;
96         protected boolean m_inDAML;
97         protected boolean m_inRDFS;
98         protected String JavaDoc m_langElement;
99         protected boolean m_owlLang = true;
100         protected boolean m_owlLiteLang = false;
101         protected boolean m_rdfsLang = false;
102         protected boolean m_damlLang = false;
103
104         public OntTestCase( String JavaDoc langElement, boolean inOWL, boolean inOWLLite, boolean inDAML, boolean inRDFS ) {
105             super( "Ontology API test " + langElement );
106             m_langElement = langElement;
107             m_inOWL = inOWL;
108             m_inOWLLite = inOWLLite;
109             m_inDAML = inDAML;
110             m_inRDFS = inRDFS;
111         }
112
113         public void runTest()
114             throws Exception JavaDoc
115         {
116             // we don't want inferencing for these unit tests
117
runTest( ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null ), m_inOWL );
118             
119             m_owlLiteLang = true;
120             
121             runTest( ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM, null ), m_inOWLLite );
122             
123             // now DAML
124
m_owlLang = false;
125             m_owlLiteLang = false;
126             m_damlLang = true;
127             
128             runTest( ModelFactory.createOntologyModel( OntModelSpec.DAML_MEM, null ), m_inDAML );
129             
130             // now RDFS
131

132             m_rdfsLang = true;
133             m_damlLang = false;
134             runTest( ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM, null ), m_inRDFS);
135         }
136     
137         protected void runTest( OntModel m, boolean inModel )
138             throws Exception JavaDoc
139         {
140             boolean profileEx = false;
141         
142             try {
143                 ontTest( m );
144             }
145             catch (ProfileException e) {
146                 profileEx = true;
147             }
148         
149             assertEquals( "language element " + m_langElement + " was " + (inModel ? "" : "not") + " expected in model " + m.getProfile().getLabel(), inModel, !profileEx );
150         }
151     
152         /** Does the work in the test sub-class */
153         protected abstract void ontTest( OntModel m ) throws Exception JavaDoc;
154     
155         /** Test that an iterator delivers the expected values */
156         protected void iteratorTest( Iterator i, Object JavaDoc[] expected ) {
157             TestUtil.assertIteratorValues( this, i, expected );
158         }
159     
160         public void setUp() {
161             // ensure the ont doc manager is in a consistent state
162
OntDocumentManager.getInstance().reset( true );
163         }
164         
165         protected boolean owlFull() {
166             return m_owlLang && !m_owlLiteLang;
167         }
168         
169     }
170 }
171
172
173 /*
174     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
175     All rights reserved.
176
177     Redistribution and use in source and binary forms, with or without
178     modification, are permitted provided that the following conditions
179     are met:
180
181     1. Redistributions of source code must retain the above copyright
182        notice, this list of conditions and the following disclaimer.
183
184     2. Redistributions in binary form must reproduce the above copyright
185        notice, this list of conditions and the following disclaimer in the
186        documentation and/or other materials provided with the distribution.
187
188     3. The name of the author may not be used to endorse or promote products
189        derived from this software without specific prior written permission.
190
191     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
192     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
194     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
195     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
196     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
197     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
198     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
199     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
200     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
201 */

202
203
Popular Tags