KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > dig > test > TestRacer


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 11-Sep-2003
9  * Filename $RCSfile: TestRacer.java,v $
10  * Revision $Revision: 1.8 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:16:34 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * [See end of file]
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.reasoner.dig.test;
23
24
25
26 // Imports
27
///////////////
28
import java.util.*;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 import com.hp.hpl.jena.ontology.*;
34 import com.hp.hpl.jena.ontology.OntModelSpec;
35 import com.hp.hpl.jena.rdf.model.ModelFactory;
36 import com.hp.hpl.jena.reasoner.dig.DIGAdapter;
37
38 import junit.framework.*;
39
40
41 /**
42  * <p>
43  * Unit test suite for DIG reasoner interface to Racer - note <b>not</b> part of standard Jena test
44  * suite, since it requires a running Racer reasoner.
45  * </p>
46  *
47  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
48  * @version Release @release@ ($Id: TestRacer.java,v 1.8 2005/02/21 12:16:34 andy_seaborne Exp $)
49  */

50 public class TestRacer
51     extends TestCase
52 {
53     // Constants
54
//////////////////////////////////
55

56     // Static variables
57
//////////////////////////////////
58

59     // Instance variables
60
//////////////////////////////////
61

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

65     // External signature methods
66
//////////////////////////////////
67

68     public void setUp() {
69         // ensure the ont doc manager is in a consistent state
70
OntDocumentManager.getInstance().reset( true );
71     }
72     
73     
74     public void testRacerName() {
75         DIGAdapter r = new DIGAdapter( OntModelSpec.OWL_DL_MEM, ModelFactory.createOntologyModel().getGraph() );
76         assertEquals( "Name should be racer", "Racer", r.getDigIdentifier().getName() );
77     }
78     
79     public void testRacerVersion() {
80         DIGAdapter r = new DIGAdapter( OntModelSpec.OWL_DL_MEM, ModelFactory.createOntologyModel().getGraph() );
81         assertNotNull( "Version should be non-null", r.getDigIdentifier().getVersion() );
82     }
83     
84     public void testRacerMessage() {
85         DIGAdapter r = new DIGAdapter( OntModelSpec.OWL_DL_MEM, ModelFactory.createOntologyModel().getGraph() );
86         assertNotNull( "Message should be non-null", r.getDigIdentifier().getMessage() );
87     }
88     
89     public void testRacerSupportsLanguage() {
90         DIGAdapter r = new DIGAdapter( OntModelSpec.OWL_DL_MEM, ModelFactory.createOntologyModel().getGraph() );
91         iteratorTest( r.getDigIdentifier().supportsLanguage(),
92                       new Object JavaDoc[] {"top", "bottom", "catom", "ratom", "and", "or",
93                                     "not", "some", "all", "atmost", "atleast", "inverse", "feature", "attribute",
94                                     "intmin", "intmax", "intrange", "intequals", "defined", "stringequals"} );
95     }
96     
97     public void testRacerSupportsTell() {
98         DIGAdapter r = new DIGAdapter( OntModelSpec.OWL_DL_MEM, ModelFactory.createOntologyModel().getGraph() );
99         iteratorTest( r.getDigIdentifier().supportsTell(),
100                       new Object JavaDoc[] {"defconcept", "defrole", "deffeature", "defattribute", "defindividual", "impliesc", "equalc",
101                                     "disjoint", "impliesr", "domain", "range", "rangeint", "transitive", "functional",
102                                     "instanceof", "related", "value", "equalr", "rangestring"} );
103     }
104     
105     public void testRacerSupportsAsk() {
106         DIGAdapter r = new DIGAdapter( OntModelSpec.OWL_DL_MEM, ModelFactory.createOntologyModel().getGraph() );
107         iteratorTest( r.getDigIdentifier().supportsAsk(),
108                       new Object JavaDoc[] {"allConceptNames", "allRoleNames", "allIndividuals", "satisfiable", "subsumes",
109                                     "disjoint", "parents", "children", "descendants", "ancestors", "equivalents",
110                                     "rparents", "rchildren", "rancestors", "rdescendants", "instances", "types",
111                                     "instance", "roleFillers", "relatedIndividuals", "toldValues", } );
112     }
113     
114     // Internal implementation methods
115
//////////////////////////////////
116

117     /** Test that an iterator delivers the expected values */
118     protected void iteratorTest( Iterator i, Object JavaDoc[] expected ) {
119         assertNotNull( "Iterator should not be null", i );
120         
121         Log logger = LogFactory.getLog( getClass() );
122         List expList = new ArrayList();
123         for (int j = 0; j < expected.length; j++) {
124             expList.add( expected[j] );
125         }
126         
127         while (i.hasNext()) {
128             Object JavaDoc next = i.next();
129                 
130             // debugging
131
if (!expList.contains( next )) {
132                 logger.debug( getName() + " - Unexpected iterator result: " + next );
133             }
134                 
135             assertTrue( "Value " + next + " was not expected as a result from this iterator ", expList.contains( next ) );
136             assertTrue( "Value " + next + " was not removed from the list ", expList.remove( next ) );
137         }
138         
139         if (!(expList.size() == 0)) {
140             logger.debug( getName() + "Expected iterator results not found" );
141             for (Iterator j = expList.iterator(); j.hasNext(); ) {
142                 logger.debug( getName() + " - missing: " + j.next() );
143             }
144         }
145         assertEquals( "There were expected elements from the iterator that were not found", 0, expList.size() );
146     }
147
148
149     //==============================================================================
150
// Inner class definitions
151
//==============================================================================
152

153 }
154
155
156 /*
157  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
158  * All rights reserved.
159  *
160  * Redistribution and use in source and binary forms, with or without
161  * modification, are permitted provided that the following conditions
162  * are met:
163  * 1. Redistributions of source code must retain the above copyright
164  * notice, this list of conditions and the following disclaimer.
165  * 2. Redistributions in binary form must reproduce the above copyright
166  * notice, this list of conditions and the following disclaimer in the
167  * documentation and/or other materials provided with the distribution.
168  * 3. The name of the author may not be used to endorse or promote products
169  * derived from this software without specific prior written permission.
170  *
171  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
172  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
173  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
174  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
175  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
176  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
177  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
178  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
179  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
180  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
181  */

182
Popular Tags