Search in sources :

Example 6 with BeanDefinition

use of cn.taketoday.beans.factory.config.BeanDefinition in project today-infrastructure by TAKETODAY.

the class JeeNamespaceHandlerTests method testWithReferencedEnvironment.

@Test
public void testWithReferencedEnvironment() {
    BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withReferencedEnvironment");
    assertPropertyValue(beanDefinition, "jndiEnvironment", new RuntimeBeanReference("myEnvironment"));
    assertThat(beanDefinition.getPropertyValues().contains("environmentRef")).isFalse();
}
Also used : BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RuntimeBeanReference(cn.taketoday.beans.factory.config.RuntimeBeanReference) Test(org.junit.jupiter.api.Test)

Example 7 with BeanDefinition

use of cn.taketoday.beans.factory.config.BeanDefinition in project today-infrastructure by TAKETODAY.

the class JeeNamespaceHandlerTests method testSimpleDefinition.

@Test
public void testSimpleDefinition() {
    BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simple");
    assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName());
    assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource");
    assertPropertyValue(beanDefinition, "resourceRef", "true");
}
Also used : BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) JndiObjectFactoryBean(cn.taketoday.jndi.JndiObjectFactoryBean) Test(org.junit.jupiter.api.Test)

Example 8 with BeanDefinition

use of cn.taketoday.beans.factory.config.BeanDefinition in project today-infrastructure by TAKETODAY.

the class AsyncAnnotationBeanPostProcessorTests method taskExecutorByBeanName.

@Test
public void taskExecutorByBeanName() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
    context.registerBeanDefinition("postProcessor", processorDefinition);
    BeanDefinition executorDefinition = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
    executorDefinition.getPropertyValues().add("threadNamePrefix", "testExecutor");
    context.registerBeanDefinition("myExecutor", executorDefinition);
    BeanDefinition executorDefinition2 = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
    executorDefinition2.getPropertyValues().add("threadNamePrefix", "testExecutor2");
    context.registerBeanDefinition("taskExecutor", executorDefinition2);
    BeanDefinition targetDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessorTests.TestBean.class);
    context.registerBeanDefinition("target", targetDefinition);
    context.refresh();
    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertThat(asyncThread.getName().startsWith("testExecutor2")).isTrue();
    context.close();
}
Also used : StaticApplicationContext(cn.taketoday.context.support.StaticApplicationContext) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 9 with BeanDefinition

use of cn.taketoday.beans.factory.config.BeanDefinition in project today-infrastructure by TAKETODAY.

the class AsyncAnnotationBeanPostProcessorTests method taskExecutorByBeanType.

@Test
public void taskExecutorByBeanType() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
    context.registerBeanDefinition("postProcessor", processorDefinition);
    BeanDefinition executorDefinition = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
    executorDefinition.getPropertyValues().add("threadNamePrefix", "testExecutor");
    context.registerBeanDefinition("myExecutor", executorDefinition);
    BeanDefinition targetDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessorTests.TestBean.class);
    context.registerBeanDefinition("target", targetDefinition);
    context.refresh();
    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertThat(asyncThread.getName().startsWith("testExecutor")).isTrue();
    context.close();
}
Also used : StaticApplicationContext(cn.taketoday.context.support.StaticApplicationContext) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 10 with BeanDefinition

use of cn.taketoday.beans.factory.config.BeanDefinition in project today-infrastructure by TAKETODAY.

the class AsyncAnnotationBeanPostProcessorTests method handleExceptionWithCustomExceptionHandler.

@Test
public void handleExceptionWithCustomExceptionHandler() {
    Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
    TestableAsyncUncaughtExceptionHandler exceptionHandler = new TestableAsyncUncaughtExceptionHandler();
    BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
    processorDefinition.getPropertyValues().add("exceptionHandler", exceptionHandler);
    ConfigurableApplicationContext context = initContext(processorDefinition);
    ITestBean testBean = context.getBean("target", ITestBean.class);
    assertThat(exceptionHandler.isCalled()).as("Handler should not have been called").isFalse();
    testBean.failWithVoid();
    exceptionHandler.await(3000);
    exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
}
Also used : ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Method(java.lang.reflect.Method) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)239 Test (org.junit.jupiter.api.Test)163 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)90 AnnotatedBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition)36 PropertyValues (cn.taketoday.beans.PropertyValues)31 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)24 GenericBeanDefinition (cn.taketoday.beans.factory.support.GenericBeanDefinition)19 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)19 AbstractBeanDefinition (cn.taketoday.beans.factory.support.AbstractBeanDefinition)17 ScannedGenericBeanDefinition (cn.taketoday.context.annotation.ScannedGenericBeanDefinition)15 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)14 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)13 NoSuchBeanDefinitionException (cn.taketoday.beans.factory.NoSuchBeanDefinitionException)12 GenericApplicationContext (cn.taketoday.context.support.GenericApplicationContext)12 Properties (java.util.Properties)12 RuntimeBeanReference (cn.taketoday.beans.factory.config.RuntimeBeanReference)10 AssignableTypeFilter (cn.taketoday.core.type.filter.AssignableTypeFilter)10 BeanDefinitionBuilder.genericBeanDefinition (cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition)9 ChildBeanDefinition (cn.taketoday.beans.factory.support.ChildBeanDefinition)9 StaticApplicationContext (cn.taketoday.context.support.StaticApplicationContext)9