2013-10-21 217 views
1

我測試我的應用程序,它將文件從ftp發送到我的電腦,我正在檢查不復制一個文件兩次。對於這個我使用IdempotentConsumer
我的問題是,我無法運行測試,因爲這個IdempotentConsumer總是給我錯誤。
這怎麼解決?嘲笑IdempotentConsumer

@Component 
public class Converter extends SpringRouteBuilder { 

@Override 
public void configure() throws Exception { 

final XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat(); 
xmlJsonFormat.setTypeHints(String.valueOf("YES")); 

from("ftp://[email protected]?" + 
     "noop=true&binary=true&consumer.delay=5s&include=.*xml") 
     .idempotentConsumer(header("CamelFileName"), FileIdempotentRepository.fileIdempotentRepository(new File("data", "repo.dat"))) 
     .marshal(xmlJsonFormat).to("file://data").process(
     new Processor() { 
      //System.out.println(); 
     } 
    }); 
    } 
}  

測試類

public class ConverterTest extends CamelTestSupport { 

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

@Test 
public void testAdvisedMockEndpoints() throws Exception { 
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { 
    @Override 
    public void configure() throws Exception { 
     replaceFromWith("direct:inputXML"); 
     interceptSendToEndpoint("file://data") 
       .skipSendToOriginalEndpoint() 
       .to("mock:outXML"); 
    } 
});   

    context.start(); 
    getMockEndpoint("mock:outXML").expectedMessageCount(1);   
    template.sendBody("direct:inputXML", "Test data");   
    assertMockEndpointsSatisfied(); 
} 
} 

,我發現了以下錯誤:

org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: Test data] 
Caused by: org.apache.camel.processor.idempotent.NoMessageIdException: No message ID could be found using expression: header(CamelFileName) on message exchange: Exchange[Message: Test data] 
+1

請分享您遇到的錯誤(詳細)。 –

回答

1

如果啓動上下文normaly CamelFileName頭由FTP組件添加。 但是既然你在測試中直接注入信息,這可能不是這種情況。

嘗試使用.setHeader("CamelFileName", constant("msg01.txt"))手動添加標題來調整您的測試。