use of java.io.File in project camel by apache.
the class FileConfigureTest method assertFileEndpoint.
private void assertFileEndpoint(String endpointUri, String expectedPath, boolean absolute) throws IOException {
FileEndpoint endpoint = resolveMandatoryEndpoint(endpointUri, FileEndpoint.class);
assertNotNull("Could not find endpoint: " + endpointUri, endpoint);
if (!absolute) {
File file = endpoint.getFile();
String path = file.getPath();
assertDirectoryEquals("For uri: " + endpointUri + " the file is not equal", expectedPath, path);
file = new File(expectedPath + (expectedPath.endsWith(File.separator) ? "" : File.separator) + EXPECT_FILE);
GenericFile<File> consumedFile = FileConsumer.asGenericFile(endpoint.getFile().getPath(), file, null, false);
assertEquals(EXPECT_FILE, consumedFile.getRelativeFilePath());
}
}
use of java.io.File in project camel by apache.
the class FileConsumeAlterFileNameHeaderIssueTest method testConsumeAndDeleteRemoveAllHeaders.
public void testConsumeAndDeleteRemoveAllHeaders() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://target/files?delete=true").removeHeaders("*").to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME, "hello.txt");
assertMockEndpointsSatisfied();
oneExchangeDone.matchesMockWaitTime();
assertFalse("Headers should have been removed", mock.getExchanges().get(0).getIn().hasHeaders());
// the original file should have been deleted, as the file consumer should be resilient against
// end users deleting headers
assertFalse("File should been deleted", new File("target/files/hello.txt").exists());
}
use of java.io.File in project camel by apache.
the class FileConsumeAlterFileNameHeaderIssueTest method testConsumeAndMoveChangeFileHeader.
public void testConsumeAndMoveChangeFileHeader() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://target/files").setHeader(Exchange.FILE_NAME, constant("bye.txt")).to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
mock.expectedHeaderReceived(Exchange.FILE_NAME, "bye.txt");
template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME, "hello.txt");
assertMockEndpointsSatisfied();
oneExchangeDone.matchesMockWaitTime();
// the original file should have been moved, as the file consumer should be resilient against
// end users changing headers
assertTrue("File should been moved", new File("target/files/.camel/hello.txt").exists());
}
use of java.io.File in project camel by apache.
the class FileConsumeAlterFileNameHeaderIssueTest method testConsumeAndDeleteChangeFileHeader.
public void testConsumeAndDeleteChangeFileHeader() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://target/files?delete=true").setHeader(Exchange.FILE_NAME, constant("bye.txt")).to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
mock.expectedHeaderReceived(Exchange.FILE_NAME, "bye.txt");
template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME, "hello.txt");
assertMockEndpointsSatisfied();
oneExchangeDone.matchesMockWaitTime();
// the original file should have been deleted, as the file consumer should be resilient against
// end users changing headers
assertFalse("File should been deleted", new File("target/files/hello.txt").exists());
}
use of java.io.File in project camel by apache.
the class FileConsumeCharsetTest method testConsumeAndDelete.
public void testConsumeAndDelete() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World 你好");
assertMockEndpointsSatisfied();
oneExchangeDone.matchesMockWaitTime();
// file should not exists
assertFalse("File should been deleted", new File("target/files/report.txt").exists());
}
Aggregations