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 11-Sep-2003
009: * Filename $RCSfile: TestRacer.java,v $
010: * Revision $Revision: 1.11 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:10:28 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: *****************************************************************************/package com.hp.hpl.jena.reasoner.dig.test;
019:
020: // Imports
021: ///////////////
022: import java.util.*;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026:
027: import com.hp.hpl.jena.ontology.*;
028: import com.hp.hpl.jena.ontology.OntModelSpec;
029: import com.hp.hpl.jena.rdf.model.ModelFactory;
030: import com.hp.hpl.jena.reasoner.dig.DIGAdapter;
031:
032: import junit.framework.*;
033:
034: /**
035: * <p>
036: * Unit test suite for DIG reasoner interface to Racer - note <b>not</b> part of standard Jena test
037: * suite, since it requires a running Racer reasoner.
038: * </p>
039: *
040: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
041: * @version Release @release@ ($Id: TestRacer.java,v 1.11 2008/01/02 12:10:28 andy_seaborne Exp $)
042: */
043: public class TestRacer extends TestCase {
044: // Constants
045: //////////////////////////////////
046:
047: // Static variables
048: //////////////////////////////////
049:
050: // Instance variables
051: //////////////////////////////////
052:
053: // Constructors
054: //////////////////////////////////
055:
056: // External signature methods
057: //////////////////////////////////
058:
059: public void setUp() {
060: // ensure the ont doc manager is in a consistent state
061: OntDocumentManager.getInstance().reset(true);
062: }
063:
064: public void testRacerName() {
065: DIGAdapter r = new DIGAdapter(OntModelSpec.OWL_DL_MEM,
066: ModelFactory.createOntologyModel().getGraph());
067: assertEquals("Name should be racer", "Racer", r
068: .getDigIdentifier().getName());
069: }
070:
071: public void testRacerVersion() {
072: DIGAdapter r = new DIGAdapter(OntModelSpec.OWL_DL_MEM,
073: ModelFactory.createOntologyModel().getGraph());
074: assertNotNull("Version should be non-null", r
075: .getDigIdentifier().getVersion());
076: }
077:
078: public void testRacerMessage() {
079: DIGAdapter r = new DIGAdapter(OntModelSpec.OWL_DL_MEM,
080: ModelFactory.createOntologyModel().getGraph());
081: assertNotNull("Message should be non-null", r
082: .getDigIdentifier().getMessage());
083: }
084:
085: public void testRacerSupportsLanguage() {
086: DIGAdapter r = new DIGAdapter(OntModelSpec.OWL_DL_MEM,
087: ModelFactory.createOntologyModel().getGraph());
088: iteratorTest(r.getDigIdentifier().supportsLanguage(),
089: new Object[] { "top", "bottom", "catom", "ratom",
090: "and", "or", "not", "some", "all", "atmost",
091: "atleast", "inverse", "feature", "attribute",
092: "intmin", "intmax", "intrange", "intequals",
093: "defined", "stringequals" });
094: }
095:
096: public void testRacerSupportsTell() {
097: DIGAdapter r = new DIGAdapter(OntModelSpec.OWL_DL_MEM,
098: ModelFactory.createOntologyModel().getGraph());
099: iteratorTest(r.getDigIdentifier().supportsTell(), new Object[] {
100: "defconcept", "defrole", "deffeature", "defattribute",
101: "defindividual", "impliesc", "equalc", "disjoint",
102: "impliesr", "domain", "range", "rangeint",
103: "transitive", "functional", "instanceof", "related",
104: "value", "equalr", "rangestring" });
105: }
106:
107: public void testRacerSupportsAsk() {
108: DIGAdapter r = new DIGAdapter(OntModelSpec.OWL_DL_MEM,
109: ModelFactory.createOntologyModel().getGraph());
110: iteratorTest(r.getDigIdentifier().supportsAsk(), new Object[] {
111: "allConceptNames", "allRoleNames", "allIndividuals",
112: "satisfiable", "subsumes", "disjoint", "parents",
113: "children", "descendants", "ancestors", "equivalents",
114: "rparents", "rchildren", "rancestors", "rdescendants",
115: "instances", "types", "instance", "roleFillers",
116: "relatedIndividuals", "toldValues", });
117: }
118:
119: // Internal implementation methods
120: //////////////////////////////////
121:
122: /** Test that an iterator delivers the expected values */
123: protected void iteratorTest(Iterator i, Object[] expected) {
124: assertNotNull("Iterator should not be null", i);
125:
126: Log logger = LogFactory.getLog(getClass());
127: List expList = new ArrayList();
128: for (int j = 0; j < expected.length; j++) {
129: expList.add(expected[j]);
130: }
131:
132: while (i.hasNext()) {
133: Object next = i.next();
134:
135: // debugging
136: if (!expList.contains(next)) {
137: logger.debug(getName()
138: + " - Unexpected iterator result: " + next);
139: }
140:
141: assertTrue(
142: "Value "
143: + next
144: + " was not expected as a result from this iterator ",
145: expList.contains(next));
146: assertTrue("Value " + next
147: + " was not removed from the list ", expList
148: .remove(next));
149: }
150:
151: if (!(expList.size() == 0)) {
152: logger.debug(getName()
153: + "Expected iterator results not found");
154: for (Iterator j = expList.iterator(); j.hasNext();) {
155: logger.debug(getName() + " - missing: " + j.next());
156: }
157: }
158: assertEquals(
159: "There were expected elements from the iterator that were not found",
160: 0, expList.size());
161: }
162:
163: //==============================================================================
164: // Inner class definitions
165: //==============================================================================
166:
167: }
168:
169: /*
170: * (c) Copyright 2001, 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: * 1. Redistributions of source code must retain the above copyright
177: * notice, this list of conditions and the following disclaimer.
178: * 2. Redistributions in binary form must reproduce the above copyright
179: * notice, this list of conditions and the following disclaimer in the
180: * documentation and/or other materials provided with the distribution.
181: * 3. The name of the author may not be used to endorse or promote products
182: * derived from this software without specific prior written permission.
183: *
184: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
185: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
187: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
188: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
189: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
190: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
191: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
192: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
193: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
194: */
|