From 3ac3a72e910ce4734459e9359f979fbed8cb64a1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 8 Aug 2009 13:57:05 +0000 Subject: [PATCH] added test with custom repository annotation --- ...tenceExceptionTranslationAdvisorTests.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/org.springframework.transaction/src/test/java/org/springframework/dao/annotation/PersistenceExceptionTranslationAdvisorTests.java b/org.springframework.transaction/src/test/java/org/springframework/dao/annotation/PersistenceExceptionTranslationAdvisorTests.java index 2c6fb3d81d..8099156006 100644 --- a/org.springframework.transaction/src/test/java/org/springframework/dao/annotation/PersistenceExceptionTranslationAdvisorTests.java +++ b/org.springframework.transaction/src/test/java/org/springframework/dao/annotation/PersistenceExceptionTranslationAdvisorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,10 @@ package org.springframework.dao.annotation; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import javax.persistence.PersistenceException; import junit.framework.TestCase; @@ -109,6 +113,10 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase { doTestTranslationNeededForTheseExceptions(new MyStereotypedRepositoryInterfaceImpl()); } + public void testTranslationNeededForTheseExceptionsWithCustomStereotype() { + doTestTranslationNeededForTheseExceptions(new CustomStereotypedRepositoryInterfaceImpl()); + } + public void testTranslationNeededForTheseExceptionsOnInterface() { doTestTranslationNeededForTheseExceptions(new MyInterfaceStereotypedRepositoryInterfaceImpl()); } @@ -142,6 +150,7 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase { } } + public interface RepositoryInterface { void noThrowsClause(); @@ -149,6 +158,7 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase { void throwsPersistenceException() throws PersistenceException; } + public static class RepositoryInterfaceImpl implements RepositoryInterface { private RuntimeException runtimeException; @@ -170,29 +180,49 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase { } } + @Repository public static class StereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl { // Extends above class just to add repository annotation } + public static class MyStereotypedRepositoryInterfaceImpl extends StereotypedRepositoryInterfaceImpl { } + + @MyRepository + public static class CustomStereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl { + + } + + + @Target({ElementType.TYPE}) + @Retention(RetentionPolicy.RUNTIME) + @Repository + public @interface MyRepository { + + } + + @Repository public interface StereotypedInterface { } + public static class MyInterfaceStereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl implements StereotypedInterface { } + public interface StereotypedInheritingInterface extends StereotypedInterface { } + public static class MyInterfaceInheritedStereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl implements StereotypedInheritingInterface {