refactoring .testsuite .aop.aspectj tests in preparation for migration to .context
This commit is contained in:
parent
aee972c5b1
commit
eabec18151
|
@ -1,47 +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;
|
|
||||||
|
|
||||||
import org.springframework.aop.framework.Advised;
|
|
||||||
import org.springframework.aop.support.AopUtils;
|
|
||||||
import org.springframework.beans.ITestBean;
|
|
||||||
import org.springframework.beans.TestBean;
|
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Rod Johnson
|
|
||||||
*/
|
|
||||||
public abstract class AbstractAdviceBindingTests extends AbstractDependencyInjectionSpringContextTests {
|
|
||||||
|
|
||||||
protected ITestBean testBeanProxy;
|
|
||||||
|
|
||||||
protected TestBean testBeanTarget;
|
|
||||||
|
|
||||||
public final void setTestBean(ITestBean injectedTestBean) throws Exception {
|
|
||||||
assertTrue(AopUtils.isAopProxy(injectedTestBean));
|
|
||||||
this.testBeanProxy = injectedTestBean;
|
|
||||||
// we need the real target too, not just the proxy...
|
|
||||||
this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simple test to ensure all is well with the XML file.
|
|
||||||
// Note that this implicitly tests that the arg-names binding is working.
|
|
||||||
public final void testParse() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,11 +19,13 @@ package org.springframework.aop.aspectj;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aspect used as part of before advice binding tests.
|
* Aspect used as part of before before advice binding tests and
|
||||||
|
* serves as base class for a number of more specialized test aspects.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AdviceBindingTestAspect {
|
class AdviceBindingTestAspect {
|
||||||
|
|
||||||
protected AdviceBindingCollaborator collaborator = null;
|
protected AdviceBindingCollaborator collaborator = null;
|
||||||
|
|
||||||
|
|
|
@ -16,81 +16,94 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.easymock.MockControl;
|
import static org.easymock.EasyMock.*;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
|
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
|
||||||
|
import org.springframework.aop.framework.Advised;
|
||||||
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
import org.springframework.beans.ITestBean;
|
||||||
|
import org.springframework.beans.TestBean;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for various parameter binding scenarios with before advice.
|
* Tests for various parameter binding scenarios with before advice.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AfterAdviceBindingTests extends AbstractAdviceBindingTests {
|
public final class AfterAdviceBindingTests {
|
||||||
|
|
||||||
private AdviceBindingTestAspect afterAdviceAspect;
|
|
||||||
|
|
||||||
private MockControl mockControl;
|
|
||||||
|
|
||||||
private AdviceBindingCollaborator mockCollaborator;
|
private AdviceBindingCollaborator mockCollaborator;
|
||||||
|
|
||||||
|
private ITestBean testBeanProxy;
|
||||||
|
|
||||||
public void setAfterAdviceAspect(AdviceBindingTestAspect anAspect) {
|
private TestBean testBeanTarget;
|
||||||
this.afterAdviceAspect = anAspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
@Before
|
||||||
return "after-advice-tests.xml";
|
public void setUp() throws Exception {
|
||||||
}
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("after-advice-tests.xml", getClass());
|
||||||
|
AdviceBindingTestAspect afterAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||||
super.onSetUp();
|
assertTrue(AopUtils.isAopProxy(testBeanProxy));
|
||||||
mockControl = MockControl.createNiceControl(AdviceBindingCollaborator.class);
|
|
||||||
mockCollaborator = (AdviceBindingCollaborator) mockControl.getMock();
|
// we need the real target too, not just the proxy...
|
||||||
|
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||||
|
|
||||||
|
mockCollaborator = createNiceMock(AdviceBindingCollaborator.class);
|
||||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneIntArg() {
|
public void testOneIntArg() {
|
||||||
mockCollaborator.oneIntArg(5);
|
mockCollaborator.oneIntArg(5);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneObjectArgBindingProxyWithThis() {
|
public void testOneObjectArgBindingProxyWithThis() {
|
||||||
mockCollaborator.oneObjectArg(this.testBeanProxy);
|
mockCollaborator.oneObjectArg(this.testBeanProxy);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneObjectArgBindingTarget() {
|
public void testOneObjectArgBindingTarget() {
|
||||||
mockCollaborator.oneObjectArg(this.testBeanTarget);
|
mockCollaborator.oneObjectArg(this.testBeanTarget);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getDoctor();
|
testBeanProxy.getDoctor();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneIntAndOneObjectArgs() {
|
public void testOneIntAndOneObjectArgs() {
|
||||||
mockCollaborator.oneIntAndOneObject(5,this.testBeanProxy);
|
mockCollaborator.oneIntAndOneObject(5,this.testBeanProxy);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNeedsJoinPoint() {
|
public void testNeedsJoinPoint() {
|
||||||
mockCollaborator.needsJoinPoint("getAge");
|
mockCollaborator.needsJoinPoint("getAge");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNeedsJoinPointStaticPart() {
|
public void testNeedsJoinPointStaticPart() {
|
||||||
mockCollaborator.needsJoinPointStaticPart("getAge");
|
mockCollaborator.needsJoinPointStaticPart("getAge");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +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;
|
|
||||||
|
|
||||||
import org.springframework.beans.ITestBean;
|
|
||||||
import org.springframework.beans.TestBean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
*/
|
|
||||||
public class AfterReturningAdviceBindingTestAspect extends AdviceBindingTestAspect {
|
|
||||||
|
|
||||||
private AfterReturningAdviceBindingCollaborator getCollaborator() {
|
|
||||||
return (AfterReturningAdviceBindingCollaborator) this.collaborator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void oneString(String name) {
|
|
||||||
getCollaborator().oneString(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void oneTestBeanArg(TestBean bean) {
|
|
||||||
getCollaborator().oneTestBeanArg(bean);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBeanArrayArg(ITestBean[] beans) {
|
|
||||||
getCollaborator().testBeanArrayArg(beans);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void objectMatchNoArgs() {
|
|
||||||
getCollaborator().objectMatchNoArgs();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stringMatchNoArgs() {
|
|
||||||
getCollaborator().stringMatchNoArgs();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void oneInt(int result) {
|
|
||||||
getCollaborator().oneInt(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface AfterReturningAdviceBindingCollaborator extends AdviceBindingCollaborator {
|
|
||||||
|
|
||||||
void oneString(String s);
|
|
||||||
void oneTestBeanArg(TestBean b);
|
|
||||||
void testBeanArrayArg(ITestBean[] b);
|
|
||||||
void objectMatchNoArgs();
|
|
||||||
void stringMatchNoArgs();
|
|
||||||
void oneInt(int result);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,14 +16,18 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.easymock.MockControl;
|
import static org.easymock.EasyMock.*;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.AfterReturningAdviceBindingTestAspect.AfterReturningAdviceBindingCollaborator;
|
import org.springframework.aop.aspectj.AfterReturningAdviceBindingTestAspect.AfterReturningAdviceBindingCollaborator;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for various parameter binding scenarios with before advice.
|
* Tests for various parameter binding scenarios with before advice.
|
||||||
|
@ -31,8 +35,9 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AfterReturningAdviceBindingTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class AfterReturningAdviceBindingTests {
|
||||||
|
|
||||||
private AfterReturningAdviceBindingTestAspect afterAdviceAspect;
|
private AfterReturningAdviceBindingTestAspect afterAdviceAspect;
|
||||||
|
|
||||||
|
@ -40,8 +45,6 @@ public class AfterReturningAdviceBindingTests extends AbstractDependencyInjectio
|
||||||
|
|
||||||
private TestBean testBeanTarget;
|
private TestBean testBeanTarget;
|
||||||
|
|
||||||
private MockControl mockControl;
|
|
||||||
|
|
||||||
private AfterReturningAdviceBindingCollaborator mockCollaborator;
|
private AfterReturningAdviceBindingCollaborator mockCollaborator;
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,121 +52,172 @@ public class AfterReturningAdviceBindingTests extends AbstractDependencyInjectio
|
||||||
this.afterAdviceAspect = anAspect;
|
this.afterAdviceAspect = anAspect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTestBean(ITestBean aBean) throws Exception {
|
|
||||||
assertTrue(AopUtils.isAopProxy(aBean));
|
|
||||||
this.testBeanProxy = aBean;
|
|
||||||
// we need the real target too, not just the proxy...
|
|
||||||
this.testBeanTarget = (TestBean) ((Advised)aBean).getTargetSource().getTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
protected String getConfigPath() {
|
||||||
return "afterReturning-advice-tests.xml";
|
return "afterReturning-advice-tests.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
@Before
|
||||||
super.onSetUp();
|
public void setUp() throws Exception {
|
||||||
mockControl = MockControl.createNiceControl(AfterReturningAdviceBindingCollaborator.class);
|
ApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigPath(), getClass());
|
||||||
mockCollaborator = (AfterReturningAdviceBindingCollaborator) mockControl.getMock();
|
|
||||||
|
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||||
|
|
||||||
|
mockCollaborator = createNiceMock(AfterReturningAdviceBindingCollaborator.class);
|
||||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
|
|
||||||
|
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||||
|
assertTrue(AopUtils.isAopProxy(testBeanProxy));
|
||||||
|
|
||||||
|
// we need the real target too, not just the proxy...
|
||||||
|
this.testBeanTarget = (TestBean) ((Advised)testBeanProxy).getTargetSource().getTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// simple test to ensure all is well with the xml file
|
@Test
|
||||||
// note that this implicitly tests that the arg-names binding is working
|
|
||||||
public void testParse() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testOneIntArg() {
|
public void testOneIntArg() {
|
||||||
mockCollaborator.oneIntArg(5);
|
mockCollaborator.oneIntArg(5);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneObjectArg() {
|
public void testOneObjectArg() {
|
||||||
mockCollaborator.oneObjectArg(this.testBeanProxy);
|
mockCollaborator.oneObjectArg(this.testBeanProxy);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneIntAndOneObjectArgs() {
|
public void testOneIntAndOneObjectArgs() {
|
||||||
mockCollaborator.oneIntAndOneObject(5,this.testBeanProxy);
|
mockCollaborator.oneIntAndOneObject(5,this.testBeanProxy);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNeedsJoinPoint() {
|
public void testNeedsJoinPoint() {
|
||||||
mockCollaborator.needsJoinPoint("getAge");
|
mockCollaborator.needsJoinPoint("getAge");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNeedsJoinPointStaticPart() {
|
public void testNeedsJoinPointStaticPart() {
|
||||||
mockCollaborator.needsJoinPointStaticPart("getAge");
|
mockCollaborator.needsJoinPointStaticPart("getAge");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturningString() {
|
public void testReturningString() {
|
||||||
mockCollaborator.oneString("adrian");
|
mockCollaborator.oneString("adrian");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setName("adrian");
|
testBeanProxy.setName("adrian");
|
||||||
testBeanProxy.getName();
|
testBeanProxy.getName();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturningObject() {
|
public void testReturningObject() {
|
||||||
mockCollaborator.oneObjectArg(this.testBeanTarget);
|
mockCollaborator.oneObjectArg(this.testBeanTarget);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.returnsThis();
|
testBeanProxy.returnsThis();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturningBean() {
|
public void testReturningBean() {
|
||||||
mockCollaborator.oneTestBeanArg(this.testBeanTarget);
|
mockCollaborator.oneTestBeanArg(this.testBeanTarget);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.returnsThis();
|
testBeanProxy.returnsThis();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturningBeanArray() {
|
public void testReturningBeanArray() {
|
||||||
this.testBeanTarget.setSpouse(new TestBean());
|
this.testBeanTarget.setSpouse(new TestBean());
|
||||||
ITestBean[] spouses = (ITestBean[]) this.testBeanTarget.getSpouses();
|
ITestBean[] spouses = (ITestBean[]) this.testBeanTarget.getSpouses();
|
||||||
mockCollaborator.testBeanArrayArg(spouses);
|
mockCollaborator.testBeanArrayArg(spouses);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getSpouses();
|
testBeanProxy.getSpouses();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNoInvokeWhenReturningParameterTypeDoesNotMatch() {
|
public void testNoInvokeWhenReturningParameterTypeDoesNotMatch() {
|
||||||
// we need a strict mock for this...
|
// we need a strict mock for this...
|
||||||
mockControl = MockControl.createControl(AfterReturningAdviceBindingCollaborator.class);
|
mockCollaborator = createMock(AfterReturningAdviceBindingCollaborator.class);
|
||||||
mockCollaborator = (AfterReturningAdviceBindingCollaborator) mockControl.getMock();
|
|
||||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
|
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setSpouse(this.testBeanProxy);
|
testBeanProxy.setSpouse(this.testBeanProxy);
|
||||||
testBeanProxy.getSpouse();
|
testBeanProxy.getSpouse();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturningByType() {
|
public void testReturningByType() {
|
||||||
mockCollaborator.objectMatchNoArgs();
|
mockCollaborator.objectMatchNoArgs();
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.returnsThis();
|
testBeanProxy.returnsThis();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturningPrimitive() {
|
public void testReturningPrimitive() {
|
||||||
mockCollaborator.oneInt(20);
|
mockCollaborator.oneInt(20);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(20);
|
testBeanProxy.setAge(20);
|
||||||
testBeanProxy.haveBirthday();
|
testBeanProxy.haveBirthday();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final class AfterReturningAdviceBindingTestAspect extends AdviceBindingTestAspect {
|
||||||
|
|
||||||
|
private AfterReturningAdviceBindingCollaborator getCollaborator() {
|
||||||
|
return (AfterReturningAdviceBindingCollaborator) this.collaborator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oneString(String name) {
|
||||||
|
getCollaborator().oneString(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oneTestBeanArg(TestBean bean) {
|
||||||
|
getCollaborator().oneTestBeanArg(bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBeanArrayArg(ITestBean[] beans) {
|
||||||
|
getCollaborator().testBeanArrayArg(beans);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void objectMatchNoArgs() {
|
||||||
|
getCollaborator().objectMatchNoArgs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stringMatchNoArgs() {
|
||||||
|
getCollaborator().stringMatchNoArgs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oneInt(int result) {
|
||||||
|
getCollaborator().oneInt(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AfterReturningAdviceBindingCollaborator extends AdviceBindingCollaborator {
|
||||||
|
|
||||||
|
void oneString(String s);
|
||||||
|
void oneTestBeanArg(TestBean b);
|
||||||
|
void testBeanArrayArg(ITestBean[] b);
|
||||||
|
void objectMatchNoArgs();
|
||||||
|
void stringMatchNoArgs();
|
||||||
|
void oneInt(int result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aspect used as part of before advice binding tests.
|
|
||||||
* @author Adrian Colyer
|
|
||||||
*/
|
|
||||||
public class AfterThrowingAdviceBindingTestAspect {
|
|
||||||
|
|
||||||
// collaborator interface that makes it easy to test this aspect is
|
|
||||||
// working as expected through mocking.
|
|
||||||
public interface AfterThrowingAdviceBindingCollaborator {
|
|
||||||
void noArgs();
|
|
||||||
void oneThrowable(Throwable t);
|
|
||||||
void oneRuntimeException(RuntimeException re);
|
|
||||||
void noArgsOnThrowableMatch();
|
|
||||||
void noArgsOnRuntimeExceptionMatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AfterThrowingAdviceBindingCollaborator collaborator = null;
|
|
||||||
|
|
||||||
public void setCollaborator(AfterThrowingAdviceBindingCollaborator aCollaborator) {
|
|
||||||
this.collaborator = aCollaborator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void noArgs() {
|
|
||||||
this.collaborator.noArgs();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void oneThrowable(Throwable t) {
|
|
||||||
this.collaborator.oneThrowable(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void oneRuntimeException(RuntimeException ex) {
|
|
||||||
this.collaborator.oneRuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void noArgsOnThrowableMatch() {
|
|
||||||
this.collaborator.noArgsOnThrowableMatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void noArgsOnRuntimeExceptionMatch() {
|
|
||||||
this.collaborator.noArgsOnRuntimeExceptionMatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,132 +16,136 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.easymock.MockControl;
|
import static org.easymock.EasyMock.*;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.AfterThrowingAdviceBindingTestAspect.AfterThrowingAdviceBindingCollaborator;
|
import org.springframework.aop.aspectj.AfterThrowingAdviceBindingTestAspect.AfterThrowingAdviceBindingCollaborator;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for various parameter binding scenarios with before advice.
|
* Tests for various parameter binding scenarios with before advice.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AfterThrowingAdviceBindingTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class AfterThrowingAdviceBindingTests {
|
||||||
|
|
||||||
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect;
|
|
||||||
|
|
||||||
private ITestBean testBean;
|
private ITestBean testBean;
|
||||||
|
|
||||||
private MockControl mockControl;
|
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect;
|
||||||
|
|
||||||
private AfterThrowingAdviceBindingCollaborator mockCollaborator;
|
private AfterThrowingAdviceBindingCollaborator mockCollaborator;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("afterThrowing-advice-tests.xml", getClass());
|
||||||
|
|
||||||
public void setAfterAdviceAspect(AfterThrowingAdviceBindingTestAspect anAspect) {
|
testBean = (ITestBean) ctx.getBean("testBean");
|
||||||
this.afterThrowingAdviceAspect = anAspect;
|
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||||
}
|
|
||||||
|
|
||||||
public void setTestBean(ITestBean aBean) throws Exception {
|
mockCollaborator = createNiceMock(AfterThrowingAdviceBindingCollaborator.class);
|
||||||
this.testBean = aBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "afterThrowing-advice-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
|
||||||
mockControl = MockControl.createNiceControl(AfterThrowingAdviceBindingCollaborator.class);
|
|
||||||
mockCollaborator = (AfterThrowingAdviceBindingCollaborator) mockControl.getMock();
|
|
||||||
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
// Simple test to ensure all is well with the XML file.
|
public void tearDown() {
|
||||||
// Note that this implicitly tests that the arg-names binding is working.
|
verify(mockCollaborator);
|
||||||
public void testParse() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleAfterThrowing() {
|
@Test(expected=Throwable.class)
|
||||||
|
public void testSimpleAfterThrowing() throws Throwable {
|
||||||
mockCollaborator.noArgs();
|
mockCollaborator.noArgs();
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
try {
|
|
||||||
this.testBean.exceptional(new Throwable());
|
this.testBean.exceptional(new Throwable());
|
||||||
fail("should throw exception");
|
|
||||||
} catch (Throwable t) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
mockControl.verify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAfterThrowingWithBinding() {
|
@Test(expected=Throwable.class)
|
||||||
|
public void testAfterThrowingWithBinding() throws Throwable {
|
||||||
Throwable t = new Throwable();
|
Throwable t = new Throwable();
|
||||||
mockCollaborator.oneThrowable(t);
|
mockCollaborator.oneThrowable(t);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
try {
|
|
||||||
this.testBean.exceptional(t);
|
this.testBean.exceptional(t);
|
||||||
fail("should throw exception");
|
|
||||||
} catch (Throwable x) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
mockControl.verify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAfterThrowingWithNamedTypeRestriction() {
|
@Test(expected=Throwable.class)
|
||||||
|
public void testAfterThrowingWithNamedTypeRestriction() throws Throwable {
|
||||||
Throwable t = new Throwable();
|
Throwable t = new Throwable();
|
||||||
// need a strict mock for this test...
|
// need a strict mock for this test...
|
||||||
mockControl = MockControl.createControl(AfterThrowingAdviceBindingCollaborator.class);
|
mockCollaborator = createMock(AfterThrowingAdviceBindingCollaborator.class);
|
||||||
mockCollaborator = (AfterThrowingAdviceBindingCollaborator) mockControl.getMock();
|
|
||||||
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
|
|
||||||
mockCollaborator.noArgs();
|
mockCollaborator.noArgs();
|
||||||
mockCollaborator.oneThrowable(t);
|
mockCollaborator.oneThrowable(t);
|
||||||
mockCollaborator.noArgsOnThrowableMatch();
|
mockCollaborator.noArgsOnThrowableMatch();
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
try {
|
|
||||||
this.testBean.exceptional(t);
|
this.testBean.exceptional(t);
|
||||||
fail("should throw exception");
|
|
||||||
} catch (Throwable x) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
mockControl.verify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAfterThrowingWithRuntimeExceptionBinding() {
|
@Test(expected=Throwable.class)
|
||||||
|
public void testAfterThrowingWithRuntimeExceptionBinding() throws Throwable {
|
||||||
RuntimeException ex = new RuntimeException();
|
RuntimeException ex = new RuntimeException();
|
||||||
mockCollaborator.oneRuntimeException(ex);
|
mockCollaborator.oneRuntimeException(ex);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
try {
|
|
||||||
this.testBean.exceptional(ex);
|
this.testBean.exceptional(ex);
|
||||||
fail("should throw exception");
|
|
||||||
} catch (Throwable x) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
mockControl.verify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAfterThrowingWithTypeSpecified() {
|
@Test(expected=Throwable.class)
|
||||||
|
public void testAfterThrowingWithTypeSpecified() throws Throwable {
|
||||||
mockCollaborator.noArgsOnThrowableMatch();
|
mockCollaborator.noArgsOnThrowableMatch();
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
try {
|
|
||||||
this.testBean.exceptional(new Throwable());
|
this.testBean.exceptional(new Throwable());
|
||||||
fail("should throw exception");
|
|
||||||
} catch (Throwable t) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
mockControl.verify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAfterThrowingWithRuntimeTypeSpecified() {
|
@Test(expected=Throwable.class)
|
||||||
|
public void testAfterThrowingWithRuntimeTypeSpecified() throws Throwable {
|
||||||
mockCollaborator.noArgsOnRuntimeExceptionMatch();
|
mockCollaborator.noArgsOnRuntimeExceptionMatch();
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
try {
|
|
||||||
this.testBean.exceptional(new RuntimeException());
|
this.testBean.exceptional(new RuntimeException());
|
||||||
fail("should throw exception");
|
verify(mockCollaborator);
|
||||||
} catch (Throwable t) {
|
}
|
||||||
// no-op
|
|
||||||
}
|
}
|
||||||
mockControl.verify();
|
|
||||||
|
|
||||||
|
final class AfterThrowingAdviceBindingTestAspect {
|
||||||
|
|
||||||
|
// collaborator interface that makes it easy to test this aspect is
|
||||||
|
// working as expected through mocking.
|
||||||
|
public interface AfterThrowingAdviceBindingCollaborator {
|
||||||
|
void noArgs();
|
||||||
|
void oneThrowable(Throwable t);
|
||||||
|
void oneRuntimeException(RuntimeException re);
|
||||||
|
void noArgsOnThrowableMatch();
|
||||||
|
void noArgsOnRuntimeExceptionMatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AfterThrowingAdviceBindingCollaborator collaborator = null;
|
||||||
|
|
||||||
|
public void setCollaborator(AfterThrowingAdviceBindingCollaborator aCollaborator) {
|
||||||
|
this.collaborator = aCollaborator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void noArgs() {
|
||||||
|
this.collaborator.noArgs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oneThrowable(Throwable t) {
|
||||||
|
this.collaborator.oneThrowable(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oneRuntimeException(RuntimeException ex) {
|
||||||
|
this.collaborator.oneRuntimeException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void noArgsOnThrowableMatch() {
|
||||||
|
this.collaborator.noArgsOnThrowableMatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void noArgsOnRuntimeExceptionMatch() {
|
||||||
|
this.collaborator.noArgsOnRuntimeExceptionMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,71 +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;
|
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aspect used as part of before advice binding tests.
|
|
||||||
*
|
|
||||||
* @author Adrian Colyer
|
|
||||||
*/
|
|
||||||
public class AroundAdviceBindingTestAspect {
|
|
||||||
|
|
||||||
private AroundAdviceBindingCollaborator collaborator = null;
|
|
||||||
|
|
||||||
public void setCollaborator(AroundAdviceBindingCollaborator aCollaborator) {
|
|
||||||
this.collaborator = aCollaborator;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "advice" methods
|
|
||||||
public void oneIntArg(ProceedingJoinPoint pjp, int age) throws Throwable {
|
|
||||||
this.collaborator.oneIntArg(age);
|
|
||||||
pjp.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int oneObjectArg(ProceedingJoinPoint pjp, Object bean) throws Throwable {
|
|
||||||
this.collaborator.oneObjectArg(bean);
|
|
||||||
return ((Integer) pjp.proceed()).intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void oneIntAndOneObject(ProceedingJoinPoint pjp, int x , Object o) throws Throwable {
|
|
||||||
this.collaborator.oneIntAndOneObject(x,o);
|
|
||||||
pjp.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int justJoinPoint(ProceedingJoinPoint pjp) throws Throwable {
|
|
||||||
this.collaborator.justJoinPoint(pjp.getSignature().getName());
|
|
||||||
return ((Integer) pjp.proceed()).intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collaborator interface that makes it easy to test this aspect
|
|
||||||
* is working as expected through mocking.
|
|
||||||
*/
|
|
||||||
public interface AroundAdviceBindingCollaborator {
|
|
||||||
|
|
||||||
void oneIntArg(int x);
|
|
||||||
|
|
||||||
void oneObjectArg(Object o);
|
|
||||||
|
|
||||||
void oneIntAndOneObject(int x, Object o);
|
|
||||||
|
|
||||||
void justJoinPoint(String s);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,66 +16,135 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.easymock.MockControl;
|
import static org.easymock.EasyMock.*;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.AroundAdviceBindingTestAspect.AroundAdviceBindingCollaborator;
|
import org.springframework.aop.aspectj.AroundAdviceBindingTestAspect.AroundAdviceBindingCollaborator;
|
||||||
|
import org.springframework.aop.framework.Advised;
|
||||||
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
import org.springframework.beans.ITestBean;
|
||||||
|
import org.springframework.beans.TestBean;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for various parameter binding scenarios with before advice.
|
* Tests for various parameter binding scenarios with before advice.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AroundAdviceBindingTests extends AbstractAdviceBindingTests {
|
public class AroundAdviceBindingTests {
|
||||||
|
|
||||||
private MockControl mockControl;
|
|
||||||
|
|
||||||
private AroundAdviceBindingCollaborator mockCollaborator;
|
private AroundAdviceBindingCollaborator mockCollaborator;
|
||||||
|
|
||||||
private AroundAdviceBindingTestAspect aroundAdviceAspect;
|
private ITestBean testBeanProxy;
|
||||||
|
|
||||||
|
private TestBean testBeanTarget;
|
||||||
|
|
||||||
public void setAroundAdviceAspect(AroundAdviceBindingTestAspect anAspect) {
|
protected ApplicationContext ctx;
|
||||||
this.aroundAdviceAspect = anAspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
protected String getConfigPath() {
|
||||||
return "around-advice-tests.xml";
|
return "around-advice-tests.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
@Before
|
||||||
super.onSetUp();
|
public void onSetUp() throws Exception {
|
||||||
mockControl = MockControl.createNiceControl(AroundAdviceBindingCollaborator.class);
|
ctx = new ClassPathXmlApplicationContext(getConfigPath(), getClass());
|
||||||
mockCollaborator = (AroundAdviceBindingCollaborator) mockControl.getMock();
|
|
||||||
|
AroundAdviceBindingTestAspect aroundAdviceAspect = ((AroundAdviceBindingTestAspect) ctx.getBean("testAspect"));
|
||||||
|
|
||||||
|
ITestBean injectedTestBean = (ITestBean) ctx.getBean("testBean");
|
||||||
|
assertTrue(AopUtils.isAopProxy(injectedTestBean));
|
||||||
|
|
||||||
|
this.testBeanProxy = injectedTestBean;
|
||||||
|
// we need the real target too, not just the proxy...
|
||||||
|
|
||||||
|
this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||||
|
|
||||||
|
mockCollaborator = createNiceMock(AroundAdviceBindingCollaborator.class);
|
||||||
aroundAdviceAspect.setCollaborator(mockCollaborator);
|
aroundAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneIntArg() {
|
public void testOneIntArg() {
|
||||||
mockCollaborator.oneIntArg(5);
|
mockCollaborator.oneIntArg(5);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneObjectArgBoundToTarget() {
|
public void testOneObjectArgBoundToTarget() {
|
||||||
mockCollaborator.oneObjectArg(this.testBeanTarget);
|
mockCollaborator.oneObjectArg(this.testBeanTarget);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneIntAndOneObjectArgs() {
|
public void testOneIntAndOneObjectArgs() {
|
||||||
mockCollaborator.oneIntAndOneObject(5, this.testBeanProxy);
|
mockCollaborator.oneIntAndOneObject(5, this.testBeanProxy);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJustJoinPoint() {
|
public void testJustJoinPoint() {
|
||||||
mockCollaborator.justJoinPoint("getAge");
|
mockCollaborator.justJoinPoint("getAge");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AroundAdviceBindingTestAspect {
|
||||||
|
|
||||||
|
private AroundAdviceBindingCollaborator collaborator = null;
|
||||||
|
|
||||||
|
public void setCollaborator(AroundAdviceBindingCollaborator aCollaborator) {
|
||||||
|
this.collaborator = aCollaborator;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "advice" methods
|
||||||
|
public void oneIntArg(ProceedingJoinPoint pjp, int age) throws Throwable {
|
||||||
|
this.collaborator.oneIntArg(age);
|
||||||
|
pjp.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int oneObjectArg(ProceedingJoinPoint pjp, Object bean) throws Throwable {
|
||||||
|
this.collaborator.oneObjectArg(bean);
|
||||||
|
return ((Integer) pjp.proceed()).intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oneIntAndOneObject(ProceedingJoinPoint pjp, int x , Object o) throws Throwable {
|
||||||
|
this.collaborator.oneIntAndOneObject(x,o);
|
||||||
|
pjp.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int justJoinPoint(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
|
this.collaborator.justJoinPoint(pjp.getSignature().getName());
|
||||||
|
return ((Integer) pjp.proceed()).intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collaborator interface that makes it easy to test this aspect
|
||||||
|
* is working as expected through mocking.
|
||||||
|
*/
|
||||||
|
public interface AroundAdviceBindingCollaborator {
|
||||||
|
|
||||||
|
void oneIntArg(int x);
|
||||||
|
|
||||||
|
void oneObjectArg(Object o);
|
||||||
|
|
||||||
|
void oneIntAndOneObject(int x, Object o);
|
||||||
|
|
||||||
|
void justJoinPoint(String s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,21 +16,26 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AroundAdviceCircularTests extends AroundAdviceBindingTests {
|
public final class AroundAdviceCircularTests extends AroundAdviceBindingTests {
|
||||||
|
|
||||||
protected String getConfigPath() {
|
protected String getConfigPath() {
|
||||||
return "around-advice-circular-tests.xml";
|
return "around-advice-circular-tests.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBothBeansAreProxies() {
|
public void testBothBeansAreProxies() {
|
||||||
Object tb = getApplicationContext().getBean("testBean");
|
Object tb = ctx.getBean("testBean");
|
||||||
assertTrue(AopUtils.isAopProxy(tb));
|
assertTrue(AopUtils.isAopProxy(tb));
|
||||||
Object tb2 = getApplicationContext().getBean("testBean2");
|
Object tb2 = ctx.getBean("testBean2");
|
||||||
assertTrue(AopUtils.isAopProxy(tb2));
|
assertTrue(AopUtils.isAopProxy(tb2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,52 +16,49 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.aop.MethodBeforeAdvice;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.beans.factory.BeanNameAware;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AspectAndAdvicePrecedenceTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class AspectAndAdvicePrecedenceTests {
|
||||||
|
|
||||||
private PrecedenceTestAspect highPrecedenceAspect;
|
private PrecedenceTestAspect highPrecedenceAspect;
|
||||||
|
|
||||||
private PrecedenceTestAspect lowPrecedenceAspect;
|
private PrecedenceTestAspect lowPrecedenceAspect;
|
||||||
private SimpleSpringBeforeAdvice lowPrecedenceSpringAdvice;
|
|
||||||
private SimpleSpringBeforeAdvice highPrecedenceSpringAdvice;
|
private SimpleSpringBeforeAdvice highPrecedenceSpringAdvice;
|
||||||
|
|
||||||
|
private SimpleSpringBeforeAdvice lowPrecedenceSpringAdvice;
|
||||||
|
|
||||||
private ITestBean testBean;
|
private ITestBean testBean;
|
||||||
|
|
||||||
|
|
||||||
public AspectAndAdvicePrecedenceTests() {
|
@Before
|
||||||
setAutowireMode(AUTOWIRE_BY_NAME);
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("advice-precedence-tests.xml", getClass());
|
||||||
|
highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect");
|
||||||
|
lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect");
|
||||||
|
highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice");
|
||||||
|
lowPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("lowPrecedenceSpringAdvice");
|
||||||
|
testBean = (ITestBean) ctx.getBean("testBean");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHighPrecedenceAspect(PrecedenceTestAspect highPrecedenceAspect) {
|
|
||||||
this.highPrecedenceAspect = highPrecedenceAspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLowPrecedenceAspect(PrecedenceTestAspect lowPrecedenceAspect) {
|
|
||||||
this.lowPrecedenceAspect = lowPrecedenceAspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLowPrecedenceSpringAdvice(SimpleSpringBeforeAdvice lowPrecedenceSpringAdvice) {
|
|
||||||
this.lowPrecedenceSpringAdvice = lowPrecedenceSpringAdvice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHighPrecedenceSpringAdvice(SimpleSpringBeforeAdvice highPrecedenceSpringAdvice) {
|
|
||||||
this.highPrecedenceSpringAdvice = highPrecedenceSpringAdvice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTestBean(ITestBean testBean) {
|
|
||||||
this.testBean = testBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "advice-precedence-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ========== end of test case set up, start of tests proper ===================
|
// ========== end of test case set up, start of tests proper ===================
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAdviceOrder() {
|
public void testAdviceOrder() {
|
||||||
PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator();
|
PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator();
|
||||||
this.highPrecedenceAspect.setCollaborator(collaborator);
|
this.highPrecedenceAspect.setCollaborator(collaborator);
|
||||||
|
@ -138,3 +135,107 @@ public class AspectAndAdvicePrecedenceTests extends AbstractDependencyInjectionS
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PrecedenceTestAspect implements BeanNameAware, Ordered {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||||
|
|
||||||
|
private Collaborator collaborator;
|
||||||
|
|
||||||
|
|
||||||
|
public void setBeanName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(int order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCollaborator(Collaborator collaborator) {
|
||||||
|
this.collaborator = collaborator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void beforeAdviceOne() {
|
||||||
|
this.collaborator.beforeAdviceOne(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void beforeAdviceTwo() {
|
||||||
|
this.collaborator.beforeAdviceTwo(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int aroundAdviceOne(ProceedingJoinPoint pjp) {
|
||||||
|
int ret = -1;
|
||||||
|
this.collaborator.aroundAdviceOne(this.name);
|
||||||
|
try {
|
||||||
|
ret = ((Integer)pjp.proceed()).intValue();
|
||||||
|
}
|
||||||
|
catch(Throwable t) { throw new RuntimeException(t); }
|
||||||
|
this.collaborator.aroundAdviceOne(this.name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int aroundAdviceTwo(ProceedingJoinPoint pjp) {
|
||||||
|
int ret = -1;
|
||||||
|
this.collaborator.aroundAdviceTwo(this.name);
|
||||||
|
try {
|
||||||
|
ret = ((Integer)pjp.proceed()).intValue();
|
||||||
|
}
|
||||||
|
catch(Throwable t) {throw new RuntimeException(t);}
|
||||||
|
this.collaborator.aroundAdviceTwo(this.name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterAdviceOne() {
|
||||||
|
this.collaborator.afterAdviceOne(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterAdviceTwo() {
|
||||||
|
this.collaborator.afterAdviceTwo(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public interface Collaborator {
|
||||||
|
|
||||||
|
void beforeAdviceOne(String beanName);
|
||||||
|
void beforeAdviceTwo(String beanName);
|
||||||
|
void aroundAdviceOne(String beanName);
|
||||||
|
void aroundAdviceTwo(String beanName);
|
||||||
|
void afterAdviceOne(String beanName);
|
||||||
|
void afterAdviceTwo(String beanName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleSpringBeforeAdvice implements MethodBeforeAdvice, BeanNameAware {
|
||||||
|
|
||||||
|
private PrecedenceTestAspect.Collaborator collaborator;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object)
|
||||||
|
*/
|
||||||
|
public void before(Method method, Object[] args, Object target)
|
||||||
|
throws Throwable {
|
||||||
|
this.collaborator.beforeAdviceOne(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCollaborator(PrecedenceTestAspect.Collaborator collaborator) {
|
||||||
|
this.collaborator = collaborator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setBeanName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -16,38 +16,35 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class AspectJExpressionPointcutAdvisorTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class AspectJExpressionPointcutAdvisorTests {
|
||||||
|
|
||||||
private ITestBean testBean;
|
private ITestBean testBean;
|
||||||
|
|
||||||
private CallCountingInterceptor interceptor;
|
private CallCountingInterceptor interceptor;
|
||||||
|
|
||||||
|
@Before
|
||||||
public void setTestBean(ITestBean testBean) {
|
public void setUp() {
|
||||||
this.testBean = testBean;
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("aspectj.xml", getClass());
|
||||||
|
testBean = (ITestBean) ctx.getBean("testBean");
|
||||||
|
interceptor = (CallCountingInterceptor) ctx.getBean("interceptor");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInterceptor(CallCountingInterceptor interceptor) {
|
@Test
|
||||||
this.interceptor = interceptor;
|
public void testPointcutting() {
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "aspectj.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
|
||||||
interceptor.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testPointcutting() throws Exception {
|
|
||||||
assertEquals("Count should be 0", 0, interceptor.getCount());
|
assertEquals("Count should be 0", 0, interceptor.getCount());
|
||||||
testBean.getSpouses();
|
testBean.getSpouses();
|
||||||
assertEquals("Count should be 1", 1, interceptor.getCount());
|
assertEquals("Count should be 1", 1, interceptor.getCount());
|
||||||
|
@ -56,3 +53,22 @@ public class AspectJExpressionPointcutAdvisorTests extends AbstractDependencyInj
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CallCountingInterceptor implements MethodInterceptor {
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||||
|
count++;
|
||||||
|
return methodInvocation.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
this.count = 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,37 +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 13-Feb-2006 by Adrian Colyer
|
|
||||||
*/
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used by before-advice-tests.xml
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public class AuthenticationLogger {
|
|
||||||
|
|
||||||
public void logAuthenticationAttempt(String username) {
|
|
||||||
System.out.println("User [" + username + "] attempting to authenticate");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class SecurityManager {
|
|
||||||
public boolean authenticate(String username, String password) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +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 15 Nov 2006 by Adrian Colyer
|
|
||||||
*/
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public class BeanNameAwareMixin implements BeanNameAware {
|
|
||||||
|
|
||||||
private String beanName;
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
|
||||||
*/
|
|
||||||
public void setBeanName(String name) {
|
|
||||||
this.beanName = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,46 +16,45 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
|
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for correct application of the bean() PCD for @AspectJ-based aspects.
|
* Test for correct application of the bean() PCD for @AspectJ-based aspects.
|
||||||
*
|
*
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class BeanNamePointcutAtAspectTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class BeanNamePointcutAtAspectTests {
|
||||||
|
|
||||||
protected ITestBean testBean1;
|
private ITestBean testBean1;
|
||||||
|
|
||||||
protected ITestBean testBean2;
|
private ITestBean testBean2;
|
||||||
|
|
||||||
protected ITestBean testBean3;
|
private ITestBean testBean3;
|
||||||
|
|
||||||
protected CounterAspect counterAspect;
|
private CounterAspect counterAspect;
|
||||||
|
|
||||||
|
|
||||||
public BeanNamePointcutAtAspectTests() {
|
@org.junit.Before
|
||||||
setPopulateProtectedVariables(true);
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bean-name-pointcut-atAspect-tests.xml", getClass());
|
||||||
|
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||||
|
testBean1 = (ITestBean) ctx.getBean("testBean1");
|
||||||
|
testBean2 = (ITestBean) ctx.getBean("testBean2");
|
||||||
|
testBean3 = (ITestBean) ctx.getBean("testBean3");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConfigPath() {
|
@Test
|
||||||
return "bean-name-pointcut-atAspect-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
|
||||||
counterAspect.count = 0;
|
|
||||||
super.onSetUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testMatchingBeanName() {
|
public void testMatchingBeanName() {
|
||||||
assertTrue("Expected a proxy", testBean1 instanceof Advised);
|
assertTrue("Expected a proxy", testBean1 instanceof Advised);
|
||||||
// Call two methods to test for SPR-3953-like condition
|
// Call two methods to test for SPR-3953-like condition
|
||||||
|
@ -64,12 +63,14 @@ public class BeanNamePointcutAtAspectTests extends AbstractDependencyInjectionSp
|
||||||
assertEquals(2 /*TODO: make this 3 when upgrading to AspectJ 1.6.0 and advice in CounterAspect are uncommented*/, counterAspect.count);
|
assertEquals(2 /*TODO: make this 3 when upgrading to AspectJ 1.6.0 and advice in CounterAspect are uncommented*/, counterAspect.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNonMatchingBeanName() {
|
public void testNonMatchingBeanName() {
|
||||||
assertFalse("Didn't expect a proxy", testBean3 instanceof Advised);
|
assertFalse("Didn't expect a proxy", testBean3 instanceof Advised);
|
||||||
testBean3.setAge(20);
|
testBean3.setAge(20);
|
||||||
assertEquals(0, counterAspect.count);
|
assertEquals(0, counterAspect.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testProgrammaticProxyCreation() {
|
public void testProgrammaticProxyCreation() {
|
||||||
ITestBean testBean = new TestBean();
|
ITestBean testBean = new TestBean();
|
||||||
|
|
||||||
|
@ -86,9 +87,11 @@ public class BeanNamePointcutAtAspectTests extends AbstractDependencyInjectionSp
|
||||||
assertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count);
|
assertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
public static class CounterAspect {
|
class CounterAspect {
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
|
@ -97,21 +100,4 @@ public class BeanNamePointcutAtAspectTests extends AbstractDependencyInjectionSp
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Pointcut("execution(* setAge(..)) && bean(testBean1)")
|
|
||||||
// public void testBean1SetAge() {}
|
|
||||||
//
|
|
||||||
// @Pointcut("execution(* setAge(..)) && bean(testBean2)")
|
|
||||||
// public void testBean2SetAge() {}
|
|
||||||
//
|
|
||||||
// @Before("testBean1SetAge()")
|
|
||||||
// public void increment1() {
|
|
||||||
// count++;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Before("testBean2SetAge()")
|
|
||||||
// public void increment2() {
|
|
||||||
// count++;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,51 +16,61 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.MethodBeforeAdvice;
|
import org.springframework.aop.MethodBeforeAdvice;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for correct application of the bean() PCD for XML-based AspectJ aspects.
|
* Test for correct application of the bean() PCD for XML-based AspectJ aspects.
|
||||||
*
|
*
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class BeanNamePointcutTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class BeanNamePointcutTests {
|
||||||
|
|
||||||
protected ITestBean testBean1;
|
private ITestBean testBean1;
|
||||||
protected ITestBean testBean2;
|
private ITestBean testBean2;
|
||||||
protected ITestBean testBeanContainingNestedBean;
|
private ITestBean testBeanContainingNestedBean;
|
||||||
protected Map testFactoryBean1;
|
private Map<?, ?> testFactoryBean1;
|
||||||
protected Map testFactoryBean2;
|
private Map<?, ?> testFactoryBean2;
|
||||||
protected Counter counterAspect;
|
private Counter counterAspect;
|
||||||
|
|
||||||
protected ITestBean interceptThis;
|
private ITestBean interceptThis;
|
||||||
protected ITestBean dontInterceptThis;
|
private ITestBean dontInterceptThis;
|
||||||
protected TestInterceptor testInterceptor;
|
private TestInterceptor testInterceptor;
|
||||||
|
|
||||||
|
private ClassPathXmlApplicationContext ctx;
|
||||||
|
|
||||||
|
|
||||||
public BeanNamePointcutTests() {
|
@Before
|
||||||
setPopulateProtectedVariables(true);
|
public void setUp() {
|
||||||
|
ctx = new ClassPathXmlApplicationContext("bean-name-pointcut-tests.xml", getClass());
|
||||||
|
testBean1 = (ITestBean) ctx.getBean("testBean1");
|
||||||
|
testBean2 = (ITestBean) ctx.getBean("testBean2");
|
||||||
|
testBeanContainingNestedBean = (ITestBean) ctx.getBean("testBeanContainingNestedBean");
|
||||||
|
testFactoryBean1 = (Map<?, ?>) ctx.getBean("testFactoryBean1");
|
||||||
|
testFactoryBean2 = (Map<?, ?>) ctx.getBean("testFactoryBean2");
|
||||||
|
counterAspect = (Counter) ctx.getBean("counterAspect");
|
||||||
|
interceptThis = (ITestBean) ctx.getBean("interceptThis");
|
||||||
|
dontInterceptThis = (ITestBean) ctx.getBean("dontInterceptThis");
|
||||||
|
testInterceptor = (TestInterceptor) ctx.getBean("testInterceptor");
|
||||||
|
|
||||||
|
counterAspect.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "bean-name-pointcut-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
|
||||||
this.counterAspect.reset();
|
|
||||||
super.onSetUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// We don't need to test all combination of pointcuts due to BeanNamePointcutMatchingTests
|
// We don't need to test all combination of pointcuts due to BeanNamePointcutMatchingTests
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMatchingBeanName() {
|
public void testMatchingBeanName() {
|
||||||
assertTrue("Matching bean must be advised (proxied)", this.testBean1 instanceof Advised);
|
assertTrue("Matching bean must be advised (proxied)", this.testBean1 instanceof Advised);
|
||||||
// Call two methods to test for SPR-3953-like condition
|
// Call two methods to test for SPR-3953-like condition
|
||||||
|
@ -69,34 +79,39 @@ public class BeanNamePointcutTests extends AbstractDependencyInjectionSpringCont
|
||||||
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
|
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNonMatchingBeanName() {
|
public void testNonMatchingBeanName() {
|
||||||
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBean2 instanceof Advised);
|
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBean2 instanceof Advised);
|
||||||
this.testBean2.setAge(20);
|
this.testBean2.setAge(20);
|
||||||
assertEquals("Advice must *not* have been executed", 0, this.counterAspect.getCount());
|
assertEquals("Advice must *not* have been executed", 0, this.counterAspect.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNonMatchingNestedBeanName() {
|
public void testNonMatchingNestedBeanName() {
|
||||||
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBeanContainingNestedBean.getDoctor() instanceof Advised);
|
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBeanContainingNestedBean.getDoctor() instanceof Advised);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMatchingFactoryBeanObject() {
|
public void testMatchingFactoryBeanObject() {
|
||||||
assertTrue("Matching bean must be advised (proxied)", this.testFactoryBean1 instanceof Advised);
|
assertTrue("Matching bean must be advised (proxied)", this.testFactoryBean1 instanceof Advised);
|
||||||
assertEquals("myValue", this.testFactoryBean1.get("myKey"));
|
assertEquals("myValue", this.testFactoryBean1.get("myKey"));
|
||||||
assertEquals("myValue", this.testFactoryBean1.get("myKey"));
|
assertEquals("myValue", this.testFactoryBean1.get("myKey"));
|
||||||
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
|
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
|
||||||
FactoryBean fb = (FactoryBean) getApplicationContext().getBean("&testFactoryBean1");
|
FactoryBean<?> fb = (FactoryBean<?>) ctx.getBean("&testFactoryBean1");
|
||||||
assertTrue("FactoryBean itself must *not* be advised", !(fb instanceof Advised));
|
assertTrue("FactoryBean itself must *not* be advised", !(fb instanceof Advised));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMatchingFactoryBeanItself() {
|
public void testMatchingFactoryBeanItself() {
|
||||||
assertTrue("Matching bean must *not* be advised (proxied)", !(this.testFactoryBean2 instanceof Advised));
|
assertTrue("Matching bean must *not* be advised (proxied)", !(this.testFactoryBean2 instanceof Advised));
|
||||||
FactoryBean fb = (FactoryBean) getApplicationContext().getBean("&testFactoryBean2");
|
FactoryBean<?> fb = (FactoryBean<?>) ctx.getBean("&testFactoryBean2");
|
||||||
assertTrue("FactoryBean itself must be advised", fb instanceof Advised);
|
assertTrue("FactoryBean itself must be advised", fb instanceof Advised);
|
||||||
assertTrue(Map.class.isAssignableFrom(fb.getObjectType()));
|
assertTrue(Map.class.isAssignableFrom(fb.getObjectType()));
|
||||||
assertTrue(Map.class.isAssignableFrom(fb.getObjectType()));
|
assertTrue(Map.class.isAssignableFrom(fb.getObjectType()));
|
||||||
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
|
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPointcutAdvisorCombination() {
|
public void testPointcutAdvisorCombination() {
|
||||||
assertTrue("Matching bean must be advised (proxied)", this.interceptThis instanceof Advised);
|
assertTrue("Matching bean must be advised (proxied)", this.interceptThis instanceof Advised);
|
||||||
assertFalse("Non-matching bean must *not* be advised (proxied)", this.dontInterceptThis instanceof Advised);
|
assertFalse("Non-matching bean must *not* be advised (proxied)", this.dontInterceptThis instanceof Advised);
|
||||||
|
|
|
@ -16,75 +16,109 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.easymock.MockControl;
|
import static org.easymock.EasyMock.*;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
|
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
|
||||||
|
import org.springframework.aop.framework.Advised;
|
||||||
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
import org.springframework.beans.ITestBean;
|
||||||
|
import org.springframework.beans.TestBean;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for various parameter binding scenarios with before advice.
|
* Tests for various parameter binding scenarios with before advice.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class BeforeAdviceBindingTests extends AbstractAdviceBindingTests {
|
public final class BeforeAdviceBindingTests {
|
||||||
|
|
||||||
private AdviceBindingTestAspect beforeAdviceAspect;
|
|
||||||
|
|
||||||
private MockControl mockControl;
|
|
||||||
|
|
||||||
private AdviceBindingCollaborator mockCollaborator;
|
private AdviceBindingCollaborator mockCollaborator;
|
||||||
|
|
||||||
|
private ITestBean testBeanProxy;
|
||||||
|
|
||||||
public void setBeforeAdviceAspect(AdviceBindingTestAspect anAspect) {
|
private TestBean testBeanTarget;
|
||||||
this.beforeAdviceAspect = anAspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
protected String getConfigPath() {
|
||||||
return "before-advice-tests.xml";
|
return "before-advice-tests.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
@Before
|
||||||
super.onSetUp();
|
public void setUp() throws Exception {
|
||||||
mockControl = MockControl.createNiceControl(AdviceBindingCollaborator.class);
|
ApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigPath(), getClass());
|
||||||
mockCollaborator = (AdviceBindingCollaborator) mockControl.getMock();
|
|
||||||
|
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||||
|
assertTrue(AopUtils.isAopProxy(testBeanProxy));
|
||||||
|
|
||||||
|
// we need the real target too, not just the proxy...
|
||||||
|
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||||
|
|
||||||
|
AdviceBindingTestAspect beforeAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||||
|
|
||||||
|
mockCollaborator = createNiceMock(AdviceBindingCollaborator.class);
|
||||||
beforeAdviceAspect.setCollaborator(mockCollaborator);
|
beforeAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneIntArg() {
|
public void testOneIntArg() {
|
||||||
mockCollaborator.oneIntArg(5);
|
mockCollaborator.oneIntArg(5);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneObjectArgBoundToProxyUsingThis() {
|
public void testOneObjectArgBoundToProxyUsingThis() {
|
||||||
mockCollaborator.oneObjectArg(this.testBeanProxy);
|
mockCollaborator.oneObjectArg(this.testBeanProxy);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneIntAndOneObjectArgs() {
|
public void testOneIntAndOneObjectArgs() {
|
||||||
mockCollaborator.oneIntAndOneObject(5,this.testBeanTarget);
|
mockCollaborator.oneIntAndOneObject(5,this.testBeanTarget);
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.setAge(5);
|
testBeanProxy.setAge(5);
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNeedsJoinPoint() {
|
public void testNeedsJoinPoint() {
|
||||||
mockCollaborator.needsJoinPoint("getAge");
|
mockCollaborator.needsJoinPoint("getAge");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNeedsJoinPointStaticPart() {
|
public void testNeedsJoinPointStaticPart() {
|
||||||
mockCollaborator.needsJoinPointStaticPart("getAge");
|
mockCollaborator.needsJoinPointStaticPart("getAge");
|
||||||
mockControl.replay();
|
replay(mockCollaborator);
|
||||||
testBeanProxy.getAge();
|
testBeanProxy.getAge();
|
||||||
mockControl.verify();
|
verify(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticationLogger {
|
||||||
|
|
||||||
|
public void logAuthenticationAttempt(String username) {
|
||||||
|
System.out.println("User [" + username + "] attempting to authenticate");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class SecurityManager {
|
||||||
|
public boolean authenticate(String username, String password) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author robh
|
|
||||||
*/
|
|
||||||
class CallCountingInterceptor implements MethodInterceptor {
|
|
||||||
|
|
||||||
private int count;
|
|
||||||
|
|
||||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
|
||||||
count++;
|
|
||||||
return methodInvocation.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
this.count = 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,7 +21,7 @@ package org.springframework.aop.aspectj;
|
||||||
*
|
*
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
*/
|
*/
|
||||||
public class Counter implements ICounter {
|
final class Counter implements ICounter {
|
||||||
|
|
||||||
private int count;
|
private int count;
|
||||||
|
|
||||||
|
|
|
@ -16,46 +16,45 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
import org.springframework.beans.factory.BeanNameAware;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class DeclarationOrderIndependenceTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class DeclarationOrderIndependenceTests {
|
||||||
|
|
||||||
private TopsyTurvyAspect aspect;
|
private TopsyTurvyAspect aspect;
|
||||||
|
|
||||||
private TopsyTurvyTarget target;
|
private TopsyTurvyTarget target;
|
||||||
|
|
||||||
|
|
||||||
public DeclarationOrderIndependenceTests() {
|
@Before
|
||||||
setAutowireMode(AUTOWIRE_BY_NAME);
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("topsy-turvy-aspect.xml", getClass());
|
||||||
|
aspect = (TopsyTurvyAspect) ctx.getBean("topsyTurvyAspect");
|
||||||
|
target = (TopsyTurvyTarget) ctx.getBean("topsyTurvyTarget");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTopsyTurvyAspect(TopsyTurvyAspect aspect) {
|
@Test
|
||||||
this.aspect = aspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTopsyTurvyTarget(TopsyTurvyTarget target) {
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "topsy-turvy-aspect.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testTargetIsSerializable() {
|
public void testTargetIsSerializable() {
|
||||||
assertTrue("target bean is serializable",this.target instanceof Serializable);
|
assertTrue("target bean is serializable",this.target instanceof Serializable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetIsBeanNameAware() {
|
public void testTargetIsBeanNameAware() {
|
||||||
assertTrue("target bean is bean name aware",this.target instanceof BeanNameAware);
|
assertTrue("target bean is bean name aware",this.target instanceof BeanNameAware);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBeforeAdviceFiringOk() {
|
public void testBeforeAdviceFiringOk() {
|
||||||
AspectCollaborator collab = new AspectCollaborator();
|
AspectCollaborator collab = new AspectCollaborator();
|
||||||
this.aspect.setCollaborator(collab);
|
this.aspect.setCollaborator(collab);
|
||||||
|
@ -63,6 +62,7 @@ public class DeclarationOrderIndependenceTests extends AbstractDependencyInjecti
|
||||||
assertTrue("before advice fired",collab.beforeFired);
|
assertTrue("before advice fired",collab.beforeFired);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAroundAdviceFiringOk() {
|
public void testAroundAdviceFiringOk() {
|
||||||
AspectCollaborator collab = new AspectCollaborator();
|
AspectCollaborator collab = new AspectCollaborator();
|
||||||
this.aspect.setCollaborator(collab);
|
this.aspect.setCollaborator(collab);
|
||||||
|
@ -70,6 +70,7 @@ public class DeclarationOrderIndependenceTests extends AbstractDependencyInjecti
|
||||||
assertTrue("around advice fired",collab.aroundFired);
|
assertTrue("around advice fired",collab.aroundFired);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAfterReturningFiringOk() {
|
public void testAfterReturningFiringOk() {
|
||||||
AspectCollaborator collab = new AspectCollaborator();
|
AspectCollaborator collab = new AspectCollaborator();
|
||||||
this.aspect.setCollaborator(collab);
|
this.aspect.setCollaborator(collab);
|
||||||
|
@ -77,7 +78,90 @@ public class DeclarationOrderIndependenceTests extends AbstractDependencyInjecti
|
||||||
assertTrue("after returning advice fired",collab.afterReturningFired);
|
assertTrue("after returning advice fired",collab.afterReturningFired);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AspectCollaborator implements TopsyTurvyAspect.Collaborator {
|
|
||||||
|
/** public visibility is required */
|
||||||
|
public static class BeanNameAwareMixin implements BeanNameAware {
|
||||||
|
|
||||||
|
private String beanName;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setBeanName(String name) {
|
||||||
|
this.beanName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** public visibility is required */
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public static class SerializableMixin implements Serializable {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TopsyTurvyAspect {
|
||||||
|
|
||||||
|
interface Collaborator {
|
||||||
|
void beforeAdviceFired();
|
||||||
|
void afterReturningAdviceFired();
|
||||||
|
void aroundAdviceFired();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collaborator collaborator;
|
||||||
|
|
||||||
|
public void setCollaborator(Collaborator collaborator) {
|
||||||
|
this.collaborator = collaborator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void before() {
|
||||||
|
this.collaborator.beforeAdviceFired();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterReturning() {
|
||||||
|
this.collaborator.afterReturningAdviceFired();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
|
Object ret = pjp.proceed();
|
||||||
|
this.collaborator.aroundAdviceFired();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface TopsyTurvyTarget {
|
||||||
|
|
||||||
|
public abstract void doSomething();
|
||||||
|
|
||||||
|
public abstract int getX();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TopsyTurvyTargetImpl implements TopsyTurvyTarget {
|
||||||
|
|
||||||
|
private int x = 5;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.aop.aspectj.TopsyTurvyTarget#doSomething()
|
||||||
|
*/
|
||||||
|
public void doSomething() {
|
||||||
|
this.x = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.aop.aspectj.TopsyTurvyTarget#getX()
|
||||||
|
*/
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AspectCollaborator implements TopsyTurvyAspect.Collaborator {
|
||||||
|
|
||||||
public boolean afterReturningFired = false;
|
public boolean afterReturningFired = false;
|
||||||
public boolean aroundFired = false;
|
public boolean aroundFired = false;
|
||||||
|
@ -105,6 +189,3 @@ public class DeclarationOrderIndependenceTests extends AbstractDependencyInjecti
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,62 +16,49 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class DeclareParentsDelegateRefTests extends AbstractDependencyInjectionSpringContextTests {
|
public class DeclareParentsDelegateRefTests {
|
||||||
|
|
||||||
protected NoMethodsBean noMethodsBean;
|
protected NoMethodsBean noMethodsBean;
|
||||||
|
|
||||||
protected CounterImpl counter;
|
protected Counter counter;
|
||||||
|
|
||||||
|
|
||||||
public DeclareParentsDelegateRefTests() {
|
@Before
|
||||||
setPopulateProtectedVariables(true);
|
public void setUp() {
|
||||||
}
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("declare-parents-delegate-ref-tests.xml", getClass());
|
||||||
|
noMethodsBean = (NoMethodsBean) ctx.getBean("noMethodsBean");
|
||||||
protected void onSetUp() throws Exception {
|
counter = (Counter) ctx.getBean("counter");
|
||||||
counter.reset();
|
counter.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConfigPath() {
|
@Test
|
||||||
return "declare-parents-delegate-ref-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testIntroductionWasMade() {
|
public void testIntroductionWasMade() {
|
||||||
assertTrue("Introduction must have been made", noMethodsBean instanceof Counter);
|
assertTrue("Introduction must have been made", noMethodsBean instanceof ICounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIntroductionDelegation() {
|
public void testIntroductionDelegation() {
|
||||||
((Counter)noMethodsBean).increment();
|
((ICounter)noMethodsBean).increment();
|
||||||
assertEquals("Delegate's counter should be updated", 1, counter.count);
|
assertEquals("Delegate's counter should be updated", 1, counter.getCount());
|
||||||
}
|
|
||||||
|
|
||||||
public static interface NoMethodsBean {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NoMethodsBeanImpl implements NoMethodsBean {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static interface Counter {
|
|
||||||
public void increment();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class CounterImpl implements Counter {
|
|
||||||
|
|
||||||
int count;
|
|
||||||
|
|
||||||
public void increment() {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface NoMethodsBean {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class NoMethodsBeanImpl implements NoMethodsBean {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,18 +16,46 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.framework.Lockable;
|
import org.springframework.aop.framework.Lockable;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
import org.springframework.beans.ITestBean;
|
||||||
|
import org.springframework.beans.TestBean;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class DeclareParentsTests extends AbstractAdviceBindingTests {
|
public final class DeclareParentsTests {
|
||||||
|
|
||||||
|
private ITestBean testBeanProxy;
|
||||||
|
|
||||||
|
private TestBean testBeanTarget;
|
||||||
|
|
||||||
|
private ApplicationContext ctx;
|
||||||
|
|
||||||
protected String getConfigPath() {
|
protected String getConfigPath() {
|
||||||
return "declare-parents-tests.xml";
|
return "declare-parents-tests.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
ctx = new ClassPathXmlApplicationContext(getConfigPath(), getClass());
|
||||||
|
|
||||||
|
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||||
|
assertTrue(AopUtils.isAopProxy(testBeanProxy));
|
||||||
|
|
||||||
|
// we need the real target too, not just the proxy...
|
||||||
|
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIntroductionWasMade() {
|
public void testIntroductionWasMade() {
|
||||||
assertTrue("Introduction must have been made", testBeanProxy instanceof Lockable);
|
assertTrue("Introduction must have been made", testBeanProxy instanceof Lockable);
|
||||||
}
|
}
|
||||||
|
@ -36,8 +64,9 @@ public class DeclareParentsTests extends AbstractAdviceBindingTests {
|
||||||
// to org.springframework..* it also matches introduction.
|
// to org.springframework..* it also matches introduction.
|
||||||
// Perhaps generated advisor bean definition could be made to depend
|
// Perhaps generated advisor bean definition could be made to depend
|
||||||
// on the introduction, in which case this would not be a problem.
|
// on the introduction, in which case this would not be a problem.
|
||||||
|
@Test
|
||||||
public void testLockingWorks() {
|
public void testLockingWorks() {
|
||||||
Object introductionObject = applicationContext.getBean("introduction");
|
Object introductionObject = ctx.getBean("introduction");
|
||||||
assertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject));
|
assertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject));
|
||||||
|
|
||||||
Lockable lockable = (Lockable) testBeanProxy;
|
Lockable lockable = (Lockable) testBeanProxy;
|
||||||
|
@ -58,3 +87,14 @@ public class DeclareParentsTests extends AbstractAdviceBindingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class NonAnnotatedMakeLockable {
|
||||||
|
|
||||||
|
public void checkNotLocked(Lockable mixin) {
|
||||||
|
if (mixin.locked()) {
|
||||||
|
throw new IllegalStateException("locked");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ package org.springframework.aop.aspectj;
|
||||||
/**
|
/**
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
*/
|
*/
|
||||||
public interface ICounter {
|
interface ICounter {
|
||||||
|
|
||||||
void increment();
|
void increment();
|
||||||
|
|
||||||
|
|
|
@ -18,33 +18,27 @@ package org.springframework.aop.aspectj;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests to check if the first implicit join point argument is correctly processed.
|
* Tests to check if the first implicit join point argument is correctly processed.
|
||||||
* See SPR-3723 for more details.
|
* See SPR-3723 for more details.
|
||||||
*
|
*
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ImplicitJPArgumentMatchingAtAspectJTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class ImplicitJPArgumentMatchingAtAspectJTests {
|
||||||
protected TestBean testBean;
|
|
||||||
|
|
||||||
public ImplicitJPArgumentMatchingAtAspectJTests() {
|
|
||||||
setPopulateProtectedVariables(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "implicit-jp-argument-matching-atAspectJ-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAspect() {
|
public void testAspect() {
|
||||||
// nothing to really test; it is enough if we don't get error while creating app context
|
// nothing to really test; it is enough if we don't get error while creating app context
|
||||||
testBean.setCountry("US");
|
new ClassPathXmlApplicationContext("implicit-jp-argument-matching-atAspectJ-tests.xml", getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
public static class CounterAtAspectJAspect {
|
static class CounterAtAspectJAspect {
|
||||||
@Around(value="execution(* org.springframework.beans.TestBean.*(..)) and this(bean) and args(argument)",
|
@Around(value="execution(* org.springframework.beans.TestBean.*(..)) and this(bean) and args(argument)",
|
||||||
argNames="bean,argument")
|
argNames="bean,argument")
|
||||||
public void increment(ProceedingJoinPoint pjp, TestBean bean, Object argument) throws Throwable {
|
public void increment(ProceedingJoinPoint pjp, TestBean bean, Object argument) throws Throwable {
|
||||||
|
|
|
@ -16,32 +16,25 @@
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.springframework.beans.TestBean;
|
import org.junit.Test;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests to check if the first implicit join point argument is correctly processed.
|
* Tests to check if the first implicit join point argument is correctly processed.
|
||||||
* See SPR-3723 for more details.
|
* See SPR-3723 for more details.
|
||||||
*
|
*
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ImplicitJPArgumentMatchingTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class ImplicitJPArgumentMatchingTests {
|
||||||
protected TestBean testBean;
|
|
||||||
|
|
||||||
public ImplicitJPArgumentMatchingTests() {
|
|
||||||
setPopulateProtectedVariables(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "implicit-jp-argument-matching-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAspect() {
|
public void testAspect() {
|
||||||
// nothing to really test; it is enough if we don't get error while creating app context
|
// nothing to really test; it is enough if we don't get error while creating app context
|
||||||
testBean.setCountry("US");
|
new ClassPathXmlApplicationContext("implicit-jp-argument-matching-tests.xml", getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CounterAspect {
|
static class CounterAspect {
|
||||||
public void increment(ProceedingJoinPoint pjp, Object bean, Object argument) throws Throwable {
|
public void increment(ProceedingJoinPoint pjp, Object bean, Object argument) throws Throwable {
|
||||||
pjp.proceed();
|
pjp.proceed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +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;
|
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Ramnivas Laddad
|
|
||||||
*/
|
|
||||||
public class JoinPointMonitorAspect {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The counter property is purposefully not used in the aspect to avoid distraction
|
|
||||||
* from the main bug -- merely needing a dependency on an advised bean
|
|
||||||
* is sufficient to reproduce the bug.
|
|
||||||
*/
|
|
||||||
private ICounter counter;
|
|
||||||
|
|
||||||
int beforeExecutions;
|
|
||||||
int aroundExecutions;
|
|
||||||
|
|
||||||
public void before() {
|
|
||||||
beforeExecutions++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
|
||||||
aroundExecutions++;
|
|
||||||
return pjp.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICounter getCounter() {
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCounter(ICounter counter) {
|
|
||||||
this.counter = counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,58 +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;
|
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Around;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Ramnivas Laddad
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
public class JoinPointMonitorAtAspectJAspect {
|
|
||||||
/* The counter property is purposefully not used in the aspect to avoid distraction
|
|
||||||
* from the main bug -- merely needing a dependency on an advised bean
|
|
||||||
* is sufficient to reproduce the bug.
|
|
||||||
*/
|
|
||||||
private ICounter counter;
|
|
||||||
|
|
||||||
int beforeExecutions;
|
|
||||||
int aroundExecutions;
|
|
||||||
|
|
||||||
@Before("execution(* increment*())")
|
|
||||||
public void before() {
|
|
||||||
beforeExecutions++;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Around("execution(* increment*())")
|
|
||||||
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
|
||||||
aroundExecutions++;
|
|
||||||
return pjp.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICounter getCounter() {
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCounter(ICounter counter) {
|
|
||||||
this.counter = counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
|
|
||||||
import org.springframework.aop.framework.Lockable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Rod Johnson
|
|
||||||
*/
|
|
||||||
public class NonAnnotatedMakeLockable {
|
|
||||||
|
|
||||||
public void checkNotLocked(Lockable mixin) {
|
|
||||||
if (mixin.locked()) {
|
|
||||||
throw new IllegalStateException("locked");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,32 +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;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aspect used as part of overloaded advice tests.
|
|
||||||
* @author Adrian Colyer
|
|
||||||
*/
|
|
||||||
public class OverloadedAdviceTestAspect {
|
|
||||||
|
|
||||||
public void myBeforeAdvice(String name) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
|
|
||||||
public void myBeforeAdvice(int age) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,12 +28,12 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class OverloadedAdviceTests {
|
public final class OverloadedAdviceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() {
|
public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() {
|
||||||
try {
|
try {
|
||||||
new ClassPathXmlApplicationContext("org/springframework/aop/aspectj/overloaded-advice-tests.xml");
|
new ClassPathXmlApplicationContext("overloaded-advice-tests.xml", getClass());
|
||||||
}
|
}
|
||||||
catch (BeanCreationException ex) {
|
catch (BeanCreationException ex) {
|
||||||
Throwable cause = ex.getRootCause();
|
Throwable cause = ex.getRootCause();
|
||||||
|
@ -46,7 +46,7 @@ public class OverloadedAdviceTests {
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() {
|
public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() {
|
||||||
try {
|
try {
|
||||||
new ClassPathXmlApplicationContext("org/springframework/aop/aspectj/ambiguous-advice-tests.xml");
|
new ClassPathXmlApplicationContext("ambiguous-advice-tests.xml", getClass());
|
||||||
}
|
}
|
||||||
catch (BeanCreationException ex) {
|
catch (BeanCreationException ex) {
|
||||||
Throwable cause = ex.getRootCause();
|
Throwable cause = ex.getRootCause();
|
||||||
|
@ -57,3 +57,16 @@ public class OverloadedAdviceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class OverloadedAdviceTestAspect {
|
||||||
|
|
||||||
|
public void myBeforeAdvice(String name) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
public void myBeforeAdvice(int age) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,103 +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;
|
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
|
||||||
import org.springframework.core.Ordered;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used in advice precedence tests (surprise!)
|
|
||||||
*
|
|
||||||
* @author Adrian Colyer
|
|
||||||
*/
|
|
||||||
public class PrecedenceTestAspect implements BeanNameAware, Ordered {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
|
||||||
|
|
||||||
private Collaborator collaborator;
|
|
||||||
|
|
||||||
|
|
||||||
public void setBeanName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrder(int order) {
|
|
||||||
this.order = order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOrder() {
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollaborator(Collaborator collaborator) {
|
|
||||||
this.collaborator = collaborator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeAdviceOne() {
|
|
||||||
this.collaborator.beforeAdviceOne(this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeAdviceTwo() {
|
|
||||||
this.collaborator.beforeAdviceTwo(this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int aroundAdviceOne(ProceedingJoinPoint pjp) {
|
|
||||||
int ret = -1;
|
|
||||||
this.collaborator.aroundAdviceOne(this.name);
|
|
||||||
try {
|
|
||||||
ret = ((Integer)pjp.proceed()).intValue();
|
|
||||||
}
|
|
||||||
catch(Throwable t) { throw new RuntimeException(t); }
|
|
||||||
this.collaborator.aroundAdviceOne(this.name);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int aroundAdviceTwo(ProceedingJoinPoint pjp) {
|
|
||||||
int ret = -1;
|
|
||||||
this.collaborator.aroundAdviceTwo(this.name);
|
|
||||||
try {
|
|
||||||
ret = ((Integer)pjp.proceed()).intValue();
|
|
||||||
}
|
|
||||||
catch(Throwable t) {throw new RuntimeException(t);}
|
|
||||||
this.collaborator.aroundAdviceTwo(this.name);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterAdviceOne() {
|
|
||||||
this.collaborator.afterAdviceOne(this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterAdviceTwo() {
|
|
||||||
this.collaborator.afterAdviceTwo(this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public interface Collaborator {
|
|
||||||
|
|
||||||
void beforeAdviceOne(String beanName);
|
|
||||||
void beforeAdviceTwo(String beanName);
|
|
||||||
void aroundAdviceOne(String beanName);
|
|
||||||
void aroundAdviceTwo(String beanName);
|
|
||||||
void afterAdviceOne(String beanName);
|
|
||||||
void afterAdviceTwo(String beanName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,70 +16,59 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.junit.Before;
|
||||||
import org.springframework.core.JdkVersion;
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for SPR-3522. Arguments changed on a call to proceed should be
|
* Test for SPR-3522. Arguments changed on a call to proceed should be
|
||||||
* visible to advice further down the invocation chain.
|
* visible to advice further down the invocation chain.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ProceedTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class ProceedTests {
|
||||||
|
|
||||||
private SimpleBean testBean;
|
private SimpleBean testBean;
|
||||||
|
|
||||||
private ProceedTestingAspect testAspect;
|
private ProceedTestingAspect firstTestAspect;
|
||||||
|
|
||||||
private ProceedTestingAspect secondTestAspect;
|
private ProceedTestingAspect secondTestAspect;
|
||||||
|
|
||||||
|
|
||||||
public ProceedTests() {
|
@Before
|
||||||
setAutowireMode(AUTOWIRE_BY_NAME);
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("proceedTests.xml", getClass());
|
||||||
|
testBean = (SimpleBean) ctx.getBean("testBean");
|
||||||
|
firstTestAspect = (ProceedTestingAspect) ctx.getBean("firstTestAspect");
|
||||||
|
secondTestAspect = (ProceedTestingAspect) ctx.getBean("secondTestAspect");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] getConfigLocations() {
|
@Test
|
||||||
return new String[] {"org/springframework/aop/aspectj/proceedTests.xml"};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstTestAspect(ProceedTestingAspect anAspect) {
|
|
||||||
this.testAspect = anAspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSecondTestAspect(ProceedTestingAspect anAspect) {
|
|
||||||
this.secondTestAspect = anAspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTestBean(SimpleBean aBean) {
|
|
||||||
this.testBean = aBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testSimpleProceedWithChangedArgs() {
|
public void testSimpleProceedWithChangedArgs() {
|
||||||
this.testBean.setName("abc");
|
this.testBean.setName("abc");
|
||||||
assertEquals("Name changed in around advice", "ABC", this.testBean.getName());
|
assertEquals("Name changed in around advice", "ABC", this.testBean.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetArgsIsDefensive() {
|
public void testGetArgsIsDefensive() {
|
||||||
this.testBean.setAge(5);
|
this.testBean.setAge(5);
|
||||||
assertEquals("getArgs is defensive", 5, this.testBean.getAge());
|
assertEquals("getArgs is defensive", 5, this.testBean.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testProceedWithArgsInSameAspect() {
|
public void testProceedWithArgsInSameAspect() {
|
||||||
if (!JdkVersion.isAtLeastJava15()) {
|
|
||||||
// Doesn't work on JDK 1.4 for some reason...
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.testBean.setMyFloat(1.0F);
|
this.testBean.setMyFloat(1.0F);
|
||||||
assertTrue("value changed in around advice", this.testBean.getMyFloat() > 1.9F);
|
assertTrue("value changed in around advice", this.testBean.getMyFloat() > 1.9F);
|
||||||
assertTrue("changed value visible to next advice in chain", this.testAspect.getLastBeforeFloatValue() > 1.9F);
|
assertTrue("changed value visible to next advice in chain", this.firstTestAspect.getLastBeforeFloatValue() > 1.9F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testProceedWithArgsAcrossAspects() {
|
public void testProceedWithArgsAcrossAspects() {
|
||||||
this.testBean.setSex("male");
|
this.testBean.setSex("male");
|
||||||
assertEquals("value changed in around advice","MALE", this.testBean.getSex());
|
assertEquals("value changed in around advice","MALE", this.testBean.getSex());
|
||||||
|
@ -88,20 +77,23 @@ public class ProceedTests extends AbstractDependencyInjectionSpringContextTests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface SimpleBean {
|
|
||||||
|
|
||||||
public void setName(String name);
|
|
||||||
public String getName();
|
|
||||||
public void setAge(int age);
|
|
||||||
public int getAge();
|
|
||||||
public void setMyFloat(float f);
|
|
||||||
public float getMyFloat();
|
|
||||||
public void setSex(String sex);
|
|
||||||
public String getSex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class SimpleBeanImpl implements SimpleBean {
|
interface SimpleBean {
|
||||||
|
|
||||||
|
void setName(String name);
|
||||||
|
String getName();
|
||||||
|
void setAge(int age);
|
||||||
|
int getAge();
|
||||||
|
void setMyFloat(float f);
|
||||||
|
float getMyFloat();
|
||||||
|
void setSex(String sex);
|
||||||
|
String getSex();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleBeanImpl implements SimpleBean {
|
||||||
|
|
||||||
private int age;
|
private int age;
|
||||||
private float aFloat;
|
private float aFloat;
|
||||||
|
@ -142,7 +134,7 @@ public class ProceedTests extends AbstractDependencyInjectionSpringContextTests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ProceedTestingAspect implements Ordered {
|
class ProceedTestingAspect implements Ordered {
|
||||||
|
|
||||||
private String lastBeforeStringValue;
|
private String lastBeforeStringValue;
|
||||||
private String lastAroundStringValue;
|
private String lastAroundStringValue;
|
||||||
|
@ -211,4 +203,3 @@ public class ProceedTests extends AbstractDependencyInjectionSpringContextTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,6 +18,10 @@ package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
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.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
@ -31,7 +35,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class PropertyDependentAspectTests {
|
public final class PropertyDependentAspectTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropertyDependentAspectWithPropertyDeclaredBeforeAdvice() throws Exception {
|
public void testPropertyDependentAspectWithPropertyDeclaredBeforeAdvice() throws Exception {
|
||||||
|
@ -76,3 +80,68 @@ public class PropertyDependentAspectTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JoinPointMonitorAspect {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The counter property is purposefully not used in the aspect to avoid distraction
|
||||||
|
* from the main bug -- merely needing a dependency on an advised bean
|
||||||
|
* is sufficient to reproduce the bug.
|
||||||
|
*/
|
||||||
|
private ICounter counter;
|
||||||
|
|
||||||
|
int beforeExecutions;
|
||||||
|
int aroundExecutions;
|
||||||
|
|
||||||
|
public void before() {
|
||||||
|
beforeExecutions++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
|
aroundExecutions++;
|
||||||
|
return pjp.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICounter getCounter() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCounter(ICounter counter) {
|
||||||
|
this.counter = counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Aspect
|
||||||
|
class JoinPointMonitorAtAspectJAspect {
|
||||||
|
/* The counter property is purposefully not used in the aspect to avoid distraction
|
||||||
|
* from the main bug -- merely needing a dependency on an advised bean
|
||||||
|
* is sufficient to reproduce the bug.
|
||||||
|
*/
|
||||||
|
private ICounter counter;
|
||||||
|
|
||||||
|
int beforeExecutions;
|
||||||
|
int aroundExecutions;
|
||||||
|
|
||||||
|
@Before("execution(* increment*())")
|
||||||
|
public void before() {
|
||||||
|
beforeExecutions++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Around("execution(* increment*())")
|
||||||
|
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
|
aroundExecutions++;
|
||||||
|
return pjp.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICounter getCounter() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCounter(ICounter counter) {
|
||||||
|
this.counter = counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,28 +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 15 Nov 2006 by Adrian Colyer
|
|
||||||
*/
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public class SerializableMixin implements Serializable {
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,33 +16,37 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See SPR-1682.
|
* See SPR-1682.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class SharedPointcutWithArgsMismatch extends AbstractDependencyInjectionSpringContextTests {
|
public final class SharedPointcutWithArgsMismatchTests {
|
||||||
|
|
||||||
private ToBeAdvised toBeAdvised;
|
private ToBeAdvised toBeAdvised;
|
||||||
|
|
||||||
|
|
||||||
public void setToBeAdvised(ToBeAdvised tba) {
|
@Before
|
||||||
this.toBeAdvised = tba;
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("args-mismatch.xml", getClass());
|
||||||
|
toBeAdvised = (ToBeAdvised) ctx.getBean("toBeAdvised");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConfigPath() {
|
@Test
|
||||||
return "args-mismatch.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testMismatchedArgBinding() {
|
public void testMismatchedArgBinding() {
|
||||||
this.toBeAdvised.foo("Hello");
|
this.toBeAdvised.foo("Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ToBeAdvised {
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ToBeAdvised {
|
||||||
|
|
||||||
public void foo(String s) {
|
public void foo(String s) {
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
|
@ -50,7 +54,7 @@ public class SharedPointcutWithArgsMismatch extends AbstractDependencyInjectionS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class MyAspect {
|
class MyAspect {
|
||||||
|
|
||||||
public void doBefore(int x) {
|
public void doBefore(int x) {
|
||||||
System.out.println(x);
|
System.out.println(x);
|
||||||
|
@ -61,4 +65,3 @@ public class SharedPointcutWithArgsMismatch extends AbstractDependencyInjectionS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
|
@ -1,55 +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 14-Feb-2006 by Adrian Colyer
|
|
||||||
*/
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import org.springframework.aop.MethodBeforeAdvice;
|
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used as part of aspect precedence tests
|
|
||||||
*
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public class SimpleSpringBeforeAdvice implements MethodBeforeAdvice, BeanNameAware {
|
|
||||||
|
|
||||||
private PrecedenceTestAspect.Collaborator collaborator;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object)
|
|
||||||
*/
|
|
||||||
public void before(Method method, Object[] args, Object target)
|
|
||||||
throws Throwable {
|
|
||||||
this.collaborator.beforeAdviceOne(this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollaborator(PrecedenceTestAspect.Collaborator collaborator) {
|
|
||||||
this.collaborator = collaborator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
|
||||||
*/
|
|
||||||
public void setBeanName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +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;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
|
|
||||||
// strange looking interfaces are just to set up certain test conditions...
|
|
||||||
interface NonSerializableFoo { void foo(); }
|
|
||||||
interface SerializableFoo extends Serializable { void foo(); }
|
|
||||||
|
|
||||||
class SubtypeMatchingTestClassA implements NonSerializableFoo {
|
|
||||||
|
|
||||||
public void foo() {}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class SubtypeMatchingTestClassB implements SerializableFoo {
|
|
||||||
|
|
||||||
public void foo() {}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Bar { void bar(Object o); }
|
|
||||||
|
|
||||||
class SubtypeMatchingTestClassC implements Bar {
|
|
||||||
|
|
||||||
public void bar(Object o) {}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,13 +16,20 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class SubtypeSensitiveMatchingTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class SubtypeSensitiveMatchingTests {
|
||||||
|
|
||||||
private NonSerializableFoo nonSerializableBean;
|
private NonSerializableFoo nonSerializableBean;
|
||||||
|
|
||||||
|
@ -31,36 +38,56 @@ public class SubtypeSensitiveMatchingTests extends AbstractDependencyInjectionSp
|
||||||
private Bar bar;
|
private Bar bar;
|
||||||
|
|
||||||
|
|
||||||
public void setNonSerializableFoo(NonSerializableFoo aBean) {
|
@Before
|
||||||
this.nonSerializableBean = aBean;
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("subtype-sensitive-matching.xml", getClass());
|
||||||
|
nonSerializableBean = (NonSerializableFoo) ctx.getBean("testClassA");
|
||||||
|
serializableBean = (SerializableFoo) ctx.getBean("testClassB");
|
||||||
|
bar = (Bar) ctx.getBean("testClassC");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSerializableFoo(SerializableFoo aBean) {
|
@Test
|
||||||
this.serializableBean = aBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBar(Bar aBean) {
|
|
||||||
this.bar = aBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "subtype-sensitive-matching.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testBeansAreProxiedOnStaticMatch() {
|
public void testBeansAreProxiedOnStaticMatch() {
|
||||||
assertTrue("bean with serializable type should be proxied",
|
assertTrue("bean with serializable type should be proxied",
|
||||||
this.serializableBean instanceof Advised);
|
this.serializableBean instanceof Advised);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBeansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() {
|
public void testBeansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() {
|
||||||
assertFalse("bean with non-serializable type should not be proxied",
|
assertFalse("bean with non-serializable type should not be proxied",
|
||||||
this.nonSerializableBean instanceof Advised);
|
this.nonSerializableBean instanceof Advised);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBeansThatDoNotMatchBasedOnOtherTestAreProxied() {
|
public void testBeansThatDoNotMatchBasedOnOtherTestAreProxied() {
|
||||||
assertTrue("bean with args check should be proxied",
|
assertTrue("bean with args check should be proxied",
|
||||||
this.bar instanceof Advised);
|
this.bar instanceof Advised);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//strange looking interfaces are just to set up certain test conditions...
|
||||||
|
interface NonSerializableFoo { void foo(); }
|
||||||
|
|
||||||
|
interface SerializableFoo extends Serializable { void foo(); }
|
||||||
|
|
||||||
|
class SubtypeMatchingTestClassA implements NonSerializableFoo {
|
||||||
|
|
||||||
|
public void foo() {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
class SubtypeMatchingTestClassB implements SerializableFoo {
|
||||||
|
|
||||||
|
public void foo() {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Bar { void bar(Object o); }
|
||||||
|
|
||||||
|
class SubtypeMatchingTestClassC implements Bar {
|
||||||
|
|
||||||
|
public void bar(Object o) {}
|
||||||
|
|
||||||
|
}
|
|
@ -16,42 +16,45 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
import org.junit.Before;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for target selection matching (see SPR-3783).
|
* Tests for target selection matching (see SPR-3783).
|
||||||
* Thanks to Tomasz Blachowicz for the bug report!
|
* Thanks to Tomasz Blachowicz for the bug report!
|
||||||
*
|
*
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class TargetPointcutSelectionTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class TargetPointcutSelectionTests {
|
||||||
|
|
||||||
protected TestInterface testImpl1;
|
public TestInterface testImpl1;
|
||||||
protected TestInterface testImpl2;
|
public TestInterface testImpl2;
|
||||||
protected TestAspect testAspectForTestImpl1;
|
public TestAspect testAspectForTestImpl1;
|
||||||
protected TestAspect testAspectForAbstractTestImpl;
|
public TestAspect testAspectForAbstractTestImpl;
|
||||||
protected TestInterceptor testInterceptor;
|
public TestInterceptor testInterceptor;
|
||||||
|
|
||||||
|
|
||||||
public TargetPointcutSelectionTests() {
|
@Before
|
||||||
setPopulateProtectedVariables(true);
|
public void setUp() {
|
||||||
}
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("targetPointcutSelectionTests.xml", getClass());
|
||||||
|
testImpl1 = (TestInterface) ctx.getBean("testImpl1");
|
||||||
|
testImpl2 = (TestInterface) ctx.getBean("testImpl2");
|
||||||
|
testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1");
|
||||||
|
testAspectForAbstractTestImpl = (TestAspect) ctx.getBean("testAspectForAbstractTestImpl");
|
||||||
|
testInterceptor = (TestInterceptor) ctx.getBean("testInterceptor");
|
||||||
|
|
||||||
protected String getConfigPath() {
|
|
||||||
return "targetPointcutSelectionTests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
|
||||||
testAspectForTestImpl1.count = 0;
|
testAspectForTestImpl1.count = 0;
|
||||||
testAspectForAbstractTestImpl.count = 0;
|
testAspectForAbstractTestImpl.count = 0;
|
||||||
testInterceptor.count = 0;
|
testInterceptor.count = 0;
|
||||||
super.onSetUp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetSelectionForMatchedType() {
|
public void testTargetSelectionForMatchedType() {
|
||||||
testImpl1.interfaceMethod();
|
testImpl1.interfaceMethod();
|
||||||
assertEquals("Should have been advised by POJO advice for impl", 1, testAspectForTestImpl1.count);
|
assertEquals("Should have been advised by POJO advice for impl", 1, testAspectForTestImpl1.count);
|
||||||
|
@ -59,6 +62,7 @@ public class TargetPointcutSelectionTests extends AbstractDependencyInjectionSpr
|
||||||
assertEquals("Should have been advised by advisor", 1, testInterceptor.count);
|
assertEquals("Should have been advised by advisor", 1, testInterceptor.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetNonSelectionForMismatchedType() {
|
public void testTargetNonSelectionForMismatchedType() {
|
||||||
testImpl2.interfaceMethod();
|
testImpl2.interfaceMethod();
|
||||||
assertEquals("Shouldn't have been advised by POJO advice for impl", 0, testAspectForTestImpl1.count);
|
assertEquals("Shouldn't have been advised by POJO advice for impl", 0, testAspectForTestImpl1.count);
|
||||||
|
|
|
@ -16,78 +16,87 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||||
protected TestInterface testBean;
|
public TestInterface testBean;
|
||||||
protected TestInterface testAnnotatedClassBean;
|
public TestInterface testAnnotatedClassBean;
|
||||||
protected TestInterface testAnnotatedMethodBean;
|
public TestInterface testAnnotatedMethodBean;
|
||||||
|
|
||||||
protected Counter counter;
|
protected Counter counter;
|
||||||
|
|
||||||
public ThisAndTargetSelectionOnlyPointcutsAtAspectJTests() {
|
@org.junit.Before
|
||||||
setPopulateProtectedVariables(true);
|
public void setUp() {
|
||||||
}
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("this-and-target-selectionOnly-pointcuts-atAspectJ-tests.xml", getClass());
|
||||||
|
testBean = (TestInterface) ctx.getBean("testBean");
|
||||||
@Override
|
testAnnotatedClassBean = (TestInterface) ctx.getBean("testAnnotatedClassBean");
|
||||||
protected void onSetUp() throws Exception {
|
testAnnotatedMethodBean = (TestInterface) ctx.getBean("testAnnotatedMethodBean");
|
||||||
super.onSetUp();
|
counter = (Counter) ctx.getBean("counter");
|
||||||
counter.reset();
|
counter.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConfigPath() {
|
@Test
|
||||||
return "this-and-target-selectionOnly-pointcuts-atAspectJ-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testThisAsClassDoesNotMatch() {
|
public void testThisAsClassDoesNotMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(0, counter.thisAsClassCounter);
|
assertEquals(0, counter.thisAsClassCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsInterfaceMatch() {
|
public void testThisAsInterfaceMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.thisAsInterfaceCounter);
|
assertEquals(1, counter.thisAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetAsClassDoesMatch() {
|
public void testTargetAsClassDoesMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.targetAsClassCounter);
|
assertEquals(1, counter.targetAsClassCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetAsInterfaceMatch() {
|
public void testTargetAsInterfaceMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.targetAsInterfaceCounter);
|
assertEquals(1, counter.targetAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
|
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(0, counter.thisAsClassAndTargetAsClassCounter);
|
assertEquals(0, counter.thisAsClassAndTargetAsClassCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
|
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAtTargetClassAnnotationMatch() {
|
public void testAtTargetClassAnnotationMatch() {
|
||||||
testAnnotatedClassBean.doIt();
|
testAnnotatedClassBean.doIt();
|
||||||
assertEquals(1, counter.atTargetClassAnnotationCounter);
|
assertEquals(1, counter.atTargetClassAnnotationCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAtAnnotationMethodAnnotationMatch() {
|
public void testAtAnnotationMethodAnnotationMatch() {
|
||||||
testAnnotatedMethodBean.doIt();
|
testAnnotatedMethodBean.doIt();
|
||||||
assertEquals(1, counter.atAnnotationMethodAnnotationCounter);
|
assertEquals(1, counter.atAnnotationMethodAnnotationCounter);
|
||||||
|
|
|
@ -16,28 +16,43 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
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 Ramnivas Laddad
|
* @author Ramnivas Laddad
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ThisAndTargetSelectionOnlyPointcutsTests extends AbstractDependencyInjectionSpringContextTests {
|
public final class ThisAndTargetSelectionOnlyPointcutsTests {
|
||||||
protected TestInterface testBean;
|
|
||||||
|
|
||||||
protected Counter thisAsClassCounter;
|
private TestInterface testBean;
|
||||||
protected Counter thisAsInterfaceCounter;
|
|
||||||
protected Counter targetAsClassCounter;
|
|
||||||
protected Counter targetAsInterfaceCounter;
|
|
||||||
protected Counter thisAsClassAndTargetAsClassCounter;
|
|
||||||
protected Counter thisAsInterfaceAndTargetAsInterfaceCounter;
|
|
||||||
protected Counter thisAsInterfaceAndTargetAsClassCounter;
|
|
||||||
|
|
||||||
public ThisAndTargetSelectionOnlyPointcutsTests() {
|
private Counter thisAsClassCounter;
|
||||||
setPopulateProtectedVariables(true);
|
private Counter thisAsInterfaceCounter;
|
||||||
}
|
private Counter targetAsClassCounter;
|
||||||
|
private Counter targetAsInterfaceCounter;
|
||||||
|
private Counter thisAsClassAndTargetAsClassCounter;
|
||||||
|
private Counter thisAsInterfaceAndTargetAsInterfaceCounter;
|
||||||
|
private Counter thisAsInterfaceAndTargetAsClassCounter;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("this-and-target-selectionOnly-pointcuts-tests.xml", getClass());
|
||||||
|
|
||||||
|
testBean = (TestInterface) ctx.getBean("testBean");
|
||||||
|
|
||||||
|
thisAsClassCounter = (Counter) ctx.getBean("thisAsClassCounter");
|
||||||
|
thisAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceCounter");
|
||||||
|
targetAsClassCounter = (Counter) ctx.getBean("targetAsClassCounter");
|
||||||
|
targetAsInterfaceCounter = (Counter) ctx.getBean("targetAsInterfaceCounter");
|
||||||
|
|
||||||
|
thisAsClassAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsClassAndTargetAsClassCounter");
|
||||||
|
thisAsInterfaceAndTargetAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsInterfaceCounter");
|
||||||
|
thisAsInterfaceAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsClassCounter");
|
||||||
|
|
||||||
protected void onSetUp() throws Exception {
|
|
||||||
super.onSetUp();
|
|
||||||
thisAsClassCounter.reset();
|
thisAsClassCounter.reset();
|
||||||
thisAsInterfaceCounter.reset();
|
thisAsInterfaceCounter.reset();
|
||||||
targetAsClassCounter.reset();
|
targetAsClassCounter.reset();
|
||||||
|
@ -48,52 +63,57 @@ public class ThisAndTargetSelectionOnlyPointcutsTests extends AbstractDependency
|
||||||
thisAsInterfaceAndTargetAsClassCounter.reset();
|
thisAsInterfaceAndTargetAsClassCounter.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConfigPath() {
|
@Test
|
||||||
return "this-and-target-selectionOnly-pointcuts-tests.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testThisAsClassDoesNotMatch() {
|
public void testThisAsClassDoesNotMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(0, thisAsClassCounter.getCount());
|
assertEquals(0, thisAsClassCounter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsInterfaceMatch() {
|
public void testThisAsInterfaceMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, thisAsInterfaceCounter.getCount());
|
assertEquals(1, thisAsInterfaceCounter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetAsClassDoesMatch() {
|
public void testTargetAsClassDoesMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, targetAsClassCounter.getCount());
|
assertEquals(1, targetAsClassCounter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetAsInterfaceMatch() {
|
public void testTargetAsInterfaceMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, targetAsInterfaceCounter.getCount());
|
assertEquals(1, targetAsInterfaceCounter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
|
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(0, thisAsClassAndTargetAsClassCounter.getCount());
|
assertEquals(0, thisAsClassAndTargetAsClassCounter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount());
|
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
|
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||||
testBean.doIt();
|
testBean.doIt();
|
||||||
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount());
|
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface TestInterface {
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface TestInterface {
|
||||||
public void doIt();
|
public void doIt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestImpl implements TestInterface {
|
|
||||||
|
class TestImpl implements TestInterface {
|
||||||
public void doIt() {
|
public void doIt() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,53 +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 15 Nov 2006 by Adrian Colyer
|
|
||||||
*/
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public class TopsyTurvyAspect {
|
|
||||||
|
|
||||||
interface Collaborator {
|
|
||||||
void beforeAdviceFired();
|
|
||||||
void afterReturningAdviceFired();
|
|
||||||
void aroundAdviceFired();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Collaborator collaborator;
|
|
||||||
|
|
||||||
public void setCollaborator(Collaborator collaborator) {
|
|
||||||
this.collaborator = collaborator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void before() {
|
|
||||||
this.collaborator.beforeAdviceFired();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterReturning() {
|
|
||||||
this.collaborator.afterReturningAdviceFired();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
|
||||||
Object ret = pjp.proceed();
|
|
||||||
this.collaborator.aroundAdviceFired();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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 15 Nov 2006 by Adrian Colyer
|
|
||||||
*/
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public interface TopsyTurvyTarget {
|
|
||||||
|
|
||||||
public abstract void doSomething();
|
|
||||||
|
|
||||||
public abstract int getX();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,42 +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 15 Nov 2006 by Adrian Colyer
|
|
||||||
*/
|
|
||||||
package org.springframework.aop.aspectj;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Colyer
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public class TopsyTurvyTargetImpl implements TopsyTurvyTarget {
|
|
||||||
|
|
||||||
private int x = 5;
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.aop.aspectj.TopsyTurvyTarget#doSomething()
|
|
||||||
*/
|
|
||||||
public void doSomething() {
|
|
||||||
this.x = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.aop.aspectj.TopsyTurvyTarget#getX()
|
|
||||||
*/
|
|
||||||
public int getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -14,7 +14,7 @@
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
</aop:config>
|
</aop:config>
|
||||||
|
|
||||||
<bean id="someBean" class="org.springframework.aop.aspectj.SharedPointcutWithArgsMismatch$ToBeAdvised"/>
|
<bean id="toBeAdvised" class="org.springframework.aop.aspectj.ToBeAdvised"/>
|
||||||
|
|
||||||
<bean id="testAspect" class="org.springframework.aop.aspectj.SharedPointcutWithArgsMismatch$MyAspect"/>
|
<bean id="testAspect" class="org.springframework.aop.aspectj.MyAspect"/>
|
||||||
</beans>
|
</beans>
|
|
@ -11,5 +11,5 @@
|
||||||
<bean id="testBean2" class="org.springframework.beans.TestBean"/>
|
<bean id="testBean2" class="org.springframework.beans.TestBean"/>
|
||||||
<bean id="testBean3" class="org.springframework.beans.TestBean"/>
|
<bean id="testBean3" class="org.springframework.beans.TestBean"/>
|
||||||
|
|
||||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.BeanNamePointcutAtAspectTests$CounterAspect"/>
|
<bean id="counterAspect" class="org.springframework.aop.aspectj.CounterAspect"/>
|
||||||
</beans>
|
</beans>
|
|
@ -8,15 +8,15 @@
|
||||||
<aop:config>
|
<aop:config>
|
||||||
<aop:aspect id="testAspect">
|
<aop:aspect id="testAspect">
|
||||||
<aop:declare-parents
|
<aop:declare-parents
|
||||||
types-matching="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests.NoMethodsBean+"
|
types-matching="org.springframework.aop.aspectj.NoMethodsBean+"
|
||||||
implement-interface="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests$Counter"
|
implement-interface="org.springframework.aop.aspectj.ICounter"
|
||||||
delegate-ref="counter"
|
delegate-ref="counter"
|
||||||
/>
|
/>
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
</aop:config>
|
</aop:config>
|
||||||
|
|
||||||
<bean id="noMethodsBean" class="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests$NoMethodsBeanImpl"/>
|
<bean id="noMethodsBean" class="org.springframework.aop.aspectj.NoMethodsBeanImpl"/>
|
||||||
|
|
||||||
<bean id="counter" class="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests$CounterImpl"/>
|
<bean id="counter" class="org.springframework.aop.aspectj.Counter"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
</aop:config>
|
</aop:config>
|
||||||
|
|
||||||
<bean id="testBean" class="org.springframework.aop.aspectj.ProceedTests$SimpleBeanImpl"/>
|
<bean id="testBean" class="org.springframework.aop.aspectj.SimpleBeanImpl"/>
|
||||||
|
|
||||||
<bean id="firstTestAspect" class="org.springframework.aop.aspectj.ProceedTests$ProceedTestingAspect">
|
<bean id="firstTestAspect" class="org.springframework.aop.aspectj.ProceedTestingAspect">
|
||||||
<property name="order" value="1"/>
|
<property name="order" value="1"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="secondTestAspect" class="org.springframework.aop.aspectj.ProceedTests$ProceedTestingAspect">
|
<bean id="secondTestAspect" class="org.springframework.aop.aspectj.ProceedTestingAspect">
|
||||||
<property name="order" value="2"/>
|
<property name="order" value="2"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
|
@ -9,56 +9,48 @@
|
||||||
<aop:config>
|
<aop:config>
|
||||||
<aop:aspect ref="thisAsClassCounter">
|
<aop:aspect ref="thisAsClassCounter">
|
||||||
<aop:before method="increment"
|
<aop:before method="increment"
|
||||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" />
|
pointcut="this(org.springframework.aop.aspectj.TestImpl)" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
|
|
||||||
<aop:aspect ref="thisAsInterfaceCounter">
|
<aop:aspect ref="thisAsInterfaceCounter">
|
||||||
<aop:before method="increment"
|
<aop:before method="increment"
|
||||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface)" />
|
pointcut="this(org.springframework.aop.aspectj.TestInterface)" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
|
|
||||||
<aop:aspect ref="targetAsClassCounter">
|
<aop:aspect ref="targetAsClassCounter">
|
||||||
<aop:before method="increment"
|
<aop:before method="increment"
|
||||||
pointcut="target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" />
|
pointcut="target(org.springframework.aop.aspectj.TestImpl)" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
|
|
||||||
<aop:aspect ref="targetAsInterfaceCounter">
|
<aop:aspect ref="targetAsInterfaceCounter">
|
||||||
<aop:before method="increment"
|
<aop:before method="increment"
|
||||||
pointcut="target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface)" />
|
pointcut="target(org.springframework.aop.aspectj.TestInterface)" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
|
|
||||||
<aop:aspect ref="thisAsClassAndTargetAsClassCounter">
|
<aop:aspect ref="thisAsClassAndTargetAsClassCounter">
|
||||||
<aop:before method="increment"
|
<aop:before method="increment"
|
||||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl) and target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" />
|
pointcut="this(org.springframework.aop.aspectj.TestImpl) and target(org.springframework.aop.aspectj.TestImpl)" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
|
|
||||||
<aop:aspect ref="thisAsInterfaceAndTargetAsInterfaceCounter">
|
<aop:aspect ref="thisAsInterfaceAndTargetAsInterfaceCounter">
|
||||||
<aop:before method="increment"
|
<aop:before method="increment"
|
||||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface) and target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface)" />
|
pointcut="this(org.springframework.aop.aspectj.TestInterface) and target(org.springframework.aop.aspectj.TestInterface)" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
|
|
||||||
<aop:aspect ref="thisAsInterfaceAndTargetAsClassCounter">
|
<aop:aspect ref="thisAsInterfaceAndTargetAsClassCounter">
|
||||||
<aop:before method="increment"
|
<aop:before method="increment"
|
||||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface) and target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" />
|
pointcut="this(org.springframework.aop.aspectj.TestInterface) and target(org.springframework.aop.aspectj.TestImpl)" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
|
|
||||||
</aop:config>
|
</aop:config>
|
||||||
|
|
||||||
<bean id="thisAsClassCounter"
|
<bean id="thisAsClassCounter" class="org.springframework.aop.aspectj.Counter" />
|
||||||
class="org.springframework.aop.aspectj.Counter" />
|
<bean id="thisAsInterfaceCounter" class="org.springframework.aop.aspectj.Counter" />
|
||||||
<bean id="thisAsInterfaceCounter"
|
<bean id="targetAsClassCounter" class="org.springframework.aop.aspectj.Counter" />
|
||||||
class="org.springframework.aop.aspectj.Counter" />
|
<bean id="targetAsInterfaceCounter" class="org.springframework.aop.aspectj.Counter" />
|
||||||
<bean id="targetAsClassCounter"
|
<bean id="thisAsClassAndTargetAsClassCounter" class="org.springframework.aop.aspectj.Counter" />
|
||||||
class="org.springframework.aop.aspectj.Counter" />
|
<bean id="thisAsInterfaceAndTargetAsInterfaceCounter" class="org.springframework.aop.aspectj.Counter" />
|
||||||
<bean id="targetAsInterfaceCounter"
|
<bean id="thisAsInterfaceAndTargetAsClassCounter" class="org.springframework.aop.aspectj.Counter" />
|
||||||
class="org.springframework.aop.aspectj.Counter" />
|
<bean id="testBean" class="org.springframework.aop.aspectj.TestImpl" />
|
||||||
<bean id="thisAsClassAndTargetAsClassCounter"
|
|
||||||
class="org.springframework.aop.aspectj.Counter" />
|
|
||||||
<bean id="thisAsInterfaceAndTargetAsInterfaceCounter"
|
|
||||||
class="org.springframework.aop.aspectj.Counter" />
|
|
||||||
<bean id="thisAsInterfaceAndTargetAsClassCounter"
|
|
||||||
class="org.springframework.aop.aspectj.Counter" />
|
|
||||||
|
|
||||||
<bean id="testBean" class="org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests$TestImpl" />
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
|
@ -16,7 +16,7 @@
|
||||||
<aop:declare-parents
|
<aop:declare-parents
|
||||||
types-matching="*..TopsyTurvyTarget+"
|
types-matching="*..TopsyTurvyTarget+"
|
||||||
implement-interface="java.io.Serializable"
|
implement-interface="java.io.Serializable"
|
||||||
default-impl="org.springframework.aop.aspectj.SerializableMixin"/>
|
default-impl="org.springframework.aop.aspectj.DeclarationOrderIndependenceTests$SerializableMixin"/>
|
||||||
<aop:after-returning pointcut-ref="pc2" method="afterReturning"/>
|
<aop:after-returning pointcut-ref="pc2" method="afterReturning"/>
|
||||||
<aop:pointcut id="pc1" expression="execution(* *..do*(..))"/>
|
<aop:pointcut id="pc1" expression="execution(* *..do*(..))"/>
|
||||||
<aop:around pointcut-ref="pc2"
|
<aop:around pointcut-ref="pc2"
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
<aop:declare-parents
|
<aop:declare-parents
|
||||||
types-matching="*..TopsyTurvyTarget+"
|
types-matching="*..TopsyTurvyTarget+"
|
||||||
implement-interface="org.springframework.beans.factory.BeanNameAware"
|
implement-interface="org.springframework.beans.factory.BeanNameAware"
|
||||||
default-impl="org.springframework.aop.aspectj.BeanNameAwareMixin"/>
|
default-impl="org.springframework.aop.aspectj.DeclarationOrderIndependenceTests$BeanNameAwareMixin"/>
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
</aop:config>
|
</aop:config>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue