[rules-users] JUnit testing

J Michael Dean mdean77 at comcast.net
Sat Dec 1 15:04:08 EST 2007


I am having problems with testing Drools rules;  the code is JUnit  
setup code that is shown below.  However, I get a problem that the  
dialect cannot be opened (see after code).  This problem persists  
whether I tell JUnit to use my core plugin, or if I add every piece of  
code in the Drools distribution.  I added the several lines about Java  
configuration, and this has made no difference.  The crash occurs on  
the first line invoking Drools routines.  I know I am having so much  
trouble with this code that many readers are tiring of my stupidity,  
but I just don't get this.  The core plugin that I am including in the  
classpath runs completely well in the standalone RCP. Thanks for any  
assistance.

- Mike

	@BeforeClass
	public static void setUp() throws Exception {
		Reader source;
		PackageBuilderConfiguration pkgConfig = new  
PackageBuilderConfiguration(); //CRASH OCCURS IN THIS LINE
		JavaDialectConfiguration javaDialectConf =  
(JavaDialectConfiguration) pkgConfig.getDialectConfiguration("java");
		javaDialectConf.setCompiler(JavaDialectConfiguration.ECLIPSE);
		
		final PackageBuilder builder = new PackageBuilder(pkgConfig); //IF  
PREVIOUS THREE LINES DELETED SAME CRASH OCCURS HERE
		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);
	}

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:39)
	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

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


More information about the rules-users mailing list