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 SubclassingProxyAopProxy_Test extends TCTestCase {
017:
018: private static final String BEAN_CONFIG = "com/tctest/spring/beanfactory-fastproxy.xml";
019:
020: public SubclassingProxyAopProxy_Test(String name) {
021: super (name);
022: disableAllUntil("2008-11-01");
023: }
024:
025: public static void testBeforeAdvice() {
026: Logger.log = "";
027: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
028: BEAN_CONFIG);
029: SubclassingProxyTarget proxy = (SubclassingProxyTarget) ctx
030: .getBean("testBeforeAdviceSubclassing");
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: SubclassingProxyTarget proxy = (SubclassingProxyTarget) ctx
042: .getBean("testAfterReturningAdviceSubclassing");
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: SubclassingProxyTarget proxy = (SubclassingProxyTarget) ctx
055: .getBean("testAfterThrowingAdviceSubclassing");
056: assertNotNull(proxy);
057: try {
058: proxy.throwStuff("fuzzy");
059: } catch (ExpectedException e) {
060: e.printStackTrace();
061: assertEquals(
062: "throwStuff after-throwing(expected) args(fuzzy) this("
063: + proxy.getClass().getName() + ") ",
064: Logger.log);
065: return;
066: }
067: fail("should have exited with an exception");
068: }
069:
070: public static void testAroundAdvice() {
071: Logger.log = "";
072: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
073: BEAN_CONFIG);
074: SubclassingProxyTarget proxy = (SubclassingProxyTarget) ctx
075: .getBean("testAroundAdviceSubclassing");
076: assertNotNull(proxy);
077: proxy.doStuff("fuzzy");
078: assertEquals("before-around args(fuzzy) this("
079: + proxy.getClass().getName()
080: + ") doStuff after-around ", Logger.log);
081: }
082:
083: public static void testAroundAdviceChain() {
084: Logger.log = "";
085: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
086: BEAN_CONFIG);
087: SubclassingProxyTarget proxy = (SubclassingProxyTarget) ctx
088: .getBean("testAroundAdviceChainSubclassing");
089: assertNotNull(proxy);
090: proxy.doStuff("fuzzy");
091: assertEquals("before-around args(fuzzy) this("
092: + proxy.getClass().getName()
093: + ") before-around args(fuzzy) this("
094: + proxy.getClass().getName()
095: + ") doStuff after-around after-around ", Logger.log);
096: }
097:
098: // XXX use test decoration to activate AW pipeline
099: public static junit.framework.Test suite() {
100: return new junit.framework.TestSuite(
101: SubclassingProxyAopProxy_Test.class);
102: }
103:
104: }
|