org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisorTests.StereotypedRepositoryInterfaceImpl Java Examples

The following examples show how to use org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisorTests.StereotypedRepositoryInterfaceImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistenceExceptionTranslationPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
	}
}
 
Example #2
Source File: PersistenceExceptionTranslationPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
	}
}
 
Example #3
Source File: PersistenceExceptionTranslationPostProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
	}
}