<br>&nbsp; Thanks Marcus,<br><br>&nbsp; We will include the patch in the next drools release! We do appreciate the contribution.<br><br>&nbsp;&nbsp; Edson<br><br><div class="gmail_quote">2008/5/22 Marcus Ilgner &lt;<a href="mailto:marcus.ilgner@gmail.com">marcus.ilgner@gmail.com</a>&gt;:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Glad that I could actually contribute something back to this great project.<br>
I put together a patch for this issue in the JIRA at<br>
<a href="http://jira.jboss.org/jira/browse/JBRULES-1618" target="_blank">http://jira.jboss.org/jira/browse/JBRULES-1618</a> as promised.<br>
<br>
Best regards<br>
<font color="#888888">Marcus<br>
</font><div><div></div><div class="Wj3C7c"><br>
On Tue, May 20, 2008 at 2:34 AM, Mike Dean &lt;<a href="mailto:mdean77@comcast.net">mdean77@comcast.net</a>&gt; wrote:<br>
&gt;<br>
&gt; Sorry to ask question and then figure it out! &nbsp;I just substituted the actual<br>
&gt; name of my suite class instead of saying this.class and it works<br>
&gt; beautifully. &nbsp;I am now testing Drools with JUnit 4 with no problems, after<br>
&gt; nearly six months! &nbsp;THANK YOU.<br>
&gt;<br>
&gt; - Mike<br>
&gt;<br>
&gt; Mike Dean wrote:<br>
&gt;&gt;<br>
&gt;&gt; Thanks to both of you for pursuing this problem. &nbsp;I have worked around it<br>
&gt;&gt; by putting my business classes and rules in a separate Drools project,<br>
&gt;&gt; testing everything there, and then copying them to my RCP. &nbsp;I look forward<br>
&gt;&gt; to a better solution!<br>
&gt;&gt;<br>
&gt;&gt; I must confess Java ignorance, but I use a test suite and try to<br>
&gt;&gt; instantiate the engine once and then run a series of tests. &nbsp;My crash<br>
&gt;&gt; occurs before I get to the individual tests. &nbsp;However, the setUp routine<br>
&gt;&gt; is static, and your code work around cannot be executed in a static<br>
&gt;&gt; context. &nbsp;Where exactly to you put the test for a null classloader?<br>
&gt;&gt;<br>
&gt;&gt; Thanks again. &nbsp;I thought this issue simply died.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Marcus Ilgner wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hi Edson,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; thank you very much for testing this! Since I could not discern any<br>
&gt;&gt;&gt; differences between your approach and mine, I decided to resolve the<br>
&gt;&gt;&gt; issue manually by inserting a work-around in my test routine which<br>
&gt;&gt;&gt; sets the context class loader for the current thread before calling<br>
&gt;&gt;&gt; the method under test.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; if (Thread.currentThread().getContextClassLoader() == null) {<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; My guess is that the custom JUnit 4 class runner<br>
&gt;&gt;&gt; (SpringJUnit4ClassRunner) somehow is responsible for the faulty<br>
&gt;&gt;&gt; behaviour.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thanks again<br>
&gt;&gt;&gt; Marcus<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Mon, May 19, 2008 at 3:09 PM, Edson Tirelli &lt;<a href="mailto:tirelli@post.com">tirelli@post.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp;All,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp;I see that the code in that spot is weak and could be improved.<br>
&gt;&gt;&gt;&gt; Although,<br>
&gt;&gt;&gt;&gt; using drools 4.0.7, I successfully created a junit 4 test that I paste<br>
&gt;&gt;&gt;&gt; bellow. Also, the whole drools code is tested with junit 3 and we have<br>
&gt;&gt;&gt;&gt; no<br>
&gt;&gt;&gt;&gt; problems. For instance, look at our integration tests here:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; <a href="http://anonsvn.labs.jboss.com/labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/" target="_blank">http://anonsvn.labs.jboss.com/labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/</a><br>

&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp;The code I used to create the junit 4 test is based on the default<br>
&gt;&gt;&gt;&gt; example create by the drools plugin + the snippet you showed bellow:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; @Test<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; public void testRuleBase() {<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; try {<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //load up the rulebase<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RuleBase ruleBase = readRule();<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StatefulSession workingMemory =<br>
&gt;&gt;&gt;&gt; ruleBase.newStatefulSession();<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //go !<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Message message = new Message();<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message.setMessage( &nbsp;&quot;Hello World&quot; );<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message.setStatus( Message.HELLO );<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; workingMemory.insert( message );<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; workingMemory.fireAllRules();<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; workingMemory.dispose();<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; } catch (Throwable t) {<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.printStackTrace();<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.fail(&quot;Something is wrong: &quot;+t.getMessage());<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; /**<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp;* Please note that this is the &quot;low level&quot; rule assembly API.<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp;*/<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; private RuleBase readRule() throws Exception {<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; //read in the source<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; Reader source = new InputStreamReader(<br>
&gt;&gt;&gt;&gt; DroolsTest.class.getResourceAsStream( &quot;/Sample.drl&quot; ) );<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; PackageBuilderConfiguration conf = new<br>
&gt;&gt;&gt;&gt; PackageBuilderConfiguration();<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; JavaDialectConfiguration javaConf = (JavaDialectConfiguration)<br>
&gt;&gt;&gt;&gt; conf.getDialectConfiguration(&quot;java&quot;);<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; javaConf.setJavaLanguageLevel(&quot;1.5&quot;);<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; PackageBuilder builder = new PackageBuilder( conf );<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; builder.addPackageFromDrl( source );<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; ruleBase.addPackage( builder.getPackage() );<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; return ruleBase;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; }<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; Hope it helps,<br>
&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; Edson<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; 2008/5/19 Marcus Ilgner &lt;<a href="mailto:marcus.ilgner@gmail.com">marcus.ilgner@gmail.com</a>&gt;:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Hi list,<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; I&#39;m reviving this thread because I happen to have the same problem.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; On Sun, Mar 23, 2008 at 7:34 PM, Mike Dean &lt;<a href="mailto:mdean77@comcast.net">mdean77@comcast.net</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt;&gt; &gt; Thanks (months later!). &nbsp;I have cut down my code example below to<br>
&gt;&gt;&gt;&gt;&gt; show<br>
&gt;&gt;&gt;&gt;&gt; &gt; this<br>
&gt;&gt;&gt;&gt;&gt; &gt; issue more clearly:<br>
&gt;&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt;&gt; &gt; John J. Franey wrote:<br>
&gt;&gt;&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; &gt;&gt; NullPointerException on line 146 means classLoader is null. &nbsp; That<br>
&gt;&gt;&gt;&gt;&gt; is<br>
&gt;&gt;&gt;&gt;&gt; &gt;&gt; odd.<br>
&gt;&gt;&gt;&gt;&gt; &gt;&gt; I have no idea why the code that gets classLoader won&#39;t work in<br>
&gt;&gt;&gt;&gt;&gt; &gt;&gt; eclipse&#39;s<br>
&gt;&gt;&gt;&gt;&gt; &gt;&gt; junit runtime, but does when run in your eclipse plugin.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; &nbsp;It seems indeed like during JUnit tests, the context classloader of<br>
&gt;&gt;&gt;&gt;&gt; the thread gets not set (null).<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; The code leading up to the problem is as follows:<br>
&gt;&gt;&gt;&gt;&gt; PackageBuilderConfiguration conf = new PackageBuilderConfiguration();<br>
&gt;&gt;&gt;&gt;&gt; JavaDialectConfiguration javaConf = (JavaDialectConfiguration)<br>
&gt;&gt;&gt;&gt;&gt; conf.getDialectConfiguration(&quot;java&quot;);<br>
&gt;&gt;&gt;&gt;&gt; javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
&gt;&gt;&gt;&gt;&gt; javaConf.setJavaLanguageLevel(&quot;1.5&quot;);<br>
&gt;&gt;&gt;&gt;&gt; RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; The resulting stacktrace is:<br>
&gt;&gt;&gt;&gt;&gt; java.lang.NullPointerException<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.RuleBaseConfiguration.instantiateClass(RuleBaseConfiguration.java:569)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.RuleBaseConfiguration.determineConsequenceExceptionHandler(RuleBaseConfiguration.java:561)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.RuleBaseConfiguration.init(RuleBaseConfiguration.java:220)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.RuleBaseConfiguration.&lt;init&gt;(RuleBaseConfiguration.java:133)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.common.AbstractRuleBase.&lt;init&gt;(AbstractRuleBase.java:147)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.reteoo.ReteooRuleBase.&lt;init&gt;(ReteooRuleBase.java:124)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.reteoo.ReteooRuleBase.&lt;init&gt;(ReteooRuleBase.java:101)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:57)<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt;&gt;&gt;&gt; org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:38)<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Has anyone set up Drools and JUnit successfully? Maybe we forgot to<br>
&gt;&gt;&gt;&gt;&gt; set up the environment properly?<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Best regards<br>
&gt;&gt;&gt;&gt;&gt; Marcus<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt; --<br>
&gt; View this message in context: <a href="http://www.nabble.com/Re%3AJUnit-testing-tp14164710p17331006.html" target="_blank">http://www.nabble.com/Re%3AJUnit-testing-tp14164710p17331006.html</a><br>
&gt; Sent from the drools - user mailing list archive at Nabble.com.<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>