KickJava   Java API By Example, From Geeks To Geeks.

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


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 26-Mar-2003
9  * Filename $RCSfile: TestOntology.java,v $
10  * Revision $Revision: 1.10 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:07:32 $
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 junit.framework.TestSuite;
28
29 import com.hp.hpl.jena.ontology.*;
30
31
32 /**
33  * <p>
34  * Unit test cases for the Ontology class
35  * </p>
36  *
37  * @author Ian Dickinson, HP Labs
38  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
39  * @version CVS $Id: TestOntology.java,v 1.10 2005/02/21 12:07:32 andy_seaborne Exp $
40  */

41 public class TestOntology
42     extends OntTestBase
43 {
44     // Constants
45
//////////////////////////////////
46

47     // Static variables
48
//////////////////////////////////
49

50
51
52     // Instance variables
53
//////////////////////////////////
54

55     // Constructors
56
//////////////////////////////////
57

58     static public TestSuite suite() {
59         return new TestOntology( "TestOntology" );
60     }
61     
62     public TestOntology( String JavaDoc name ) {
63         super( name );
64     }
65     
66     
67     
68     
69     // External signature methods
70
//////////////////////////////////
71

72     public OntTestCase[] getTests() {
73         return new OntTestCase[] {
74             new OntTestCase( "Ontology.imports", true, true, true, false ) {
75                 public void ontTest( OntModel m ) throws Exception JavaDoc {
76                     Profile prof = m.getProfile();
77                     Ontology x = m.createOntology( NS + "x" );
78                     Ontology y = m.createOntology( NS + "y" );
79                     Ontology z = m.createOntology( NS + "z" );
80                         
81                     x.addImport( y );
82                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) );
83                     assertEquals( "x should import y", y, x.getImport() );
84                         
85                     x.addImport( z );
86                     assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.IMPORTS() ) );
87                     iteratorTest( x.listImports(), new Object JavaDoc[] {y,z} );
88                         
89                     x.setImport( z );
90                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) );
91                     assertEquals( "x should import z", z, x.getImport() );
92                     
93                     x.removeImport( y );
94                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) );
95                     x.removeImport( z );
96                     assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.IMPORTS() ) );
97                 }
98             },
99             new OntTestCase( "Ontology.backwardCompatibleWith", true, true, false, false ) {
100                 public void ontTest( OntModel m ) throws Exception JavaDoc {
101                     Profile prof = m.getProfile();
102                     Ontology x = m.createOntology( NS + "x" );
103                     Ontology y = m.createOntology( NS + "y" );
104                     Ontology z = m.createOntology( NS + "z" );
105                         
106                     x.addBackwardCompatibleWith( y );
107                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) );
108                     assertEquals( "x should be back comp with y", y, x.getBackwardCompatibleWith() );
109                         
110                     x.addBackwardCompatibleWith( z );
111                     assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) );
112                     iteratorTest( x.listBackwardCompatibleWith(), new Object JavaDoc[] {y,z} );
113                         
114                     x.setBackwardCompatibleWith( z );
115                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) );
116                     assertEquals( "x should be back comp with z", z, x.getBackwardCompatibleWith() );
117                     
118                     x.removeBackwardCompatibleWith( y );
119                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) );
120                     x.removeBackwardCompatibleWith( z );
121                     assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) );
122                 }
123             },
124             new OntTestCase( "Ontology.priorVersion", true, true, false, false ) {
125                 public void ontTest( OntModel m ) throws Exception JavaDoc {
126                     Profile prof = m.getProfile();
127                     Ontology x = m.createOntology( NS + "x" );
128                     Ontology y = m.createOntology( NS + "y" );
129                     Ontology z = m.createOntology( NS + "z" );
130                         
131                     x.addPriorVersion( y );
132                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) );
133                     assertEquals( "x should have prior y", y, x.getPriorVersion() );
134                         
135                     x.addPriorVersion( z );
136                     assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.PRIOR_VERSION() ) );
137                     iteratorTest( x.listPriorVersion(), new Object JavaDoc[] {y,z} );
138                         
139                     x.setPriorVersion( z );
140                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) );
141                     assertEquals( "x should have prior z", z, x.getPriorVersion() );
142                     
143                     x.removePriorVersion( y );
144                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) );
145                     x.removePriorVersion( z );
146                     assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.PRIOR_VERSION() ) );
147                 }
148             },
149             new OntTestCase( "Ontology.incompatibleWith", true, true, false, false ) {
150                 public void ontTest( OntModel m ) throws Exception JavaDoc {
151                     Profile prof = m.getProfile();
152                     Ontology x = m.createOntology( NS + "x" );
153                     Ontology y = m.createOntology( NS + "y" );
154                     Ontology z = m.createOntology( NS + "z" );
155                         
156                     x.addIncompatibleWith( y );
157                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) );
158                     assertEquals( "x should be in comp with y", y, x.getIncompatibleWith() );
159                         
160                     x.addIncompatibleWith( z );
161                     assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.INCOMPATIBLE_WITH() ) );
162                     iteratorTest( x.listIncompatibleWith(), new Object JavaDoc[] {y,z} );
163                         
164                     x.setIncompatibleWith( z );
165                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) );
166                     assertEquals( "x should be incomp with z", z, x.getIncompatibleWith() );
167                     
168                     x.removeIncompatibleWith( y );
169                     assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) );
170                     x.removeIncompatibleWith( z );
171                     assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.INCOMPATIBLE_WITH() ) );
172                 }
173             },
174         };
175     }
176     
177     // Internal implementation methods
178
//////////////////////////////////
179

180     //==============================================================================
181
// Inner class definitions
182
//==============================================================================
183

184 }
185
186
187 /*
188     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
189     All rights reserved.
190
191     Redistribution and use in source and binary forms, with or without
192     modification, are permitted provided that the following conditions
193     are met:
194
195     1. Redistributions of source code must retain the above copyright
196        notice, this list of conditions and the following disclaimer.
197
198     2. Redistributions in binary form must reproduce the above copyright
199        notice, this list of conditions and the following disclaimer in the
200        documentation and/or other materials provided with the distribution.
201
202     3. The name of the author may not be used to endorse or promote products
203        derived from this software without specific prior written permission.
204
205     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
206     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
207     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
208     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
209     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
210     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
212     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
213     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
214     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
215 */

216
217
218
Popular Tags