1 6 package com.hp.hpl.jena.reasoner.rulesys.test; 7 8 import java.util.*; 9 10 import junit.framework.TestSuite; 11 12 import com.hp.hpl.jena.rdf.model.Model; 13 import com.hp.hpl.jena.rdf.model.Resource; 14 import com.hp.hpl.jena.rdf.model.impl.ModelSpecImpl; 15 import com.hp.hpl.jena.rdf.model.test.ModelTestBase; 16 import com.hp.hpl.jena.reasoner.*; 17 import com.hp.hpl.jena.reasoner.Reasoner; 18 import com.hp.hpl.jena.reasoner.rulesys.*; 19 import com.hp.hpl.jena.reasoner.rulesys.impl.WrappedReasonerFactory; 20 21 25 public class TestSetRules extends ModelTestBase 26 { 27 28 public TestSetRules( String name ) 29 { super( name ); } 30 31 public static TestSuite suite() 32 { return new TestSuite( TestSetRules.class ); } 33 34 static final List rules = Rule.parseRules( "[name: (?s owl:foo ?p) -> (?s ?p ?a)]" ); 35 36 public void testRuleReasonerWrapper() 37 { 38 MockFactory mock = new MockFactory(); 39 ReasonerFactory wrapped = wrap( mock ); 40 assertEquals( MockFactory.capabilities, wrapped.getCapabilities() ); 41 assertEquals( MockFactory.uri, wrapped.getURI() ); 42 assertEquals( MockFactory.reasoner, wrapped.create( null ) ); 43 assertEquals( Arrays.asList( new Object [] {"capabilities", "uri", "create"} ), mock.done ); 44 } 45 46 private static class MockFactory implements ReasonerFactory 47 { 48 List done = new ArrayList(); 49 static final Model capabilities = modelWithStatements( "this isA Capability" ); 50 static final String uri = "eg:mockURI"; 51 static final Reasoner reasoner = new GenericRuleReasoner( rules ); 52 53 public void addRules( List rules ) 54 { assertEquals( TestSetRules.rules, rules ); 55 done.add( "addRules" ); } 56 57 public Reasoner create(Resource configuration) 58 { done.add( "create" ); 59 return reasoner; } 60 61 public Model getCapabilities() 62 { done.add( "capabilities" ); 63 return capabilities; } 64 65 public String getURI() 66 { done.add( "uri" ); 67 return uri; } 68 } 69 70 private static ReasonerFactory wrap( final ReasonerFactory rrf ) 71 { 72 return new WrappedReasonerFactory( rrf, ModelSpecImpl.emptyResource ); 73 } 74 75 } 76 77 78 | Popular Tags |