use of java.io.File in project camel by apache.
the class FileConsumerCommitRenameAbsolutePathStrategyTest method setUp.
@Override
protected void setUp() throws Exception {
deleteDirectory("target/done");
deleteDirectory("target/reports");
// use current dir as base as aboslute path
base = new File("").getAbsolutePath() + "/target";
super.setUp();
}
use of java.io.File in project camel by apache.
the class FileConsumerCommitRenameStrategyTest method testRenameFileExists.
public void testRenameFileExists() throws Exception {
// create a file in done to let there be a duplicate file
File file = new File("target/done");
file.mkdirs();
FileWriter fw = new FileWriter("target/done/london.txt");
try {
fw.write("I was there once in London");
fw.flush();
} finally {
fw.close();
}
MockEndpoint mock = getMockEndpoint("mock:report");
mock.expectedBodiesReceived("Hello London");
template.sendBodyAndHeader("file:target/reports", "Hello London", Exchange.FILE_NAME, "london.txt");
mock.assertIsSatisfied();
oneExchangeDone.matchesMockWaitTime();
// content of file should be Hello London
String content = IOConverter.toString(new File("target/done/london.txt"), null);
assertEquals("The file should have been renamed replacing any existing files", "Hello London", content);
}
use of java.io.File in project camel by apache.
the class CachedOutputStreamTest method testCachedOutputStreamCustomBufferSize.
public void testCachedOutputStreamCustomBufferSize() throws Exception {
// double the default buffer size
context.getStreamCachingStrategy().setBufferSize(8192);
context.start();
CachedOutputStream cos = new CachedOutputStream(exchange);
cos.write(TEST_STRING.getBytes("UTF-8"));
assertEquals("we should have a custom buffer size", cos.getStrategyBufferSize(), 8192);
// make sure things still work after custom buffer size set
File file = new File("target/cachedir");
String[] files = file.list();
assertEquals("we should have a temp file", 1, files.length);
assertTrue("The file name should start with cos", files[0].startsWith("cos"));
StreamCache cache = cos.newStreamCache();
assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
String temp = toString((InputStream) cache);
assertEquals("Cached a wrong file", temp, TEST_STRING);
cache.reset();
temp = toString((InputStream) cache);
assertEquals("Cached a wrong file", temp, TEST_STRING);
((InputStream) cache).close();
files = file.list();
assertEquals("we should have a temp file", 1, files.length);
exchange.getUnitOfWork().done(exchange);
files = file.list();
assertEquals("we should have no temp file", 0, files.length);
IOHelper.close(cos);
}
use of java.io.File in project camel by apache.
the class CachedOutputStreamTest method testCacheStreamToFileAndCloseStream.
public void testCacheStreamToFileAndCloseStream() throws Exception {
context.start();
CachedOutputStream cos = new CachedOutputStream(exchange);
cos.write(TEST_STRING.getBytes("UTF-8"));
File file = new File("target/cachedir");
String[] files = file.list();
assertEquals("we should have a temp file", 1, files.length);
assertTrue("The file name should start with cos", files[0].startsWith("cos"));
StreamCache cache = cos.newStreamCache();
assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
String temp = toString((InputStream) cache);
((InputStream) cache).close();
files = file.list();
assertEquals("we should have a temp file", 1, files.length);
assertEquals("Cached a wrong file", temp, TEST_STRING);
exchange.getUnitOfWork().done(exchange);
try {
cache.reset();
// The stream is closed, so the temp file is gone.
fail("we expect the exception here");
} catch (Exception exception) {
// do nothing
}
files = file.list();
assertEquals("we should have no temp file", 0, files.length);
IOHelper.close(cos);
}
use of java.io.File in project camel by apache.
the class FileInputStreamCacheTest method testFileInputStreamCache.
public void testFileInputStreamCache() throws Exception {
File file = new File(TEST_FILE);
FileInputStreamCache cache = new FileInputStreamCache(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
cache.writeTo(bos);
String s = context.getTypeConverter().convertTo(String.class, bos);
assertNotNull(s);
assertTrue(s.contains("<firstName>James</firstName>"));
IOHelper.close(cache, bos);
}
Aggregations