View Javadoc
1   /*
2    *    Copyright 2009-2024 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.session.defaults;
17  
18  import java.io.Reader;
19  
20  import org.apache.ibatis.BaseDataTest;
21  import org.apache.ibatis.io.Resources;
22  import org.apache.ibatis.session.SqlSession;
23  import org.apache.ibatis.session.SqlSessionFactory;
24  import org.assertj.core.api.Assertions;
25  import org.junit.Test;
26  
27  public class ExtendedSqlSessionFactoryTest extends BaseDataTest {
28  
29    @Test
30    public void testCanUseExtendedSqlSessionUsingDefaults() throws Exception {
31      createBlogDataSource();
32  
33      final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
34      final Reader reader = Resources.getResourceAsReader(resource);
35  
36      SqlSessionFactory sessionFactory = new ExtendedSqlSessionFactoryBuilder().build(reader);
37      Assertions.assertThat(sessionFactory).isNotNull();
38  
39      try (SqlSession sqlSession = sessionFactory.openSession()) {
40        Assertions.assertThat(sqlSession).isNotNull().isInstanceOf(ExtendedSqlSession.class);
41      }
42    }
43  }