Hi,
Could you try the following to see if you get the same problem please?
I modified the following class which is generated by default when creating a
Drools Project in eclipse:
( I highlighted in bold the lines of code I have added)
Then I tried to compile the class, including all the necessary jar files in
the classpath manually (I have puteverything in the same Java directory so
that it is easier to follow (ie no long dir paths)).
*javac -cp
"./drools-core.jar;./knowledge-api.jar;./mockito-all-1.9.0.jar;./drools-compiler.jar;./drools-jsr94.jar;./drools-decisiontables.jar"
DroolsTest.java*
I get the same error as before:
*
DroolsTest.java:33: cannot find symbol
symbol : method addListener(org.drools.event.AgendaEventListener)
location: interface org.drools.runtime.StatefulKnowledgeSession
ksession.addListener(ael);*
The reason why I did this was to eliminate any possible issue with spring or
maven. I just took the default class and tried to compile it.
Please see if you can replicate this.
many thanks.
package com.me;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
*import static org.mockito.Mockito.*;
import org.drools.event.AgendaEventListener;*
/**
* This is a sample class to launch a rule.
*/
public class DroolsTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
* AgendaEventListener ael = mock(AgendaEventListener.class);
ksession.addListener(ael);
*
ksession.insert(message);
ksession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
ResourceType.DRL);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus(int status) {
this.status = status;
}
}
}
--
View this message in context:
http://drools.46999.n3.nabble.com/JUnit-Test-Mockito-AgendaEventListener-...
Sent from the Drools: User forum mailing list archive at
Nabble.com.