camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siano, Stephan" <>
Subject Camel build, tests and charsets
Date Fri, 29 Apr 2016 12:49:12 GMT

I have found an issue with the camel-csv component. The fix itself is pretty trivial (a one-liner
to use the IOHelper.getCharsetName(exchange)) for an OutputStreamWriter in the marhaller (the
InputStreamWriter in the unmarshaller already does this).

However I have some difficulties with the unit test.

1.       The issue will only happen if there are non-ASCII characters in the code. As far
as I understand it is not exactly desired to have those in the coding (on the other hand I
just copied the appropriate test for the unmarshaller and that one does also have german umlaut
characters in the code.

2.       The test only fails (with the original code) if the default encoding on the JVM that
executes this is not UTF-8. There is some very hacky way to change the JVM default encoding
for a test but I would not want to contribute that.

I put the test into this mail as an example (because it is short enough to demonstrate the
issues). How could I test this properly? Wouldn't it be a good idea in general to run tests
with an ASCII default charset to find issues with default encodings better (set file.encoding
to "ASCII" in the surefire plugin configuration)?

Best regards

public class CsvMarshalCharsetTest extends CamelTestSupport {

    public static void hackEncoding() throws NoSuchFieldException, SecurityException, IllegalArgumentException,
IllegalAccessException {
        System.setProperty("file.encoding", "ASCII");
        Field charset = Charset.class.getDeclaredField("defaultCharset");
        charset.set(null, null);

    public void testMarshal() throws Exception {
        MockEndpoint endpoint = getMockEndpoint("mock:daltons");

        List<List<String>> data = new ArrayList<List<String>>();
        data.add(0, new ArrayList<String>());
        data.get(0).add(0, "Lücky Luke");
        template.sendBody("direct:start", data);


        Exchange exchange = endpoint.getExchanges().get(0);
        String body = exchange.getIn().getBody(String.class);
        assertThat(body, startsWith("Lücky Luke"));

    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message