1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.substitution_in_annots;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import org.apache.ibatis.BaseDataTest;
21 import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
22 import org.apache.ibatis.mapping.Environment;
23 import org.apache.ibatis.session.Configuration;
24 import org.apache.ibatis.session.SqlSession;
25 import org.apache.ibatis.session.SqlSessionFactory;
26 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.Test;
30
31 class SubstitutionInAnnotsTest {
32
33 protected static SqlSessionFactory sqlSessionFactory;
34
35 @BeforeAll
36 static void setUp() throws Exception {
37 Configuration configuration = new Configuration();
38 Environment environment = new Environment("test", new JdbcTransactionFactory(),
39 new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null));
40 configuration.setEnvironment(environment);
41 configuration.addMapper(SubstitutionInAnnotsMapper.class);
42 sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
43
44 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
45 "org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql");
46 }
47
48 @Test
49 void testSubstitutionWithXml() {
50 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
51 SubstitutionInAnnotsMapper mapper = sqlSession.getMapper(SubstitutionInAnnotsMapper.class);
52 assertEquals("Barney", mapper.getPersonNameByIdWithXml(4));
53 }
54 }
55
56 @Test
57 void testSubstitutionWithAnnotsValue() {
58 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
59 SubstitutionInAnnotsMapper mapper = sqlSession.getMapper(SubstitutionInAnnotsMapper.class);
60 assertEquals("Barney", mapper.getPersonNameByIdWithAnnotsValue(4));
61 }
62 }
63
64 @Test
65 void testSubstitutionWithAnnotsParameter() {
66 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
67 SubstitutionInAnnotsMapper mapper = sqlSession.getMapper(SubstitutionInAnnotsMapper.class);
68 assertEquals("Barney", mapper.getPersonNameByIdWithAnnotsParameter(4));
69 }
70 }
71
72 @Test
73 void testSubstitutionWithAnnotsParamAnnot() {
74 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
75 SubstitutionInAnnotsMapper mapper = sqlSession.getMapper(SubstitutionInAnnotsMapper.class);
76 assertEquals("Barney", mapper.getPersonNameByIdWithAnnotsParamAnnot(4));
77 }
78 }
79
80 }