1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.duplicate_statements;
17
18 import java.io.Reader;
19 import java.util.List;
20
21 import org.apache.ibatis.BaseDataTest;
22 import org.apache.ibatis.io.Resources;
23 import org.apache.ibatis.session.RowBounds;
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.Assertions;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Disabled;
30 import org.junit.jupiter.api.Test;
31
32 class DuplicateStatementsTest {
33
34 private SqlSessionFactory sqlSessionFactory;
35
36 @BeforeEach
37 void setupDb() throws Exception {
38
39 try (Reader reader = Resources
40 .getResourceAsReader("org/apache/ibatis/submitted/duplicate_statements/mybatis-config.xml")) {
41 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
42 }
43
44
45 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
46 "org/apache/ibatis/submitted/duplicate_statements/CreateDB.sql");
47 }
48
49 @Test
50 void shouldGetAllUsers() {
51 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
52 Mapper mapper = sqlSession.getMapper(Mapper.class);
53 List<User> users = mapper.getAllUsers();
54 Assertions.assertEquals(10, users.size());
55 }
56 }
57
58 @Test
59 void shouldGetFirstFourUsers() {
60 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
61 Mapper mapper = sqlSession.getMapper(Mapper.class);
62 List<User> users = mapper.getAllUsers(new RowBounds(0, 4));
63 Assertions.assertEquals(4, users.size());
64 }
65 }
66
67 @Test
68 @Disabled("fails currently - issue 507")
69 void shouldGetAllUsers_Annotated() {
70 sqlSessionFactory.getConfiguration().addMapper(AnnotatedMapper.class);
71 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
72 AnnotatedMapper mapper = sqlSession.getMapper(AnnotatedMapper.class);
73 List<User> users = mapper.getAllUsers();
74 Assertions.assertEquals(10, users.size());
75 }
76 }
77
78 @Test
79 @Disabled("fails currently - issue 507")
80 void shouldGetFirstFourUsers_Annotated() {
81 sqlSessionFactory.getConfiguration().addMapper(AnnotatedMapper.class);
82 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
83 AnnotatedMapper mapper = sqlSession.getMapper(AnnotatedMapper.class);
84 List<User> users = mapper.getAllUsers(new RowBounds(0, 4));
85 Assertions.assertEquals(4, users.size());
86 }
87 }
88
89 @Test
90 void shouldFailForDuplicateMethod() {
91 Assertions.assertThrows(IllegalArgumentException.class,
92 () -> sqlSessionFactory.getConfiguration().addMapper(AnnotatedMapperExtended.class));
93 }
94 }