[rules-users] Cannot use ViewChangeEventListener in tests

mreynolds mireynol at redhat.com
Thu Oct 24 19:19:06 EDT 2013


I am testing an application using Fusion with Cucumber. I create a knowledge
session with the pseudo clock such that I have control over how the clock
advances.

I insert events built from Cucumber data tables with a loop that also
advances the pseudo clock the approriate amount of time. Some of my
scenarios involve complex events being inserted and then retracted before an
external action is taken. From what I read I can use a LiveQuery and a
ViewChangeEventListener in my tests for running my assertions at the end of
the test case.

In my test case, the warnings list is always 0 in length, none of the log
messages get triggered, and the debug view of the LiveQueryImpl is mostly
uninteresting. I can see from the Audit log however that in this case there
was indeed a Warning object added and thus I believe rowAdded should have
been invocated.

I have the following query:
query "Collect Warnings"
	$warnings : Warning()
end

And the following support code in the @Setup method of my cucumber step
definitions:

// parts have been truncated for relevance and possibly brevity
private LiveQuery query; // this is declared as a variable
private List<Warning> warnings = new ArrayList<Warning>();

@Before
public void setup() {
	session = getKnowledgeSession(); // truncated for brevity

	ViewChangedEventListener listener = new ViewChangedEventListener() {

		public void rowUpdated( Row row ) {
                    logger.info( "rowUpdated" );
                    warnings.add( (Warning) row.get( "$warnings" ) );
                }

                public void rowRemoved( Row row ) {
                    logger.info( "rowRemoved" );
                    warnings.add( (Warning) row.get( "$warnings" ) );
                }

                public void rowAdded( Row row ) {
                    logger.info( "rowAdded" );
                    warnings.add( (Warning) row.get( "$warnings" ) );
                }

	};

	// Open the LiveQuery
	query = application.getKnowledgeSession().openLiveQuery( "Collect
Warnings", new Object[] { "$warnings" }, listener );
}



--
View this message in context: http://drools.46999.n3.nabble.com/Cannot-use-ViewChangeEventListener-in-tests-tp4026491.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list