1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.manyanno;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.util.List;
21
22 import org.apache.ibatis.BaseDataTest;
23 import org.apache.ibatis.mapping.Environment;
24 import org.apache.ibatis.session.Configuration;
25 import org.apache.ibatis.session.SqlSession;
26 import org.apache.ibatis.session.SqlSessionFactory;
27 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
28 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
29 import org.junit.jupiter.api.Test;
30
31 class ManyAnnoTest extends BaseDataTest {
32
33 @Test
34 void testGetMessageForEmptyDatabase() throws Exception {
35 final Environment environment = new Environment("test", new JdbcTransactionFactory(),
36 BaseDataTest.createBlogDataSource());
37 final Configuration config = new Configuration(environment);
38 config.addMapper(PostMapper.class);
39 final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(config);
40 try (SqlSession session = factory.openSession()) {
41
42 PostMapper mapper = session.getMapper(PostMapper.class);
43 List<AnnoPost> posts = mapper.getPosts(101);
44
45 assertEquals(3, posts.size());
46 assertEquals(3, posts.get(0).getTags().size());
47 assertEquals(1, posts.get(1).getTags().size());
48 assertEquals(0, posts.get(2).getTags().size());
49 }
50 }
51
52 }