<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I have continued to try to isolate the problem that I have previously described, where my RCP application that calls Drools runs properly, but am unable to Unit test. Can reproduce the problem simply and am hoping someone can lend some insight.<div><br></div><div>I started by creating a simple Drools project that had a JUnit 4 test in it; this runs. It contains two java files and a DRL file. (Shown at very bottom of this post)</div><div><br></div><div>I then created a Hello World RCP application from the Eclipse templates. I copied the Drools project files (2 Java files and 1 DRL file) into the same package as my RCP stuff. When I run the test, I get the following error, which is exactly the same error I have been getting with my much more complicated project:</div><div><br></div><div>java.lang.NullPointerException<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.mvel.optimizers.OptimizerFactory.<clinit>(OptimizerFactory.java:43)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.drools.rule.builder.dialect.mvel.MVELDialect.init(MVELDialect.java:142)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.drools.compiler.DialectRegistry.initAll(DialectRegistry.java:49)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:146)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:108)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at rcp_with_drool.mikeTest..setUp(mikeTest.java:39)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at java.lang.reflect.Method.invoke(Method.java:585)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)<br>[MVEL] Notice: Possible incorrect version of ASM present (3.0 required). Disabling JIT compiler. Reflective Optimizer will be used.</div><div><br></div><div>I then removed all the source files relating to the RCP itself, and the error persists. If I now remove the plugin dependencies from this project from the build path, the problem goes away and the tests run. If I add the plugin dependencies back into the project, the error resumes. Finally, if I make my ORIGINAL Drools project depend on this second one with the plugin dependencies, the test fails there too. If I remove the plugin dependencies, the tests run.</div><div><br></div><div>The plugin dependencies are:</div><div>org.eclipse.ui</div><div>org.eclipse.swt</div><div>CodeProSWTFragment</div><div>org.eclipse.swt.carbon.macosx</div><div>org.eclipse.jface</div><div>org.eclipse.core.commands</div><div>org.eclipse.ui.workbench</div><div>org.eclipse.core.runtime</div><div>org.eclipse.osgi</div><div>org.eclipse.equinox.common</div><div>org.eclipse.core.jobs</div><div>runtime_registry_compatibility</div><div>org.eclipse.equinox.registry</div><div>org.eclipse.equinox.preferences</div><div>org.eclipse.core.contenttype</div><div>org.eclipse.equinox.app</div><div><br></div><div>Thanks for any assistance.</div><div><br></div><div>Here are the two java files and the rules file:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">package</span> rcp_with_drool;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> <span style="color: #7f0055">static</span> org.junit.Assert.*;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> java.io.IOException;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> java.io.InputStreamReader;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> java.io.Reader;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.drools.RuleBase;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.drools.RuleBaseFactory;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.drools.WorkingMemory;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.drools.compiler.DroolsParserException;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.drools.compiler.PackageBuilder;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.drools.rule.Package;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.junit.After;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.junit.AfterClass;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.junit.Before;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.junit.BeforeClass;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> org.junit.Test;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">import</span> rcp_with_drool.DroolsTest.Message;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #7f0055">public</span> <span style="color: #7f0055">class</span> mikeTest {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">static</span> RuleBase <span style="color: #0000c0">ruleBase</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">static</span> WorkingMemory <span style="color: #0000c0">workingMemory</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">static</span> Message <span style="color: #0000c0">message</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@BeforeClass</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">static</span> <span style="color: #7f0055">void</span> setUpBeforeClass() <span style="color: #7f0055">throws</span> Exception {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #0000c0">message</span> = <span style="color: #7f0055">new</span> Message();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@AfterClass</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">static</span> <span style="color: #7f0055">void</span> tearDownAfterClass() <span style="color: #7f0055">throws</span> Exception {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@Before</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">void</span> setUp() <span style="color: #7f0055">throws</span> Exception {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>Reader source = <span style="color: #7f0055">new</span> InputStreamReader( DroolsTest.<span style="color: #7f0055">class</span>.getResourceAsStream( <span style="color: #2a00ff">"Sample.drl"</span> ) );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>PackageBuilder builder = <span style="color: #7f0055">new</span> PackageBuilder();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #7f0055">try</span> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>builder.addPackageFromDrl(source);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>} <span style="color: #7f0055">catch</span> (DroolsParserException e1) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>e1.printStackTrace();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>} <span style="color: #7f0055">catch</span> (IOException e1) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>e1.printStackTrace();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px"><span class="Apple-tab-span" style="white-space:pre">                </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>Package pkg = builder.getPackage();<span class="Apple-tab-span" style="white-space:pre">        </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #0000c0">ruleBase</span> = RuleBaseFactory.newRuleBase();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #7f0055">try</span> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #0000c0">ruleBase</span>.addPackage( pkg );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>} <span style="color: #7f0055">catch</span> (Exception e) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>e.printStackTrace();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #0000c0">workingMemory</span> = <span style="color: #0000c0">ruleBase</span>.newStatefulSession();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@After</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">void</span> tearDown() <span style="color: #7f0055">throws</span> Exception {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@Test</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">void</span> testMain() {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(63, 127, 95); "><span style="color: #000000"> </span>//Message message = new Message();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setMessage( <span style="color: #2a00ff">"Hello World"</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setStatus( Message.<span style="color: #0000c0">HELLO</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.insert( <span style="color: #0000c0">message</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>, <span style="color: #0000c0">message</span>.getStatus(), Message.<span style="color: #0000c0">HELLO</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.fireAllRules();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>,<span style="color: #0000c0">message</span>.getStatus(),Message.<span style="color: #0000c0">GOODBYE</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@Test</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">void</span> testMain1() {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(63, 127, 95); "><span style="color: #000000"> </span>//Message message = new Message();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setMessage( <span style="color: #2a00ff">"Hello World"</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setStatus( Message.<span style="color: #0000c0">HELLO</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.insert( <span style="color: #0000c0">message</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>, <span style="color: #0000c0">message</span>.getStatus(), Message.<span style="color: #0000c0">HELLO</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.fireAllRules();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>,<span style="color: #0000c0">message</span>.getStatus(),Message.<span style="color: #0000c0">GOODBYE</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@Test</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">void</span> testMain2() {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(63, 127, 95); "><span style="color: #000000"> </span>//Message message = new Message();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setMessage( <span style="color: #2a00ff">"Hello World"</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setStatus( Message.<span style="color: #0000c0">HELLO</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.insert( <span style="color: #0000c0">message</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>, <span style="color: #0000c0">message</span>.getStatus(), Message.<span style="color: #0000c0">HELLO</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.fireAllRules();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>,<span style="color: #0000c0">message</span>.getStatus(),Message.<span style="color: #0000c0">GOODBYE</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(100, 100, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@Test</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">void</span> testMain3() {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(63, 127, 95); "><span style="color: #000000"> </span>//Message message = new Message();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setMessage( <span style="color: #2a00ff">"Hello World"</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">message</span>.setStatus( Message.<span style="color: #0000c0">HELLO</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.insert( <span style="color: #0000c0">message</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>, <span style="color: #0000c0">message</span>.getStatus(), Message.<span style="color: #0000c0">HELLO</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: #0000c0">workingMemory</span>.fireAllRules();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> assertEquals(<span style="color: #2a00ff">"Message status set"</span>,<span style="color: #0000c0">message</span>.getStatus(),Message.<span style="color: #0000c0">GOODBYE</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">}</div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;"><div>package rcp_with_drool;</div><div><br></div><div>import java.io.InputStreamReader;</div><div>import java.io.Reader;</div><div><br></div><div>import org.drools.RuleBase;</div><div>import org.drools.RuleBaseFactory;</div><div>import org.drools.WorkingMemory;</div><div>import org.drools.compiler.PackageBuilder;</div><div>import org.drools.rule.Package;</div><div><br></div><div>/**</div><div> * This is a sample file to launch a rule package from a rule source file.</div><div> */</div><div>public class DroolsTest {</div><div><br></div><div> public static final void main(String[] args) {</div><div> try {</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span></div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>//load up the rulebase</div><div> RuleBase ruleBase = readRule();</div><div> WorkingMemory workingMemory = ruleBase.newStatefulSession();</div><div> </div><div> //go !</div><div> Message message = new Message();</div><div> message.setMessage( "Hello World" );</div><div> message.setStatus( Message.HELLO );</div><div> workingMemory.insert( message );</div><div> workingMemory.fireAllRules(); </div><div> </div><div> </div><div> } catch (Throwable t) {</div><div> t.printStackTrace();</div><div> }</div><div> }</div><div><br></div><div> /**</div><div> * Please note that this is the "low level" rule assembly API.</div><div> */</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private static RuleBase readRule() throws Exception {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//read in the source</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//optionally read in the DSL (if you are using it).</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//Use package builder to build up a rule package.</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//An alternative lower level class called "DrlParser" can also be used...</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>PackageBuilder builder = new PackageBuilder();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//this wil parse and compile in one step</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//NOTE: There are 2 methods here, the one argument one is for normal DRL.</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>builder.addPackageFromDrl( source );</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//Use the following instead of above if you are using a DSL:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//builder.addPackageFromDrl( source, dsl );</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//get the compiled package (which is serializable)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Package pkg = builder.getPackage();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//add the package to a rulebase (deploy the rule package).</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>RuleBase ruleBase = RuleBaseFactory.newRuleBase();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ruleBase.addPackage( pkg );</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return ruleBase;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public static class Message {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public static final int HELLO = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public static final int GOODBYE = 1;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>private String message;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>private int status;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public String getMessage() {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return this.message;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public void setMessage(String message) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>this.message = message;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public int getStatus() {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return this.status;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public void setStatus( int status ) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>this.status = status;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div> </div><div>}</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #960000">package</span> glucose.rules</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px"> <br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #960000">import</span> rcp_with_drool.DroolsTest.Message;</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px"> <br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(0, 128, 0); "><span style="color: #960000">rule</span><span style="color: #000000"> </span>"Hello World"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(150, 0, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>when</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>m : Message( status == Message.HELLO, message : message )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(150, 0, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>then</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>System.out.println( message ); </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(0, 128, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                </span>m.setMessage( </span>"Goodbye crueller world"<span style="color: #000000"> );</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>m.setStatus( Message.GOODBYE );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #960000">update</span>( m );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(150, 0, 0); ">end</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(0, 128, 0); "><span style="color: #960000">rule</span><span style="color: #000000"> </span>"GoodBye"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(150, 0, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>no-loop<span style="color: #000000"> </span>true</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(150, 0, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>when</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>m : Message( status == Message.GOODBYE, message : message )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(150, 0, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>then</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>System.out.println( message ); </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>m.setMessage( message );<span class="Apple-tab-span" style="white-space:pre">        </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(150, 0, 0); ">end</div></div></span></font></div></div><div><br></div></body></html>