use of cn.taketoday.context.support.GenericApplicationContext in project today-framework by TAKETODAY.
the class AbstractMBeanServerTests method loadContext.
protected final ConfigurableApplicationContext loadContext(String configLocation) {
GenericApplicationContext ctx = new GenericApplicationContext();
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(configLocation);
ctx.getBeanFactory().registerSingleton("server", getServer());
ctx.refresh();
return ctx;
}
use of cn.taketoday.context.support.GenericApplicationContext in project today-framework by TAKETODAY.
the class ScriptFactoryPostProcessorTests method testForRefreshedScriptHavingErrorPickedUpOnFirstCall.
@Test
void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
collaboratorBuilder.addPropertyReference(MESSENGER_BEAN_NAME, MESSENGER_BEAN_NAME);
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition);
ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition);
final String collaboratorBeanName = "collaborator";
ctx.registerBeanDefinition(collaboratorBeanName, collaboratorBuilder.getBeanDefinition());
ctx.refresh();
Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertThat(messenger.getMessage()).isEqualTo(MESSAGE_TEXT);
// cool; now let's change the script and check the refresh behaviour...
pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE);
StaticScriptSource source = getScriptSource(ctx);
// needs The Sundays compiler; must NOT throw any exception here...
source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea");
Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(refreshedMessenger::getMessage).matches(ex -> ex.contains(ScriptCompilationException.class));
}
use of cn.taketoday.context.support.GenericApplicationContext in project today-framework by TAKETODAY.
the class PersistenceExceptionTranslationPostProcessorTests method proxiesCorrectly.
@Test
@SuppressWarnings("resource")
public void proxiesCorrectly() {
GenericApplicationContext gac = new GenericApplicationContext();
gac.registerBeanDefinition("translator", new RootBeanDefinition(PersistenceExceptionTranslationPostProcessor.class));
gac.registerBeanDefinition("notProxied", new RootBeanDefinition(RepositoryInterfaceImpl.class));
gac.registerBeanDefinition("proxied", new RootBeanDefinition(StereotypedRepositoryInterfaceImpl.class));
gac.registerBeanDefinition("classProxied", new RootBeanDefinition(RepositoryWithoutInterface.class));
gac.registerBeanDefinition("classProxiedAndAdvised", new RootBeanDefinition(RepositoryWithoutInterfaceAndOtherwiseAdvised.class));
gac.registerBeanDefinition("myTranslator", new RootBeanDefinition(MyPersistenceExceptionTranslator.class));
gac.registerBeanDefinition("proxyCreator", BeanDefinitionBuilder.rootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class).addPropertyValue("order", 50).getBeanDefinition());
gac.registerBeanDefinition("logger", new RootBeanDefinition(LogAllAspect.class));
gac.refresh();
RepositoryInterface shouldNotBeProxied = (RepositoryInterface) gac.getBean("notProxied");
assertThat(AopUtils.isAopProxy(shouldNotBeProxied)).isFalse();
RepositoryInterface shouldBeProxied = (RepositoryInterface) gac.getBean("proxied");
assertThat(AopUtils.isAopProxy(shouldBeProxied)).isTrue();
RepositoryWithoutInterface rwi = (RepositoryWithoutInterface) gac.getBean("classProxied");
assertThat(AopUtils.isAopProxy(rwi)).isTrue();
checkWillTranslateExceptions(rwi);
Additional rwi2 = (Additional) gac.getBean("classProxiedAndAdvised");
assertThat(AopUtils.isAopProxy(rwi2)).isTrue();
rwi2.additionalMethod(false);
checkWillTranslateExceptions(rwi2);
assertThatExceptionOfType(DataAccessResourceFailureException.class).isThrownBy(() -> rwi2.additionalMethod(true)).withMessage("my failure");
}
use of cn.taketoday.context.support.GenericApplicationContext in project today-framework by TAKETODAY.
the class AsyncExecutionTests method asyncInterfaceWithPostProcessor.
@Test
public void asyncInterfaceWithPostProcessor() throws Exception {
originalThreadName = Thread.currentThread().getName();
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("asyncTest", new BeanDefinition(AsyncInterfaceBean.class));
context.registerBeanDefinition("asyncProcessor", new BeanDefinition(AsyncAnnotationBeanPostProcessor.class));
context.refresh();
AsyncInterface asyncTest = context.getBean("asyncTest", AsyncInterface.class);
asyncTest.doSomething(10);
Future<String> future = asyncTest.returnSomething(20);
assertThat(future.get()).isEqualTo("20");
}
use of cn.taketoday.context.support.GenericApplicationContext in project today-framework by TAKETODAY.
the class AsyncExecutionTests method asyncMethodListener.
@Test
public void asyncMethodListener() throws Exception {
// Arrange
originalThreadName = Thread.currentThread().getName();
listenerCalled = 0;
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("asyncTest", new BeanDefinition(AsyncMethodListener.class));
context.registerBeanDefinition("autoProxyCreator", new BeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new BeanDefinition(AsyncAnnotationAdvisor.class));
// Act
context.refresh();
// Assert
Awaitility.await().atMost(1, TimeUnit.SECONDS).pollInterval(10, TimeUnit.MILLISECONDS).until(() -> listenerCalled == 1);
context.close();
}
Aggregations