First of all, I' moving this to drools-users list.
Hello everybody,
I am new to drools. We have to integrate drools in our application. After
lot of searching a found something very helpful. Here is what I did.
I created a new package say test.
I uploaded a new jar file which contains my model.
I created a new category say banking.
Then I created a rule under the banking category in test package.
Finally I create a new snapshot for deployment.
Then I get the changeset.xml
<change-set xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd'
>
<add>
<resource
source='http://localhost:8080/guvnor-5.2.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/Banking/Test'
type='PKG' />
</add>
</change-set>
Below is the code to test
package com.test;
import junit.framework.TestCase;
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class Test extends TestCase{
public void testDroolsWithGuvnor() throws Exception {
KnowledgeBase knowledgeBase = createKnowledgeBase();
StatefulKnowledgeSession session =
knowledgeBase.newStatefulKnowledgeSession();
try {
Person person = new Person();
person.setAge(20);
session.insert(person);
assertTrue(session.getFactCount() == 1);
session.fireAllRules();
assertTrue(session.getFactCount() == 2);
}
finally {
session.dispose();
}
}
public static KnowledgeBase createKnowledgeBase(){
KnowledgeAgentConfiguration kaconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaconf.setProperty( "drools.agent.scanDirectories", "false"
);
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent( "test
agent", kaconf );
kagent.applyChangeSet(
ResourceFactory.newClassPathResource("ChangeSet(12).xml"));
return kagent.getKnowledgeBase();
}
}
But when i try to test it using junit i get the following exception.
java.lang.NullPointerException
at
org.drools.agent.impl.KnowledgeAgentImpl.processChangeSet(KnowledgeAgentImpl.java:223)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:189)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:174)
at com.test.Test.createKnowledgeBase(Test.java:34)
at com.test.Test.testDroolsWithGuvnor(Test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Dont know how to deal with this
please help
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-NullPointerException-while-testing-tp3378523p3378523.html
Sent from the Drools: Developer (committer) mailing list mailing list archive at Nabble.com.
_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev