什么' moveFailed'真的吗?

时间:2013-04-18 02:48:38

标签: apache-camel fuseesb

我想创建一个行为如下的文件输入:

  1. 处理交换
  2. 尝试将输入文件复制到共享驱动器
  3. 如果步骤(2)失败(例如,共享已关闭),则转移到本地文件
  4. doc之后,'moveFailed'参数允许“在处理后移动文件时设置不同的目标目录(通过上面定义的移动配置)失败”。所以这听起来像moveFailed将涵盖步骤(3)。

    然而,以下测试失败了...我做错了什么?我使用的是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 个答案:

答案 0 :(得分:0)

您的测试很可能是错误的。 autocreate选项默认为true,表示在需要时创建目录。