View Javadoc
1   /*
2    * Copyright 2014 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;
17  
18  import java.util.Scanner;
19  
20  import org.apache.camel.EndpointInject;
21  import org.apache.camel.Message;
22  import org.apache.camel.component.mock.MockEndpoint;
23  import org.junit.After;
24  import org.junit.Test;
25  import org.openehealth.ipf.platform.camel.hl7.extend.AbstractExtensionTest;
26  import org.springframework.test.context.ContextConfiguration;
27  
28  import static org.junit.Assert.assertTrue;
29  
30  /**
31   *
32   */
33  @ContextConfiguration(locations = { "/config/context-sample2.xml" })
34  public class SampleRouteBuilder2Test extends AbstractExtensionTest {
35  
36      private static String MSH_EXPECTED_1 = "MSH|^~\\&|SAP-ISH|HZL|blah||20040805152637||ADT^A01|123456|T|2.2|||ER";
37      private static String MSH_EXPECTED_2 = "MSH|^~\\&|SAP-ISH|HZL|blub||20040805152637||ADT^A01|123456|T|2.2|||ER";
38      
39      @EndpointInject(uri="mock:output1")
40      private MockEndpoint mockOutput1;
41      
42      @EndpointInject(uri="mock:output2")
43      private MockEndpoint mockOutput2;
44      
45      private String resource = "message/msg-01.hl7";
46      
47      @After
48      public void myTearDown() throws Exception {
49          mockOutput1.reset();
50          mockOutput2.reset();
51      }
52  
53      @Test
54      public void testRoute1() throws Exception {
55          String message = inputMessage(resource);
56          mockOutput1.expectedMessageCount(1);
57          producerTemplate.sendBodyAndHeader("direct:input1", message, "foo", "blah");
58          mockOutput1.assertIsSatisfied();
59          assertTrue(resultString(mockOutput1).contains(MSH_EXPECTED_1));
60      }
61  
62      @Test
63      public void testRoute2() throws Exception {
64          String message = inputMessage(resource);
65          mockOutput2.expectedMessageCount(1);
66          producerTemplate.sendBodyAndHeader("direct:input1", message, "foo", "blub");
67          mockOutput2.assertIsSatisfied();
68          assertTrue(resultString(mockOutput2).contains(MSH_EXPECTED_2));
69      }
70  
71      private static String resultString(MockEndpoint mock) {
72          return resultMessage(mock).getBody(String.class);
73      }
74  
75      private static Message resultMessage(MockEndpoint mock) {
76          return mock.getExchanges().get(0).getIn();
77      }
78  
79      private static String inputMessage(String resource) {
80          return new Scanner(SampleRouteBuilder2Test.class.getResourceAsStream("/" + resource)).useDelimiter("\\A").next();
81      }
82      
83  }