Trying to point at Guvnor with a URL, and the JBoss console indicates that
Guvnor is being properly hit. However, the following test case succeeds
only when I leave the try..catch clauses in both locations; if I remove the
try..catch clauses then the code does not finish (does not fail). However,
even when the unit test passes, I get the console message that follows the
test case. The model itself already has an import and declaration of the
class in question (top of source as reported by Guvnor is also shown). I am
confused by the fact that this test passes when I add the try .. catch
clauses (probably my Java naivete) but more perplexed because of the
exception. Have also uploaded the test case code and the DRL downloaded
from Guvnor in case it would be helpful. Assistance greatly appreciated.
- Mike
http://www.nabble.com/file/p22100280/KnowledgeFromGuvnorTest.java
KnowledgeFromGuvnorTest.java
http://www.nabble.com/file/p22100280/glucose.decision.rules.drl
glucose.decision.rules.drl
TEST CASE
package drools.engine;
import static org.junit.Assert.*;
import java.util.Collection;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgePackage;
import org.drools.io.ResourceFactory;
import org.junit.Test;
public class KnowledgeFromGuvnorTest {
private KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
private KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
@Test
public void testKnowledgeEngineFromURL(){
KnowledgeEngineFromGuvnor engine;
try {
engine = new
KnowledgeEngineFromGuvnor("http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/glucose.decision.rules/LATEST",
true);
}catch (Exception e) {
e.printStackTrace();
engine = null;
}
assertNotNull("Knowledge engine should not be null", engine);
assertFalse("There should not be builder errors", kbuilder.hasErrors());
}
public class KnowledgeEngineFromGuvnor {
public KnowledgeEngineFromGuvnor(String url, boolean guvnor) {
super();
System.out.println("Pushing URL into kbuilder");
try {
kbuilder.add(ResourceFactory.newUrlResource(url), ResourceType.PKG);
} catch (Exception e) {
System.out.println("Error occurred when URL was passed");
e.printStackTrace();
}
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
System.out.println("Unable to compile " + url + ".");
throw new RuntimeException("Bad things happened in
KnowledgeEngineFromGuvnor");
}
final Collection<KnowledgePackage> pkgs = kbuilder
.getKnowledgePackages();
kbase.addKnowledgePackages(pkgs);
}
}
}
SYSTEM CONSOLE OUTPUT
Pushing URL into kbuilder
Error occurred when URL was passed
org.drools.RuntimeDroolsException: unable to resolve Type Declaration class
'GlucoseDecisionState'
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:766)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:521)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:30)
at
drools.engine.KnowledgeFromGuvnorTest$KnowledgeEngineFromGuvnor.<init>(KnowledgeFromGuvnorTest.java:43)
at
drools.engine.KnowledgeFromGuvnorTest.testKnowledgeEngineFromURL(KnowledgeFromGuvnorTest.java:27)
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.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at
org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
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)
TOP OF SOURCE FROM GUVNOR
package glucose.decision.rules
import glucose.decision.object.GlucoseDecision;
import glucose.decision.object.GlucoseDecisionState;
declare GlucoseDecision
@propertyChangeSupport
end
declare GlucoseDecisionState
@propertyChangeSupport
end
(WHOLE BUNCH OF RULES FOLLOW)
JBOSS CONSOLE OUTPUT
06:08:33,104 INFO [STDOUT] PackageName: glucose.decision.rules
06:08:33,104 INFO [STDOUT] PackageVersion: LATEST
06:08:33,105 INFO [STDOUT] PackageIsLatest: true
06:08:33,105 INFO [STDOUT] PackageIsSource: false
--
View this message in context:
http://www.nabble.com/Type-Declaration-exception-from-Guvnor-tp22100280p2...
Sent from the drools - user mailing list archive at
Nabble.com.