KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestProperty.java,v $
10  * Revision $Revision: 1.12 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:07:36 $
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 import com.hp.hpl.jena.rdf.model.Property;
31 import com.hp.hpl.jena.vocabulary.RDF;
32
33
34
35 /**
36  * <p>
37  * Unit test cases for the Ontology class
38  * </p>
39  *
40  * @author Ian Dickinson, HP Labs
41  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
42  * @version CVS $Id: TestProperty.java,v 1.12 2005/02/21 12:07:36 andy_seaborne Exp $
43  */

44 public class TestProperty
45     extends OntTestBase
46 {
47     // Constants
48
//////////////////////////////////
49

50     // Static variables
51
//////////////////////////////////
52

53
54
55     // Instance variables
56
//////////////////////////////////
57

58     // Constructors
59
//////////////////////////////////
60

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

73     public OntTestCase[] getTests() {
74         return new OntTestCase[] {
75             new OntTestCase( "OntProperty.super-property", true, true, true, true ) {
76                 public void ontTest( OntModel m ) throws Exception JavaDoc {
77                     Profile prof = m.getProfile();
78                     OntProperty p = m.createOntProperty( NS + "p" );
79                     OntProperty q = m.createOntProperty( NS + "q" );
80                     OntProperty r = m.createOntProperty( NS + "r" );
81                     
82                     p.addSuperProperty( q );
83                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.SUB_PROPERTY_OF() ) );
84                     assertEquals( "p have super-prop q", q, p.getSuperProperty() );
85                     
86                     p.addSuperProperty( r );
87                     assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.SUB_PROPERTY_OF() ) );
88                     iteratorTest( p.listSuperProperties(), new Object JavaDoc[] {q, r} );
89                     
90                     p.setSuperProperty( r );
91                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.SUB_PROPERTY_OF() ) );
92                     assertEquals( "p shuold have super-prop r", r, p.getSuperProperty() );
93                     
94                     p.removeSuperProperty( q );
95                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.SUB_PROPERTY_OF() ) );
96                     p.removeSuperProperty( r );
97                     assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.SUB_PROPERTY_OF() ) );
98                 }
99             },
100             new OntTestCase( "OntProperty.sub-property", true, true, true, true ) {
101                 public void ontTest( OntModel m ) throws Exception JavaDoc {
102                     Profile prof = m.getProfile();
103                     OntProperty p = m.createOntProperty( NS + "p" );
104                     OntProperty q = m.createOntProperty( NS + "q" );
105                     OntProperty r = m.createOntProperty( NS + "r" );
106                     
107                     p.addSubProperty( q );
108                     assertEquals( "Cardinality should be 1", 1, q.getCardinality( prof.SUB_PROPERTY_OF() ) );
109                     assertEquals( "p have sub-prop q", q, p.getSubProperty() );
110                     
111                     p.addSubProperty( r );
112                     assertEquals( "Cardinality should be 2", 2, q.getCardinality( prof.SUB_PROPERTY_OF() ) + r.getCardinality( prof.SUB_PROPERTY_OF() ) );
113                     iteratorTest( p.listSubProperties(), new Object JavaDoc[] {q, r} );
114                     iteratorTest( q.listSuperProperties(), new Object JavaDoc[] {p} );
115                     iteratorTest( r.listSuperProperties(), new Object JavaDoc[] {p} );
116                     
117                     p.setSubProperty( r );
118                     assertEquals( "Cardinality should be 1", 1, q.getCardinality( prof.SUB_PROPERTY_OF() ) + r.getCardinality( prof.SUB_PROPERTY_OF() ) );
119                     assertEquals( "p should have sub-prop r", r, p.getSubProperty() );
120                     
121                     p.removeSubProperty( q );
122                     assertTrue( "Should have sub-prop r", p.hasSubProperty( r, false ) );
123                     p.removeSubProperty( r );
124                     assertTrue( "Should not have sub-prop r", !p.hasSubProperty( r, false ) );
125                 }
126             },
127             new OntTestCase( "OntProperty.domain", true, true, true, true ) {
128                 public void ontTest( OntModel m ) throws Exception JavaDoc {
129                     Profile prof = m.getProfile();
130                     OntProperty p = m.createOntProperty( NS + "p" );
131                     OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
132                     OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class );
133                     
134                     p.addDomain( a );
135                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.DOMAIN() ) );
136                     assertEquals( "p have domain a", a, p.getDomain() );
137                     
138                     p.addDomain( b );
139                     assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.DOMAIN() ) );
140                     iteratorTest( p.listDomain(), new Object JavaDoc[] {a, b} );
141                     
142                     p.setDomain( b );
143                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.DOMAIN() ) );
144                     assertEquals( "p should have domain b", b, p.getDomain() );
145                     
146                     p.removeDomain( a );
147                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.DOMAIN() ) );
148                     p.removeDomain( b );
149                     assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.DOMAIN() ) );
150                 }
151             },
152             new OntTestCase( "OntProperty.range", true, true, true, true ) {
153                 public void ontTest( OntModel m ) throws Exception JavaDoc {
154                     Profile prof = m.getProfile();
155                     OntProperty p = m.createOntProperty( NS + "p" );
156                     OntResource a = (OntResource) m.getResource( NS + "a" ).as( OntResource.class );
157                     OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class );
158                     
159                     p.addRange( a );
160                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.RANGE() ) );
161                     assertEquals( "p have range a", a, p.getRange() );
162                     
163                     p.addRange( b );
164                     assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.RANGE() ) );
165                     iteratorTest( p.listRange(), new Object JavaDoc[] {a, b} );
166                     
167                     p.setRange( b );
168                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.RANGE() ) );
169                     assertEquals( "p should have range b", b, p.getRange() );
170                     
171                     p.removeRange( a );
172                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.RANGE() ) );
173                     p.removeRange( b );
174                     assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.RANGE() ) );
175                 }
176             },
177             new OntTestCase( "OntProperty.equivalentProperty", true, true, true, false ) {
178                 public void ontTest( OntModel m ) throws Exception JavaDoc {
179                     Profile prof = m.getProfile();
180                     OntProperty p = m.createObjectProperty( NS + "p" );
181                     OntProperty q = m.createObjectProperty( NS + "q" );
182                     OntProperty r = m.createObjectProperty( NS + "r" );
183                     
184                     p.addEquivalentProperty( q );
185                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) );
186                     assertEquals( "p have equivalentProperty q", q, p.getEquivalentProperty() );
187                     
188                     p.addEquivalentProperty( r );
189                     assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) );
190                     iteratorTest( p.listEquivalentProperties(), new Object JavaDoc[] {q,r} );
191                     
192                     p.setEquivalentProperty( r );
193                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) );
194                     assertEquals( "p should have equivalentProperty r", r, p.getEquivalentProperty() );
195                     
196                     p.removeEquivalentProperty( q );
197                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) );
198                     p.removeEquivalentProperty( r );
199                     assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) );
200                 }
201             },
202             new OntTestCase( "OntProperty.inverseOf", true, true, true, false ) {
203                 public void ontTest( OntModel m ) throws Exception JavaDoc {
204                     Profile prof = m.getProfile();
205                     OntProperty p = m.createObjectProperty( NS + "p" );
206                     OntProperty q = m.createObjectProperty( NS + "q" );
207                     OntProperty r = m.createObjectProperty( NS + "r" );
208                     
209                     p.addInverseOf( q );
210                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.INVERSE_OF() ) );
211                     assertEquals( "p should have inverse q", q, p.getInverseOf() );
212                     
213                     p.addInverseOf( r );
214                     assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.INVERSE_OF() ) );
215                     iteratorTest( p.listInverseOf(), new Object JavaDoc[] {q,r} );
216                     
217                     p.setInverseOf( r );
218                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.INVERSE_OF() ) );
219                     assertEquals( "p should have inverse r", r, p.getInverseOf() );
220                     
221                     p.removeInverseProperty( q );
222                     assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.INVERSE_OF() ) );
223                     p.removeInverseProperty( r );
224                     assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.INVERSE_OF() ) );
225                 }
226             },
227             new OntTestCase( "OntProperty.subproperty.fromFile", true, true, true, true ) {
228                 public void ontTest( OntModel m ) throws Exception JavaDoc {
229                     String JavaDoc lang = m_owlLang ? "owl" : (m_damlLang ? "daml" : "rdfs");
230                     String JavaDoc fileName = "file:testing/ontology/" + lang + "/Property/test.rdf";
231                     m.read( fileName );
232
233                     OntProperty p = (OntProperty) m.getProperty( NS, "p" ).as( OntProperty.class );
234                     OntProperty q = (OntProperty) m.getProperty( NS, "q" ).as( OntProperty.class );
235                     
236                     iteratorTest( p.listSuperProperties(), new Object JavaDoc[] {q} );
237                     iteratorTest( q.listSubProperties(), new Object JavaDoc[] {p} );
238                 }
239             },
240             new OntTestCase( "OntProperty.domain.fromFile", true, true, true, true ) {
241                 public void ontTest( OntModel m ) throws Exception JavaDoc {
242                     String JavaDoc lang = m_owlLang ? "owl" : (m_damlLang ? "daml" : "rdfs");
243                     String JavaDoc fileName = "file:testing/ontology/" + lang + "/Property/test.rdf";
244                     m.read( fileName );
245
246                     OntProperty p = (OntProperty) m.getProperty( NS, "p" ).as( OntProperty.class );
247                     OntClass A = (OntClass) m.getResource( NS + "ClassA").as( OntClass.class);
248                     
249                     assertTrue( "p should have domain A", p.hasDomain( A ) );
250                 }
251             },
252             new OntTestCase( "OntProperty.range.fromFile", true, true, true, true ) {
253                 public void ontTest( OntModel m ) throws Exception JavaDoc {
254                     String JavaDoc lang = m_owlLang ? "owl" : (m_damlLang ? "daml" : "rdfs");
255                     String JavaDoc fileName = "file:testing/ontology/" + lang + "/Property/test.rdf";
256                     m.read( fileName );
257
258                     OntProperty p = (OntProperty) m.getProperty( NS, "p" ).as( OntProperty.class );
259                     OntClass B = (OntClass) m.getResource( NS + "ClassB").as( OntClass.class);
260                     
261                     assertTrue( "p should have domain B", p.hasRange( B ) );
262                 }
263             },
264             new OntTestCase( "OntProperty.equivalentProeprty.fromFile", true, true, true, false ) {
265                 public void ontTest( OntModel m ) throws Exception JavaDoc {
266                     String JavaDoc lang = m_owlLang ? "owl" : (m_damlLang ? "daml" : "rdfs");
267                     String JavaDoc fileName = "file:testing/ontology/" + lang + "/Property/test.rdf";
268                     m.read( fileName );
269
270                     OntProperty p = (OntProperty) m.getProperty( NS, "p" ).as( OntProperty.class );
271                     OntProperty r = (OntProperty) m.getProperty( NS, "r" ).as( OntProperty.class );
272                     
273                     assertTrue( "p should have equiv prop r", p.hasEquivalentProperty( r ) );
274                 }
275             },
276             new OntTestCase( "OntProperty.inversePropertyOf.fromFile", true, true, true, false ) {
277                 public void ontTest( OntModel m ) throws Exception JavaDoc {
278                     String JavaDoc lang = m_owlLang ? "owl" : (m_damlLang ? "daml" : "rdfs");
279                     String JavaDoc fileName = "file:testing/ontology/" + lang + "/Property/test.rdf";
280                     m.read( fileName );
281
282                     OntProperty p = (OntProperty) m.getProperty( NS, "p" ).as( OntProperty.class );
283                     OntProperty s = (OntProperty) m.getProperty( NS, "s" ).as( OntProperty.class );
284                     
285                     assertTrue( "p should have inv prop s", p.isInverseOf( s ) );
286                 }
287             },
288             
289             // type tests
290
new OntTestCase( "OntProperty.isFunctionalProperty dt", true, true, true, false ) {
291                 public void ontTest( OntModel m ) throws Exception JavaDoc {
292                     OntProperty p = m.createDatatypeProperty( NS + "p", true );
293                 
294                     assertTrue( "isFunctionalProperty not correct", p.isFunctionalProperty() );
295                     assertTrue( "isDatatypeProperty not correct", p.isDatatypeProperty() );
296                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
297                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
298                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
299                     if (m_owlLang) {
300                         assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() );
301                     }
302                 }
303             },
304             new OntTestCase( "OntProperty.isFunctionalProperty object", true, true, true, false ) {
305                 public void ontTest( OntModel m ) throws Exception JavaDoc {
306                     OntProperty p = m.createObjectProperty( NS + "p", true );
307                 
308                     assertTrue( "isFunctionalProperty not correct", p.isFunctionalProperty() );
309                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
310                     assertTrue( "isObjectProperty not correct", p.isObjectProperty() );
311                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
312                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
313                     if (m_owlLang) {
314                         assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() );
315                     }
316                 }
317             },
318             new OntTestCase( "OntProperty.isDatatypeProperty", true, true, true, false ) {
319                 public void ontTest( OntModel m ) throws Exception JavaDoc {
320                     OntProperty p = m.createDatatypeProperty( NS + "p", false );
321                 
322                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
323                     assertTrue( "isDatatypeProperty not correct", p.isDatatypeProperty() );
324                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
325                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
326                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
327                     if (m_owlLang) {
328                         assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() );
329                     }
330                 }
331             },
332             new OntTestCase( "OntProperty.isObjectProperty", true, true, true, false ) {
333                 public void ontTest( OntModel m ) throws Exception JavaDoc {
334                     OntProperty p = m.createObjectProperty( NS + "p", false );
335                 
336                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
337                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
338                     assertTrue( "isObjectProperty not correct", p.isObjectProperty() );
339                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
340                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
341                     if (m_owlLang) {
342                         assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() );
343                     }
344                 }
345             },
346             new OntTestCase( "OntProperty.isTransitiveProperty", true, true, true, false ) {
347                 public void ontTest( OntModel m ) throws Exception JavaDoc {
348                     OntProperty p = m.createTransitiveProperty( NS + "p" );
349                 
350                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
351                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
352                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); // this should be true by entailment, but we have reasoning switched off
353
assertTrue( "isTransitiveProperty not correct", p.isTransitiveProperty() );
354                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
355                     if (m_owlLang) {
356                         assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() );
357                     }
358                 }
359             },
360             new OntTestCase( "OntProperty.isInverseFunctionalProperty", true, true, true, false ) {
361                 public void ontTest( OntModel m ) throws Exception JavaDoc {
362                     OntProperty p = m.createInverseFunctionalProperty( NS + "p" );
363                 
364                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
365                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
366                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); // this should be true by entailment, but we have reasoning switched off
367
assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
368                     assertTrue( "isInverseFunctionalProperty not correct", p.isInverseFunctionalProperty() );
369                     if (m_owlLang) {
370                         assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() );
371                     }
372                 }
373             },
374             new OntTestCase( "OntProperty.isSymmetricProperty", true, true, false, false ) {
375                 public void ontTest( OntModel m ) throws Exception JavaDoc {
376                     OntProperty p = m.createSymmetricProperty( NS + "p" );
377                 
378                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
379                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
380                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); // this should be true by entailment, but we have reasoning switched off
381
assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
382                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
383                     if (m_owlLang) {
384                         assertTrue( "isSymmetricProperty not correct", p.isSymmetricProperty() );
385                     }
386                 }
387             },
388             new OntTestCase( "OntProperty.convertToFunctionalProperty", true, true, true, false ) {
389                 public void ontTest( OntModel m ) throws Exception JavaDoc {
390                     Property pSimple = m.createProperty( NS, "p" );
391                     pSimple.addProperty( RDF.type, RDF.Property );
392                     OntProperty p = (OntProperty) pSimple.as( OntProperty.class );
393                 
394                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
395                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
396                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
397                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
398                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
399                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
400                 
401                     p = p.convertToFunctionalProperty();
402                     
403                     assertTrue( "isFunctionalProperty not correct", p.isFunctionalProperty() );
404                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
405                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
406                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
407                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
408                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
409                 }
410             },
411             new OntTestCase( "OntProperty.convertToDatatypeProperty", true, true, true, false ) {
412                 public void ontTest( OntModel m ) throws Exception JavaDoc {
413                     Property pSimple = m.createProperty( NS, "p" );
414                     pSimple.addProperty( RDF.type, RDF.Property );
415                     OntProperty p = (OntProperty) pSimple.as( OntProperty.class );
416                 
417                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
418                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
419                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
420                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
421                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
422                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
423                 
424                     p = p.convertToDatatypeProperty();
425                     
426                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
427                     assertTrue( "isDatatypeProperty not correct", p.isDatatypeProperty() );
428                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
429                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
430                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
431                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
432                 }
433             },
434             new OntTestCase( "OntProperty.convertToObjectProperty", true, true, true, false ) {
435                 public void ontTest( OntModel m ) throws Exception JavaDoc {
436                     Property pSimple = m.createProperty( NS, "p" );
437                     pSimple.addProperty( RDF.type, RDF.Property );
438                     OntProperty p = (OntProperty) pSimple.as( OntProperty.class );
439                 
440                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
441                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
442                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
443                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
444                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
445                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
446                 
447                     p = p.convertToObjectProperty();
448                     
449                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
450                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
451                     assertTrue( "isObjectProperty not correct", p.isObjectProperty() );
452                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
453                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
454                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
455                 }
456             },
457             new OntTestCase( "OntProperty.convertToTransitiveProperty", true, true, true, false ) {
458                 public void ontTest( OntModel m ) throws Exception JavaDoc {
459                     Property pSimple = m.createProperty( NS, "p" );
460                     pSimple.addProperty( RDF.type, RDF.Property );
461                     OntProperty p = (OntProperty) pSimple.as( OntProperty.class );
462                 
463                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
464                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
465                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
466                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
467                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
468                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
469                 
470                     p = p.convertToTransitiveProperty();
471                     
472                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
473                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
474                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
475                     assertTrue( "isTransitiveProperty not correct", p.isTransitiveProperty() );
476                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
477                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
478                 }
479             },
480             new OntTestCase( "OntProperty.convertToInverseFunctionalProperty", true, true, true, false ) {
481                 public void ontTest( OntModel m ) throws Exception JavaDoc {
482                     Property pSimple = m.createProperty( NS, "p" );
483                     pSimple.addProperty( RDF.type, RDF.Property );
484                     OntProperty p = (OntProperty) pSimple.as( OntProperty.class );
485                 
486                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
487                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
488                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
489                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
490                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
491                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
492                 
493                     p = p.convertToInverseFunctionalProperty();
494                     
495                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
496                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
497                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
498                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
499                     assertTrue( "isInverseFunctionalProperty not correct", p.isInverseFunctionalProperty() );
500                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
501                 }
502             },
503             new OntTestCase( "OntProperty.convertToSymmetricProperty", true, true, false, false ) {
504                 public void ontTest( OntModel m ) throws Exception JavaDoc {
505                     Property pSimple = m.createProperty( NS, "p" );
506                     pSimple.addProperty( RDF.type, RDF.Property );
507                     OntProperty p = (OntProperty) pSimple.as( OntProperty.class );
508                 
509                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
510                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
511                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
512                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
513                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
514                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); }
515                 
516                     p = p.convertToSymmetricProperty();
517                     
518                     assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() );
519                     assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() );
520                     assertTrue( "isObjectProperty not correct", !p.isObjectProperty() );
521                     assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() );
522                     assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() );
523                     if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", p.isSymmetricProperty() ); }
524                 }
525             },
526             new OntTestCase( "OntProperty.inverse", true, true, true, false ) {
527                 public void ontTest( OntModel m ) throws Exception JavaDoc {
528                     ObjectProperty p = m.createObjectProperty( NS + "p" );
529                     ObjectProperty q = m.createObjectProperty( NS + "q" );
530                     ObjectProperty r = m.createObjectProperty( NS + "r" );
531                     
532                     assertFalse( "No inverse of p", p.hasInverse() );
533                     
534                     q.addInverseOf( p );
535                     assertTrue( "Inverse of p", p.hasInverse() );
536                     assertEquals( "inverse of p ", q, p.getInverse() );
537                     
538                     r.addInverseOf( p );
539                     iteratorTest( p.listInverse(), new Object JavaDoc[] {q,r} );
540                 }
541             },
542         };
543     }
544     
545     // Internal implementation methods
546
//////////////////////////////////
547

548     //==============================================================================
549
// Inner class definitions
550
//==============================================================================
551

552 }
553
554
555 /*
556     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
557     All rights reserved.
558
559     Redistribution and use in source and binary forms, with or without
560     modification, are permitted provided that the following conditions
561     are met:
562
563     1. Redistributions of source code must retain the above copyright
564        notice, this list of conditions and the following disclaimer.
565
566     2. Redistributions in binary form must reproduce the above copyright
567        notice, this list of conditions and the following disclaimer in the
568        documentation and/or other materials provided with the distribution.
569
570     3. The name of the author may not be used to endorse or promote products
571        derived from this software without specific prior written permission.
572
573     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
574     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
575     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
576     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
577     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
578     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
579     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
580     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
581     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
582     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
583 */

584
585
586
Popular Tags