Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@173 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
1104 changed files with 144705 additions and 0 deletions
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project name="org.springframework.testsuite"> |
||||
<property file="${basedir}/../build.properties"/> |
||||
<import file="${basedir}/../build-spring-framework/package-bundle.xml"/> |
||||
<import file="${basedir}/../spring-build/standard/default.xml"/> |
||||
</project> |
||||
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> |
||||
<ivy-module |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:noNamespaceSchemaLocation="http://incubator.apache.org/ivy/schemas/ivy.xsd" |
||||
version="1.3"> |
||||
|
||||
<info organisation="org.springframework" module="${ant.project.name}"> |
||||
<license name="Apache 2.0" url="http://www.apache.org/licenses/LICENSE-2.0"/> |
||||
</info> |
||||
|
||||
<configurations> |
||||
<include file="${spring.build.dir}/common/default-ivy-configurations.xml"/> |
||||
<conf name="aspectj" extends="runtime" description="JARs needed to run with AspectJ"/> |
||||
<conf name="commons-collections" extends="runtime" description="JARs needed to run with Commons Collections"/> |
||||
<conf name="log4j" extends="runtime" description="JARs needed to use Log4J"/> |
||||
</configurations> |
||||
|
||||
<publications> |
||||
<artifact name="${ant.project.name}"/> |
||||
<artifact name="${ant.project.name}-sources" type="src" ext="jar"/> |
||||
</publications> |
||||
|
||||
<dependencies> |
||||
<dependency org="com.oracle.toplink" name="com.springsource.oracle.toplink" rev="10.1.3" conf="test->compile"/> |
||||
<dependency org="com.ibm.websphere" name="com.springsource.com.ibm.websphere.uow" rev="6.0.2.17" conf="test->compile"/> |
||||
<dependency org="com.opensymphony.quartz" name="com.springsource.org.quartz" rev="1.6.2" conf="test->compile"/> |
||||
<dependency org="edu.emory.mathcs.backport" name="com.springsource.edu.emory.mathcs.backport" rev="3.0.0" conf="test->compile"/> |
||||
<dependency org="javax.el" name="com.springsource.javax.el" rev="2.1.0" conf="test->compile"/> |
||||
<dependency org="javax.faces" name="com.springsource.javax.faces" rev="1.2.0.08" conf="test->compile"/> |
||||
<dependency org="javax.jdo" name="com.springsource.javax.jdo" rev="2.0.0" conf="test->compile"/> |
||||
<dependency org="javax.jms" name="com.springsource.javax.jms" rev="1.1.0" conf="test->compile"/> |
||||
<dependency org="javax.mail" name="com.springsource.javax.mail" rev="1.4.0" conf="test->compile"/> |
||||
<dependency org="javax.portlet" name="com.springsource.javax.portlet" rev="1.0.0" conf="test->compile"/> |
||||
<dependency org="javax.resource" name="com.springsource.javax.resource" rev="1.5.0" conf="test->compile"/> |
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.4.0" conf="test->compile"/> |
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet.jsp" rev="2.0.0" conf="test->compile"/> |
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet.jsp.jstl" rev="1.1.2" conf="test->compile"/> |
||||
<dependency org="javax.xml.rpc" name="com.springsource.javax.xml.rpc" rev="1.1.0" conf="test->compile"/> |
||||
<dependency org="javax.transaction" name="com.springsource.javax.transaction" rev="1.1.0" conf="test->compile"/> |
||||
<dependency org="net.sourceforge.cglib" name="com.springsource.net.sf.cglib" rev="2.1.3" conf="test->compile"/> |
||||
<dependency org="net.sourceforge.ehcache" name="com.springsource.net.sf.ehcache" rev="1.3.0" conf="test->compile"/> |
||||
<dependency org="net.sourceforge.jexcelapi" name="com.springsource.jxl" rev="2.6.6" conf="test->compile"/> |
||||
<dependency org="net.sourceforge.jasperreports" name="com.springsource.net.sf.jasperreports" rev="2.0.5" conf="test->compile"/> |
||||
<dependency org="org.dom4j" name="com.springsource.org.dom4j" rev="1.6.1" conf="test->compile"/> |
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.dbcp" rev="1.2.2.osgi" conf="test->runtime"/> |
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.fileupload" rev="1.2.0" conf="test->compile"/> |
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.pool" rev="1.4.0" conf="test->compile"/> |
||||
<dependency org="org.apache.poi" name="com.springsource.org.apache.poi" rev="3.0.2.FINAL" conf="test->compile"/> |
||||
<dependency org="org.apache.tiles" name="com.springsource.org.apache.tiles" rev="2.0.5" conf="test->compile"/> |
||||
<dependency org="org.apache.tiles" name="com.springsource.org.apache.tiles.core" rev="2.0.5.osgi" conf="test->compile"/> |
||||
<dependency org="org.apache.velocity" name="com.springsource.org.apache.velocity" rev="1.5.0" conf="test->compile"/> |
||||
<dependency org="org.apache.velocity" name="com.springsource.org.apache.velocity.tools.view" rev="1.4.0" conf="test->compile"/> |
||||
<dependency org="org.apache.tiles" name="com.springsource.org.apache.tiles.jsp" rev="2.0.5" conf="test->compile"/> |
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="test->compile"/> |
||||
<dependency org="org.codehaus.groovy" name="com.springsource.org.codehaus.groovy" rev="1.5.1" conf="test->compile"/> |
||||
<dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/> |
||||
<dependency org="org.freemarker" name="com.springsource.freemarker" rev="2.3.12" conf="test->compile"/> |
||||
<dependency org="org.hibernate" name="com.springsource.org.hibernate" rev="3.2.6.ga" conf="test->compile"/> |
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm" rev="2.2.3" conf="test->runtime" /> |
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="2.2.3" conf="test->runtime" /> |
||||
<dependency org="org.springframework" name="org.springframework.aop" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.beans" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.context" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.context.support" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.core" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.jdbc" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.jms" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.orm" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.test" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.transaction" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.web" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.web.servlet" rev="latest.integration" conf="test->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.web.portlet" rev="latest.integration" conf="test->compile"/> |
||||
<!-- test dependencies --> |
||||
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.4.0" conf="test->runtime" /> |
||||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="test->compile"/> |
||||
|
||||
</dependencies> |
||||
|
||||
</ivy-module> |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<groupId>org.springframework</groupId> |
||||
<artifactId>org.springframework.core</artifactId> |
||||
<packaging>jar</packaging> |
||||
<name>Spring Core Abstractions and Utilities</name> |
||||
<version>3.0.0.M1</version> |
||||
<repositories> |
||||
<repository> |
||||
<id>com.springsource.repository.bundles.external</id> |
||||
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name> |
||||
<url>http://repository.springsource.com/maven/bundles/external</url> |
||||
</repository> |
||||
</repositories> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<configuration> |
||||
<source>1.5</source> |
||||
<target>1.5</target> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>com.springsource.org.apache.commons.logging</artifactId> |
||||
<version>1.1.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.log4j</groupId> |
||||
<artifactId>com.springsource.org.apache.log4j</artifactId> |
||||
<version>1.2.15</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>com.springsource.org.apache.commons.collections</artifactId> |
||||
<version>3.2.0</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.aspectj</groupId> |
||||
<artifactId>com.springsource.org.aspectj.weaver</artifactId> |
||||
<version>1.6.2.RELEASE</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.objectweb.asm</groupId> |
||||
<artifactId>com.springsource.org.objectweb.asm.commons</artifactId> |
||||
<version>2.2.3</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* Simple BeforeAdvice for testing. |
||||
* |
||||
* @author Dmitriy Kopylenko |
||||
*/ |
||||
public interface SimpleBeforeAdvice extends BeforeAdvice { |
||||
|
||||
void before() throws Throwable; |
||||
|
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import org.aopalliance.aop.Advice; |
||||
import org.aopalliance.intercept.MethodInterceptor; |
||||
|
||||
import org.springframework.aop.framework.adapter.AdvisorAdapter; |
||||
|
||||
/** |
||||
* @author Dmitriy Kopylenko |
||||
*/ |
||||
public class SimpleBeforeAdviceAdapter implements AdvisorAdapter, Serializable { |
||||
|
||||
public boolean supportsAdvice(Advice advice) { |
||||
return (advice instanceof SimpleBeforeAdvice); |
||||
} |
||||
|
||||
public MethodInterceptor getInterceptor(Advisor advisor) { |
||||
SimpleBeforeAdvice advice = (SimpleBeforeAdvice) advisor.getAdvice(); |
||||
return new SimpleBeforeAdviceInterceptor(advice) ; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2002-2005 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.aop; |
||||
|
||||
/** |
||||
* @author Dmitriy Kopylenko |
||||
*/ |
||||
public class SimpleBeforeAdviceImpl implements SimpleBeforeAdvice { |
||||
|
||||
private int invocationCounter; |
||||
|
||||
public void before() throws Throwable { |
||||
++invocationCounter; |
||||
} |
||||
|
||||
public int getInvocationCounter() { |
||||
return invocationCounter; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2002-2005 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.aop; |
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor; |
||||
import org.aopalliance.intercept.MethodInvocation; |
||||
|
||||
/** |
||||
* @author Dmitriy Kopylenko |
||||
*/ |
||||
final class SimpleBeforeAdviceInterceptor implements MethodInterceptor { |
||||
|
||||
private SimpleBeforeAdvice advice; |
||||
|
||||
public SimpleBeforeAdviceInterceptor(SimpleBeforeAdvice advice) { |
||||
this.advice = advice; |
||||
} |
||||
|
||||
public Object invoke(MethodInvocation mi) throws Throwable { |
||||
advice.before(); |
||||
return mi.proceed(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/* |
||||
* 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
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
/* |
||||
* 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.JoinPoint; |
||||
|
||||
/** |
||||
* Aspect used as part of before advice binding tests. |
||||
* |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AdviceBindingTestAspect { |
||||
|
||||
protected AdviceBindingCollaborator collaborator = null; |
||||
|
||||
public void setCollaborator(AdviceBindingCollaborator aCollaborator) { |
||||
this.collaborator = aCollaborator; |
||||
} |
||||
|
||||
// "advice" methods
|
||||
public void oneIntArg(int age) { |
||||
this.collaborator.oneIntArg(age); |
||||
} |
||||
|
||||
public void oneObjectArg(Object bean) { |
||||
this.collaborator.oneObjectArg(bean); |
||||
} |
||||
|
||||
public void oneIntAndOneObject(int x, Object o) { |
||||
this.collaborator.oneIntAndOneObject(x,o); |
||||
} |
||||
|
||||
public void needsJoinPoint(JoinPoint tjp) { |
||||
this.collaborator.needsJoinPoint(tjp.getSignature().getName()); |
||||
} |
||||
|
||||
public void needsJoinPointStaticPart(JoinPoint.StaticPart tjpsp) { |
||||
this.collaborator.needsJoinPointStaticPart(tjpsp.getSignature().getName()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Collaborator interface that makes it easy to test this aspect is |
||||
* working as expected through mocking. |
||||
*/ |
||||
public interface AdviceBindingCollaborator { |
||||
|
||||
void oneIntArg(int x); |
||||
void oneObjectArg(Object o); |
||||
void oneIntAndOneObject(int x, Object o); |
||||
void needsJoinPoint(String s); |
||||
void needsJoinPointStaticPart(String s); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
/* |
||||
* 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.easymock.MockControl; |
||||
|
||||
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator; |
||||
|
||||
/** |
||||
* Tests for various parameter binding scenarios with before advice. |
||||
* |
||||
* @author Adrian Colyer |
||||
* @author Rod Johnson |
||||
*/ |
||||
public class AfterAdviceBindingTests extends AbstractAdviceBindingTests { |
||||
|
||||
private AdviceBindingTestAspect afterAdviceAspect; |
||||
|
||||
private MockControl mockControl; |
||||
|
||||
private AdviceBindingCollaborator mockCollaborator; |
||||
|
||||
|
||||
public void setAfterAdviceAspect(AdviceBindingTestAspect anAspect) { |
||||
this.afterAdviceAspect = anAspect; |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "after-advice-tests.xml"; |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
super.onSetUp(); |
||||
mockControl = MockControl.createNiceControl(AdviceBindingCollaborator.class); |
||||
mockCollaborator = (AdviceBindingCollaborator) mockControl.getMock(); |
||||
afterAdviceAspect.setCollaborator(mockCollaborator); |
||||
} |
||||
|
||||
|
||||
public void testOneIntArg() { |
||||
mockCollaborator.oneIntArg(5); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneObjectArgBindingProxyWithThis() { |
||||
mockCollaborator.oneObjectArg(this.testBeanProxy); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneObjectArgBindingTarget() { |
||||
mockCollaborator.oneObjectArg(this.testBeanTarget); |
||||
mockControl.replay(); |
||||
testBeanProxy.getDoctor(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneIntAndOneObjectArgs() { |
||||
mockCollaborator.oneIntAndOneObject(5,this.testBeanProxy); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testNeedsJoinPoint() { |
||||
mockCollaborator.needsJoinPoint("getAge"); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testNeedsJoinPointStaticPart() { |
||||
mockCollaborator.needsJoinPointStaticPart("getAge"); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
/* |
||||
* 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); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,169 @@
@@ -0,0 +1,169 @@
|
||||
/* |
||||
* 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.easymock.MockControl; |
||||
|
||||
import org.springframework.aop.aspectj.AfterReturningAdviceBindingTestAspect.AfterReturningAdviceBindingCollaborator; |
||||
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; |
||||
|
||||
/** |
||||
* Tests for various parameter binding scenarios with before advice. |
||||
* |
||||
* @author Adrian Colyer |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class AfterReturningAdviceBindingTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private AfterReturningAdviceBindingTestAspect afterAdviceAspect; |
||||
|
||||
private ITestBean testBeanProxy; |
||||
|
||||
private TestBean testBeanTarget; |
||||
|
||||
private MockControl mockControl; |
||||
|
||||
private AfterReturningAdviceBindingCollaborator mockCollaborator; |
||||
|
||||
|
||||
public void setAfterReturningAdviceAspect(AfterReturningAdviceBindingTestAspect 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() { |
||||
return "afterReturning-advice-tests.xml"; |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
super.onSetUp(); |
||||
mockControl = MockControl.createNiceControl(AfterReturningAdviceBindingCollaborator.class); |
||||
mockCollaborator = (AfterReturningAdviceBindingCollaborator) mockControl.getMock(); |
||||
afterAdviceAspect.setCollaborator(mockCollaborator); |
||||
} |
||||
|
||||
|
||||
// simple test to ensure all is well with the xml file
|
||||
// note that this implicitly tests that the arg-names binding is working
|
||||
public void testParse() { |
||||
} |
||||
|
||||
public void testOneIntArg() { |
||||
mockCollaborator.oneIntArg(5); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneObjectArg() { |
||||
mockCollaborator.oneObjectArg(this.testBeanProxy); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneIntAndOneObjectArgs() { |
||||
mockCollaborator.oneIntAndOneObject(5,this.testBeanProxy); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testNeedsJoinPoint() { |
||||
mockCollaborator.needsJoinPoint("getAge"); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testNeedsJoinPointStaticPart() { |
||||
mockCollaborator.needsJoinPointStaticPart("getAge"); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testReturningString() { |
||||
mockCollaborator.oneString("adrian"); |
||||
mockControl.replay(); |
||||
testBeanProxy.setName("adrian"); |
||||
testBeanProxy.getName(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testReturningObject() { |
||||
mockCollaborator.oneObjectArg(this.testBeanTarget); |
||||
mockControl.replay(); |
||||
testBeanProxy.returnsThis(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testReturningBean() { |
||||
mockCollaborator.oneTestBeanArg(this.testBeanTarget); |
||||
mockControl.replay(); |
||||
testBeanProxy.returnsThis(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testReturningBeanArray() { |
||||
this.testBeanTarget.setSpouse(new TestBean()); |
||||
ITestBean[] spouses = (ITestBean[]) this.testBeanTarget.getSpouses(); |
||||
mockCollaborator.testBeanArrayArg(spouses); |
||||
mockControl.replay(); |
||||
testBeanProxy.getSpouses(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testNoInvokeWhenReturningParameterTypeDoesNotMatch() { |
||||
// we need a strict mock for this...
|
||||
mockControl = MockControl.createControl(AfterReturningAdviceBindingCollaborator.class); |
||||
mockCollaborator = (AfterReturningAdviceBindingCollaborator) mockControl.getMock(); |
||||
afterAdviceAspect.setCollaborator(mockCollaborator); |
||||
|
||||
mockControl.replay(); |
||||
testBeanProxy.setSpouse(this.testBeanProxy); |
||||
testBeanProxy.getSpouse(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testReturningByType() { |
||||
mockCollaborator.objectMatchNoArgs(); |
||||
mockControl.replay(); |
||||
testBeanProxy.returnsThis(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testReturningPrimitive() { |
||||
mockCollaborator.oneInt(20); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(20); |
||||
testBeanProxy.haveBirthday(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,147 @@
@@ -0,0 +1,147 @@
|
||||
/* |
||||
* 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.easymock.MockControl; |
||||
|
||||
import org.springframework.aop.aspectj.AfterThrowingAdviceBindingTestAspect.AfterThrowingAdviceBindingCollaborator; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* Tests for various parameter binding scenarios with before advice. |
||||
* |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AfterThrowingAdviceBindingTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect; |
||||
|
||||
private ITestBean testBean; |
||||
|
||||
private MockControl mockControl; |
||||
|
||||
private AfterThrowingAdviceBindingCollaborator mockCollaborator; |
||||
|
||||
|
||||
public void setAfterAdviceAspect(AfterThrowingAdviceBindingTestAspect anAspect) { |
||||
this.afterThrowingAdviceAspect = anAspect; |
||||
} |
||||
|
||||
public void setTestBean(ITestBean aBean) throws Exception { |
||||
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); |
||||
} |
||||
|
||||
|
||||
// Simple test to ensure all is well with the XML file.
|
||||
// Note that this implicitly tests that the arg-names binding is working.
|
||||
public void testParse() { |
||||
} |
||||
|
||||
public void testSimpleAfterThrowing() { |
||||
mockCollaborator.noArgs(); |
||||
mockControl.replay(); |
||||
try { |
||||
this.testBean.exceptional(new Throwable()); |
||||
fail("should throw exception"); |
||||
} catch (Throwable t) { |
||||
// no-op
|
||||
} |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testAfterThrowingWithBinding() { |
||||
Throwable t = new Throwable(); |
||||
mockCollaborator.oneThrowable(t); |
||||
mockControl.replay(); |
||||
try { |
||||
this.testBean.exceptional(t); |
||||
fail("should throw exception"); |
||||
} catch (Throwable x) { |
||||
// no-op
|
||||
} |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testAfterThrowingWithNamedTypeRestriction() { |
||||
Throwable t = new Throwable(); |
||||
// need a strict mock for this test...
|
||||
mockControl = MockControl.createControl(AfterThrowingAdviceBindingCollaborator.class); |
||||
mockCollaborator = (AfterThrowingAdviceBindingCollaborator) mockControl.getMock(); |
||||
afterThrowingAdviceAspect.setCollaborator(mockCollaborator); |
||||
|
||||
mockCollaborator.noArgs(); |
||||
mockCollaborator.oneThrowable(t); |
||||
mockCollaborator.noArgsOnThrowableMatch(); |
||||
mockControl.replay(); |
||||
try { |
||||
this.testBean.exceptional(t); |
||||
fail("should throw exception"); |
||||
} catch (Throwable x) { |
||||
// no-op
|
||||
} |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testAfterThrowingWithRuntimeExceptionBinding() { |
||||
RuntimeException ex = new RuntimeException(); |
||||
mockCollaborator.oneRuntimeException(ex); |
||||
mockControl.replay(); |
||||
try { |
||||
this.testBean.exceptional(ex); |
||||
fail("should throw exception"); |
||||
} catch (Throwable x) { |
||||
// no-op
|
||||
} |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testAfterThrowingWithTypeSpecified() { |
||||
mockCollaborator.noArgsOnThrowableMatch(); |
||||
mockControl.replay(); |
||||
try { |
||||
this.testBean.exceptional(new Throwable()); |
||||
fail("should throw exception"); |
||||
} catch (Throwable t) { |
||||
// no-op
|
||||
} |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testAfterThrowingWithRuntimeTypeSpecified() { |
||||
mockCollaborator.noArgsOnRuntimeExceptionMatch(); |
||||
mockControl.replay(); |
||||
try { |
||||
this.testBean.exceptional(new RuntimeException()); |
||||
fail("should throw exception"); |
||||
} catch (Throwable t) { |
||||
// no-op
|
||||
} |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
/* |
||||
* 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); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
/* |
||||
* 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.easymock.MockControl; |
||||
|
||||
import org.springframework.aop.aspectj.AroundAdviceBindingTestAspect.AroundAdviceBindingCollaborator; |
||||
|
||||
/** |
||||
* Tests for various parameter binding scenarios with before advice. |
||||
* |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AroundAdviceBindingTests extends AbstractAdviceBindingTests { |
||||
|
||||
private MockControl mockControl; |
||||
|
||||
private AroundAdviceBindingCollaborator mockCollaborator; |
||||
|
||||
private AroundAdviceBindingTestAspect aroundAdviceAspect; |
||||
|
||||
|
||||
public void setAroundAdviceAspect(AroundAdviceBindingTestAspect anAspect) { |
||||
this.aroundAdviceAspect = anAspect; |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "around-advice-tests.xml"; |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
super.onSetUp(); |
||||
mockControl = MockControl.createNiceControl(AroundAdviceBindingCollaborator.class); |
||||
mockCollaborator = (AroundAdviceBindingCollaborator) mockControl.getMock(); |
||||
aroundAdviceAspect.setCollaborator(mockCollaborator); |
||||
} |
||||
|
||||
|
||||
public void testOneIntArg() { |
||||
mockCollaborator.oneIntArg(5); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneObjectArgBoundToTarget() { |
||||
mockCollaborator.oneObjectArg(this.testBeanTarget); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneIntAndOneObjectArgs() { |
||||
mockCollaborator.oneIntAndOneObject(5, this.testBeanProxy); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testJustJoinPoint() { |
||||
mockCollaborator.justJoinPoint("getAge"); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.support.AopUtils; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class AroundAdviceCircularTests extends AroundAdviceBindingTests { |
||||
|
||||
protected String getConfigPath() { |
||||
return "around-advice-circular-tests.xml"; |
||||
} |
||||
|
||||
public void testBothBeansAreProxies() { |
||||
Object tb = getApplicationContext().getBean("testBean"); |
||||
assertTrue(AopUtils.isAopProxy(tb)); |
||||
Object tb2 = getApplicationContext().getBean("testBean2"); |
||||
assertTrue(AopUtils.isAopProxy(tb2)); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,140 @@
@@ -0,0 +1,140 @@
|
||||
/* |
||||
* 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.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AspectAndAdvicePrecedenceTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private PrecedenceTestAspect highPrecedenceAspect; |
||||
private PrecedenceTestAspect lowPrecedenceAspect; |
||||
private SimpleSpringBeforeAdvice lowPrecedenceSpringAdvice; |
||||
private SimpleSpringBeforeAdvice highPrecedenceSpringAdvice; |
||||
private ITestBean testBean; |
||||
|
||||
|
||||
public AspectAndAdvicePrecedenceTests() { |
||||
setAutowireMode(AUTOWIRE_BY_NAME); |
||||
} |
||||
|
||||
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 ===================
|
||||
|
||||
public void testAdviceOrder() { |
||||
PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator(); |
||||
this.highPrecedenceAspect.setCollaborator(collaborator); |
||||
this.lowPrecedenceAspect.setCollaborator(collaborator); |
||||
this.highPrecedenceSpringAdvice.setCollaborator(collaborator); |
||||
this.lowPrecedenceSpringAdvice.setCollaborator(collaborator); |
||||
this.testBean.getAge(); |
||||
} |
||||
|
||||
|
||||
private static class PrecedenceVerifyingCollaborator implements PrecedenceTestAspect.Collaborator { |
||||
|
||||
private static final String[] EXPECTED = { |
||||
// this order confirmed by running the same aspects (minus the Spring AOP advisors)
|
||||
// through AspectJ...
|
||||
"beforeAdviceOne(highPrecedenceAspect)", // 1
|
||||
"beforeAdviceTwo(highPrecedenceAspect)", // 2
|
||||
"aroundAdviceOne(highPrecedenceAspect)", // 3, before proceed
|
||||
"aroundAdviceTwo(highPrecedenceAspect)", // 4, before proceed
|
||||
"beforeAdviceOne(highPrecedenceSpringAdvice)", // 5
|
||||
"beforeAdviceOne(lowPrecedenceSpringAdvice)", // 6
|
||||
"beforeAdviceOne(lowPrecedenceAspect)", // 7
|
||||
"beforeAdviceTwo(lowPrecedenceAspect)", // 8
|
||||
"aroundAdviceOne(lowPrecedenceAspect)", // 9, before proceed
|
||||
"aroundAdviceTwo(lowPrecedenceAspect)", // 10, before proceed
|
||||
"aroundAdviceTwo(lowPrecedenceAspect)", // 11, after proceed
|
||||
"aroundAdviceOne(lowPrecedenceAspect)", // 12, after proceed
|
||||
"afterAdviceOne(lowPrecedenceAspect)", // 13
|
||||
"afterAdviceTwo(lowPrecedenceAspect)", // 14
|
||||
"aroundAdviceTwo(highPrecedenceAspect)", // 15, after proceed
|
||||
"aroundAdviceOne(highPrecedenceAspect)", // 16, after proceed
|
||||
"afterAdviceOne(highPrecedenceAspect)", // 17
|
||||
"afterAdviceTwo(highPrecedenceAspect)" // 18
|
||||
}; |
||||
|
||||
private int adviceInvocationNumber = 0; |
||||
|
||||
private void checkAdvice(String whatJustHappened) { |
||||
//System.out.println("[" + adviceInvocationNumber + "] " + whatJustHappened + " ==> " + EXPECTED[adviceInvocationNumber]);
|
||||
if (adviceInvocationNumber > (EXPECTED.length - 1)) { |
||||
fail("Too many advice invocations, expecting " + EXPECTED.length |
||||
+ " but had " + adviceInvocationNumber); |
||||
} |
||||
String expecting = EXPECTED[adviceInvocationNumber++]; |
||||
if (!whatJustHappened.equals(expecting)) { |
||||
fail("Expecting '" + expecting + "' on advice invocation " + adviceInvocationNumber + |
||||
" but got '" + whatJustHappened + "'"); |
||||
} |
||||
} |
||||
|
||||
public void beforeAdviceOne(String beanName) { |
||||
checkAdvice("beforeAdviceOne(" + beanName + ")"); |
||||
} |
||||
|
||||
public void beforeAdviceTwo(String beanName) { |
||||
checkAdvice("beforeAdviceTwo(" + beanName + ")"); |
||||
} |
||||
|
||||
public void aroundAdviceOne(String beanName) { |
||||
checkAdvice("aroundAdviceOne(" + beanName + ")"); |
||||
} |
||||
|
||||
public void aroundAdviceTwo(String beanName) { |
||||
checkAdvice("aroundAdviceTwo(" + beanName + ")"); |
||||
} |
||||
|
||||
public void afterAdviceOne(String beanName) { |
||||
checkAdvice("afterAdviceOne(" + beanName + ")"); |
||||
} |
||||
|
||||
public void afterAdviceTwo(String beanName) { |
||||
checkAdvice("afterAdviceTwo(" + beanName + ")"); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,298 @@
@@ -0,0 +1,298 @@
|
||||
/* |
||||
* 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 junit.framework.TestCase; |
||||
import org.aspectj.lang.JoinPoint; |
||||
import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* Unit tests for the {@link AspectJAdviceParameterNameDiscoverer} class. |
||||
* <p/> |
||||
* <p>See also <code>TigerAspectJAdviceParameterNameDiscovererTests</code> in |
||||
* the 'tiger' tree for tests relating to annotations. |
||||
* |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AspectJAdviceParameterNameDiscovererTests extends TestCase { |
||||
|
||||
// methods to discover parameter names for
|
||||
public void noArgs() { |
||||
} |
||||
|
||||
public void tjp(JoinPoint jp) { |
||||
} |
||||
|
||||
public void tjpsp(JoinPoint.StaticPart tjpsp) { |
||||
} |
||||
|
||||
public void twoJoinPoints(JoinPoint jp1, JoinPoint jp2) { |
||||
} |
||||
|
||||
public void oneThrowable(Exception ex) { |
||||
} |
||||
|
||||
public void jpAndOneThrowable(JoinPoint jp, Exception ex) { |
||||
} |
||||
|
||||
public void jpAndTwoThrowables(JoinPoint jp, Exception ex, Error err) { |
||||
} |
||||
|
||||
public void oneObject(Object x) { |
||||
} |
||||
|
||||
public void twoObjects(Object x, Object y) { |
||||
} |
||||
|
||||
public void onePrimitive(int x) { |
||||
} |
||||
|
||||
public void oneObjectOnePrimitive(Object x, int y) { |
||||
} |
||||
|
||||
public void oneThrowableOnePrimitive(Throwable x, int y) { |
||||
} |
||||
|
||||
public void theBigOne(JoinPoint jp, Throwable x, int y, Object foo) { |
||||
} |
||||
|
||||
|
||||
public void testNoArgs() { |
||||
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]); |
||||
} |
||||
|
||||
public void testJoinPointOnly() { |
||||
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[]{"thisJoinPoint"}); |
||||
} |
||||
|
||||
public void testJoinPointStaticPartOnly() { |
||||
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[]{"thisJoinPointStaticPart"}); |
||||
} |
||||
|
||||
public void testTwoJoinPoints() { |
||||
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class, "Failed to bind all argument names: 1 argument(s) could not be bound"); |
||||
} |
||||
|
||||
public void testOneThrowable() { |
||||
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[]{"ex"}); |
||||
} |
||||
|
||||
public void testOneJPAndOneThrowable() { |
||||
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[]{"thisJoinPoint", "ex"}); |
||||
} |
||||
|
||||
public void testOneJPAndTwoThrowables() { |
||||
assertException(getMethod("jpAndTwoThrowables"), "foo()", null, "ex", AmbiguousBindingException.class, |
||||
"Binding of throwing parameter 'ex' is ambiguous: could be bound to argument 1 or argument 2"); |
||||
} |
||||
|
||||
public void testThrowableNoCandidates() { |
||||
assertException(getMethod("noArgs"), "foo()", null, "ex", IllegalStateException.class, |
||||
"Not enough arguments in method to satisfy binding of returning and throwing variables"); |
||||
} |
||||
|
||||
public void testReturning() { |
||||
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[]{"obj"}); |
||||
} |
||||
|
||||
public void testAmbiguousReturning() { |
||||
assertException(getMethod("twoObjects"), "foo()", "obj", null, AmbiguousBindingException.class, |
||||
"Binding of returning parameter 'obj' is ambiguous, there are 2 candidates."); |
||||
} |
||||
|
||||
public void testReturningNoCandidates() { |
||||
assertException(getMethod("noArgs"), "foo()", "obj", null, IllegalStateException.class, |
||||
"Not enough arguments in method to satisfy binding of returning and throwing variables"); |
||||
} |
||||
|
||||
public void testThisBindingOneCandidate() { |
||||
assertParameterNames(getMethod("oneObject"), "this(x)", new String[]{"x"}); |
||||
} |
||||
|
||||
public void testThisBindingWithAlternateTokenizations() { |
||||
assertParameterNames(getMethod("oneObject"), "this( x )", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "this( x)", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "this (x )", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "this(x )", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[]{"x"}); |
||||
} |
||||
|
||||
public void testThisBindingTwoCandidates() { |
||||
assertException(getMethod("oneObject"), "this(x) || this(y)", AmbiguousBindingException.class, |
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot"); |
||||
} |
||||
|
||||
public void testThisBindingWithBadPointcutExpressions() { |
||||
assertException(getMethod("oneObject"), "this(", IllegalStateException.class, |
||||
"Failed to bind all argument names: 1 argument(s) could not be bound"); |
||||
assertException(getMethod("oneObject"), "this(x && foo()", IllegalStateException.class, |
||||
"Failed to bind all argument names: 1 argument(s) could not be bound"); |
||||
} |
||||
|
||||
public void testTargetBindingOneCandidate() { |
||||
assertParameterNames(getMethod("oneObject"), "target(x)", new String[]{"x"}); |
||||
} |
||||
|
||||
public void testTargetBindingWithAlternateTokenizations() { |
||||
assertParameterNames(getMethod("oneObject"), "target( x )", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "target( x)", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "target (x )", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "target(x )", new String[]{"x"}); |
||||
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[]{"x"}); |
||||
} |
||||
|
||||
public void testTargetBindingTwoCandidates() { |
||||
assertException(getMethod("oneObject"), "target(x) || target(y)", AmbiguousBindingException.class, |
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot"); |
||||
} |
||||
|
||||
public void testTargetBindingWithBadPointcutExpressions() { |
||||
assertException(getMethod("oneObject"), "target(", IllegalStateException.class, |
||||
"Failed to bind all argument names: 1 argument(s) could not be bound"); |
||||
assertException(getMethod("oneObject"), "target(x && foo()", IllegalStateException.class, |
||||
"Failed to bind all argument names: 1 argument(s) could not be bound"); |
||||
} |
||||
|
||||
public void testArgsBindingOneObject() { |
||||
assertParameterNames(getMethod("oneObject"), "args(x)", new String[]{"x"}); |
||||
} |
||||
|
||||
public void testArgsBindingOneObjectTwoCandidates() { |
||||
assertException(getMethod("oneObject"), "args(x,y)", AmbiguousBindingException.class, |
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot"); |
||||
} |
||||
|
||||
public void testAmbiguousArgsBinding() { |
||||
assertException(getMethod("twoObjects"), "args(x,y)", AmbiguousBindingException.class, |
||||
"Still 2 unbound args at this(),target(),args() binding stage, with no way to determine between them"); |
||||
} |
||||
|
||||
public void testArgsOnePrimitive() { |
||||
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[]{"count"}); |
||||
} |
||||
|
||||
public void testArgsOnePrimitiveOneObject() { |
||||
assertException(getMethod("oneObjectOnePrimitive"), "args(count,obj)", AmbiguousBindingException.class, |
||||
"Found 2 candidate variable names but only one candidate binding slot when matching primitive args"); |
||||
} |
||||
|
||||
public void testThisAndPrimitive() { |
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", new String[]{"obj", "count"}); |
||||
} |
||||
|
||||
public void testTargetAndPrimitive() { |
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", new String[]{"obj", "count"}); |
||||
} |
||||
|
||||
public void testThrowingAndPrimitive() { |
||||
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", new String[]{"ex", "count"}); |
||||
} |
||||
|
||||
public void testAllTogetherNow() { |
||||
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", new String[]{"thisJoinPoint", "ex", "x", "foo"}); |
||||
} |
||||
|
||||
public void testReferenceBinding() { |
||||
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)",new String[] {"foo"}); |
||||
} |
||||
|
||||
public void testReferenceBindingWithAlternateTokenizations() { |
||||
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)",new String[] {"foo"}); |
||||
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )",new String[] {"foo"}); |
||||
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)",new String[] {"foo"}); |
||||
} |
||||
|
||||
|
||||
protected Method getMethod(String name) { |
||||
// assumes no overloading of test methods...
|
||||
Method[] candidates = this.getClass().getMethods(); |
||||
for (int i = 0; i < candidates.length; i++) { |
||||
if (candidates[i].getName().equals(name)) { |
||||
return candidates[i]; |
||||
} |
||||
} |
||||
fail("Bad test specification, no method '" + name + "' found in test class"); |
||||
return null; |
||||
} |
||||
|
||||
protected void assertParameterNames(Method m, String pointcut, String[] parameterNames) { |
||||
assertParameterNames(m, pointcut, null, null, parameterNames); |
||||
} |
||||
|
||||
protected void assertParameterNames(Method m, String pointcut, String returning, String throwing, String[] parameterNames) { |
||||
assertEquals("bad test specification, must have same number of parameter names as method arguments", |
||||
m.getParameterTypes().length, parameterNames.length); |
||||
|
||||
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut); |
||||
discoverer.setRaiseExceptions(true); |
||||
discoverer.setReturningName(returning); |
||||
discoverer.setThrowingName(throwing); |
||||
String[] discoveredNames = discoverer.getParameterNames(m); |
||||
|
||||
String formattedExpectedNames = format(parameterNames); |
||||
String formattedActualNames = format(discoveredNames); |
||||
|
||||
assertEquals("Expecting " + parameterNames.length + " parameter names in return set '" + |
||||
formattedExpectedNames + "', but found " + discoveredNames.length + |
||||
" '" + formattedActualNames + "'", |
||||
parameterNames.length, discoveredNames.length); |
||||
|
||||
for (int i = 0; i < discoveredNames.length; i++) { |
||||
assertNotNull("Parameter names must never be null", discoveredNames[i]); |
||||
assertEquals("Expecting parameter " + i + " to be named '" + |
||||
parameterNames[i] + "' but was '" + discoveredNames[i] + "'", |
||||
parameterNames[i], discoveredNames[i]); |
||||
} |
||||
} |
||||
|
||||
protected void assertException(Method m, String pointcut, Class exceptionType, String message) { |
||||
assertException(m, pointcut, null, null, exceptionType, message); |
||||
} |
||||
|
||||
protected void assertException(Method m, String pointcut, String returning, String throwing, Class exceptionType, String message) { |
||||
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut); |
||||
discoverer.setRaiseExceptions(true); |
||||
discoverer.setReturningName(returning); |
||||
discoverer.setThrowingName(throwing); |
||||
|
||||
try { |
||||
discoverer.getParameterNames(m); |
||||
fail("Expecting " + exceptionType.getName() + " with message '" + message + "'"); |
||||
} catch (RuntimeException expected) { |
||||
assertEquals("Expecting exception of type " + exceptionType.getName(), |
||||
exceptionType, expected.getClass()); |
||||
assertEquals("Exception message does not match expected", message, expected.getMessage()); |
||||
} |
||||
} |
||||
|
||||
|
||||
private static String format(String[] names) { |
||||
StringBuffer sb = new StringBuffer(); |
||||
sb.append("("); |
||||
for (int i = 0; i < names.length; i++) { |
||||
sb.append(names[i]); |
||||
if ((i + 1) < names.length) { |
||||
sb.append(","); |
||||
} |
||||
} |
||||
sb.append(")"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
/* |
||||
* 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.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class AspectJExpressionPointcutAdvisorTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private ITestBean testBean; |
||||
|
||||
private CallCountingInterceptor interceptor; |
||||
|
||||
|
||||
public void setTestBean(ITestBean testBean) { |
||||
this.testBean = testBean; |
||||
} |
||||
|
||||
public void setInterceptor(CallCountingInterceptor interceptor) { |
||||
this.interceptor = interceptor; |
||||
} |
||||
|
||||
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()); |
||||
testBean.getSpouses(); |
||||
assertEquals("Count should be 1", 1, interceptor.getCount()); |
||||
testBean.getSpouse(); |
||||
assertEquals("Count should be 1", 1, interceptor.getCount()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,332 @@
@@ -0,0 +1,332 @@
|
||||
/* |
||||
* Copyright 2002-2005 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.aop.aspectj; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.aspectj.weaver.tools.PointcutExpression; |
||||
import org.aspectj.weaver.tools.PointcutPrimitive; |
||||
import org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException; |
||||
import org.springframework.aop.ClassFilter; |
||||
import org.springframework.aop.MethodMatcher; |
||||
import org.springframework.aop.Pointcut; |
||||
import org.springframework.aop.aspectj.AspectJExpressionPointcut; |
||||
import org.springframework.aop.framework.ProxyFactory; |
||||
import org.springframework.aop.support.DefaultPointcutAdvisor; |
||||
import org.springframework.beans.IOther; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.TestBean; |
||||
import org.springframework.beans.factory.BeanFactory; |
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
* @author Rod Johnson |
||||
*/ |
||||
public class AspectJExpressionPointcutTests extends TestCase { |
||||
|
||||
public static final String MATCH_ALL_METHODS = "execution(* *(..))"; |
||||
|
||||
private Method getAge; |
||||
|
||||
private Method setAge; |
||||
|
||||
private Method setSomeNumber; |
||||
|
||||
private Method isPostProcessed; |
||||
|
||||
public void testMatchExplicit() { |
||||
String expression = "execution(int org.springframework.beans.TestBean.getAge())"; |
||||
|
||||
Pointcut pointcut = getPointcut(expression); |
||||
ClassFilter classFilter = pointcut.getClassFilter(); |
||||
MethodMatcher methodMatcher = pointcut.getMethodMatcher(); |
||||
|
||||
assertMatchesTestBeanClass(classFilter); |
||||
|
||||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertFalse("Should not be a runtime match", methodMatcher.isRuntime()); |
||||
assertMatchesGetAge(methodMatcher); |
||||
assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class)); |
||||
} |
||||
|
||||
|
||||
public void setUp() throws NoSuchMethodException { |
||||
getAge = TestBean.class.getMethod("getAge", null); |
||||
setAge = TestBean.class.getMethod("setAge", new Class[]{int.class}); |
||||
setSomeNumber = TestBean.class.getMethod("setSomeNumber", new Class[]{Number.class}); |
||||
isPostProcessed = TestBean.class.getMethod("isPostProcessed", (Class[]) null); |
||||
} |
||||
|
||||
|
||||
|
||||
public void testMatchWithTypePattern() throws Exception { |
||||
String expression = "execution(* *..TestBean.*Age(..))"; |
||||
|
||||
Pointcut pointcut = getPointcut(expression); |
||||
ClassFilter classFilter = pointcut.getClassFilter(); |
||||
MethodMatcher methodMatcher = pointcut.getMethodMatcher(); |
||||
|
||||
assertMatchesTestBeanClass(classFilter); |
||||
|
||||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertFalse("Should not be a runtime match", methodMatcher.isRuntime()); |
||||
assertMatchesGetAge(methodMatcher); |
||||
assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class)); |
||||
} |
||||
|
||||
|
||||
public void testThis() throws SecurityException, NoSuchMethodException{ |
||||
testThisOrTarget("this"); |
||||
} |
||||
|
||||
public void testTarget() throws SecurityException, NoSuchMethodException { |
||||
testThisOrTarget("target"); |
||||
} |
||||
|
||||
public static class OtherIOther implements IOther { |
||||
|
||||
public void absquatulate() { |
||||
// Empty
|
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* This and target are equivalent. Really instanceof pointcuts. |
||||
* @throws Exception |
||||
* @param which this or target |
||||
* @throws NoSuchMethodException |
||||
* @throws SecurityException |
||||
*/ |
||||
private void testThisOrTarget(String which) throws SecurityException, NoSuchMethodException { |
||||
String matchesTestBean = which + "(org.springframework.beans.TestBean)"; |
||||
String matchesIOther = which + "(org.springframework.beans.IOther)"; |
||||
AspectJExpressionPointcut testBeanPc = new AspectJExpressionPointcut(); |
||||
testBeanPc.setExpression(matchesTestBean); |
||||
|
||||
AspectJExpressionPointcut iOtherPc = new AspectJExpressionPointcut(); |
||||
iOtherPc.setExpression(matchesIOther); |
||||
|
||||
assertTrue(testBeanPc.matches(TestBean.class)); |
||||
assertTrue(testBeanPc.matches(getAge, TestBean.class)); |
||||
assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate", null), |
||||
OtherIOther.class)); |
||||
|
||||
assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate", null), |
||||
OtherIOther.class)); |
||||
} |
||||
|
||||
public void testWithinRootPackage() throws SecurityException, NoSuchMethodException { |
||||
testWithinPackage(false); |
||||
} |
||||
|
||||
public void testWithinRootAndSubpackages() throws SecurityException, NoSuchMethodException { |
||||
testWithinPackage(true); |
||||
} |
||||
|
||||
private void testWithinPackage(boolean matchSubpackages) throws SecurityException, NoSuchMethodException { |
||||
String withinBeansPackage = "within(org.springframework.beans."; |
||||
// Subpackages are matched by **
|
||||
if (matchSubpackages) { |
||||
withinBeansPackage += "."; |
||||
} |
||||
withinBeansPackage = withinBeansPackage + "*)"; |
||||
AspectJExpressionPointcut withinBeansPc = new AspectJExpressionPointcut(); |
||||
withinBeansPc.setExpression(withinBeansPackage); |
||||
|
||||
assertTrue(withinBeansPc.matches(TestBean.class)); |
||||
assertTrue(withinBeansPc.matches(getAge, TestBean.class)); |
||||
assertEquals(matchSubpackages, withinBeansPc.matches(BeanFactory.class)); |
||||
assertEquals(matchSubpackages, withinBeansPc.matches( |
||||
DefaultListableBeanFactory.class.getMethod("getBeanDefinitionCount", null), |
||||
DefaultListableBeanFactory.class)); |
||||
assertFalse(withinBeansPc.matches(String.class)); |
||||
assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate", null), |
||||
OtherIOther.class)); |
||||
} |
||||
|
||||
public void testFriendlyErrorOnNoLocationClassMatching() { |
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
||||
try { |
||||
pc.matches(ITestBean.class); |
||||
fail(); |
||||
} |
||||
catch (IllegalStateException ex) { |
||||
assertTrue(ex.getMessage().indexOf("expression") != -1); |
||||
} |
||||
} |
||||
|
||||
public void testFriendlyErrorOnNoLocation2ArgMatching() { |
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
||||
try { |
||||
pc.matches(getAge, ITestBean.class); |
||||
fail(); |
||||
} |
||||
catch (IllegalStateException ex) { |
||||
assertTrue(ex.getMessage().indexOf("expression") != -1); |
||||
} |
||||
} |
||||
|
||||
public void testFriendlyErrorOnNoLocation3ArgMatching() { |
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
||||
try { |
||||
pc.matches(getAge, ITestBean.class, (Object[]) null); |
||||
fail(); |
||||
} |
||||
catch (IllegalStateException ex) { |
||||
assertTrue(ex.getMessage().indexOf("expression") != -1); |
||||
} |
||||
} |
||||
|
||||
|
||||
public void testMatchWithArgs() throws Exception { |
||||
String expression = "execution(void org.springframework.beans.TestBean.setSomeNumber(Number)) && args(Double)"; |
||||
|
||||
Pointcut pointcut = getPointcut(expression); |
||||
ClassFilter classFilter = pointcut.getClassFilter(); |
||||
MethodMatcher methodMatcher = pointcut.getMethodMatcher(); |
||||
|
||||
assertMatchesTestBeanClass(classFilter); |
||||
|
||||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertTrue("Should match with setSomeNumber with Double input", |
||||
methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Double(12)})); |
||||
assertFalse("Should not match setSomeNumber with Integer input", |
||||
methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Integer(11)})); |
||||
assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class, null)); |
||||
assertTrue("Should be a runtime match", methodMatcher.isRuntime()); |
||||
} |
||||
|
||||
public void testSimpleAdvice() { |
||||
String expression = "execution(int org.springframework.beans.TestBean.getAge())"; |
||||
|
||||
CallCountingInterceptor interceptor = new CallCountingInterceptor(); |
||||
|
||||
TestBean testBean = getAdvisedProxy(expression, interceptor); |
||||
|
||||
assertEquals("Calls should be 0", 0, interceptor.getCount()); |
||||
|
||||
testBean.getAge(); |
||||
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount()); |
||||
|
||||
testBean.setAge(90); |
||||
|
||||
assertEquals("Calls should still be 1", 1, interceptor.getCount()); |
||||
} |
||||
|
||||
public void testDynamicMatchingProxy() { |
||||
String expression = "execution(void org.springframework.beans.TestBean.setSomeNumber(Number)) && args(Double)"; |
||||
|
||||
CallCountingInterceptor interceptor = new CallCountingInterceptor(); |
||||
|
||||
TestBean testBean = getAdvisedProxy(expression, interceptor); |
||||
|
||||
assertEquals("Calls should be 0", 0, interceptor.getCount()); |
||||
|
||||
testBean.setSomeNumber(new Double(30)); |
||||
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount()); |
||||
|
||||
testBean.setSomeNumber(new Integer(90)); |
||||
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount()); |
||||
} |
||||
|
||||
public void testInvalidExpression() { |
||||
String expression = "execution(void org.springframework.beans.TestBean.setSomeNumber(Number) && args(Double)"; |
||||
|
||||
try { |
||||
getPointcut(expression).getClassFilter(); // call to getClassFilter forces resolution
|
||||
fail("Invalid expression should throw IllegalArgumentException"); |
||||
} |
||||
catch (IllegalArgumentException ex) { |
||||
assertTrue(true); |
||||
System.out.println(ex.getMessage()); |
||||
} |
||||
} |
||||
|
||||
private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) { |
||||
TestBean target = new TestBean(); |
||||
|
||||
Pointcut pointcut = getPointcut(pointcutExpression); |
||||
|
||||
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(); |
||||
advisor.setAdvice(interceptor); |
||||
advisor.setPointcut(pointcut); |
||||
|
||||
ProxyFactory pf = new ProxyFactory(); |
||||
pf.setTarget(target); |
||||
pf.addAdvisor(advisor); |
||||
|
||||
return (TestBean) pf.getProxy(); |
||||
} |
||||
|
||||
private void assertMatchesGetAge(MethodMatcher methodMatcher) { |
||||
assertTrue("Expression should match getAge() method", methodMatcher.matches(getAge, TestBean.class)); |
||||
} |
||||
|
||||
private void assertMatchesTestBeanClass(ClassFilter classFilter) { |
||||
assertTrue("Expression should match TestBean class", classFilter.matches(TestBean.class)); |
||||
} |
||||
|
||||
private void assertDoesNotMatchStringClass(ClassFilter classFilter) { |
||||
assertFalse("Expression should not match String class", classFilter.matches(String.class)); |
||||
} |
||||
|
||||
public void testWithUnsupportedPointcutPrimitive() throws Exception { |
||||
String expression = "call(int org.springframework.beans.TestBean.getAge())"; |
||||
|
||||
try { |
||||
getPointcut(expression).getClassFilter(); // call to getClassFilter forces resolution...
|
||||
fail("Should not support call pointcuts"); |
||||
} |
||||
catch (UnsupportedPointcutPrimitiveException ex) { |
||||
assertEquals("Should not support call pointcut", PointcutPrimitive.CALL, ex.getUnsupportedPrimitive()); |
||||
} |
||||
|
||||
} |
||||
|
||||
public void testAndSubstitution() { |
||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String)"); |
||||
PointcutExpression expr = |
||||
((AspectJExpressionPointcut) pc).getPointcutExpression(); |
||||
assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression()); |
||||
} |
||||
|
||||
public void testMultipleAndSubstitutions() { |
||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)"); |
||||
PointcutExpression expr = |
||||
((AspectJExpressionPointcut) pc).getPointcutExpression(); |
||||
assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression()); |
||||
} |
||||
|
||||
private Pointcut getPointcut(String expression) { |
||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); |
||||
pointcut.setExpression(expression); |
||||
return pointcut; |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* |
||||
* 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; |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* |
||||
* 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; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
/* |
||||
* 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 junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.TestBean; |
||||
|
||||
/** |
||||
* Tests for matching of bean() pointcut designator. |
||||
* |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public class BeanNamePointcutMatchingTests extends TestCase { |
||||
|
||||
public void testMatchingPointcuts() { |
||||
assertMatch("someName", "bean(someName)"); |
||||
|
||||
// Spring bean names are less restrictive compared to AspectJ names (methods, types etc.)
|
||||
// MVC Controller-kind
|
||||
assertMatch("someName/someOtherName", "bean(someName/someOtherName)"); |
||||
assertMatch("someName/foo/someOtherName", "bean(someName/*/someOtherName)"); |
||||
assertMatch("someName/foo/bar/someOtherName", "bean(someName/*/someOtherName)"); |
||||
assertMatch("someName/*/**", "bean(someName/*)"); |
||||
// JMX-kind
|
||||
assertMatch("service:name=traceService", "bean(service:name=traceService)"); |
||||
assertMatch("service:name=traceService", "bean(service:name=*)"); |
||||
assertMatch("service:name=traceService", "bean(*:name=traceService)"); |
||||
|
||||
// Wildcards
|
||||
assertMatch("someName", "bean(*someName)"); |
||||
assertMatch("someName", "bean(*Name)"); |
||||
assertMatch("someName", "bean(*)"); |
||||
assertMatch("someName", "bean(someName*)"); |
||||
assertMatch("someName", "bean(some*)"); |
||||
assertMatch("someName", "bean(some*Name)"); |
||||
assertMatch("someName", "bean(*some*Name*)"); |
||||
assertMatch("someName", "bean(*s*N*)"); |
||||
|
||||
// Or, and, not expressions
|
||||
assertMatch("someName", "bean(someName) || bean(someOtherName)"); |
||||
assertMatch("someOtherName", "bean(someName) || bean(someOtherName)"); |
||||
|
||||
assertMatch("someName", "!bean(someOtherName)"); |
||||
|
||||
assertMatch("someName", "bean(someName) || !bean(someOtherName)"); |
||||
assertMatch("someName", "bean(someName) && !bean(someOtherName)"); |
||||
} |
||||
|
||||
public void testNonMatchingPointcuts() { |
||||
assertMisMatch("someName", "bean(someNamex)"); |
||||
assertMisMatch("someName", "bean(someX*Name)"); |
||||
|
||||
// And, not expressions
|
||||
assertMisMatch("someName", "bean(someName) && bean(someOtherName)"); |
||||
assertMisMatch("someName", "!bean(someName)"); |
||||
assertMisMatch("someName", "!bean(someName) && bean(someOtherName)"); |
||||
assertMisMatch("someName", "!bean(someName) || bean(someOtherName)"); |
||||
} |
||||
|
||||
private void assertMatch(String beanName, String pcExpression) { |
||||
assertTrue("Unexpected mismatch for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"", |
||||
matches(beanName, pcExpression)); |
||||
} |
||||
|
||||
private void assertMisMatch(String beanName, String pcExpression) { |
||||
assertFalse("Unexpected match for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"", |
||||
matches(beanName, pcExpression)); |
||||
} |
||||
|
||||
private static boolean matches(final String beanName, String pcExpression) { |
||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut() { |
||||
protected String getCurrentProxiedBeanName() { |
||||
return beanName; |
||||
} |
||||
}; |
||||
pointcut.setExpression(pcExpression); |
||||
return pointcut.matches(TestBean.class); |
||||
} |
||||
} |
||||
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.lang.reflect.Method; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.aop.MethodBeforeAdvice; |
||||
import org.springframework.aop.framework.Advised; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.factory.FactoryBean; |
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* Test for correct application of the bean() PCD for XML-based AspectJ aspects. |
||||
* |
||||
* @author Ramnivas Laddad |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class BeanNamePointcutTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
protected ITestBean testBean1; |
||||
protected ITestBean testBean2; |
||||
protected ITestBean testBeanContainingNestedBean; |
||||
protected Map testFactoryBean1; |
||||
protected Map testFactoryBean2; |
||||
protected Counter counterAspect; |
||||
|
||||
protected ITestBean interceptThis; |
||||
protected ITestBean dontInterceptThis; |
||||
protected TestInterceptor testInterceptor; |
||||
|
||||
|
||||
public BeanNamePointcutTests() { |
||||
setPopulateProtectedVariables(true); |
||||
} |
||||
|
||||
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
|
||||
|
||||
public void testMatchingBeanName() { |
||||
assertTrue("Matching bean must be advised (proxied)", this.testBean1 instanceof Advised); |
||||
// Call two methods to test for SPR-3953-like condition
|
||||
this.testBean1.setAge(20); |
||||
this.testBean1.setName(""); |
||||
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount()); |
||||
} |
||||
|
||||
public void testNonMatchingBeanName() { |
||||
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBean2 instanceof Advised); |
||||
this.testBean2.setAge(20); |
||||
assertEquals("Advice must *not* have been executed", 0, this.counterAspect.getCount()); |
||||
} |
||||
|
||||
public void testNonMatchingNestedBeanName() { |
||||
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBeanContainingNestedBean.getDoctor() instanceof Advised); |
||||
} |
||||
|
||||
public void testMatchingFactoryBeanObject() { |
||||
assertTrue("Matching bean must be advised (proxied)", this.testFactoryBean1 instanceof Advised); |
||||
assertEquals("myValue", this.testFactoryBean1.get("myKey")); |
||||
assertEquals("myValue", this.testFactoryBean1.get("myKey")); |
||||
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount()); |
||||
FactoryBean fb = (FactoryBean) getApplicationContext().getBean("&testFactoryBean1"); |
||||
assertTrue("FactoryBean itself must *not* be advised", !(fb instanceof Advised)); |
||||
} |
||||
|
||||
public void testMatchingFactoryBeanItself() { |
||||
assertTrue("Matching bean must *not* be advised (proxied)", !(this.testFactoryBean2 instanceof Advised)); |
||||
FactoryBean fb = (FactoryBean) getApplicationContext().getBean("&testFactoryBean2"); |
||||
assertTrue("FactoryBean itself must be advised", fb instanceof Advised); |
||||
assertTrue(Map.class.isAssignableFrom(fb.getObjectType())); |
||||
assertTrue(Map.class.isAssignableFrom(fb.getObjectType())); |
||||
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount()); |
||||
} |
||||
|
||||
public void testPointcutAdvisorCombination() { |
||||
assertTrue("Matching bean must be advised (proxied)", this.interceptThis instanceof Advised); |
||||
assertFalse("Non-matching bean must *not* be advised (proxied)", this.dontInterceptThis instanceof Advised); |
||||
interceptThis.setAge(20); |
||||
assertEquals(1, testInterceptor.interceptionCount); |
||||
dontInterceptThis.setAge(20); |
||||
assertEquals(1, testInterceptor.interceptionCount); |
||||
} |
||||
|
||||
|
||||
public static class TestInterceptor implements MethodBeforeAdvice { |
||||
|
||||
private int interceptionCount; |
||||
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable { |
||||
interceptionCount++; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
/* |
||||
* 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.easymock.MockControl; |
||||
|
||||
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator; |
||||
|
||||
/** |
||||
* Tests for various parameter binding scenarios with before advice. |
||||
* |
||||
* @author Adrian Colyer |
||||
* @author Rod Johnson |
||||
*/ |
||||
public class BeforeAdviceBindingTests extends AbstractAdviceBindingTests { |
||||
|
||||
private AdviceBindingTestAspect beforeAdviceAspect; |
||||
|
||||
private MockControl mockControl; |
||||
|
||||
private AdviceBindingCollaborator mockCollaborator; |
||||
|
||||
|
||||
public void setBeforeAdviceAspect(AdviceBindingTestAspect anAspect) { |
||||
this.beforeAdviceAspect = anAspect; |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "before-advice-tests.xml"; |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
super.onSetUp(); |
||||
mockControl = MockControl.createNiceControl(AdviceBindingCollaborator.class); |
||||
mockCollaborator = (AdviceBindingCollaborator) mockControl.getMock(); |
||||
beforeAdviceAspect.setCollaborator(mockCollaborator); |
||||
} |
||||
|
||||
|
||||
public void testOneIntArg() { |
||||
mockCollaborator.oneIntArg(5); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneObjectArgBoundToProxyUsingThis() { |
||||
mockCollaborator.oneObjectArg(this.testBeanProxy); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testOneIntAndOneObjectArgs() { |
||||
mockCollaborator.oneIntAndOneObject(5,this.testBeanTarget); |
||||
mockControl.replay(); |
||||
testBeanProxy.setAge(5); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testNeedsJoinPoint() { |
||||
mockCollaborator.needsJoinPoint("getAge"); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
public void testNeedsJoinPointStaticPart() { |
||||
mockCollaborator.needsJoinPointStaticPart("getAge"); |
||||
mockControl.replay(); |
||||
testBeanProxy.getAge(); |
||||
mockControl.verify(); |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
|
||||
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; |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* A simple counter for use in simple tests (for example, how many times an advice was executed) |
||||
* |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public class Counter implements ICounter { |
||||
|
||||
private int count; |
||||
|
||||
public Counter() { |
||||
} |
||||
|
||||
public void increment() { |
||||
count++; |
||||
} |
||||
|
||||
public void decrement() { |
||||
count--; |
||||
} |
||||
|
||||
public int getCount() { |
||||
return count; |
||||
} |
||||
|
||||
public void setCount(int counter) { |
||||
this.count = counter; |
||||
} |
||||
|
||||
public void reset() { |
||||
this.count = 0; |
||||
} |
||||
} |
||||
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
/* |
||||
* 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 java.io.Serializable; |
||||
|
||||
import org.springframework.beans.factory.BeanNameAware; |
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class DeclarationOrderIndependenceTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private TopsyTurvyAspect aspect; |
||||
|
||||
private TopsyTurvyTarget target; |
||||
|
||||
|
||||
public DeclarationOrderIndependenceTests() { |
||||
setAutowireMode(AUTOWIRE_BY_NAME); |
||||
} |
||||
|
||||
public void setTopsyTurvyAspect(TopsyTurvyAspect aspect) { |
||||
this.aspect = aspect; |
||||
} |
||||
|
||||
public void setTopsyTurvyTarget(TopsyTurvyTarget target) { |
||||
this.target = target; |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "topsy-turvy-aspect.xml"; |
||||
} |
||||
|
||||
|
||||
public void testTargetIsSerializable() { |
||||
assertTrue("target bean is serializable",this.target instanceof Serializable); |
||||
} |
||||
|
||||
public void testTargetIsBeanNameAware() { |
||||
assertTrue("target bean is bean name aware",this.target instanceof BeanNameAware); |
||||
} |
||||
|
||||
public void testBeforeAdviceFiringOk() { |
||||
AspectCollaborator collab = new AspectCollaborator(); |
||||
this.aspect.setCollaborator(collab); |
||||
this.target.doSomething(); |
||||
assertTrue("before advice fired",collab.beforeFired); |
||||
} |
||||
|
||||
public void testAroundAdviceFiringOk() { |
||||
AspectCollaborator collab = new AspectCollaborator(); |
||||
this.aspect.setCollaborator(collab); |
||||
this.target.getX(); |
||||
assertTrue("around advice fired",collab.aroundFired); |
||||
} |
||||
|
||||
public void testAfterReturningFiringOk() { |
||||
AspectCollaborator collab = new AspectCollaborator(); |
||||
this.aspect.setCollaborator(collab); |
||||
this.target.getX(); |
||||
assertTrue("after returning advice fired",collab.afterReturningFired); |
||||
} |
||||
|
||||
private static class AspectCollaborator implements TopsyTurvyAspect.Collaborator { |
||||
|
||||
public boolean afterReturningFired = false; |
||||
public boolean aroundFired = false; |
||||
public boolean beforeFired = false; |
||||
|
||||
/* (non-Javadoc) |
||||
* @see org.springframework.aop.aspectj.TopsyTurvyAspect.Collaborator#afterReturningAdviceFired() |
||||
*/ |
||||
public void afterReturningAdviceFired() { |
||||
this.afterReturningFired = true; |
||||
} |
||||
|
||||
/* (non-Javadoc) |
||||
* @see org.springframework.aop.aspectj.TopsyTurvyAspect.Collaborator#aroundAdviceFired() |
||||
*/ |
||||
public void aroundAdviceFired() { |
||||
this.aroundFired = true; |
||||
} |
||||
|
||||
/* (non-Javadoc) |
||||
* @see org.springframework.aop.aspectj.TopsyTurvyAspect.Collaborator#beforeAdviceFired() |
||||
*/ |
||||
public void beforeAdviceFired() { |
||||
this.beforeFired = true; |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
|
||||
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public class DeclareParentsDelegateRefTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
protected NoMethodsBean noMethodsBean; |
||||
|
||||
protected CounterImpl counter; |
||||
|
||||
|
||||
public DeclareParentsDelegateRefTests() { |
||||
setPopulateProtectedVariables(true); |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
counter.reset(); |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "declare-parents-delegate-ref-tests.xml"; |
||||
} |
||||
|
||||
|
||||
public void testIntroductionWasMade() { |
||||
assertTrue("Introduction must have been made", noMethodsBean instanceof Counter); |
||||
} |
||||
|
||||
public void testIntroductionDelegation() { |
||||
((Counter)noMethodsBean).increment(); |
||||
assertEquals("Delegate's counter should be updated", 1, counter.count); |
||||
} |
||||
|
||||
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; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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; |
||||
import org.springframework.aop.support.AopUtils; |
||||
|
||||
/** |
||||
* @author Rod Johnson |
||||
*/ |
||||
public class DeclareParentsTests extends AbstractAdviceBindingTests { |
||||
|
||||
protected String getConfigPath() { |
||||
return "declare-parents-tests.xml"; |
||||
} |
||||
|
||||
public void testIntroductionWasMade() { |
||||
assertTrue("Introduction must have been made", testBeanProxy instanceof Lockable); |
||||
} |
||||
|
||||
// TODO if you change type pattern from org.springframework.beans..*
|
||||
// to org.springframework..* it also matches introduction.
|
||||
// Perhaps generated advisor bean definition could be made to depend
|
||||
// on the introduction, in which case this would not be a problem.
|
||||
public void testLockingWorks() { |
||||
Object introductionObject = applicationContext.getBean("introduction"); |
||||
assertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject)); |
||||
|
||||
Lockable lockable = (Lockable) testBeanProxy; |
||||
assertFalse(lockable.locked()); |
||||
|
||||
// Invoke a non-advised method
|
||||
testBeanProxy.getAge(); |
||||
|
||||
testBeanProxy.setName(""); |
||||
lockable.lock(); |
||||
try { |
||||
testBeanProxy.setName(" "); |
||||
fail("Should be locked"); |
||||
} |
||||
catch (IllegalStateException ex) { |
||||
// expected
|
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public interface ICounter { |
||||
|
||||
void increment(); |
||||
|
||||
void decrement(); |
||||
|
||||
int getCount(); |
||||
|
||||
void setCount(int counter); |
||||
|
||||
void reset(); |
||||
|
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
/* |
||||
* 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.aspectj.lang.ProceedingJoinPoint; |
||||
import org.springframework.beans.TestBean; |
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* Tests to check if the first implicit join point argument is correctly processed. |
||||
* See SPR-3723 for more details. |
||||
* |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public class ImplicitJPArgumentMatchingTests extends AbstractDependencyInjectionSpringContextTests { |
||||
protected TestBean testBean; |
||||
|
||||
public ImplicitJPArgumentMatchingTests() { |
||||
setPopulateProtectedVariables(true); |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "implicit-jp-argument-matching-tests.xml"; |
||||
} |
||||
|
||||
public void testAspect() { |
||||
// nothing to really test; it is enough if we don't get error while creating app context
|
||||
testBean.setCountry("US"); |
||||
} |
||||
|
||||
public static class CounterAspect { |
||||
public void increment(ProceedingJoinPoint pjp, Object bean, Object argument) throws Throwable { |
||||
pjp.proceed(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,180 @@
@@ -0,0 +1,180 @@
|
||||
/* |
||||
* 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.lang.reflect.Method; |
||||
import java.util.Arrays; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.aspectj.lang.JoinPoint; |
||||
import org.aspectj.lang.JoinPoint.StaticPart; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
import org.aspectj.lang.reflect.SourceLocation; |
||||
|
||||
import org.springframework.aop.MethodBeforeAdvice; |
||||
import org.springframework.aop.framework.AopContext; |
||||
import org.springframework.aop.framework.ProxyFactory; |
||||
import org.springframework.aop.interceptor.ExposeInvocationInterceptor; |
||||
import org.springframework.aop.support.AopUtils; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.TestBean; |
||||
|
||||
/** |
||||
* @author Rod Johnson |
||||
* @since 2.0 |
||||
*/ |
||||
public class MethodInvocationProceedingJoinPointTests extends TestCase { |
||||
|
||||
public void testingBindingWithJoinPoint() { |
||||
try { |
||||
AbstractAspectJAdvice.currentJoinPoint(); |
||||
fail("Needs to be bound by interceptor action"); |
||||
} |
||||
catch (IllegalStateException ex) { |
||||
// expected
|
||||
} |
||||
} |
||||
|
||||
public void testingBindingWithProceedingJoinPoint() { |
||||
try { |
||||
AbstractAspectJAdvice.currentJoinPoint(); |
||||
fail("Needs to be bound by interceptor action"); |
||||
} |
||||
catch (IllegalStateException ex) { |
||||
// expected
|
||||
} |
||||
} |
||||
|
||||
public void testCanGetMethodSignatureFromJoinPoint() { |
||||
final Object raw = new TestBean(); |
||||
// Will be set by advice during a method call
|
||||
final int newAge = 23; |
||||
|
||||
ProxyFactory pf = new ProxyFactory(raw); |
||||
pf.setExposeProxy(true); |
||||
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR); |
||||
pf.addAdvice(new MethodBeforeAdvice() { |
||||
private int depth; |
||||
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable { |
||||
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint(); |
||||
assertTrue("Method named in toString", jp.toString().indexOf(method.getName()) != -1); |
||||
// Ensure that these don't cause problems
|
||||
jp.toShortString(); |
||||
jp.toLongString(); |
||||
|
||||
assertSame(target, AbstractAspectJAdvice.currentJoinPoint().getTarget()); |
||||
assertFalse(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())); |
||||
|
||||
ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis(); |
||||
assertTrue(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())); |
||||
|
||||
assertNotSame(target, thisProxy); |
||||
|
||||
// Check getting again doesn't cause a problem
|
||||
assertSame(thisProxy, AbstractAspectJAdvice.currentJoinPoint().getThis()); |
||||
|
||||
// Try reentrant call--will go through this advice.
|
||||
// Be sure to increment depth to avoid infinite recursion
|
||||
if (depth++ == 0) { |
||||
// Check that toString doesn't cause a problem
|
||||
thisProxy.toString(); |
||||
// Change age, so this will be returned by invocation
|
||||
thisProxy.setAge(newAge); |
||||
assertEquals(newAge, thisProxy.getAge()); |
||||
} |
||||
|
||||
assertSame(AopContext.currentProxy(), thisProxy); |
||||
assertSame(target, raw); |
||||
|
||||
assertSame(method.getName(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getName()); |
||||
assertEquals(method.getModifiers(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers()); |
||||
|
||||
MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature(); |
||||
assertSame("Return same MethodSignature repeatedly", msig, AbstractAspectJAdvice.currentJoinPoint().getSignature()); |
||||
assertSame("Return same JoinPoint repeatedly", AbstractAspectJAdvice.currentJoinPoint(), AbstractAspectJAdvice.currentJoinPoint()); |
||||
assertEquals(method.getDeclaringClass(), msig.getDeclaringType()); |
||||
assertTrue(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes())); |
||||
assertEquals(method.getReturnType(), msig.getReturnType()); |
||||
assertTrue(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())); |
||||
try { |
||||
msig.getParameterNames(); |
||||
fail("Can't determine parameter names"); |
||||
} |
||||
catch (UnsupportedOperationException ex) { |
||||
// Expected
|
||||
} |
||||
msig.toLongString(); |
||||
msig.toShortString(); |
||||
} |
||||
}); |
||||
ITestBean itb = (ITestBean) pf.getProxy(); |
||||
// Any call will do
|
||||
assertEquals("Advice reentrantly set age", newAge, itb.getAge()); |
||||
} |
||||
|
||||
public void testCanGetSourceLocationFromJoinPoint() { |
||||
final Object raw = new TestBean(); |
||||
ProxyFactory pf = new ProxyFactory(raw); |
||||
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR); |
||||
pf.addAdvice(new MethodBeforeAdvice() { |
||||
public void before(Method method, Object[] args, Object target) throws Throwable { |
||||
SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(); |
||||
assertEquals("Same source location must be returned on subsequent requests", sloc, AbstractAspectJAdvice.currentJoinPoint().getSourceLocation()); |
||||
assertEquals(TestBean.class, sloc.getWithinType()); |
||||
try { |
||||
sloc.getLine(); |
||||
fail("Can't get line number"); |
||||
} |
||||
catch (UnsupportedOperationException ex) { |
||||
// Expected
|
||||
} |
||||
|
||||
try { |
||||
sloc.getFileName(); |
||||
fail("Can't get file name"); |
||||
} |
||||
catch (UnsupportedOperationException ex) { |
||||
// Expected
|
||||
} |
||||
} |
||||
}); |
||||
ITestBean itb = (ITestBean) pf.getProxy(); |
||||
// Any call will do
|
||||
itb.getAge(); |
||||
} |
||||
|
||||
public void testCanGetStaticPartFromJoinPoint() { |
||||
final Object raw = new TestBean(); |
||||
ProxyFactory pf = new ProxyFactory(raw); |
||||
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR); |
||||
pf.addAdvice(new MethodBeforeAdvice() { |
||||
public void before(Method method, Object[] args, Object target) throws Throwable { |
||||
StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart(); |
||||
assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart()); |
||||
assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind()); |
||||
assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature()); |
||||
assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation()); |
||||
} |
||||
}); |
||||
ITestBean itb = (ITestBean) pf.getProxy(); |
||||
// Any call will do
|
||||
itb.getAge(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* 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"); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* 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
|
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
/* |
||||
* 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 junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.factory.BeanCreationException; |
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
|
||||
/** |
||||
* Tests for overloaded advice. |
||||
* |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class OverloadedAdviceTests extends TestCase { |
||||
|
||||
public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() { |
||||
try { |
||||
new ClassPathXmlApplicationContext("org/springframework/aop/aspectj/overloaded-advice-tests.xml"); |
||||
} |
||||
catch (BeanCreationException ex) { |
||||
Throwable cause = ex.getRootCause(); |
||||
assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); |
||||
assertTrue("invalidAbsoluteTypeName should be detected by AJ", |
||||
cause.getMessage().indexOf("invalidAbsoluteTypeName") != -1); |
||||
} |
||||
} |
||||
|
||||
public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() { |
||||
try { |
||||
new ClassPathXmlApplicationContext("org/springframework/aop/aspectj/ambiguous-advice-tests.xml"); |
||||
} |
||||
catch (BeanCreationException ex) { |
||||
Throwable cause = ex.getRootCause(); |
||||
assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); |
||||
assertTrue("Cannot resolve method 'myBeforeAdvice' to a unique method", |
||||
cause.getMessage().indexOf("Cannot resolve method 'myBeforeAdvice' to a unique method") != -1); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
/* |
||||
* 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); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,214 @@
@@ -0,0 +1,214 @@
|
||||
/** |
||||
* 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.aspectj.lang.JoinPoint; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
|
||||
import org.springframework.core.JdkVersion; |
||||
import org.springframework.core.Ordered; |
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* Test for SPR-3522. Arguments changed on a call to proceed should be |
||||
* visible to advice further down the invocation chain. |
||||
* |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class ProceedTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private SimpleBean testBean; |
||||
|
||||
private ProceedTestingAspect testAspect; |
||||
|
||||
private ProceedTestingAspect secondTestAspect; |
||||
|
||||
|
||||
public ProceedTests() { |
||||
setAutowireMode(AUTOWIRE_BY_NAME); |
||||
} |
||||
|
||||
protected String[] getConfigLocations() { |
||||
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() { |
||||
this.testBean.setName("abc"); |
||||
assertEquals("Name changed in around advice", "ABC", this.testBean.getName()); |
||||
} |
||||
|
||||
public void testGetArgsIsDefensive() { |
||||
this.testBean.setAge(5); |
||||
assertEquals("getArgs is defensive", 5, this.testBean.getAge()); |
||||
} |
||||
|
||||
public void testProceedWithArgsInSameAspect() { |
||||
if (!JdkVersion.isAtLeastJava15()) { |
||||
// Doesn't work on JDK 1.4 for some reason...
|
||||
return; |
||||
} |
||||
|
||||
this.testBean.setMyFloat(1.0F); |
||||
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); |
||||
} |
||||
|
||||
public void testProceedWithArgsAcrossAspects() { |
||||
this.testBean.setSex("male"); |
||||
assertEquals("value changed in around advice","MALE", this.testBean.getSex()); |
||||
assertEquals("changed value visible to next before advice in chain","MALE", this.secondTestAspect.getLastBeforeStringValue()); |
||||
assertEquals("changed value visible to next around advice in chain","MALE", this.secondTestAspect.getLastAroundStringValue()); |
||||
} |
||||
|
||||
|
||||
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 { |
||||
|
||||
private int age; |
||||
private float aFloat; |
||||
private String name; |
||||
private String sex; |
||||
|
||||
public int getAge() { |
||||
return age; |
||||
} |
||||
|
||||
public float getMyFloat() { |
||||
return aFloat; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public String getSex() { |
||||
return sex; |
||||
} |
||||
|
||||
public void setAge(int age) { |
||||
this.age = age; |
||||
} |
||||
|
||||
public void setMyFloat(float f) { |
||||
this.aFloat = f; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public void setSex(String sex) { |
||||
this.sex = sex; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class ProceedTestingAspect implements Ordered { |
||||
|
||||
private String lastBeforeStringValue; |
||||
private String lastAroundStringValue; |
||||
private float lastBeforeFloatValue; |
||||
private int order; |
||||
|
||||
public void setOrder(int order) { this.order = order; } |
||||
public int getOrder() { return this.order; } |
||||
|
||||
public Object capitalize(ProceedingJoinPoint pjp, String value) throws Throwable { |
||||
return pjp.proceed(new Object[] {value.toUpperCase()}); |
||||
} |
||||
|
||||
public Object doubleOrQuits(ProceedingJoinPoint pjp) throws Throwable { |
||||
int value = ((Integer) pjp.getArgs()[0]).intValue(); |
||||
pjp.getArgs()[0] = new Integer(value * 2); |
||||
return pjp.proceed(); |
||||
} |
||||
|
||||
public Object addOne(ProceedingJoinPoint pjp, Float value) throws Throwable { |
||||
float fv = value.floatValue(); |
||||
return pjp.proceed(new Object[] {new Float(fv + 1.0F)}); |
||||
} |
||||
|
||||
public void captureStringArgument(JoinPoint tjp, String arg) { |
||||
if (!tjp.getArgs()[0].equals(arg)) { |
||||
throw new IllegalStateException( |
||||
"argument is '" + arg + "', " + |
||||
"but args array has '" + tjp.getArgs()[0] + "'" |
||||
); |
||||
} |
||||
this.lastBeforeStringValue = arg; |
||||
} |
||||
|
||||
public Object captureStringArgumentInAround(ProceedingJoinPoint pjp, String arg) throws Throwable { |
||||
if (!pjp.getArgs()[0].equals(arg)) { |
||||
throw new IllegalStateException( |
||||
"argument is '" + arg + "', " + |
||||
"but args array has '" + pjp.getArgs()[0] + "'"); |
||||
} |
||||
this.lastAroundStringValue = arg; |
||||
return pjp.proceed(); |
||||
} |
||||
|
||||
public void captureFloatArgument(JoinPoint tjp, float arg) { |
||||
float tjpArg = ((Float) tjp.getArgs()[0]).floatValue(); |
||||
if (Math.abs(tjpArg - arg) > 0.000001) { |
||||
throw new IllegalStateException( |
||||
"argument is '" + arg + "', " + |
||||
"but args array has '" + tjpArg + "'" |
||||
); |
||||
} |
||||
this.lastBeforeFloatValue = arg; |
||||
} |
||||
|
||||
public String getLastBeforeStringValue() { |
||||
return this.lastBeforeStringValue; |
||||
} |
||||
|
||||
public String getLastAroundStringValue() { |
||||
return this.lastAroundStringValue; |
||||
} |
||||
|
||||
public float getLastBeforeFloatValue() { |
||||
return this.lastBeforeFloatValue; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/* |
||||
* 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 { |
||||
|
||||
} |
||||
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
/* |
||||
* 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.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* See SPR-1682. |
||||
* |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class SharedPointcutWithArgsMismatch extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private ToBeAdvised toBeAdvised; |
||||
|
||||
|
||||
public void setToBeAdvised(ToBeAdvised tba) { |
||||
this.toBeAdvised = tba; |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "args-mismatch.xml"; |
||||
} |
||||
|
||||
|
||||
public void testMismatchedArgBinding() { |
||||
this.toBeAdvised.foo("Hello"); |
||||
} |
||||
|
||||
|
||||
public static class ToBeAdvised { |
||||
|
||||
public void foo(String s) { |
||||
System.out.println(s); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class MyAspect { |
||||
|
||||
public void doBefore(int x) { |
||||
System.out.println(x); |
||||
} |
||||
|
||||
public void doBefore(String x) { |
||||
System.out.println(x); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
/* |
||||
* 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; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* 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) {} |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
/* |
||||
* 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.Advised; |
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class SubtypeSensitiveMatchingTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
private NonSerializableFoo nonSerializableBean; |
||||
|
||||
private SerializableFoo serializableBean; |
||||
|
||||
private Bar bar; |
||||
|
||||
|
||||
public void setNonSerializableFoo(NonSerializableFoo aBean) { |
||||
this.nonSerializableBean = aBean; |
||||
} |
||||
|
||||
public void setSerializableFoo(SerializableFoo aBean) { |
||||
this.serializableBean = aBean; |
||||
} |
||||
|
||||
public void setBar(Bar aBean) { |
||||
this.bar = aBean; |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "subtype-sensitive-matching.xml"; |
||||
} |
||||
|
||||
|
||||
public void testBeansAreProxiedOnStaticMatch() { |
||||
assertTrue("bean with serializable type should be proxied", |
||||
this.serializableBean instanceof Advised); |
||||
} |
||||
|
||||
public void testBeansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() { |
||||
assertFalse("bean with non-serializable type should not be proxied", |
||||
this.nonSerializableBean instanceof Advised); |
||||
} |
||||
|
||||
public void testBeansThatDoNotMatchBasedOnOtherTestAreProxied() { |
||||
assertTrue("bean with args check should be proxied", |
||||
this.bar instanceof Advised); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
/* |
||||
* 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.aopalliance.intercept.MethodInterceptor; |
||||
import org.aopalliance.intercept.MethodInvocation; |
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* Tests for target selection matching (see SPR-3783). |
||||
* Thanks to Tomasz Blachowicz for the bug report! |
||||
* |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public class TargetPointcutSelectionTests extends AbstractDependencyInjectionSpringContextTests { |
||||
|
||||
protected TestInterface testImpl1; |
||||
protected TestInterface testImpl2; |
||||
protected TestAspect testAspectForTestImpl1; |
||||
protected TestAspect testAspectForAbstractTestImpl; |
||||
protected TestInterceptor testInterceptor; |
||||
|
||||
|
||||
public TargetPointcutSelectionTests() { |
||||
setPopulateProtectedVariables(true); |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "targetPointcutSelectionTests.xml"; |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
testAspectForTestImpl1.count = 0; |
||||
testAspectForAbstractTestImpl.count = 0; |
||||
testInterceptor.count = 0; |
||||
super.onSetUp(); |
||||
} |
||||
|
||||
|
||||
public void testTargetSelectionForMatchedType() { |
||||
testImpl1.interfaceMethod(); |
||||
assertEquals("Should have been advised by POJO advice for impl", 1, testAspectForTestImpl1.count); |
||||
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count); |
||||
assertEquals("Should have been advised by advisor", 1, testInterceptor.count); |
||||
} |
||||
|
||||
public void testTargetNonSelectionForMismatchedType() { |
||||
testImpl2.interfaceMethod(); |
||||
assertEquals("Shouldn't have been advised by POJO advice for impl", 0, testAspectForTestImpl1.count); |
||||
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count); |
||||
assertEquals("Shouldn't have been advised by advisor", 0, testInterceptor.count); |
||||
} |
||||
|
||||
|
||||
public static interface TestInterface { |
||||
|
||||
public void interfaceMethod(); |
||||
} |
||||
|
||||
|
||||
// Reproducing bug requires that the class specified in target() pointcut doesn't
|
||||
// include the advised method's implementation (instead a base class should include it)
|
||||
public static abstract class AbstractTestImpl implements TestInterface { |
||||
|
||||
public void interfaceMethod() { |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class TestImpl1 extends AbstractTestImpl { |
||||
} |
||||
|
||||
|
||||
public static class TestImpl2 extends AbstractTestImpl { |
||||
} |
||||
|
||||
|
||||
public static class TestAspect { |
||||
|
||||
public int count; |
||||
|
||||
public void increment() { |
||||
count++; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class TestInterceptor extends TestAspect implements MethodInterceptor { |
||||
|
||||
public Object invoke(MethodInvocation mi) throws Throwable { |
||||
increment(); |
||||
return mi.proceed(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
/* |
||||
* 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.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public class ThisAndTargetSelectionOnlyPointcutsTests extends AbstractDependencyInjectionSpringContextTests { |
||||
protected TestInterface testBean; |
||||
|
||||
protected Counter thisAsClassCounter; |
||||
protected Counter thisAsInterfaceCounter; |
||||
protected Counter targetAsClassCounter; |
||||
protected Counter targetAsInterfaceCounter; |
||||
protected Counter thisAsClassAndTargetAsClassCounter; |
||||
protected Counter thisAsInterfaceAndTargetAsInterfaceCounter; |
||||
protected Counter thisAsInterfaceAndTargetAsClassCounter; |
||||
|
||||
public ThisAndTargetSelectionOnlyPointcutsTests() { |
||||
setPopulateProtectedVariables(true); |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
super.onSetUp(); |
||||
thisAsClassCounter.reset(); |
||||
thisAsInterfaceCounter.reset(); |
||||
targetAsClassCounter.reset(); |
||||
targetAsInterfaceCounter.reset(); |
||||
|
||||
thisAsClassAndTargetAsClassCounter.reset(); |
||||
thisAsInterfaceAndTargetAsInterfaceCounter.reset(); |
||||
thisAsInterfaceAndTargetAsClassCounter.reset(); |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "this-and-target-selectionOnly-pointcuts-tests.xml"; |
||||
} |
||||
|
||||
public void testThisAsClassDoesNotMatch() { |
||||
testBean.doIt(); |
||||
assertEquals(0, thisAsClassCounter.getCount()); |
||||
} |
||||
|
||||
public void testThisAsInterfaceMatch() { |
||||
testBean.doIt(); |
||||
assertEquals(1, thisAsInterfaceCounter.getCount()); |
||||
} |
||||
|
||||
public void testTargetAsClassDoesMatch() { |
||||
testBean.doIt(); |
||||
assertEquals(1, targetAsClassCounter.getCount()); |
||||
} |
||||
|
||||
public void testTargetAsInterfaceMatch() { |
||||
testBean.doIt(); |
||||
assertEquals(1, targetAsInterfaceCounter.getCount()); |
||||
} |
||||
|
||||
public void testThisAsClassAndTargetAsClassCounterNotMatch() { |
||||
testBean.doIt(); |
||||
assertEquals(0, thisAsClassAndTargetAsClassCounter.getCount()); |
||||
} |
||||
|
||||
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() { |
||||
testBean.doIt(); |
||||
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount()); |
||||
} |
||||
|
||||
public void testThisAsInterfaceAndTargetAsClassCounterMatch() { |
||||
testBean.doIt(); |
||||
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount()); |
||||
} |
||||
|
||||
public static interface TestInterface { |
||||
public void doIt(); |
||||
} |
||||
|
||||
public static class TestImpl implements TestInterface { |
||||
public void doIt() { |
||||
} |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/* |
||||
* 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; |
||||
} |
||||
} |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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(); |
||||
|
||||
} |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
/* |
||||
* 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; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
/* |
||||
* 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 junit.framework.TestCase; |
||||
import org.springframework.aop.framework.autoproxy.CountingTestBean; |
||||
import org.springframework.beans.IOther; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.TestBean; |
||||
import org.springframework.beans.factory.BeanFactory; |
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
||||
import org.springframework.test.AssertThrows; |
||||
|
||||
/** |
||||
* Unit tests for the {@link TypePatternClassFilter} class. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Rick Evans |
||||
*/ |
||||
public final class TypePatternClassFilterTests extends TestCase { |
||||
|
||||
public void testInvalidPattern() { |
||||
try { |
||||
new TypePatternClassFilter("-"); |
||||
fail("Pattern must be recognized as invalid."); |
||||
} |
||||
catch (IllegalArgumentException expected) { |
||||
} |
||||
} |
||||
|
||||
public void testValidPatternMatching() { |
||||
TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.beans.*"); |
||||
assertTrue("Must match: in package", tpcf.matches(TestBean.class)); |
||||
assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); |
||||
assertTrue("Must match: in package", tpcf.matches(IOther.class)); |
||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(CountingTestBean.class)); |
||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class)); |
||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class)); |
||||
} |
||||
|
||||
public void testSubclassMatching() { |
||||
TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.beans.ITestBean+"); |
||||
assertTrue("Must match: in package", tpcf.matches(TestBean.class)); |
||||
assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); |
||||
assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class)); |
||||
assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class)); |
||||
assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class)); |
||||
} |
||||
|
||||
public void testAndOrNotReplacement() { |
||||
TypePatternClassFilter tpcf = new TypePatternClassFilter("java.lang.Object or java.lang.String"); |
||||
assertFalse("matches Number",tpcf.matches(Number.class)); |
||||
assertTrue("matches Object",tpcf.matches(Object.class)); |
||||
assertTrue("matchesString",tpcf.matches(String.class)); |
||||
tpcf = new TypePatternClassFilter("java.lang.Number+ and java.lang.Float"); |
||||
assertTrue("matches Float",tpcf.matches(Float.class)); |
||||
assertFalse("matches Double",tpcf.matches(Double.class)); |
||||
tpcf = new TypePatternClassFilter("java.lang.Number+ and not java.lang.Float"); |
||||
assertFalse("matches Float",tpcf.matches(Float.class)); |
||||
assertTrue("matches Double",tpcf.matches(Double.class)); |
||||
} |
||||
|
||||
public void testSetTypePatternWithNullArgument() throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
new TypePatternClassFilter(null); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
|
||||
public void testInvocationOfMatchesMethodBlowsUpWhenNoTypePatternHasBeenSet() throws Exception { |
||||
new AssertThrows(IllegalStateException.class) { |
||||
public void test() throws Exception { |
||||
new TypePatternClassFilter().matches(String.class); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
|
||||
<aop:advisor id="lowPrecedenceAdvisor" |
||||
advice-ref="lowPrecedenceSpringAdvice" |
||||
pointcut="execution(* getAge(..))" |
||||
order="900"/> |
||||
|
||||
<aop:advisor id="highPrecedenceAdvisor" |
||||
advice-ref="highPrecedenceSpringAdvice" |
||||
pointcut="execution(* getAge(..))" |
||||
order="90"/> |
||||
|
||||
<aop:aspect ref="lowPrecedenceAspect" order="1000"> |
||||
|
||||
<aop:before |
||||
method="beforeAdviceOne" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:before |
||||
method="beforeAdviceTwo" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:around |
||||
method="aroundAdviceOne" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:around |
||||
method="aroundAdviceTwo" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:after-returning |
||||
method="afterAdviceOne" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:after-returning |
||||
method="afterAdviceTwo" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="highPrecedenceAspect"> |
||||
|
||||
<aop:before |
||||
method="beforeAdviceOne" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:before |
||||
method="beforeAdviceTwo" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:around |
||||
method="aroundAdviceOne" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:around |
||||
method="aroundAdviceTwo" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:after-returning |
||||
method="afterAdviceOne" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
<aop:after-returning |
||||
method="afterAdviceTwo" |
||||
pointcut="execution(* getAge())"/> |
||||
|
||||
</aop:aspect> |
||||
|
||||
</aop:config> |
||||
|
||||
<bean id="highPrecedenceSpringAdvice" class="org.springframework.aop.aspectj.SimpleSpringBeforeAdvice"/> |
||||
|
||||
<bean id="lowPrecedenceSpringAdvice" class="org.springframework.aop.aspectj.SimpleSpringBeforeAdvice"/> |
||||
|
||||
<bean id="highPrecedenceAspect" class="org.springframework.aop.aspectj.PrecedenceTestAspect"> |
||||
<property name="order" value="10"/> |
||||
</bean> |
||||
|
||||
<bean id="lowPrecedenceAspect" class="org.springframework.aop.aspectj.PrecedenceTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="afterAdviceBindingTests" ref="testAspect"> |
||||
<aop:after method="oneIntArg" pointcut="execution(* setAge(int)) and args(age)"/> |
||||
<aop:after method="oneObjectArg" pointcut="execution(* getAge()) and this(bean)"/> |
||||
<aop:after method="oneObjectArg" pointcut="execution(* getDoctor()) and target(bean)"/> |
||||
<aop:after method="oneIntAndOneObject" |
||||
pointcut="execution(* setAge(..)) and args(age) and this(bean)" arg-names="age,bean"/> |
||||
<aop:after method="needsJoinPoint" pointcut="execution(* getAge())"/> |
||||
<aop:after method="needsJoinPointStaticPart" pointcut="execution(* getAge())"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.AdviceBindingTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="afterReturningAdviceBindingTests" ref="testAspect"> |
||||
<aop:after-returning method="oneIntArg" pointcut="execution(* setAge(int)) and args(age)"/> |
||||
<aop:after-returning method="oneObjectArg" pointcut="execution(* getAge()) and this(bean)"/> |
||||
<aop:after-returning method="oneIntAndOneObject" |
||||
pointcut="execution(* setAge(..)) and args(age) and this(bean)" arg-names="age,bean"/> |
||||
<aop:after-returning method="needsJoinPoint" pointcut="execution(* getAge())"/> |
||||
<aop:after-returning method="needsJoinPointStaticPart" pointcut="execution(* getAge())"/> |
||||
<!-- additional tests using the returning attribute --> |
||||
<aop:after-returning method="oneString" returning="name" pointcut="execution(* getName())"/> |
||||
<aop:after-returning method="oneObjectArg" returning="bean" pointcut="execution(* returnsThis())"/> |
||||
<aop:after-returning method="oneTestBeanArg" returning="bean" pointcut="execution(* returnsThis())"/> |
||||
<aop:after-returning method="testBeanArrayArg" returning="beans" |
||||
pointcut="execution(org.springframework.beans.ITestBean[] *(..))"/> |
||||
<aop:after-returning method="oneString" returning="name" pointcut="execution(* getSpouse())"/> |
||||
<aop:after-returning method="objectMatchNoArgs" returning="java.lang.Object" |
||||
pointcut="execution(* returnsThis())"/> |
||||
<aop:after-returning method="stringMatchNoArgs" returning="java.lang.String" |
||||
pointcut="execution(* getSpouse())"/> |
||||
<aop:after-returning method="oneInt" returning="result" pointcut="execution(* haveBirthday())"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.AfterReturningAdviceBindingTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
|
||||
<aop:config> |
||||
<aop:aspect id="afterThrowingAdviceBindingTests" ref="testAspect"> |
||||
<aop:after-throwing |
||||
method="noArgs" |
||||
pointcut="execution(* exceptional(..))" |
||||
/> |
||||
<aop:after-throwing |
||||
method="oneThrowable" |
||||
throwing="t" |
||||
pointcut="execution(* exceptional(..))" |
||||
/> |
||||
<aop:after-throwing |
||||
method="oneRuntimeException" |
||||
throwing="ex" |
||||
pointcut="execution(* exceptional(..))" |
||||
/> |
||||
<aop:after-throwing |
||||
method="noArgsOnThrowableMatch" |
||||
throwing="java.lang.Throwable" |
||||
pointcut="execution(* exceptional(..))" |
||||
/> |
||||
<aop:after-throwing |
||||
method="noArgsOnRuntimeExceptionMatch" |
||||
throwing="java.lang.RuntimeException" |
||||
pointcut="execution(* exceptional(..))" |
||||
/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.AfterThrowingAdviceBindingTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
|
||||
<aop:config> |
||||
<aop:aspect id="ambiguousAdviceTest" ref="testAspect"> |
||||
<aop:pointcut id="setter" expression="execution(* setName(..)) and args(name)"/> |
||||
<aop:before pointcut-ref="setter" method="myBeforeAdvice"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.OverloadedAdviceTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
|
||||
<aop:config> |
||||
<aop:aspect id="beforeAdviceBindingTests" ref="testAspect"> |
||||
<aop:pointcut id="foo" expression="execution(* foo(..)) and args(x)"/> |
||||
<aop:before pointcut-ref="foo" method="doBefore(int)"/> |
||||
<aop:before pointcut-ref="foo" method="doBefore(java.lang.String)"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="someBean" class="org.springframework.aop.aspectj.SharedPointcutWithArgsMismatch$ToBeAdvised"/> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.SharedPointcutWithArgsMismatch$MyAspect"/> |
||||
</beans> |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="beforeAdviceBindingTests" ref="testAspect"> |
||||
<aop:around method="oneIntArg" pointcut="execution(* setAge(int)) and args(age)" /> |
||||
<aop:around method="oneObjectArg" pointcut="execution(* getAge()) and target(bean)"/> |
||||
<aop:around method="oneIntAndOneObject" |
||||
pointcut="execution(* setAge(..)) and args(age) and this(bean)" arg-names="thisJoinPoint,age,bean"/> |
||||
<aop:around method="justJoinPoint" pointcut="execution(* getAge())"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.AroundAdviceBindingTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"> |
||||
<property name="spouse" ref="testBean2"/> |
||||
</bean> |
||||
|
||||
<bean id="testBean2" class="org.springframework.beans.TestBean" autowire-candidate="false"> |
||||
<property name="spouse" ref="testBean"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="beforeAdviceBindingTests" ref="testAspect"> |
||||
<aop:around method="oneIntArg" pointcut="execution(* setAge(int)) and args(age)" /> |
||||
<aop:around method="oneObjectArg" pointcut="execution(* getAge()) and target(bean)"/> |
||||
<aop:around method="oneIntAndOneObject" |
||||
pointcut="execution(* setAge(..)) and args(age) and this(bean)" arg-names="thisJoinPoint,age,bean"/> |
||||
<aop:around method="justJoinPoint" pointcut="execution(* getAge())"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.AroundAdviceBindingTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> |
||||
|
||||
<beans> |
||||
|
||||
<bean id="proxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="advisor" class="org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor"> |
||||
<property name="expression" |
||||
value="execution(org.springframework.beans.ITestBean[] org.springframework.beans.ITestBean.*(..))"/> |
||||
<property name="advice" ref="interceptor"/> |
||||
</bean> |
||||
|
||||
<bean id="interceptor" class="org.springframework.aop.aspectj.CallCountingInterceptor"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
/* |
||||
* Copyright 2002-2007 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.aop.aspectj.autoproxy; |
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.springframework.aop.framework.Advised; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
||||
|
||||
/** |
||||
* Test for ensuring the aspects aren't advised. See SPR-3893 for more details. |
||||
* |
||||
* @author Ramnivas Laddad |
||||
*/ |
||||
public class AspectImplementingInterfaceTests extends AbstractDependencyInjectionSpringContextTests { |
||||
protected ITestBean testBean; |
||||
protected AnInterface interfaceExtendingAspect; |
||||
|
||||
public AspectImplementingInterfaceTests() { |
||||
setPopulateProtectedVariables(true); |
||||
} |
||||
|
||||
protected String getConfigPath() { |
||||
return "aspect-implementing-interface-tests.xml"; |
||||
} |
||||
|
||||
protected void onSetUp() throws Exception { |
||||
super.onSetUp(); |
||||
} |
||||
|
||||
public void testProxyCreation() { |
||||
assertTrue(testBean instanceof Advised); |
||||
assertFalse(interfaceExtendingAspect instanceof Advised); |
||||
} |
||||
|
||||
public static interface AnInterface { |
||||
public void interfaceMethod(); |
||||
} |
||||
|
||||
public static class InterfaceExtendingAspect implements AnInterface { |
||||
public void increment(ProceedingJoinPoint pjp) throws Throwable { |
||||
pjp.proceed(); |
||||
} |
||||
|
||||
public void interfaceMethod() { |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,223 @@
@@ -0,0 +1,223 @@
|
||||
/* |
||||
* Copyright 2002-2007 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.aop.aspectj.autoproxy; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.aop.Advisor; |
||||
import org.springframework.aop.AfterReturningAdvice; |
||||
import org.springframework.aop.BeforeAdvice; |
||||
import org.springframework.aop.aspectj.AbstractAspectJAdvice; |
||||
import org.springframework.aop.aspectj.AspectJAfterAdvice; |
||||
import org.springframework.aop.aspectj.AspectJAfterReturningAdvice; |
||||
import org.springframework.aop.aspectj.AspectJAfterThrowingAdvice; |
||||
import org.springframework.aop.aspectj.AspectJAroundAdvice; |
||||
import org.springframework.aop.aspectj.AspectJExpressionPointcut; |
||||
import org.springframework.aop.aspectj.AspectJMethodBeforeAdvice; |
||||
import org.springframework.aop.aspectj.AspectJPointcutAdvisor; |
||||
import org.springframework.aop.support.DefaultPointcutAdvisor; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AspectJPrecedenceComparatorTests extends TestCase { |
||||
|
||||
/* |
||||
* Specification for the comparator (as defined in the |
||||
* AspectJPrecedenceComparator class) |
||||
* |
||||
* <p> |
||||
* Orders AspectJ advice/advisors by invocation order. |
||||
* </p> |
||||
* <p> |
||||
* Given two pieces of advice, <code>a</code> and <code>b</code>: |
||||
* </p> |
||||
* <ul> |
||||
* <li>if <code>a</code> and <code>b</code> are defined in different |
||||
* aspects, then the advice in the aspect with the lowest order |
||||
* value has the highest precedence</li> |
||||
* <li>if <code>a</code> and <code>b</code> are defined in the same |
||||
* aspect, then if one of <code>a</code> or <code>b</code> is a form of |
||||
* after advice, then the advice declared last in the aspect has the |
||||
* highest precedence. If neither <code>a</code> nor <code>b</code> is a |
||||
* form of after advice, then the advice declared first in the aspect has |
||||
* the highest precedence.</li> |
||||
* </ul> |
||||
*/ |
||||
|
||||
private static final int HIGH_PRECEDENCE_ADVISOR_ORDER = 100; |
||||
private static final int LOW_PRECEDENCE_ADVISOR_ORDER = 200; |
||||
private static final int EARLY_ADVICE_DECLARATION_ORDER = 5; |
||||
private static final int LATE_ADVICE_DECLARATION_ORDER = 10; |
||||
|
||||
|
||||
private AspectJPrecedenceComparator comparator; |
||||
|
||||
private Method anyOldMethod; |
||||
|
||||
private AspectJExpressionPointcut anyOldPointcut; |
||||
|
||||
|
||||
protected void setUp() throws Exception { |
||||
this.comparator = new AspectJPrecedenceComparator(); |
||||
this.anyOldMethod = getClass().getMethods()[0]; |
||||
this.anyOldPointcut = new AspectJExpressionPointcut(); |
||||
this.anyOldPointcut.setExpression("execution(* *(..))"); |
||||
} |
||||
|
||||
|
||||
public void testSameAspectNoAfterAdvice() { |
||||
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
assertEquals("advisor2 sorted before advisor1", 1, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testSameAspectAfterAdvice() { |
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
assertEquals("advisor2 sorted before advisor1", 1, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testSameAspectOneOfEach() { |
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
assertEquals("advisor1 and advisor2 not comparable", 0, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testSameAdvisorPrecedenceDifferentAspectNoAfterAdvice() { |
||||
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testSameAdvisorPrecedenceDifferentAspectAfterAdvice() { |
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testHigherAdvisorPrecedenceNoAfterAdvice() { |
||||
Advisor advisor1 = createSpringAOPBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER); |
||||
Advisor advisor2 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testHigherAdvisorPrecedenceAfterAdvice() { |
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
advisor2 = createAspectJAfterThrowingAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor2 sorted after advisor1", -1, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testLowerAdvisorPrecedenceNoAfterAdvice() { |
||||
Advisor advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
public void testLowerAdvisorPrecedenceAfterAdvice() { |
||||
Advisor advisor1 = createAspectJAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect"); |
||||
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2)); |
||||
|
||||
advisor1 = createSpringAOPAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER); |
||||
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect"); |
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2)); |
||||
} |
||||
|
||||
|
||||
private Advisor createAspectJBeforeAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) { |
||||
AspectJMethodBeforeAdvice advice = new AspectJMethodBeforeAdvice(this.anyOldMethod, this.anyOldPointcut, null); |
||||
return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice); |
||||
} |
||||
|
||||
private Advisor createAspectJAroundAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) { |
||||
AspectJAroundAdvice advice = new AspectJAroundAdvice(this.anyOldMethod, this.anyOldPointcut, null); |
||||
return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice); |
||||
} |
||||
|
||||
private Advisor createAspectJAfterAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) { |
||||
AspectJAfterAdvice advice = new AspectJAfterAdvice(this.anyOldMethod, this.anyOldPointcut, null); |
||||
return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice); |
||||
} |
||||
|
||||
private Advisor createAspectJAfterReturningAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) { |
||||
AspectJAfterReturningAdvice advice = new AspectJAfterReturningAdvice(this.anyOldMethod, this.anyOldPointcut, null); |
||||
return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice); |
||||
} |
||||
|
||||
private Advisor createAspectJAfterThrowingAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) { |
||||
AspectJAfterThrowingAdvice advice = new AspectJAfterThrowingAdvice(this.anyOldMethod, this.anyOldPointcut, null); |
||||
return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice); |
||||
} |
||||
|
||||
private Advisor createAspectJAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName, AbstractAspectJAdvice advice) { |
||||
advice.setDeclarationOrder(adviceDeclarationOrder); |
||||
advice.setAspectName(aspectName); |
||||
AspectJPointcutAdvisor advisor = new AspectJPointcutAdvisor(advice); |
||||
advisor.setOrder(advisorOrder); |
||||
return advisor; |
||||
} |
||||
|
||||
private Advisor createSpringAOPAfterAdvice(int order) { |
||||
AfterReturningAdvice advice = new AfterReturningAdvice() { |
||||
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { |
||||
} |
||||
}; |
||||
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice); |
||||
advisor.setOrder(order); |
||||
return advisor; |
||||
} |
||||
|
||||
private Advisor createSpringAOPBeforeAdvice(int order) { |
||||
BeforeAdvice advice = new BeforeAdvice() { |
||||
}; |
||||
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice); |
||||
advisor.setOrder(order); |
||||
return advisor; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect ref="interfaceExtendingAspect"> |
||||
<aop:pointcut id="anyOperation" |
||||
expression="execution(* *(..))"/> |
||||
<aop:around pointcut-ref="anyOperation" method="increment"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean" /> |
||||
|
||||
<bean id="interfaceExtendingAspect" |
||||
class="org.springframework.aop.aspectj.autoproxy.AspectImplementingInterfaceTests$InterfaceExtendingAspect"/> |
||||
</beans> |
||||
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="beanNameMatchingTest" ref="counterAspect"> |
||||
<aop:pointcut id="bean1Operation" expression="execution(* set*(..)) and bean(myBean) and !bean(foo)"/> |
||||
<aop:before pointcut-ref="bean1Operation" method="increment()"/> |
||||
|
||||
<aop:pointcut id="nestedBeanOperation" expression="execution(* getCompany(..)) and bean(testBean*)"/> |
||||
<aop:before pointcut-ref="nestedBeanOperation" method="increment()"/> |
||||
|
||||
<aop:pointcut id="factoryBean1Operation" expression="bean(testFactoryBean1)"/> |
||||
<aop:before pointcut-ref="factoryBean1Operation" method="increment()"/> |
||||
|
||||
<aop:pointcut id="factoryBean2Operation" expression="bean(&testFactoryBean2)"/> |
||||
<aop:before pointcut-ref="factoryBean2Operation" method="increment()"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testBean1" name="myBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="testBean2" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="testBeanContainingNestedBean" class="org.springframework.beans.TestBean"> |
||||
<property name="doctor"> |
||||
<bean class="org.springframework.beans.NestedTestBean"/> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="testFactoryBean1" class="org.springframework.beans.factory.config.MapFactoryBean"> |
||||
<property name="sourceMap"> |
||||
<map> |
||||
<entry key="myKey" value="myValue"/> |
||||
</map> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="testFactoryBean2" class="org.springframework.beans.factory.config.MapFactoryBean"> |
||||
<property name="sourceMap"> |
||||
<map> |
||||
<entry key="myKey" value="myValue"/> |
||||
</map> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.Counter"/> |
||||
|
||||
<aop:config> |
||||
<aop:advisor pointcut="bean(*This) and !bean(dont*)" advice-ref="testInterceptor"/> |
||||
</aop:config> |
||||
|
||||
<bean id="interceptThis" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="dontInterceptThis" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="testInterceptor" class="org.springframework.aop.aspectj.BeanNamePointcutTests$TestInterceptor"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="beforeAdviceBindingTests" ref="testAspect"> |
||||
<aop:before method="oneIntArg" pointcut="execution(* setAge(int)) and args(age)"/> |
||||
<aop:before method="oneObjectArg" pointcut="execution(* getAge()) and this(bean)"/> |
||||
<aop:before method="oneIntAndOneObject" |
||||
pointcut="execution(* setAge(..)) and args(age) and target(bean)" arg-names="age,bean"/> |
||||
<aop:before method="needsJoinPoint" pointcut="execution(* getAge())"/> |
||||
<aop:before method="needsJoinPointStaticPart" pointcut="execution(* getAge())"/> |
||||
</aop:aspect> |
||||
|
||||
<!-- variation with external pointcut reference --> |
||||
<aop:aspect ref="authenticationLogger"> |
||||
<aop:pointcut id="authenticationMethodWithString" |
||||
expression="execution(boolean *..SecurityManager.authenticate(..)) and args(username,java.lang.String)"/> |
||||
<aop:before pointcut-ref="authenticationMethodWithString" |
||||
method="logAuthenticationAttempt(java.lang.String)"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.AdviceBindingTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="authenticationLogger" class="org.springframework.aop.aspectj.AuthenticationLogger"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="testAspect"> |
||||
<aop:declare-parents |
||||
types-matching="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests.NoMethodsBean+" |
||||
implement-interface="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests$Counter" |
||||
delegate-ref="counter" |
||||
/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="noMethodsBean" class="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests$NoMethodsBeanImpl"/> |
||||
|
||||
<bean id="counter" class="org.springframework.aop.aspectj.DeclareParentsDelegateRefTests$CounterImpl"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="beforeAdviceBindingTests" ref="introduction"> |
||||
<aop:declare-parents |
||||
types-matching="org.springframework.beans..*" |
||||
implement-interface="org.springframework.aop.framework.Lockable" |
||||
default-impl="org.springframework.aop.framework.DefaultLockable" |
||||
/> |
||||
<aop:before |
||||
method="checkNotLocked" |
||||
pointcut="execution(* set*(*)) and this(mixin)" |
||||
arg-names="mixin" |
||||
/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="introduction" class="org.springframework.aop.aspectj.NonAnnotatedMakeLockable"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config proxy-target-class="true"> |
||||
<aop:aspect ref="counterAspect"> |
||||
<aop:pointcut id="anyOperation" |
||||
expression="execution(* org.springframework.beans.TestBean.*(..)) and this(bean) and args(argument)"/> |
||||
<aop:around pointcut-ref="anyOperation" method="increment" arg-names="bean,argument"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"> |
||||
<property name="name" value="aTestBean"/> |
||||
</bean> |
||||
|
||||
<bean id="counterAspect" |
||||
class="org.springframework.aop.aspectj.ImplicitJPArgumentMatchingTests$CounterAspect"/> |
||||
</beans> |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
|
||||
<aop:config> |
||||
<aop:aspect id="overloadedAdviceTest" ref="testAspect"> |
||||
<aop:pointcut id="setter" expression="execution(* setName(..)) and args(name)"/> |
||||
<aop:before pointcut-ref="setter" method="myBeforeAdvice(java.lang.String)"/> |
||||
<aop:before pointcut-ref="setter" method="myBeforeAdvice(int)"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testAspect" class="org.springframework.aop.aspectj.OverloadedAdviceTestAspect"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="aspectOne" ref="firstTestAspect"> |
||||
<aop:around pointcut="execution(* setName(..)) and args(value)" method="capitalize"/> |
||||
<aop:around pointcut="execution(* setAge(..))" method="doubleOrQuits"/> |
||||
<aop:around pointcut="execution(* setMyFloat(..)) and args(value)" method="addOne"/> |
||||
<aop:before pointcut="execution(* setMyFloat(..)) and args(arg)" method="captureFloatArgument"/> |
||||
<aop:around pointcut="execution(* setSex(..)) and args(value)" method="capitalize"/> |
||||
</aop:aspect> |
||||
<aop:aspect id="aspectTwo" ref="secondTestAspect"> |
||||
<aop:before pointcut="execution(* setSex(..)) and args(arg)" method="captureStringArgument"/> |
||||
<aop:around pointcut="execution(* setSex(..)) and args(arg)" method="captureStringArgumentInAround"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="testBean" class="org.springframework.aop.aspectj.ProceedTests$SimpleBeanImpl"/> |
||||
|
||||
<bean id="firstTestAspect" class="org.springframework.aop.aspectj.ProceedTests$ProceedTestingAspect"> |
||||
<property name="order" value="1"/> |
||||
</bean> |
||||
|
||||
<bean id="secondTestAspect" class="org.springframework.aop.aspectj.ProceedTests$ProceedTestingAspect"> |
||||
<property name="order" value="2"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
|
||||
<aop:config> |
||||
<aop:aspect id="thisMatcher" ref="testAspect"> |
||||
<aop:before pointcut="execution(* *(..)) and this(java.io.Serializable)" method="toString"/> |
||||
</aop:aspect> |
||||
<aop:aspect id="targetMatcher" ref="testAspect"> |
||||
<aop:before pointcut="execution(* *(..)) and target(java.io.Serializable)" method="toString"/> |
||||
</aop:aspect> |
||||
<aop:aspect id="argsMatcher" ref="testAspect"> |
||||
<aop:before pointcut="execution(* bar(..)) and args(java.io.Serializable)" method="toString"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<!-- should not be proxied --> |
||||
<bean id="testClassA" class="org.springframework.aop.aspectj.SubtypeMatchingTestClassA"/> |
||||
|
||||
<!-- should be proxied --> |
||||
<bean id="testClassB" class="org.springframework.aop.aspectj.SubtypeMatchingTestClassB"/> |
||||
|
||||
<!-- should be proxied --> |
||||
<bean id="testClassC" class="org.springframework.aop.aspectj.SubtypeMatchingTestClassC"/> |
||||
|
||||
<bean id="testAspect" class="java.lang.Object"/> |
||||
</beans> |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
|
||||
<aop:advisor pointcut="target(org.springframework.aop.aspectj.TargetPointcutSelectionTests$TestImpl1)" |
||||
advice-ref="testInterceptor"/> |
||||
|
||||
<aop:aspect ref="testAspectForTestImpl1"> |
||||
<aop:before pointcut="target(org.springframework.aop.aspectj.TargetPointcutSelectionTests$TestImpl1)" |
||||
method="increment"/> |
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="testAspectForAbstractTestImpl"> |
||||
<aop:before pointcut="target(org.springframework.aop.aspectj.TargetPointcutSelectionTests$AbstractTestImpl)" |
||||
method="increment"/> |
||||
</aop:aspect> |
||||
|
||||
</aop:config> |
||||
|
||||
<bean id="testImpl1" class="org.springframework.aop.aspectj.TargetPointcutSelectionTests$TestImpl1"/> |
||||
|
||||
<bean id="testImpl2" class="org.springframework.aop.aspectj.TargetPointcutSelectionTests$TestImpl2"/> |
||||
|
||||
<bean id="testAspectForTestImpl1" class="org.springframework.aop.aspectj.TargetPointcutSelectionTests$TestAspect"/> |
||||
|
||||
<bean id="testAspectForAbstractTestImpl" class="org.springframework.aop.aspectj.TargetPointcutSelectionTests$TestAspect"/> |
||||
|
||||
<bean id="testInterceptor" class="org.springframework.aop.aspectj.TargetPointcutSelectionTests$TestInterceptor"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
|
||||
<aop:config> |
||||
<aop:aspect ref="thisAsClassCounter"> |
||||
<aop:before method="increment" |
||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" /> |
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="thisAsInterfaceCounter"> |
||||
<aop:before method="increment" |
||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface)" /> |
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="targetAsClassCounter"> |
||||
<aop:before method="increment" |
||||
pointcut="target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" /> |
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="targetAsInterfaceCounter"> |
||||
<aop:before method="increment" |
||||
pointcut="target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface)" /> |
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="thisAsClassAndTargetAsClassCounter"> |
||||
<aop:before method="increment" |
||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl) and target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" /> |
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="thisAsInterfaceAndTargetAsInterfaceCounter"> |
||||
<aop:before method="increment" |
||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface) and target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface)" /> |
||||
</aop:aspect> |
||||
|
||||
<aop:aspect ref="thisAsInterfaceAndTargetAsClassCounter"> |
||||
<aop:before method="increment" |
||||
pointcut="this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestInterface) and target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsTests.TestImpl)" /> |
||||
</aop:aspect> |
||||
|
||||
</aop:config> |
||||
|
||||
<bean id="thisAsClassCounter" |
||||
class="org.springframework.aop.aspectj.Counter" /> |
||||
<bean id="thisAsInterfaceCounter" |
||||
class="org.springframework.aop.aspectj.Counter" /> |
||||
<bean id="targetAsClassCounter" |
||||
class="org.springframework.aop.aspectj.Counter" /> |
||||
<bean id="targetAsInterfaceCounter" |
||||
class="org.springframework.aop.aspectj.Counter" /> |
||||
<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> |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<bean id="topsyTurvyAspect" class="org.springframework.aop.aspectj.TopsyTurvyAspect"/> |
||||
|
||||
<bean id="topsyTurvyTarget" class="org.springframework.aop.aspectj.TopsyTurvyTargetImpl"/> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="myAspect" ref="topsyTurvyAspect"> |
||||
<aop:before pointcut-ref="pc1" |
||||
method="before"/> |
||||
<aop:declare-parents |
||||
types-matching="*..TopsyTurvyTarget+" |
||||
implement-interface="java.io.Serializable" |
||||
default-impl="org.springframework.aop.aspectj.SerializableMixin"/> |
||||
<aop:after-returning pointcut-ref="pc2" method="afterReturning"/> |
||||
<aop:pointcut id="pc1" expression="execution(* *..do*(..))"/> |
||||
<aop:around pointcut-ref="pc2" |
||||
method="around"/> |
||||
<aop:pointcut id="pc2" expression="execution(* *..TopsyTurvyTarget+.get*(..))"/> |
||||
<aop:declare-parents |
||||
types-matching="*..TopsyTurvyTarget+" |
||||
implement-interface="org.springframework.beans.factory.BeanNameAware" |
||||
default-impl="org.springframework.aop.aspectj.BeanNameAwareMixin"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.factory.BeanCreationException; |
||||
import org.springframework.beans.factory.BeanDefinitionStoreException; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
import org.xml.sax.SAXParseException; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AopNamespaceAdviceTypeTests extends TestCase { |
||||
|
||||
private ApplicationContext context; |
||||
|
||||
protected String getOKConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerAdviceTypeOKTests.xml"; |
||||
} |
||||
|
||||
protected String getErrorConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerAdviceTypeErrorTests.xml"; |
||||
} |
||||
|
||||
public void testParsingOfAdviceTypes() { |
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); |
||||
} |
||||
|
||||
public void testParsingOfAdviceTypesWithError() { |
||||
try { |
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); |
||||
fail("Expected BeanDefinitionStoreException"); |
||||
} |
||||
catch (BeanDefinitionStoreException ex) { |
||||
assertTrue(ex.contains(SAXParseException.class)); |
||||
} |
||||
} |
||||
|
||||
protected ITestBean getTestBean() { |
||||
return (ITestBean) this.context.getBean("testBean"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.factory.BeanCreationException; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AopNamespaceHandlerArgNamesTests extends TestCase { |
||||
|
||||
private ApplicationContext context; |
||||
|
||||
protected String getOKConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerArgNamesOKTests.xml"; |
||||
} |
||||
|
||||
protected String getErrorConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml"; |
||||
} |
||||
|
||||
public void testArgNamesOK() { |
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); |
||||
} |
||||
|
||||
public void testArgNamesError() { |
||||
try { |
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); |
||||
fail("Expected BeanCreationException"); |
||||
} |
||||
catch (BeanCreationException ex) { |
||||
assertTrue(ex.contains(IllegalArgumentException.class)); |
||||
} |
||||
} |
||||
|
||||
protected ITestBean getTestBean() { |
||||
return (ITestBean) this.context.getBean("testBean"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,181 @@
@@ -0,0 +1,181 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition; |
||||
import org.springframework.beans.factory.config.BeanReference; |
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition; |
||||
import org.springframework.beans.factory.parsing.CollectingReaderEventListener; |
||||
import org.springframework.beans.factory.parsing.ComponentDefinition; |
||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition; |
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
||||
import org.springframework.core.io.ClassPathResource; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class AopNamespaceHandlerEventTests extends TestCase { |
||||
|
||||
private CollectingReaderEventListener eventListener = new CollectingReaderEventListener(); |
||||
|
||||
private XmlBeanDefinitionReader reader; |
||||
|
||||
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); |
||||
|
||||
|
||||
protected void setUp() throws Exception { |
||||
this.reader = new XmlBeanDefinitionReader(this.beanFactory); |
||||
this.reader.setEventListener(this.eventListener); |
||||
} |
||||
|
||||
public void testPointcutEvents() throws Exception { |
||||
loadBeansFrom("aopNamespaceHandlerPointcutEventTests.xml"); |
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); |
||||
assertEquals("Incorrect number of events fired", 1, componentDefinitions.length); |
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); |
||||
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; |
||||
assertEquals("aop:config", compositeDef.getName()); |
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); |
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length); |
||||
PointcutComponentDefinition pcd = null; |
||||
for (int i = 0; i < nestedComponentDefs.length; i++) { |
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i]; |
||||
if (componentDefinition instanceof PointcutComponentDefinition) { |
||||
pcd = (PointcutComponentDefinition) componentDefinition; |
||||
break; |
||||
} |
||||
} |
||||
assertNotNull("PointcutComponentDefinition not found", pcd); |
||||
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length); |
||||
} |
||||
|
||||
public void testAdvisorEventsWithPointcutRef() throws Exception { |
||||
loadBeansFrom("aopNamespaceHandlerAdvisorWithPointcutRefEventTests.xml"); |
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); |
||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length); |
||||
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); |
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; |
||||
assertEquals("aop:config", compositeDef.getName()); |
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); |
||||
assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length); |
||||
AdvisorComponentDefinition acd = null; |
||||
for (int i = 0; i < nestedComponentDefs.length; i++) { |
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i]; |
||||
if (componentDefinition instanceof AdvisorComponentDefinition) { |
||||
acd = (AdvisorComponentDefinition) componentDefinition; |
||||
break; |
||||
} |
||||
} |
||||
assertNotNull("AdvisorComponentDefinition not found", acd); |
||||
assertEquals(1, acd.getBeanDefinitions().length); |
||||
assertEquals(2, acd.getBeanReferences().length); |
||||
|
||||
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition); |
||||
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1]; |
||||
assertEquals("countingAdvice", adviceDef.getBeanName()); |
||||
} |
||||
|
||||
public void testAdvisorEventsWithDirectPointcut() throws Exception { |
||||
loadBeansFrom("aopNamespaceHandlerAdvisorWithDirectPointcutEventTests.xml"); |
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); |
||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length); |
||||
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); |
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; |
||||
assertEquals("aop:config", compositeDef.getName()); |
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); |
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length); |
||||
AdvisorComponentDefinition acd = null; |
||||
for (int i = 0; i < nestedComponentDefs.length; i++) { |
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i]; |
||||
if (componentDefinition instanceof AdvisorComponentDefinition) { |
||||
acd = (AdvisorComponentDefinition) componentDefinition; |
||||
break; |
||||
} |
||||
} |
||||
assertNotNull("AdvisorComponentDefinition not found", acd); |
||||
assertEquals(2, acd.getBeanDefinitions().length); |
||||
assertEquals(1, acd.getBeanReferences().length); |
||||
|
||||
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition); |
||||
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1]; |
||||
assertEquals("countingAdvice", adviceDef.getBeanName()); |
||||
} |
||||
|
||||
public void testAspectEvent() throws Exception { |
||||
loadBeansFrom("aopNamespaceHandlerAspectEventTests.xml"); |
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); |
||||
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length); |
||||
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); |
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; |
||||
assertEquals("aop:config", compositeDef.getName()); |
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); |
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length); |
||||
AspectComponentDefinition acd = null; |
||||
for (int i = 0; i < nestedComponentDefs.length; i++) { |
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i]; |
||||
if (componentDefinition instanceof AspectComponentDefinition) { |
||||
acd = (AspectComponentDefinition) componentDefinition; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
assertNotNull("AspectComponentDefinition not found", acd); |
||||
BeanDefinition[] beanDefinitions = acd.getBeanDefinitions(); |
||||
assertEquals(5, beanDefinitions.length); |
||||
BeanReference[] beanReferences = acd.getBeanReferences(); |
||||
assertEquals(6, beanReferences.length); |
||||
|
||||
Set expectedReferences = new HashSet(); |
||||
expectedReferences.add("pc"); |
||||
expectedReferences.add("countingAdvice"); |
||||
for (int i = 0; i < beanReferences.length; i++) { |
||||
BeanReference beanReference = beanReferences[i]; |
||||
expectedReferences.remove(beanReference.getBeanName()); |
||||
} |
||||
assertEquals("Incorrect references found", 0, expectedReferences.size()); |
||||
|
||||
for (int i = 1; i < componentDefinitions.length; i++) { |
||||
assertTrue(componentDefinitions[i] instanceof BeanComponentDefinition); |
||||
} |
||||
|
||||
ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents(); |
||||
assertEquals("Inner PointcutComponentDefinition not found", 1, nestedComponentDefs2.length); |
||||
assertTrue(nestedComponentDefs2[0] instanceof PointcutComponentDefinition); |
||||
PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0]; |
||||
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length); |
||||
} |
||||
|
||||
private void loadBeansFrom(String path) { |
||||
this.reader.loadBeanDefinitions(new ClassPathResource(path, getClass())); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException; |
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
||||
import org.springframework.beans.factory.xml.XmlBeanFactory; |
||||
import org.springframework.core.io.ClassPathResource; |
||||
|
||||
/** |
||||
* @author Mark Fisher |
||||
*/ |
||||
public class AopNamespaceHandlerPointcutErrorTests extends TestCase { |
||||
|
||||
public void testDuplicatePointcutConfig() { |
||||
try { |
||||
new XmlBeanFactory(new ClassPathResource( |
||||
"org/springframework/aop/config/aopNamespaceHandlerPointcutDuplicationTests.xml")); |
||||
fail("parsing should have caused a BeanDefinitionStoreException"); |
||||
} |
||||
catch (BeanDefinitionStoreException ex) { |
||||
assertTrue(ex.contains(BeanDefinitionParsingException.class)); |
||||
} |
||||
} |
||||
|
||||
public void testMissingPointcutConfig() { |
||||
try { |
||||
new XmlBeanFactory(new ClassPathResource( |
||||
"org/springframework/aop/config/aopNamespaceHandlerPointcutMissingTests.xml")); |
||||
fail("parsing should have caused a BeanDefinitionStoreException"); |
||||
} |
||||
catch (BeanDefinitionStoreException ex) { |
||||
assertTrue(ex.contains(BeanDefinitionParsingException.class)); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import org.springframework.aop.support.AopUtils; |
||||
import org.springframework.beans.ITestBean; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
*/ |
||||
public class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandlerTests { |
||||
|
||||
public void testIsClassProxy() { |
||||
ITestBean bean = getTestBean(); |
||||
assertTrue("Should be a CGLIB proxy", AopUtils.isCglibProxy(bean)); |
||||
} |
||||
|
||||
protected String getConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerProxyTargetClassTests.xml"; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.factory.BeanDefinitionStoreException; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
import org.xml.sax.SAXParseException; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AopNamespaceHandlerReturningTests extends TestCase { |
||||
|
||||
private ApplicationContext context; |
||||
|
||||
protected String getOKConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerReturningOKTests.xml"; |
||||
} |
||||
|
||||
protected String getErrorConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerReturningErrorTests.xml"; |
||||
} |
||||
|
||||
public void testReturningOnReturningAdvice() { |
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); |
||||
} |
||||
|
||||
public void testParseReturningOnOtherAdviceType() { |
||||
try { |
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); |
||||
fail("Expected BeanDefinitionStoreException"); |
||||
} |
||||
catch (BeanDefinitionStoreException ex) { |
||||
assertTrue(ex.contains(SAXParseException.class)); |
||||
} |
||||
} |
||||
|
||||
protected ITestBean getTestBean() { |
||||
return (ITestBean) this.context.getBean("testBean"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
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.mock.web.MockHttpServletRequest; |
||||
import org.springframework.mock.web.MockHttpSession; |
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
import org.springframework.web.context.support.XmlWebApplicationContext; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class AopNamespaceHandlerScopeTests extends TestCase { |
||||
|
||||
private ApplicationContext context; |
||||
|
||||
public void setUp() { |
||||
XmlWebApplicationContext wac = new XmlWebApplicationContext(); |
||||
wac.setConfigLocations(new String[] {"classpath:org/springframework/aop/config/aopNamespaceHandlerScopeTests.xml"}); |
||||
wac.refresh(); |
||||
this.context = wac; |
||||
} |
||||
|
||||
public void testRequestScoping() throws Exception { |
||||
MockHttpServletRequest oldRequest = new MockHttpServletRequest(); |
||||
MockHttpServletRequest newRequest = new MockHttpServletRequest(); |
||||
|
||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); |
||||
|
||||
ITestBean scoped = (ITestBean) this.context.getBean("requestScoped"); |
||||
assertTrue("Should be AOP proxy", AopUtils.isAopProxy(scoped)); |
||||
assertTrue("Should be target class proxy", scoped instanceof TestBean); |
||||
|
||||
ITestBean testBean = (ITestBean) this.context.getBean("testBean"); |
||||
assertTrue("Should be AOP proxy", AopUtils.isAopProxy(testBean)); |
||||
assertFalse("Regular bean should be JDK proxy", testBean instanceof TestBean); |
||||
|
||||
String rob = "Rob Harrop"; |
||||
String bram = "Bram Smeets"; |
||||
|
||||
assertEquals(rob, scoped.getName()); |
||||
scoped.setName(bram); |
||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(newRequest)); |
||||
assertEquals(rob, scoped.getName()); |
||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); |
||||
assertEquals(bram, scoped.getName()); |
||||
|
||||
assertTrue("Should have advisors", ((Advised) scoped).getAdvisors().length > 0); |
||||
} |
||||
|
||||
public void testSessionScoping() throws Exception { |
||||
MockHttpSession oldSession = new MockHttpSession(); |
||||
MockHttpSession newSession = new MockHttpSession(); |
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setSession(oldSession); |
||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); |
||||
|
||||
ITestBean scoped = (ITestBean) this.context.getBean("sessionScoped"); |
||||
assertTrue("Should be AOP proxy", AopUtils.isAopProxy(scoped)); |
||||
assertFalse("Should not be target class proxy", scoped instanceof TestBean); |
||||
|
||||
ITestBean scopedAlias = (ITestBean) this.context.getBean("sessionScopedAlias"); |
||||
assertSame(scoped, scopedAlias); |
||||
|
||||
ITestBean testBean = (ITestBean) this.context.getBean("testBean"); |
||||
assertTrue("Should be AOP proxy", AopUtils.isAopProxy(testBean)); |
||||
assertFalse("Regular bean should be JDK proxy", testBean instanceof TestBean); |
||||
|
||||
String rob = "Rob Harrop"; |
||||
String bram = "Bram Smeets"; |
||||
|
||||
assertEquals(rob, scoped.getName()); |
||||
scoped.setName(bram); |
||||
request.setSession(newSession); |
||||
assertEquals(rob, scoped.getName()); |
||||
request.setSession(oldSession); |
||||
assertEquals(bram, scoped.getName()); |
||||
|
||||
assertTrue("Should have advisors", ((Advised) scoped).getAdvisors().length > 0); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
/* |
||||
* Copyright 2002-2005 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.aop.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.springframework.aop.Advisor; |
||||
import org.springframework.aop.framework.Advised; |
||||
import org.springframework.aop.framework.CountingBeforeAdvice; |
||||
import org.springframework.aop.support.AopUtils; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
*/ |
||||
public class AopNamespaceHandlerTests extends TestCase { |
||||
|
||||
private ApplicationContext context; |
||||
|
||||
public void setUp() { |
||||
this.context = new ClassPathXmlApplicationContext(getConfigLocation()); |
||||
} |
||||
|
||||
protected String getConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerTests.xml"; |
||||
} |
||||
|
||||
public void testIsProxy() throws Exception { |
||||
ITestBean bean = getTestBean(); |
||||
|
||||
assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean)); |
||||
|
||||
// check the advice details
|
||||
Advised advised = (Advised) bean; |
||||
Advisor[] advisors = advised.getAdvisors(); |
||||
|
||||
assertTrue("Advisors should not be empty", advisors.length > 0); |
||||
} |
||||
|
||||
public void testAdviceInvokedCorrectly() throws Exception { |
||||
CountingBeforeAdvice getAgeCounter = (CountingBeforeAdvice) this.context.getBean("getAgeCounter"); |
||||
CountingBeforeAdvice getNameCounter = (CountingBeforeAdvice) this.context.getBean("getNameCounter"); |
||||
|
||||
ITestBean bean = getTestBean(); |
||||
|
||||
assertEquals("Incorrect initial getAge count", 0, getAgeCounter.getCalls("getAge")); |
||||
assertEquals("Incorrect initial getName count", 0, getNameCounter.getCalls("getName")); |
||||
|
||||
bean.getAge(); |
||||
|
||||
assertEquals("Incorrect getAge count on getAge counter", 1, getAgeCounter.getCalls("getAge")); |
||||
assertEquals("Incorrect getAge count on getName counter", 0, getNameCounter.getCalls("getAge")); |
||||
|
||||
bean.getName(); |
||||
|
||||
assertEquals("Incorrect getName count on getName counter", 1, getNameCounter.getCalls("getName")); |
||||
assertEquals("Incorrect getName count on getAge counter", 0, getAgeCounter.getCalls("getName")); |
||||
} |
||||
|
||||
public void testAspectApplied() throws Exception { |
||||
ITestBean testBean = getTestBean(); |
||||
|
||||
CountingAspectJAdvice advice = (CountingAspectJAdvice) this.context.getBean("countingAdvice"); |
||||
|
||||
assertEquals("Incorrect before count", 0, advice.getBeforeCount()); |
||||
assertEquals("Incorrect after count", 0, advice.getAfterCount()); |
||||
|
||||
testBean.setName("Sally"); |
||||
|
||||
assertEquals("Incorrect before count", 1, advice.getBeforeCount()); |
||||
assertEquals("Incorrect after count", 1, advice.getAfterCount()); |
||||
|
||||
testBean.getName(); |
||||
|
||||
assertEquals("Incorrect before count", 1, advice.getBeforeCount()); |
||||
assertEquals("Incorrect after count", 1, advice.getAfterCount()); |
||||
} |
||||
|
||||
protected ITestBean getTestBean() { |
||||
return (ITestBean) this.context.getBean("testBean"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.factory.BeanDefinitionStoreException; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
import org.xml.sax.SAXParseException; |
||||
|
||||
/** |
||||
* @author Adrian Colyer |
||||
*/ |
||||
public class AopNamespaceHandlerThrowingTests extends TestCase { |
||||
|
||||
private ApplicationContext context; |
||||
|
||||
protected String getOKConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerThrowingOKTests.xml"; |
||||
} |
||||
|
||||
protected String getErrorConfigLocation() { |
||||
return "org/springframework/aop/config/aopNamespaceHandlerThrowingErrorTests.xml"; |
||||
} |
||||
|
||||
public void testThrowingOnThrowingAdvice() { |
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation()); |
||||
} |
||||
|
||||
public void testParseThrowingOnOtherAdviceType() { |
||||
try { |
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation()); |
||||
fail("Expected BeanDefinitionStoreException"); |
||||
} |
||||
catch (BeanDefinitionStoreException ex) { |
||||
assertTrue(ex.contains(SAXParseException.class)); |
||||
} |
||||
} |
||||
|
||||
protected ITestBean getTestBean() { |
||||
return (ITestBean) this.context.getBean("testBean"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
/* |
||||
* Copyright 2002-2005 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.aop.config; |
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.springframework.beans.ITestBean; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
*/ |
||||
public class CountingAspectJAdvice { |
||||
|
||||
private int beforeCount; |
||||
|
||||
private int afterCount; |
||||
|
||||
private int aroundCount; |
||||
|
||||
public void myBeforeAdvice() throws Throwable { |
||||
this.beforeCount++; |
||||
} |
||||
|
||||
public void myAfterAdvice() throws Throwable { |
||||
this.afterCount++; |
||||
} |
||||
|
||||
public void myAroundAdvice(ProceedingJoinPoint pjp) throws Throwable { |
||||
this.aroundCount++; |
||||
pjp.proceed(); |
||||
} |
||||
|
||||
public void myAfterReturningAdvice(int age) { |
||||
this.afterCount++; |
||||
} |
||||
|
||||
public void myAfterThrowingAdvice(RuntimeException ex) { |
||||
this.afterCount++; |
||||
} |
||||
|
||||
public void mySetAgeAdvice(int newAge, ITestBean bean) { |
||||
// no-op
|
||||
} |
||||
|
||||
public int getBeforeCount() { |
||||
return this.beforeCount; |
||||
} |
||||
|
||||
public int getAfterCount() { |
||||
return this.afterCount; |
||||
} |
||||
|
||||
public int getAroundCount() { |
||||
return this.aroundCount; |
||||
} |
||||
} |
||||
@ -0,0 +1,183 @@
@@ -0,0 +1,183 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.easymock.MockControl; |
||||
|
||||
import org.springframework.beans.factory.BeanFactory; |
||||
import org.springframework.mock.easymock.AbstractScalarMockTemplate; |
||||
import org.springframework.test.AssertThrows; |
||||
|
||||
/** |
||||
* @author Rick Evans |
||||
*/ |
||||
public final class MethodLocatingFactoryBeanTests extends TestCase { |
||||
|
||||
private static final String BEAN_NAME = "string"; |
||||
|
||||
|
||||
public void testIsSingleton() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
assertTrue(factory.isSingleton()); |
||||
} |
||||
|
||||
public void testGetObjectType() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
assertEquals(Method.class, factory.getObjectType()); |
||||
} |
||||
|
||||
public void testWithNullTargetBeanName() throws Exception { |
||||
new BeanFactoryScalarMockTemplate() { |
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
factory.setMethodName("toString()"); |
||||
factory.setBeanFactory(beanFactory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testWithEmptyTargetBeanName() throws Exception { |
||||
new BeanFactoryScalarMockTemplate() { |
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
factory.setTargetBeanName(""); |
||||
factory.setMethodName("toString()"); |
||||
factory.setBeanFactory(beanFactory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testWithNullTargetMethodName() throws Exception { |
||||
new BeanFactoryScalarMockTemplate() { |
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
factory.setTargetBeanName(BEAN_NAME); |
||||
factory.setBeanFactory(beanFactory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testWithEmptyTargetMethodName() throws Exception { |
||||
new BeanFactoryScalarMockTemplate() { |
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
factory.setTargetBeanName(BEAN_NAME); |
||||
factory.setMethodName(""); |
||||
factory.setBeanFactory(beanFactory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testWhenTargetBeanClassCannotBeResolved() throws Exception { |
||||
new BeanFactoryScalarMockTemplate() { |
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { |
||||
beanFactory.getType(BEAN_NAME); |
||||
mockControl.setReturnValue(null); |
||||
} |
||||
protected void doTestInternal(final BeanFactory beanFactory) throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
factory.setTargetBeanName(BEAN_NAME); |
||||
factory.setMethodName("toString()"); |
||||
factory.setBeanFactory(beanFactory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testSunnyDayPath() throws Exception { |
||||
new BeanFactoryScalarMockTemplate() { |
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { |
||||
beanFactory.getType(BEAN_NAME); |
||||
mockControl.setReturnValue(String.class); |
||||
} |
||||
protected void doTestInternal(final BeanFactory beanFactory) throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
factory.setTargetBeanName(BEAN_NAME); |
||||
factory.setMethodName("toString()"); |
||||
factory.setBeanFactory(beanFactory); |
||||
Object result = factory.getObject(); |
||||
assertNotNull(result); |
||||
assertTrue(result instanceof Method); |
||||
Method method = (Method) result; |
||||
assertEquals("Bingo", method.invoke("Bingo", new Object[]{})); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testWhereMethodCannotBeResolved() throws Exception { |
||||
new BeanFactoryScalarMockTemplate() { |
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { |
||||
beanFactory.getType(BEAN_NAME); |
||||
mockControl.setReturnValue(String.class); |
||||
} |
||||
protected void doTestInternal(final BeanFactory beanFactory) throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean(); |
||||
factory.setTargetBeanName(BEAN_NAME); |
||||
factory.setMethodName("loadOfOld()"); |
||||
factory.setBeanFactory(beanFactory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
|
||||
private static abstract class BeanFactoryScalarMockTemplate extends AbstractScalarMockTemplate { |
||||
|
||||
public BeanFactoryScalarMockTemplate() { |
||||
super(BeanFactory.class); |
||||
} |
||||
|
||||
public void setupExpectations(MockControl mockControl, Object mockObject) throws Exception { |
||||
setupBeanFactoryExpectations(mockControl, (BeanFactory) mockObject); |
||||
} |
||||
|
||||
public void doTest(Object mockObject) throws Exception { |
||||
doTestInternal((BeanFactory) mockObject); |
||||
} |
||||
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception { |
||||
} |
||||
|
||||
protected abstract void doTestInternal(final BeanFactory beanFactory) throws Exception; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class PrototypeProxyTests extends TestCase { |
||||
|
||||
public void testInjectionBeforeWrappingCheckDoesNotKickInForPrototypeProxy() { |
||||
new ClassPathXmlApplicationContext("prototypeProxy.xml", getClass()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* 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.config; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
||||
import org.springframework.core.io.ClassPathResource; |
||||
|
||||
/** |
||||
* Tests that the <aop:config/> element can be used as a top level element. |
||||
* |
||||
* @author Rob Harrop |
||||
*/ |
||||
public final class TopLevelAopTagTests extends TestCase { |
||||
|
||||
public void testParse() throws Exception { |
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); |
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); |
||||
reader.loadBeanDefinitions(new ClassPathResource("topLevelAop.xml", getClass())); |
||||
|
||||
assertTrue(beanFactory.containsBeanDefinition("testPointcut")); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/> |
||||
<aop:before pointcut-ref="pc" method="myBeforeAdvice" returning="age" /> |
||||
</aop:aspect> |
||||
</aop:aspect> |
||||
|
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/> |
||||
<aop:before pointcut-ref="pc" method="myBeforeAdvice" /> |
||||
<aop:after pointcut-ref="pc" method="myAfterAdvice" /> |
||||
<aop:after-returning pointcut-ref="pc" method="myAfterReturningAdvice" returning="age"/> |
||||
<aop:after-throwing pointcut-ref="pc" method="myAfterThrowingAdvice" throwing="ex"/> |
||||
<aop:around pointcut-ref="pc" method="myAroundAdvice"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:advisor advice-ref="countingAdvice" pointcut="within(org.springframework..*)"/> |
||||
</aop:config> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:pointcut id="pc" expression="within(org.springframework..*)"/> |
||||
<aop:advisor advice-ref="countingAdvice" pointcut-ref="pc"/> |
||||
</aop:config> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:before pointcut="execution(* setAge(..)) and args(age) and this(bean)" |
||||
method="mySetAgeAdvice" arg-names="age bean"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:before pointcut="execution(* setAge(..)) and args(age) and this(bean)" |
||||
method="mySetAgeAdvice" arg-names="age,bean"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/> |
||||
<aop:before pointcut-ref="pc" method="myBeforeAdvice" /> |
||||
<aop:after pointcut-ref="pc" method="myAfterAdvice" /> |
||||
<aop:after-returning pointcut-ref="pc" method="myAfterReturningAdvice" returning="age"/> |
||||
<aop:after-throwing pointcut-ref="pc" method="myAfterThrowingAdvice" throwing="ex"/> |
||||
<aop:around pointcut-ref="pc" method="myAroundAdvice"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/> |
||||
<aop:before pointcut-ref="pc" pointcut="execution(* getAge())" method="myBeforeAdvice"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:pointcut id="myPointcut" expression="within(org.springframework..*)"/> |
||||
</aop:config> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/> |
||||
<aop:before method="myBeforeAdvice" /> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config proxy-target-class="true"> |
||||
<aop:pointcut id="getNameCalls" expression="execution(* getName(..)) and within(*..ITestBean+)"/> |
||||
<aop:advisor id="getAgeAdvisor" pointcut="execution(* *..ITestBean.getAge(..))" advice-ref="getAgeCounter"/> |
||||
<aop:advisor id="getNameAdvisor" pointcut-ref="getNameCalls" advice-ref="getNameCounter"/> |
||||
|
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:pointcut id="setCalls" expression="execution(* *..ITestBean.set*(..))"/> |
||||
<aop:before pointcut="execution(* *..ITestBean.set*(..))" method="myBeforeAdvice"/> |
||||
<aop:after pointcut-ref="setCalls" method="myAfterAdvice"/> |
||||
<aop:around pointcut-ref="setCalls" method="myAroundAdvice"/> |
||||
</aop:aspect> |
||||
|
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:after pointcut="execution(int getAge(..))" method="myAfterAdvice" returning="age"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice"> |
||||
<aop:after-returning pointcut="execution(int getAge(..))" method="myAfterReturningAdvice" returning="age"/> |
||||
</aop:aspect> |
||||
</aop:config> |
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> |
||||
|
||||
<aop:config> |
||||
<aop:advisor advice-ref="advice" pointcut="execution(* *..ITestBean.*(..))"/> |
||||
</aop:config> |
||||
|
||||
<bean id="advice" class="org.springframework.aop.interceptor.DebugInterceptor"/> |
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="requestScoped" class="org.springframework.beans.TestBean" scope="request"> |
||||
<aop:scoped-proxy/> |
||||
<property name="name" value="Rob Harrop"/> |
||||
</bean> |
||||
|
||||
<bean id="sessionScoped" name="sessionScopedAlias" class="org.springframework.beans.TestBean" scope="session"> |
||||
<aop:scoped-proxy proxy-target-class="false"/> |
||||
<property name="name" value="Rob Harrop"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue