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.autodiscover;
17  
18  import static org.junit.jupiter.api.Assertions.assertNotNull;
19  import static org.junit.jupiter.api.Assertions.assertTrue;
20  
21  import java.io.Reader;
22  import java.math.BigInteger;
23  
24  import org.apache.ibatis.io.Resources;
25  import org.apache.ibatis.session.SqlSessionFactory;
26  import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27  import org.apache.ibatis.submitted.autodiscover.mappers.DummyMapper;
28  import org.apache.ibatis.type.TypeAliasRegistry;
29  import org.apache.ibatis.type.TypeHandlerRegistry;
30  import org.junit.jupiter.api.BeforeAll;
31  import org.junit.jupiter.api.Test;
32  
33  class AutodiscoverTest {
34  
35    protected static SqlSessionFactory sqlSessionFactory;
36  
37    @BeforeAll
38    static void setup() throws Exception {
39      try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/autodiscover/MapperConfig.xml")) {
40        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
41      }
42    }
43  
44    @Test
45    void testTypeAlias() {
46      TypeAliasRegistry typeAliasRegistry = sqlSessionFactory.getConfiguration().getTypeAliasRegistry();
47      assertNotNull(typeAliasRegistry.resolveAlias("testAlias"));
48    }
49  
50    @Test
51    void testTypeHandler() {
52      TypeHandlerRegistry typeHandlerRegistry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry();
53      assertTrue(typeHandlerRegistry.hasTypeHandler(BigInteger.class));
54    }
55  
56    @Test
57    void testMapper() {
58      assertTrue(sqlSessionFactory.getConfiguration().hasMapper(DummyMapper.class));
59    }
60  }