I’ve been messing with this, and I can’t get it to behave the way you describe. I’m running this against Camel 2.16.2
The following works for me. Note that I remove the seconds and milliseconds from the filename to make the test a little more reliable - but it’s still vulnerable to false failures because of the potential time difference between when I create my expected filename and when the File component moves the file.
public class PollEnrichFileBuilderTest extends CamelTestSupport {
@Override
public boolean isUseAdviceWith() { return true; }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct://trigger")
.pollEnrich("file://target/data/in?move=../archive/${file:name.noext}-${date:now:yyyyMMddHHmm}.${file:ext}")
.to("mock://complete");
}
};
}
@Test
public void testSingleMessage() throws Exception {
File srcDataDir = new File("src/data");
String srcDataFileName = "message1";
String srcDataFileExtension =".xml";
NotifyBuilder complete = new NotifyBuilder(context).whenDone(1).create();
File testSrcDir = new File("target/data/in");
File testArchiveDir = new File("target/data/archive");
if (testSrcDir.exists()) {
FileUtil.removeDir(testSrcDir);
}
if (testArchiveDir.exists()) {
FileUtil.removeDir(testArchiveDir);
}
testSrcDir.mkdirs();
FileUtil.copyFile(new File(srcDataDir, srcDataFileName + srcDataFileExtension), new File(testSrcDir, srcDataFileName + srcDataFileExtension));
SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMddHHmm");
String expectedFilename = srcDataFileName + "-" + timestampFormat.format(new Date()) + srcDataFileExtension;
context.start();
template.sendBody("direct://trigger", "Dummy Body");
assertTrue("Should have completed on exchange", complete.matches(10, TimeUnit.SECONDS));
assertTrue("Test Archive directory should exist", testArchiveDir.exists());
assertEquals("Should not have any files in source directory", 0, testSrcDir.listFiles().length);
File[] archiveFiles = testArchiveDir.listFiles();
assertEquals("Should only have one file in archive directory", 1, archiveFiles.length);
assertEquals("Unexpected archive file name", archiveFiles[0].getName(), expectedFilename);
}
}
> On Sep 8, 2016, at 1:50 PM, Quinn Stevenson <
[hidden email]> wrote:
>
> I apologize - I missed the "&move=" when I looked at this the first time. What you have looks like it should work to me as well.
>
>
>> On Sep 8, 2016, at 1:45 PM, souciance <
[hidden email]> wrote:
>>
>> Well in that case the documentation needs to be updated because looking at:
>>
https://camel.apache.org/file2.html>> in the section *About movedFailed* that is how it is defined there as well
>> without the fileName. But I will try with the fileName just to verify.
>> Thanks.
>>
>>
>>
>> --
>> View this message in context:
http://camel.465427.n5.nabble.com/PollEnrich-with-file-language-tp5787380p5787386.html>> Sent from the Camel - Users mailing list archive at Nabble.com.
>