use of cn.taketoday.dao.annotation.PersistenceExceptionTranslationAdvisorTests.RepositoryInterface 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.dao.annotation.PersistenceExceptionTranslationAdvisorTests.RepositoryInterface in project today-infrastructure 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");
}
Aggregations