1 package org.drools.jsr94.rules; 2 3 import javax.rules.RuleExecutionSetNotFoundException; 4 import javax.rules.RuleRuntime; 5 import javax.rules.StatefulRuleSession; 6 import javax.rules.StatelessRuleSession; 7 import javax.rules.admin.LocalRuleExecutionSetProvider; 8 import javax.rules.admin.RuleAdministrator; 9 import javax.rules.admin.RuleExecutionSet; 10 import java.io.InputStreamReader; 11 import java.io.Reader; 12 import java.util.List; 13 14 /* 15 $Id: RuleRuntimeTestCase.java,v 1.1 2003/03/22 00:59:49 tdiesler Exp $ 16 17 Copyright 2002 (C) The Werken Company. All Rights Reserved. 18 19 Redistribution and use of this software and associated documentation 20 ("Software"), with or without modification, are permitted provided 21 that the following conditions are met: 22 23 1. Redistributions of source code must retain copyright 24 statements and notices. Redistributions must also contain a 25 copy of this document. 26 27 2. Redistributions in binary form must reproduce the 28 above copyright notice, this list of conditions and the 29 following disclaimer in the documentation and/or other 30 materials provided with the distribution. 31 32 3. The name "drools" must not be used to endorse or promote 33 products derived from this Software without prior written 34 permission of The Werken Company. For written permission, 35 please contact bob@werken.com. 36 37 4. Products derived from this Software may not be called "drools" 38 nor may "drools" appear in their names without prior written 39 permission of The Werken Company. "drools" is a registered 40 trademark of The Werken Company. 41 42 5. Due credit should be given to The Werken Company. 43 (http://drools.werken.com/). 44 45 THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS 46 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 47 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 48 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 49 THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 50 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 51 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 52 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 54 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 55 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 56 OF THE POSSIBILITY OF SUCH DAMAGE. 57 58 */ 59 60 /*** 61 * Test the RuleRuntime implementation. 62 * 63 * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler</a> 64 */ 65 public class RuleRuntimeTestCase extends JSR94TestBase { 66 67 private LocalRuleExecutionSetProvider ruleSetProvider; 68 private RuleAdministrator ruleAdministrator; 69 70 /*** 71 * Setup the test case. 72 */ 73 protected void setUp() throws Exception { 74 super.setUp(); 75 ruleAdministrator = ruleServiceProvider.getRuleAdministrator(); 76 ruleSetProvider = ruleAdministrator.getLocalRuleExecutionSetProvider(null); 77 } 78 79 /*** 80 * Test createRuleSession. 81 */ 82 public void testCreateRuleStatelessRuleSession() throws Exception { 83 84 RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); 85 assertNotNull("cannot obtain RuleRuntime", ruleRuntime); 86 87 // expect RuleExecutionSetNotFoundException 88 StatelessRuleSession statelessRuleSession = null; 89 try { 90 statelessRuleSession = (StatelessRuleSession)ruleRuntime.createRuleSession(RULES_RESOURCE, null, RuleRuntime.STATELESS_SESSION_TYPE); 91 fail("RuleExecutionSetNotFoundException expected"); 92 } catch (RuleExecutionSetNotFoundException ex) { 93 } 94 95 // read rules and register with administrator 96 Reader ruleReader = new InputStreamReader(getResourceAsStream(RULES_RESOURCE)); 97 RuleExecutionSet ruleSet = ruleSetProvider.createRuleExecutionSet(ruleReader, null); 98 ruleAdministrator.registerRuleExecutionSet(RULES_RESOURCE, ruleSet, null); 99 100 statelessRuleSession = (StatelessRuleSession)ruleRuntime.createRuleSession(RULES_RESOURCE, null, RuleRuntime.STATELESS_SESSION_TYPE); 101 assertNotNull("cannot obtain StatelessRuleSession", statelessRuleSession); 102 103 ruleAdministrator.unregisterRuleExecutionSet(RULES_RESOURCE, null); 104 } 105 106 /*** 107 * Test createRuleSession. 108 */ 109 public void testCreateRuleStatefulRuleSession() throws Exception { 110 111 RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); 112 assertNotNull("cannot obtain RuleRuntime", ruleRuntime); 113 114 // expect RuleExecutionSetNotFoundException 115 StatefulRuleSession statefulRuleSession = null; 116 try { 117 statefulRuleSession = (StatefulRuleSession)ruleRuntime.createRuleSession(RULES_RESOURCE, null, RuleRuntime.STATEFUL_SESSION_TYPE); 118 fail("RuleExecutionSetNotFoundException expected"); 119 } catch (RuleExecutionSetNotFoundException ex) { 120 } 121 122 // read rules and register with administrator 123 Reader ruleReader = new InputStreamReader(getResourceAsStream(RULES_RESOURCE)); 124 RuleExecutionSet ruleSet = ruleSetProvider.createRuleExecutionSet(ruleReader, null); 125 ruleAdministrator.registerRuleExecutionSet(RULES_RESOURCE, ruleSet, null); 126 127 statefulRuleSession = (StatefulRuleSession)ruleRuntime.createRuleSession(RULES_RESOURCE, null, RuleRuntime.STATEFUL_SESSION_TYPE); 128 assertNotNull("cannot obtain StatefulRuleSession", statefulRuleSession); 129 130 ruleAdministrator.unregisterRuleExecutionSet(RULES_RESOURCE, null); 131 } 132 133 /*** 134 * Test getRegistrations. 135 */ 136 public void testGetRegistrations() throws Exception { 137 138 RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); 139 assertNotNull("cannot obtain RuleRuntime", ruleRuntime); 140 141 // read rules and register with administrator 142 Reader ruleReader = new InputStreamReader(getResourceAsStream(RULES_RESOURCE)); 143 RuleExecutionSet ruleSet = ruleSetProvider.createRuleExecutionSet(ruleReader, null); 144 ruleAdministrator.registerRuleExecutionSet(RULES_RESOURCE, ruleSet, null); 145 146 List list = ruleRuntime.getRegistrations(); 147 assertTrue("no registrations found", list.size() > 0); 148 149 ruleAdministrator.unregisterRuleExecutionSet(RULES_RESOURCE, null); 150 } 151 }

This page was automatically generated by Maven