1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.dml_return_types;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertTrue;
20
21 import java.io.Reader;
22
23 import org.apache.ibatis.BaseDataTest;
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.AfterEach;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32
33 class DmlMapperReturnTypesTest {
34
35 private static final String SQL = "org/apache/ibatis/submitted/dml_return_types/CreateDB.sql";
36 private static final String XML = "org/apache/ibatis/submitted/dml_return_types/mybatis-config.xml";
37
38 private static SqlSessionFactory sqlSessionFactory;
39
40 private SqlSession sqlSession;
41 private Mapper mapper;
42
43 @BeforeAll
44 static void setUp() throws Exception {
45
46 try (Reader reader = Resources.getResourceAsReader(XML)) {
47 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
48 }
49
50
51 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), SQL);
52
53 }
54
55 @BeforeEach
56 void openSession() {
57 sqlSession = sqlSessionFactory.openSession();
58 mapper = sqlSession.getMapper(Mapper.class);
59 }
60
61 @AfterEach
62 void closeSession() {
63 sqlSession.close();
64 }
65
66 @Test
67 void updateShouldReturnVoid() {
68 mapper.updateReturnsVoid(new User(1, "updateShouldReturnVoid"));
69 }
70
71 @Test
72 void shouldReturnPrimitiveInteger() {
73 final int rows = mapper.updateReturnsPrimitiveInteger(new User(1, "shouldReturnPrimitiveInteger"));
74 assertEquals(1, rows);
75 }
76
77 @Test
78 void shouldReturnInteger() {
79 final Integer rows = mapper.updateReturnsInteger(new User(1, "shouldReturnInteger"));
80 assertEquals(Integer.valueOf(1), rows);
81 }
82
83 @Test
84 void shouldReturnPrimitiveLong() {
85 final long rows = mapper.updateReturnsPrimitiveLong(new User(1, "shouldReturnPrimitiveLong"));
86 assertEquals(1L, rows);
87 }
88
89 @Test
90 void shouldReturnLong() {
91 final Long rows = mapper.updateReturnsLong(new User(1, "shouldReturnLong"));
92 assertEquals(Long.valueOf(1), rows);
93 }
94
95 @Test
96 void shouldReturnPrimitiveBoolean() {
97 final boolean rows = mapper.updateReturnsPrimitiveBoolean(new User(1, "shouldReturnPrimitiveBoolean"));
98 assertTrue(rows);
99 }
100
101 @Test
102 void shouldReturnBoolean() {
103 final Boolean rows = mapper.updateReturnsBoolean(new User(1, "shouldReturnBoolean"));
104 assertTrue(rows);
105 }
106
107 }