Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring集成程序的单元测试问题_Spring_Unit Testing_Spring Integration - Fatal编程技术网

spring集成程序的单元测试问题

spring集成程序的单元测试问题,spring,unit-testing,spring-integration,Spring,Unit Testing,Spring Integration,我试图对xpath路由器进行单元测试,但遇到了问题。这是我的上下文文件: <int:channel id="toTransactionTypeRouterChannel" /> <int-xml:xpath-router id="transactionsTypeRouter" input-channel="toTransactionTypeRouterChannel" resolution-required="false" evaluate-as

我试图对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' " />   

基本上,我需要一个单独的流程来进行单元测试。

使用该配置,您只需向transactionChannel添加第二个使用者-消息将循环分发到转换器和桥接器

您可以通过将transformer按id自动连接为EventDrivenConsumer来取消对测试用例的订阅,并在发送消息之前停止它

        @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);
    <int:bridge input-channel="transactionChannel"
    output-channel="testChannel"/>
    <int:channel id="testChannel">
    <int:queue/>
</int:channel>
     WireTap  wireTap = new WireTap(someChannel);
        boolean w = wireTap.isRunning();        
        transactionChannel.addInterceptor(wireTap);