1 10 package com.hp.hpl.jena.reasoner.test; 11 12 import com.hp.hpl.jena.reasoner.rulesys.RDFSRuleReasonerFactory; 14 import com.hp.hpl.jena.reasoner.rulesys.RDFSFBRuleReasonerFactory; 15 import com.hp.hpl.jena.reasoner.*; 16 import com.hp.hpl.jena.rdf.model.*; 17 import com.hp.hpl.jena.vocabulary.*; 18 19 import java.io.*; 20 import java.util.Iterator ; 21 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 34 public class TestRDFSReasoners extends ReasonerTestBase { 35 36 37 public static final String NAMESPACE = "http://www.hpl.hp.com/semweb/2003/query_tester/"; 38 39 protected static Log logger = LogFactory.getLog(TestReasoners.class); 40 41 44 public TestRDFSReasoners( String name ) { 45 super( name ); 46 } 47 48 52 public static TestSuite suite() { 53 TestSuite suite = new TestSuite(); 54 try { 55 59 constructQuerytests(suite, "rdfs/manifest-nodirect-noresource.rdf", RDFSFBRuleReasonerFactory.theInstance(), null); 63 64 Resource config = newResource().addProperty(ReasonerVocabulary.PROPenableCMPScan, true); 65 constructRDFWGtests(suite, RDFSRuleReasonerFactory.theInstance(), null); 67 constructQuerytests(suite, "rdfs/manifest-standard.rdf", RDFSRuleReasonerFactory.theInstance(), config); 68 69 suite.addTest(new TestRDFSMisc(RDFSRuleReasonerFactory.theInstance(), null)); 70 71 Resource configFull = newResource().addProperty(ReasonerVocabulary.PROPsetRDFSLevel, ReasonerVocabulary.RDFS_FULL); 72 constructQuerytests(suite, "rdfs/manifest.rdf", RDFSRuleReasonerFactory.theInstance(), configFull); 73 74 78 Resource configSimple = newResource().addProperty(ReasonerVocabulary.PROPsetRDFSLevel, ReasonerVocabulary.RDFS_SIMPLE); 79 constructQuerytests(suite, "rdfs/manifest-simple.rdf", RDFSRuleReasonerFactory.theInstance(), configSimple); 80 81 88 } catch (IOException e) { 89 logger.error("Failed to construct RDFS test harness", e); 91 } 92 return suite; 93 } 94 95 98 private static void constructSingleQuerytests(TestSuite suite, String manifest, String test, ReasonerFactory rf, Resource config) throws IOException { 99 ReasonerTester tester = new ReasonerTester(manifest); 100 Reasoner r = rf.create(config); 101 suite.addTest(new TestReasonerFromManifest(tester, test, r)); 102 } 103 104 107 private static void constructQuerytests(TestSuite suite, String manifest, ReasonerFactory rf, Resource config) throws IOException { 108 ReasonerTester tester = new ReasonerTester(manifest); 109 Reasoner r = rf.create(config); 110 for (Iterator i = tester.listTests().iterator(); i.hasNext(); ) { 111 String test = (String )i.next(); 112 suite.addTest(new TestReasonerFromManifest(tester, test, r)); 113 } 114 } 115 116 119 private static void constructRDFWGtests(TestSuite suite, ReasonerFactory rf, Resource config) throws IOException { 120 WGReasonerTester tester = new WGReasonerTester("Manifest.rdf"); 121 for (Iterator i = tester.listTests().iterator(); i.hasNext(); ) { 122 String test = (String )i.next(); 123 suite.addTest(new TestReasonerWG(tester, test, rf, config)); 124 } 125 } 126 127 128 131 public static void constructQuerytests(TestSuite suite, String manifest, Reasoner reasoner) throws IOException { 132 ReasonerTester tester = new ReasonerTester(manifest); 133 for (Iterator i = tester.listTests().iterator(); i.hasNext(); ) { 134 String test = (String )i.next(); 135 suite.addTest(new TestReasonerFromManifest(tester, test, reasoner)); 136 } 137 } 138 139 143 static class TestReasonerFromManifest extends TestCase { 144 145 146 ReasonerTester tester; 147 148 149 String test; 150 151 152 Reasoner reasoner; 153 154 155 TestReasonerFromManifest(ReasonerTester tester, String test, Reasoner reasoner) { 156 super(test); 157 this.tester = tester; 158 this.test = test; 159 this.reasoner = reasoner; 160 } 161 162 163 166 public void runTest() throws IOException { 167 tester.runTest(test, reasoner, this); 168 } 169 170 } 171 172 176 static class TestReasonerWG extends TestCase { 177 178 179 WGReasonerTester tester; 180 181 182 String test; 183 184 185 ReasonerFactory reasonerFactory; 186 187 188 Resource config; 189 190 191 TestReasonerWG(WGReasonerTester tester, String test, 192 ReasonerFactory reasonerFactory, Resource config) { 193 super(test); 194 this.tester = tester; 195 this.test = test; 196 this.reasonerFactory = reasonerFactory; 197 this.config = config; 198 } 199 200 203 public void runTest() throws IOException { 204 tester.runTest(test, reasonerFactory, this, config); 205 } 206 207 } 208 209 213 static class TestRDFSMisc extends TestCase { 214 215 216 ReasonerFactory reasonerFactory; 217 218 219 Resource config; 220 221 222 TestRDFSMisc(ReasonerFactory reasonerFactory, Resource config) { 223 super("TestRDFSMisc"); 224 this.reasonerFactory = reasonerFactory; 225 this.config = config; 226 } 227 228 231 public void runTest() throws IOException { 232 ReasonerTester tester = new ReasonerTester("rdfs/manifest.rdf"); 233 Resource configuration = newResource(); 235 if (config != null) { 236 for (StmtIterator i = config.listProperties(); i.hasNext();) { 237 Statement s = i.nextStatement(); 238 configuration.addProperty(s.getPredicate(), s.getObject()); 239 } 240 } 241 configuration.addProperty(ReasonerVocabulary.PROPenableCMPScan, "false"); 242 assertTrue("scanproperties off", 243 !tester.runTest(NAMESPACE + "rdfs/test17", reasonerFactory, null, configuration)); 244 245 Reasoner r = reasonerFactory.create(null); 247 assertTrue(r.supportsProperty(RDFS.subClassOf)); 248 assertTrue(r.supportsProperty(RDFS.domain)); 249 assertTrue(r.supportsProperty(RDFS.range)); 250 251 assertTrue( ! doTestRDFSDTRange("dttest1.nt", reasonerFactory)); 253 assertTrue( ! doTestRDFSDTRange("dttest2.nt", reasonerFactory)); 254 assertTrue( doTestRDFSDTRange("dttest3.nt", reasonerFactory)); 255 } 256 257 261 private boolean doTestRDFSDTRange(String file, ReasonerFactory rf) throws IOException { 262 String langType = "RDF/XML"; 263 if (file.endsWith(".nt")) { 264 langType = "N-TRIPLE"; 265 } else if (file.endsWith("n3")) { 266 langType = "N3"; 267 } 268 Model m = ModelFactory.createNonreifyingModel(); 269 Reader reader = new BufferedReader(new FileReader("testing/reasoners/rdfs/"+file)); 270 m.read(reader, WGReasonerTester.BASE_URI + file, langType); 271 InfGraph g = rf.create(null).bind(m.getGraph()); 272 ValidityReport report = g.validate(); 273 if (!report.isValid()) { 274 logger.debug("Validation error report:"); 275 for (Iterator i = report.getReports(); i.hasNext(); ) { 276 logger.debug(i.next().toString()); 277 } 278 } 279 return report.isValid(); 280 } 281 282 } 283 284 } 285 286 287 288 | Popular Tags |