use of java.io.InputStream in project camel by apache.
the class LogInputStreamTest method testD.
public void testD() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:d");
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello World");
InputStream is = new ByteArrayInputStream("Hello World".getBytes());
template.sendBody("direct:d", is);
assertMockEndpointsSatisfied();
}
use of java.io.InputStream in project camel by apache.
the class ConverterTest method testConvertStringAndStreams.
public void testConvertStringAndStreams() throws Exception {
InputStream inputStream = converter.convertTo(InputStream.class, "bar");
assertNotNull(inputStream);
String text = converter.convertTo(String.class, inputStream);
assertEquals("Converted to String", "bar", text);
}
use of java.io.InputStream in project camel by apache.
the class XmlConverterTest method testToInputStreamFromDocument.
public void testToInputStreamFromDocument() throws Exception {
XmlConverter conv = new XmlConverter();
Document doc = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
InputStream is = conv.toInputStream(doc, null);
assertNotNull(is);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, is));
}
use of java.io.InputStream in project camel by apache.
the class XmlConverterTest method testToSaxSourceByInputStream.
public void testToSaxSourceByInputStream() throws Exception {
XmlConverter conv = new XmlConverter();
InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<foo>bar</foo>");
SAXSource out = conv.toSAXSource(is, null);
assertNotNull(out);
assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
use of java.io.InputStream in project camel by apache.
the class CachedOutputStreamTest method testCacheStreamToFileAndCloseStreamEncrypted.
public void testCacheStreamToFileAndCloseStreamEncrypted() throws Exception {
// set some stream or 8-bit block cipher transformation name
context.getStreamCachingStrategy().setSpoolChiper("RC4");
context.start();
CachedOutputStream cos = new CachedOutputStream(exchange);
cos.write(TEST_STRING.getBytes("UTF-8"));
cos.flush();
File file = new File("target/cachedir");
String[] files = file.list();
assertEquals("we should have a temp file", 1, files.length);
assertTrue("The content is written", new File(file, files[0]).length() > 10);
java.io.FileInputStream tmpin = new java.io.FileInputStream(new File(file, files[0]));
String temp = toString(tmpin);
assertTrue("The content is not encrypted", temp.length() > 0 && temp.indexOf("aaa") < 0);
tmpin.close();
StreamCache cache = cos.newStreamCache();
assertTrue("Should get the FileInputStreamCache", cache instanceof FileInputStreamCache);
temp = toString((InputStream) cache);
((InputStream) cache).close();
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);
}
Aggregations