1 19 20 package com.hp.hpl.jena.ontology.impl.test; 23 24 25 import junit.framework.TestSuite; 28 29 import com.hp.hpl.jena.ontology.*; 30 31 32 41 public class TestOntology 42 extends OntTestBase 43 { 44 47 50 51 52 55 58 static public TestSuite suite() { 59 return new TestOntology( "TestOntology" ); 60 } 61 62 public TestOntology( String name ) { 63 super( name ); 64 } 65 66 67 68 69 72 public OntTestCase[] getTests() { 73 return new OntTestCase[] { 74 new OntTestCase( "Ontology.imports", true, true, true, false ) { 75 public void ontTest( OntModel m ) throws Exception { 76 Profile prof = m.getProfile(); 77 Ontology x = m.createOntology( NS + "x" ); 78 Ontology y = m.createOntology( NS + "y" ); 79 Ontology z = m.createOntology( NS + "z" ); 80 81 x.addImport( y ); 82 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) ); 83 assertEquals( "x should import y", y, x.getImport() ); 84 85 x.addImport( z ); 86 assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.IMPORTS() ) ); 87 iteratorTest( x.listImports(), new Object [] {y,z} ); 88 89 x.setImport( z ); 90 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) ); 91 assertEquals( "x should import z", z, x.getImport() ); 92 93 x.removeImport( y ); 94 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) ); 95 x.removeImport( z ); 96 assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.IMPORTS() ) ); 97 } 98 }, 99 new OntTestCase( "Ontology.backwardCompatibleWith", true, true, false, false ) { 100 public void ontTest( OntModel m ) throws Exception { 101 Profile prof = m.getProfile(); 102 Ontology x = m.createOntology( NS + "x" ); 103 Ontology y = m.createOntology( NS + "y" ); 104 Ontology z = m.createOntology( NS + "z" ); 105 106 x.addBackwardCompatibleWith( y ); 107 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); 108 assertEquals( "x should be back comp with y", y, x.getBackwardCompatibleWith() ); 109 110 x.addBackwardCompatibleWith( z ); 111 assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); 112 iteratorTest( x.listBackwardCompatibleWith(), new Object [] {y,z} ); 113 114 x.setBackwardCompatibleWith( z ); 115 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); 116 assertEquals( "x should be back comp with z", z, x.getBackwardCompatibleWith() ); 117 118 x.removeBackwardCompatibleWith( y ); 119 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); 120 x.removeBackwardCompatibleWith( z ); 121 assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); 122 } 123 }, 124 new OntTestCase( "Ontology.priorVersion", true, true, false, false ) { 125 public void ontTest( OntModel m ) throws Exception { 126 Profile prof = m.getProfile(); 127 Ontology x = m.createOntology( NS + "x" ); 128 Ontology y = m.createOntology( NS + "y" ); 129 Ontology z = m.createOntology( NS + "z" ); 130 131 x.addPriorVersion( y ); 132 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) ); 133 assertEquals( "x should have prior y", y, x.getPriorVersion() ); 134 135 x.addPriorVersion( z ); 136 assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.PRIOR_VERSION() ) ); 137 iteratorTest( x.listPriorVersion(), new Object [] {y,z} ); 138 139 x.setPriorVersion( z ); 140 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) ); 141 assertEquals( "x should have prior z", z, x.getPriorVersion() ); 142 143 x.removePriorVersion( y ); 144 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) ); 145 x.removePriorVersion( z ); 146 assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.PRIOR_VERSION() ) ); 147 } 148 }, 149 new OntTestCase( "Ontology.incompatibleWith", true, true, false, false ) { 150 public void ontTest( OntModel m ) throws Exception { 151 Profile prof = m.getProfile(); 152 Ontology x = m.createOntology( NS + "x" ); 153 Ontology y = m.createOntology( NS + "y" ); 154 Ontology z = m.createOntology( NS + "z" ); 155 156 x.addIncompatibleWith( y ); 157 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); 158 assertEquals( "x should be in comp with y", y, x.getIncompatibleWith() ); 159 160 x.addIncompatibleWith( z ); 161 assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); 162 iteratorTest( x.listIncompatibleWith(), new Object [] {y,z} ); 163 164 x.setIncompatibleWith( z ); 165 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); 166 assertEquals( "x should be incomp with z", z, x.getIncompatibleWith() ); 167 168 x.removeIncompatibleWith( y ); 169 assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); 170 x.removeIncompatibleWith( z ); 171 assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); 172 } 173 }, 174 }; 175 } 176 177 180 184 } 185 186 187 216 217 218 | Popular Tags |