1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.association_nested;
17
18 import java.io.InputStream;
19 import java.sql.Connection;
20 import java.sql.DriverManager;
21 import java.sql.Statement;
22 import java.util.List;
23
24 import org.apache.ibatis.io.Resources;
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.Test;
30
31
32
33
34 class FolderMapperTest {
35
36 @Test
37 void testFindWithChildren() throws Exception {
38 try (Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:association_nested", "SA", "");
39 Statement stmt = conn.createStatement()) {
40 stmt.execute("create table folder (id int, name varchar(100), parent_id int)");
41 stmt.execute("insert into folder (id, name) values(1, 'Root')");
42 stmt.execute("insert into folder values(2, 'Folder 1', 1)");
43 stmt.execute("insert into folder values(3, 'Folder 2', 1)");
44 stmt.execute("insert into folder values(4, 'Folder 2_1', 3)");
45 stmt.execute("insert into folder values(5, 'Folder 2_2', 3)");
46 }
47
48
49
50
51
52
53
54
55
56
57 String resource = "org/apache/ibatis/submitted/association_nested/mybatis-config.xml";
58 try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
59 SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
60 try (SqlSession session = sqlSessionFactory.openSession()) {
61 FolderMapper postMapper = session.getMapper(FolderMapper.class);
62
63 List<FolderFlatTree> folders = postMapper.findWithSubFolders("Root");
64
65 Assertions.assertEquals(3, folders.size());
66 }
67 }
68 }
69
70 }