1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.associationtype;
17
18 import java.io.Reader;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.ibatis.BaseDataTest;
23 import org.apache.ibatis.io.Resources;
24 import org.apache.ibatis.session.LocalCacheScope;
25 import org.apache.ibatis.session.SqlSession;
26 import org.apache.ibatis.session.SqlSessionFactory;
27 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
28 import org.junit.jupiter.api.Assertions;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.params.ParameterizedTest;
31 import org.junit.jupiter.params.provider.EnumSource;
32
33 class AssociationTypeTest {
34
35 private static SqlSessionFactory sqlSessionFactory;
36
37 @BeforeAll
38 static void setUp() throws Exception {
39
40 try (Reader reader = Resources
41 .getResourceAsReader("org/apache/ibatis/submitted/associationtype/mybatis-config.xml")) {
42 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
43 }
44
45
46 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
47 "org/apache/ibatis/submitted/associationtype/CreateDB.sql");
48 }
49
50 @ParameterizedTest
51 @EnumSource
52 void shouldGetAUser(LocalCacheScope localCacheScope) {
53 sqlSessionFactory.getConfiguration().setLocalCacheScope(localCacheScope);
54 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
55 List<Map<String, ?>> results = sqlSession.selectList("getUser");
56 for (Map<String, ?> r : results) {
57 Object a1 = r.get("a1");
58 Object a2 = r.get("a2");
59 Assertions.assertEquals(String.class, a1.getClass());
60 Assertions.assertEquals(String.class, a2.getClass());
61 Assertions.assertSame(a1, a2,
62 "The result should be put into local cache regardless of localCacheScope setting.");
63 }
64 } finally {
65
66 sqlSessionFactory.getConfiguration().setLocalCacheScope(LocalCacheScope.SESSION);
67 }
68 }
69
70 }