use of java.io.File in project camel by apache.
the class DirectoryCreateIssueTest method testFileCreatedAsDir.
public void testFileCreatedAsDir() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(numFiles);
template.send("seda:testFileCreatedAsDir", new Processor() {
public void process(Exchange exchange) {
Message in = exchange.getIn();
in.setBody("Contents of test file");
}
});
assertMockEndpointsSatisfied();
// wait a little while for the files to settle down
Thread.sleep(200);
for (int i = 0; i < numFiles; i++) {
assertTrue((new File(path + "/file" + i + ".txt")).isFile());
}
}
use of java.io.File in project camel by apache.
the class FileAbsoluteAndRelativeConsumerTest method setUp.
@Override
protected void setUp() throws Exception {
deleteDirectory("target/filerelative");
deleteDirectory("target/fileabsolute");
// use current dir as base as aboslute path
base = new File("").getAbsolutePath() + "/target/fileabsolute";
super.setUp();
}
use of java.io.File in project camel by apache.
the class FileBrowsableEndpointTest method testBrowsableOneFile.
public void testBrowsableOneFile() throws Exception {
template.sendBodyAndHeader("file:target/browse", "A", Exchange.FILE_NAME, "a.txt");
FileEndpoint endpoint = context.getEndpoint("file:target/browse", FileEndpoint.class);
assertNotNull(endpoint);
MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
assertEquals(0, repo.getCacheSize());
List<Exchange> list = endpoint.getExchanges();
assertNotNull(list);
assertEquals(1, list.size());
assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
// the in progress repo should not leak
assertEquals(0, repo.getCacheSize());
// and the file is still there
File file = new File("target/browse/a.txt");
assertTrue("File should exist " + file, file.exists());
}
use of java.io.File in project camel by apache.
the class FileBrowsableEndpointTest method testBrowsableThreeFilesRecursive.
public void testBrowsableThreeFilesRecursive() throws Exception {
template.sendBodyAndHeader("file:target/browse", "A", Exchange.FILE_NAME, "a.txt");
template.sendBodyAndHeader("file:target/browse", "B", Exchange.FILE_NAME, "foo/b.txt");
template.sendBodyAndHeader("file:target/browse", "C", Exchange.FILE_NAME, "bar/c.txt");
FileEndpoint endpoint = context.getEndpoint("file:target/browse?recursive=true&sortBy=file:name", FileEndpoint.class);
assertNotNull(endpoint);
MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
assertEquals(0, repo.getCacheSize());
List<Exchange> list = endpoint.getExchanges();
assertNotNull(list);
assertEquals(3, list.size());
assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
assertEquals("c.txt", list.get(1).getIn().getHeader(Exchange.FILE_NAME_ONLY));
assertEquals("b.txt", list.get(2).getIn().getHeader(Exchange.FILE_NAME_ONLY));
// the in progress repo should not leak
assertEquals(0, repo.getCacheSize());
// and the files is still there
File fileA = new File("target/browse/a.txt");
assertTrue("File should exist " + fileA, fileA.exists());
File fileB = new File("target/browse/foo/b.txt");
assertTrue("File should exist " + fileB, fileB.exists());
File fileC = new File("target/browse/bar/c.txt");
assertTrue("File should exist " + fileC, fileC.exists());
}
use of java.io.File in project camel by apache.
the class FileConcurrentWriteAppendSameFileTest method testConcurrentAppend.
public void testConcurrentAppend() throws Exception {
// create file with many lines
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size; i++) {
sb.append("Line " + i + LS);
}
template.sendBodyAndHeader("file:target/concurrent", sb.toString(), Exchange.FILE_NAME, "input.txt");
// start route
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(size);
mock.expectsNoDuplicates(body());
mock.setResultWaitTime(30000);
// we need to wait a bit for our slow CI server to make sure the entire file is written on disc
Thread.sleep(1000);
context.startRoute("foo");
assertMockEndpointsSatisfied();
// check the file has correct number of lines
String txt = context.getTypeConverter().convertTo(String.class, new File("target/concurrent/outbox/result.txt"));
assertNotNull(txt);
String[] lines = txt.split(LS);
assertEquals("Should be " + size + " lines", size, lines.length);
// should be unique
Set<String> rows = new LinkedHashSet<String>(Arrays.asList(lines));
assertEquals("Should be " + size + " unique lines", size, rows.size());
log.info(txt);
}
Aggregations