1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }