SendEvent failed in Junit test

SendEvent failed in Junit test

book

Article ID: KB0083806

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition 5.4.0

Description

In our rule, we are sending out an event with Event.sendEvent()/Event.routeTo(). The rule works as expected while starting the BE engine. But when running the Junit test with the same project, the following exception is thrown:
2017 Mar 22 16:39:46:094 GMT -7 inference-class Error [main] - [functions.event] [inference-class] Event not sent [id=18] Invalid destination uri [/Channels/JMSChannel/NewDestination_0] specified. Event will not be sent.
java.lang.Exception: Invalid destination uri [/Channels/JMSChannel/NewDestination_0] specified. Event will not be sent.
	at com.tibco.cep.runtime.channel.impl.ChannelManagerImpl.sendEvent(ChannelManagerImpl.java:157)
	at com.tibco.cep.runtime.channel.impl.ChannelManagerImpl.sendEvent(ChannelManagerImpl.java:146)
	at com.tibco.be.functions.event.EventHelper.sendEvent_Impl(SourceFile:130)
	at com.tibco.be.functions.event.EventHelper.sendEvent(SourceFile:110)
	at be.gen.Rules.PriceAdjustmentRule$PriceAdjustmentRule_a.execute(PriceAdjustmentRule.java:77)
	at com.tibco.cep.kernel.core.rete.ReteWM.resolveConflict(SourceFile:401)
	at com.tibco.cep.kernel.core.rete.ReteWM.void(SourceFile:377)
	at com.tibco.cep.kernel.core.rete.ReteWM.assertObject(SourceFile:1729)
	at com.tibco.cep.runtime.session.impl.RuleSessionImpl.assertObject(RuleSessionImpl.java:1450)
	at com.tibco.cep.runtime.service.tester.core.TesterRun.assertObject(TesterRun.java:315)
	at com.tibco.cep.runtime.service.tester.core.TesterRun.assertObject(TesterRun.java:281)
	at com.tibco.cep.runtime.service.tester.beunit.BETestEngine.assertEvent(BETestEngine.java:252)
	at com.tibco.test.BEUnitTestSuite.assertTestData(BEUnitTestSuite.java:139)
	at com.tibco.test.BEUnitTestSuite.testEventAsserted(BEUnitTestSuite.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

 

Issue/Introduction

SendEvent failed in Junit test.

Environment

All

Resolution

This error will be seen while trying to send an event to an invalid destination. By default, the Junit test is starting the BE engine in API mode.
engine = new BETestEngine("D:/BEUnitTest.ear", "C:/BE540_HOME/be/5.4/bin/be-engine.tra", "Deployments/test.cdd", "default", "inference-class", RuleServiceProvider.MODE_API);
Destination is not started while BE engine is started in API mode which causes this error.

Running the Junit test in Primary mode will resolve the issue. To start the BE engine in Primary mode, try removing the last parameter directly, e.g.:
engine = new BETestEngine("D:/BEUnitTest.ear", "C:/BE540_HOME/be/5.4/bin/be-engine.tra", "Deployments/test.cdd", "default", "inference-class");