0

I want to create a file input that behaves as follows:

  1. Process the exchange
  2. Attempt to copy the input file to a shared drive
  3. If step (2) fails (e.g. share is down) then move to local file instead

Following the doc the 'moveFailed' parameter allows to "set a different target directory when moving files after processing (configured via move defined above) failed". So this sounds like the moveFailed would cover step (3).

The following test, however fails...what am I doing wrong ? I am using camel 2.10.0.fuse.

package sandbox.camel;

import java.io.File;    
import org.apache.camel.Endpoint;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;

public class MoveFailedTest extends org.apache.camel.test.junit4.CamelTestSupport {

    private String failedDir = "move-failed";

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {



            @Override
            public void configure() throws Exception {
                from("file:tmp/prepare").to("file:tmp/input");
                from("file:tmp/input?move=/doesnotexist&moveFailed=" + failedDir).to("file:tmp/output");
            }
        };
    }        

    @Test
    public void test_move() throws Exception {

        // arrange
        File moveFailedDir = new File("tmp/input/" + failedDir);
        moveFailedDir.mkdirs();
        File[] failedCount1 = moveFailedDir.listFiles();
        failedCount1 = failedCount1 == null ? new File[0] : failedCount1;
        String messagePayload = "Hello";

        Endpoint input = getMandatoryEndpoint("file:tmp/prepare");
        MockEndpoint output = getMockEndpoint("mock:file:tmp/output");
        output.setMinimumExpectedMessageCount(1);
        output.expectedBodiesReceived(messagePayload);

        // act
        template.asyncSendBody(input, messagePayload);
        Thread.sleep(3000);

        // assert: only 1 output
        assertMockEndpointsSatisfied();
        // assert: renamed failed, hence input file was moved to 'movefailed' directory
        File[] failedCount2 = moveFailedDir.listFiles();
        assertEquals("No file appeared in 'movefailed' directory", failedCount1.length + 1, failedCount2.length);
    }

}

1 Answers1

0

Your test is most likely wrong. The autocreate option is default true, which means directories is created if needed.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65