View Javadoc
1   /*
2    * Copyright 2009 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.hl7.transport;
17  
18  import java.nio.charset.Charset;
19  import java.util.Scanner;
20  
21  import org.apache.camel.EndpointInject;
22  import org.apache.camel.ProducerTemplate;
23  import org.apache.camel.component.mock.MockEndpoint;
24  import org.apache.commons.io.IOUtils;
25  import org.junit.After;
26  import org.junit.Test;
27  import org.junit.runner.RunWith;
28  import org.springframework.beans.factory.annotation.Autowired;
29  import org.springframework.test.context.ContextConfiguration;
30  import org.springframework.test.context.TestExecutionListeners;
31  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
32  import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
33  
34  /**
35   * @author Martin Krasser
36   */
37  @RunWith(SpringJUnit4ClassRunner.class)
38  @TestExecutionListeners({DependencyInjectionTestExecutionListener.class})
39  @ContextConfiguration(locations = { "/config/context-transport.xml" })
40  public class TransportTest {
41  
42      @Autowired
43      protected ProducerTemplate producerTemplate;
44      
45      @EndpointInject(uri="mock:output")
46      protected MockEndpoint mockOutput;
47      
48      @After
49      public void tearDown() throws Exception {
50          mockOutput.reset();
51      }
52  
53      @Test
54      public void testMessage02() throws Exception {
55          String message = inputMessage("message/msg-02.hl7");
56          String content = IOUtils.toString(getClass().getResourceAsStream("/message/msg-02.content"), Charset.defaultCharset());
57          mockOutput.expectedBodiesReceived(content);
58          producerTemplate.sendBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7Codec", message);
59          mockOutput.assertIsSatisfied();
60      }
61  
62      private static String inputMessage(String resource) {
63          return new Scanner(TransportTest.class.getResourceAsStream("/" + resource)).useDelimiter("\\A").next();
64      }
65      
66  }