1 4 package com.tctest.spring.aop; 5 6 import org.springframework.context.support.ClassPathXmlApplicationContext; 7 8 import com.tc.test.TCTestCase; 9 10 11 14 17 public class DelegatingProxyAopProxy_Test extends TCTestCase { 18 19 private static final String BEAN_CONFIG = "com/tctest/spring/beanfactory-fastproxy.xml"; 20 21 public DelegatingProxyAopProxy_Test(String name) { 22 super(name); 23 disableAllUntil("2008-09-18"); } 25 26 public static void testBeforeAdvice() { 27 Logger.log = ""; 28 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(BEAN_CONFIG); 29 IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx.getBean("testBeforeAdviceDelegating"); 30 assertNotNull(proxy); 31 proxy.doStuff("fuzzy"); 32 assertEquals("before args(fuzzy) this(" + proxy.getClass().getName() + ") doStuff ", Logger.log); 33 } 34 35 public static void testAfterReturningAdvice() { 36 Logger.log = ""; 37 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(BEAN_CONFIG); 38 IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx.getBean("testAfterReturningAdviceDelegating"); 39 assertNotNull(proxy); 40 String stuff = proxy.returnStuff("fuzzy"); 41 assertEquals("returnStuff after-returning(stuff) args(fuzzy) this(" + proxy.getClass().getName() + ") ", Logger.log); 42 } 43 44 public static void testAfterThrowingAdvice() { 45 Logger.log = ""; 46 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(BEAN_CONFIG); 47 IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx.getBean("testAfterThrowingAdviceDelegating"); 48 assertNotNull(proxy); 49 try { 50 proxy.throwStuff("fuzzy"); 51 } catch (ExpectedException e) { 52 assertEquals("throwStuff after-throwing(expected) args(fuzzy) this(" + proxy.getClass().getName() + ") ", 53 Logger.log); 54 return; 55 } 56 fail("should have exited with an exception"); 57 } 58 59 public static void testAroundAdvice() { 60 Logger.log = ""; 61 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(BEAN_CONFIG); 62 IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx.getBean("testAroundAdviceDelegating"); 63 assertNotNull(proxy); 64 proxy.doStuff("fuzzy"); 65 assertEquals("before-around args(fuzzy) this(" + proxy.getClass().getName() + ") doStuff after-around ", Logger.log); 66 } 67 68 public static void testAroundAdviceChain() { 69 Logger.log = ""; 70 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(BEAN_CONFIG); 71 IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx.getBean("testAroundAdviceChainDelegating"); 72 assertNotNull(proxy); 73 proxy.doStuff("fuzzy"); 74 assertEquals("before-around args(fuzzy) this(" + proxy.getClass().getName() + ") before-around args(fuzzy) this(" 75 + proxy.getClass().getName() + ") doStuff after-around after-around ", Logger.log); 76 } 77 78 79 public static junit.framework.Test suite() { 81 return new junit.framework.TestSuite(DelegatingProxyAopProxy_Test.class); 82 } 83 } 84 | Popular Tags |