2013-04-18 82 views
0

我想要创建的行为如下文件输入:'moveFailed'真的做了什么?

  1. 过程中的交换
  2. 尝试将输入文件复制到共享驱动器
  3. 如果步骤(2)失败(例如份额是向下)然后移动到本地文件而不是

doc的“moveFailed”参数允许“处理后移动文件时设置了不同的目标目录(通过如上所定义的移动配置的)失败”。所以这听起来像moveFailed将包括步骤(3)。

下面的测试,然而失败......我做错了什么?我正在使用骆驼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); 
    } 

} 

回答

0

您的测试很可能是错误的。 autocreate选项默认为true,这意味着如果需要,将创建目录。