1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.adapter;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.io.ByteArrayInputStream;
21 import java.io.InputStream;
22 import java.io.Reader;
23 import java.io.StringReader;
24 import java.nio.charset.Charset;
25
26 import javax.xml.transform.stream.StreamSource;
27
28 import org.apache.camel.ExchangePattern;
29 import org.apache.commons.io.IOUtils;
30 import org.junit.Test;
31 import org.openehealth.ipf.platform.camel.core.AbstractRouteTest;
32
33
34
35
36
37 public class ConverterRouteTest extends AbstractRouteTest {
38
39 @Test
40 public void testConverter1() throws InterruptedException {
41 String result = (String) producerTemplate.sendBody("direct:converter-test",
42 ExchangePattern.InOut, "input");
43 assertEquals("string: input", result);
44 }
45
46 @Test
47 public void testConverter2() throws Exception {
48 InputStream result = (InputStream) producerTemplate.sendBody("direct:converter-test",
49 ExchangePattern.InOut, new ByteArrayInputStream("input".getBytes()));
50 assertEquals("stream: input", IOUtils.toString(result, Charset.defaultCharset()));
51 }
52
53 @Test
54 public void testConverter3() throws Exception {
55 Reader result = (Reader) producerTemplate.sendBody("direct:converter-test",
56 ExchangePattern.InOut, new StringReader("input"));
57 assertEquals("reader: input", IOUtils.toString(result));
58 }
59
60 @Test
61 public void testConverter4() throws Exception {
62 StreamSource result = (StreamSource) producerTemplate.sendBody("direct:converter-test",
63 ExchangePattern.InOut, new StreamSource(new StringReader("input")));
64 assertEquals("source: input", IOUtils.toString(result.getReader()));
65 }
66
67 }