View Javadoc
1   /*
2    * Copyright 2010 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.hl7.parser;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  
22  import java.util.Map;
23  
24  import ca.uhn.hl7v2.HL7Exception;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.openehealth.ipf.modules.hl7.config.CustomModelClassFactoryConfigurer;
28  import org.springframework.beans.factory.annotation.Autowired;
29  import org.springframework.test.context.ContextConfiguration;
30  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31  
32  @RunWith(SpringJUnit4ClassRunner.class)
33  @ContextConfiguration(locations = { "/context-custom-configurer.xml",
34  		"/context-custom-classes.xml" })
35  public class GroovyCustomModelClassFactoryTest {
36  
37      @Autowired
38      private CustomModelClassFactoryConfigurer configurer;
39      
40      @Test
41      public void testMappings() throws HL7Exception {
42          Map<String, String[]> map = configurer.getCustomModelClassFactory().getCustomModelClasses();
43          assertTrue(map.containsKey("2.5"));
44          assertTrue(map.containsKey("2.4"));
45          Class<?> clazz = configurer.getCustomModelClassFactory()
46                  .getMessageClass("MDM_T01", "2.5", false);
47          assertNotNull(clazz);
48          assertEquals("org.openehealth.ipf.modules.hl7.parser.test.hl7v2.def.v25.message.MDM_T01",
49                  clazz.getCanonicalName());
50          Class<?> clazz1 = configurer.getCustomModelClassFactory()
51                  .getMessageClass("MDM_T02", "2.4", false);
52          assertNotNull(clazz1);
53          assertEquals("org.openehealth.ipf.modules.hl7.parser.groovytest.hl7v2.def.v24.message.MDM_T02",
54                  clazz1.getCanonicalName());
55      }	
56  }