1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.tutorials.hl7.route;
17
18 import ca.uhn.hl7v2.HL7Exception;
19 import ca.uhn.hl7v2.model.Message;
20 import ca.uhn.hl7v2.parser.PipeParser;
21 import org.apache.camel.ProducerTemplate;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.core.io.FileSystemResource;
26 import org.springframework.core.io.Resource;
27 import org.springframework.test.context.ContextConfiguration;
28 import org.springframework.test.context.TestExecutionListeners;
29 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30 import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
31
32 import java.io.InputStream;
33 import java.util.Scanner;
34
35 import static org.junit.Assert.assertEquals;
36
37
38
39
40 @RunWith(SpringJUnit4ClassRunner.class)
41 @TestExecutionListeners({DependencyInjectionTestExecutionListener.class})
42 @ContextConfiguration(locations = { "/context.xml" })
43 public class SampleRouteTest {
44
45 @Autowired
46 private ProducerTemplate producerTemplate;
47
48 @Test
49 public void testRoute() throws Exception {
50 producerTemplate.sendBody("direct:input", getClass().getResourceAsStream("/msg-01.hl7"));
51 Resource result = new FileSystemResource("target/output/HZL.hl7");
52 assertEquals(
53 load(getClass().getResourceAsStream("/msg-01.hl7.expected")).toString(),
54 load(result.getInputStream()).toString());
55 }
56
57 protected static <T extends Message> T load(InputStream is) throws HL7Exception {
58 return (T)new PipeParser().parse(
59 new Scanner(is).useDelimiter("\\A").next());
60 }
61 }