Source Code Cross Referenced for FastAopProxy_Test.java in  » Net » Terracotta » com » tctest » spring » aop » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tctest.spring.aop 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.aop.framework.ProxyFactoryBean;
007:
008:        import com.tc.test.TCTestCase;
009:        import com.tcspring.FastAopProxy;
010:
011:        // XXX use test decorator to activate AW pipeline
012:        public class FastAopProxy_Test extends TCTestCase {
013:            IMessageWriter target = null;
014:            ProxyFactoryBean proxyFactoryBean = null;
015:
016:            Object cglibProxied = null;
017:            Object cglibProxied2 = null;
018:
019:            Object jdkDynamicProxied = null;
020:            Object jdkDynamicProxied2 = null;
021:
022:            FastAopProxy fastProxy = null;
023:
024:            public FastAopProxy_Test() {
025:                disableAllUntil("2008-09-18"); // XXX timebombed
026:            }
027:
028:            public void setUp() {
029:                target = new MessageWriter();
030:
031:                proxyFactoryBean = new ProxyFactoryBean();
032:                proxyFactoryBean.setFrozen(false);
033:                proxyFactoryBean.setOptimize(true);
034:                proxyFactoryBean.setTarget(target);
035:                proxyFactoryBean.addAdvice(new SimpleBeforeAdvice());
036:
037:                cglibProxied = proxyFactoryBean.getObject();
038:
039:                proxyFactoryBean
040:                        .setInterfaces(new Class[] { IMessageWriter.class });
041:                proxyFactoryBean.setOptimize(false);
042:                jdkDynamicProxied = proxyFactoryBean.getObject();
043:
044:                // get the 2nd copy
045:
046:                proxyFactoryBean = new ProxyFactoryBean();
047:                proxyFactoryBean.setFrozen(false);
048:                proxyFactoryBean.setOptimize(true);
049:                proxyFactoryBean.setTarget(target);
050:                proxyFactoryBean.addAdvice(new SimpleBeforeAdvice());
051:
052:                cglibProxied2 = proxyFactoryBean.getObject();
053:
054:                proxyFactoryBean
055:                        .setInterfaces(new Class[] { IMessageWriter.class });
056:                proxyFactoryBean.setOptimize(false);
057:
058:                jdkDynamicProxied2 = proxyFactoryBean.getObject();
059:
060:                // get the fast proxy
061:
062:                fastProxy = new FastAopProxy(proxyFactoryBean);
063:            }
064:
065:            public void testClassLoader() throws Exception {
066:                assertTrue(cglibProxied instanceof  MessageWriter);
067:
068:                assertTrue(jdkDynamicProxied instanceof  IMessageWriter);
069:                assertFalse(jdkDynamicProxied instanceof  MessageWriter);
070:
071:                Object fastProxied1 = fastProxy.getProxy();
072:                Object fastProxied2 = fastProxy.getProxy(target.getClass()
073:                        .getClassLoader());
074:                Object fastProxied3 = fastProxy.getProxy(new MyClassLoader(
075:                        target.getClass().getClassLoader()));
076:
077:                assertTrue(fastProxied1 instanceof  IMessageWriter);
078:                assertFalse(fastProxied1 instanceof  MessageWriter);
079:
080:                assertTrue(fastProxied2 instanceof  IMessageWriter);
081:                assertFalse(fastProxied2 instanceof  MessageWriter);
082:
083:                assertTrue(fastProxied3 instanceof  IMessageWriter);
084:                assertFalse(fastProxied3 instanceof  MessageWriter);
085:            }
086:
087:            // interesting to observation
088:            public void testEquality() throws Exception {
089:                assertFalse(jdkDynamicProxied.equals(jdkDynamicProxied2));
090:
091:                assertFalse(cglibProxied.equals(cglibProxied2));
092:
093:                Object fastProxied1 = fastProxy.getProxy();
094:                assertFalse(fastProxied1.equals(fastProxy.getProxy()));
095:            }
096:
097:            public void testBeforeAdvice() throws Exception {
098:                Logger.log = null;
099:                String cglibProxiedRv = ((MessageWriter) cglibProxied)
100:                        .writeMessage();
101:                String cglibProxiedLog = Logger.log;
102:                assertEquals("World", cglibProxiedRv);
103:                assertTrue(cglibProxiedLog.indexOf("*EMPTY*") > -1);
104:
105:                Logger.log = null;
106:                String jdkDynamicProxiedRv = ((IMessageWriter) cglibProxied)
107:                        .writeMessage();
108:                String jdkDynamicProxiedLog = Logger.log;
109:                assertEquals("World", jdkDynamicProxiedRv);
110:                assertTrue(jdkDynamicProxiedLog.indexOf("*EMPTY*") > -1);
111:
112:                Object fastProxied = fastProxy.getProxy();
113:                Logger.log = null;
114:                String fastProxiedRv = ((IMessageWriter) fastProxied)
115:                        .writeMessage();
116:                String fastProxiedLog = Logger.log;
117:                assertEquals("World", fastProxiedRv);
118:                assertTrue("This is what we get: " + fastProxiedLog,
119:                        fastProxiedLog.indexOf("*EMPTY*") > -1);
120:            }
121:
122:            public void testNested1() {
123:                ProxyFactoryBean factory = new ProxyFactoryBean();
124:                factory.setFrozen(false);
125:                factory.setOptimize(true);
126:                factory.setInterfaces(new Class[] { IMessageWriter.class });
127:                factory.setTarget(cglibProxied);
128:
129:                FastAopProxy proxy = new FastAopProxy(factory);
130:
131:                Object nested = proxy.getProxy();
132:
133:                Logger.log = null;
134:                String nestedRv = ((IMessageWriter) nested).writeMessage();
135:                String nestedLog = Logger.log;
136:                assertEquals("World", nestedRv);
137:            }
138:
139:            public void testNested2() {
140:                ProxyFactoryBean factory = new ProxyFactoryBean();
141:                factory.setFrozen(false);
142:                factory.setOptimize(true);
143:                factory.setInterfaces(new Class[] { IMessageWriter.class });
144:                factory.setTarget(this .jdkDynamicProxied);
145:
146:                FastAopProxy proxy = new FastAopProxy(factory);
147:
148:                Object nested = proxy.getProxy();
149:
150:                Logger.log = null;
151:                String nestedRv = ((IMessageWriter) nested).writeMessage();
152:                String nestedLog = Logger.log;
153:                assertEquals("World", nestedRv);
154:            }
155:
156:            public void testNested3() {
157:                ProxyFactoryBean factory = new ProxyFactoryBean();
158:                factory.setFrozen(false);
159:                factory.setOptimize(true);
160:                factory.setInterfaces(new Class[] { IMessageWriter.class });
161:                factory.setTarget(fastProxy.getProxy());
162:
163:                FastAopProxy proxy = new FastAopProxy(factory);
164:
165:                Object nested = proxy.getProxy();
166:
167:                Logger.log = null;
168:                String nestedRv = ((IMessageWriter) nested).writeMessage();
169:                String nestedLog = Logger.log;
170:                assertEquals("World", nestedRv);
171:            }
172:
173:            public void testNullConfig() {
174:                try {
175:                    this .fastProxy = new FastAopProxy(null);
176:                    fastProxy.getProxy();
177:                    fail("Shouldn't allow null interceptors");
178:                } catch (Exception ex) {
179:                    ex.printStackTrace();
180:                }
181:            }
182:
183:            public void testNoTarget() {
184:                proxyFactoryBean = new ProxyFactoryBean();
185:                proxyFactoryBean.setFrozen(false);
186:                proxyFactoryBean.setOptimize(true);
187:                proxyFactoryBean
188:                        .setInterfaces(new Class[] { IMessageWriter.class });
189:                proxyFactoryBean.addAdvice(new SimpleBeforeAdvice());
190:
191:                try {
192:                    this .fastProxy = new FastAopProxy(proxyFactoryBean);
193:                    fastProxy.getProxy();
194:                    fail("Shouldn't allow null interceptors");
195:                } catch (Exception ex) {
196:                    ex.printStackTrace();
197:                }
198:            }
199:
200:            private static class MyClassLoader extends ClassLoader {
201:                public MyClassLoader(ClassLoader parent) {
202:                    super(parent);
203:                }
204:            }
205:
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.