1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.cda.extend;
17
18 import java.io.InputStream;
19
20 import org.apache.camel.EndpointInject;
21 import org.apache.camel.component.mock.MockEndpoint;
22 import org.junit.Test;
23 import org.springframework.test.context.ContextConfiguration;
24
25
26
27
28 @ContextConfiguration(locations = { "/config/context-extend.xml" })
29 public class CDAModelExtensionTest extends AbstractExtensionTest {
30
31 private String cdaExample = "/message/SampleCDADocument.xml";
32 private String ccdExample = "/message/SampleCCDDocument.xml";
33
34 @EndpointInject(uri="mock:error")
35 protected MockEndpoint mockError;
36
37 @Test
38 public void testXsdValidateSuccess() throws Exception {
39 testValidateCDA("direct:input3", cdaExample);
40 testValidateCDA("direct:input3", ccdExample);
41 }
42
43 @Test
44 public void testSchematronValidateSuccess() throws Exception {
45 testValidateCDA("direct:input4", ccdExample);
46 }
47
48
49 private void testValidateCDA(String endpoint, String file) throws Exception {
50 mockOutput.reset();
51 mockError.reset();
52 InputStream stream = inputStream(file);
53 mockOutput.expectedMessageCount(1);
54 mockError.expectedMessageCount(0);
55 producerTemplate.sendBody(endpoint, stream);
56 mockOutput.assertIsSatisfied();
57 mockError.assertIsSatisfied();
58 }
59
60 private static InputStream inputStream(String resource) {
61 return CDAModelExtensionTest.class.getResourceAsStream(resource);
62 }
63
64 }