View Javadoc
1   /*
2    * Copyright 2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Martin Krasser
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  }