View Javadoc
1   /*
2    *    Copyright 2009-2022 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
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  }