Search in sources :

Example 1 with Mapper

use of org.apache.ibatis.annotations.Mapper in project today-framework by TAKETODAY.

the class MapperScannerConfigurerTest method testScopedProxyMapperScanByDefault.

@Test
@Disabled
void testScopedProxyMapperScanByDefault() {
    applicationContext.getBeanDefinition("mapperScanner").propertyValues().add("defaultScope", "thread");
    startContext();
    List<String> scopedProxyTargetBeans = Stream.of(applicationContext.getBeanDefinitionNames()).filter(x -> x.startsWith("scopedTarget")).collect(Collectors.toList());
    assertThat(scopedProxyTargetBeans).hasSize(6).contains("scopedTarget.scopedProxyMapper", "scopedTarget.annotatedMapper", "scopedTarget.annotatedMapperZeroMethods", "scopedTarget.mapperInterface", "scopedTarget.mapperSubinterface", "scopedTarget.mapperChildInterface");
    for (String scopedProxyTargetBean : scopedProxyTargetBeans) {
        {
            BeanDefinition definition = applicationContext.getBeanDefinition(scopedProxyTargetBean);
            assertThat(definition.getBeanClassName()).isEqualTo("cn.taketoday.orm.mybatis.mapper.MapperFactoryBean");
            assertThat(definition.getScope()).isEqualTo("thread");
        }
        {
            BeanDefinition definition = applicationContext.getBeanDefinition(scopedProxyTargetBean.substring(13));
            assertThat(definition.getBeanClassName()).isEqualTo("cn.taketoday.aop.scope.ScopedProxyFactoryBean");
            assertThat(definition.getScope()).isEqualTo("");
        }
    }
    {
        ScopedProxyMapper mapper = applicationContext.getBean(ScopedProxyMapper.class);
        assertThat(mapper.test()).isEqualTo("test");
    }
    {
        AnnotatedMapper mapper = applicationContext.getBean(AnnotatedMapper.class);
        assertThat(mapper.test()).isEqualTo("main");
    }
    SqlSessionFactory sqlSessionFactory = applicationContext.getBean(SqlSessionFactory.class);
    assertEquals(2, sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers().size());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) GenericApplicationContext(cn.taketoday.context.support.GenericApplicationContext) Component(cn.taketoday.lang.Component) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RuntimeBeanReference(cn.taketoday.beans.factory.config.RuntimeBeanReference) Disabled(org.junit.jupiter.api.Disabled) BeanNamePopulator(cn.taketoday.beans.factory.support.BeanNamePopulator) SimpleThreadScope(cn.taketoday.beans.factory.config.SimpleThreadScope) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) NoSuchBeanDefinitionException(cn.taketoday.beans.factory.NoSuchBeanDefinitionException) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BeanFactoryUtils(cn.taketoday.beans.factory.BeanFactoryUtils) DummyMapperFactoryBean(cn.taketoday.orm.mybatis.type.DummyMapperFactoryBean) Properties(java.util.Properties) SqlSessionFactoryBean(cn.taketoday.orm.mybatis.SqlSessionFactoryBean) ExecutorType(org.apache.ibatis.session.ExecutorType) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Stream(java.util.stream.Stream) PropertyPlaceholderConfigurer(cn.taketoday.beans.factory.config.PropertyPlaceholderConfigurer) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mapper(org.apache.ibatis.annotations.Mapper) PropertySourcesPlaceholderConfigurer(cn.taketoday.context.support.PropertySourcesPlaceholderConfigurer) MapperChildInterface(cn.taketoday.orm.mybatis.mapper.child.MapperChildInterface) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

BeanFactoryUtils (cn.taketoday.beans.factory.BeanFactoryUtils)1 NoSuchBeanDefinitionException (cn.taketoday.beans.factory.NoSuchBeanDefinitionException)1 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)1 PropertyPlaceholderConfigurer (cn.taketoday.beans.factory.config.PropertyPlaceholderConfigurer)1 RuntimeBeanReference (cn.taketoday.beans.factory.config.RuntimeBeanReference)1 SimpleThreadScope (cn.taketoday.beans.factory.config.SimpleThreadScope)1 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)1 BeanNamePopulator (cn.taketoday.beans.factory.support.BeanNamePopulator)1 GenericApplicationContext (cn.taketoday.context.support.GenericApplicationContext)1 PropertySourcesPlaceholderConfigurer (cn.taketoday.context.support.PropertySourcesPlaceholderConfigurer)1 Component (cn.taketoday.lang.Component)1 SqlSessionFactoryBean (cn.taketoday.orm.mybatis.SqlSessionFactoryBean)1 MapperChildInterface (cn.taketoday.orm.mybatis.mapper.child.MapperChildInterface)1 DummyMapperFactoryBean (cn.taketoday.orm.mybatis.type.DummyMapperFactoryBean)1 MockDataSource (com.mockrunner.mock.jdbc.MockDataSource)1 List (java.util.List)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Mapper (org.apache.ibatis.annotations.Mapper)1