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.xml_references;
17  
18  import java.io.Reader;
19  import java.util.Properties;
20  
21  import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
22  import org.apache.ibatis.io.Resources;
23  import org.apache.ibatis.mapping.Environment;
24  import org.apache.ibatis.session.Configuration;
25  import org.apache.ibatis.session.SqlSessionFactory;
26  import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27  import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory;
28  import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
29  import org.junit.jupiter.api.Test;
30  
31  class EnumWithOgnlTest {
32  
33    @Test
34    void testConfiguration() {
35      UnpooledDataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
36      Properties dataSourceProperties = new Properties();
37      dataSourceProperties.put("driver", "org.hsqldb.jdbcDriver");
38      dataSourceProperties.put("url", "jdbc:hsqldb:mem:xml_references");
39      dataSourceProperties.put("username", "sa");
40      dataSourceFactory.setProperties(dataSourceProperties);
41      Environment environment = new Environment("test", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
42      Configuration configuration = new Configuration();
43      configuration.setEnvironment(environment);
44      configuration.getTypeAliasRegistry().registerAlias(Person.class);
45      configuration.addMapper(PersonMapper.class);
46      configuration.addMapper(PersonMapper2.class);
47      new DefaultSqlSessionFactory(configuration);
48    }
49  
50    @Test
51    void testMixedConfiguration() throws Exception {
52      try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_references/ibatisConfig.xml")) {
53        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
54        sqlSessionFactory.getConfiguration().addMapper(PersonMapper2.class);
55      }
56    }
57  }