Source Code Cross Referenced for MultipleRepositoryTest.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:        import java.io.InputStream;
004:        import java.util.Arrays;
005:        import java.util.List;
006:
007:        import javax.rules.RuleRuntime;
008:        import javax.rules.RuleServiceProvider;
009:        import javax.rules.RuleServiceProviderManager;
010:        import javax.rules.StatelessRuleSession;
011:        import javax.rules.admin.RuleAdministrator;
012:        import javax.rules.admin.RuleExecutionSet;
013:
014:        import junit.framework.TestCase;
015:
016:        /**
017:         * A test for independent repository instances for different runtimes.
018:         *
019:         * @author jgilbert
020:         * @author <a href="mailto:michael.frandsen@syngenio.de">michael frandsen </a>
021:         */
022:        public class MultipleRepositoryTest extends TestCase {
023:
024:            public MultipleRepositoryTest(final String name) {
025:                super (name);
026:            }
027:
028:            /**
029:             * Do the test.
030:             *
031:             * @throws Exception
032:             */
033:            public void testMultipleInstances() throws Exception {
034:                // create 2 different runtimes with different rulesets
035:                final RuleRuntime ruleRuntime1 = getServiceProvider("engine1",
036:                        "multiple-engine1.drl").getRuleRuntime();
037:                final RuleRuntime ruleRuntime2 = getServiceProvider("engine2",
038:                        "multiple-engine2.drl").getRuleRuntime();
039:
040:                // there should be only 1
041:                System.out.println(ruleRuntime1.getRegistrations().size());
042:                assertTrue(ruleRuntime1.getRegistrations().size() == 1);
043:
044:                // there should be only 1
045:                System.out.println(ruleRuntime2.getRegistrations().size());
046:                assertTrue(ruleRuntime2.getRegistrations().size() == 1);
047:
048:                // execute them both for good measure...
049:                execute(ruleRuntime1, "Engine1", new Object[] { "value1" });
050:                execute(ruleRuntime2, "Engine2", new Object[] { "value2" });
051:
052:            }
053:
054:            /**
055:             * Create a Provider.
056:             *
057:             * @param url
058:             * @param rulesets
059:             * @return
060:             * @throws Exception
061:             */
062:            public RuleServiceProvider getServiceProvider(final String url,
063:                    final String ruleset) throws Exception {
064:                // create the provider
065:                final Class clazz = this .getClass().getClassLoader().loadClass(
066:                        "org.drools.jsr94.rules.RuleServiceProviderImpl");
067:                RuleServiceProviderManager.registerRuleServiceProvider(url,
068:                        clazz);
069:                final RuleServiceProvider serviceProvider = RuleServiceProviderManager
070:                        .getRuleServiceProvider(url);
071:                final RuleAdministrator ruleAdministrator = serviceProvider
072:                        .getRuleAdministrator();
073:
074:                // register the ruleset
075:                final InputStream inStream = this .getClass()
076:                        .getResourceAsStream(ruleset);
077:                final RuleExecutionSet res1 = ruleAdministrator
078:                        .getLocalRuleExecutionSetProvider(null)
079:                        .createRuleExecutionSet(inStream, null);
080:
081:                inStream.close();
082:                final String uri = res1.getName();
083:                System.out.println(uri);
084:                ruleAdministrator.registerRuleExecutionSet(uri, res1, null);
085:                return serviceProvider;
086:            }
087:
088:            /**
089:             * Execute a ruleset for the input.
090:             *
091:             * @param rt
092:             * @param ruleset
093:             * @param input
094:             * @throws Exception
095:             */
096:            public void execute(final RuleRuntime rt, final String ruleset,
097:                    final Object[] input) throws Exception {
098:                final StatelessRuleSession srs = (StatelessRuleSession) rt
099:                        .createRuleSession(ruleset, null,
100:                                RuleRuntime.STATELESS_SESSION_TYPE);
101:                final List output = srs.executeRules(Arrays.asList(input));
102:                System.out.println(output);
103:            }
104:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.