简体   繁体   中英

Mule: JUnit test is not working for file endpoint

On running below flow under Mule server, Message.xml file located at C:\\vikas\\file location moved to C:\\vikas\\file\\error location successfully.

<flow name="Demo" doc:name="Demo">

    <file:inbound-endpoint path="C:\vikas\file\"
        responseTimeout="10000" doc:name="File" />

    <file:outbound-endpoint path="C:\vikas\file\error"
        outputPattern="#[function:datestamp:dd-MM-yy]_#[function:systime].xml"
        responseTimeout="10000" doc:name="ErrorQueue" />
</flow>

But, on running below JUnit test, 913d4c34-c754-11e2-8cfb-696bc9376bf8.dat file is created at C:/vikas/file location instead. Why Message.xml is not copied to C:\\vikas\\file\\error location? How to fix it?

@Test
public void testFile() throws Exception {

    String fileInputPath = "file://C:/vikas/file";
    String payload = IOUtils.getResourceAsString(
            "Message.xml", this.getClass());
    client.dispatch(fileInputPath, payload, null);

    MuleMessage result = client.request(
            "file://C:/vikas/file/error", 5000);
}

I have fixed it after adding Thread.sleep after client.dispatch() method.

@Test
public void testFile() throws Exception {

    String fileInputPath = "file://C:/vikas/file";
    String payload = IOUtils.getResourceAsString(
            "Message.xml", this.getClass());
    client.dispatch(fileInputPath, payload, null);

    Thread.sleep(685000);

    MuleMessage result = client.request(
            "file://C:/vikas/file/error", 5000);
}

Since dispatch is asynchronous method, Mule need some waiting time to complete the file move process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM