View Javadoc
1   /*
2    * Copyright 2018 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  
17  package org.openehealth.ipf.commons.spring.map;
18  
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.springframework.core.io.ClassPathResource;
22  import org.springframework.core.io.Resource;
23  
24  import java.util.Arrays;
25  import java.util.List;
26  
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.fail;
29  
30  /**
31   *
32   */
33  public class SpringBidiMappingServiceTest {
34  
35      SpringBidiMappingService mappingService;
36  
37      @Before
38      public void setUp() {
39          mappingService = new SpringBidiMappingService();
40      }
41  
42      /**
43       * Tests whether the "ignoreResourceNotFound" option works.
44       */
45      @Test
46      public void testIgnoreResourceNotFound() {
47          List<? extends Resource> resources = Arrays.asList(
48                  new ClassPathResource("example2.map.NONEXISTENT"),
49                  new ClassPathResource("example3.map")
50          );
51  
52          mappingService.setIgnoreResourceNotFound(true);
53          mappingService.setMappingResources(resources);
54          assertEquals("PRPA_IN401001", mappingService.get("messageType", "ADT^A04"));
55  
56          try {
57              mappingService.get("O", "encounterType");
58              fail();
59          } catch (IllegalArgumentException e) {
60              assertEquals("Unknown key O", e.getMessage());
61          }
62      }
63  
64      @Test(expected = IllegalArgumentException.class)
65      public void testFailResourceNotFound() {
66          List<? extends Resource> resources = Arrays.asList(
67                  new ClassPathResource("example2.map.NONEXISTENT"),
68                  new ClassPathResource("example3.map")
69          );
70          mappingService.setIgnoreResourceNotFound(false);
71          mappingService.setMappingResources(resources);
72      }
73  }