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