<br> All,<br><br> 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> 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> @Test<br> public void testRuleBase() {<br> try {<br> <br>
//load up the rulebase<br> RuleBase ruleBase = readRule();<br> StatefulSession workingMemory = ruleBase.newStatefulSession();<br> <br> //go !<br> Message message = new Message();<br>
message.setMessage( "Hello World" );<br> message.setStatus( Message.HELLO );<br> workingMemory.insert( message );<br> workingMemory.fireAllRules();<br> workingMemory.dispose();<br>
<br> } catch (Throwable t) {<br> t.printStackTrace();<br> Assert.fail("Something is wrong: "+t.getMessage());<br> }<br> }<br><br> /**<br> * Please note that this is the "low level" rule assembly API.<br>
*/<br> private RuleBase readRule() throws Exception {<br> //read in the source<br> Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );<br> <br>
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();<br> JavaDialectConfiguration javaConf = (JavaDialectConfiguration) conf.getDialectConfiguration("java");<br> javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
javaConf.setJavaLanguageLevel("1.5");<br> <br> PackageBuilder builder = new PackageBuilder( conf );<br> builder.addPackageFromDrl( source );<br> <br> RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
ruleBase.addPackage( builder.getPackage() );<br> return ruleBase;<br> }<br><br> Hope it helps,<br> Edson<br><br><br><div class="gmail_quote">2008/5/19 Marcus Ilgner <<a href="mailto:marcus.ilgner@gmail.com">marcus.ilgner@gmail.com</a>>:<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'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 <<a href="mailto:mdean77@comcast.net">mdean77@comcast.net</a>> wrote:<br>
><br>
> Thanks (months later!). I have cut down my code example below to show this<br>
> issue more clearly:<br>
><br>
><br>
> John J. Franey wrote:<br>
>><br>
>> NullPointerException on line 146 means classLoader is null. That is odd.<br>
>> I have no idea why the code that gets classLoader won't work in eclipse's<br>
>> junit runtime, but does when run in your eclipse plugin.<br>
<br>
</div> 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("java");<br>
javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
javaConf.setJavaLanguageLevel("1.5");<br>
RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
<br>
The resulting stacktrace is:<br>
java.lang.NullPointerException<br>
at org.drools.RuleBaseConfiguration.instantiateClass(RuleBaseConfiguration.java:569)<br>
at org.drools.RuleBaseConfiguration.determineConsequenceExceptionHandler(RuleBaseConfiguration.java:561)<br>
at org.drools.RuleBaseConfiguration.init(RuleBaseConfiguration.java:220)<br>
at org.drools.RuleBaseConfiguration.<init>(RuleBaseConfiguration.java:133)<br>
at org.drools.common.AbstractRuleBase.<init>(AbstractRuleBase.java:147)<br>
at org.drools.reteoo.ReteooRuleBase.<init>(ReteooRuleBase.java:124)<br>
at org.drools.reteoo.ReteooRuleBase.<init>(ReteooRuleBase.java:101)<br>
at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:57)<br>
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>