1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.not_null_column;
17
18 import static org.junit.jupiter.api.Assertions.*;
19
20 import java.io.Reader;
21
22 import org.apache.ibatis.BaseDataTest;
23 import org.apache.ibatis.io.Resources;
24 import org.apache.ibatis.session.SqlSession;
25 import org.apache.ibatis.session.SqlSessionFactory;
26 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27 import org.junit.jupiter.api.BeforeAll;
28 import org.junit.jupiter.api.Test;
29
30 class NotNullColumnTest {
31
32 private static SqlSessionFactory sqlSessionFactory;
33
34 @BeforeAll
35 static void initDatabase() throws Exception {
36 try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/not_null_column/ibatisConfig.xml")) {
37 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
38 }
39
40 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
41 "org/apache/ibatis/submitted/not_null_column/CreateDB.sql");
42 }
43
44 @Test
45 void testNotNullColumnWithChildrenNoFid() {
46 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
47 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
48
49 Father test = fatherMapper.selectByIdNoFid(1);
50 assertNotNull(test);
51 assertNotNull(test.getChildren());
52 assertEquals(2, test.getChildren().size());
53 }
54 }
55
56 @Test
57 void testNotNullColumnWithoutChildrenNoFid() {
58 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
59 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
60
61 Father test = fatherMapper.selectByIdNoFid(2);
62 assertNotNull(test);
63 assertNotNull(test.getChildren());
64 assertTrue(test.getChildren().isEmpty());
65 }
66 }
67
68 @Test
69 void testNotNullColumnWithoutChildrenFid() {
70 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
71 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
72
73 Father test = fatherMapper.selectByIdFid(2);
74 assertNotNull(test);
75 assertNotNull(test.getChildren());
76 assertTrue(test.getChildren().isEmpty());
77 }
78 }
79
80 @Test
81 void testNotNullColumnWithoutChildrenWithInternalResultMap() {
82 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
83 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
84
85 Father test = fatherMapper.selectByIdWithInternalResultMap(2);
86 assertNotNull(test);
87 assertNotNull(test.getChildren());
88 assertTrue(test.getChildren().isEmpty());
89 }
90 }
91
92 @Test
93 void testNotNullColumnWithoutChildrenWithRefResultMap() {
94 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
95 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
96
97 Father test = fatherMapper.selectByIdWithRefResultMap(2);
98 assertNotNull(test);
99 assertNotNull(test.getChildren());
100 assertTrue(test.getChildren().isEmpty());
101 }
102 }
103
104 @Test
105 void testNotNullColumnWithoutChildrenFidMultipleNullColumns() {
106 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
107 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
108
109 Father test = fatherMapper.selectByIdFidMultipleNullColumns(2);
110 assertNotNull(test);
111 assertNotNull(test.getChildren());
112 assertTrue(test.getChildren().isEmpty());
113 }
114 }
115
116 @Test
117 void testNotNullColumnWithoutChildrenFidMultipleNullColumnsAndBrackets() {
118 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
119 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
120
121 Father test = fatherMapper.selectByIdFidMultipleNullColumnsAndBrackets(2);
122 assertNotNull(test);
123 assertNotNull(test.getChildren());
124 assertTrue(test.getChildren().isEmpty());
125 }
126 }
127
128 @Test
129 void testNotNullColumnWithoutChildrenFidWorkaround() {
130 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
131 FatherMapper fatherMapper = sqlSession.getMapper(FatherMapper.class);
132
133 Father test = fatherMapper.selectByIdFidWorkaround(2);
134 assertNotNull(test);
135 assertNotNull(test.getChildren());
136 assertTrue(test.getChildren().isEmpty());
137 }
138 }
139 }