[rules-users] JUnit testing

Mike Dean mdean77 at comcast.net
Sun Mar 23 13:34:59 EDT 2008


Thanks (months later!).  I have cut down my code example below to show this
issue more clearly:


John J. Franey wrote:
> 
> NullPointerException on line 146 means classLoader is null.   That is odd. 
> I have no idea why the code that gets classLoader won't work in eclipse's
> junit runtime, but does when run in your eclipse plugin.
> 
> I'm not a plugin developer but I have a hunch that the junit environment
> for plugin development is different than application development. 
> 
> Regards,
> John
> 
> 

<code>
	@BeforeClass
	public static void setUp() throws Exception {
		Reader source;
		PackageBuilderConfiguration pkgConfig = new PackageBuilderConfiguration();
		JavaDialectConfiguration javaDialectConf = (JavaDialectConfiguration)
pkgConfig.getDialectConfiguration("java");
		javaDialectConf.setCompiler(JavaDialectConfiguration.ECLIPSE);
		if (pkgConfig.equals(null)){
			System.out.println("Error - null package configuration");
		} else {
			System.out.println("Package configuration is not null");
			System.out.println(pkgConfig);
		}
		final PackageBuilder builder = new PackageBuilder(pkgConfig);
		....
</code>

The crash occurs in this last line, so it is before I even attempt to find a
DRL file, etc.:

<console>
Package configuration is not null
org.drools.compiler.PackageBuilderConfiguration at 46e381
java.lang.NullPointerException
	at org.mvel.optimizers.OptimizerFactory.<clinit>(OptimizerFactory.java:43)
	at
org.drools.rule.builder.dialect.mvel.MVELDialect.init(MVELDialect.java:142)
	at org.drools.compiler.DialectRegistry.initAll(DialectRegistry.java:49)
	at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:146)
	at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:108)
	at droolsRules.tests.AllDroolsRulesTests.setUp(AllDroolsRulesTests.java:49)
</console>

When I run this in debugging mode and stop just before last line, the
pkgConfig object exists, has a defaultDialect of "java", but in its
dialectConfigurations table, the only HashMap entry is an MVEL Dialect
Configuration.  That is, when I inspect the dialectConfigurations part of my
object, there is no Java dialect.

The javaDialectConf object that I explicitly created is similar - it points
to my pkgConfig object, indicates that it has a default dialect of "java",
but then its dialectConfigurations HashMap only has an entry for MVEL.  

I don't know if any of this makes any sense, but am hoping this information
might provide someone a hint.

Thanks.
-- 
View this message in context: http://www.nabble.com/Re%3AJUnit-testing-tp14164710p16238773.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list