use of java.io.File in project camel by apache.
the class FromFtpPreMoveNoopTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from(getFtpUrl()).process(new Processor() {
public void process(Exchange exchange) throws Exception {
// assert the file is pre moved
File file = new File(FTP_ROOT_DIR + "/movefile/work/hello.txt");
assertTrue("The file should have been moved", file.exists());
}
}).to("mock:result");
}
};
}
use of java.io.File in project camel by apache.
the class FromFtpDeleteFileTest method prepareFtpServer.
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server that we want to unit
// test that we can pool and store as a local file
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World this file will be deleted");
exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
// assert file is created
File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt");
assertTrue("The file should exists", file.exists());
}
use of java.io.File in project camel by apache.
the class FromFtpNoopTest method testNoop.
@Test
public void testNoop() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
// we should not be able to poll the file more than once since its noop and idempotent
mock.expectedMessageCount(1);
mock.assertIsSatisfied();
// assert the file is still there
File file = new File(FTP_ROOT_DIR + "/noop/hello.txt");
assertTrue("The file should exists", file.exists());
}
use of java.io.File in project camel by apache.
the class FtpBrowsableEndpointTest method testBrowsableTwoFiles.
@Test
public void testBrowsableTwoFiles() throws Exception {
template.sendBodyAndHeader(getFtpUrl(), "A", Exchange.FILE_NAME, "a.txt");
template.sendBodyAndHeader(getFtpUrl(), "B", Exchange.FILE_NAME, "b.txt");
FtpEndpoint<?> endpoint = context.getEndpoint(getFtpUrl() + "&sortBy=file:name", FtpEndpoint.class);
assertNotNull(endpoint);
MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
assertEquals(0, repo.getCacheSize());
List<Exchange> list = endpoint.getExchanges();
assertNotNull(list);
assertEquals(2, list.size());
assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
assertEquals("b.txt", list.get(1).getIn().getHeader(Exchange.FILE_NAME));
// the in progress repo should not leak
assertEquals(0, repo.getCacheSize());
// and the files is still there
File fileA = new File(FTP_ROOT_DIR + "/browse/a.txt");
assertTrue("File should exist " + fileA, fileA.exists());
File fileB = new File(FTP_ROOT_DIR + "/browse/b.txt");
assertTrue("File should exist " + fileB, fileB.exists());
}
use of java.io.File in project camel by apache.
the class FtpConsumerWithCharsetTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
byte[] iso = payload.getBytes("iso-8859-1");
byte[] utf = payload.getBytes("utf-8");
log.debug("iso: {}", new String(iso, Charset.forName("iso-8859-1")));
log.debug("utf: {}", new String(utf, Charset.forName("utf-8")));
for (byte b : iso) {
log.debug("iso byte: {}", b);
}
for (byte b : utf) {
log.debug("utf byte: {}", b);
}
prepareFtpServer();
// Check that the payload exists in upload and is in iso charset.ß
File file = new File(FTP_ROOT_DIR + "/upload/iso.txt");
assertTrue("The uploaded file should exists", file.exists());
// Lets also test byte wise
InputStream fis = IOHelper.buffered(new FileInputStream(file));
byte[] buffer = new byte[100];
int len = fis.read(buffer);
assertTrue("Should read data: " + len, len != -1);
byte[] data = new byte[len];
System.arraycopy(buffer, 0, data, 0, len);
fis.close();
// data should be in iso, where the danish ae is -26, oe is -8 aa is -27
// and copyright is -87
assertEquals(5, data.length);
assertEquals(-26, data[0]);
assertEquals(-8, data[1]);
assertEquals(-27, data[2]);
assertEquals(32, data[3]);
assertEquals(-87, data[4]);
}
Aggregations