KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > test > OWLUnitTest


1 /******************************************************************
2  * File: OWLUnitTest.java
3  * Created by: Dave Reynolds
4  * Created on: 19-Mar-2004
5  *
6  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
7  * [See end of file]
8  * $Id: OWLUnitTest.java,v 1.10 2005/04/11 11:27:04 der Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.test;
11
12 import com.hp.hpl.jena.rdf.model.ResourceFactory;
13 import com.hp.hpl.jena.reasoner.*;
14 import com.hp.hpl.jena.reasoner.rulesys.*;
15 import com.hp.hpl.jena.reasoner.rulesys.test.OWLWGTester;
16
17 import junit.framework.TestCase;
18 import junit.framework.TestSuite;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * Version of the OWL unit tests used during development of the mini ruleset.
24  *
25  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
26  * @version $Revision: 1.10 $ on $Date: 2005/04/11 11:27:04 $
27  */

28 public class OWLUnitTest extends TestCase {
29     
30 // -------------- statics defining the whole test suite ---------------------
31

32     /** The set of reasoner(factories) to test */
33     public static ReasonerFactory[] reasonerFactories = {
34         OWLFBRuleReasonerFactory.theInstance(),
35         OWLMicroReasonerFactory.theInstance(),
36         OWLMiniReasonerFactory.theInstance()
37     };
38     
39     /** The names of the reasoner(factories) to report in the test suite */
40     public static final String JavaDoc[] reasonerNames = { "full", "Micro", "Mini" };
41     
42     /** bit flag to indicate the test should be passed by the default reasoner */
43     public static final int FB = 1;
44
45     /** bit flag to indicate the test should be passed by the mini reasoner */
46     public static final int MINI = 2;
47
48     /** bit flag to indicate the test should be passed by the micro reasoner */
49     public static final int MICRO = 4;
50     
51     // Flags from OWLConsistencyTest, copied here for brevity
52
public static final int INCONSISTENT = OWLConsistencyTest.INCONSISTENT;
53     public static final int WARNINGS = OWLConsistencyTest.WARNINGS;
54     public static final int CLEAN = OWLConsistencyTest.CLEAN;
55
56     /** The set of test cases to be used */
57     public static TestDef[] testDefs = {
58         // /*
59
// subClass
60
new TestDef("localtests/ManifestSubclass001.rdf", FB | MICRO | MINI),
61         
62         // equivalentClass
63
new TestDef("equivalentClass/Manifest001.rdf", FB | MICRO | MINI),
64         new TestDef("equivalentClass/Manifest002.rdf", FB | MICRO | MINI),
65         new TestDef("equivalentClass/Manifest003.rdf", FB | MICRO | MINI),
66         new TestDef("equivalentClass/Manifest004.rdf", FB | MINI), // Requires prototypes
67
new TestDef("equivalentClass/Manifest005.rdf", FB | MICRO | MINI),
68         new TestDef("localtests/ManifestRestriction001.rdf", FB | MICRO | MINI),
69
70         // intersectionOf
71
new TestDef("intersectionOf/Manifest001.rdf", FB | MICRO | MINI),
72         new TestDef("localtests/Manifest001.rdf", FB | MICRO | MINI),
73         new TestDef("localtests/Manifest002.rdf", FB | MICRO | MINI),
74
75         // unionOf
76
new TestDef("unionOf/Manifest001.rdf", FB | MICRO | MINI ),
77         
78         // This could be supported but isn't at the moment
79
// new TestDef("unionOf/Manifest002.rdf", FB | MICRO | MINI),
80

81         // Property axioms
82
new TestDef("SymmetricProperty/Manifest001.rdf", FB | MICRO | MINI),
83         new TestDef("SymmetricProperty/Manifest001.rdf", FB | MICRO | MINI),
84         new TestDef("inverseOf/Manifest001.rdf", FB | MICRO | MINI),
85         new TestDef("TransitiveProperty/Manifest001.rdf", FB | MICRO | MINI),
86         new TestDef("localtests/Manifest005.rdf", FB | MICRO | MINI),
87         
88         // Equality related
89
new TestDef("FunctionalProperty/Manifest001.rdf", FB | MINI),
90         new TestDef("FunctionalProperty/Manifest002.rdf", FB | MINI),
91         new TestDef("FunctionalProperty/Manifest003.rdf", FB | MICRO | MINI),
92         new TestDef("InverseFunctionalProperty/Manifest001.rdf", FB | MINI),
93         new TestDef("InverseFunctionalProperty/Manifest002.rdf", FB | MINI),
94         new TestDef("InverseFunctionalProperty/Manifest003.rdf", FB | MICRO | MINI),
95         new TestDef("I5.1/Manifest001.rdf", FB | MINI),
96         
97         new TestDef("rdf-charmod-uris/Manifest.rdf", FB | MICRO | MINI),
98         new TestDef("I4.6/Manifest003.rdf", FB | MICRO | MINI),
99         new TestDef("I5.5/Manifest001.rdf", FB | MICRO | MINI),
100         new TestDef("I5.5/Manifest002.rdf", FB | MICRO | MINI),
101         new TestDef("I5.5/Manifest003.rdf", FB | MICRO | MINI),
102         new TestDef("I5.5/Manifest004.rdf", FB | MICRO | MINI),
103         new TestDef("inverseOf/Manifest001.rdf", FB | MICRO | MINI),
104         new TestDef("TransitiveProperty/Manifest001.rdf", FB | MICRO | MINI),
105         new TestDef("equivalentProperty/Manifest001.rdf", FB | MICRO | MINI),
106         new TestDef("equivalentProperty/Manifest002.rdf", FB | MICRO | MINI),
107         new TestDef("equivalentProperty/Manifest003.rdf", FB | MICRO | MINI),
108         new TestDef("I5.24/Manifest001.rdf", FB | MICRO | MINI),
109         new TestDef("I5.24/Manifest002-mod.rdf", FB | MICRO | MINI),
110         new TestDef("equivalentProperty/Manifest006.rdf", FB | MICRO | MINI),
111
112         // owl:Nothing
113
new TestDef("I5.2/Manifest002.rdf", FB | MINI),
114         
115         // Disjointness tests
116
new TestDef("differentFrom/Manifest001.rdf", FB | MICRO | MINI),
117         new TestDef("disjointWith/Manifest001.rdf", FB | MICRO | MINI),
118         new TestDef("disjointWith/Manifest002.rdf", FB | MICRO | MINI),
119         new TestDef("AllDifferent/Manifest001.rdf", FB | MICRO | MINI),
120
121         // Restriction tests
122
new TestDef("allValuesFrom/Manifest001.rdf", FB | MINI), // Want to move this into MICRO
123
new TestDef("allValuesFrom/Manifest002.rdf", FB | MICRO | MINI),
124         new TestDef("someValuesFrom/Manifest002.rdf", FB | MICRO | MINI),
125         new TestDef("maxCardinality/Manifest001.rdf", FB | MICRO | MINI),
126         new TestDef("maxCardinality/Manifest002.rdf", FB | MICRO | MINI),
127         new TestDef("FunctionalProperty/Manifest005-mod.rdf", FB | MICRO | MINI),
128         new TestDef("I5.24/Manifest004-mod.rdf", FB | MINI),
129         new TestDef("cardinality/Manifest001-mod.rdf", FB | MINI),
130         new TestDef("cardinality/Manifest002-mod.rdf", FB | MINI),
131         new TestDef("cardinality/Manifest003-mod.rdf", FB | MINI),
132         new TestDef("cardinality/Manifest004-mod.rdf", FB | MINI),
133         new TestDef("I5.24/Manifest003-mod.rdf", FB | MICRO | MINI),
134         new TestDef("cardinality/Manifest005-mod.rdf", FB | MINI),
135         new TestDef("cardinality/Manifest006-mod.rdf", FB | MINI),
136         
137         // Needs bNode creation rule
138
new TestDef("someValuesFrom/Manifest001.rdf", FB ),
139     
140          // New local tests
141
new TestDef("localtests/Manifest003.rdf", FB | MICRO | MINI),
142         new TestDef("localtests/Manifest004.rdf", FB | MINI), // Requires equality
143
new TestDef("localtests/Manifest006.rdf", FB ), // a oneOF case
144

145         // Inheritance of domain/range by subProperties
146
new TestDef("localtests/Manifest007.rdf", FB | MICRO | MINI),
147
148         // Consistency tests
149
// clean case
150
new TestDef(new OWLConsistencyTest("tbox.owl", "consistentData.rdf", CLEAN, null), FB | MICRO | MINI),
151         // Instance of disjoint classes
152
new TestDef(new OWLConsistencyTest("tbox.owl", "inconsistent1.rdf", INCONSISTENT,
153                 ResourceFactory.createResource("http://jena.hpl.hp.com/testing/reasoners/owl#ia")), FB | MICRO | MINI),
154         // Type violation
155
new TestDef(new OWLConsistencyTest("tbox.owl", "inconsistent2.rdf", INCONSISTENT, null), FB | MICRO | MINI),
156         // Count violation
157
new TestDef(new OWLConsistencyTest("tbox.owl", "inconsistent3.rdf", INCONSISTENT, null), FB | MINI),
158         // Distinct values for functional property
159
new TestDef(new OWLConsistencyTest("tbox.owl", "inconsistent4.rdf", INCONSISTENT, null), FB | MINI),
160         // Distinct literal values for functional property
161
new TestDef(new OWLConsistencyTest("tbox.owl", "inconsistent6.rdf", INCONSISTENT, null), FB | MINI),
162         // Type clash - allValuesFrom rdfs:Literal
163
new TestDef(new OWLConsistencyTest("tbox.owl", "inconsistent5.rdf", INCONSISTENT, null), FB | MICRO | MINI),
164         // Intersection of disjoint classes
165
new TestDef(new OWLConsistencyTest("tbox.owl", "emptyClass1.rdf", WARNINGS, null), FB | MICRO | MINI),
166         // Equivalent to Nothing
167
new TestDef(new OWLConsistencyTest("tbox.owl", "emptyClass2.rdf", WARNINGS, null), FB | MICRO | MINI),
168         // disjoint with Thing
169
new TestDef(new OWLConsistencyTest("tbox.owl", "emptyClass3.rdf", WARNINGS, null), FB | MICRO | MINI),
170     };
171
172 // -------------- instance variables for a single test ----------------------
173

174     /** The name of the manifest file to test */
175     protected String JavaDoc manifest;
176     
177     /** The reasoner factory under test */
178     protected ReasonerFactory reasonerFactory;
179     
180     /**
181      * Boilerplate for junit
182      */

183     public OWLUnitTest( String JavaDoc manifest, String JavaDoc rName, ReasonerFactory rf) {
184         super( rName + ":" + manifest );
185         this.manifest = manifest;
186         this.reasonerFactory = rf;
187     }
188     
189     /**
190      * Boilerplate for junit.
191      * This is its own test suite
192      */

193     public static TestSuite suite() {
194         TestSuite suite = new TestSuite();
195         for (int i = 0; i < reasonerFactories.length; i++) {
196             String JavaDoc rName = reasonerNames[i];
197             ReasonerFactory rf = reasonerFactories[i];
198             for (int j = 0; j < testDefs.length; j++) {
199                 TestDef test = testDefs[j];
200                 if (test.applicableTo(rf)) {
201                     if (test.spec instanceof String JavaDoc) {
202                         suite.addTest(new OWLUnitTest((String JavaDoc)test.spec, rName, rf));
203                     } else if (test.spec instanceof OWLConsistencyTest) {
204                         OWLConsistencyTest oct = (OWLConsistencyTest)test.spec;
205                         suite.addTest(new OWLConsistencyTest(oct, rName, rf));
206                     }
207                 }
208             }
209         }
210         return suite;
211     }
212     
213     /**
214      * The test runner
215      */

216     protected void runTest() throws IOException JavaDoc {
217 // System.out.println(" - " + manifest + " using " + reasonerFactory.getURI());
218
OWLWGTester tester = new OWLWGTester(reasonerFactory, this, null);
219         tester.runTests(manifest, false, false);
220     }
221     
222     /**
223      * Inner class - use to represent a single test case and which reasoners
224      * it is relevant to.
225      */

226     static class TestDef {
227         /** Test spec, could be a the relative URI for a manifest, or a consistecy test object */
228         public Object JavaDoc spec;
229         
230         /** Bitmap of the reasoners this test is relevant to */
231         public int validFor;
232          
233         /** Constructor */
234         public TestDef(Object JavaDoc spec, int validFor) {
235             this.spec = spec;
236             this.validFor = validFor;
237         }
238         
239         /** Return the bitflag corresponding to the given reasoner factory */
240         public int flagFor(ReasonerFactory rf) {
241             if (rf.equals(OWLFBRuleReasonerFactory.theInstance())) {
242                 return FB;
243             } else if (rf.equals(OWLMiniReasonerFactory.theInstance())) {
244                 return MINI;
245             } else if (rf.equals(OWLMicroReasonerFactory.theInstance())) {
246                 return MICRO;
247             } else {
248                 throw new ReasonerException("Unrecognized OWL reasoner config in unit test");
249             }
250         }
251         
252         /** Return true if the test is relevant to this reasoner factory */
253         public boolean applicableTo(ReasonerFactory rf) {
254             return (validFor & flagFor(rf)) != 0;
255         }
256     }
257     
258 }
259
260
261 /*
262     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
263     All rights reserved.
264
265     Redistribution and use in source and binary forms, with or without
266     modification, are permitted provided that the following conditions
267     are met:
268
269     1. Redistributions of source code must retain the above copyright
270        notice, this list of conditions and the following disclaimer.
271
272     2. Redistributions in binary form must reproduce the above copyright
273        notice, this list of conditions and the following disclaimer in the
274        documentation and/or other materials provided with the distribution.
275
276     3. The name of the author may not be used to endorse or promote products
277        derived from this software without specific prior written permission.
278
279     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
280     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
281     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
282     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
283     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
284     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
286     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
287     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
288     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
289 */
Popular Tags