use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class StaticFallbackConverterTest method testStaticFallbackConverter.
public void testStaticFallbackConverter() throws Exception {
Exchange exchange = new DefaultExchange(context);
TimeZone tz = TimeZone.getDefault();
String money = context.getTypeConverter().convertTo(String.class, exchange, tz);
assertEquals("Time talks", money);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class StaticFallbackConverterTest method testStaticFallbackMandatoryConverter.
public void testStaticFallbackMandatoryConverter() throws Exception {
Exchange exchange = new DefaultExchange(context);
TimeZone tz = TimeZone.getDefault();
String money = context.getTypeConverter().mandatoryConvertTo(String.class, exchange, tz);
assertEquals("Time talks", money);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class StaticFallbackConverterTest method testStaticFallbackMandatoryFailed.
public void testStaticFallbackMandatoryFailed() throws Exception {
Exchange exchange = new DefaultExchange(context);
try {
context.getTypeConverter().mandatoryConvertTo(Date.class, exchange, new Timestamp(0));
fail("Should have thrown an exception");
} catch (NoTypeConversionAvailableException e) {
// expected
}
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class StAX2SAXSourceTest method testDefaultPrefixInRootElementWithCopyTransformer.
public void testDefaultPrefixInRootElementWithCopyTransformer() throws Exception {
TransformerFactory trf = TransformerFactory.newInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamReader reader = context.getTypeConverter().mandatoryConvertTo(XMLStreamReader.class, new StringReader(TEST_XML));
// ensure UTF-8 encoding
Exchange exchange = new DefaultExchange(context);
exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.toString());
XMLStreamWriter writer = context.getTypeConverter().mandatoryConvertTo(XMLStreamWriter.class, exchange, baos);
StAX2SAXSource staxSource = new StAX2SAXSource(reader);
StreamSource templateSource = new StreamSource(getClass().getResourceAsStream("/xslt/common/copy.xsl"));
Transformer transformer = trf.newTransformer(templateSource);
log.info("Used transformer: {}", transformer.getClass().getName());
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(staxSource, new StreamResult(baos));
writer.flush();
baos.flush();
assertThat(new String(baos.toByteArray()), equalTo(TEST_XML));
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class IOConverterTest method testToInputStreamStringBufferAndBuilderExchange.
public void testToInputStreamStringBufferAndBuilderExchange() throws Exception {
Exchange exchange = new DefaultExchange(context);
exchange.setProperty(Exchange.CHARSET_NAME, ObjectHelper.getDefaultCharacterSet());
StringBuffer buffer = new StringBuffer();
buffer.append("Hello World");
InputStream is = IOConverter.toInputStream(buffer, exchange);
assertNotNull(is);
assertEquals("Hello World", IOConverter.toString(is, exchange));
StringBuilder builder = new StringBuilder();
builder.append("Hello World");
is = IOConverter.toInputStream(builder, exchange);
assertNotNull(is);
assertEquals("Hello World", IOConverter.toString(is, exchange));
}
Aggregations