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 26-Mar-2003
009: * Filename $RCSfile: TestOntology.java,v $
010: * Revision $Revision: 1.13 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:08:41 $
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 junit.framework.TestSuite;
023:
024: import com.hp.hpl.jena.ontology.*;
025:
026: /**
027: * <p>
028: * Unit test cases for the Ontology class
029: * </p>
030: *
031: * @author Ian Dickinson, HP Labs
032: * (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
033: * @version CVS $Id: TestOntology.java,v 1.13 2008/01/02 12:08:41 andy_seaborne Exp $
034: */
035: public class TestOntology extends OntTestBase {
036: // Constants
037: //////////////////////////////////
038:
039: // Static variables
040: //////////////////////////////////
041:
042: // Instance variables
043: //////////////////////////////////
044:
045: // Constructors
046: //////////////////////////////////
047:
048: static public TestSuite suite() {
049: return new TestOntology("TestOntology");
050: }
051:
052: public TestOntology(String name) {
053: super (name);
054: }
055:
056: // External signature methods
057: //////////////////////////////////
058:
059: public OntTestCase[] getTests() {
060: return new OntTestCase[] {
061: new OntTestCase("Ontology.imports", true, true, true,
062: false) {
063: public void ontTest(OntModel m) throws Exception {
064: Profile prof = m.getProfile();
065: Ontology x = m.createOntology(NS + "x");
066: Ontology y = m.createOntology(NS + "y");
067: Ontology z = m.createOntology(NS + "z");
068:
069: x.addImport(y);
070: assertEquals("Cardinality should be 1", 1, x
071: .getCardinality(prof.IMPORTS()));
072: assertEquals("x should import y", y, x
073: .getImport());
074:
075: x.addImport(z);
076: assertEquals("Cardinality should be 2", 2, x
077: .getCardinality(prof.IMPORTS()));
078: iteratorTest(x.listImports(), new Object[] { y,
079: z });
080:
081: x.setImport(z);
082: assertEquals("Cardinality should be 1", 1, x
083: .getCardinality(prof.IMPORTS()));
084: assertEquals("x should import z", z, x
085: .getImport());
086:
087: x.removeImport(y);
088: assertEquals("Cardinality should be 1", 1, x
089: .getCardinality(prof.IMPORTS()));
090: x.removeImport(z);
091: assertEquals("Cardinality should be 0", 0, x
092: .getCardinality(prof.IMPORTS()));
093: }
094: },
095: new OntTestCase("Ontology.backwardCompatibleWith",
096: true, true, false, false) {
097: public void ontTest(OntModel m) throws Exception {
098: Profile prof = m.getProfile();
099: Ontology x = m.createOntology(NS + "x");
100: Ontology y = m.createOntology(NS + "y");
101: Ontology z = m.createOntology(NS + "z");
102:
103: x.addBackwardCompatibleWith(y);
104: assertEquals("Cardinality should be 1", 1, x
105: .getCardinality(prof
106: .BACKWARD_COMPATIBLE_WITH()));
107: assertEquals("x should be back comp with y", y,
108: x.getBackwardCompatibleWith());
109:
110: x.addBackwardCompatibleWith(z);
111: assertEquals("Cardinality should be 2", 2, x
112: .getCardinality(prof
113: .BACKWARD_COMPATIBLE_WITH()));
114: iteratorTest(x.listBackwardCompatibleWith(),
115: new Object[] { y, z });
116:
117: x.setBackwardCompatibleWith(z);
118: assertEquals("Cardinality should be 1", 1, x
119: .getCardinality(prof
120: .BACKWARD_COMPATIBLE_WITH()));
121: assertEquals("x should be back comp with z", z,
122: x.getBackwardCompatibleWith());
123:
124: x.removeBackwardCompatibleWith(y);
125: assertEquals("Cardinality should be 1", 1, x
126: .getCardinality(prof
127: .BACKWARD_COMPATIBLE_WITH()));
128: x.removeBackwardCompatibleWith(z);
129: assertEquals("Cardinality should be 0", 0, x
130: .getCardinality(prof
131: .BACKWARD_COMPATIBLE_WITH()));
132: }
133: },
134: new OntTestCase("Ontology.priorVersion", true, true,
135: false, false) {
136: public void ontTest(OntModel m) throws Exception {
137: Profile prof = m.getProfile();
138: Ontology x = m.createOntology(NS + "x");
139: Ontology y = m.createOntology(NS + "y");
140: Ontology z = m.createOntology(NS + "z");
141:
142: x.addPriorVersion(y);
143: assertEquals("Cardinality should be 1", 1, x
144: .getCardinality(prof.PRIOR_VERSION()));
145: assertEquals("x should have prior y", y, x
146: .getPriorVersion());
147:
148: x.addPriorVersion(z);
149: assertEquals("Cardinality should be 2", 2, x
150: .getCardinality(prof.PRIOR_VERSION()));
151: iteratorTest(x.listPriorVersion(),
152: new Object[] { y, z });
153:
154: x.setPriorVersion(z);
155: assertEquals("Cardinality should be 1", 1, x
156: .getCardinality(prof.PRIOR_VERSION()));
157: assertEquals("x should have prior z", z, x
158: .getPriorVersion());
159:
160: x.removePriorVersion(y);
161: assertEquals("Cardinality should be 1", 1, x
162: .getCardinality(prof.PRIOR_VERSION()));
163: x.removePriorVersion(z);
164: assertEquals("Cardinality should be 0", 0, x
165: .getCardinality(prof.PRIOR_VERSION()));
166: }
167: },
168: new OntTestCase("Ontology.incompatibleWith", true,
169: true, false, false) {
170: public void ontTest(OntModel m) throws Exception {
171: Profile prof = m.getProfile();
172: Ontology x = m.createOntology(NS + "x");
173: Ontology y = m.createOntology(NS + "y");
174: Ontology z = m.createOntology(NS + "z");
175:
176: x.addIncompatibleWith(y);
177: assertEquals("Cardinality should be 1", 1, x
178: .getCardinality(prof
179: .INCOMPATIBLE_WITH()));
180: assertEquals("x should be in comp with y", y, x
181: .getIncompatibleWith());
182:
183: x.addIncompatibleWith(z);
184: assertEquals("Cardinality should be 2", 2, x
185: .getCardinality(prof
186: .INCOMPATIBLE_WITH()));
187: iteratorTest(x.listIncompatibleWith(),
188: new Object[] { y, z });
189:
190: x.setIncompatibleWith(z);
191: assertEquals("Cardinality should be 1", 1, x
192: .getCardinality(prof
193: .INCOMPATIBLE_WITH()));
194: assertEquals("x should be incomp with z", z, x
195: .getIncompatibleWith());
196:
197: x.removeIncompatibleWith(y);
198: assertEquals("Cardinality should be 1", 1, x
199: .getCardinality(prof
200: .INCOMPATIBLE_WITH()));
201: x.removeIncompatibleWith(z);
202: assertEquals("Cardinality should be 0", 0, x
203: .getCardinality(prof
204: .INCOMPATIBLE_WITH()));
205: }
206: }, };
207: }
208:
209: // Internal implementation methods
210: //////////////////////////////////
211:
212: //==============================================================================
213: // Inner class definitions
214: //==============================================================================
215:
216: }
217:
218: /*
219: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
220: All rights reserved.
221:
222: Redistribution and use in source and binary forms, with or without
223: modification, are permitted provided that the following conditions
224: are met:
225:
226: 1. Redistributions of source code must retain the above copyright
227: notice, this list of conditions and the following disclaimer.
228:
229: 2. Redistributions in binary form must reproduce the above copyright
230: notice, this list of conditions and the following disclaimer in the
231: documentation and/or other materials provided with the distribution.
232:
233: 3. The name of the author may not be used to endorse or promote products
234: derived from this software without specific prior written permission.
235:
236: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
237: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
238: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
239: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
240: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
244: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
245: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
246: */
|