KickJava   Java API By Example, From Geeks To Geeks.

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


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 03-Apr-2003
9  * Filename $RCSfile: TestCreate.java,v $
10  * Revision $Revision: 1.13 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:07:17 $
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 com.hp.hpl.jena.rdf.model.*;
28 import com.hp.hpl.jena.ontology.*;
29
30 import junit.framework.*;
31
32
33
34 /**
35  * <p>
36  * Unit test cases for creating values in ontology models
37  * </p>
38  *
39  * @author Ian Dickinson, HP Labs
40  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
41  * @version CVS $Id: TestCreate.java,v 1.13 2005/02/21 12:07:17 andy_seaborne Exp $
42  */

43 public class TestCreate
44     extends TestCase
45 {
46     // Constants
47
//////////////////////////////////
48
public static final String JavaDoc BASE = "http://jena.hpl.hp.com/testing/ontology";
49     public static final String JavaDoc NS = BASE + "#";
50
51     // Static variables
52
//////////////////////////////////
53

54     protected static CreateTestCase[] testCases = new CreateTestCase[] {
55         new CreateTestCase( "OWL create ontology", ProfileRegistry.OWL_LANG, BASE ) {
56             public OntResource doCreate( OntModel m ) { return m.createOntology( BASE ); }
57             public boolean test( OntResource r ) { return r instanceof Ontology;}
58         },
59         new CreateTestCase( "DAML create ontology", ProfileRegistry.DAML_LANG, BASE ) {
60             public OntResource doCreate( OntModel m ) { return m.createOntology( BASE ); }
61             public boolean test( OntResource r ) { return r instanceof Ontology;}
62         },
63         
64         new CreateTestCase( "OWL create class", ProfileRegistry.OWL_LANG, NS + "C" ) {
65             public OntResource doCreate( OntModel m ) { return m.createClass( NS + "C" ); }
66             public boolean test( OntResource r ) { return r instanceof OntClass;}
67         },
68         
69         new CreateTestCase( "OWL create anon complement class", ProfileRegistry.OWL_LANG, null ) {
70             public OntResource doCreate( OntModel m ) { return m.createComplementClass( null, m.createClass( NS + "A" ) ); }
71             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof ComplementClass; }
72         },
73         new CreateTestCase( "OWL create anon enumeration class", ProfileRegistry.OWL_LANG, null ) {
74             public OntResource doCreate( OntModel m ) {
75                 OntClass A = m.createClass( NS + "A" );
76                 Individual a0 = m.createIndividual( A );
77                 Individual a1 = m.createIndividual( A );
78                 Individual a2 = m.createIndividual( A );
79                 RDFList l = m.createList( new OntResource[] {a0, a1, a2} );
80                 return m.createEnumeratedClass( null, l );
81             }
82             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof EnumeratedClass; }
83         },
84         new CreateTestCase( "OWL create anon union class", ProfileRegistry.OWL_LANG, null ) {
85             public OntResource doCreate( OntModel m ) {
86                 OntClass A = m.createClass( NS + "A" );
87                 Individual a0 = m.createIndividual( A );
88                 Individual a1 = m.createIndividual( A );
89                 Individual a2 = m.createIndividual( A );
90                 RDFList l = m.createList( new OntResource[] {a0, a1, a2} );
91                 return m.createUnionClass( null, l );
92             }
93             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof UnionClass; }
94         },
95         new CreateTestCase( "OWL create anon intersection class", ProfileRegistry.OWL_LANG, null ) {
96             public OntResource doCreate( OntModel m ) {
97                 OntClass A = m.createClass( NS + "A" );
98                 Individual a0 = m.createIndividual( A );
99                 Individual a1 = m.createIndividual( A );
100                 Individual a2 = m.createIndividual( A );
101                 RDFList l = m.createList( new OntResource[] {a0, a1, a2} );
102                 return m.createIntersectionClass( null, l );
103             }
104             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof IntersectionClass; }
105         },
106         
107         new CreateTestCase( "OWL create class", ProfileRegistry.OWL_LANG, NS + "C" ) {
108             public OntResource doCreate( OntModel m ) { return m.createClass( NS + "C" ); }
109             public boolean test( OntResource r ) { return r instanceof OntClass;}
110         },
111
112         new CreateTestCase( "DAML create class", ProfileRegistry.DAML_LANG, NS + "C" ) {
113             public OntResource doCreate( OntModel m ) { return m.createClass( NS + "C" ); }
114             public boolean test( OntResource r ) { return r instanceof OntClass;}
115         },
116         new CreateTestCase( "DAML create anon class", ProfileRegistry.DAML_LANG, null ) {
117             public OntResource doCreate( OntModel m ) { return m.createClass(); }
118             public boolean test( OntResource r ) { return r instanceof OntClass;}
119         },
120         
121         new CreateTestCase( "DAML create anon complement class", ProfileRegistry.DAML_LANG, null ) {
122             public OntResource doCreate( OntModel m ) { return m.createComplementClass( null, m.createClass( NS + "A" ) ); }
123             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof ComplementClass; }
124         },
125         new CreateTestCase( "DAML create anon enumeration class", ProfileRegistry.DAML_LANG, null ) {
126             public OntResource doCreate( OntModel m ) {
127                 OntClass A = m.createClass( NS + "A" );
128                 Individual a0 = m.createIndividual( A );
129                 Individual a1 = m.createIndividual( A );
130                 Individual a2 = m.createIndividual( A );
131                 RDFList l = m.createList( new OntResource[] {a0, a1, a2} );
132                 return m.createEnumeratedClass( null, l );
133             }
134             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof EnumeratedClass; }
135         },
136         new CreateTestCase( "DAML create anon union class", ProfileRegistry.DAML_LANG, null ) {
137             public OntResource doCreate( OntModel m ) {
138                 OntClass A = m.createClass( NS + "A" );
139                 Individual a0 = m.createIndividual( A );
140                 Individual a1 = m.createIndividual( A );
141                 Individual a2 = m.createIndividual( A );
142                 RDFList l = m.createList( new OntResource[] {a0, a1, a2} );
143                 return m.createUnionClass( null, l );
144             }
145             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof UnionClass; }
146         },
147         new CreateTestCase( "DAML create anon intersection class", ProfileRegistry.DAML_LANG, null ) {
148             public OntResource doCreate( OntModel m ) {
149                 OntClass A = m.createClass( NS + "A" );
150                 Individual a0 = m.createIndividual( A );
151                 Individual a1 = m.createIndividual( A );
152                 Individual a2 = m.createIndividual( A );
153                 RDFList l = m.createList( new OntResource[] {a0, a1, a2} );
154                 return m.createIntersectionClass( null, l );
155             }
156             public boolean test( OntResource r ) { return r instanceof OntClass && r instanceof IntersectionClass; }
157         },
158
159         new CreateTestCase( "OWL create individual", ProfileRegistry.OWL_LANG, NS + "a" ) {
160             public OntResource doCreate( OntModel m ) {
161                 OntClass c = m.createClass( NS + "C" );
162                 return m.createIndividual( NS + "a", c );
163             }
164             public boolean test( OntResource r ) { return r instanceof Individual;}
165         },
166         new CreateTestCase( "OWL create anon individual", ProfileRegistry.OWL_LANG, null ) {
167             public OntResource doCreate( OntModel m ) {
168                 OntClass c = m.createClass( NS + "C" );
169                 return m.createIndividual( c );
170             }
171             public boolean test( OntResource r ) { return r instanceof Individual;}
172         },
173         new CreateTestCase( "DAML create individual", ProfileRegistry.DAML_LANG, NS + "a" ) {
174             public OntResource doCreate( OntModel m ) {
175                 OntClass c = m.createClass( NS + "C" );
176                 return m.createIndividual( NS + "a", c );
177             }
178             public boolean test( OntResource r ) { return r instanceof Individual;}
179         },
180         new CreateTestCase( "DAML create anon individual", ProfileRegistry.DAML_LANG, null ) {
181             public OntResource doCreate( OntModel m ) {
182                 OntClass c = m.createClass( NS + "C" );
183                 return m.createIndividual( c );
184             }
185             public boolean test( OntResource r ) { return r instanceof Individual;}
186         },
187         
188         // OWL property types
189
new CreateTestCase( "OWL create object property", ProfileRegistry.OWL_LANG, NS + "p" ) {
190             public OntResource doCreate( OntModel m ) { return m.createObjectProperty( NS + "p" ); }
191             public boolean test( OntResource r ) { return r instanceof ObjectProperty;}
192         },
193         new CreateTestCase( "OWL create object property non-F", ProfileRegistry.OWL_LANG, NS + "p" ) {
194             public OntResource doCreate( OntModel m ) { return m.createObjectProperty( NS + "p", false ); }
195             public boolean test( OntResource r ) { return r instanceof ObjectProperty && !r.canAs( FunctionalProperty.class );}
196         },
197         new CreateTestCase( "OWL create object property F", ProfileRegistry.OWL_LANG, NS + "p" ) {
198             public OntResource doCreate( OntModel m ) { return m.createObjectProperty( NS + "p", true ); }
199             public boolean test( OntResource r ) { return r instanceof ObjectProperty && r.canAs( FunctionalProperty.class );}
200         },
201         
202         new CreateTestCase( "OWL create transitive property", ProfileRegistry.OWL_LANG, NS + "p" ) {
203             public OntResource doCreate( OntModel m ) { return m.createTransitiveProperty( NS + "p" ); }
204             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
205                                                                  r instanceof TransitiveProperty;
206                                                         }
207         },
208         new CreateTestCase( "OWL create transitive property non-F", ProfileRegistry.OWL_LANG, NS + "p" ) {
209             public OntResource doCreate( OntModel m ) { return m.createTransitiveProperty( NS + "p", false ); }
210             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
211                                                                  r instanceof TransitiveProperty &&
212                                                                  !r.canAs( FunctionalProperty.class );
213                                                         }
214         },
215         new CreateTestCase( "OWL create transitive property F", ProfileRegistry.OWL_LANG, NS + "p" ) {
216             public OntResource doCreate( OntModel m ) { return m.createTransitiveProperty( NS + "p", true ); }
217             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
218                                                                  r instanceof TransitiveProperty &&
219                                                                  r.canAs( FunctionalProperty.class );
220                                                         }
221         },
222         new CreateTestCase( "OWL create symmetric property", ProfileRegistry.OWL_LANG, NS + "p" ) {
223             public OntResource doCreate( OntModel m ) { return m.createSymmetricProperty( NS + "p" ); }
224             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
225                                                                  r instanceof SymmetricProperty;
226                                                         }
227         },
228         new CreateTestCase( "OWL create symmetric property non-F", ProfileRegistry.OWL_LANG, NS + "p" ) {
229             public OntResource doCreate( OntModel m ) { return m.createSymmetricProperty( NS + "p", false ); }
230             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
231                                                                  r instanceof SymmetricProperty &&
232                                                                  !r.canAs( FunctionalProperty.class );
233                                                         }
234         },
235         new CreateTestCase( "OWL create symmetric property F", ProfileRegistry.OWL_LANG, NS + "p" ) {
236             public OntResource doCreate( OntModel m ) { return m.createSymmetricProperty( NS + "p", true ); }
237             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
238                                                                  r instanceof SymmetricProperty &&
239                                                                  r.canAs( FunctionalProperty.class );
240                                                         }
241         },
242         new CreateTestCase( "OWL create inverse functional property", ProfileRegistry.OWL_LANG, NS + "p" ) {
243             public OntResource doCreate( OntModel m ) { return m.createInverseFunctionalProperty( NS + "p" ); }
244             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
245                                                                  r instanceof InverseFunctionalProperty;
246                                                         }
247         },
248         new CreateTestCase( "OWL create inverse functional property non-F", ProfileRegistry.OWL_LANG, NS + "p" ) {
249             public OntResource doCreate( OntModel m ) { return m.createInverseFunctionalProperty( NS + "p", false ); }
250             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
251                                                                  r instanceof InverseFunctionalProperty &&
252                                                                  !r.canAs( FunctionalProperty.class );
253                                                         }
254         },
255         new CreateTestCase( "OWL create inverse functional property F", ProfileRegistry.OWL_LANG, NS + "p" ) {
256             public OntResource doCreate( OntModel m ) { return m.createInverseFunctionalProperty( NS + "p", true ); }
257             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
258                                                                  r instanceof InverseFunctionalProperty &&
259                                                                  r.canAs( FunctionalProperty.class );
260                                                         }
261         },
262         
263         new CreateTestCase( "OWL create datatype property", ProfileRegistry.OWL_LANG, NS + "p" ) {
264             public OntResource doCreate( OntModel m ) { return m.createDatatypeProperty( NS + "p" ); }
265             public boolean test( OntResource r ) { return r instanceof DatatypeProperty;}
266         },
267         new CreateTestCase( "OWL create datatype property non-F", ProfileRegistry.OWL_LANG, NS + "p" ) {
268             public OntResource doCreate( OntModel m ) { return m.createDatatypeProperty( NS + "p", false ); }
269             public boolean test( OntResource r ) { return r instanceof DatatypeProperty && !r.canAs( FunctionalProperty.class );}
270         },
271         new CreateTestCase( "OWL create datatype property F", ProfileRegistry.OWL_LANG, NS + "p" ) {
272             public OntResource doCreate( OntModel m ) { return m.createDatatypeProperty( NS + "p", true ); }
273             public boolean test( OntResource r ) { return r instanceof DatatypeProperty && r.canAs( FunctionalProperty.class );}
274         },
275         
276         new CreateTestCase( "OWL create annotation property", ProfileRegistry.OWL_LANG, NS + "p" ) {
277             public OntResource doCreate( OntModel m ) { return m.createAnnotationProperty( NS + "p" ); }
278             public boolean test( OntResource r ) { return r instanceof AnnotationProperty;}
279         },
280         
281         // DAML property types
282
new CreateTestCase( "DAML create object property", ProfileRegistry.DAML_LANG, NS + "p" ) {
283             public OntResource doCreate( OntModel m ) { return m.createObjectProperty( NS + "p" ); }
284             public boolean test( OntResource r ) { return r instanceof ObjectProperty;}
285         },
286         new CreateTestCase( "DAML create object property non-F", ProfileRegistry.DAML_LANG, NS + "p" ) {
287             public OntResource doCreate( OntModel m ) { return m.createObjectProperty( NS + "p", false ); }
288             public boolean test( OntResource r ) { return r instanceof ObjectProperty && !r.canAs( FunctionalProperty.class );}
289         },
290         new CreateTestCase( "DAML create object property F", ProfileRegistry.DAML_LANG, NS + "p" ) {
291             public OntResource doCreate( OntModel m ) { return m.createObjectProperty( NS + "p", true ); }
292             public boolean test( OntResource r ) { return r instanceof ObjectProperty && r.canAs( FunctionalProperty.class );}
293         },
294         
295         new CreateTestCase( "DAML create transitive property", ProfileRegistry.DAML_LANG, NS + "p" ) {
296             public OntResource doCreate( OntModel m ) { return m.createTransitiveProperty( NS + "p" ); }
297             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
298                                                                  r instanceof TransitiveProperty;
299                                                         }
300         },
301         new CreateTestCase( "DAML create transitive property non-F", ProfileRegistry.DAML_LANG, NS + "p" ) {
302             public OntResource doCreate( OntModel m ) { return m.createTransitiveProperty( NS + "p", false ); }
303             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
304                                                                  r instanceof TransitiveProperty &&
305                                                                  !r.canAs( FunctionalProperty.class );
306                                                         }
307         },
308         new CreateTestCase( "DAML create transitive property F", ProfileRegistry.DAML_LANG, NS + "p" ) {
309             public OntResource doCreate( OntModel m ) { return m.createTransitiveProperty( NS + "p", true ); }
310             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
311                                                                  r instanceof TransitiveProperty &&
312                                                                  r.canAs( FunctionalProperty.class );
313                                                         }
314         },
315         new CreateTestCase( "DAML create inverse functional property", ProfileRegistry.DAML_LANG, NS + "p" ) {
316             public OntResource doCreate( OntModel m ) { return m.createInverseFunctionalProperty( NS + "p" ); }
317             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
318                                                                  r instanceof InverseFunctionalProperty;
319                                                         }
320         },
321         new CreateTestCase( "DAML create inverse functional property non-F", ProfileRegistry.DAML_LANG, NS + "p" ) {
322             public OntResource doCreate( OntModel m ) { return m.createInverseFunctionalProperty( NS + "p", false ); }
323             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
324                                                                  r instanceof InverseFunctionalProperty &&
325                                                                  !r.canAs( FunctionalProperty.class );
326                                                         }
327         },
328         new CreateTestCase( "DAML create inverse functional property F", ProfileRegistry.DAML_LANG, NS + "p" ) {
329             public OntResource doCreate( OntModel m ) { return m.createInverseFunctionalProperty( NS + "p", true ); }
330             public boolean test( OntResource r ) { return r instanceof ObjectProperty &&
331                                                                  r instanceof InverseFunctionalProperty &&
332                                                                  r.canAs( FunctionalProperty.class );
333                                                         }
334         },
335         
336         new CreateTestCase( "DAML create datatype property", ProfileRegistry.DAML_LANG, NS + "p" ) {
337             public OntResource doCreate( OntModel m ) { return m.createDatatypeProperty( NS + "p" ); }
338             public boolean test( OntResource r ) { return r instanceof DatatypeProperty;}
339         },
340         new CreateTestCase( "DAML create datatype property non-F", ProfileRegistry.DAML_LANG, NS + "p" ) {
341             public OntResource doCreate( OntModel m ) { return m.createDatatypeProperty( NS + "p", false ); }
342             public boolean test( OntResource r ) { return r instanceof DatatypeProperty && !r.canAs( FunctionalProperty.class );}
343         },
344         new CreateTestCase( "DAML create datatype property F", ProfileRegistry.DAML_LANG, NS + "p" ) {
345             public OntResource doCreate( OntModel m ) { return m.createDatatypeProperty( NS + "p", true ); }
346             public boolean test( OntResource r ) { return r instanceof DatatypeProperty && r.canAs( FunctionalProperty.class );}
347         },
348         
349         new CreateTestCase( "OWL create allDifferent", ProfileRegistry.OWL_LANG, null ) {
350             public OntResource doCreate( OntModel m ) { return m.createAllDifferent(); }
351             public boolean test( OntResource r ) { return r instanceof AllDifferent;}
352         },
353         
354         // Restrictions
355

