Source Code Cross Referenced for RuleRuntimeTest.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » jsr94 » rules » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Rule Engine » drolls Rule Engine » org.drools.jsr94.rules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.jsr94.rules;
002:
003:        /*
004:         * $Id: RuleRuntimeTestCase.java,v 1.7 2005/02/04 02:13:38 mproctor 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.InputStreamReader;
045:        import java.io.Reader;
046:        import java.util.ArrayList;
047:        import java.util.HashMap;
048:        import java.util.List;
049:        import java.util.Map;
050:
051:        import javax.rules.RuleExecutionSetNotFoundException;
052:        import javax.rules.RuleRuntime;
053:        import javax.rules.RuleServiceProvider;
054:        import javax.rules.RuleServiceProviderManager;
055:        import javax.rules.StatefulRuleSession;
056:        import javax.rules.StatelessRuleSession;
057:        import javax.rules.admin.LocalRuleExecutionSetProvider;
058:        import javax.rules.admin.RuleAdministrator;
059:        import javax.rules.admin.RuleExecutionSet;
060:
061:        import org.drools.RuleBaseConfiguration;
062:        import org.drools.decisiontable.Cheese;
063:        import org.drools.decisiontable.Person;
064:        import org.drools.decisiontable.SpreadsheetIntegrationTest;
065:
066:        /**
067:         * Test the RuleRuntime implementation.
068:         *
069:         * @author N. Alex Rupp (n_alex <at>codehaus.org)
070:         * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
071:         */
072:        public class RuleRuntimeTest extends RuleEngineTestBase {
073:            private LocalRuleExecutionSetProvider ruleSetProvider;
074:
075:            private RuleAdministrator ruleAdministrator;
076:
077:            private String RULES_RESOURCE;
078:
079:            /**
080:             * Setup the test case.
081:             */
082:            protected void setUp() throws Exception {
083:                super .setUp();
084:                this .RULES_RESOURCE = this .bindUri;
085:                this .ruleAdministrator = this .ruleServiceProvider
086:                        .getRuleAdministrator();
087:                this .ruleSetProvider = this .ruleAdministrator
088:                        .getLocalRuleExecutionSetProvider(null);
089:            }
090:
091:            /**
092:             * Test createRuleSession.
093:             */
094:            public void testCreateRuleStatelessRuleSession() throws Exception {
095:                final RuleRuntime ruleRuntime = this .ruleServiceProvider
096:                        .getRuleRuntime();
097:                assertNotNull("cannot obtain RuleRuntime", ruleRuntime);
098:
099:                // expect RuleExecutionSetNotFoundException
100:                try {
101:                    ruleRuntime.createRuleSession("someUri", null,
102:                            RuleRuntime.STATELESS_SESSION_TYPE);
103:                    fail("RuleExecutionSetNotFoundException expected");
104:                } catch (final RuleExecutionSetNotFoundException ex) {
105:                    // ignore exception
106:                }
107:
108:                // read rules and register with administrator
109:                final Reader ruleReader = new InputStreamReader(
110:                        RuleRuntimeTest.class
111:                                .getResourceAsStream(this .RULES_RESOURCE));
112:                final RuleExecutionSet ruleSet = this .ruleSetProvider
113:                        .createRuleExecutionSet(ruleReader, null);
114:                this .ruleAdministrator.registerRuleExecutionSet(
115:                        this .RULES_RESOURCE, ruleSet, null);
116:
117:                final StatelessRuleSession statelessRuleSession = (StatelessRuleSession) ruleRuntime
118:                        .createRuleSession(this .RULES_RESOURCE, null,
119:                                RuleRuntime.STATELESS_SESSION_TYPE);
120:                assertNotNull("cannot obtain StatelessRuleSession",
121:                        statelessRuleSession);
122:
123:                this .ruleAdministrator.deregisterRuleExecutionSet(
124:                        this .RULES_RESOURCE, null);
125:            }
126:
127:            /**
128:             * Test createRuleSession.
129:             */
130:            public void testCreateRuleStatefulRuleSession() throws Exception {
131:                final RuleRuntime ruleRuntime = this .ruleServiceProvider
132:                        .getRuleRuntime();
133:                assertNotNull("cannot obtain RuleRuntime", ruleRuntime);
134:
135:                // expect RuleExecutionSetNotFoundException
136:                try {
137:                    ruleRuntime.createRuleSession("someUri", null,
138:                            RuleRuntime.STATEFUL_SESSION_TYPE);
139:                    fail("RuleExecutionSetNotFoundException expected");
140:                } catch (final RuleExecutionSetNotFoundException ex) {
141:                    // ignore exception
142:                }
143:
144:                // read rules and register with administrator
145:                final Reader ruleReader = new InputStreamReader(
146:                        RuleRuntimeTest.class
147:                                .getResourceAsStream(this .RULES_RESOURCE));
148:                final RuleExecutionSet ruleSet = this .ruleSetProvider
149:                        .createRuleExecutionSet(ruleReader, null);
150:                this .ruleAdministrator.registerRuleExecutionSet(
151:                        this .RULES_RESOURCE, ruleSet, null);
152:
153:                final StatefulRuleSession statefulRuleSession = (StatefulRuleSession) ruleRuntime
154:                        .createRuleSession(this .RULES_RESOURCE, null,
155:                                RuleRuntime.STATEFUL_SESSION_TYPE);
156:                assertNotNull("cannot obtain StatefulRuleSession",
157:                        statefulRuleSession);
158:
159:                this .ruleAdministrator.deregisterRuleExecutionSet(
160:                        this .RULES_RESOURCE, null);
161:            }
162:
163:            /**
164:             * Test getRegistrations.
165:             */
166:            public void testGetRegistrations() throws Exception {
167:                final RuleRuntime ruleRuntime = this .ruleServiceProvider
168:                        .getRuleRuntime();
169:                assertNotNull("cannot obtain RuleRuntime", ruleRuntime);
170:
171:                // read rules and register with administrator
172:                final Reader ruleReader = new InputStreamReader(
173:                        RuleRuntimeTest.class
174:                                .getResourceAsStream(this .RULES_RESOURCE));
175:                final RuleExecutionSet ruleSet = this .ruleSetProvider
176:                        .createRuleExecutionSet(ruleReader, null);
177:                this .ruleAdministrator.registerRuleExecutionSet(
178:                        this .RULES_RESOURCE, ruleSet, null);
179:
180:                final List list = ruleRuntime.getRegistrations();
181:                assertTrue("no registrations found", list.size() > 0);
182:
183:                this .ruleAdministrator.deregisterRuleExecutionSet(
184:                        this .RULES_RESOURCE, null);
185:            }
186:
187:            public void testRuleBaseConfigurationConstant() throws Exception {
188:                // JBRULES-1061
189:
190:                Map properties = new HashMap();
191:                properties.put(Constants.RES_SOURCE,
192:                        Constants.RES_SOURCE_TYPE_DECISION_TABLE);
193:
194:                properties.put(Constants.RES_RULEBASE_CONFIG,
195:                        new RuleBaseConfiguration());
196:
197:                RuleServiceProviderManager.registerRuleServiceProvider(
198:                        ExampleRuleEngineFacade.RULE_SERVICE_PROVIDER,
199:                        RuleServiceProviderImpl.class);
200:
201:                RuleServiceProvider ruleServiceProvider = RuleServiceProviderManager
202:                        .getRuleServiceProvider(ExampleRuleEngineFacade.RULE_SERVICE_PROVIDER);
203:                RuleAdministrator ruleAdministrator = ruleServiceProvider
204:                        .getRuleAdministrator();
205:                LocalRuleExecutionSetProvider ruleSetProvider = ruleAdministrator
206:                        .getLocalRuleExecutionSetProvider(null);
207:
208:                try {
209:                    RuleExecutionSet ruleExecutionSet = ruleSetProvider
210:                            .createRuleExecutionSet(
211:                                    SpreadsheetIntegrationTest.class
212:                                            .getResourceAsStream("IntegrationExampleTest.xls"),
213:                                    properties);
214:                } catch (Exception e) {
215:                    // fail should not throw an Excetpion
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.