Search in sources :

Example 1 with GenericBeanDefinition

use of cn.taketoday.beans.factory.support.GenericBeanDefinition in project today-infrastructure by TAKETODAY.

the class StandardDependenciesBeanPostProcessorTests method testIncompleteBeanDefinition.

@Test
public void testIncompleteBeanDefinition() {
    bf.registerBeanDefinition("testBean", new GenericBeanDefinition());
    assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> bf.getBean("testBean")).withRootCauseInstanceOf(IllegalStateException.class);
}
Also used : GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with GenericBeanDefinition

use of cn.taketoday.beans.factory.support.GenericBeanDefinition in project today-infrastructure by TAKETODAY.

the class AutowiredAnnotationBeanPostProcessorTests method testIncompleteBeanDefinition.

@Test
public void testIncompleteBeanDefinition() {
    bf.registerBeanDefinition("testBean", new GenericBeanDefinition());
    assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> bf.getBean("testBean")).withRootCauseInstanceOf(IllegalStateException.class);
}
Also used : GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with GenericBeanDefinition

use of cn.taketoday.beans.factory.support.GenericBeanDefinition in project today-infrastructure by TAKETODAY.

the class BeanDefinitionTests method genericBeanDefinitionEquality.

@Test
public void genericBeanDefinitionEquality() {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setParentName("parent");
    bd.setScope("request");
    bd.setAbstract(true);
    bd.setLazyInit(true);
    GenericBeanDefinition otherBd = new GenericBeanDefinition();
    otherBd.setScope("request");
    otherBd.setAbstract(true);
    otherBd.setLazyInit(true);
    boolean condition1 = !bd.equals(otherBd);
    assertThat(condition1).isTrue();
    boolean condition = !otherBd.equals(bd);
    assertThat(condition).isTrue();
    otherBd.setParentName("parent");
    assertThat(bd.equals(otherBd)).isTrue();
    assertThat(otherBd.equals(bd)).isTrue();
    assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
    bd.getPropertyValues();
    assertThat(bd.equals(otherBd)).isTrue();
    assertThat(otherBd.equals(bd)).isTrue();
    assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
    bd.getConstructorArgumentValues();
    assertThat(bd.equals(otherBd)).isTrue();
    assertThat(otherBd.equals(bd)).isTrue();
    assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
}
Also used : GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with GenericBeanDefinition

use of cn.taketoday.beans.factory.support.GenericBeanDefinition in project today-infrastructure by TAKETODAY.

the class MapperScanTest method testScanWithNameConflict.

@Test
void testScanWithNameConflict() {
    GenericBeanDefinition definition = new GenericBeanDefinition();
    definition.setBeanClass(Object.class);
    applicationContext.registerBeanDefinition("mapperInterface", definition);
    applicationContext.register(AppConfigWithPackageScan.class);
    startContext();
    assertThat(applicationContext.getBean("mapperInterface").getClass()).as("scanner should not overwrite existing bean definition").isSameAs(Object.class);
}
Also used : GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with GenericBeanDefinition

use of cn.taketoday.beans.factory.support.GenericBeanDefinition in project today-infrastructure by TAKETODAY.

the class MapperScanTest method testScanWithExplicitSqlSessionTemplate.

@Test
void testScanWithExplicitSqlSessionTemplate() {
    GenericBeanDefinition definition = new GenericBeanDefinition();
    definition.setBeanClass(SqlSessionTemplate.class);
    ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues();
    constructorArgs.addGenericArgumentValue(new RuntimeBeanReference("sqlSessionFactory"));
    definition.setConstructorArgumentValues(constructorArgs);
    applicationContext.registerBeanDefinition("sqlSessionTemplate", definition);
    applicationContext.register(AppConfigWithSqlSessionTemplate.class);
    startContext();
    // all interfaces with methods should be loaded
    applicationContext.getBean("mapperInterface");
    applicationContext.getBean("mapperSubinterface");
    applicationContext.getBean("mapperChildInterface");
    applicationContext.getBean("annotatedMapper");
}
Also used : GenericBeanDefinition(cn.taketoday.beans.factory.support.GenericBeanDefinition) RuntimeBeanReference(cn.taketoday.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(cn.taketoday.beans.factory.config.ConstructorArgumentValues) Test(org.junit.jupiter.api.Test)

Aggregations

GenericBeanDefinition (cn.taketoday.beans.factory.support.GenericBeanDefinition)41 Test (org.junit.jupiter.api.Test)26 RuntimeBeanReference (cn.taketoday.beans.factory.config.RuntimeBeanReference)10 ConstructorArgumentValues (cn.taketoday.beans.factory.config.ConstructorArgumentValues)8 GenericApplicationContext (cn.taketoday.context.support.GenericApplicationContext)6 MockDataSource (com.mockrunner.mock.jdbc.MockDataSource)6 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)5 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)5 Nullable (cn.taketoday.lang.Nullable)5 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)4 Properties (java.util.Properties)4 AbstractBeanFactoryTargetSource (cn.taketoday.aop.target.AbstractBeanFactoryTargetSource)2 BeanDefinitionDefaults (cn.taketoday.beans.factory.support.BeanDefinitionDefaults)2 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)2 SimpleThreadScope (cn.taketoday.context.support.SimpleThreadScope)2 MapperChildInterface (cn.taketoday.orm.mybatis.mapper.child.MapperChildInterface)2 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2