View Javadoc
1   /*
2    * Copyright 2008 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.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   * @author Christian Ohr
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  }