001: package org.drools.jsr94.rules;
002:
003: /*
004: * $Id: JSR94TestBase.java,v 1.7 2004/11/17 03:09:50 dbarnett Exp $
005: *
006: * Copyright 2002-2004 (C) The Werken Company. All Rights Reserved.
007: *
008: * Redistribution and use of this software and associated documentation
009: * ("Software"), with or without modification, are permitted provided that the
010: * following conditions are met:
011: *
012: * 1. Redistributions of source code must retain copyright statements and
013: * notices. Redistributions must also contain a copy of this document.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright notice,
016: * this list of conditions and the following disclaimer in the documentation
017: * and/or other materials provided with the distribution.
018: *
019: * 3. The name "drools" must not be used to endorse or promote products derived
020: * from this Software without prior written permission of The Werken Company.
021: * For written permission, please contact bob@werken.com.
022: *
023: * 4. Products derived from this Software may not be called "drools" nor may
024: * "drools" appear in their names without prior written permission of The Werken
025: * Company. "drools" is a registered trademark of The Werken Company.
026: *
027: * 5. Due credit should be given to The Werken Company.
028: * (http://drools.werken.com/).
029: *
030: * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
031: * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
032: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
033: * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
034: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
035: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
036: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
037: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
038: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
039: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
040: * POSSIBILITY OF SUCH DAMAGE.
041: *
042: */
043:
044: import java.io.InputStream;
045: import java.net.URL;
046:
047: import javax.rules.RuleServiceProvider;
048: import javax.rules.StatefulRuleSession;
049: import javax.rules.StatelessRuleSession;
050:
051: import junit.framework.TestCase;
052:
053: /**
054: * Base class for all drools JSR94 test cases.
055: *
056: * @author N. Alex Rupp (n_alex <at>codehaus.org)
057: * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
058: */
059: public abstract class JSR94TestBase extends TestCase {
060: protected StatefulRuleSession statefulSession;
061:
062: protected StatelessRuleSession statelessSession;
063:
064: protected ExampleRuleEngineFacade engine;
065:
066: protected String bindUri = "sisters.drl";
067:
068: protected RuleServiceProvider ruleServiceProvider;
069:
070: /**
071: * Setup the test case.
072: */
073: protected void setUp() throws Exception {
074: super .setUp();
075: this .engine = new ExampleRuleEngineFacade();
076: this .engine.addRuleExecutionSet(this .bindUri,
077: StatelessRuleSessionTest.class
078: .getResourceAsStream(this .bindUri));
079:
080: this .ruleServiceProvider = this .engine.getRuleServiceProvider();
081: this .statelessSession = this .engine
082: .getStatelessRuleSession(this .bindUri);
083: this .statefulSession = this .engine
084: .getStatefulRuleSession(this .bindUri);
085: }
086:
087: /**
088: * Get the requested resource from the ClassLoader.
089: *
090: * @see ClassLoader#getResource
091: */
092: protected URL getResource(final String res) {
093: return getClass().getClassLoader().getResource(res);
094: }
095:
096: /**
097: * Get the requested resource from the ClassLoader.
098: *
099: * @see ClassLoader#getResourceAsStream
100: */
101: protected InputStream getResourceAsStream(final String res) {
102: return getClass().getClassLoader().getResourceAsStream(res);
103: }
104: }
|