我正在尝试测试以下路线,但由于我希望消息计数为1,但实际上为0,所以它失败了,
即使我路由中的第一个方法beginTransaction
也应无条件调用一次,但不会被调用。
如何在这种情况下进行调试? 看来我的路线本身没有被调用。
在vm:start:portfoliot-tnc
的情况下,我尝试direct:start:portfoliot-tnc
时遇到错误org.apache.camel.component.directvm.DirectConsumerNotAvailableException: No consumers available on endpoint: direct://portfoliot-tnc. Exchange[ID-SPLS1800411-10N-1560229168214-0-1]
此错误是什么意思?为什么说没有消费者可用,而消费者却在嘲笑:结果正在嘲笑我的消息队列。
application-test.properties
tp.portfolio-tnc.source-endpoint: vm:start:portfoliot-tnc
PortfolioRoute.java
from("{{tp.portfolio-tnc.source-endpoint}}")
.routeId("portfolio-tnc-route")
.log(LoggingLevel.INFO, logger,"***** PORTFOLIO-TNC ROUTE STARTED *****")
.doTry()
.bean(transactionManager, "beginTransaction()")
.bean(clientApi, "search(${body},${header.region})")
.setHeader("transactionSize", simple("${body.size()}"))
...
...
..
PortfolioRouteTest.java
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"camel.springboot.java-routes-include-pattern=**/Portfolio*"})
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, SecurityAutoConfiguration.class})
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@DisableJmx(true)
@ActiveProfiles("test")
public class PortfolioTncRouteTest {
...
... //Mocks
...
@Test
public void portfolioTncRouteTest() throws Exception {
Mockito.when(clientApiService.search(Mockito.any(TxnChangeLog.class))).thenReturn(txns);
Mockito.when(cache.getValue("frequencies", "8")).thenReturn("Monthly");
Mockito.when(cache.getValue("currencies", "1002")).thenReturn("USD");
Transaction transaction = new Transaction();
transaction.setRefStatusId(2);
Mockito.when(transactionService.findTransaction(Mockito.any(), Mockito.any())).thenReturn(transaction);
producerTemplate.sendBody(txns);
producerTemplate.start();
Mockito.verify(transactionManager, Mockito.times(1)).beginTransaction();
mock.expectedBodiesReceived();
mock.expectedMessageCount(1);
mock.assertIsSatisfied(30000);
}
}
>> Stacktrace
Wanted but not invoked:
portfolioTncDbTransacitonManager bean.beginTransaction();
-> at org.tp.route.PortfolioTncRouteTest.portfolioTncRouteTest(PortfolioTncRouteTest.java:143)
Actually, there were zero interactions with this mock.
...
...
...
即使我排除了一些路由,它也会在创建xyzRoute bean时引发异常,因此我不得不在我的junit中模拟那些bean,这很奇怪。