1 16 17 package org.springframework.aop.support; 18 19 import junit.framework.TestCase; 20 21 import org.springframework.aop.framework.Advised; 22 import org.springframework.aop.interceptor.NopInterceptor; 23 import org.springframework.aop.interceptor.SerializableNopInterceptor; 24 import org.springframework.beans.ITestBean; 25 import org.springframework.beans.Person; 26 import org.springframework.beans.TestBean; 27 import org.springframework.beans.factory.BeanFactory; 28 import org.springframework.context.support.ClassPathXmlApplicationContext; 29 import org.springframework.util.SerializationTestUtils; 30 31 34 public class RegexpMethodPointcutAdvisorIntegrationTests extends TestCase { 35 36 public void testSinglePattern() throws Throwable { 37 BeanFactory bf = new ClassPathXmlApplicationContext("org/springframework/aop/support/regexpSetterTests.xml"); 38 ITestBean advised = (ITestBean) bf.getBean("settersAdvised"); 39 NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor"); 41 assertEquals(0, nop.getCount()); 42 43 int newAge = 12; 44 advised.exceptional(null); 46 assertEquals(0, nop.getCount()); 47 advised.setAge(newAge); 48 assertEquals(newAge, advised.getAge()); 49 assertEquals(1, nop.getCount()); 51 } 52 53 public void testMultiplePatterns() throws Throwable { 54 BeanFactory bf = new ClassPathXmlApplicationContext("org/springframework/aop/support/regexpSetterTests.xml"); 55 TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised"); 57 NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor"); 59 assertEquals(0, nop.getCount()); 60 61 int newAge = 12; 62 advised.exceptional(null); 64 assertEquals(0, nop.getCount()); 65 66 advised.absquatulate(); 68 assertEquals(1, nop.getCount()); 69 advised.setAge(newAge); 70 assertEquals(newAge, advised.getAge()); 71 assertEquals(2, nop.getCount()); 73 } 74 75 public void testSerialization() throws Throwable { 76 BeanFactory bf = new ClassPathXmlApplicationContext("org/springframework/aop/support/regexpSetterTests.xml"); 77 Person p = (Person) bf.getBean("serializableSettersAdvised"); 79 NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor"); 81 assertEquals(0, nop.getCount()); 82 83 int newAge = 12; 84 assertEquals(0, p.getAge()); 86 assertEquals(0, nop.getCount()); 87 88 p.setAge(newAge); 90 assertEquals(1, nop.getCount()); 91 p.setAge(newAge); 92 assertEquals(newAge, p.getAge()); 93 assertEquals(2, nop.getCount()); 95 96 p = (Person) SerializationTestUtils.serializeAndDeserialize(p); 98 assertEquals(newAge, p.getAge()); 99 nop = (SerializableNopInterceptor) ((Advised) p).getAdvisors()[0].getAdvice(); 101 assertEquals(2, nop.getCount()); 102 assertEquals("serializableSettersAdvised", p.getName()); 103 p.setAge(newAge + 1); 104 assertEquals(3, nop.getCount()); 105 assertEquals(newAge + 1, p.getAge()); 106 } 107 108 } 109 | Popular Tags |