356         new CreateTestCase( "OWL create restriction", ProfileRegistry.OWL_LANG, NS + "C" ) {
357             public OntResource doCreate( OntModel m ) { return m.createRestriction( NS + "C", null ); }
358             public boolean test( OntResource r ) { return r instanceof Restriction;}
359         },
360         new CreateTestCase( "OWL create anon restriction", ProfileRegistry.OWL_LANG, null ) {
361             public OntResource doCreate( OntModel m ) { return m.createRestriction( null ); }
362             public boolean test( OntResource r ) { return r instanceof Restriction;}
363         },
364         
365         new CreateTestCase( "OWL create has value restriction", ProfileRegistry.OWL_LANG, null ) {
366             public OntResource doCreate( OntModel m ) {
367                 Property p = m.createObjectProperty( NS + "p" );
368                 Resource x = m.createResource( NS + "x" );
369                 return m.createHasValueRestriction( null, p, x );
370             }
371             public boolean test( OntResource r ) { return r instanceof HasValueRestriction;}
372         },
373         new CreateTestCase( "OWL create has value restriction (literal)", ProfileRegistry.OWL_LANG, null ) {
374             public OntResource doCreate( OntModel m ) {
375                 Property p = m.createDatatypeProperty( NS + "p" );
376                 Literal x = m.createTypedLiteral( new Integer JavaDoc( 42 ) );
377                 return m.createHasValueRestriction( null, p, x );
378             }
379             public boolean test( OntResource r ) { return r instanceof HasValueRestriction;}
380         },
381         new CreateTestCase( "OWL create all values from restriction", ProfileRegistry.OWL_LANG, null ) {
382             public OntResource doCreate( OntModel m ) {
383                 Property p = m.createObjectProperty( NS + "p" );
384                 OntClass c = m.createClass( NS + "C" );
385                 return m.createAllValuesFromRestriction( null, p, c );
386             }
387             public boolean test( OntResource r ) { return r instanceof AllValuesFromRestriction;}
388         },
389         new CreateTestCase( "OWL create some values from restriction", ProfileRegistry.OWL_LANG, null ) {
390             public OntResource doCreate( OntModel m ) {
391                 Property p = m.createObjectProperty( NS + "p" );
392                 OntClass c = m.createClass( NS + "C" );
393                 return m.createSomeValuesFromRestriction( null, p, c );
394             }
395             public boolean test( OntResource r ) { return r instanceof SomeValuesFromRestriction;}
396         },
397         new CreateTestCase( "OWL create cardinality restriction", ProfileRegistry.OWL_LANG, null ) {
398             public OntResource doCreate( OntModel m ) {
399                 Property p = m.createObjectProperty( NS + "p" );
400                 return m.createCardinalityRestriction( null, p, 17 );
401             }
402             public boolean test( OntResource r ) { return r instanceof CardinalityRestriction;}
403         },
404         new CreateTestCase( "OWL create min cardinality restriction", ProfileRegistry.OWL_LANG, null ) {
405             public OntResource doCreate( OntModel m ) {
406                 Property p = m.createObjectProperty( NS + "p" );
407                 return m.createMinCardinalityRestriction( null, p, 1 );
408             }
409             public boolean test( OntResource r ) { return r instanceof MinCardinalityRestriction;}
410         },
411         new CreateTestCase( "OWL create max cardinality restriction", ProfileRegistry.OWL_LANG, null ) {
412             public OntResource doCreate( OntModel m ) {
413                 Property p = m.createObjectProperty( NS + "p" );
414                 return m.createMaxCardinalityRestriction( null, p, 4 );
415             }
416             public boolean test( OntResource r ) { return r instanceof MaxCardinalityRestriction;}
417         },
418         
419         new CreateTestCase( "DAML create restriction", ProfileRegistry.DAML_LANG, NS + "C" ) {
420             public OntResource doCreate( OntModel m ) { return m.createRestriction( NS + "C", null ); }
421             public boolean test( OntResource r ) { return r instanceof Restriction;}
422         },
423         new CreateTestCase( "DAML create anon restriction", ProfileRegistry.DAML_LANG, null ) {
424             public OntResource doCreate( OntModel m ) { return m.createRestriction( null ); }
425             public boolean test( OntResource r ) { return r instanceof Restriction;}
426         },
427         
428         new CreateTestCase( "DAML create has value restriction", ProfileRegistry.DAML_LANG, null ) {
429             public OntResource doCreate( OntModel m ) {
430                 Property p = m.createObjectProperty( NS + "p" );
431                 Resource x = m.createResource( NS + "x" );
432                 return m.createHasValueRestriction( null, p, x );
433             }
434             public boolean test( OntResource r ) { return r instanceof HasValueRestriction;}
435         },
436         new CreateTestCase( "DAML create has value restriction (literal)", ProfileRegistry.DAML_LANG, null ) {
437             public OntResource doCreate( OntModel m ) {
438                 Property p = m.createDatatypeProperty( NS + "p" );
439                 Literal x = m.createTypedLiteral( new Integer JavaDoc( 42 ) );
440                 return m.createHasValueRestriction( null, p, x );
441             }
442             public boolean test( OntResource r ) { return r instanceof HasValueRestriction;}
443         },
444         new CreateTestCase( "DAML create all values from restriction", ProfileRegistry.DAML_LANG, null ) {
445             public OntResource doCreate( OntModel m ) {
446                 Property p = m.createObjectProperty( NS + "p" );
447                 OntClass c = m.createClass( NS + "C" );
448                 return m.createAllValuesFromRestriction( null, p, c );
449             }
450             public boolean test( OntResource r ) { return r instanceof AllValuesFromRestriction;}
451         },
452         new CreateTestCase( "DAML create some values from restriction", ProfileRegistry.DAML_LANG, null ) {
453             public OntResource doCreate( OntModel m ) {
454                 Property p = m.createObjectProperty( NS + "p" );
455                 OntClass c = m.createClass( NS + "C" );
456                 return m.createSomeValuesFromRestriction( null, p, c );
457             }
458             public boolean test( OntResource r ) { return r instanceof SomeValuesFromRestriction;}
459         },
460         new CreateTestCase( "DAML create cardinality restriction", ProfileRegistry.DAML_LANG, null ) {
461             public OntResource doCreate( OntModel m ) {
462                 Property p = m.createObjectProperty( NS + "p" );
463                 return m.createCardinalityRestriction( null, p, 17 );
464             }
465             public boolean test( OntResource r ) { return r instanceof CardinalityRestriction;}
466         },
467         new CreateTestCase( "DAML create min cardinality restriction", ProfileRegistry.DAML_LANG, null ) {
468             public OntResource doCreate( OntModel m ) {
469                 Property p = m.createObjectProperty( NS + "p" );
470                 return m.createMinCardinalityRestriction( null, p, 1 );
471             }
472             public boolean test( OntResource r ) { return r instanceof MinCardinalityRestriction;}
473         },
474         new CreateTestCase( "DAML create max cardinality restriction", ProfileRegistry.DAML_LANG, null ) {
475             public OntResource doCreate( OntModel m ) {
476                 Property p = m.createObjectProperty( NS + "p" );
477                 return m.createMaxCardinalityRestriction( null, p, 4 );
478             }
479             public boolean test( OntResource r ) { return r instanceof MaxCardinalityRestriction;}
480         },
481         
482     };
483     
484     // Instance variables
485
//////////////////////////////////
486

