<br>&nbsp;&nbsp; All,<br><br>&nbsp;&nbsp; I see that the code in that spot is weak and could be improved. Although, using drools 4.0.7, I successfully created a junit 4 test that I paste bellow. Also, the whole drools code is tested with junit 3 and we have no problems. For instance, look at our integration tests here:<br>
<br><a href="http://anonsvn.labs.jboss.com/labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/">http://anonsvn.labs.jboss.com/labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/</a><br>
<br>&nbsp;&nbsp; The code I used to create the junit 4 test is based on the default example create by the drools plugin + the snippet you showed bellow:<br><br>&nbsp;&nbsp;&nbsp; @Test<br>&nbsp;&nbsp;&nbsp; public void testRuleBase() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //load up the rulebase<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RuleBase ruleBase = readRule();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StatefulSession workingMemory = ruleBase.newStatefulSession();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //go !<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Message message = new Message();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message.setMessage(&nbsp; &quot;Hello World&quot; );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message.setStatus( Message.HELLO );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; workingMemory.insert( message );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; workingMemory.fireAllRules();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; workingMemory.dispose();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Throwable t) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.printStackTrace();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Assert.fail(&quot;Something is wrong: &quot;+t.getMessage());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp;&nbsp; * Please note that this is the &quot;low level&quot; rule assembly API.<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>&nbsp;&nbsp;&nbsp; private RuleBase readRule() throws Exception {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //read in the source<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( &quot;/Sample.drl&quot; ) );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PackageBuilderConfiguration conf = new PackageBuilderConfiguration();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JavaDialectConfiguration javaConf = (JavaDialectConfiguration) conf.getDialectConfiguration(&quot;java&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; javaConf.setJavaLanguageLevel(&quot;1.5&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PackageBuilder builder = new PackageBuilder( conf );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.addPackageFromDrl( source );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ruleBase.addPackage( builder.getPackage() );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ruleBase;<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; Hope it helps,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson<br><br><br><div class="gmail_quote">2008/5/19 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;">Hi list,<br>
<br>
I&#39;m reviving this thread because I happen to have the same problem.<br>
<div class="Ih2E3d"><br>
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;<br>
&gt; Thanks (months later!). &nbsp;I have cut down my code example below to show this<br>
&gt; issue more clearly:<br>
&gt;<br>
&gt;<br>
&gt; John J. Franey wrote:<br>
&gt;&gt;<br>
&gt;&gt; NullPointerException on line 146 means classLoader is null. &nbsp; That is odd.<br>
&gt;&gt; I have no idea why the code that gets classLoader won&#39;t work in eclipse&#39;s<br>
&gt;&gt; junit runtime, but does when run in your eclipse plugin.<br>
<br>
</div>&nbsp;It seems indeed like during JUnit tests, the context classloader of<br>
the thread gets not set (null).<br>
<br>
The code leading up to the problem is as follows:<br>
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();<br>
JavaDialectConfiguration javaConf = (JavaDialectConfiguration)<br>
conf.getDialectConfiguration(&quot;java&quot;);<br>
javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
javaConf.setJavaLanguageLevel(&quot;1.5&quot;);<br>
RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
<br>
The resulting stacktrace is:<br>
java.lang.NullPointerException<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseConfiguration.instantiateClass(RuleBaseConfiguration.java:569)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseConfiguration.determineConsequenceExceptionHandler(RuleBaseConfiguration.java:561)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseConfiguration.init(RuleBaseConfiguration.java:220)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseConfiguration.&lt;init&gt;(RuleBaseConfiguration.java:133)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.common.AbstractRuleBase.&lt;init&gt;(AbstractRuleBase.java:147)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.reteoo.ReteooRuleBase.&lt;init&gt;(ReteooRuleBase.java:124)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.reteoo.ReteooRuleBase.&lt;init&gt;(ReteooRuleBase.java:101)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:57)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:38)<br>
<br>
Has anyone set up Drools and JUnit successfully? Maybe we forgot to<br>
set up the environment properly?<br>
<br>
Best regards<br>
<font color="#888888">Marcus<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<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>