diff --git a/org.springframework.aspects/ivy.xml b/org.springframework.aspects/ivy.xml index 526bf8ec013..5bd5219b489 100644 --- a/org.springframework.aspects/ivy.xml +++ b/org.springframework.aspects/ivy.xml @@ -22,7 +22,7 @@ - + diff --git a/org.springframework.context/src/test/java/org/springframework/aop/aspectj/_TestTypes.java b/org.springframework.context/src/test/java/org/springframework/aop/aspectj/_TestTypes.java index c8150a7500d..3ad14e51d5e 100644 --- a/org.springframework.context/src/test/java/org/springframework/aop/aspectj/_TestTypes.java +++ b/org.springframework.context/src/test/java/org/springframework/aop/aspectj/_TestTypes.java @@ -1,4 +1,3 @@ -package org.springframework.aop.aspectj; /* * Copyright 2002-2006 the original author or authors. * @@ -15,6 +14,8 @@ package org.springframework.aop.aspectj; * limitations under the License. */ +package org.springframework.aop.aspectj; + import org.aspectj.lang.JoinPoint; /** diff --git a/org.springframework.core/ivy.xml b/org.springframework.core/ivy.xml index 3be2f2a097c..218231af423 100644 --- a/org.springframework.core/ivy.xml +++ b/org.springframework.core/ivy.xml @@ -25,7 +25,7 @@ - + diff --git a/org.springframework.samples.petclinic/ivy.xml b/org.springframework.samples.petclinic/ivy.xml index dbab588ebd3..d66bac9ed54 100644 --- a/org.springframework.samples.petclinic/ivy.xml +++ b/org.springframework.samples.petclinic/ivy.xml @@ -25,7 +25,7 @@ - + diff --git a/org.springframework.test/ivy.xml b/org.springframework.test/ivy.xml index 3b019fcdae0..37daf4b40d4 100644 --- a/org.springframework.test/ivy.xml +++ b/org.springframework.test/ivy.xml @@ -29,7 +29,7 @@ - + diff --git a/org.springframework.testsuite/ivy.xml b/org.springframework.testsuite/ivy.xml index 1c346d88e3c..539263e8cd0 100644 --- a/org.springframework.testsuite/ivy.xml +++ b/org.springframework.testsuite/ivy.xml @@ -62,7 +62,7 @@ - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AdviceUsingThisJoinPoint.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AdviceUsingThisJoinPoint.java deleted file mode 100644 index a00a8fe65c3..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AdviceUsingThisJoinPoint.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; - -@Aspect -public class AdviceUsingThisJoinPoint { - - private String lastEntry = ""; - - public String getLastMethodEntered() { - return this.lastEntry; - } - - @Pointcut("execution(* *(..))") - public void methodExecution() {} - - @Before("methodExecution()") - public void entryTrace(JoinPoint jp) { - this.lastEntry = jp.toString(); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotatedTestBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotatedTestBean.java deleted file mode 100644 index 85506559731..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotatedTestBean.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -/** - * @author Adrian Colyer - * @since 2.0 - */ -public interface AnnotatedTestBean { - - String doThis(); - - String doThat(); - - String doTheOther(); - - String[] doArray(); - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotatedTestBeanImpl.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotatedTestBeanImpl.java deleted file mode 100644 index 00a47ff1a20..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotatedTestBeanImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.springframework.transaction.annotation.Transactional; - -/** - * @author Adrian Colyer - * @since 2.0 - */ -@Transactional -public class AnnotatedTestBeanImpl implements AnnotatedTestBean { - - @TestAnnotation("this value") - public String doThis() { - return "doThis"; - } - - @TestAnnotation("that value") - public String doThat() { - return "doThat"; - } - - @TestAnnotation("array value") - public String[] doArray() { - return new String[] {"doThis", "doThat"}; - } - - // not annotated - public String doTheOther() { - return "doTheOther"; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTestAspect.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTestAspect.java deleted file mode 100644 index ba74b1a7a4b..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTestAspect.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.ProceedingJoinPoint; - -/** - * @author Adrian Colyer - */ -public class AnnotationBindingTestAspect { - - public String doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnnotation) throws Throwable { - return testAnnotation.value(); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/around-advice-tests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests-context.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/around-advice-tests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests-context.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java index 9487fd7132f..af3310eaa35 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java @@ -16,29 +16,35 @@ package org.springframework.aop.aspectj.autoproxy; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author Adrian Colyer + * @author Chris Beams */ -public class AnnotationBindingTests extends AbstractDependencyInjectionSpringContextTests { +public final class AnnotationBindingTests { private AnnotatedTestBean testBean; - @Override - protected String getConfigPath() { - return "around-advice-tests.xml"; - } - - public void setTestBean(AnnotatedTestBean testBean) { - this.testBean = testBean; + @Before + public void setUp() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + + testBean = (AnnotatedTestBean) ctx.getBean("testBean"); } + @Test public void testAnnotationBindingInAroundAdvice() { assertEquals("this value", testBean.doThis()); assertEquals("that value", testBean.doThat()); } + @Test public void testNoMatchingWithoutAnnotationPresent() { assertEquals("doTheOther", testBean.doTheOther()); } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/annotationPointcut.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationPointcutTests-context.xml similarity index 94% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/annotationPointcut.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationPointcutTests-context.xml index 63505eaa375..9d3daabaddb 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/annotationPointcut.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationPointcutTests-context.xml @@ -9,7 +9,7 @@ - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationPointcutTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationPointcutTests.java index a894b8f9536..b2bf8acec7a 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationPointcutTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationPointcutTests.java @@ -16,41 +16,47 @@ package org.springframework.aop.aspectj.autoproxy; +import static org.junit.Assert.assertEquals; + import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author Juergen Hoeller + * @author Chris Beams */ -public class AnnotationPointcutTests extends AbstractDependencyInjectionSpringContextTests { +public final class AnnotationPointcutTests { private AnnotatedTestBean testBean; - @Override - protected String getConfigPath() { - return "annotationPointcut.xml"; - } - - public void setTestBean(AnnotatedTestBean testBean) { - this.testBean = testBean; + @Before + public void setUp() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + + testBean = (AnnotatedTestBean) ctx.getBean("testBean"); } + @Test public void testAnnotationBindingInAroundAdvice() { assertEquals("this value", testBean.doThis()); } + @Test public void testNoMatchingWithoutAnnotationPresent() { assertEquals("doTheOther", testBean.doTheOther()); } - - public static class TestMethodInterceptor implements MethodInterceptor { - - public Object invoke(MethodInvocation methodInvocation) throws Throwable { - return "this value"; - } - } - } + + +class TestMethodInterceptor implements MethodInterceptor { + + public Object invoke(MethodInvocation methodInvocation) throws Throwable { + return "this value"; + } +} + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspect-implementing-interface-tests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectImplementingInterfaceTests-context.xml similarity index 86% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspect-implementing-interface-tests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectImplementingInterfaceTests-context.xml index dffe959a329..7d846604000 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspect-implementing-interface-tests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectImplementingInterfaceTests-context.xml @@ -16,5 +16,5 @@ + class="org.springframework.aop.aspectj.autoproxy.InterfaceExtendingAspect"/> \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectImplementingInterfaceTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectImplementingInterfaceTests.java index 3ef06b4001b..9507d488916 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectImplementingInterfaceTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectImplementingInterfaceTests.java @@ -16,47 +16,47 @@ package org.springframework.aop.aspectj.autoproxy; +import static org.junit.Assert.*; + import org.aspectj.lang.ProceedingJoinPoint; +import org.junit.Test; import org.springframework.aop.framework.Advised; import org.springframework.beans.ITestBean; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Test for ensuring the aspects aren't advised. See SPR-3893 for more details. * * @author Ramnivas Laddad + * @author Chris Beams */ -public class AspectImplementingInterfaceTests extends AbstractDependencyInjectionSpringContextTests { - protected ITestBean testBean; - protected AnInterface interfaceExtendingAspect; - - public AspectImplementingInterfaceTests() { - setPopulateProtectedVariables(true); - } - - protected String getConfigPath() { - return "aspect-implementing-interface-tests.xml"; - } - - protected void onSetUp() throws Exception { - super.onSetUp(); - } +public final class AspectImplementingInterfaceTests { + @Test public void testProxyCreation() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + + ITestBean testBean = (ITestBean) ctx.getBean("testBean"); + AnInterface interfaceExtendingAspect = (AnInterface) ctx.getBean("interfaceExtendingAspect"); + assertTrue(testBean instanceof Advised); assertFalse(interfaceExtendingAspect instanceof Advised); } - public static interface AnInterface { - public void interfaceMethod(); - } - - public static class InterfaceExtendingAspect implements AnInterface { - public void increment(ProceedingJoinPoint pjp) throws Throwable { - pjp.proceed(); - } +} - public void interfaceMethod() { - } + +interface AnInterface { + public void interfaceMethod(); +} + + +class InterfaceExtendingAspect implements AnInterface { + public void increment(ProceedingJoinPoint pjp) throws Throwable { + pjp.proceed(); + } + + public void interfaceMethod() { } } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/lazy.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorAndLazyInitTargetSourceTests-context.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/lazy.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorAndLazyInitTargetSourceTests-context.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorAndLazyInitTargetSourceTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorAndLazyInitTargetSourceTests.java index 760d10849c2..9524e6dce3e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorAndLazyInitTargetSourceTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorAndLazyInitTargetSourceTests.java @@ -16,26 +16,26 @@ package org.springframework.aop.aspectj.autoproxy; +import static org.junit.Assert.*; + +import org.junit.Test; import org.springframework.beans.ITestBean; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import org.springframework.beans.TestBean; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author Rod Johnson * @author Rob Harrop + * @author Chris Beams */ -public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests extends AbstractDependencyInjectionSpringContextTests { - - public AspectJAutoProxyCreatorAndLazyInitTargetSourceTests() { - setAutowireMode(AUTOWIRE_BY_NAME); - } - - @Override - protected String getConfigPath() { - return "lazy.xml"; - } +public final class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests { + @Test public void testAdrian() { - ITestBean adrian = (ITestBean) applicationContext.getBean("adrian"); + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + + ITestBean adrian = (ITestBean) ctx.getBean("adrian"); assertEquals(0, LazyTestBean.instantiations); assertNotNull(adrian); adrian.getAge(); @@ -44,3 +44,14 @@ public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests extends Abstrac } } + + +class LazyTestBean extends TestBean { + + public static int instantiations; + + public LazyTestBean() { + ++instantiations; + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspects.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspects.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspects.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspects.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsPlusAdvisor.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsPlusAdvisor.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithAbstractBean.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsWithAbstractBean.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithAbstractBean.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsWithAbstractBean.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithCGLIB.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsWithCGLIB.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithCGLIB.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsWithCGLIB.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithOrdering.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsWithOrdering.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithOrdering.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-aspectsWithOrdering.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/pertarget.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-pertarget.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/pertarget.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-pertarget.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/perthis.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-perthis.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/perthis.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-perthis.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/retryAspect.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-retryAspect.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/retryAspect.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-retryAspect.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/twoAdviceAspect.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-twoAdviceAspect.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/twoAdviceAspect.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-twoAdviceAspect.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/twoAdviceAspectPrototype.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-twoAdviceAspectPrototype.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/twoAdviceAspectPrototype.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-twoAdviceAspectPrototype.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/usesInclude.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-usesInclude.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/usesInclude.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-usesInclude.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/usesJoinPointAspect.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-usesJoinPointAspect.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/usesJoinPointAspect.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests-usesJoinPointAspect.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java index 5f23b9bfa25..bccbfa15466 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java @@ -15,27 +15,36 @@ */ package org.springframework.aop.aspectj.autoproxy; +import static java.lang.String.format; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; +import java.lang.reflect.Method; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; import org.junit.Test; +import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator; import org.springframework.aop.aspectj.annotation.AspectMetadata; import org.springframework.aop.config.AopConfigUtils; import org.springframework.aop.framework.ProxyConfig; import org.springframework.aop.support.AopUtils; +import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; import org.springframework.beans.INestedTestBean; import org.springframework.beans.ITestBean; import org.springframework.beans.NestedTestBean; import org.springframework.beans.PropertyValue; import org.springframework.beans.TestBean; +import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.MethodInvokingFactoryBean; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; @@ -43,7 +52,10 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.NestedRuntimeException; import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.core.io.ClassPathResource; import org.springframework.util.StopWatch; /** @@ -54,14 +66,13 @@ import org.springframework.util.StopWatch; * @author Juergen Hoeller * @author Chris Beams */ -public class AspectJAutoProxyCreatorTests { +public final class AspectJAutoProxyCreatorTests { private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class); @Test public void testAspectsAreApplied() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspects.xml"); + ClassPathXmlApplicationContext bf = newContext("aspects.xml"); ITestBean tb = (ITestBean) bf.getBean("adrian"); assertEquals(68, tb.getAge()); MethodInvokingFactoryBean factoryBean = (MethodInvokingFactoryBean) bf.getBean("&factoryBean"); @@ -71,8 +82,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testMultipleAspectsWithParameterApplied() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspects.xml"); + ClassPathXmlApplicationContext bf = newContext("aspects.xml"); ITestBean tb = (ITestBean) bf.getBean("adrian"); tb.setAge(10); assertEquals(20, tb.getAge()); @@ -80,18 +90,16 @@ public class AspectJAutoProxyCreatorTests { @Test public void testAspectsAreAppliedInDefinedOrder() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspectsWithOrdering.xml"); + ClassPathXmlApplicationContext bf = newContext("aspectsWithOrdering.xml"); ITestBean tb = (ITestBean) bf.getBean("adrian"); assertEquals(71, tb.getAge()); } @Test public void testAspectsAndAdvisorAreApplied() { - ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml"); + ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian"); - testAspectsAndAdvisorAreApplied(ac, shouldBeWeaved); + doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved); } @Test @@ -100,14 +108,13 @@ public class AspectJAutoProxyCreatorTests { // Skip this test: Trace logging blows the time limit. return; } - ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml"); + ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 10000; i++) { ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2"); if (i < 10) { - testAspectsAndAdvisorAreApplied(ac, shouldBeWeaved); + doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved); } } sw.stop(); @@ -121,8 +128,7 @@ public class AspectJAutoProxyCreatorTests { // Skip this test: Trace logging blows the time limit. return; } - ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml"); + ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); StopWatch sw = new StopWatch(); sw.start("prototype"); for (int i = 0; i < 100000; i++) { @@ -144,7 +150,7 @@ public class AspectJAutoProxyCreatorTests { } GenericApplicationContext ac = new GenericApplicationContext(); new XmlBeanDefinitionReader(ac).loadBeanDefinitions( - "/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml"); + new ClassPathResource(qName("aspectsPlusAdvisor.xml"), getClass())); for (int i = 0; i < 10000; i++) { ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class)); } @@ -158,8 +164,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() { - ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml"); + ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); GenericApplicationContext childAc = new GenericApplicationContext(ac); // Create a child factory with a bean that should be weaved RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); @@ -173,10 +178,10 @@ public class AspectJAutoProxyCreatorTests { ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2"); //testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian")); - testAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved); + doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved); } - protected void testAspectsAndAdvisorAreApplied(ApplicationContext ac, ITestBean shouldBeWeaved) { + protected void doTestAspectsAndAdvisorAreApplied(ApplicationContext ac, ITestBean shouldBeWeaved) { TestBeanAdvisor tba = (TestBeanAdvisor) ac.getBean("advisor"); MultiplyReturnValue mrv = (MultiplyReturnValue) ac.getBean("aspect"); @@ -195,8 +200,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testPerThisAspect() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/perthis.xml"); + ClassPathXmlApplicationContext bf = newContext("perthis.xml"); ITestBean adrian1 = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian1)); @@ -216,8 +220,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testPerTargetAspect() throws SecurityException, NoSuchMethodException { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/pertarget.xml"); + ClassPathXmlApplicationContext bf = newContext("pertarget.xml"); ITestBean adrian1 = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian1)); @@ -262,8 +265,7 @@ public class AspectJAutoProxyCreatorTests { } private void doTestTwoAdviceAspectWith(String location) { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/" + location); + ClassPathXmlApplicationContext bf = newContext(location); boolean aspectSingleton = bf.isSingleton("aspect"); ITestBean adrian1 = (ITestBean) bf.getBean("adrian"); @@ -275,8 +277,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testAdviceUsingJoinPoint() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/usesJoinPointAspect.xml"); + ClassPathXmlApplicationContext bf = newContext("usesJoinPointAspect.xml"); ITestBean adrian1 = (ITestBean) bf.getBean("adrian"); adrian1.getAge(); @@ -288,8 +289,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testIncludeMechanism() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/usesInclude.xml"); + ClassPathXmlApplicationContext bf = newContext("usesInclude.xml"); ITestBean adrian = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian)); @@ -310,8 +310,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testForceProxyTargetClass() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspectsWithCGLIB.xml"); + ClassPathXmlApplicationContext bf = newContext("aspectsWithCGLIB.xml"); ProxyConfig pc = (ProxyConfig) bf.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); assertTrue("should be proxying classes", pc.isProxyTargetClass()); @@ -319,8 +318,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testWithAbstractFactoryBeanAreApplied() { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/aspectsWithAbstractBean.xml"); + ClassPathXmlApplicationContext bf = newContext("aspectsWithAbstractBean.xml"); ITestBean adrian = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian)); @@ -329,8 +327,7 @@ public class AspectJAutoProxyCreatorTests { @Test public void testRetryAspect() throws Exception { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext( - "/org/springframework/aop/aspectj/autoproxy/retryAspect.xml"); + ClassPathXmlApplicationContext bf = newContext("retryAspect.xml"); UnreliableBean bean = (UnreliableBean) bf.getBean("unreliableBean"); RetryAspect aspect = (RetryAspect) bf.getBean("retryAspect"); int attempts = bean.unreliable(); @@ -340,6 +337,22 @@ public class AspectJAutoProxyCreatorTests { assertEquals(1, aspect.getCommitCalls()); } + /** + * Returns a new {@link ClassPathXmlApplicationContext} for the file ending in fileSuffix. + */ + private ClassPathXmlApplicationContext newContext(String fileSuffix) { + return new ClassPathXmlApplicationContext(qName(fileSuffix), getClass()); + } + + /** + * Returns the relatively qualified name for fileSuffix. + * e.g. for a fileSuffix='foo.xml', this method will return + * 'AspectJAutoProxyCreatorTests-foo.xml' + */ + private String qName(String fileSuffix) { + return format("%s-%s", getClass().getSimpleName(), fileSuffix); + } + } @@ -369,3 +382,203 @@ class PerTargetAspect implements Ordered { } } +@Aspect +class AdviceUsingThisJoinPoint { + + private String lastEntry = ""; + + public String getLastMethodEntered() { + return this.lastEntry; + } + + @Pointcut("execution(* *(..))") + public void methodExecution() {} + + @Before("methodExecution()") + public void entryTrace(JoinPoint jp) { + this.lastEntry = jp.toString(); + } + +} + + +@Aspect +class DummyAspect { + + @Around("execution(* setAge(int))") + public Object test(ProceedingJoinPoint pjp) throws Throwable { + return pjp.proceed(); + } + +} + + +@Aspect +class DummyAspectWithParameter { + + @Around("execution(* setAge(int)) && args(age)") + public Object test(ProceedingJoinPoint pjp, int age) throws Throwable { + return pjp.proceed(); + } + +} + + +class DummyFactoryBean implements FactoryBean { + + public Object getObject() throws Exception { + throw new UnsupportedOperationException(); + } + + public Class getObjectType() { + throw new UnsupportedOperationException(); + } + + public boolean isSingleton() { + throw new UnsupportedOperationException(); + } + +} + + +@Aspect +@Order(10) +class IncreaseReturnValue { + + @Around("execution(int *.getAge())") + public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable { + int result = (Integer) pjp.proceed(); + return result + 3; + } + +} + + +@Aspect +class MultiplyReturnValue { + + private int multiple = 2; + + public int invocations; + + public void setMultiple(int multiple) { + this.multiple = multiple; + } + + public int getMultiple() { + return this.multiple; + } + + @Around("execution(int *.getAge())") + public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable { + ++this.invocations; + int result = (Integer) pjp.proceed(); + return result * this.multiple; + } + +} + + +@Aspect +class RetryAspect { + + private int beginCalls; + + private int commitCalls; + + private int rollbackCalls; + + + @Pointcut("execution(public * UnreliableBean.*(..))") + public void execOfPublicMethod() { + } + + /** + * Retry Advice + */ + @Around("execOfPublicMethod()") + public Object retry(ProceedingJoinPoint jp) throws Throwable { + boolean retry = true; + Object o = null; + while (retry) { + try { + retry = false; + this.beginCalls++; + try { + o = jp.proceed(); + this.commitCalls++; + } + catch (RetryableException e) { + this.rollbackCalls++; + throw e; + } + } + catch (RetryableException re) { + retry = true; + } + } + return o; + } + + + public int getBeginCalls() { + return this.beginCalls; + } + + public int getCommitCalls() { + return this.commitCalls; + } + + public int getRollbackCalls() { + return this.rollbackCalls; + } + +} + + +@SuppressWarnings("serial") +class RetryableException extends NestedRuntimeException { + + public RetryableException(String msg) { + super(msg); + } + + public RetryableException(String msg, Throwable cause) { + super(msg, cause); + } +} + + +class UnreliableBean { + + private int calls; + + public int unreliable() { + this.calls++; + if (this.calls % 2 != 0) { + throw new RetryableException("foo"); + } + return this.calls; + } + +} + + +@SuppressWarnings("serial") +class TestBeanAdvisor extends StaticMethodMatcherPointcutAdvisor { + + public int count; + + public TestBeanAdvisor() { + setAdvice(new MethodBeforeAdvice() { + public void before(Method method, Object[] args, Object target) throws Throwable { + ++count; + } + }); + } + + public boolean matches(Method method, Class targetClass) { + return ITestBean.class.isAssignableFrom(targetClass); + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/afterThrowingAdviceTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAfterThrowingTests-context.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/afterThrowingAdviceTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAfterThrowingTests-context.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAfterThrowingTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAfterThrowingTests.java index db47f73fc4f..0c6b68d805f 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAfterThrowingTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAfterThrowingTests.java @@ -18,6 +18,8 @@ package org.springframework.aop.aspectj.autoproxy; import static org.junit.Assert.*; +import org.aspectj.lang.annotation.AfterThrowing; +import org.aspectj.lang.annotation.Aspect; import org.junit.Test; import org.springframework.beans.ITestBean; import org.springframework.aop.support.AopUtils; @@ -27,16 +29,18 @@ import java.io.IOException; /** * @author Rob Harrop + * @author Chris Beams * @since 2.0 */ -public class AtAspectJAfterThrowingTests { +public final class AtAspectJAfterThrowingTests { @Test public void testAccessThrowable() throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("afterThrowingAdviceTests.xml", getClass()); + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); - ITestBean bean = (ITestBean) context.getBean("testBean"); - ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) context.getBean("aspect"); + ITestBean bean = (ITestBean) ctx.getBean("testBean"); + ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) ctx.getBean("aspect"); assertTrue(AopUtils.isAopProxy(bean)); try { @@ -50,3 +54,19 @@ public class AtAspectJAfterThrowingTests { assertNotNull(aspect.lastException); } } + + +@Aspect +class ExceptionHandlingAspect { + + public int handled; + + public IOException lastException; + + @AfterThrowing(pointcut = "within(org.springframework.beans.ITestBean+)", throwing = "ex") + public void handleIOException(IOException ex) { + handled++; + lastException = ex; + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTestAspect.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTestAspect.java deleted file mode 100644 index 4cbafcc52ad..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTestAspect.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; - -/** - * @author Adrian Colyer - * @author Juergen Hoeller - */ -@Aspect -public class AtAspectJAnnotationBindingTestAspect { - - @Around("execution(* *(..)) && @annotation(testAnn)") - public Object doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnn) - throws Throwable { - String annValue = testAnn.value(); - Object result = pjp.proceed(); - return (result instanceof String ? annValue + " " + result : result); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ataspectj-around-advice-tests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests-context.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ataspectj-around-advice-tests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests-context.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java index aa5a08e1b78..29867330f83 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java @@ -16,39 +16,84 @@ package org.springframework.aop.aspectj.autoproxy; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import static org.junit.Assert.assertEquals; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.core.io.Resource; + /** * @author Adrian Colyer * @author Juergen Hoeller + * @author Chris Beams */ -public class AtAspectJAnnotationBindingTests extends AbstractDependencyInjectionSpringContextTests { +public final class AtAspectJAnnotationBindingTests { private AnnotatedTestBean testBean; + private ClassPathXmlApplicationContext ctx; - public void setTestBean(AnnotatedTestBean testBean) { - this.testBean = testBean; - } - - @Override - protected String getConfigPath() { - return "ataspectj-around-advice-tests.xml"; + @Before + public void setUp() { + ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + testBean = (AnnotatedTestBean) ctx.getBean("testBean"); } + @Test public void testAnnotationBindingInAroundAdvice() { assertEquals("this value doThis", testBean.doThis()); assertEquals("that value doThat", testBean.doThat()); assertEquals(2, testBean.doArray().length); } + @Test public void testNoMatchingWithoutAnnotationPresent() { assertEquals("doTheOther", testBean.doTheOther()); } + @Test public void testPointcutEvaulatedAgainstArray() { - applicationContext.getBean("arrayFactoryBean"); + ctx.getBean("arrayFactoryBean"); } } + + +@Aspect +class AtAspectJAnnotationBindingTestAspect { + + @Around("execution(* *(..)) && @annotation(testAnn)") + public Object doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnn) + throws Throwable { + String annValue = testAnn.value(); + Object result = pjp.proceed(); + return (result instanceof String ? annValue + " " + result : result); + } + +} + + +class ResourceArrayFactoryBean implements FactoryBean { + + @TestAnnotation("some value") + public Object getObject() throws Exception { + return new Resource[0]; + } + + @TestAnnotation("some value") + public Class getObjectType() { + return Resource[].class; + } + + public boolean isSingleton() { + return true; + } + +} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyAspect.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyAspect.java deleted file mode 100644 index eb771d91cea..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyAspect.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; - -/** - * @author Juergen Hoeller - */ -@Aspect -public class DummyAspect { - - @Around("execution(* setAge(int))") - public Object test(ProceedingJoinPoint pjp) throws Throwable { - return pjp.proceed(); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyAspectWithParameter.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyAspectWithParameter.java deleted file mode 100644 index cb081575394..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyAspectWithParameter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; - -/** - * @author Juergen Hoeller - */ -@Aspect -public class DummyAspectWithParameter { - - @Around("execution(* setAge(int)) && args(age)") - public Object test(ProceedingJoinPoint pjp, int age) throws Throwable { - return pjp.proceed(); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyFactoryBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyFactoryBean.java deleted file mode 100644 index 41b452d770f..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/DummyFactoryBean.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.springframework.beans.factory.FactoryBean; - -/** - * @author Rob Harrop - */ -public class DummyFactoryBean implements FactoryBean { - - public Object getObject() throws Exception { - throw new UnsupportedOperationException(); - } - - public Class getObjectType() { - throw new UnsupportedOperationException(); - } - - public boolean isSingleton() { - throw new UnsupportedOperationException(); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ExceptionHandlingAspect.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ExceptionHandlingAspect.java deleted file mode 100644 index bcc52144403..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ExceptionHandlingAspect.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.annotation.AfterThrowing; -import org.aspectj.lang.annotation.Aspect; - -import java.io.IOException; - -/** - * @author Rob Harrop - * @since 2.0 - */ -@Aspect -public class ExceptionHandlingAspect { - - public int handled; - - public IOException lastException; - - @AfterThrowing(pointcut = "within(org.springframework.beans.ITestBean+)", throwing = "ex") - public void handleIOException(IOException ex) { - handled++; - lastException = ex; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/IncreaseReturnValue.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/IncreaseReturnValue.java deleted file mode 100644 index 79f44dd42ff..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/IncreaseReturnValue.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; - -import org.springframework.core.annotation.Order; - -/** - * @author Juergen Hoeller - */ -@Aspect -@Order(10) -public class IncreaseReturnValue { - - @Around("execution(int *.getAge())") - public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable { - int result = (Integer) pjp.proceed(); - return result + 3; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/LazyTestBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/LazyTestBean.java deleted file mode 100644 index cc4c891f439..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/LazyTestBean.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.springframework.beans.TestBean; - -/** - * @author Rod Johnson - * @since 2.0 - */ -public class LazyTestBean extends TestBean { - - public static int instantiations; - - /** - * - */ - public LazyTestBean() { - ++instantiations; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java deleted file mode 100644 index 9d940e7ac66..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; - -/** - * @author Rod Johnson - */ -@Aspect -public class MultiplyReturnValue { - - private int multiple = 2; - - public int invocations; - - public void setMultiple(int multiple) { - this.multiple = multiple; - } - - public int getMultiple() { - return this.multiple; - } - - @Around("execution(int *.getAge())") - public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable { - ++this.invocations; - int result = (Integer) pjp.proceed(); - return result * this.multiple; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ResourceArrayFactoryBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ResourceArrayFactoryBean.java deleted file mode 100644 index 61edc6c2107..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/ResourceArrayFactoryBean.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.springframework.beans.factory.FactoryBean; -import org.springframework.core.io.Resource; - -/** - * @author Juergen Hoeller - */ -public class ResourceArrayFactoryBean implements FactoryBean { - - @TestAnnotation("some value") - public Object getObject() throws Exception { - return new Resource[0]; - } - - @TestAnnotation("some value") - public Class getObjectType() { - return Resource[].class; - } - - public boolean isSingleton() { - return true; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/RetryAspect.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/RetryAspect.java deleted file mode 100644 index 67fd0b7dbb5..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/RetryAspect.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; - -/** - * @author Rob Harrop - * @author Juergen Hoeller - */ -@Aspect -public class RetryAspect { - - private int beginCalls; - - private int commitCalls; - - private int rollbackCalls; - - - @Pointcut("execution(public * UnreliableBean.*(..))") - public void execOfPublicMethod() { - } - - /** - * Retry Advice - */ - @Around("execOfPublicMethod()") - public Object retry(ProceedingJoinPoint jp) throws Throwable { - boolean retry = true; - Object o = null; - while (retry) { - try { - retry = false; - this.beginCalls++; - try { - o = jp.proceed(); - this.commitCalls++; - } - catch (RetryableException e) { - this.rollbackCalls++; - throw e; - } - } - catch (RetryableException re) { - retry = true; - } - } - return o; - } - - - public int getBeginCalls() { - return this.beginCalls; - } - - public int getCommitCalls() { - return this.commitCalls; - } - - public int getRollbackCalls() { - return this.rollbackCalls; - } - -} - diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/RetryableException.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/RetryableException.java deleted file mode 100644 index 0f66d295d33..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/RetryableException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import org.springframework.core.NestedRuntimeException; - -/** - * @author Rob Harrop - * @since 2.0 - */ -public class RetryableException extends NestedRuntimeException { - - public RetryableException(String msg) { - super(msg); - } - - public RetryableException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/TestAnnotation.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/TestAnnotation.java deleted file mode 100644 index edc2dc690f8..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/TestAnnotation.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Created on 6 Oct 2006 by Adrian Colyer - */ -package org.springframework.aop.aspectj.autoproxy; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * @author Adrian Colyer - * @since 2.0 - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface TestAnnotation { - String value() ; -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/TestBeanAdvisor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/TestBeanAdvisor.java deleted file mode 100644 index d1668590ebc..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/TestBeanAdvisor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -import java.lang.reflect.Method; - -import org.springframework.aop.MethodBeforeAdvice; -import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; -import org.springframework.beans.ITestBean; - -public class TestBeanAdvisor extends StaticMethodMatcherPointcutAdvisor { - - public int count; - - public TestBeanAdvisor() { - setAdvice(new MethodBeforeAdvice() { - public void before(Method method, Object[] args, Object target) throws Throwable { - ++count; - } - }); - } - - public boolean matches(Method method, Class targetClass) { - return ITestBean.class.isAssignableFrom(targetClass); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/UnreliableBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/UnreliableBean.java deleted file mode 100644 index 4d694c225f3..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/UnreliableBean.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy; - -/** - * @author Rob Harrop - */ -public class UnreliableBean { - - private int calls; - - public int unreliable() { - this.calls++; - if (this.calls % 2 != 0) { - throw new RetryableException("foo"); - } - return this.calls; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/aspectj.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests-aspectj.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/aspectj.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests-aspectj.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/springAop.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests-springAop.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/springAop.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests-springAop.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests.java index 9895e299195..5051cac166e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/BenchmarkTests.java @@ -18,9 +18,21 @@ package org.springframework.aop.aspectj.autoproxy.benchmark; import static org.junit.Assert.*; +import java.lang.reflect.Method; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; import org.junit.Test; +import org.springframework.aop.Advisor; +import org.springframework.aop.AfterReturningAdvice; +import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.framework.Advised; import org.springframework.aop.support.AopUtils; +import org.springframework.aop.support.DefaultPointcutAdvisor; +import org.springframework.aop.support.StaticMethodMatcherPointcut; import org.springframework.beans.ITestBean; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.util.StopWatch; @@ -32,19 +44,14 @@ import org.springframework.util.StopWatch; * @author Rod Johnson * @author Chris Beams */ -public class BenchmarkTests { - - private static final String ASPECTJ_CONTEXT = "/org/springframework/aop/aspectj/autoproxy/benchmark/aspectj.xml"; - - private static final String SPRING_AOP_CONTEXT = "/org/springframework/aop/aspectj/autoproxy/benchmark/springAop.xml"; - - /** - * Change the return number to a higher number to make this test useful. - */ - protected int getCount() { - return 10; - } +public final class BenchmarkTests { + private static final Class CLASS = BenchmarkTests.class; + + private static final String ASPECTJ_CONTEXT = CLASS.getSimpleName() + "-aspectj.xml"; + + private static final String SPRING_AOP_CONTEXT = CLASS.getSimpleName() + "-springAop.xml"; + @Test public void testRepeatedAroundAdviceInvocationsWithAspectJ() { testRepeatedAroundAdviceInvocations(ASPECTJ_CONTEXT, getCount(), "AspectJ"); @@ -84,9 +91,16 @@ public class BenchmarkTests { public void testRepeatedMixWithSpringAop() { testMix(SPRING_AOP_CONTEXT, getCount(), "Spring AOP"); } + + /** + * Change the return number to a higher number to make this test useful. + */ + protected int getCount() { + return 10; + } private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file); + ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated around advice invocations with " + technology); @@ -105,7 +119,7 @@ public class BenchmarkTests { } private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file); + ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated before advice invocations with " + technology); @@ -126,7 +140,7 @@ public class BenchmarkTests { } private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file); + ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated after returning advice invocations with " + technology); @@ -148,7 +162,7 @@ public class BenchmarkTests { } private long testMix(String file, int howmany, String technology) { - ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file); + ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS); StopWatch sw = new StopWatch(); sw.start(howmany + " repeated mixed invocations with " + technology); @@ -176,3 +190,89 @@ public class BenchmarkTests { } } + + +class MultiplyReturnValueInterceptor implements MethodInterceptor { + + private int multiple = 2; + + public int invocations; + + public void setMultiple(int multiple) { + this.multiple = multiple; + } + + public int getMultiple() { + return this.multiple; + } + + public Object invoke(MethodInvocation mi) throws Throwable { + ++invocations; + int result = (Integer) mi.proceed(); + return result * this.multiple; + } + +} + + +class TraceAfterReturningAdvice implements AfterReturningAdvice { + + public int afterTakesInt; + + public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { + ++afterTakesInt; + } + + public static Advisor advisor() { + return new DefaultPointcutAdvisor( + new StaticMethodMatcherPointcut() { + public boolean matches(Method method, Class targetClass) { + return method.getParameterTypes().length == 1 && + method.getParameterTypes()[0].equals(Integer.class); + } + }, + new TraceAfterReturningAdvice()); + } + +} + + +@Aspect +class TraceAspect { + + public int beforeStringReturn; + + public int afterTakesInt; + + @Before("execution(String *.*(..))") + public void traceWithoutJoinPoint() { + ++beforeStringReturn; + } + + @AfterReturning("execution(void *.*(int))") + public void traceWithoutJoinPoint2() { + ++afterTakesInt; + } + +} + + +class TraceBeforeAdvice implements MethodBeforeAdvice { + + public int beforeStringReturn; + + public void before(Method method, Object[] args, Object target) throws Throwable { + ++beforeStringReturn; + } + + public static Advisor advisor() { + return new DefaultPointcutAdvisor( + new StaticMethodMatcherPointcut() { + public boolean matches(Method method, Class targetClass) { + return method.getReturnType().equals(String.class); + } + }, + new TraceBeforeAdvice()); + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/MultiplyReturnValueInterceptor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/MultiplyReturnValueInterceptor.java deleted file mode 100644 index ce806da1c28..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/MultiplyReturnValueInterceptor.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy.benchmark; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; - -public class MultiplyReturnValueInterceptor implements MethodInterceptor { - - private int multiple = 2; - - public int invocations; - - public void setMultiple(int multiple) { - this.multiple = multiple; - } - - public int getMultiple() { - return this.multiple; - } - - public Object invoke(MethodInvocation mi) throws Throwable { - ++invocations; - int result = (Integer) mi.proceed(); - return result * this.multiple; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceAfterReturningAdvice.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceAfterReturningAdvice.java deleted file mode 100644 index 454aba80c46..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceAfterReturningAdvice.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy.benchmark; - -import java.lang.reflect.Method; - -import org.springframework.aop.Advisor; -import org.springframework.aop.AfterReturningAdvice; -import org.springframework.aop.support.DefaultPointcutAdvisor; -import org.springframework.aop.support.StaticMethodMatcherPointcut; - -/** - * - * - * @author Rod Johnson - * - */ -public class TraceAfterReturningAdvice implements AfterReturningAdvice { - - public int afterTakesInt; - - public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { - ++afterTakesInt; - } - - public static Advisor advisor() { - return new DefaultPointcutAdvisor( - new StaticMethodMatcherPointcut() { - public boolean matches(Method method, Class targetClass) { - return method.getParameterTypes().length == 1 && - method.getParameterTypes()[0].equals(Integer.class); - } - }, - new TraceAfterReturningAdvice()); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceAspect.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceAspect.java deleted file mode 100644 index 4a7fce1abb0..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceAspect.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy.benchmark; - -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; - -@Aspect -public class TraceAspect { - - public int beforeStringReturn; - - public int afterTakesInt; - - @Before("execution(String *.*(..))") - public void traceWithoutJoinPoint() { - ++beforeStringReturn; - } - - @AfterReturning("execution(void *.*(int))") - public void traceWithoutJoinPoint2() { - ++afterTakesInt; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceBeforeAdvice.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceBeforeAdvice.java deleted file mode 100644 index e331bdfcf74..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/TraceBeforeAdvice.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2006 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.aspectj.autoproxy.benchmark; - -import java.lang.reflect.Method; - -import org.springframework.aop.Advisor; -import org.springframework.aop.MethodBeforeAdvice; -import org.springframework.aop.support.DefaultPointcutAdvisor; -import org.springframework.aop.support.StaticMethodMatcherPointcut; - -public class TraceBeforeAdvice implements MethodBeforeAdvice { - - public int beforeStringReturn; - - public void before(Method method, Object[] args, Object target) throws Throwable { - ++beforeStringReturn; - } - - public static Advisor advisor() { - return new DefaultPointcutAdvisor( - new StaticMethodMatcherPointcut() { - public boolean matches(Method method, Class targetClass) { - return method.getReturnType().equals(String.class); - } - }, - new TraceBeforeAdvice()); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/SPR3064Tests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/SPR3064Tests.java index 7044b80b8cd..e2e6b5270ff 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/SPR3064Tests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/SPR3064Tests.java @@ -15,26 +15,33 @@ */ package org.springframework.aop.aspectj.autoproxy.spr3064; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import static org.junit.Assert.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; + /** - * @author acolyer - * + * @author Adrian Colyer + * @author Chris Beams */ -public class SPR3064Tests extends AbstractDependencyInjectionSpringContextTests { +public final class SPR3064Tests { private Service service; - @Override - protected String[] getConfigLocations() { - return new String[] {"org/springframework/aop/aspectj/autoproxy/spr3064/annotationbinding-spr3064.xml"}; - } - - public void setService(Service service) { - this.service = service; - } - + @Test public void testServiceIsAdvised() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + + service = (Service) ctx.getBean("service"); + try { this.service.serveMe(); fail("service operation has not been advised by transaction interceptor"); @@ -45,3 +52,37 @@ public class SPR3064Tests extends AbstractDependencyInjectionSpringContextTests } } + + +@Retention(RetentionPolicy.RUNTIME) +@interface Transaction { + +} + + +@Aspect +class TransactionInterceptor { + + @Around(value="execution(* *..Service.*(..)) && @annotation(transaction)") + public Object around(ProceedingJoinPoint pjp, Transaction transaction) throws Throwable { + throw new RuntimeException("advice invoked"); + //return pjp.proceed(); + } + +} + + +interface Service { + + void serveMe(); + +} + + +class ServiceImpl implements Service { + + @Transaction + public void serveMe() { + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/annotationbinding-spr3064.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/SPR3064Tests.xml similarity index 85% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/annotationbinding-spr3064.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/SPR3064Tests.xml index 567b2f1ae67..f70a7a15c06 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/annotationbinding-spr3064.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/SPR3064Tests.xml @@ -7,7 +7,7 @@ - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/Service.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/Service.java deleted file mode 100644 index deff9f8496a..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/Service.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.aop.aspectj.autoproxy.spr3064; - -/** - * @author acolyer - * - */ -public interface Service { - - void serveMe(); - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/ServiceImpl.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/ServiceImpl.java deleted file mode 100644 index 0904f512da2..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/ServiceImpl.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.aop.aspectj.autoproxy.spr3064; - -/** - * @author acolyer - * - */ -public class ServiceImpl implements Service { - - /* (non-Javadoc) - * @see org.springframework.aop.aspectj.autoproxy.spr3064.Service#serveMe() - */ - @Transaction - public void serveMe() { - - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/Transaction.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/Transaction.java deleted file mode 100644 index 5e8c381bd82..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/Transaction.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.aop.aspectj.autoproxy.spr3064; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * @author acolyer - * - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface Transaction { - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/TransactionInterceptor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/TransactionInterceptor.java deleted file mode 100644 index 568c11d7c01..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/TransactionInterceptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.aop.aspectj.autoproxy.spr3064; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; - -/** - * @author acolyer - * - */ -@Aspect -public class TransactionInterceptor { - - @Around(value="execution(* *..Service.*(..)) && @annotation(transaction)") - public Object around(ProceedingJoinPoint pjp, Transaction transaction) throws Throwable { - throw new RuntimeException("advice invoked"); - //return pjp.proceed(); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/afterReturningGenericTypeMatchingTests-context.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests-context.xml similarity index 81% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/afterReturningGenericTypeMatchingTests-context.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests-context.xml index 4edba5d74e4..3b53bf50649 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/afterReturningGenericTypeMatchingTests-context.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests-context.xml @@ -7,8 +7,8 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java index ce25d83b47b..3f00658151e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java @@ -16,16 +16,19 @@ package org.springframework.aop.aspectj.generic; +import static org.junit.Assert.*; + import java.util.ArrayList; import java.util.Collection; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; - +import org.junit.Before; +import org.junit.Test; import org.springframework.beans.Employee; import org.springframework.beans.TestBean; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Tests ensuring that after-returning advice for generic parameters bound to @@ -34,29 +37,27 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests; *

See SPR-3628 for more details. * * @author Ramnivas Laddad + * @author Chris Beams */ -public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyInjectionSpringContextTests { +public final class AfterReturningGenericTypeMatchingTests { - protected GenericReturnTypeVariationClass testBean; + private GenericReturnTypeVariationClass testBean; - protected CounterAspect counterAspect; + private CounterAspect counterAspect; - public AfterReturningGenericTypeMatchingTests() { - setPopulateProtectedVariables(true); - } - - @Override - protected String getConfigPath() { - return "afterReturningGenericTypeMatchingTests-context.xml"; - } - - @Override - protected void onSetUp() throws Exception { + @Before + public void setUp() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + + counterAspect = (CounterAspect) ctx.getBean("counterAspect"); counterAspect.reset(); - super.onSetUp(); + + testBean = (GenericReturnTypeVariationClass) ctx.getBean("testBean"); } + @Test public void testReturnTypeExactMatching() { testBean.getStrings(); assertEquals(1, counterAspect.getStringsInvocationsCount); @@ -69,6 +70,7 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn assertEquals(1, counterAspect.getIntegersInvocationsCount); } + @Test public void testReturnTypeRawMatching() { testBean.getStrings(); assertEquals(1, counterAspect.getRawsInvocationsCount); @@ -79,11 +81,13 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn assertEquals(1, counterAspect.getRawsInvocationsCount); } + @Test public void testReturnTypeUpperBoundMatching() { testBean.getIntegers(); assertEquals(1, counterAspect.getNumbersInvocationsCount); } + @Test public void testReturnTypeLowerBoundMatching() { testBean.getTestBeans(); assertEquals(1, counterAspect.getTestBeanInvocationsCount); @@ -94,76 +98,77 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn assertEquals(0, counterAspect.getTestBeanInvocationsCount); } - - public static class GenericReturnTypeVariationClass { - - public Collection getStrings() { - return new ArrayList(); - } - - public Collection getIntegers() { - return new ArrayList(); - } - - public Collection getTestBeans() { - return new ArrayList(); - } - - public Collection getEmployees() { - return new ArrayList(); - } - } - - - @Aspect - public static class CounterAspect { - - private int getRawsInvocationsCount; - - private int getStringsInvocationsCount; - - private int getIntegersInvocationsCount; - - private int getNumbersInvocationsCount; - - private int getTestBeanInvocationsCount; - - @Pointcut("execution(* org.springframework.aop.aspectj.generic.AfterReturningGenericTypeMatchingTests.GenericReturnTypeVariationClass.*(..))") - public void anyTestMethod() { - } - - @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") - public void incrementGetRawsInvocationsCount(Collection ret) { - getRawsInvocationsCount++; - } - - @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") - public void incrementGetStringsInvocationsCount(Collection ret) { - getStringsInvocationsCount++; - } - - @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") - public void incrementGetIntegersInvocationsCount(Collection ret) { - getIntegersInvocationsCount++; - } - - @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") - public void incrementGetNumbersInvocationsCount(Collection ret) { - getNumbersInvocationsCount++; - } - - @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") - public void incrementTestBeanInvocationsCount(Collection ret) { - getTestBeanInvocationsCount++; - } - - public void reset() { - getRawsInvocationsCount = 0; - getStringsInvocationsCount = 0; - getIntegersInvocationsCount = 0; - getNumbersInvocationsCount = 0; - getTestBeanInvocationsCount = 0; - } - } - } + + +class GenericReturnTypeVariationClass { + + public Collection getStrings() { + return new ArrayList(); + } + + public Collection getIntegers() { + return new ArrayList(); + } + + public Collection getTestBeans() { + return new ArrayList(); + } + + public Collection getEmployees() { + return new ArrayList(); + } +} + + +@Aspect +class CounterAspect { + + int getRawsInvocationsCount; + + int getStringsInvocationsCount; + + int getIntegersInvocationsCount; + + int getNumbersInvocationsCount; + + int getTestBeanInvocationsCount; + + @Pointcut("execution(* org.springframework.aop.aspectj.generic.GenericReturnTypeVariationClass.*(..))") + public void anyTestMethod() { + } + + @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") + public void incrementGetRawsInvocationsCount(Collection ret) { + getRawsInvocationsCount++; + } + + @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") + public void incrementGetStringsInvocationsCount(Collection ret) { + getStringsInvocationsCount++; + } + + @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") + public void incrementGetIntegersInvocationsCount(Collection ret) { + getIntegersInvocationsCount++; + } + + @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") + public void incrementGetNumbersInvocationsCount(Collection ret) { + getNumbersInvocationsCount++; + } + + @AfterReturning(pointcut = "anyTestMethod()", returning = "ret") + public void incrementTestBeanInvocationsCount(Collection ret) { + getTestBeanInvocationsCount++; + } + + public void reset() { + getRawsInvocationsCount = 0; + getStringsInvocationsCount = 0; + getIntegersInvocationsCount = 0; + getNumbersInvocationsCount = 0; + getTestBeanInvocationsCount = 0; + } +} + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-classProxy-context.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests-context.xml similarity index 83% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-classProxy-context.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests-context.xml index e43671351fc..8e662cc3331 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-classProxy-context.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests-context.xml @@ -7,8 +7,8 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests.java index 75442968d91..f1338831dd4 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests.java @@ -16,6 +16,10 @@ package org.springframework.aop.aspectj.generic; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + /** * Tests for AspectJ pointcut expression matching when working with bridge methods. * @@ -24,19 +28,17 @@ package org.springframework.aop.aspectj.generic; *

See GenericBridgeMethodMatchingTests for more details. * * @author Ramnivas Laddad + * @author Chris Beams */ -public class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests { - - @Override - protected String getConfigPath() { - return "genericBridgeMethodMatchingTests-classProxy-context.xml"; - } +public final class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests { + @Test public void testGenericDerivedInterfaceMethodThroughClass() { ((DerivedStringParameterizedClass) testBean).genericDerivedInterfaceMethod(""); assertEquals(1, counterAspect.count); } + @Test public void testGenericBaseInterfaceMethodThroughClass() { ((DerivedStringParameterizedClass) testBean).genericBaseInterfaceMethod(""); assertEquals(1, counterAspect.count); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-context.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests-context.xml similarity index 83% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-context.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests-context.xml index 9b65f285833..6297095d17d 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-context.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests-context.xml @@ -7,8 +7,8 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java index ff5423f2b3d..ce7790ab768 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java @@ -16,9 +16,12 @@ package org.springframework.aop.aspectj.generic; +import static org.junit.Assert.*; + import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Tests for AspectJ pointcut expression matching when working with bridge methods. @@ -33,71 +36,73 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests; * See SPR-3556 for more details. * * @author Ramnivas Laddad + * @author Chris Beams */ -public class GenericBridgeMethodMatchingTests extends AbstractDependencyInjectionSpringContextTests { +public class GenericBridgeMethodMatchingTests { protected DerivedInterface testBean; - protected CounterAspect counterAspect; + protected GenericCounterAspect counterAspect; - public GenericBridgeMethodMatchingTests() { - setPopulateProtectedVariables(true); - } - - @Override - protected String getConfigPath() { - return "genericBridgeMethodMatchingTests-context.xml"; - } - - @Override - protected void onSetUp() throws Exception { + @SuppressWarnings("unchecked") + @org.junit.Before + public void setUp() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + + counterAspect = (GenericCounterAspect) ctx.getBean("counterAspect"); counterAspect.count = 0; - super.onSetUp(); + + testBean = (DerivedInterface) ctx.getBean("testBean"); } + + @Test public void testGenericDerivedInterfaceMethodThroughInterface() { testBean.genericDerivedInterfaceMethod(""); assertEquals(1, counterAspect.count); } + @Test public void testGenericBaseInterfaceMethodThroughInterface() { testBean.genericBaseInterfaceMethod(""); assertEquals(1, counterAspect.count); } +} - public interface BaseInterface { - void genericBaseInterfaceMethod(T t); +interface BaseInterface { + + void genericBaseInterfaceMethod(T t); +} + + +interface DerivedInterface extends BaseInterface { + + public void genericDerivedInterfaceMethod(T t); +} + + +class DerivedStringParameterizedClass implements DerivedInterface { + + public void genericDerivedInterfaceMethod(String t) { } - - public interface DerivedInterface extends BaseInterface { - - public void genericDerivedInterfaceMethod(T t); + public void genericBaseInterfaceMethod(String t) { } +} +@Aspect +class GenericCounterAspect { - public static class DerivedStringParameterizedClass implements DerivedInterface { - - public void genericDerivedInterfaceMethod(String t) { - } - - public void genericBaseInterfaceMethod(String t) { - } - } - - @Aspect - public static class CounterAspect { - - public int count; - - @Before("execution(* *..BaseInterface+.*(..))") - public void increment() { - count++; - } + public int count; + @Before("execution(* *..BaseInterface+.*(..))") + public void increment() { + count++; } } + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericParameterMatchingTests-context.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests-context.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/genericParameterMatchingTests-context.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests-context.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java index 6fb313bcaf1..011095b95db 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java @@ -16,54 +16,56 @@ package org.springframework.aop.aspectj.generic; +import static org.junit.Assert.assertEquals; + import java.util.Collection; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; - -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Tests that poitncut matching is correct with generic method parameter. * See SPR-3904 for more details. * * @author Ramnivas Laddad + * @author Chris Beams */ -public class GenericParameterMatchingTests extends AbstractDependencyInjectionSpringContextTests { +public final class GenericParameterMatchingTests { - protected CounterAspect counterAspect; + private CounterAspect counterAspect; - protected GenericInterface testBean; + private GenericInterface testBean; - public GenericParameterMatchingTests() { - setPopulateProtectedVariables(true); - } - - @Override - protected String getConfigPath() { - return "genericParameterMatchingTests-context.xml"; - } - - @Override - protected void onSetUp() throws Exception { + @SuppressWarnings("unchecked") + @org.junit.Before + public void setUp() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + + counterAspect = (CounterAspect) ctx.getBean("counterAspect"); counterAspect.reset(); - super.onSetUp(); + + testBean = (GenericInterface) ctx.getBean("testBean"); } - + + @Test public void testGenericInterfaceGenericArgExecution() { testBean.save(""); assertEquals(1, counterAspect.genericInterfaceGenericArgExecutionCount); } + @Test public void testGenericInterfaceGenericCollectionArgExecution() { testBean.saveAll(null); - // TODO: uncomment once we officially update to AspectJ 1.6.0 - //assertEquals(1, counterAspect.genericInterfaceGenericCollectionArgExecutionCount); + assertEquals(1, counterAspect.genericInterfaceGenericCollectionArgExecutionCount); } + @Test public void testGenericInterfaceSubtypeGenericCollectionArgExecution() { testBean.saveAll(null); assertEquals(1, counterAspect.genericInterfaceSubtypeGenericCollectionArgExecutionCount); @@ -89,7 +91,7 @@ public class GenericParameterMatchingTests extends AbstractDependencyInjectionSp @Aspect - public static class CounterAspect { + static class CounterAspect { int genericInterfaceGenericArgExecutionCount; int genericInterfaceGenericCollectionArgExecutionCount; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdviceTypeErrorTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests-error.xml similarity index 83% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdviceTypeErrorTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests-error.xml index efdd2acb7c2..1761a3552e4 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdviceTypeErrorTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests-error.xml @@ -15,9 +15,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdviceTypeOKTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests-ok.xml similarity index 86% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdviceTypeOKTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests-ok.xml index 157ffe66781..68681cf9fbd 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdviceTypeOKTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests-ok.xml @@ -16,9 +16,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceAdviceTypeTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests.java similarity index 63% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceAdviceTypeTests.java rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests.java index f71f2dbb81b..01ffc09ec77 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceAdviceTypeTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerAdviceTypeTests.java @@ -19,36 +19,25 @@ package org.springframework.aop.config; import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.beans.ITestBean; import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.xml.sax.SAXParseException; /** * @author Adrian Colyer + * @author Chris Beams */ -public class AopNamespaceAdviceTypeTests { - - private ApplicationContext context; - - protected String getOKConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerAdviceTypeOKTests.xml"; - } - - protected String getErrorConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerAdviceTypeErrorTests.xml"; - } +public final class AopNamespaceHandlerAdviceTypeTests { @Test public void testParsingOfAdviceTypes() { - this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass()); } @Test public void testParsingOfAdviceTypesWithError() { try { - this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass()); fail("Expected BeanDefinitionStoreException"); } catch (BeanDefinitionStoreException ex) { @@ -56,8 +45,4 @@ public class AopNamespaceAdviceTypeTests { } } - protected ITestBean getTestBean() { - return (ITestBean) this.context.getBean("testBean"); - } - } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests-error.xml similarity index 82% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests-error.xml index c156060d093..2a83b2078a5 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests-error.xml @@ -12,9 +12,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesOKTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests-ok.xml similarity index 82% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesOKTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests-ok.xml index 1cafd6663a1..88cad34d9aa 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesOKTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests-ok.xml @@ -12,9 +12,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests.java index f59748bca34..030d2539e2e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerArgNamesTests.java @@ -19,35 +19,24 @@ package org.springframework.aop.config; import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.beans.ITestBean; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author Adrian Colyer + * @author Chris Beams */ -public class AopNamespaceHandlerArgNamesTests { - - private ApplicationContext context; - - protected String getOKConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerArgNamesOKTests.xml"; - } - - protected String getErrorConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml"; - } +public final class AopNamespaceHandlerArgNamesTests { @Test public void testArgNamesOK() { - this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass()); } @Test public void testArgNamesError() { try { - this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass()); fail("Expected BeanCreationException"); } catch (BeanCreationException ex) { @@ -55,8 +44,4 @@ public class AopNamespaceHandlerArgNamesTests { } } - protected ITestBean getTestBean() { - return (ITestBean) this.context.getBean("testBean"); - } - } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerProxyTargetClassTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerProxyTargetClassTests-context.xml similarity index 88% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerProxyTargetClassTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerProxyTargetClassTests-context.xml index 4d0f93b4e70..600de99a9fc 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerProxyTargetClassTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerProxyTargetClassTests-context.xml @@ -19,9 +19,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerProxyTargetClassTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerProxyTargetClassTests.java index d1f90744873..2afa01cc707 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerProxyTargetClassTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerProxyTargetClassTests.java @@ -24,8 +24,9 @@ import org.springframework.beans.ITestBean; /** * @author Rob Harrop + * @author Chris Beams */ -public class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandlerTests { +public final class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandlerTests { @Test public void testIsClassProxy() { @@ -33,8 +34,4 @@ public class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandle assertTrue("Should be a CGLIB proxy", AopUtils.isCglibProxy(bean)); } - protected String getConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerProxyTargetClassTests.xml"; - } - } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerReturningErrorTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests-error.xml similarity index 81% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerReturningErrorTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests-error.xml index 26da583dd3d..1f84e8edac2 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerReturningErrorTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests-error.xml @@ -11,9 +11,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerReturningOKTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests-ok.xml similarity index 81% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerReturningOKTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests-ok.xml index 17f64373dcc..3fe28a8663d 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerReturningOKTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests-ok.xml @@ -11,9 +11,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests.java index e3d05a601a9..3e1d3f0a47f 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerReturningTests.java @@ -19,36 +19,25 @@ package org.springframework.aop.config; import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.beans.ITestBean; import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.xml.sax.SAXParseException; /** * @author Adrian Colyer + * @author Chris Beams */ -public class AopNamespaceHandlerReturningTests { - - private ApplicationContext context; - - protected String getOKConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerReturningOKTests.xml"; - } - - protected String getErrorConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerReturningErrorTests.xml"; - } +public final class AopNamespaceHandlerReturningTests { @Test public void testReturningOnReturningAdvice() { - this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass()); } @Test public void testParseReturningOnOtherAdviceType() { try { - this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass()); fail("Expected BeanDefinitionStoreException"); } catch (BeanDefinitionStoreException ex) { @@ -56,8 +45,4 @@ public class AopNamespaceHandlerReturningTests { } } - protected ITestBean getTestBean() { - return (ITestBean) this.context.getBean("testBean"); - } - } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerScopeTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeTests-context.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerScopeTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeTests-context.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeTests.java index 1d1cc6bb8b3..91c906dcb0a 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeTests.java @@ -34,15 +34,16 @@ import org.springframework.web.context.support.XmlWebApplicationContext; /** * @author Rob Harrop * @author Juergen Hoeller + * @author Chris Beams */ -public class AopNamespaceHandlerScopeTests { +public final class AopNamespaceHandlerScopeTests { private ApplicationContext context; @Before public void setUp() { XmlWebApplicationContext wac = new XmlWebApplicationContext(); - wac.setConfigLocations(new String[] {"classpath:org/springframework/aop/config/aopNamespaceHandlerScopeTests.xml"}); + wac.setConfigLocations(new String[] {"classpath:org/springframework/aop/config/AopNamespaceHandlerScopeTests-context.xml"}); wac.refresh(); this.context = wac; } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerTests-context.xml similarity index 87% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerTests-context.xml index 1ac7a3c38be..90ead2afe56 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerTests-context.xml @@ -19,9 +19,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerTests.java index bc2d07e58c9..4623a8b7dd9 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerTests.java @@ -18,16 +18,18 @@ package org.springframework.aop.config; import static org.junit.Assert.*; +import org.aspectj.lang.ProceedingJoinPoint; import org.junit.Before; import org.junit.Test; import org.springframework.aop.Advisor; import org.springframework.aop.framework.Advised; -import org.springframework.aop.framework.CountingBeforeAdvice; import org.springframework.aop.support.AopUtils; import org.springframework.beans.ITestBean; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import test.advice.CountingBeforeAdvice; + /** * @author Rob Harrop */ @@ -35,13 +37,11 @@ public class AopNamespaceHandlerTests { private ApplicationContext context; + @Before public void setUp() { - this.context = new ClassPathXmlApplicationContext(getConfigLocation()); - } - - protected String getConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerTests.xml"; + this.context = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); } @Test @@ -103,3 +103,51 @@ public class AopNamespaceHandlerTests { } } + + +class CountingAspectJAdvice { + + private int beforeCount; + + private int afterCount; + + private int aroundCount; + + public void myBeforeAdvice() throws Throwable { + this.beforeCount++; + } + + public void myAfterAdvice() throws Throwable { + this.afterCount++; + } + + public void myAroundAdvice(ProceedingJoinPoint pjp) throws Throwable { + this.aroundCount++; + pjp.proceed(); + } + + public void myAfterReturningAdvice(int age) { + this.afterCount++; + } + + public void myAfterThrowingAdvice(RuntimeException ex) { + this.afterCount++; + } + + public void mySetAgeAdvice(int newAge, ITestBean bean) { + // no-op + } + + public int getBeforeCount() { + return this.beforeCount; + } + + public int getAfterCount() { + return this.afterCount; + } + + public int getAroundCount() { + return this.aroundCount; + } +} + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerThrowingErrorTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests-error.xml similarity index 81% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerThrowingErrorTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests-error.xml index 1334e21719b..73ed03922c3 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerThrowingErrorTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests-error.xml @@ -11,9 +11,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerThrowingOKTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests-ok.xml similarity index 81% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerThrowingOKTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests-ok.xml index 86d7624c0a6..85080527360 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/aopNamespaceHandlerThrowingOKTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests-ok.xml @@ -11,9 +11,9 @@ - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests.java index 2786c8ab710..7533dc41966 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/AopNamespaceHandlerThrowingTests.java @@ -19,36 +19,25 @@ package org.springframework.aop.config; import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.beans.ITestBean; import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.xml.sax.SAXParseException; /** * @author Adrian Colyer + * @author Chris Beams */ -public class AopNamespaceHandlerThrowingTests { - - private ApplicationContext context; - - protected String getOKConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerThrowingOKTests.xml"; - } - - protected String getErrorConfigLocation() { - return "org/springframework/aop/config/aopNamespaceHandlerThrowingErrorTests.xml"; - } +public final class AopNamespaceHandlerThrowingTests { @Test public void testThrowingOnThrowingAdvice() { - this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass()); } @Test public void testParseThrowingOnOtherAdviceType() { try { - this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass()); fail("Expected BeanDefinitionStoreException"); } catch (BeanDefinitionStoreException ex) { @@ -56,8 +45,4 @@ public class AopNamespaceHandlerThrowingTests { } } - protected ITestBean getTestBean() { - return (ITestBean) this.context.getBean("testBean"); - } - } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/CountingAspectJAdvice.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/CountingAspectJAdvice.java deleted file mode 100644 index 6251cf40948..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/CountingAspectJAdvice.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.config; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.springframework.beans.ITestBean; - -/** - * @author Rob Harrop - */ -public class CountingAspectJAdvice { - - private int beforeCount; - - private int afterCount; - - private int aroundCount; - - public void myBeforeAdvice() throws Throwable { - this.beforeCount++; - } - - public void myAfterAdvice() throws Throwable { - this.afterCount++; - } - - public void myAroundAdvice(ProceedingJoinPoint pjp) throws Throwable { - this.aroundCount++; - pjp.proceed(); - } - - public void myAfterReturningAdvice(int age) { - this.afterCount++; - } - - public void myAfterThrowingAdvice(RuntimeException ex) { - this.afterCount++; - } - - public void mySetAgeAdvice(int newAge, ITestBean bean) { - // no-op - } - - public int getBeforeCount() { - return this.beforeCount; - } - - public int getAfterCount() { - return this.afterCount; - } - - public int getAroundCount() { - return this.aroundCount; - } -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/MethodLocatingFactoryBeanTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/MethodLocatingFactoryBeanTests.java index 620a300931f..43f5b36630b 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/MethodLocatingFactoryBeanTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/MethodLocatingFactoryBeanTests.java @@ -16,179 +16,118 @@ package org.springframework.aop.config; +import static org.easymock.EasyMock.*; import static org.junit.Assert.*; import java.lang.reflect.Method; -import org.easymock.MockControl; +import org.junit.After; +import org.junit.Before; import org.junit.Test; - import org.springframework.beans.factory.BeanFactory; -import org.springframework.mock.easymock.AbstractScalarMockTemplate; -import org.springframework.test.AssertThrows; /** * @author Rick Evans + * @author Chris Beams */ public final class MethodLocatingFactoryBeanTests { private static final String BEAN_NAME = "string"; - + private MethodLocatingFactoryBean factory; + private BeanFactory beanFactory; + + @Before + public void setUp() { + factory = new MethodLocatingFactoryBean(); + + // methods must set up expectations and call replay() manually for this mock + beanFactory = createMock(BeanFactory.class); + } + + @After + public void tearDown() { + verify(beanFactory); + } @Test - public void testIsSingleton() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); + public void testIsSingleton() { + replay(beanFactory); assertTrue(factory.isSingleton()); } @Test - public void testGetObjectType() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); + public void testGetObjectType() { + replay(beanFactory); assertEquals(Method.class, factory.getObjectType()); } - @Test - public void testWithNullTargetBeanName() throws Exception { - new BeanFactoryScalarMockTemplate() { - public void doTestInternal(final BeanFactory beanFactory) throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); - factory.setMethodName("toString()"); - factory.setBeanFactory(beanFactory); - } - }.runTest(); - } - }.test(); + @Test(expected=IllegalArgumentException.class) + public void testWithNullTargetBeanName() { + replay(beanFactory); + + factory.setMethodName("toString()"); + factory.setBeanFactory(beanFactory); } - @Test - public void testWithEmptyTargetBeanName() throws Exception { - new BeanFactoryScalarMockTemplate() { - public void doTestInternal(final BeanFactory beanFactory) throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); - factory.setTargetBeanName(""); - factory.setMethodName("toString()"); - factory.setBeanFactory(beanFactory); - } - }.runTest(); - } - }.test(); + @Test(expected=IllegalArgumentException.class) + public void testWithEmptyTargetBeanName() { + replay(beanFactory); + + factory.setTargetBeanName(""); + factory.setMethodName("toString()"); + factory.setBeanFactory(beanFactory); } - @Test - public void testWithNullTargetMethodName() throws Exception { - new BeanFactoryScalarMockTemplate() { - public void doTestInternal(final BeanFactory beanFactory) throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); - factory.setTargetBeanName(BEAN_NAME); - factory.setBeanFactory(beanFactory); - } - }.runTest(); - } - }.test(); + @Test(expected=IllegalArgumentException.class) + public void testWithNullTargetMethodName() { + replay(beanFactory); + + factory.setTargetBeanName(BEAN_NAME); + factory.setBeanFactory(beanFactory); } - @Test - public void testWithEmptyTargetMethodName() throws Exception { - new BeanFactoryScalarMockTemplate() { - public void doTestInternal(final BeanFactory beanFactory) throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); - factory.setTargetBeanName(BEAN_NAME); - factory.setMethodName(""); - factory.setBeanFactory(beanFactory); - } - }.runTest(); - } - }.test(); + @Test(expected=IllegalArgumentException.class) + public void testWithEmptyTargetMethodName() { + replay(beanFactory); + + factory.setTargetBeanName(BEAN_NAME); + factory.setMethodName(""); + factory.setBeanFactory(beanFactory); } - @Test - public void testWhenTargetBeanClassCannotBeResolved() throws Exception { - new BeanFactoryScalarMockTemplate() { - protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { - beanFactory.getType(BEAN_NAME); - mockControl.setReturnValue(null); - } - protected void doTestInternal(final BeanFactory beanFactory) throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); - factory.setTargetBeanName(BEAN_NAME); - factory.setMethodName("toString()"); - factory.setBeanFactory(beanFactory); - } - }.runTest(); - } - }.test(); + @Test(expected=IllegalArgumentException.class) + public void testWhenTargetBeanClassCannotBeResolved() { + expect(beanFactory.getType(BEAN_NAME)).andReturn(null); + replay(beanFactory); + + factory.setTargetBeanName(BEAN_NAME); + factory.setMethodName("toString()"); + factory.setBeanFactory(beanFactory); } @Test public void testSunnyDayPath() throws Exception { - new BeanFactoryScalarMockTemplate() { - protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { - beanFactory.getType(BEAN_NAME); - mockControl.setReturnValue(String.class); - } - protected void doTestInternal(final BeanFactory beanFactory) throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); - factory.setTargetBeanName(BEAN_NAME); - factory.setMethodName("toString()"); - factory.setBeanFactory(beanFactory); - Object result = factory.getObject(); - assertNotNull(result); - assertTrue(result instanceof Method); - Method method = (Method) result; - assertEquals("Bingo", method.invoke("Bingo", new Object[]{})); - } - }.test(); + expect(beanFactory.getType(BEAN_NAME)).andReturn(String.class); + replay(beanFactory); + + factory.setTargetBeanName(BEAN_NAME); + factory.setMethodName("toString()"); + factory.setBeanFactory(beanFactory); + Object result = factory.getObject(); + assertNotNull(result); + assertTrue(result instanceof Method); + Method method = (Method) result; + assertEquals("Bingo", method.invoke("Bingo", new Object[]{})); } - @Test - public void testWhereMethodCannotBeResolved() throws Exception { - new BeanFactoryScalarMockTemplate() { - protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { - beanFactory.getType(BEAN_NAME); - mockControl.setReturnValue(String.class); - } - protected void doTestInternal(final BeanFactory beanFactory) throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); - factory.setTargetBeanName(BEAN_NAME); - factory.setMethodName("loadOfOld()"); - factory.setBeanFactory(beanFactory); - } - }.runTest(); - } - }.test(); - } - - - private static abstract class BeanFactoryScalarMockTemplate extends AbstractScalarMockTemplate { - - public BeanFactoryScalarMockTemplate() { - super(BeanFactory.class); - } - - public void setupExpectations(MockControl mockControl, Object mockObject) throws Exception { - setupBeanFactoryExpectations(mockControl, (BeanFactory) mockObject); - } - - public void doTest(Object mockObject) throws Exception { - doTestInternal((BeanFactory) mockObject); - } - - protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { - } - - protected abstract void doTestInternal(final BeanFactory beanFactory) throws Exception; + @Test(expected=IllegalArgumentException.class) + public void testWhereMethodCannotBeResolved() { + expect(beanFactory.getType(BEAN_NAME)).andReturn(String.class); + replay(beanFactory); + + factory.setTargetBeanName(BEAN_NAME); + factory.setMethodName("loadOfOld()"); + factory.setBeanFactory(beanFactory); } } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/prototypeProxy.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/PrototypeProxyTests-context.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/config/prototypeProxy.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/config/PrototypeProxyTests-context.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/PrototypeProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/PrototypeProxyTests.java index 95413370fdb..9594752490e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/config/PrototypeProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/config/PrototypeProxyTests.java @@ -21,12 +21,13 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author Juergen Hoeller + * @author Chris Beams */ -public class PrototypeProxyTests { +public final class PrototypeProxyTests { @Test public void testInjectionBeforeWrappingCheckDoesNotKickInForPrototypeProxy() { - new ClassPathXmlApplicationContext("prototypeProxy.xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); } } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java index 00a11510b2a..d78f8bd831d 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java @@ -31,6 +31,8 @@ import java.util.Map; import javax.servlet.ServletException; import javax.transaction.TransactionRequiredException; +import junit.framework.TestCase; + import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; @@ -42,10 +44,9 @@ import org.springframework.aop.AfterReturningAdvice; import org.springframework.aop.DynamicIntroductionAdvice; import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.TargetSource; +import org.springframework.aop.ThrowsAdvice; import org.springframework.aop.interceptor.DebugInterceptor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; -import org.springframework.aop.interceptor.NopInterceptor; -import org.springframework.aop.interceptor.SerializableNopInterceptor; import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.DefaultIntroductionAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor; @@ -61,10 +62,24 @@ import org.springframework.beans.ITestBean; import org.springframework.beans.Person; import org.springframework.beans.SerializablePerson; import org.springframework.beans.TestBean; +import org.springframework.dao.DataAccessException; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.util.SerializationTestUtils; import org.springframework.util.StopWatch; +import test.advice.CountingAfterReturningAdvice; +import test.advice.CountingBeforeAdvice; +import test.advice.MethodCounter; +import test.advice.MyThrowsHandler; +import test.interceptor.NopInterceptor; +import test.interceptor.SerializableNopInterceptor; +import test.interceptor.TimestampIntroductionInterceptor; +import test.mixin.LockMixin; +import test.mixin.LockMixinAdvisor; +import test.mixin.Lockable; +import test.mixin.LockedException; +import test.util.TimeStamped; + /** * @author Rod Johnson * @author Juergen Hoeller @@ -804,7 +819,7 @@ public abstract class AbstractAopProxyTests { @SuppressWarnings("serial") class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped { /** - * @see org.springframework.aop.framework.TimeStamped#getTimeStamp() + * @see test.util.TimeStamped#getTimeStamp() */ public long getTimeStamp() { throw new UnsupportedOperationException(); @@ -1904,4 +1919,130 @@ public abstract class AbstractAopProxyTests { } } + + @SuppressWarnings("serial") + public static class CountingMultiAdvice extends MethodCounter implements MethodBeforeAdvice, + AfterReturningAdvice, ThrowsAdvice { + + public void before(Method m, Object[] args, Object target) throws Throwable { + count(m); + } + + public void afterReturning(Object o, Method m, Object[] args, Object target) + throws Throwable { + count(m); + } + + public void afterThrowing(ServletException sex) throws Throwable { + count(ServletException.class.getName()); + } + + public void afterThrowing(DataAccessException ex) throws Throwable { + count(DataAccessException.class.getName()); + } + + } + + + @SuppressWarnings("serial") + public static class CountingThrowsAdvice extends MethodCounter implements ThrowsAdvice { + + public void afterThrowing(ServletException sex) throws Throwable { + count(ServletException.class.getName()); + } + + public void afterThrowing(DataAccessException ex) throws Throwable { + count(DataAccessException.class.getName()); + } + + } + + + static class MockTargetSource implements TargetSource { + + private Object target; + + public int gets; + + public int releases; + + public void reset() { + this.target = null; + gets = releases = 0; + } + + public void setTarget(Object target) { + this.target = target; + } + + /** + * @see org.springframework.aop.TargetSource#getTargetClass() + */ + public Class getTargetClass() { + return target.getClass(); + } + + /** + * @see org.springframework.aop.TargetSource#getTarget() + */ + public Object getTarget() throws Exception { + ++gets; + return target; + } + + /** + * @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object) + */ + public void releaseTarget(Object pTarget) throws Exception { + if (pTarget != this.target) + throw new RuntimeException("Released wrong target"); + ++releases; + } + + /** + * Check that gets and releases match + * + */ + public void verify() { + if (gets != releases) + throw new RuntimeException("Expectation failed: " + gets + " gets and " + releases + " releases"); + } + + /** + * @see org.springframework.aop.TargetSource#isStatic() + */ + public boolean isStatic() { + return false; + } + + } + + + static abstract class ExposedInvocationTestBean extends TestBean { + + public String getName() { + MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); + assertions(invocation); + return super.getName(); + } + + public void absquatulate() { + MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); + assertions(invocation); + super.absquatulate(); + } + + protected abstract void assertions(MethodInvocation invocation); + } + + + static class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean { + protected void assertions(MethodInvocation invocation) { + TestCase.assertTrue(invocation.getThis() == this); + TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(), + ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())); + } + } + } + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/withDependencyChecking.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests-with-dependency-checking.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/withDependencyChecking.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests-with-dependency-checking.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java index 75415c4080a..d59924d16e9 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibProxyTests.java @@ -23,12 +23,12 @@ import java.io.Serializable; import net.sf.cglib.core.CodeGenerationException; import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; import org.junit.Test; import org.springframework.aop.ClassFilter; import org.springframework.aop.MethodMatcher; import org.springframework.aop.Pointcut; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.beans.ITestBean; @@ -37,6 +37,10 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextException; import org.springframework.context.support.ClassPathXmlApplicationContext; +import test.advice.CountingBeforeAdvice; +import test.interceptor.NopInterceptor; +import test.mixin.LockMixinAdvisor; + /** * Additional and overridden tests for the CGLIB proxy. * @@ -46,7 +50,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * @author Ramnivas Laddad * @author Chris Beams */ -public class CglibProxyTests extends AbstractAopProxyTests { +@SuppressWarnings("serial") +public final class CglibProxyTests extends AbstractAopProxyTests implements Serializable { + + private static final String DEPENDENCY_CHECK_CONTEXT = CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml"; + protected Object createProxy(ProxyCreatorSupport as) { as.setProxyTargetClass(true); @@ -330,7 +338,7 @@ public class CglibProxyTests extends AbstractAopProxyTests { @Test public void testWithDependencyChecking() { ApplicationContext ctx = - new ClassPathXmlApplicationContext("org/springframework/aop/framework/withDependencyChecking.xml"); + new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass()); ctx.getBean("testBean"); } @@ -429,3 +437,61 @@ public class CglibProxyTests extends AbstractAopProxyTests { } } + + +class CglibTestBean { + + private String name; + + public CglibTestBean() { + setName("Some Default"); + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } +} + + +class NoArgCtorTestBean { + + private boolean called = false; + + public NoArgCtorTestBean(String x, int y) { + called = true; + } + + public boolean wasCalled() { + return called; + } + + public void reset() { + called = false; + } + +} + + +class ProtectedMethodTestBean { + + protected String getString() { + return "foo"; + } + +} + + +class UnsupportedInterceptor implements MethodInterceptor { + + /** + * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) + */ + public Object invoke(MethodInvocation mi) throws Throwable { + throw new UnsupportedOperationException(mi.getMethod().getName()); + } + +} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibTestBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibTestBean.java deleted file mode 100644 index 690e8b097f5..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CglibTestBean.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -/** - * @author Rob Harrop - */ -public class CglibTestBean { - - private String name; - - public CglibTestBean() { - setName("Some Default"); - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingMultiAdvice.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingMultiAdvice.java deleted file mode 100644 index 2b27d2e7907..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingMultiAdvice.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -import java.lang.reflect.Method; - -import javax.servlet.ServletException; - -import org.springframework.aop.AfterReturningAdvice; -import org.springframework.aop.MethodBeforeAdvice; -import org.springframework.aop.ThrowsAdvice; -import org.springframework.dao.DataAccessException; - -/** - * Advice object that implements multiple Advice interfaces. - * - * @author Juergen Hoeller - * @since 19.05.2005 - */ -public class CountingMultiAdvice extends MethodCounter - implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice { - - public void before(Method m, Object[] args, Object target) throws Throwable { - count(m); - } - - public void afterReturning(Object o, Method m, Object[] args, Object target) throws Throwable { - count(m); - } - - public void afterThrowing(ServletException sex) throws Throwable { - count(ServletException.class.getName()); - } - - public void afterThrowing(DataAccessException ex) throws Throwable { - count(DataAccessException.class.getName()); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingThrowsAdvice.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingThrowsAdvice.java deleted file mode 100644 index b17153124f0..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingThrowsAdvice.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -import javax.servlet.ServletException; - -import org.springframework.aop.ThrowsAdvice; -import org.springframework.dao.DataAccessException; - -/** - * @author Rod Johnson - */ -public class CountingThrowsAdvice extends MethodCounter implements ThrowsAdvice { - - public void afterThrowing(ServletException sex) throws Throwable { - count(ServletException.class.getName()); - } - - public void afterThrowing(DataAccessException ex) throws Throwable { - count(DataAccessException.class.getName()); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/Echo.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/Echo.java deleted file mode 100644 index da03878e47f..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/Echo.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * - */ -package org.springframework.aop.framework; - -class Echo implements IEcho { - private int a; - - public int echoException(int i, Throwable t) throws Throwable { - if (t != null) - throw t; - return i; - } - public void setA(int a) { - this.a = a; - } - public int getA() { - return a; - } -} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java deleted file mode 100644 index 83f56173791..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ExposedInvocationTestBean.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.interceptor.ExposeInvocationInterceptor; -import org.springframework.beans.TestBean; - - -/** - * Used to test ExposeInvocationInterceptor. - * @author Rod Johnson - */ -public abstract class ExposedInvocationTestBean extends TestBean { - - public String getName() { - MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); - assertions(invocation); - return super.getName(); - } - - public void absquatulate() { - MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); - assertions(invocation); - super.absquatulate(); - } - - protected abstract void assertions(MethodInvocation invocation); -} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/IEcho.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/IEcho.java deleted file mode 100644 index 78f4b0e927c..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/IEcho.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * - */ -package org.springframework.aop.framework; - -interface IEcho { - int echoException(int i, Throwable t) throws Throwable; - int getA(); - void setA(int a); -} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java deleted file mode 100644 index d5c1edc8768..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/InvocationCheckExposedInvocationTestBean.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -import junit.framework.TestCase; - -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.beans.ITestBean; - - -public class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean { - protected void assertions(MethodInvocation invocation) { - TestCase.assertTrue(invocation.getThis() == this); - TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(), - ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())); - } -} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java index 96233abea46..2e394ed68f7 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java @@ -22,6 +22,8 @@ import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import static org.junit.Assert.*; +import java.io.Serializable; + import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; @@ -32,12 +34,13 @@ import org.springframework.beans.ITestBean; import org.springframework.beans.TestBean; /** + * @since 13.03.2003 * @author Rod Johnson * @author Juergen Hoeller * @author Chris Beams - * @since 13.03.2003 */ -public class JdkDynamicProxyTests extends AbstractAopProxyTests { +@SuppressWarnings("serial") +public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements Serializable { protected Object createProxy(ProxyCreatorSupport as) { assertFalse("Not forcible CGLIB", as.isProxyTargetClass()); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MethodVisibilities.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MethodVisibilities.java deleted file mode 100644 index ad6b83463e1..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MethodVisibilities.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -/** - * Test for different method visibilities to - * test AOP proxying capabilities - * @author Rod Johnson - */ -public class MethodVisibilities { - - public String publicMethod(String s) { - return s; - } - - protected String protectedMethod(String s) { - return s; - } - - private String privateMethod(String s) { - return s; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MockTargetSource.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MockTargetSource.java deleted file mode 100644 index c2761d8492a..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MockTargetSource.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -import org.springframework.aop.TargetSource; - -/** - * - * @author Rod Johnson - */ -public class MockTargetSource implements TargetSource { - - private Object target; - - public int gets; - - public int releases; - - public void reset() { - this.target = null; - gets = releases = 0; - } - - public void setTarget(Object target) { - this.target = target; - } - - /** - * @see org.springframework.aop.TargetSource#getTargetClass() - */ - public Class getTargetClass() { - return target.getClass(); - } - - /** - * @see org.springframework.aop.TargetSource#getTarget() - */ - public Object getTarget() throws Exception { - ++gets; - return target; - } - - /** - * @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object) - */ - public void releaseTarget(Object pTarget) throws Exception { - if (pTarget != this.target) - throw new RuntimeException("Released wrong target"); - ++releases; - } - - /** - * Check that gets and releases match - * - */ - public void verify() { - if (gets != releases) - throw new RuntimeException("Expectation failed: " + gets + " gets and " + releases + " releases"); - } - - /** - * @see org.springframework.aop.TargetSource#isStatic() - */ - public boolean isStatic() { - return false; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoArgCtorTestBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoArgCtorTestBean.java deleted file mode 100644 index e872f72d82d..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoArgCtorTestBean.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -/** - * @author Rob Harrop - */ -public class NoArgCtorTestBean { - - private boolean called = false; - - public NoArgCtorTestBean(String x, int y) { - called = true; - } - - public boolean wasCalled() { - return called; - } - - public void reset() { - called = false; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoInterfaces.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoInterfaces.java deleted file mode 100644 index 603f14112d6..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoInterfaces.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -/** - * Used for testing CGLIB proxying. - * - * @author Rod Johnson - */ -public class NoInterfaces { - - private int age; - - public int getAge() { - return age; - } - public void setAge(int age) { - this.age = age; - } -} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoInterfacesConstructor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoInterfacesConstructor.java deleted file mode 100644 index e13bf0c901c..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/NoInterfacesConstructor.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -/** - * - * @author Rod Johnson - */ -public class NoInterfacesConstructor extends NoInterfaces { - - public NoInterfacesConstructor(int age) { - setAge(age); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProtectedMethodTestBean.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProtectedMethodTestBean.java deleted file mode 100644 index e4f45fe50fe..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProtectedMethodTestBean.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -/** - * @author Rob Harrop - */ -public class ProtectedMethodTestBean { - - protected String getString() { - return "foo"; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryBeanAutowiringTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-autowiring.xml similarity index 85% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryBeanAutowiringTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-autowiring.xml index b732d7af434..27e7988a7a7 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryBeanAutowiringTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-autowiring.xml @@ -3,7 +3,7 @@ - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-context.xml similarity index 94% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-context.xml index 09e68277731..8c0a313a7c3 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-context.xml @@ -9,7 +9,7 @@ 666 - + org.springframework.beans.ITestBean @@ -135,7 +135,7 @@ --> - + @@ -150,13 +150,13 @@ - + org.springframework.beans.ITestBean - org.springframework.aop.framework.Lockable + test.mixin.Lockable false diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryDoubleTargetSourceTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-double-targetsource.xml similarity index 96% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryDoubleTargetSourceTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-double-targetsource.xml index 0784675bb99..795cea64182 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryDoubleTargetSourceTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-double-targetsource.xml @@ -27,7 +27,7 @@ - \ No newline at end of file + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/frozenProxyFactoryBean.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-frozen.xml similarity index 90% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/frozenProxyFactoryBean.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-frozen.xml index 8b5b7bf70e7..45a4c2707b7 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/frozenProxyFactoryBean.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-frozen.xml @@ -10,7 +10,7 @@ - + - + - + - + serializableNopInterceptor diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryTargetSourceTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-targetsource.xml similarity index 91% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryTargetSourceTests.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-targetsource.xml index c5e48cbbbae..4e9ab797adc 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/proxyFactoryTargetSourceTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests-targetsource.xml @@ -13,11 +13,11 @@ Adam - + - + - + - + @@ -23,4 +23,4 @@ - \ No newline at end of file + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java index 1ba52a95874..73784bf947e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java @@ -35,7 +35,6 @@ import org.springframework.aop.ClassFilter; import org.springframework.aop.IntroductionAdvisor; import org.springframework.aop.IntroductionInterceptor; import org.springframework.aop.interceptor.DebugInterceptor; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.DefaultIntroductionAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor; @@ -55,22 +54,46 @@ import org.springframework.context.TestListener; import org.springframework.core.io.ClassPathResource; import org.springframework.util.SerializationTestUtils; +import test.advice.CountingBeforeAdvice; +import test.advice.MyThrowsHandler; +import test.interceptor.NopInterceptor; +import test.interceptor.TimestampIntroductionInterceptor; +import test.mixin.Lockable; +import test.mixin.LockedException; +import test.util.TimeStamped; + import common.beans.core.SideEffectBean; /** + * @since 13.03.2003 * @author Rod Johnson * @author Juergen Hoeller - * @since 13.03.2003 + * @author Chris Beams */ -public class ProxyFactoryBeanTests { - +public final class ProxyFactoryBeanTests { + + private static final Class CLASS = ProxyFactoryBeanTests.class; + private static final String CLASSNAME = CLASS.getSimpleName(); + + private static final String CONTEXT = CLASSNAME + "-context.xml"; + private static final String SERIALIZATION_CONTEXT = CLASSNAME + "-serialization.xml"; + private static final String AUTOWIRING_CONTEXT = CLASSNAME + "-autowiring.xml"; + private static final String DBL_TARGETSOURCE_CONTEXT = CLASSNAME + "-double-targetsource.xml"; + private static final String NOTLAST_TARGETSOURCE_CONTEXT = CLASSNAME + "-notlast-targetsource.xml"; + private static final String TARGETSOURCE_CONTEXT = CLASSNAME + "-targetsource.xml"; + private static final String INVALID_CONTEXT = CLASSNAME + "-invalid.xml"; + private static final String FROZEN_CONTEXT = CLASSNAME + "-frozen.xml"; + private static final String PROTOTYPE_CONTEXT = CLASSNAME + "-prototype.xml"; + private static final String THROWS_ADVICE_CONTEXT = CLASSNAME + "-throws-advice.xml"; + private static final String INNER_BEAN_TARGET_CONTEXT = CLASSNAME + "-inner-bean-target.xml"; + private BeanFactory factory; @Before public void setUp() throws Exception { DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class)); - this.factory = new XmlBeanFactory(new ClassPathResource("proxyFactoryTests.xml", getClass()), parent); + this.factory = new XmlBeanFactory(new ClassPathResource(CONTEXT, getClass()), parent); } @Test @@ -110,7 +133,7 @@ public class ProxyFactoryBeanTests { private void testDoubleTargetSourceIsRejected(String name) { try { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryDoubleTargetSourceTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean(name); fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property"); } @@ -124,7 +147,7 @@ public class ProxyFactoryBeanTests { @Test public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() { try { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryTargetSourceNotLastTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean("targetSourceNotLast"); fail("TargetSource or non-advised object must be last in interceptorNames"); } @@ -137,7 +160,7 @@ public class ProxyFactoryBeanTests { @Test public void testGetObjectTypeWithDirectTarget() { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryTargetSourceTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); // We have a counting before advice here CountingBeforeAdvice cba = (CountingBeforeAdvice) bf.getBean("countingBeforeAdvice"); @@ -153,7 +176,7 @@ public class ProxyFactoryBeanTests { @Test public void testGetObjectTypeWithTargetViaTargetSource() { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryTargetSourceTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); ITestBean tb = (ITestBean) bf.getBean("viaTargetSource"); assertTrue(tb.getName().equals("Adam")); ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&viaTargetSource"); @@ -162,7 +185,7 @@ public class ProxyFactoryBeanTests { @Test public void testGetObjectTypeWithNoTargetOrTargetSource() { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryTargetSourceTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); ITestBean tb = (ITestBean) bf.getBean("noTarget"); try { @@ -223,7 +246,7 @@ public class ProxyFactoryBeanTests { // Initial count value set in bean factory XML int INITIAL_COUNT = 10; - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("prototypeTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(PROTOTYPE_CONTEXT, CLASS)); // Check it works without AOP SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget"); @@ -314,7 +337,7 @@ public class ProxyFactoryBeanTests { */ @Test public void testTargetAsInnerBean() { - ListableBeanFactory bf = new XmlBeanFactory(new ClassPathResource("innerBeanTarget.xml", getClass())); + ListableBeanFactory bf = new XmlBeanFactory(new ClassPathResource(INNER_BEAN_TARGET_CONTEXT, CLASS)); ITestBean itb = (ITestBean) bf.getBean("testBean"); assertEquals("innerBeanTarget", itb.getName()); assertEquals("Only have proxy and interceptor: no target", 3, bf.getBeanDefinitionCount()); @@ -417,7 +440,7 @@ public class ProxyFactoryBeanTests { @Test public void testCanAddThrowsAdviceWithoutAdvisor() throws Throwable { - BeanFactory f = new XmlBeanFactory(new ClassPathResource("throwsAdvice.xml", getClass())); + BeanFactory f = new XmlBeanFactory(new ClassPathResource(THROWS_ADVICE_CONTEXT, CLASS)); MyThrowsHandler th = (MyThrowsHandler) f.getBean("throwsAdvice"); CountingBeforeAdvice cba = (CountingBeforeAdvice) f.getBean("countingBeforeAdvice"); assertEquals(0, cba.getCalls()); @@ -474,7 +497,7 @@ public class ProxyFactoryBeanTests { @Test public void testEmptyInterceptorNames() { - XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("invalidProxyFactory.xml", getClass())); + XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(INVALID_CONTEXT, CLASS)); try { factory.getBean("emptyInterceptorNames"); fail("Interceptor names cannot be empty"); @@ -489,7 +512,7 @@ public class ProxyFactoryBeanTests { */ @Test public void testGlobalsWithoutTarget() { - XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("invalidProxyFactory.xml", getClass())); + XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(INVALID_CONTEXT, CLASS)); try { factory.getBean("globalsWithoutTarget"); fail("Should require target name"); @@ -530,7 +553,7 @@ public class ProxyFactoryBeanTests { @Test public void testSerializableSingletonProxy() throws Exception { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("serializationTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); Person p = (Person) bf.getBean("serializableSingleton"); assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton")); Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p); @@ -552,7 +575,7 @@ public class ProxyFactoryBeanTests { @Test public void testSerializablePrototypeProxy() throws Exception { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("serializationTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); Person p = (Person) bf.getBean("serializablePrototype"); assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype")); Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p); @@ -563,7 +586,7 @@ public class ProxyFactoryBeanTests { @Test public void testSerializableSingletonProxyFactoryBean() throws Exception { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("serializationTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); Person p = (Person) bf.getBean("serializableSingleton"); ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton"); ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb); @@ -575,14 +598,14 @@ public class ProxyFactoryBeanTests { @Test public void testProxyNotSerializableBecauseOfAdvice() throws Exception { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("serializationTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); Person p = (Person) bf.getBean("interceptorNotSerializableSingleton"); assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p)); } @Test public void testPrototypeAdvisor() { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(CONTEXT, CLASS)); ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxy"); ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxy"); @@ -613,7 +636,7 @@ public class ProxyFactoryBeanTests { @Test public void testPrototypeInterceptorSingletonTarget() { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(CONTEXT, CLASS)); ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget"); ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget"); @@ -647,13 +670,13 @@ public class ProxyFactoryBeanTests { */ @Test public void testInnerBeanTargetUsingAutowiring() { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryBeanAutowiringTests.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(AUTOWIRING_CONTEXT, CLASS)); bf.getBean("testBean"); } @Test public void testFrozenFactoryBean() { - BeanFactory bf = new XmlBeanFactory(new ClassPathResource("frozenProxyFactoryBean.xml", getClass())); + BeanFactory bf = new XmlBeanFactory(new ClassPathResource(FROZEN_CONTEXT, CLASS)); Advised advised = (Advised)bf.getBean("frozen"); assertTrue("The proxy should be frozen", advised.isFrozen()); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/UnsupportedInterceptor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/UnsupportedInterceptor.java deleted file mode 100644 index 7f3817c663c..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/UnsupportedInterceptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; - -/** - * - * @author Rod Johnson - */ -public class UnsupportedInterceptor implements MethodInterceptor { - - /** - * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) - */ - public Object invoke(MethodInvocation mi) throws Throwable { - throw new UnsupportedOperationException(mi.getMethod().getName()); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/withBPPContext.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests-with-bpp.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/withBPPContext.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests-with-bpp.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/withoutBPPContext.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests-without-bpp.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/withoutBPPContext.xml rename to org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests-without-bpp.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java index e617618b547..32ba8eb0f5b 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java @@ -18,11 +18,16 @@ package org.springframework.aop.framework.adapter; import static org.junit.Assert.*; +import java.io.Serializable; + +import org.aopalliance.aop.Advice; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; import org.junit.Test; -import org.springframework.aop.*; +import org.springframework.aop.Advisor; +import org.springframework.aop.BeforeAdvice; import org.springframework.aop.framework.Advised; import org.springframework.beans.ITestBean; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** @@ -31,11 +36,12 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * @author Dmitriy Kopylenko * @author Chris Beams */ -public class AdvisorAdapterRegistrationTests { +public final class AdvisorAdapterRegistrationTests { @Test public void testAdvisorAdapterRegistrationManagerNotPresentInContext() { - ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withoutBPPContext.xml"); + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-without-bpp.xml", getClass()); ITestBean tb = (ITestBean) ctx.getBean("testBean"); // just invoke any method to see if advice fired try { @@ -50,7 +56,8 @@ public class AdvisorAdapterRegistrationTests { @Test public void testAdvisorAdapterRegistrationManagerPresentInContext() { - ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withBPPContext.xml"); + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-with-bpp.xml", getClass()); ITestBean tb = (ITestBean) ctx.getBean("testBean"); // just invoke any method to see if advice fired try { @@ -69,3 +76,56 @@ public class AdvisorAdapterRegistrationTests { } } + + +interface SimpleBeforeAdvice extends BeforeAdvice { + + void before() throws Throwable; + +} + + +@SuppressWarnings("serial") +class SimpleBeforeAdviceAdapter implements AdvisorAdapter, Serializable { + + public boolean supportsAdvice(Advice advice) { + return (advice instanceof SimpleBeforeAdvice); + } + + public MethodInterceptor getInterceptor(Advisor advisor) { + SimpleBeforeAdvice advice = (SimpleBeforeAdvice) advisor.getAdvice(); + return new SimpleBeforeAdviceInterceptor(advice) ; + } + +} + + +class SimpleBeforeAdviceImpl implements SimpleBeforeAdvice { + + private int invocationCounter; + + public void before() throws Throwable { + ++invocationCounter; + } + + public int getInvocationCounter() { + return invocationCounter; + } + +} + + +final class SimpleBeforeAdviceInterceptor implements MethodInterceptor { + + private SimpleBeforeAdvice advice; + + public SimpleBeforeAdviceInterceptor(SimpleBeforeAdvice advice) { + this.advice = advice; + } + + public Object invoke(MethodInvocation mi) throws Throwable { + advice.before(); + return mi.proceed(); + } + +} \ No newline at end of file diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdvice.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdvice.java deleted file mode 100644 index 3a9c276888a..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdvice.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework.adapter; - -import org.springframework.aop.BeforeAdvice; - -/** - * Simple BeforeAdvice for testing. - * - * @author Dmitriy Kopylenko - */ -public interface SimpleBeforeAdvice extends BeforeAdvice { - - void before() throws Throwable; - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceAdapter.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceAdapter.java deleted file mode 100644 index abc588d9e5d..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceAdapter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2007 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework.adapter; - -import java.io.Serializable; - -import org.aopalliance.aop.Advice; -import org.aopalliance.intercept.MethodInterceptor; - -import org.springframework.aop.Advisor; -import org.springframework.aop.framework.adapter.AdvisorAdapter; - -/** - * @author Dmitriy Kopylenko - */ -public class SimpleBeforeAdviceAdapter implements AdvisorAdapter, Serializable { - - public boolean supportsAdvice(Advice advice) { - return (advice instanceof SimpleBeforeAdvice); - } - - public MethodInterceptor getInterceptor(Advisor advisor) { - SimpleBeforeAdvice advice = (SimpleBeforeAdvice) advisor.getAdvice(); - return new SimpleBeforeAdviceInterceptor(advice) ; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceImpl.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceImpl.java deleted file mode 100644 index 33eae58208c..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework.adapter; - -/** - * @author Dmitriy Kopylenko - */ -public class SimpleBeforeAdviceImpl implements SimpleBeforeAdvice { - - private int invocationCounter; - - public void before() throws Throwable { - ++invocationCounter; - } - - public int getInvocationCounter() { - return invocationCounter; - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceInterceptor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceInterceptor.java deleted file mode 100644 index 2c60182f4d0..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/adapter/SimpleBeforeAdviceInterceptor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2005 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.aop.framework.adapter; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; - -/** - * @author Dmitriy Kopylenko - */ -final class SimpleBeforeAdviceInterceptor implements MethodInterceptor { - - private SimpleBeforeAdvice advice; - - public SimpleBeforeAdviceInterceptor(SimpleBeforeAdvice advice) { - this.advice = advice; - } - - public Object invoke(MethodInvocation mi) throws Throwable { - advice.before(); - return mi.proceed(); - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorTests.java index d85a69cab30..baaae86e950 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorTests.java @@ -26,10 +26,6 @@ import javax.servlet.ServletException; import org.junit.Test; import org.springframework.aop.framework.Advised; -import org.springframework.aop.framework.CountingBeforeAdvice; -import org.springframework.aop.framework.Lockable; -import org.springframework.aop.framework.MethodCounter; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.support.AopUtils; import org.springframework.aop.target.CommonsPoolTargetSource; import org.springframework.aop.target.LazyInitTargetSource; @@ -40,6 +36,11 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.transaction.CallCountingTransactionManager; +import test.advice.CountingBeforeAdvice; +import test.advice.MethodCounter; +import test.interceptor.NopInterceptor; +import test.mixin.Lockable; + /** * Tests for auto proxy creation by advisor recognition. * diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java index 77119a1628a..94b3c7d8417 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java @@ -23,17 +23,18 @@ import java.io.IOException; import org.junit.Before; import org.junit.Test; import org.springframework.aop.framework.Advised; -import org.springframework.aop.framework.CountingBeforeAdvice; -import org.springframework.aop.framework.Lockable; -import org.springframework.aop.framework.LockedException; -import org.springframework.aop.framework.TimeStamped; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.support.AopUtils; import org.springframework.beans.ITestBean; import org.springframework.beans.TestBean; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; +import test.advice.CountingBeforeAdvice; +import test.interceptor.NopInterceptor; +import test.mixin.Lockable; +import test.mixin.LockedException; +import test.util.TimeStamped; + /** * @author Rod Johnson * @author Rob Harrop diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/NeverMatchAdvisor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/NeverMatchAdvisor.java index 83377a8b712..1ffd4760415 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/NeverMatchAdvisor.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/NeverMatchAdvisor.java @@ -19,9 +19,10 @@ package org.springframework.aop.framework.autoproxy; import java.lang.reflect.Method; import java.util.List; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; +import test.interceptor.NopInterceptor; + /** * * @author Rod Johnson diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/OrderedTxCheckAdvisor.java b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/OrderedTxCheckAdvisor.java index aa0c134ceb0..41984f8b144 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/OrderedTxCheckAdvisor.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/OrderedTxCheckAdvisor.java @@ -18,12 +18,13 @@ package org.springframework.aop.framework.autoproxy; import java.lang.reflect.Method; -import org.springframework.aop.framework.CountingBeforeAdvice; import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; import org.springframework.beans.factory.InitializingBean; import org.springframework.transaction.NoTransactionException; import org.springframework.transaction.interceptor.TransactionInterceptor; +import test.advice.CountingBeforeAdvice; + /** * Before advisor that allow us to manipulate ordering to check * that superclass sorting works correctly. diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml index a685b944529..6eed48e89b9 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml @@ -85,7 +85,7 @@ org.springframework.beans.ITestBean.getName - + 4 diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml index d24029bbf4b..286f8c840dd 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml @@ -20,14 +20,14 @@ - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/beanNameAutoProxyCreatorTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/beanNameAutoProxyCreatorTests.xml index 0eb5a4e870e..853dddc86d4 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/beanNameAutoProxyCreatorTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/beanNameAutoProxyCreatorTests.xml @@ -59,19 +59,19 @@ - + - - + - + - + introductionUsingJdk diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml index aa771d402f0..2846b8956d4 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml @@ -7,7 +7,7 @@ - + @@ -21,4 +21,4 @@ - \ No newline at end of file + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/target/commonsPoolTests.xml b/org.springframework.testsuite/src/test/java/org/springframework/aop/target/commonsPoolTests.xml index ab9b6d208c4..93cdcd89240 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/target/commonsPoolTests.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/aop/target/commonsPoolTests.xml @@ -17,7 +17,7 @@ getPoolingConfigMixin - + - + diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java index c68abdb7d97..1bf54f8d1a6 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java @@ -28,7 +28,6 @@ import org.junit.Test; import org.springframework.aop.Advisor; import org.springframework.aop.framework.Advised; import org.springframework.aop.interceptor.DebugInterceptor; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.aop.support.AopUtils; import org.springframework.beans.ITestBean; import org.springframework.beans.TestBean; @@ -42,6 +41,8 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.xml.sax.InputSource; +import test.interceptor.NopInterceptor; + /** * @author Rob Harrop * @author Rick Evans diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/TestNamespaceHandler.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/TestNamespaceHandler.java index 997e21db8d6..5233810b12a 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/TestNamespaceHandler.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/support/TestNamespaceHandler.java @@ -18,7 +18,6 @@ package org.springframework.beans.factory.xml.support; import org.springframework.aop.config.AbstractInterceptorDrivenBeanDefinitionDecorator; import org.springframework.aop.interceptor.DebugInterceptor; -import org.springframework.aop.interceptor.NopInterceptor; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.TestBean; import org.springframework.beans.factory.config.BeanDefinition; @@ -35,6 +34,8 @@ import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; +import test.interceptor.NopInterceptor; + /** * @author Rob Harrop */ diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingAfterReturningAdvice.java b/org.springframework.testsuite/src/test/java/test/advice/CountingAfterReturningAdvice.java similarity index 95% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingAfterReturningAdvice.java rename to org.springframework.testsuite/src/test/java/test/advice/CountingAfterReturningAdvice.java index d59f74800bd..d28ac263aa7 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingAfterReturningAdvice.java +++ b/org.springframework.testsuite/src/test/java/test/advice/CountingAfterReturningAdvice.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.advice; import java.lang.reflect.Method; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java b/org.springframework.testsuite/src/test/java/test/advice/CountingBeforeAdvice.java similarity index 95% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java rename to org.springframework.testsuite/src/test/java/test/advice/CountingBeforeAdvice.java index 3f391b2c68c..f34ba8ac18e 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/CountingBeforeAdvice.java +++ b/org.springframework.testsuite/src/test/java/test/advice/CountingBeforeAdvice.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.advice; import java.lang.reflect.Method; @@ -31,4 +31,4 @@ public class CountingBeforeAdvice extends MethodCounter implements MethodBeforeA count(m); } -} \ No newline at end of file +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MethodCounter.java b/org.springframework.testsuite/src/test/java/test/advice/MethodCounter.java similarity index 97% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MethodCounter.java rename to org.springframework.testsuite/src/test/java/test/advice/MethodCounter.java index d3030ffe8e0..41fa68163ea 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MethodCounter.java +++ b/org.springframework.testsuite/src/test/java/test/advice/MethodCounter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.advice; import java.io.Serializable; import java.lang.reflect.Method; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MyThrowsHandler.java b/org.springframework.testsuite/src/test/java/test/advice/MyThrowsHandler.java similarity index 93% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MyThrowsHandler.java rename to org.springframework.testsuite/src/test/java/test/advice/MyThrowsHandler.java index ffca13d42c7..1856821a580 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/MyThrowsHandler.java +++ b/org.springframework.testsuite/src/test/java/test/advice/MyThrowsHandler.java @@ -1,7 +1,7 @@ /** * */ -package org.springframework.aop.framework; +package test.advice; import java.io.IOException; import java.lang.reflect.Method; @@ -9,6 +9,7 @@ import java.rmi.RemoteException; import org.springframework.aop.ThrowsAdvice; + @SuppressWarnings("serial") public class MyThrowsHandler extends MethodCounter implements ThrowsAdvice { // Full method signature diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimestampIntroductionAdvisor.java b/org.springframework.testsuite/src/test/java/test/advice/TimestampIntroductionAdvisor.java similarity index 92% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimestampIntroductionAdvisor.java rename to org.springframework.testsuite/src/test/java/test/advice/TimestampIntroductionAdvisor.java index 387d3818d36..c0e70dd28e9 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimestampIntroductionAdvisor.java +++ b/org.springframework.testsuite/src/test/java/test/advice/TimestampIntroductionAdvisor.java @@ -14,11 +14,13 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.advice; import org.springframework.aop.support.DelegatingIntroductionInterceptor; import org.springframework.aop.support.DefaultIntroductionAdvisor; +import test.interceptor.TimestampIntroductionInterceptor; + /** * * @author Rod Johnson diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/interceptor/NopInterceptor.java b/org.springframework.testsuite/src/test/java/test/interceptor/NopInterceptor.java similarity index 96% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/interceptor/NopInterceptor.java rename to org.springframework.testsuite/src/test/java/test/interceptor/NopInterceptor.java index 6bbbc4ff174..223a5f1a75c 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/interceptor/NopInterceptor.java +++ b/org.springframework.testsuite/src/test/java/test/interceptor/NopInterceptor.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.springframework.aop.interceptor; +package test.interceptor; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/interceptor/SerializableNopInterceptor.java b/org.springframework.testsuite/src/test/java/test/interceptor/SerializableNopInterceptor.java similarity index 96% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/interceptor/SerializableNopInterceptor.java rename to org.springframework.testsuite/src/test/java/test/interceptor/SerializableNopInterceptor.java index 328f6cf9b2f..3af0cbc2962 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/interceptor/SerializableNopInterceptor.java +++ b/org.springframework.testsuite/src/test/java/test/interceptor/SerializableNopInterceptor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.interceptor; +package test.interceptor; import java.io.Serializable; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java b/org.springframework.testsuite/src/test/java/test/interceptor/TimestampIntroductionInterceptor.java similarity index 94% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java rename to org.springframework.testsuite/src/test/java/test/interceptor/TimestampIntroductionInterceptor.java index 2584d2575c5..960be703f66 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimestampIntroductionInterceptor.java +++ b/org.springframework.testsuite/src/test/java/test/interceptor/TimestampIntroductionInterceptor.java @@ -14,10 +14,12 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.interceptor; import org.springframework.aop.support.DelegatingIntroductionInterceptor; +import test.util.TimeStamped; + public class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor implements TimeStamped { diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/DefaultLockable.java b/org.springframework.testsuite/src/test/java/test/mixin/DefaultLockable.java similarity index 95% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/DefaultLockable.java rename to org.springframework.testsuite/src/test/java/test/mixin/DefaultLockable.java index b3237f9d293..a85fb94678b 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/DefaultLockable.java +++ b/org.springframework.testsuite/src/test/java/test/mixin/DefaultLockable.java @@ -14,7 +14,8 @@ * limitations under the License. */ - package org.springframework.aop.framework; + package test.mixin; + /** * Simple implementation of Lockable interface for use in mixins. diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockMixin.java b/org.springframework.testsuite/src/test/java/test/mixin/LockMixin.java similarity index 93% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockMixin.java rename to org.springframework.testsuite/src/test/java/test/mixin/LockMixin.java index 635588aaaa1..d4d9292ee4a 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockMixin.java +++ b/org.springframework.testsuite/src/test/java/test/mixin/LockMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.mixin; import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.support.DelegatingIntroductionInterceptor; @@ -42,7 +42,7 @@ public class LockMixin extends DelegatingIntroductionInterceptor implements Lock } /** - * @see org.springframework.aop.framework.AopProxyTests.Lockable#locked() + * @see test.mixin.AopProxyTests.Lockable#locked() */ public boolean locked() { return this.locked; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockMixinAdvisor.java b/org.springframework.testsuite/src/test/java/test/mixin/LockMixinAdvisor.java similarity index 95% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockMixinAdvisor.java rename to org.springframework.testsuite/src/test/java/test/mixin/LockMixinAdvisor.java index a3b600cc739..ba28e9dd4de 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockMixinAdvisor.java +++ b/org.springframework.testsuite/src/test/java/test/mixin/LockMixinAdvisor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.mixin; import org.springframework.aop.support.DefaultIntroductionAdvisor; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/Lockable.java b/org.springframework.testsuite/src/test/java/test/mixin/Lockable.java similarity index 94% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/Lockable.java rename to org.springframework.testsuite/src/test/java/test/mixin/Lockable.java index 70d6b2cfa5f..6db63281d7c 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/Lockable.java +++ b/org.springframework.testsuite/src/test/java/test/mixin/Lockable.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.mixin; /** diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockedException.java b/org.springframework.testsuite/src/test/java/test/mixin/LockedException.java similarity index 94% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockedException.java rename to org.springframework.testsuite/src/test/java/test/mixin/LockedException.java index cbea82f2a28..f00ac9507b9 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/LockedException.java +++ b/org.springframework.testsuite/src/test/java/test/mixin/LockedException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.mixin; public class LockedException extends RuntimeException { diff --git a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimeStamped.java b/org.springframework.testsuite/src/test/java/test/util/TimeStamped.java similarity index 95% rename from org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimeStamped.java rename to org.springframework.testsuite/src/test/java/test/util/TimeStamped.java index e514210ec17..958d8b21f9a 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/aop/framework/TimeStamped.java +++ b/org.springframework.testsuite/src/test/java/test/util/TimeStamped.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.framework; +package test.util; /** * This interface can be implemented by cacheable objects or cache entries,