KickJava   Java API By Example, From Geeks To Geeks.

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


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 17-Jun-2003
9  * Filename $RCSfile: TestDAMLProperty.java,v $
10  * Revision $Revision: 1.7 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:05:48 $
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.daml.impl.test;
23
24
25 // Imports
26
///////////////
27
import com.hp.hpl.jena.ontology.daml.*;
28 import com.hp.hpl.jena.vocabulary.DAML_OIL;
29
30 import junit.framework.*;
31
32
33 /**
34  * <p>
35  * Unit tests for DAML property
36  * </p>
37  *
38  * @author Ian Dickinson, HP Labs
39  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
40  * @version CVS $Id: TestDAMLProperty.java,v 1.7 2005/02/21 12:05:48 andy_seaborne Exp $
41  */

42 public class TestDAMLProperty
43     extends DAMLTestBase
44 {
45     // Constants
46
//////////////////////////////////
47

48     // Static variables
49
//////////////////////////////////
50

51     // Instance variables
52
//////////////////////////////////
53

54     // Constructors
55
//////////////////////////////////
56

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

69     public OntTestCase[] getTests() {
70         return new OntTestCase[] {
71             new OntTestCase( "DAMLProperty.unique" ) {
72                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
73                     DAMLProperty p = m.createDAMLProperty( NS + "p" );
74                     
75                     assertFalse( "unique", p.isUnique() );
76                     p.setIsUnique( true );
77                     assertTrue( "unique", p.isUnique() );
78                 }
79             },
80             new OntTestCase( "DAMLProperty.prop_domain" ) {
81                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
82                     DAMLProperty p = m.createDAMLProperty( NS + "p" );
83                     DAMLClass B = m.createDAMLClass( NS + "B" );
84                     DAMLClass C = m.createDAMLClass( NS + "C" );
85                     
86                     assertEquals( "prop_domain property", DAML_OIL.domain, p.prop_domain().getProperty() );
87                     
88                     assertEquals( "domain cardinality", 0, p.prop_domain().count() );
89                     p.prop_domain().add( B );
90                     assertEquals( "domain cardinality", 1, p.prop_domain().count() );
91                     p.prop_domain().add( C );
92                     assertEquals( "domain cardinality", 2, p.prop_domain().count() );
93                     
94                     iteratorTest( p.prop_domain().getAll(), new Object JavaDoc[] {B,C} );
95                     
96                     p.prop_domain().remove( C );
97                     assertEquals( "domain cardinality", 1, p.prop_domain().count() );
98                     
99                     iteratorTest( p.prop_domain().getAll(), new Object JavaDoc[] {B} );
100                     
101                     assertTrue( "hasValue", p.prop_domain().hasValue( B ) );
102                     assertTrue( "hasValue", !p.prop_domain().hasValue( C ) );
103                 }
104             },
105             new OntTestCase( "DAMLProperty.prop_range" ) {
106                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
107                     DAMLProperty p = m.createDAMLProperty( NS + "p" );
108                     DAMLClass B = m.createDAMLClass( NS + "B" );
109                     DAMLClass C = m.createDAMLClass( NS + "C" );
110                     
111                     assertEquals( "prop_range property", DAML_OIL.range, p.prop_range().getProperty() );
112                     
113                     assertEquals( "range cardinality", 0, p.prop_range().count() );
114                     p.prop_range().add( B );
115                     assertEquals( "range cardinality", 1, p.prop_range().count() );
116                     p.prop_range().add( C );
117                     assertEquals( "range cardinality", 2, p.prop_range().count() );
118                     
119                     iteratorTest( p.prop_range().getAll(), new Object JavaDoc[] {B,C} );
120                     
121                     p.prop_range().remove( C );
122                     assertEquals( "range cardinality", 1, p.prop_range().count() );
123                     
124                     iteratorTest( p.prop_range().getAll(), new Object JavaDoc[] {B} );
125                     
126                     assertTrue( "hasValue", p.prop_range().hasValue( B ) );
127                     assertTrue( "hasValue", !p.prop_range().hasValue( C ) );
128                 }
129             },
130             new OntTestCase( "DAMLProperty.prop_subPropertyOf" ) {
131                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
132                     DAMLProperty p = m.createDAMLProperty( NS + "p" );
133                     DAMLProperty q = m.createDAMLProperty( NS + "q" );
134                     DAMLProperty r = m.createDAMLProperty( NS + "r" );
135                     
136                     assertEquals( "prop_subPropertyOf property", DAML_OIL.subPropertyOf, p.prop_subPropertyOf().getProperty() );
137                     
138                     assertEquals( "subPropertyOf cardinality", 0, p.prop_subPropertyOf().count() );
139                     p.prop_subPropertyOf().add( q );
140                     assertEquals( "subPropertyOf cardinality", 1, p.prop_subPropertyOf().count() );
141                     p.prop_subPropertyOf().add( r );
142                     assertEquals( "subPropertyOf cardinality", 2, p.prop_subPropertyOf().count() );
143                     
144                     iteratorTest( p.prop_subPropertyOf().getAll(), new Object JavaDoc[] {q,r} );
145                     
146                     p.prop_subPropertyOf().remove( r );
147                     assertEquals( "subPropertyOf cardinality", 1, p.prop_subPropertyOf().count() );
148                     
149                     iteratorTest( p.prop_subPropertyOf().getAll(), new Object JavaDoc[] {q} );
150                     
151                     assertTrue( "hasValue", p.prop_subPropertyOf().hasValue( q ) );
152                     assertTrue( "hasValue", !p.prop_subPropertyOf().hasValue( r ) );
153                 }
154             },
155             new OntTestCase( "DAMLProperty.getSubProperties" ) {
156                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
157                     DAMLProperty p = m.createDAMLProperty( NS + "p" );
158                     DAMLProperty q = m.createDAMLProperty( NS + "q" );
159                     DAMLProperty r = m.createDAMLProperty( NS + "r" );
160                    
161                     r.prop_subPropertyOf().add( q );
162                     q.prop_subPropertyOf().add( p );
163                     
164                     assertEquals( "subPropertyOf p", q, p.getSubProperty() );
165                     
166                     // no inference
167
iteratorTest( p.getSubProperties(), new Object JavaDoc[] {q} );
168                     iteratorTest( p.getSubProperties( false ), new Object JavaDoc[] {q} );
169                     iteratorTest( p.getSubProperties( true ), new Object JavaDoc[] {q} );
170                     
171                     r.prop_subPropertyOf().add( p ); // could be inferred
172

173                     iteratorTest( p.getSubProperties(), new Object JavaDoc[] {q,r} );
174                     iteratorTest( p.getSubProperties( false ), new Object JavaDoc[] {q} );
175                     iteratorTest( p.getSubProperties( true ), new Object JavaDoc[] {q,r} );
176                 }
177             },
178             new OntTestCase( "DAMLProperty.getSuperProperties" ) {
179                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
180                     DAMLProperty p = m.createDAMLProperty( NS + "p" );
181                     DAMLProperty q = m.createDAMLProperty( NS + "q" );
182                     DAMLProperty r = m.createDAMLProperty( NS + "r" );
183                    
184                     p.prop_subPropertyOf().add( q );
185                     q.prop_subPropertyOf().add( r );
186                     
187                     assertEquals( "superPropertyOf p", q, p.getSuperProperty() );
188                     
189                     // no inference
190
iteratorTest( p.getSuperProperties(), new Object JavaDoc[] {q} );
191                     iteratorTest( p.getSuperProperties( false ), new Object JavaDoc[] {q} );
192                     iteratorTest( p.getSuperProperties( true ), new Object JavaDoc[] {q} );
193                     
194                     p.prop_subPropertyOf().add( r ); // could be inferred
195

196                     iteratorTest( p.getSuperProperties(), new Object JavaDoc[] {q,r} );
197                     iteratorTest( p.getSuperProperties( false ), new Object JavaDoc[] {q} );
198                     iteratorTest( p.getSuperProperties( true ), new Object JavaDoc[] {q,r} );
199                 }
200             },
201             new OntTestCase( "DAMLProperty.getSameProperties" ) {
202                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
203                     DAMLProperty p = m.createDAMLProperty( NS + "p" );
204                     DAMLProperty q = m.createDAMLProperty( NS + "q" );
205                     DAMLProperty r = m.createDAMLProperty( NS + "r" );
206                    
207                     p.prop_samePropertyAs().add( q );
208                     q.prop_samePropertyAs().add( r );
209                     
210                     // no inference
211
iteratorTest( p.getSameProperties(), new Object JavaDoc[] {q} );
212                     
213                     p.prop_samePropertyAs().add( r ); // could be inferred
214

215                     iteratorTest( p.getSameProperties(), new Object JavaDoc[] {q,r} );
216                 }
217             },
218             new OntTestCase( "Datatype property" ) {
219                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
220                     DAMLDatatypeProperty p = m.createDAMLDatatypeProperty( NS + "p" );
221                     assertNotNull( p );
222                 }
223             },
224             new OntTestCase( "unambiguous property" ) {
225                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
226                     DAMLObjectProperty p = m.createDAMLObjectProperty( NS + "p" );
227                     assertFalse( "p not unambiguous", p.isUnambiguous() );
228                     p.setIsUnambiguous( true );
229                     assertTrue( "p not unambiguous", p.isUnambiguous() );
230                     p.setIsUnambiguous( false );
231                     assertFalse( "p not unambiguous", p.isUnambiguous() );
232                 }
233             },
234             new OntTestCase( "Transitive property" ) {
235                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
236                     DAMLObjectProperty p = m.createDAMLObjectProperty( NS + "p" );
237                     assertFalse( "p not Transitive", p.isTransitive() );
238                     p.setIsTransitive( true );
239                     assertTrue( "p not Transitive", p.isTransitive() );
240                     p.setIsTransitive( false );
241                     assertFalse( "p not Transitive", p.isTransitive() );
242                 }
243             },
244             new OntTestCase( "DAMLObjectProperty.prop_inverseOf" ) {
245                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
246                     DAMLObjectProperty p = m.createDAMLObjectProperty( NS + "p" );
247                     DAMLObjectProperty q = m.createDAMLObjectProperty( NS + "q" );
248                    
249                     p.prop_inverseOf().add( q );
250                     assertEquals( "inverse", q, p.prop_inverseOf().get() );
251                 }
252             },
253         };
254     }
255     
256     
257     // Internal implementation methods
258
//////////////////////////////////
259

260     //==============================================================================
261
// Inner class definitions
262
//==============================================================================
263

264 }
265
266
267 /*
268     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
269     All rights reserved.
270
271     Redistribution and use in source and binary forms, with or without
272     modification, are permitted provided that the following conditions
273     are met:
274
275     1. Redistributions of source code must retain the above copyright
276        notice, this list of conditions and the following disclaimer.
277
278     2. Redistributions in binary form must reproduce the above copyright
279        notice, this list of conditions and the following disclaimer in the
280        documentation and/or other materials provided with the distribution.
281
282     3. The name of the author may not be used to endorse or promote products
283        derived from this software without specific prior written permission.
284
285     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
286     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
287     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
288     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
289     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
290     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
291     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
292     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
293     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
294     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295 */

296
Popular Tags