487     // Constructors
488
//////////////////////////////////
489

490     public TestCreate( String JavaDoc name ) {
491         super( name );
492     }
493     
494     
495     // External signature methods
496
//////////////////////////////////
497

498     protected String JavaDoc getTestName() {
499         return "TestCreate";
500     }
501     
502     public static TestSuite suite() {
503         TestSuite s = new TestSuite( "TestCreate" );
504         
505         for (int i = 0; i < testCases.length; i++) {
506             s.addTest( testCases[i] );
507         }
508         
509         return s;
510     }
511
512     
513     
514     // Internal implementation methods
515
//////////////////////////////////
516

517     //==============================================================================
518
// Inner class definitions
519
//==============================================================================
520

521     protected static class CreateTestCase
522         extends TestCase
523     {
524         protected String JavaDoc m_lang;
525         protected String JavaDoc m_uri;
526         
527         public CreateTestCase( String JavaDoc name, String JavaDoc lang, String JavaDoc uri ) {
528             super( name );
529             m_lang = lang;
530             m_uri = uri;
531         }
532         
533         public void runTest() {
534             OntModel m = ModelFactory.createOntologyModel( m_lang );
535             
536             // do the creation step
537
OntResource r = doCreate( m );
538             assertNotNull( "Result of creation step should not be null", r );
539             
540             if (m_uri == null) {
541                 assertTrue( "Created resource should be anonymous", r.isAnon() );
542             }
543             else {
544                 assertEquals( "Created resource has wrong uri", m_uri, r.getURI() );
545             }
546             
547             assertTrue( "Result test failed", test( r ));
548         }
549         
550         public void setUp() {
551             // ensure the ont doc manager is in a consistent state
552
OntDocumentManager.getInstance().reset( true );
553         }
554         
555         
556         /* get the resource */
557         public OntResource doCreate( OntModel m ) {
558             // to be overridden in sub-classes
559
return null;
560         }
561         
562         /* test the Java type of the result, and other tests */
563         public boolean test( OntResource r ) {
564             return true;
565         }
566         
567     }
568 }
569
570
571 /*
572     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
573     All rights reserved.
574
575     Redistribution and use in source and binary forms, with or without
576     modification, are permitted provided that the following conditions
577     are met:
578
579     1. Redistributions of source code must retain the above copyright
580        notice, this list of conditions and the following disclaimer.
581
582     2. Redistributions in binary form must reproduce the above copyright
583        notice, this list of conditions and the following disclaimer in the
584        documentation and/or other materials provided with the distribution.
585
586     3. The name of the author may not be used to endorse or promote products
587        derived from this software without specific prior written permission.
588
589     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
590     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
591     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
592     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
593     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
594     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
595     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
596     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
597     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
598     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
599 */

600
Popular Tags