1 19 20 package com.hp.hpl.jena.ontology.daml.impl.test; 23 24 25 26 import junit.framework.*; 29 30 import com.hp.hpl.jena.ontology.daml.*; 31 import com.hp.hpl.jena.rdf.model.*; 32 import com.hp.hpl.jena.vocabulary.DAML_OIL; 33 import com.hp.hpl.jena.vocabulary.RDFS; 34 35 36 37 46 public class TestDAMLClass 47 extends DAMLTestBase 48 { 49 52 55 58 61 static public TestSuite suite() { 62 return new TestDAMLClass( "TestDAMLClass" ); 63 } 64 65 public TestDAMLClass( String name ) { 66 super( name ); 67 } 68 69 70 73 public OntTestCase[] getTests() { 74 return new OntTestCase[] { 75 new OntTestCase( "DAMLClass.prop_subClassOf" ) { 76 public void doTest( DAMLModel m ) throws Exception { 77 DAMLClass A = m.createDAMLClass( NS + "A" ); 78 DAMLClass B = m.createDAMLClass( NS + "B" ); 79 DAMLClass C = m.createDAMLClass( NS + "C" ); 80 81 assertEquals( "prop_subClassOf property", RDFS.subClassOf, A.prop_subClassOf().getProperty() ); 82 83 assertEquals( "sub-class cardinality", 2, A.prop_subClassOf().count() ); 84 A.prop_subClassOf().add( B ); 85 iteratorTest( A.prop_subClassOf().getAll(), new Object [] {A,B,DAML_OIL.Thing} ); 86 assertEquals( "sub-class cardinality", 3, A.prop_subClassOf().count() ); 87 A.prop_subClassOf().add( C ); 88 assertEquals( "sub-class cardinality", 4, A.prop_subClassOf().count() ); 89 90 iteratorTest( A.prop_subClassOf().getAll(), new Object [] {A,B,C,DAML_OIL.Thing} ); 91 92 A.prop_subClassOf().remove( C ); 93 assertEquals( "sub-class cardinality", 3, A.prop_subClassOf().count() ); 94 95 iteratorTest( A.prop_subClassOf().getAll(), new Object [] {A,B,DAML_OIL.Thing} ); 96 97 assertTrue( "hasValue", A.prop_subClassOf().hasValue( B ) ); 98 assertTrue( "hasValue", !A.prop_subClassOf().hasValue( C ) ); 99 } 100 }, 101 new OntTestCase( "DAMLClass.prop_disjointWith" ) { 102 public void doTest( DAMLModel m ) throws Exception { 103 DAMLClass A = m.createDAMLClass( NS + "A" ); 104 DAMLClass B = m.createDAMLClass( NS + "B" ); 105 DAMLClass C = m.createDAMLClass( NS + "C" ); 106 107 assertEquals( "prop_disjointwith property", DAML_OIL.disjointWith, A.prop_disjointWith().getProperty() ); 108 109 assertEquals( "disjointWith cardinality", 0, A.prop_disjointWith().count() ); 110 A.prop_disjointWith().add( B ); 111 assertEquals( "disjointwith cardinality", 1, A.prop_disjointWith().count() ); 112 A.prop_disjointWith().add( C ); 113 assertEquals( "disjointWith cardinality", 2, A.prop_disjointWith().count() ); 114 115 iteratorTest( A.prop_disjointWith().getAll(), new Object [] {B,C} ); 116 117 A.prop_disjointWith().remove( C ); 118 assertEquals( "disjointwith cardinality", 1, A.prop_disjointWith().count() ); 119 120 iteratorTest( A.prop_disjointWith().getAll(), new Object [] {B} ); 121 122 assertTrue( "hasValue", A.prop_disjointWith().hasValue( B ) ); 123 assertTrue( "hasValue", !A.prop_disjointWith().hasValue( C ) ); 124 } 125 }, 126 new OntTestCase( "DAMLClass.prop_sameClassAs" ) { 127 public void doTest( DAMLModel m ) throws Exception { 128 DAMLClass A = m.createDAMLClass( NS + "A" ); 129 DAMLClass B = m.createDAMLClass( NS + "B" ); 130 DAMLClass C = m.createDAMLClass( NS + "C" ); 131 132 assertEquals( "prop_sameClassAs property", DAML_OIL.sameClassAs, A.prop_sameClassAs().getProperty() ); 133 134 assertEquals( "sameClassAs cardinality", 0, A.prop_sameClassAs().count() ); 135 A.prop_sameClassAs().add( B ); 136 assertEquals( "sameClassAs cardinality", 1, A.prop_sameClassAs().count() ); 137 A.prop_sameClassAs().add( C ); 138 assertEquals( "sameClassAs cardinality", 2, A.prop_sameClassAs().count() ); 139 140 iteratorTest( A.prop_sameClassAs().getAll(), new Object [] {B,C} ); 141 142 A.prop_sameClassAs().remove( C ); 143 assertEquals( "sameClassAs cardinality", 1, A.prop_sameClassAs().count() ); 144 145 iteratorTest( A.prop_sameClassAs().getAll(), new Object [] {B} ); 146 147 assertTrue( "hasValue", A.prop_sameClassAs().hasValue( B ) ); 148 assertTrue( "hasValue", !A.prop_sameClassAs().hasValue( C ) ); 149 } 150 }, 151 new OntTestCase( "DAMLClass.prop_complementOf" ) { 152 public void doTest( DAMLModel m ) throws Exception { 153 DAMLClass A = m.createDAMLClass( NS + "A" ); 154 DAMLClass B = m.createDAMLClass( NS + "B" ); 155 DAMLClass C = m.createDAMLClass( NS + "C" ); 156 157 assertEquals( "prop_complementOf property", DAML_OIL.complementOf, A.prop_complementOf().getProperty() ); 158 159 assertEquals( "complementOf cardinality", 0, A.prop_complementOf().count() ); 160 A.prop_complementOf().add( B ); 161 assertEquals( "complementOf cardinality", 1, A.prop_complementOf().count() ); 162 A.prop_complementOf().add( C ); 163 assertEquals( "complementOf cardinality", 2, A.prop_complementOf().count() ); 164 165 iteratorTest( A.prop_complementOf().getAll(), new Object [] {B,C} ); 166 167 A.prop_complementOf().remove( C ); 168 assertEquals( "complementOf cardinality", 1, A.prop_complementOf().count() ); 169 170 iteratorTest( A.prop_complementOf().getAll(), new Object [] {B} ); 171 172 assertTrue( "hasValue", A.prop_complementOf().hasValue( B ) ); 173 assertTrue( "hasValue", !A.prop_complementOf().hasValue( C ) ); 174 } 175 }, 176 new OntTestCase( "DAMLClass.getSubClasses" ) { 177 public void doTest( DAMLModel m ) throws Exception { 178 DAMLClass A = m.createDAMLClass( NS + "A" ); 179 DAMLClass B = m.createDAMLClass( NS + "B" ); 180 DAMLClass C = m.createDAMLClass( NS + "C" ); 181 182 C.prop_subClassOf().add( B ); 183 B.prop_subClassOf().add( A ); 184 185 assertEquals( "subClassOf A", B, A.getSubClass() ); 186 187 iteratorTest( A.getSubClasses(), new Object [] {B,C} ); 188 iteratorTest( A.getSubClasses( false ), new Object [] {B} ); 189 iteratorTest( A.getSubClasses( true ), new Object [] {B,C} ); 190 } 191 }, 192 new OntTestCase( "DAMLClass.getSuperClasses" ) { 193 public void doTest( DAMLModel m ) throws Exception { 194 DAMLClass A = m.createDAMLClass( NS + "A" ); 195 DAMLClass B = m.createDAMLClass( NS + "B" ); 196 DAMLClass C = m.createDAMLClass( NS + "C" ); 197 198 A.prop_subClassOf().add( B ); 199 B.prop_subClassOf().add( C ); 200 201 iteratorTest( A.getSuperClasses(), new Object [] {B,C,DAML_OIL.Thing} ); 202 iteratorTest( A.getSuperClasses( false ), new Object [] {B} ); 203 iteratorTest( A.getSuperClasses( true ), new Object [] {B,C,DAML_OIL.Thing} ); 204 } 205 }, 206 new OntTestCase( "DAMLClass.getSameClasses" ) { 207 public void doTest( DAMLModel m ) throws Exception { 208 DAMLClass A = m.createDAMLClass( NS + "A" ); 209 DAMLClass B = m.createDAMLClass( NS + "B" ); 210 DAMLClass C = m.createDAMLClass( NS + "C" ); 211 212 A.prop_sameClassAs().add( B ); 213 B.prop_sameClassAs().add( C ); 214 215 iteratorTest( A.getSameClasses(), new Object [] {B} ); 217 218 A.prop_sameClassAs().add( C ); 220 iteratorTest( A.getSameClasses(), new Object [] {B,C} ); 221 } 222 }, 223 new OntTestCase( "DAMLClass.getInstances" ) { 224 public void doTest( DAMLModel m ) throws Exception { 225 DAMLClass A = m.createDAMLClass( NS + "A" ); 226 DAMLInstance a = m.createDAMLInstance( A, NS + "a" ); 227 DAMLInstance b = m.createDAMLInstance( A, NS + "b" ); 228 DAMLInstance c = m.createDAMLInstance( A, NS + "c" ); 229 230 iteratorTest( A.getInstances(), new Object [] {a,b,c} ); 231 } 232 }, 233 new OntTestCase( "DAMLClass.disjointUnionOf" ) { 234 public void doTest( DAMLModel m ) throws Exception { 235 DAMLClass A = m.createDAMLClass( NS + "A" ); 236 DAMLClass B = m.createDAMLClass( NS + "B" ); 237 DAMLClass C = m.createDAMLClass( NS + "C" ); 238 DAMLClass D = m.createDAMLClass( NS + "D" ); 239 240 assertEquals( "prop_disjointUnionOf property", DAML_OIL.disjointUnionOf, A.prop_disjointUnionOf().getProperty() ); 241 242 assertEquals( "disjointUnionOf cardinality", 0, A.prop_disjointUnionOf().count() ); 243 A.prop_disjointUnionOf().add( m.createDAMLList( new RDFNode[] {B,C} ) ); 244 245 assertEquals( "disjointUnionOf cardinality", 1, A.prop_disjointUnionOf().count() ); 246 247 iteratorTest( A.prop_disjointUnionOf().getList().getAll(), new Object [] {B,C} ); 248 A.prop_disjointUnionOf().getList().add( D ); 249 iteratorTest( A.prop_disjointUnionOf().getList().getAll(), new Object [] {B,C,D} ); 250 251 assertTrue( "contains", A.prop_disjointUnionOf().getList().contains( D ) ); 252 assertTrue( "contains", A.prop_disjointUnionOf().getList().contains( B ) ); 253 assertTrue( "contains", A.prop_disjointUnionOf().getList().contains( C ) ); 254 } 255 }, 256 new OntTestCase( "DAMLClass.unionOf" ) { 257 public void doTest( DAMLModel m ) throws Exception { 258 DAMLClass A = m.createDAMLClass( NS + "A" ); 259 DAMLClass B = m.createDAMLClass( NS + "B" ); 260 DAMLClass C = m.createDAMLClass( NS + "C" ); 261 DAMLClass D = m.createDAMLClass( NS + "D" ); 262 263 assertEquals( "prop_unionOf property", DAML_OIL.unionOf, A.prop_unionOf().getProperty() ); 264 265 assertEquals( "unionOf cardinality", 0, A.prop_unionOf().count() ); 266 A.prop_unionOf().add( m.createDAMLList( new RDFNode[] {B,C} ) ); 267 268 assertEquals( "unionOf cardinality", 1, A.prop_unionOf().count() ); 269 270 iteratorTest( A.prop_unionOf().getList().getAll(), new Object [] {B,C} ); 271 A.prop_unionOf().getList().add( D ); 272 iteratorTest( A.prop_unionOf().getList().getAll(), new Object [] {B,C,D} ); 273 274 assertTrue( "contains", A.prop_unionOf().getList().contains( D ) ); 275 assertTrue( "contains", A.prop_unionOf().getList().contains( B ) ); 276 assertTrue( "contains", A.prop_unionOf().getList().contains( C ) ); 277 } 278 }, 279 new OntTestCase( "DAMLClass.intersectionOf" ) { 280 public void doTest( DAMLModel m ) throws Exception { 281 DAMLClass A = m.createDAMLClass( NS + "A" ); 282 DAMLClass B = m.createDAMLClass( NS + "B" ); 283 DAMLClass C = m.createDAMLClass( NS + "C" ); 284 DAMLClass D = m.createDAMLClass( NS + "D" ); 285 286 assertEquals( "prop_intersectionOf property", DAML_OIL.intersectionOf, A.prop_intersectionOf().getProperty() ); 287 288 assertEquals( "intersectionOf cardinality", 0, A.prop_intersectionOf().count() ); 289 A.prop_intersectionOf().add( m.createDAMLList( new RDFNode[] {B,C} ) ); 290 291 assertEquals( "intersectionOf cardinality", 1, A.prop_intersectionOf().count() ); 292 293 iteratorTest( A.prop_intersectionOf().getList().getAll(), new Object [] {B,C} ); 294 A.prop_intersectionOf().getList().add( D ); 295 iteratorTest( A.prop_intersectionOf().getList().getAll(), new Object [] {B,C,D} ); 296 297 assertTrue( "contains", A.prop_intersectionOf().getList().contains( D ) ); 298 assertTrue( "contains", A.prop_intersectionOf().getList().contains( B ) ); 299 assertTrue( "contains", A.prop_intersectionOf().getList().contains( C ) ); 300 } 301 }, 302 new OntTestCase( "DAMLClass.oneOf" ) { 303 public void doTest( DAMLModel m ) throws Exception { 304 DAMLClass A = m.createDAMLClass( NS + "A" ); 305 DAMLClass B = m.createDAMLClass( NS + "B" ); 306 DAMLClass C = m.createDAMLClass( NS + "C" ); 307 DAMLClass D = m.createDAMLClass( NS + "D" ); 308 309 assertEquals( "prop_oneOf property", DAML_OIL.oneOf, A.prop_oneOf().getProperty() ); 310 311 assertEquals( "oneOf cardinality", 0, A.prop_oneOf().count() ); 312 A.prop_oneOf().add( m.createDAMLList( new RDFNode[] {B,C} ) ); 313 314 assertEquals( "oneOf cardinality", 1, A.prop_oneOf().count() ); 315 316 iteratorTest( A.prop_oneOf().getList().getAll(), new Object [] {B,C} ); 317 A.prop_oneOf().getList().add( D ); 318 iteratorTest( A.prop_oneOf().getList().getAll(), new Object [] {B,C,D} ); 319 320 assertTrue( "contains", A.prop_oneOf().getList().contains( D ) ); 321 assertTrue( "contains", A.prop_oneOf().getList().contains( B ) ); 322 assertTrue( "contains", A.prop_oneOf().getList().contains( C ) ); 323 } 324 }, 325 new OntTestCase( "DAMLClass.getDefinedProperties" ) { 326 public void doTest( DAMLModel m ) throws Exception { 327 DAMLClass A = m.createDAMLClass( NS + "A" ); 328 DAMLClass B = m.createDAMLClass( NS + "B" ); 329 330 B.prop_subClassOf().add( A ); 331 332 DAMLObjectProperty p = m.createDAMLObjectProperty( NS + "p" ); 333 DAMLObjectProperty q = m.createDAMLObjectProperty( NS + "q" ); 334 DAMLObjectProperty r = m.createDAMLObjectProperty( NS + "r" ); 335 336 p.prop_domain().add( B ); 337 q.prop_domain().add( B ); 338 r.prop_domain().add( A ); 339 340 iteratorTest( A.getDefinedProperties(), new Object [] {r} ); 341 iteratorTest( B.getDefinedProperties(), new Object [] {p,q,r} ); } 343 }, 344 new OntTestCase( "DAMLRestriction.prop_onProperty" ) { 345 public void doTest( DAMLModel m ) throws Exception { 346 DAMLRestriction A = m.createDAMLRestriction( NS + "A" ); 347 DAMLObjectProperty p = m.createDAMLObjectProperty( NS + "p" ); 348 349 assertEquals( "prop_onProperty property", DAML_OIL.onProperty, A.prop_onProperty().getProperty() ); 350 351 assertEquals( "onProperty cardinality", 0, A.prop_onProperty().count() ); 352 A.prop_onProperty().add( p ); 353 354 assertEquals( "onProperty cardinality", 1, A.prop_onProperty().count() ); 355 356 iteratorTest( A.prop_onProperty().getAll(), new Object [] {p} ); 357 } 358 }, 359 new OntTestCase( "DAMLRestriction.prop_toClass" ) { 360 public void doTest( DAMLModel m ) throws Exception { 361 DAMLRestriction A = m.createDAMLRestriction( NS + "A" ); 362 DAMLClass B = m.createDAMLClass( NS + "B" ); 363 364 assertEquals( "prop_toClass property", DAML_OIL.toClass, A.prop_toClass().getProperty() ); 365 366 assertEquals( "toClass cardinality", 0, A.prop_toClass().count() ); 367 A.prop_toClass().add( B ); 368 369 assertEquals( "toClass cardinality", 1, A.prop_toClass().count() ); 370 371 iteratorTest( A.prop_toClass().getAll(), new Object [] {B} ); 372 } 373 }, 374 new OntTestCase( "DAMLRestriction.prop_hasClass" ) { 375 public void doTest( DAMLModel m ) throws Exception { 376 DAMLRestriction A = m.createDAMLRestriction( NS + "A" ); 377 DAMLClass B = m.createDAMLClass( NS + "B" ); 378 379 assertEquals( "prop_hasClass property", DAML_OIL.hasClass, A.prop_hasClass().getProperty() ); 380 381 assertEquals( "hasClass cardinality", 0, A.prop_hasClass().count() ); 382 A.prop_hasClass().add( B ); 383 384 assertEquals( "hasClass cardinality", 1, A.prop_hasClass().count() ); 385 386 iteratorTest( A.prop_hasClass().getAll(), new Object [] {B} ); 387 } 388 }, 389 new OntTestCase( "DAMLRestriction.prop_cardinality" ) { 390 public void doTest( DAMLModel m ) throws Exception { 391 DAMLRestriction A = m.createDAMLRestriction( NS + "A" ); 392 393 assertEquals( "prop_cardinality property", DAML_OIL.cardinality, A.prop_cardinality().getProperty() ); 394 395 assertEquals( "cardinality cardinality", 0, A.prop_cardinality().count() ); 396 A.prop_cardinality().addInt( 1 ); 397 398 assertEquals( "cardinality cardinality", 1, A.prop_cardinality().count() ); 399 400 assertEquals( "cardinality", 1, A.prop_cardinality().getInt() ); 401 } 402 }, 403 }; 404 } 405 406 409 413 } 414 415 416 445 | Popular Tags |