1 16 17 package org.springframework.aop.support; 18 19 import javax.servlet.ServletException ; 20 21 import junit.framework.TestCase; 22 23 import org.springframework.util.SerializationTestUtils; 24 25 30 public abstract class AbstractRegexpMethodPointcutTests extends TestCase { 31 32 private AbstractRegexpMethodPointcut rpc; 33 34 protected void setUp() { 35 rpc = getRegexpMethodPointcut(); 36 } 37 38 protected abstract AbstractRegexpMethodPointcut getRegexpMethodPointcut(); 39 40 public void testNoPatternSupplied() throws Exception { 41 noPatternSuppliedTests(rpc); 42 } 43 44 public void testSerializationWithNoPatternSupplied() throws Exception { 45 rpc = (AbstractRegexpMethodPointcut) SerializationTestUtils.serializeAndDeserialize(rpc); 46 noPatternSuppliedTests(rpc); 47 } 48 49 protected void noPatternSuppliedTests(AbstractRegexpMethodPointcut rpc) throws Exception { 50 assertFalse(rpc.matches(Object .class.getMethod("hashCode", (Class []) null), String .class)); 51 assertFalse(rpc.matches(Object .class.getMethod("wait", (Class []) null), Object .class)); 52 assertEquals(0, rpc.getPatterns().length); 53 } 54 55 public void testExactMatch() throws Exception { 56 rpc.setPattern("java.lang.Object.hashCode"); 57 exactMatchTests(rpc); 58 rpc = (AbstractRegexpMethodPointcut) SerializationTestUtils.serializeAndDeserialize(rpc); 59 exactMatchTests(rpc); 60 } 61 62 protected void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception { 63 assertTrue(rpc.matches(Object .class.getMethod("hashCode", (Class []) null), String .class)); 65 assertFalse(rpc.matches(Object .class.getMethod("wait", (Class []) null), Object .class)); 66 } 67 68 public void testWildcard() throws Exception { 69 rpc.setPattern(".*Object.hashCode"); 70 assertTrue(rpc.matches(Object .class.getMethod("hashCode", (Class []) null), Object .class)); 71 assertFalse(rpc.matches(Object .class.getMethod("wait", (Class []) null), Object .class)); 72 } 73 74 public void testWildcardForOneClass() throws Exception { 75 rpc.setPattern("java.lang.Object.*"); 76 assertTrue(rpc.matches(Object .class.getMethod("hashCode", (Class []) null), String .class)); 77 assertTrue(rpc.matches(Object .class.getMethod("wait", (Class []) null), String .class)); 78 } 79 80 public void testMatchesObjectClass() throws Exception { 81 rpc.setPattern("java.lang.Object.*"); 82 assertTrue(rpc.matches(Exception .class.getMethod("hashCode", (Class []) null), ServletException .class)); 83 assertFalse(rpc.matches(Exception .class.getMethod("getMessage", (Class []) null), Exception .class)); 85 } 86 87 } 88 | Popular Tags |