View Javadoc
1   /*
2    * Copyright 2012 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.modules.cda.support;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.xml.SchematronProfile;
21  import org.openehealth.ipf.commons.xml.SchematronValidator;
22  import org.openehealth.ipf.commons.xml.XsdValidator;
23  
24  import javax.xml.transform.Source;
25  import javax.xml.transform.stream.StreamSource;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import static org.openehealth.ipf.modules.cda.CDAR2Constants.*;
30  
31  /**
32   * Validates the HITSP C37 schematron rule set.
33   * 
34   * @author Stefan Ivanov
35   * 
36   */
37  public class HITSPC32ValidationTest {
38  
39  	private XsdValidator validator;
40  	private SchematronValidator schematron;
41  	private Map<String, Object> params;
42  
43  	private static final String sample_c32 = "/MU_Rev3_HITSP_C32C83_4Sections_RobustEntries_NoErrors.xml";
44  
45  	@Before
46  	public void setUp() throws Exception {
47  		validator = new XsdValidator();
48  		params = new HashMap<>();
49  		params.put("phase", "errors");
50          schematron = new SchematronValidator();
51  	}
52  
53      @Test
54      public void validateSchemaGoodSample24() throws Exception {
55          Source testXml = new StreamSource(getClass().getResourceAsStream(sample_c32));
56          validator.validate(testXml, HITSP_32_2_4_SCHEMA);
57      }
58  
59      @Test
60      public void validateSchemaGoodSample25() throws Exception {
61          Source testXml = new StreamSource(getClass().getResourceAsStream(sample_c32));
62          validator.validate(testXml, HITSP_32_2_5_SCHEMA);
63      }
64  
65  	@Test
66  	public void validateComplete24() throws Exception {
67          Source testXml = new StreamSource(getClass().getResourceAsStream(sample_c32));
68  		schematron.validate(testXml, new SchematronProfile(
69  				HITSP_32_2_4_SCHEMATRON_RULES, params));
70  	}
71  
72      @Test
73      public void validateComplete25() throws Exception {
74          Source testXml = new StreamSource(getClass().getResourceAsStream(sample_c32));
75          schematron.validate(testXml, new SchematronProfile(
76                  HITSP_32_2_5_SCHEMATRON_RULES, params));
77      }
78  }