1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.sql;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.util.List;
21 import java.util.Properties;
22
23 import org.apache.ibatis.BaseDataTest;
24 import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
25 import org.apache.ibatis.mapping.Environment;
26 import org.apache.ibatis.session.Configuration;
27 import org.apache.ibatis.session.SqlSession;
28 import org.apache.ibatis.session.SqlSessionFactory;
29 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
30 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
31 import org.junit.jupiter.api.BeforeAll;
32 import org.junit.jupiter.api.Test;
33
34 class HsqldbSQLTest {
35
36 private static SqlSessionFactory sqlSessionFactory;
37
38 @BeforeAll
39 static void setUp() throws Exception {
40 Configuration configuration = new Configuration();
41 Environment environment = new Environment("development", new JdbcTransactionFactory(),
42 new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:HsqldbSQLTest", "sa", ""));
43 configuration.setEnvironment(environment);
44 configuration.setUseGeneratedKeys(true);
45 configuration.addMapper(Mapper.class);
46 Properties properties = new Properties();
47 properties.setProperty("schema", "");
48 configuration.setVariables(properties);
49 sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
50
51 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
52 "org/apache/ibatis/submitted/sql/CreateDB-hsqldb.sql");
53 }
54
55 @Test
56 void testFetchFirst() {
57 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
58 Mapper mapper = sqlSession.getMapper(Mapper.class);
59 {
60 List<User> users = mapper.findAll(0, 2);
61 assertEquals(2, users.size());
62 assertEquals("Jimmy", users.get(0).getName());
63 assertEquals("Iwao", users.get(1).getName());
64 }
65 {
66 List<User> users = mapper.findAll(1, 2);
67 assertEquals(2, users.size());
68 assertEquals("Iwao", users.get(0).getName());
69 assertEquals("Kazuki", users.get(1).getName());
70 }
71 {
72 List<User> users = mapper.findAll(2, 2);
73 assertEquals(1, users.size());
74 assertEquals("Kazuki", users.get(0).getName());
75 }
76 }
77 }
78
79 }