<br> Thanks Marcus,<br><br> We will include the patch in the next drools release! We do appreciate the contribution.<br><br> Edson<br><br><div class="gmail_quote">2008/5/22 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;">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 <<a href="mailto:mdean77@comcast.net">mdean77@comcast.net</a>> wrote:<br>
><br>
> Sorry to ask question and then figure it out! I just substituted the actual<br>
> name of my suite class instead of saying this.class and it works<br>
> beautifully. I am now testing Drools with JUnit 4 with no problems, after<br>
> nearly six months! THANK YOU.<br>
><br>
> - Mike<br>
><br>
> Mike Dean wrote:<br>
>><br>
>> Thanks to both of you for pursuing this problem. I have worked around it<br>
>> by putting my business classes and rules in a separate Drools project,<br>
>> testing everything there, and then copying them to my RCP. I look forward<br>
>> to a better solution!<br>
>><br>
>> I must confess Java ignorance, but I use a test suite and try to<br>
>> instantiate the engine once and then run a series of tests. My crash<br>
>> occurs before I get to the individual tests. However, the setUp routine<br>
>> is static, and your code work around cannot be executed in a static<br>
>> context. Where exactly to you put the test for a null classloader?<br>
>><br>
>> Thanks again. I thought this issue simply died.<br>
>><br>
>><br>
>> Marcus Ilgner wrote:<br>
>>><br>
>>> Hi Edson,<br>
>>><br>
>>> thank you very much for testing this! Since I could not discern any<br>
>>> differences between your approach and mine, I decided to resolve the<br>
>>> issue manually by inserting a work-around in my test routine which<br>
>>> sets the context class loader for the current thread before calling<br>
>>> the method under test.<br>
>>><br>
>>> if (Thread.currentThread().getContextClassLoader() == null) {<br>
>>><br>
>>> Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());<br>
>>> }<br>
>>><br>
>>> My guess is that the custom JUnit 4 class runner<br>
>>> (SpringJUnit4ClassRunner) somehow is responsible for the faulty<br>
>>> behaviour.<br>
>>><br>
>>> Thanks again<br>
>>> Marcus<br>
>>><br>
>>><br>
>>> On Mon, May 19, 2008 at 3:09 PM, Edson Tirelli <<a href="mailto:tirelli@post.com">tirelli@post.com</a>> wrote:<br>
>>>><br>
>>>> All,<br>
>>>><br>
>>>> I see that the code in that spot is weak and could be improved.<br>
>>>> Although,<br>
>>>> using drools 4.0.7, I successfully created a junit 4 test that I paste<br>
>>>> bellow. Also, the whole drools code is tested with junit 3 and we have<br>
>>>> no<br>
>>>> 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/" target="_blank">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<br>
>>>> 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 =<br>
>>>> 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(<br>
>>>> DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );<br>
>>>><br>
>>>> PackageBuilderConfiguration conf = new<br>
>>>> PackageBuilderConfiguration();<br>
>>>> JavaDialectConfiguration javaConf = (JavaDialectConfiguration)<br>
>>>> 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>
>>>> 2008/5/19 Marcus Ilgner <<a href="mailto:marcus.ilgner@gmail.com">marcus.ilgner@gmail.com</a>>:<br>
>>>>><br>
>>>>> Hi list,<br>
>>>>><br>
>>>>> I'm reviving this thread because I happen to have the same problem.<br>
>>>>><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<br>
>>>>> show<br>
>>>>> > this<br>
>>>>> > issue more clearly:<br>
>>>>> ><br>
>>>>> ><br>
>>>>> > John J. Franey wrote:<br>
>>>>> >><br>
>>>>> >> NullPointerException on line 146 means classLoader is null. That<br>
>>>>> is<br>
>>>>> >> odd.<br>
>>>>> >> I have no idea why the code that gets classLoader won't work in<br>
>>>>> >> eclipse's<br>
>>>>> >> junit runtime, but does when run in your eclipse plugin.<br>
>>>>><br>
>>>>> 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<br>
>>>>> org.drools.RuleBaseConfiguration.instantiateClass(RuleBaseConfiguration.java:569)<br>
>>>>> at<br>
>>>>> org.drools.RuleBaseConfiguration.determineConsequenceExceptionHandler(RuleBaseConfiguration.java:561)<br>
>>>>> at<br>
>>>>> org.drools.RuleBaseConfiguration.init(RuleBaseConfiguration.java:220)<br>
>>>>> at<br>
>>>>> org.drools.RuleBaseConfiguration.<init>(RuleBaseConfiguration.java:133)<br>
>>>>> at<br>
>>>>> org.drools.common.AbstractRuleBase.<init>(AbstractRuleBase.java:147)<br>
>>>>> at<br>
>>>>> org.drools.reteoo.ReteooRuleBase.<init>(ReteooRuleBase.java:124)<br>
>>>>> at<br>
>>>>> org.drools.reteoo.ReteooRuleBase.<init>(ReteooRuleBase.java:101)<br>
>>>>> at<br>
>>>>> org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:57)<br>
>>>>> at<br>
>>>>> 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>
>>>>> Marcus<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>
>>><br>
>>><br>
>><br>
>><br>
><br>
> --<br>
> 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>
> Sent from the drools - user mailing list archive at Nabble.com.<br>
><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>
><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>