1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.criterion;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.io.Reader;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.ibatis.BaseDataTest;
25 import org.apache.ibatis.io.Resources;
26 import org.apache.ibatis.session.SqlSession;
27 import org.apache.ibatis.session.SqlSessionFactory;
28 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.api.Test;
31
32 class CriterionTest {
33
34 protected static SqlSessionFactory sqlSessionFactory;
35
36 @BeforeAll
37 static void setUp() throws Exception {
38 try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/criterion/MapperConfig.xml")) {
39 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
40 }
41
42 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
43 "org/apache/ibatis/submitted/criterion/CreateDB.sql");
44 }
45
46 @Test
47 void testSimpleSelect() {
48 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
49 Criterion criterion = new Criterion();
50 criterion.setTest("firstName =");
51 criterion.setValue("Fred");
52 Parameter parameter = new Parameter();
53 parameter.setCriterion(criterion);
54
55 List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.criterion.simpleSelect",
56 parameter);
57
58 assertEquals(1, answer.size());
59 }
60 }
61 }