moving unit tests from .testsuite -> .aop
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@394 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
478dbcf13f
commit
b9c85fd5ae
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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.interceptor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass of NopInterceptor that is serializable and
|
||||||
|
* can be used to test proxy serialization.
|
||||||
|
*
|
||||||
|
* @author Rod Johnson
|
||||||
|
*/
|
||||||
|
public class SerializableNopInterceptor extends NopInterceptor implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We must override this field and the related methods as
|
||||||
|
* otherwise count won't be serialized from the non-serializable
|
||||||
|
* NopInterceptor superclass.
|
||||||
|
*/
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void increment() {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -16,12 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
|
import static org.easymock.EasyMock.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.easymock.MockControl;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.IntroductionAdvisor;
|
import org.springframework.aop.IntroductionAdvisor;
|
||||||
import org.springframework.aop.IntroductionInterceptor;
|
import org.springframework.aop.IntroductionInterceptor;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
|
|
@ -37,71 +38,65 @@ import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
* @since 13.05.2003
|
* @since 13.05.2003
|
||||||
*/
|
*/
|
||||||
public class DelegatingIntroductionInterceptorTests extends TestCase {
|
public class DelegatingIntroductionInterceptorTests {
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void testNullTarget() throws Exception {
|
public void testNullTarget() throws Exception {
|
||||||
try {
|
// Shouldn't accept null target
|
||||||
IntroductionInterceptor ii = new DelegatingIntroductionInterceptor(null);
|
new DelegatingIntroductionInterceptor(null);
|
||||||
fail("Shouldn't accept null target");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIntroductionInterceptorWithDelegation() throws Exception {
|
public void testIntroductionInterceptorWithDelegation() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertTrue(! (raw instanceof TimeStamped));
|
assertTrue(! (raw instanceof TimeStamped));
|
||||||
ProxyFactory factory = new ProxyFactory(raw);
|
ProxyFactory factory = new ProxyFactory(raw);
|
||||||
|
|
||||||
MockControl tsControl = MockControl.createControl(TimeStamped.class);
|
TimeStamped ts = createMock(TimeStamped.class);
|
||||||
TimeStamped ts = (TimeStamped) tsControl.getMock();
|
|
||||||
ts.getTimeStamp();
|
|
||||||
long timestamp = 111L;
|
long timestamp = 111L;
|
||||||
tsControl.setReturnValue(timestamp, 1);
|
expect(ts.getTimeStamp()).andReturn(timestamp);
|
||||||
tsControl.replay();
|
replay(ts);
|
||||||
|
|
||||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
|
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
|
||||||
|
|
||||||
TimeStamped tsp = (TimeStamped) factory.getProxy();
|
TimeStamped tsp = (TimeStamped) factory.getProxy();
|
||||||
assertTrue(tsp.getTimeStamp() == timestamp);
|
assertTrue(tsp.getTimeStamp() == timestamp);
|
||||||
|
|
||||||
tsControl.verify();
|
verify(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
|
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertTrue(! (raw instanceof SubTimeStamped));
|
assertTrue(! (raw instanceof SubTimeStamped));
|
||||||
ProxyFactory factory = new ProxyFactory(raw);
|
ProxyFactory factory = new ProxyFactory(raw);
|
||||||
|
|
||||||
MockControl tsControl = MockControl.createControl(SubTimeStamped.class);
|
TimeStamped ts = createMock(SubTimeStamped.class);
|
||||||
SubTimeStamped ts = (SubTimeStamped) tsControl.getMock();
|
|
||||||
ts.getTimeStamp();
|
|
||||||
long timestamp = 111L;
|
long timestamp = 111L;
|
||||||
tsControl.setReturnValue(timestamp, 1);
|
expect(ts.getTimeStamp()).andReturn(timestamp);
|
||||||
tsControl.replay();
|
replay(ts);
|
||||||
|
|
||||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));
|
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));
|
||||||
|
|
||||||
SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
|
SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
|
||||||
assertTrue(tsp.getTimeStamp() == timestamp);
|
assertTrue(tsp.getTimeStamp() == timestamp);
|
||||||
|
|
||||||
tsControl.verify();
|
verify(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
|
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertTrue(! (raw instanceof TimeStamped));
|
assertTrue(! (raw instanceof TimeStamped));
|
||||||
ProxyFactory factory = new ProxyFactory(raw);
|
ProxyFactory factory = new ProxyFactory(raw);
|
||||||
|
|
||||||
MockControl tsControl = MockControl.createControl(SubTimeStamped.class);
|
TimeStamped ts = createMock(SubTimeStamped.class);
|
||||||
SubTimeStamped ts = (SubTimeStamped) tsControl.getMock();
|
|
||||||
ts.getTimeStamp();
|
|
||||||
long timestamp = 111L;
|
long timestamp = 111L;
|
||||||
tsControl.setReturnValue(timestamp, 1);
|
expect(ts.getTimeStamp()).andReturn(timestamp);
|
||||||
tsControl.replay();
|
replay(ts);
|
||||||
|
|
||||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));
|
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));
|
||||||
|
|
||||||
|
|
@ -109,9 +104,10 @@ public class DelegatingIntroductionInterceptorTests extends TestCase {
|
||||||
assertTrue(!(tsp instanceof SubTimeStamped));
|
assertTrue(!(tsp instanceof SubTimeStamped));
|
||||||
assertTrue(tsp.getTimeStamp() == timestamp);
|
assertTrue(tsp.getTimeStamp() == timestamp);
|
||||||
|
|
||||||
tsControl.verify();
|
verify(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutomaticInterfaceRecognitionInDelegate() throws Exception {
|
public void testAutomaticInterfaceRecognitionInDelegate() throws Exception {
|
||||||
final long t = 1001L;
|
final long t = 1001L;
|
||||||
class Tester implements TimeStamped, ITester {
|
class Tester implements TimeStamped, ITester {
|
||||||
|
|
@ -139,8 +135,10 @@ public class DelegatingIntroductionInterceptorTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
|
public void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
|
||||||
final long t = 1001L;
|
final long t = 1001L;
|
||||||
|
@SuppressWarnings("serial")
|
||||||
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
|
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
|
||||||
public void foo() throws Exception {
|
public void foo() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
@ -180,6 +178,8 @@ public class DelegatingIntroductionInterceptorTests extends TestCase {
|
||||||
assertTrue(!(o instanceof TimeStamped));
|
assertTrue(!(o instanceof TimeStamped));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
@Test
|
||||||
public void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
|
public void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertTrue(! (raw instanceof TimeStamped));
|
assertTrue(! (raw instanceof TimeStamped));
|
||||||
|
|
@ -199,6 +199,7 @@ public class DelegatingIntroductionInterceptorTests extends TestCase {
|
||||||
assertEquals(raw.toString(), tsp.toString());
|
assertEquals(raw.toString(), tsp.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDelegateReturnsThisIsMassagedToReturnProxy() {
|
public void testDelegateReturnsThisIsMassagedToReturnProxy() {
|
||||||
NestedTestBean target = new NestedTestBean();
|
NestedTestBean target = new NestedTestBean();
|
||||||
String company = "Interface21";
|
String company = "Interface21";
|
||||||
|
|
@ -218,6 +219,7 @@ public class DelegatingIntroductionInterceptorTests extends TestCase {
|
||||||
assertTrue("Introduced method returning delegate returns proxy", AopUtils.isAopProxy(introduction.getSpouse()));
|
assertTrue("Introduced method returning delegate returns proxy", AopUtils.isAopProxy(introduction.getSpouse()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
|
public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
|
||||||
SerializablePerson serializableTarget = new SerializablePerson();
|
SerializablePerson serializableTarget = new SerializablePerson();
|
||||||
String name = "Tony";
|
String name = "Tony";
|
||||||
|
|
@ -241,23 +243,11 @@ public class DelegatingIntroductionInterceptorTests extends TestCase {
|
||||||
assertEquals(time, ((TimeStamped) p1).getTimeStamp());
|
assertEquals(time, ((TimeStamped) p1).getTimeStamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testDelegatingIntroductionInterceptorDoesntMakeNonserializableSerializable() throws Exception {
|
|
||||||
// // Target is NOT serialiable
|
|
||||||
// TestBean raw = new TestBean();
|
|
||||||
// ProxyFactory factory = new ProxyFactory(raw);
|
|
||||||
// factory.addInterface(Person.class);
|
|
||||||
// long time = 1000;
|
|
||||||
// TimeStamped ts = new SerializableTimeStamped(time);
|
|
||||||
//
|
|
||||||
// factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
|
|
||||||
// Object proxy = factory.getProxy();
|
|
||||||
//
|
|
||||||
// assertFalse(proxy instanceof Serializable);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Test when target implements the interface: should get interceptor by preference.
|
// Test when target implements the interface: should get interceptor by preference.
|
||||||
|
@Test
|
||||||
public void testIntroductionMasksTargetImplementation() throws Exception {
|
public void testIntroductionMasksTargetImplementation() throws Exception {
|
||||||
final long t = 1001L;
|
final long t = 1001L;
|
||||||
|
@SuppressWarnings("serial")
|
||||||
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped {
|
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped {
|
||||||
public long getTimeStamp() {
|
public long getTimeStamp() {
|
||||||
return t;
|
return t;
|
||||||
|
|
@ -278,6 +268,7 @@ public class DelegatingIntroductionInterceptorTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
private static class SerializableTimeStamped implements TimeStamped, Serializable {
|
private static class SerializableTimeStamped implements TimeStamped, Serializable {
|
||||||
|
|
||||||
private final long ts;
|
private final long ts;
|
||||||
|
|
@ -16,10 +16,11 @@
|
||||||
|
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.MethodMatcher;
|
import org.springframework.aop.MethodMatcher;
|
||||||
import org.springframework.beans.IOther;
|
import org.springframework.beans.IOther;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
|
|
@ -27,9 +28,10 @@ import org.springframework.beans.TestBean;
|
||||||
import org.springframework.util.SerializationTestUtils;
|
import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id: MethodMatchersTests.java,v 1.7 2005/03/25 09:28:18 jhoeller Exp $
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class MethodMatchersTests extends TestCase {
|
public class MethodMatchersTests {
|
||||||
|
|
||||||
private final Method EXCEPTION_GETMESSAGE;
|
private final Method EXCEPTION_GETMESSAGE;
|
||||||
|
|
||||||
|
|
@ -46,16 +48,19 @@ public class MethodMatchersTests extends TestCase {
|
||||||
IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null);
|
IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDefaultMatchesAll() throws Exception {
|
public void testDefaultMatchesAll() throws Exception {
|
||||||
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
||||||
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
||||||
assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
|
assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMethodMatcherTrueSerializable() throws Exception {
|
public void testMethodMatcherTrueSerializable() throws Exception {
|
||||||
assertSame(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE), MethodMatcher.TRUE);
|
assertSame(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE), MethodMatcher.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSingle() throws Exception {
|
public void testSingle() throws Exception {
|
||||||
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
||||||
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
||||||
|
|
@ -67,6 +72,7 @@ public class MethodMatchersTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDynamicAndStaticMethodMatcherIntersection() throws Exception {
|
public void testDynamicAndStaticMethodMatcherIntersection() throws Exception {
|
||||||
MethodMatcher mm1 = MethodMatcher.TRUE;
|
MethodMatcher mm1 = MethodMatcher.TRUE;
|
||||||
MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
|
MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
|
||||||
|
|
@ -81,6 +87,7 @@ public class MethodMatchersTests extends TestCase {
|
||||||
assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
|
assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testStaticMethodMatcherUnion() throws Exception {
|
public void testStaticMethodMatcherUnion() throws Exception {
|
||||||
MethodMatcher getterMatcher = new StartsWithMatcher("get");
|
MethodMatcher getterMatcher = new StartsWithMatcher("get");
|
||||||
MethodMatcher setterMatcher = new StartsWithMatcher("set");
|
MethodMatcher setterMatcher = new StartsWithMatcher("set");
|
||||||
|
|
@ -16,8 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.aop.interceptor.NopInterceptor;
|
import org.springframework.aop.interceptor.NopInterceptor;
|
||||||
|
|
@ -27,10 +29,10 @@ import org.springframework.beans.SerializablePerson;
|
||||||
import org.springframework.util.SerializationTestUtils;
|
import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class NameMatchMethodPointcutTests extends TestCase {
|
public class NameMatchMethodPointcutTests {
|
||||||
|
|
||||||
protected NameMatchMethodPointcut pc;
|
protected NameMatchMethodPointcut pc;
|
||||||
|
|
||||||
|
|
@ -38,15 +40,12 @@ public class NameMatchMethodPointcutTests extends TestCase {
|
||||||
|
|
||||||
protected SerializableNopInterceptor nop;
|
protected SerializableNopInterceptor nop;
|
||||||
|
|
||||||
public NameMatchMethodPointcutTests(String s) {
|
|
||||||
super(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an empty pointcut, populating instance variables.
|
* Create an empty pointcut, populating instance variables.
|
||||||
* @see junit.framework.TestCase#setUp()
|
* @see junit.framework.TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
protected void setUp() {
|
@Before
|
||||||
|
public void setUp() {
|
||||||
ProxyFactory pf = new ProxyFactory(new SerializablePerson());
|
ProxyFactory pf = new ProxyFactory(new SerializablePerson());
|
||||||
nop = new SerializableNopInterceptor();
|
nop = new SerializableNopInterceptor();
|
||||||
pc = new NameMatchMethodPointcut();
|
pc = new NameMatchMethodPointcut();
|
||||||
|
|
@ -54,6 +53,7 @@ public class NameMatchMethodPointcutTests extends TestCase {
|
||||||
proxied = (Person) pf.getProxy();
|
proxied = (Person) pf.getProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMatchingOnly() {
|
public void testMatchingOnly() {
|
||||||
// Can't do exact matching through isMatch
|
// Can't do exact matching through isMatch
|
||||||
assertTrue(pc.isMatch("echo", "ech*"));
|
assertTrue(pc.isMatch("echo", "ech*"));
|
||||||
|
|
@ -64,6 +64,7 @@ public class NameMatchMethodPointcutTests extends TestCase {
|
||||||
assertTrue(pc.isMatch("testing", "*ing"));
|
assertTrue(pc.isMatch("testing", "*ing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmpty() throws Throwable {
|
public void testEmpty() throws Throwable {
|
||||||
assertEquals(0, nop.getCount());
|
assertEquals(0, nop.getCount());
|
||||||
proxied.getName();
|
proxied.getName();
|
||||||
|
|
@ -73,6 +74,7 @@ public class NameMatchMethodPointcutTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMatchOneMethod() throws Throwable {
|
public void testMatchOneMethod() throws Throwable {
|
||||||
pc.addMethodName("echo");
|
pc.addMethodName("echo");
|
||||||
pc.addMethodName("set*");
|
pc.addMethodName("set*");
|
||||||
|
|
@ -90,6 +92,7 @@ public class NameMatchMethodPointcutTests extends TestCase {
|
||||||
assertEquals(3, nop.getCount());
|
assertEquals(3, nop.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSets() throws Throwable {
|
public void testSets() throws Throwable {
|
||||||
pc.setMappedNames(new String[] { "set*", "echo" });
|
pc.setMappedNames(new String[] { "set*", "echo" });
|
||||||
assertEquals(0, nop.getCount());
|
assertEquals(0, nop.getCount());
|
||||||
|
|
@ -100,6 +103,7 @@ public class NameMatchMethodPointcutTests extends TestCase {
|
||||||
assertEquals(2, nop.getCount());
|
assertEquals(2, nop.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerializable() throws Throwable {
|
public void testSerializable() throws Throwable {
|
||||||
testSets();
|
testSets();
|
||||||
// Count is now 2
|
// Count is now 2
|
||||||
|
|
@ -111,6 +115,7 @@ public class NameMatchMethodPointcutTests extends TestCase {
|
||||||
assertEquals(3, nop2.getCount());
|
assertEquals(3, nop2.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEqualsAndHashCode() throws Exception {
|
public void testEqualsAndHashCode() throws Exception {
|
||||||
NameMatchMethodPointcut pc1 = new NameMatchMethodPointcut();
|
NameMatchMethodPointcut pc1 = new NameMatchMethodPointcut();
|
||||||
NameMatchMethodPointcut pc2 = new NameMatchMethodPointcut();
|
NameMatchMethodPointcut pc2 = new NameMatchMethodPointcut();
|
||||||
|
|
@ -16,8 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.interceptor.NopInterceptor;
|
import org.springframework.aop.interceptor.NopInterceptor;
|
||||||
import org.springframework.aop.interceptor.SerializableNopInterceptor;
|
import org.springframework.aop.interceptor.SerializableNopInterceptor;
|
||||||
|
|
@ -25,16 +26,19 @@ import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.Person;
|
import org.springframework.beans.Person;
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.util.SerializationTestUtils;
|
import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class RegexpMethodPointcutAdvisorIntegrationTests extends TestCase {
|
public class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSinglePattern() throws Throwable {
|
public void testSinglePattern() throws Throwable {
|
||||||
BeanFactory bf = new ClassPathXmlApplicationContext("org/springframework/aop/support/regexpSetterTests.xml");
|
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("regexpSetterTests.xml", getClass()));
|
||||||
ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
|
ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
|
||||||
// Interceptor behind regexp advisor
|
// Interceptor behind regexp advisor
|
||||||
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||||
|
|
@ -50,8 +54,9 @@ public class RegexpMethodPointcutAdvisorIntegrationTests extends TestCase {
|
||||||
assertEquals(1, nop.getCount());
|
assertEquals(1, nop.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultiplePatterns() throws Throwable {
|
public void testMultiplePatterns() throws Throwable {
|
||||||
BeanFactory bf = new ClassPathXmlApplicationContext("org/springframework/aop/support/regexpSetterTests.xml");
|
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("regexpSetterTests.xml", getClass()));
|
||||||
// This is a CGLIB proxy, so we can proxy it to the target class
|
// This is a CGLIB proxy, so we can proxy it to the target class
|
||||||
TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
|
TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
|
||||||
// Interceptor behind regexp advisor
|
// Interceptor behind regexp advisor
|
||||||
|
|
@ -72,8 +77,9 @@ public class RegexpMethodPointcutAdvisorIntegrationTests extends TestCase {
|
||||||
assertEquals(2, nop.getCount());
|
assertEquals(2, nop.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerialization() throws Throwable {
|
public void testSerialization() throws Throwable {
|
||||||
BeanFactory bf = new ClassPathXmlApplicationContext("org/springframework/aop/support/regexpSetterTests.xml");
|
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("regexpSetterTests.xml", getClass()));
|
||||||
// This is a CGLIB proxy, so we can proxy it to the target class
|
// This is a CGLIB proxy, so we can proxy it to the target class
|
||||||
Person p = (Person) bf.getBean("serializableSettersAdvised");
|
Person p = (Person) bf.getBean("serializableSettersAdvised");
|
||||||
// Interceptor behind regexp advisor
|
// Interceptor behind regexp advisor
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* 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.beans;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Rod Johnson
|
||||||
|
*/
|
||||||
|
public interface Person {
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
void setName(String name);
|
||||||
|
int getAge();
|
||||||
|
void setAge(int i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for non-property method matching.
|
||||||
|
* If the parameter is a Throwable, it will be thrown rather than
|
||||||
|
* returned.
|
||||||
|
*/
|
||||||
|
Object echo(Object o) throws Throwable;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* 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.beans;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable implementation of the Person interface.
|
||||||
|
*
|
||||||
|
* @author Rod Johnson
|
||||||
|
*/
|
||||||
|
public class SerializablePerson implements Person, Serializable {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int age;
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object echo(Object o) throws Throwable {
|
||||||
|
if (o instanceof Throwable) {
|
||||||
|
throw (Throwable) o;
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (!(other instanceof SerializablePerson)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SerializablePerson p = (SerializablePerson) other;
|
||||||
|
return p.age == age && ObjectUtils.nullSafeEquals(name, p.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue