use of org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisorTests.RepositoryInterface in project spring-framework by spring-projects.
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");
assertFalse(AopUtils.isAopProxy(shouldNotBeProxied));
RepositoryInterface shouldBeProxied = (RepositoryInterface) gac.getBean("proxied");
assertTrue(AopUtils.isAopProxy(shouldBeProxied));
RepositoryWithoutInterface rwi = (RepositoryWithoutInterface) gac.getBean("classProxied");
assertTrue(AopUtils.isAopProxy(rwi));
checkWillTranslateExceptions(rwi);
Additional rwi2 = (Additional) gac.getBean("classProxiedAndAdvised");
assertTrue(AopUtils.isAopProxy(rwi2));
rwi2.additionalMethod(false);
checkWillTranslateExceptions(rwi2);
try {
rwi2.additionalMethod(true);
fail("Should have thrown DataAccessResourceFailureException");
} catch (DataAccessResourceFailureException ex) {
assertEquals("my failure", ex.getMessage());
}
}
Aggregations