KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > test > TestSetRules


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: TestSetRules.java,v 1.8 2005/02/21 12:18:14 andy_seaborne Exp $
5 */

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 /**
22      TestSetRules - tests to bring setRules into existence on RuleReasonerFactory.
23      @author kers
24 */

25 public class TestSetRules extends ModelTestBase
26     {
27
28     public TestSetRules( String JavaDoc 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 JavaDoc[] {"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 JavaDoc 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 JavaDoc 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 /*
79     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
80     All rights reserved.
81     
82     Redistribution and use in source and binary forms, with or without
83     modification, are permitted provided that the following conditions
84     are met:
85     
86     1. Redistributions of source code must retain the above copyright
87        notice, this list of conditions and the following disclaimer.
88     
89     2. Redistributions in binary form must reproduce the above copyright
90        notice, this list of conditions and the following disclaimer in the
91        documentation and/or other materials provided with the distribution.
92     
93     3. The name of the author may not be used to endorse or promote products
94        derived from this software without specific prior written permission.
95     
96     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
97     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
98     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
99     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
100     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
101     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
102     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
103     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
104     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
105     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
106 */
Popular Tags