1 10 11 package com.hp.hpl.jena.reasoner.rulesys.test; 12 13 import java.util.Iterator ; 14 15 import junit.framework.TestCase; 16 17 import com.hp.hpl.jena.rdf.model.InfModel; 18 import com.hp.hpl.jena.rdf.model.Model; 19 import com.hp.hpl.jena.rdf.model.ModelFactory; 20 import com.hp.hpl.jena.reasoner.Reasoner; 21 import com.hp.hpl.jena.reasoner.ReasonerFactory; 22 import com.hp.hpl.jena.reasoner.ValidityReport; 23 import com.hp.hpl.jena.util.FileManager; 24 25 31 32 public class OWLConsistencyTest extends TestCase { 33 34 35 public static final String BASE_DIR = "file:testing/reasoners/owl/"; 36 37 38 protected String tbox; 39 40 41 protected String abox; 42 43 44 protected int expected; 45 46 47 protected ReasonerFactory rf; 48 49 50 public static final int INCONSISTENT = 1; 51 52 53 public static final int WARNINGS = 2; 54 55 56 public static final int CLEAN = 3; 57 58 59 protected Object culprit; 60 61 76 public OWLConsistencyTest(String tbox, String abox, int expected, 77 Object culprit) { 78 super(abox); 79 this.tbox = tbox; 80 this.abox = abox; 81 this.expected = expected; 82 this.culprit = culprit; 83 } 84 85 88 public OWLConsistencyTest(OWLConsistencyTest base, String reasonerName, 89 ReasonerFactory rf) { 90 super(reasonerName + ":" + base.abox); 91 this.tbox = base.tbox; 92 this.abox = base.abox; 93 this.expected = base.expected; 94 this.culprit = base.culprit; 95 this.rf = rf; 96 } 97 98 101 public void setReasonerFactory(ReasonerFactory rf) { 102 this.rf = rf; 103 } 104 105 111 public ValidityReport testResults() { 112 Model t = FileManager.get().loadModel(BASE_DIR + tbox); 113 Model a = FileManager.get().loadModel(BASE_DIR + abox); 114 Reasoner r = rf.create(null); 117 a.add(t); 118 InfModel im = ModelFactory.createInfModel(r, a); 119 return im.validate(); 120 } 121 122 128 public void runTest() { 129 ValidityReport report = testResults(); 130 switch (expected) { 131 case INCONSISTENT: 132 assertTrue("expected inconsistent", !report.isValid()); 133 break; 134 case WARNINGS: 135 assertTrue("expected just warnings but reports not valid", report 136 .isValid()); 137 assertFalse("expected warnings but reports clean", report.isClean()); 138 break; 139 case CLEAN: 140 assertTrue("expected clean", report.isClean()); 141 } 142 if (culprit != null) { 143 boolean foundit = false; 144 for (Iterator i = report.getReports(); i.hasNext();) { 145 ValidityReport.Report r = (ValidityReport.Report) i.next(); 146 if (r.getExtension() != null 147 && r.getExtension().equals(culprit)) { 148 foundit = true; 149 break; 150 } 151 } 152 if (!foundit) { 153 assertTrue("Expcted to find a culprint " + culprit, false); 154 } 155 } 156 } 157 158 } 159 160 188 | Popular Tags |