Я пытаюсь выполнить тестирование тестового маршрутизатора xpath, но с этим возникли проблемы. вот мой файл контекст:Проблемы с модульным тестированием программы интеграции пружин
<int:channel id="toTransactionTypeRouterChannel" />
<int-xml:xpath-router id="transactionsTypeRouter"
input-channel="toTransactionTypeRouterChannel" resolution-required="false"
evaluate-as-string="true" default-output-channel="errorChannel">
<!-- Select node name of the first child -->
<int-xml:xpath-expression
expression="name(/soapNs:Envelope/soapNs:Body/schNs:processArchiveRequest/schNs:fulfillmentRequest/schNs:requestDetail/*[1])"
namespace-map="archiveNamespaceMap" />
<int-xml:mapping value="sch:bulkRequestDetail"
channel="bulkChannel" />
<int-xml:mapping value="sch:transactionalRequestDetail"
channel="transactionChannel" />
</int-xml:xpath-router>
<int:channel id="bulkChannel" />
<int:channel id="transactionChannel" />
<int:transformer input-channel="bulkChannel"
output-channel="consoleOut" expression="'Bulk channel has received the payload' " />
<int:transformer input-channel="transactionChannel"
output-channel="consoleOut" expression="'Transaction channel has received payload' " />
<int:transformer input-channel="errorChannel"
output-channel="consoleOut" expression="'Error channel has received payload' " />
Как вы можете видеть здесь, есть 2 различные маршруты + ошибка channel.Here мой блок прецедент для транса маршрута канала (навалочные, перли.):
@Test
public void testTransactionFlow() throws Exception {
try {
Resource bulkRequest = new FileSystemResource("src/main/resources/mock-message-examples/SampleProcessArchiveTransRequest.xml");
String transRequestStr= extractResouceAsString(bulkRequest);
toTransactionTypeRouterChannel.send(MessageBuilder.withPayload(transRequestStr).build());
Message<?> outMessage = testChannel.receive(0);
assertNotNull(outMessage);
файл контекста для JUnit
<int:bridge input-channel="transactionChannel"
output-channel="testChannel"/>
<int:channel id="testChannel">
<int:queue/>
</int:channel>
Как вы можете видеть, в файле контекста JUnit, я соединительном транзакционный канал испытания channel.in испытываемого JUnit случае, я посылаю полезную нагрузку на маршрутизатор в junit me и попытаться получить его из входного канала и использовать его для утверждения. однако утверждение терпит неудачу, поскольку сообщение из канала транзакции напрямую переходит к consoleOut, прежде чем направляется на inputChannel, как указано в файле countext junit. Как перехватить сообщение до того, как оно поступит в consoleOut? Я также попытался добавить прослушку перехватчики, но они не сделали работу:
WireTap wireTap = new WireTap(someChannel);
boolean w = wireTap.isRunning();
transactionChannel.addInterceptor(wireTap);
В принципе, мне нужен отдельный поток для модульного тестирования.