1 19 20 package com.hp.hpl.jena.ontology.daml.impl.test; 23 24 25 import com.hp.hpl.jena.ontology.daml.*; 28 import com.hp.hpl.jena.vocabulary.DAML_OIL; 29 30 import junit.framework.*; 31 32 33 42 public class TestDAMLProperty 43 extends DAMLTestBase 44 { 45 48 51 54 57 static public TestSuite suite() { 58 return new TestDAMLProperty( "TestDAMLProperty" ); 59 } 60 61 public TestDAMLProperty( String name ) { 62 super( name ); 63 } 64 65 66 69 public OntTestCase[] getTests() { 70 return new OntTestCase[] { 71 new OntTestCase( "DAMLProperty.unique" ) { 72 public void doTest( DAMLModel m ) throws Exception { 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 { 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 [] {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 [] {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 { 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 [] {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 [] {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 { 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 [] {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 [] {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 { 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 iteratorTest( p.getSubProperties(), new Object [] {q} ); 168 iteratorTest( p.getSubProperties( false ), new Object [] {q} ); 169 iteratorTest( p.getSubProperties( true ), new Object [] {q} ); 170 171 r.prop_subPropertyOf().add( p ); 173 iteratorTest( p.getSubProperties(), new Object [] {q,r} ); 174 iteratorTest( p.getSubProperties( false ), new Object [] {q} ); 175 iteratorTest( p.getSubProperties( true ), new Object [] {q,r} ); 176 } 177 }, 178 new OntTestCase( "DAMLProperty.getSuperProperties" ) { 179 public void doTest( DAMLModel m ) throws Exception { 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 iteratorTest( p.getSuperProperties(), new Object [] {q} ); 191 iteratorTest( p.getSuperProperties( false ), new Object [] {q} ); 192 iteratorTest( p.getSuperProperties( true ), new Object [] {q} ); 193 194 p.prop_subPropertyOf().add( r ); 196 iteratorTest( p.getSuperProperties(), new Object [] {q,r} ); 197 iteratorTest( p.getSuperProperties( false ), new Object [] {q} ); 198 iteratorTest( p.getSuperProperties( true ), new Object [] {q,r} ); 199 } 200 }, 201 new OntTestCase( "DAMLProperty.getSameProperties" ) { 202 public void doTest( DAMLModel m ) throws Exception { 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 iteratorTest( p.getSameProperties(), new Object [] {q} ); 212 213 p.prop_samePropertyAs().add( r ); 215 iteratorTest( p.getSameProperties(), new Object [] {q,r} ); 216 } 217 }, 218 new OntTestCase( "Datatype property" ) { 219 public void doTest( DAMLModel m ) throws Exception { 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 { 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 { 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 { 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 260 264 } 265 266 267 296 | Popular Tags |