View Javadoc
1   /*
2    * Copyright 2013 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;
17  
18  import java.io.InputStream;
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.junit.Ignore;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.eclipse.emf.common.util.URI;
26  import org.eclipse.emf.ecore.resource.URIConverter;
27  import org.junit.After;
28  import org.junit.Before;
29  import org.junit.Test;
30  import org.openehealth.ipf.commons.core.modules.api.ValidationException;
31  import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
32  import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
33  
34  public class CDAR2ValidatorTest {
35      private static final Logger LOG = LoggerFactory.getLogger(CDAR2ValidatorTest.class.getName());
36  
37      private CDAR2Validator validator;
38  
39      // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=364797
40      static {
41          URIConverter.URI_MAP.put(
42              URI.createURI("http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore"),
43              URI.createPlatformPluginURI("/org.eclipse.ocl.ecore/model/oclstdlib.ecore", true));
44      }
45  
46      @Before
47      public void setUp() throws Exception {
48          validator = new CDAR2Validator();
49          Map<Object, Object> context = new HashMap<>();
50          context.put(CDAUtil.ValidationHandler.class, new DefaultValidationHandler());
51          CDAR2Utils.initCCD();
52          CDAR2Utils.initHITSPC32();
53  
54      }
55      
56      @After
57      public void tearDown() throws Exception {
58      }
59      
60      @Test
61      public final void validateCDA() throws Exception {
62          LOG.info("Validating plain CDA document");
63          InputStream is = getClass().getResourceAsStream(
64              "/builders/content/document/SampleCDADocument.xml");
65          ClinicalDocument cda = CDAUtil.load(is);
66          validator.validate(cda, null);
67      }
68      
69      @Test(expected=ValidationException.class)
70      public final void validateCDAError() throws Exception {
71          LOG.info("Validating erroneous plain CDA document");
72          InputStream is = getClass().getResourceAsStream(
73              "/builders/content/document/InvalidCDADocument.xml");
74          ClinicalDocument cda = CDAUtil.load(is);
75          validator.validate(cda, null);
76          // TODO check expected validation errors
77      }
78      
79      @Test
80      public final void validateCCD() throws Exception {
81          LOG.info("Validating CCD document");
82          InputStream is = getClass().getResourceAsStream(
83              "/builders/content/document/SampleCCDDocument.xml");
84          ClinicalDocument ccd = CDAUtil.load(is);
85          validator.validate(ccd, null);
86      }
87      
88      @Test(expected = ValidationException.class)
89      public final void validateCCDError() throws Exception {
90          LOG.info("Validating erroneous CCD document");
91          InputStream is = getClass().getResourceAsStream(
92              "/builders/content/document/InvalidCCDDocument.xml");
93          ClinicalDocument ccd = CDAUtil.load(is);
94          validator.validate(ccd, null);
95          // TODO check expected validation errors
96      }
97  
98      @Ignore
99      public final void validateCDAwithHITSPProfile() throws Exception {
100         LOG.info("Validating HITSPC32 document");
101         InputStream is = getClass().getResourceAsStream(
102                 "/builders/content/document/SampleHITSPC32v25Document.xml");
103         ClinicalDocument hitsp = CDAUtil.load(is);
104         validator.validate(hitsp, null);
105     }
106 }