1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.lazyload_proxyfactory_comparison;
17
18 import java.io.Reader;
19
20 import org.apache.ibatis.BaseDataTest;
21 import org.apache.ibatis.io.Resources;
22 import org.apache.ibatis.session.SqlSession;
23 import org.apache.ibatis.session.SqlSessionFactory;
24 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
25 import org.junit.jupiter.api.AfterEach;
26 import org.junit.jupiter.api.Assertions;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29
30 abstract class AbstractLazyTest {
31
32 private SqlSession sqlSession;
33 private Mapper mapper;
34
35 protected abstract String getConfiguration();
36
37 @BeforeEach
38 void before() throws Exception {
39
40 SqlSessionFactory sqlSessionFactory;
41 try (Reader reader = Resources.getResourceAsReader(
42 "org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/mybatis-config-" + getConfiguration() + ".xml")) {
43 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
44 }
45
46
47 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
48 "org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/CreateDB.sql");
49
50 sqlSession = sqlSessionFactory.openSession();
51 mapper = sqlSession.getMapper(Mapper.class);
52 }
53
54 @AfterEach
55 void after() {
56 if (sqlSession != null) {
57 sqlSession.close();
58 }
59 }
60
61 @Test
62 void lazyLoadUserWithGetObjectWithInterface() {
63 Assertions.assertNotNull(mapper.getUserWithGetObjectWithInterface(1).getOwner());
64 }
65
66 @Test
67 void lazyLoadUserWithGetObjectWithoutInterface() {
68 Assertions.assertNotNull(mapper.getUserWithGetObjectWithoutInterface(1).getOwner());
69 }
70
71 @Test
72 void lazyLoadUserWithGetXxxWithInterface() {
73 Assertions.assertNotNull(mapper.getUserWithGetXxxWithInterface(1).getOwner());
74 }
75
76 @Test
77 void lazyLoadUserWithGetXxxWithoutInterface() {
78 Assertions.assertNotNull(mapper.getUserWithGetXxxWithoutInterface(1).getOwner());
79 }
80
81 @Test
82 void lazyLoadUserWithNothingWithInterface() {
83 Assertions.assertNotNull(mapper.getUserWithNothingWithInterface(1).getOwner());
84 }
85
86 @Test
87 void lazyLoadUserWithNothingWithoutInterface() {
88 Assertions.assertNotNull(mapper.getUserWithNothingWithoutInterface(1).getOwner());
89 }
90 }