Search in sources :

Example 1 with MyBatisSystemException

use of cn.taketoday.orm.mybatis.MyBatisSystemException in project today-framework by TAKETODAY.

the class MapperFactoryBeanTest method testAddToConfigFalse.

// will fail because TestDao's mapper config is never loaded
@Test
void testAddToConfigFalse() throws Throwable {
    try {
        // the default SqlSessionFactory in AbstractMyBatisTodayTest is created with an explicitly
        // set MapperLocations list, so create a new factory here that tests auto-loading the
        // config
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        // mapperLocations properties defaults to null
        factoryBean.setDataSource(dataSource);
        SqlSessionFactory sqlSessionFactory = factoryBean.getObject();
        assertThrows(org.apache.ibatis.binding.BindingException.class, () -> find(new SqlSessionTemplate(sqlSessionFactory), false));
    // fail("TestDao's mapper xml should not be loaded");
    } catch (MyBatisSystemException mbse) {
        // unwrap exception so the exact MyBatis exception can be tested
        throw mbse.getCause();
    } finally {
        // connection not used; force close to avoid failing in validateConnectionClosed()
        connection.close();
    }
}
Also used : SqlSessionTemplate(cn.taketoday.orm.mybatis.SqlSessionTemplate) MyBatisSystemException(cn.taketoday.orm.mybatis.MyBatisSystemException) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) SqlSessionFactoryBean(cn.taketoday.orm.mybatis.SqlSessionFactoryBean) AbstractMyBatisTest(cn.taketoday.orm.mybatis.AbstractMyBatisTest) Test(org.junit.jupiter.api.Test)

Example 2 with MyBatisSystemException

use of cn.taketoday.orm.mybatis.MyBatisSystemException in project today-infrastructure by TAKETODAY.

the class MapperFactoryBeanTest method testAddToConfigFalse.

// will fail because TestDao's mapper config is never loaded
@Test
void testAddToConfigFalse() throws Throwable {
    try {
        // the default SqlSessionFactory in AbstractMyBatisTodayTest is created with an explicitly
        // set MapperLocations list, so create a new factory here that tests auto-loading the
        // config
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        // mapperLocations properties defaults to null
        factoryBean.setDataSource(dataSource);
        SqlSessionFactory sqlSessionFactory = factoryBean.getObject();
        assertThrows(org.apache.ibatis.binding.BindingException.class, () -> find(new SqlSessionTemplate(sqlSessionFactory), false));
    // fail("TestDao's mapper xml should not be loaded");
    } catch (MyBatisSystemException mbse) {
        // unwrap exception so the exact MyBatis exception can be tested
        throw mbse.getCause();
    } finally {
        // connection not used; force close to avoid failing in validateConnectionClosed()
        connection.close();
    }
}
Also used : SqlSessionTemplate(cn.taketoday.orm.mybatis.SqlSessionTemplate) MyBatisSystemException(cn.taketoday.orm.mybatis.MyBatisSystemException) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) SqlSessionFactoryBean(cn.taketoday.orm.mybatis.SqlSessionFactoryBean) AbstractMyBatisTest(cn.taketoday.orm.mybatis.AbstractMyBatisTest) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractMyBatisTest (cn.taketoday.orm.mybatis.AbstractMyBatisTest)2 MyBatisSystemException (cn.taketoday.orm.mybatis.MyBatisSystemException)2 SqlSessionFactoryBean (cn.taketoday.orm.mybatis.SqlSessionFactoryBean)2 SqlSessionTemplate (cn.taketoday.orm.mybatis.SqlSessionTemplate)2 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)2 Test (org.junit.jupiter.api.Test)2