[rules-users] Re:JUnit testing

J. Michael Dean mdean77 at comcast.net
Tue Dec 4 22:25:06 EST 2007


>
Thanks.  Sorry for few details as this has been a several message  
question.  I have created a Drools plugin that contains EITHER the  
maximum number of jars and dependencies (i.e. ALL), or the minimum  
(i.e. those needed for compiler option only processing DRL files), or  
adding the entire Drools distribution to my Java extensions folder in  
OS X, and in all instances, I get an error loading dialects.  The  
enigma for me is that all of these plugin options enable me to make a  
stand alone RCP application that works fine.

Here is the test unit code:

	@BeforeClass
	public static void setUp() throws Exception {
		Reader source;
		PackageBuilderConfiguration pkgConfig = new  
PackageBuilderConfiguration();
		JavaDialectConfiguration javaDialectConf =  
(JavaDialectConfiguration) pkgConfig.getDialectConfiguration("java");
		javaDialectConf.setCompiler(JavaDialectConfiguration.ECLIPSE);
		
		final PackageBuilder builder = new PackageBuilder(pkgConfig);
		boolean exists = (new File("rules/GlucoseDroolRules00.drl")).exists();
		if (exists) {
			builder.addPackageFromDrl(new FileReader(
				"rules/GlucoseDroolRules00.drl"));
			System.out.println("Found the file!");
		} else {
			System.out.println("Cannot locate the file - will try as resource");
			source = new InputStreamReader(AllDroolsRulesTests.class
					.getResourceAsStream("rules/GlucoseDroolRules00.drl"));

			builder.addPackageFromDrl(source);
		}
		if (builder.hasErrors()) {
			System.out.println(builder.getErrors().toString());
		}
		Package pkg = builder.getPackage();
		ruleBase = RuleBaseFactory.newRuleBase();
		ruleBase.addPackage(pkg);
	}

It crashes in the line trying to instantiate the package  
configuration.  If I eliminate the lines that configure the package,  
and invoke the package building without an argument (the default),  
then the crash occurs in that line. The crash trace:

org.drools.RuntimeDroolsException: Unable to load dialect  
'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java'
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration 
.addDialect(PackageBuilderConfiguration.java:152)
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration 
.buildDialectConfigurationMap(PackageBuilderConfiguration.java:140)
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:117)
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:94)
	at  
droolsRules.tests.AllDroolsRulesTests.setUp(AllDroolsRulesTests.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at  
sun 
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
39)
	at  
sun 
.reflect 
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 
25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
	at  
org 
.junit 
.internal 
.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
	at  
org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at  
org 
.eclipse 
.jdt 
.internal 
.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at  
org 
.eclipse 
.jdt 
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 
460)
	at  
org 
.eclipse 
.jdt 
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 
673)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 
386)
	at  
org 
.eclipse 
.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 
196)
Caused by: java.lang.NullPointerException
	at  
org 
.drools 
.compiler 
.PackageBuilderConfiguration 
.addDialect(PackageBuilderConfiguration.java:146)
	... 18 more

This trace is identical in all instances.  I have looked at the source  
code and it appears that the Drools code is looking for the drools  
configuration file, and I am not sure if this is included in the  
classpath when running JUnit.  However, the minimal and maximal plugin  
configurations make an RCP run perfectly as a standalone application.

This is Eclipse 3.3 fall version, Mac OXX Leopard (but have run on  
Tiger and same error, so not a new Apple bug), Drools 4.03, and JUnit 4.

Thanks.

> ------------------------------
>
> Message: 8
> Date: Tue, 4 Dec 2007 06:50:15 -0800 (PST)
> From: "John J. Franey" <jjfraney at gmail.com>
> Subject: Re: [rules-users] JUnit testing
> To: rules-users at lists.jboss.org
> Message-ID: <14151759.post at talk.nabble.com>
> Content-Type: text/plain; charset=us-ascii
>
>
>
>
> J Michael Dean wrote:
>>
>> I am having problems figuring out how to do JUnit 4 unit tests with
>> Drools and am wondering what I am missing.
>>
>
> I'm successfully using junit4 to test rules.  I build a rules  
> package from
> my rules file, create a stateful session, insert facts, fire all  
> rules, run
> queries, and finally, perform junit asserts on the results.
>
> I can't tell you what you are missing, unless you say what you have.
>
> Regards,
> John
>
>
> -- 
> View this message in context: http://www.nabble.com/JUnit-testing-tf4930259.html#a14151759
> Sent from the drools - user mailing list archive at Nabble.com.
>
>
>
> ------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> End of rules-users Digest, Vol 13, Issue 6
> ******************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20071204/b3bc1f06/attachment.html 


More information about the rules-users mailing list