1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.orphan_result_maps;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21
22 import org.apache.ibatis.session.Configuration;
23 import org.junit.jupiter.api.Test;
24
25 class OrphanResultMapTest {
26
27 private static final String RESULT_MAP_BLOG = "BlogResultMap";
28 private static final String RESULT_MAP_POST = "PostResultMap";
29 private static final String RESULT_MAP_INNER = "mapper_resultMap[BlogResultMap]_collection[posts]";
30
31 @Test
32 void testSeparateResultMaps() {
33
34 Configuration configuration = new Configuration();
35 configuration.getTypeAliasRegistry().registerAlias(Blog.class);
36 configuration.getTypeAliasRegistry().registerAlias(Post.class);
37 configuration.addMapper(SeparateCollectionMapper.class);
38
39
40 assertEquals(4, configuration.getResultMaps().size());
41
42
43 assertNotNull(configuration.getResultMap(RESULT_MAP_BLOG));
44 assertNotNull(configuration.getResultMap(RESULT_MAP_POST));
45 assertThrows(IllegalArgumentException.class, () -> configuration.getResultMap(RESULT_MAP_INNER));
46
47
48 String prefix = SeparateCollectionMapper.class.getName() + ".";
49 assertNotNull(configuration.getResultMap(prefix + RESULT_MAP_BLOG));
50 assertNotNull(configuration.getResultMap(prefix + RESULT_MAP_POST));
51 assertThrows(IllegalArgumentException.class, () -> configuration.getResultMap(prefix + RESULT_MAP_INNER));
52 }
53
54 @Test
55 void testNestedResultMap() {
56
57 Configuration configuration = new Configuration();
58 configuration.getTypeAliasRegistry().registerAlias(Blog.class);
59 configuration.getTypeAliasRegistry().registerAlias(Post.class);
60 configuration.addMapper(NestedCollectionMapper.class);
61
62
63 assertEquals(4, configuration.getResultMaps().size());
64
65
66 assertNotNull(configuration.getResultMap(RESULT_MAP_BLOG));
67 assertNotNull(configuration.getResultMap(RESULT_MAP_INNER));
68
69
70 String prefix = NestedCollectionMapper.class.getName() + ".";
71 assertNotNull(configuration.getResultMap(prefix + RESULT_MAP_BLOG));
72 assertNotNull(configuration.getResultMap(prefix + RESULT_MAP_INNER));
73 }
74
75 }