001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: TestSetRules.java,v 1.12 2008/01/14 11:26:29 chris-dollin Exp $
005: */
006: package com.hp.hpl.jena.reasoner.rulesys.test;
007:
008: import java.util.*;
009:
010: import junit.framework.TestSuite;
011:
012: import com.hp.hpl.jena.rdf.model.*;
013: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
014: import com.hp.hpl.jena.reasoner.*;
015: import com.hp.hpl.jena.reasoner.rulesys.*;
016: import com.hp.hpl.jena.reasoner.rulesys.impl.WrappedReasonerFactory;
017:
018: /**
019: TestSetRules - tests to bring setRules into existence on RuleReasonerFactory.
020: @author kers
021: */
022: public class TestSetRules extends ModelTestBase {
023:
024: public TestSetRules(String name) {
025: super (name);
026: }
027:
028: public static TestSuite suite() {
029: return new TestSuite(TestSetRules.class);
030: }
031:
032: static final List rules = Rule
033: .parseRules("[name: (?s owl:foo ?p) -> (?s ?p ?a)]");
034:
035: public void testRuleReasonerWrapper() {
036: MockFactory mock = new MockFactory();
037: ReasonerFactory wrapped = wrap(mock);
038: assertEquals(MockFactory.capabilities, wrapped
039: .getCapabilities());
040: assertEquals(MockFactory.uri, wrapped.getURI());
041: assertEquals(MockFactory.reasoner, wrapped.create(null));
042: assertEquals(Arrays.asList(new Object[] { "capabilities",
043: "uri", "create" }), mock.done);
044: }
045:
046: private static class MockFactory implements ReasonerFactory {
047: List done = new ArrayList();
048: static final Model capabilities = modelWithStatements("this isA Capability");
049: static final String uri = "eg:mockURI";
050: static final Reasoner reasoner = new GenericRuleReasoner(rules);
051:
052: public void addRules(List rules) {
053: assertEquals(TestSetRules.rules, rules);
054: done.add("addRules");
055: }
056:
057: public Reasoner create(Resource configuration) {
058: done.add("create");
059: return reasoner;
060: }
061:
062: public Model getCapabilities() {
063: done.add("capabilities");
064: return capabilities;
065: }
066:
067: public String getURI() {
068: done.add("uri");
069: return uri;
070: }
071: }
072:
073: private static Resource emptyResource = ModelFactory
074: .createDefaultModel().createResource();
075:
076: private static ReasonerFactory wrap(final ReasonerFactory rrf) {
077: return new WrappedReasonerFactory(rrf, emptyResource);
078: }
079:
080: }
081:
082: /*
083: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
084: All rights reserved.
085:
086: Redistribution and use in source and binary forms, with or without
087: modification, are permitted provided that the following conditions
088: are met:
089:
090: 1. Redistributions of source code must retain the above copyright
091: notice, this list of conditions and the following disclaimer.
092:
093: 2. Redistributions in binary form must reproduce the above copyright
094: notice, this list of conditions and the following disclaimer in the
095: documentation and/or other materials provided with the distribution.
096:
097: 3. The name of the author may not be used to endorse or promote products
098: derived from this software without specific prior written permission.
099:
100: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
101: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
102: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
103: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
104: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
105: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
106: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
107: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
108: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
109: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
110: */
|