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.mapping.Environment;
25 import org.apache.ibatis.session.Configuration;
26 import org.apache.ibatis.session.SqlSession;
27 import org.apache.ibatis.session.SqlSessionFactory;
28 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
29 import org.apache.ibatis.testcontainers.PgContainer;
30 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
31 import org.junit.jupiter.api.BeforeAll;
32 import org.junit.jupiter.api.Tag;
33 import org.junit.jupiter.api.Test;
34
35 @Tag("TestcontainersTests")
36 class PostgresSQLTest {
37
38 private static SqlSessionFactory sqlSessionFactory;
39
40 @BeforeAll
41 static void setUp() throws Exception {
42 Configuration configuration = new Configuration();
43 Environment environment = new Environment("development", new JdbcTransactionFactory(),
44 PgContainer.getUnpooledDataSource());
45 configuration.setEnvironment(environment);
46 configuration.setUseGeneratedKeys(true);
47 configuration.addMapper(Mapper.class);
48 Properties properties = new Properties();
49 properties.setProperty("schema", "mbtest.");
50 configuration.setVariables(properties);
51 sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
52
53 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
54 "org/apache/ibatis/submitted/sql/CreateDB.sql");
55 }
56
57 @Test
58 void testFetchFirst() {
59 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
60 Mapper mapper = sqlSession.getMapper(Mapper.class);
61 {
62 List<User> users = mapper.findAll(0, 2);
63 assertEquals(2, users.size());
64 assertEquals("Jimmy", users.get(0).getName());
65 assertEquals("Iwao", users.get(1).getName());
66 }
67 {
68 List<User> users = mapper.findAll(1, 2);
69 assertEquals(2, users.size());
70 assertEquals("Iwao", users.get(0).getName());
71 assertEquals("Kazuki", users.get(1).getName());
72 }
73 {
74 List<User> users = mapper.findAll(2, 2);
75 assertEquals(1, users.size());
76 assertEquals("Kazuki", users.get(0).getName());
77 }
78 }
79 }
80
81 }