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.modules.cda.support;
17  
18  
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.openehealth.ipf.commons.xml.SchematronProfile;
22  import org.openehealth.ipf.commons.xml.SchematronValidator;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
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  import static org.openehealth.ipf.modules.cda.CDAR2Constants.CCDA_SCHEMATRON_RULES;
32  
33  /**
34   * @author Boris Stanojevic
35   */
36  public class CCDASchematronValidationTest {
37  
38      protected static final transient Logger LOG = LoggerFactory.getLogger(CCDASchematronValidationTest.class);
39  
40      private SchematronValidator schematron;
41      private Map<String, Object> params;
42  
43      private static final String[] ccdaFiles = new String[]{"CCD 1", "Consult 1", "DIR.sample", "Discharge Summary 1",
44                                                             "HandP 1", "Op Note 1", "Proc Note 1", "Progress Note 1",
45                                                             "UD 1", "UD 2"};
46  
47      @Before
48      public void setUp() throws Exception {
49          params = new HashMap<>();
50          params.put("phase", "errors");
51          schematron = new SchematronValidator();
52      }
53  
54      @Test
55      public void validateSchemaGoodSamples() throws Exception {
56          for (String ccdaFile: ccdaFiles){
57              String ccdaFilePathFormat = "/ccda/%s.xml";
58              String ccdaFilePath = String.format(ccdaFilePathFormat, ccdaFile);
59              Source testXml = new StreamSource(getClass().getResourceAsStream(ccdaFilePath));
60              LOG.info("Testing {} ...", ccdaFile);
61              schematron.validate(testXml, new SchematronProfile(CCDA_SCHEMATRON_RULES, params));
62              LOG.info("{} - OK", ccdaFile);
63          }
64      }
65  
66  }