1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.modules.cda.support;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.openehealth.ipf.commons.core.modules.api.ValidationException;
21 import org.openehealth.ipf.commons.xml.SchematronProfile;
22 import org.openehealth.ipf.commons.xml.SchematronValidator;
23 import org.openehealth.ipf.commons.xml.XsdValidator;
24 import org.openehealth.ipf.modules.cda.CDAR2Constants;
25
26 import javax.xml.transform.Source;
27 import javax.xml.transform.stream.StreamSource;
28 import java.util.HashMap;
29 import java.util.Map;
30
31
32
33
34
35
36
37 public class LabCDAValidationTest {
38
39 private XsdValidator validator;
40 private SchematronValidator schematron;
41 private Map<String, Object> params;
42
43 private String sample = "/IHE_LabReport_20080103.xml";
44 private String sample_extended = "/IHE_LabReport_21_Extended.xml";
45 private String sample2 = "/IHE_LabReport_20080103_Errored.xml";
46
47 @Before
48 public void setUp() throws Exception {
49 validator = new XsdValidator();
50 schematron = new SchematronValidator();
51 params = new HashMap<>();
52 params.put("phase", "errors");
53 }
54
55 @Test
56 public void testSchemaValidate() throws Exception {
57 Source testXml = new StreamSource(getClass().getResourceAsStream(sample));
58 validator.validate(testXml, CDAR2Constants.IHE_LAB_SCHEMA);
59 }
60
61 @Test
62 public void testSchemaValidateExtended() throws Exception {
63 Source testXml = new StreamSource(getClass().getResourceAsStream(sample_extended));
64 validator.validate(testXml, CDAR2Constants.IHE_LAB_SCHEMA);
65 }
66
67 @Test
68 public void testValidateErrors() throws Exception {
69 Source testXml = new StreamSource(getClass().getResourceAsStream(sample));
70 schematron.validate(testXml, new SchematronProfile(CDAR2Constants.IHE_LAB_SCHEMATRON_RULES,
71 params));
72 }
73
74 @Test
75 public void testValidateErrorsExtended() throws Exception {
76 Source testXml = new StreamSource(getClass().getResourceAsStream(sample_extended));
77 schematron.validate(testXml, new SchematronProfile(CDAR2Constants.IHE_LAB_SCHEMATRON_RULES,
78 params));
79 }
80
81 @Test(expected = ValidationException.class)
82 public void testValidateOnlyErrors() throws Exception {
83 Source testXml = new StreamSource(getClass().getResourceAsStream(sample2));
84 schematron.validate(testXml, new SchematronProfile(CDAR2Constants.IHE_LAB_SCHEMATRON_RULES,
85 params));
86 }
87
88 @Test(expected = ValidationException.class)
89 public void testValidateWarnings() throws Exception {
90 Source testXml = new StreamSource(getClass().getResourceAsStream(sample));
91 schematron
92 .validate(testXml, new SchematronProfile(CDAR2Constants.IHE_LAB_SCHEMATRON_RULES));
93 }
94
95
96 }