001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tctest.spring.aop;
005:
006: import org.springframework.context.support.ClassPathXmlApplicationContext;
007:
008: import com.tc.test.TCTestCase;
009:
010: // FIXME test IntroductionInterceptor
011: // FIXME more complex tests - chained tests etc.
012:
013: /**
014: * @author Jonas Bonér
015: */
016: public class DelegatingProxyAopProxy_Test extends TCTestCase {
017:
018: private static final String BEAN_CONFIG = "com/tctest/spring/beanfactory-fastproxy.xml";
019:
020: public DelegatingProxyAopProxy_Test(String name) {
021: super (name);
022: disableAllUntil("2008-09-18"); // XXX timebombed
023: }
024:
025: public static void testBeforeAdvice() {
026: Logger.log = "";
027: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
028: BEAN_CONFIG);
029: IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx
030: .getBean("testBeforeAdviceDelegating");
031: assertNotNull(proxy);
032: proxy.doStuff("fuzzy");
033: assertEquals("before args(fuzzy) this("
034: + proxy.getClass().getName() + ") doStuff ", Logger.log);
035: }
036:
037: public static void testAfterReturningAdvice() {
038: Logger.log = "";
039: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
040: BEAN_CONFIG);
041: IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx
042: .getBean("testAfterReturningAdviceDelegating");
043: assertNotNull(proxy);
044: String stuff = proxy.returnStuff("fuzzy");
045: assertEquals(
046: "returnStuff after-returning(stuff) args(fuzzy) this("
047: + proxy.getClass().getName() + ") ", Logger.log);
048: }
049:
050: public static void testAfterThrowingAdvice() {
051: Logger.log = "";
052: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
053: BEAN_CONFIG);
054: IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx
055: .getBean("testAfterThrowingAdviceDelegating");
056: assertNotNull(proxy);
057: try {
058: proxy.throwStuff("fuzzy");
059: } catch (ExpectedException e) {
060: assertEquals(
061: "throwStuff after-throwing(expected) args(fuzzy) this("
062: + proxy.getClass().getName() + ") ",
063: Logger.log);
064: return;
065: }
066: fail("should have exited with an exception");
067: }
068:
069: public static void testAroundAdvice() {
070: Logger.log = "";
071: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
072: BEAN_CONFIG);
073: IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx
074: .getBean("testAroundAdviceDelegating");
075: assertNotNull(proxy);
076: proxy.doStuff("fuzzy");
077: assertEquals("before-around args(fuzzy) this("
078: + proxy.getClass().getName()
079: + ") doStuff after-around ", Logger.log);
080: }
081:
082: public static void testAroundAdviceChain() {
083: Logger.log = "";
084: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
085: BEAN_CONFIG);
086: IDelegatingProxyTarget proxy = (IDelegatingProxyTarget) ctx
087: .getBean("testAroundAdviceChainDelegating");
088: assertNotNull(proxy);
089: proxy.doStuff("fuzzy");
090: assertEquals("before-around args(fuzzy) this("
091: + proxy.getClass().getName()
092: + ") before-around args(fuzzy) this("
093: + proxy.getClass().getName()
094: + ") doStuff after-around after-around ", Logger.log);
095: }
096:
097: // XXX use test decorator to activate AW pipeline
098: public static junit.framework.Test suite() {
099: return new junit.framework.TestSuite(
100: DelegatingProxyAopProxy_Test.class);
101: }
102: }
|