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();
}
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");
}
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();
}
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();
}
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);
}
Aggregations