Source Code Cross Referenced for ArgsAdviceTest.java in  » Aspect-oriented » aspectwerkz-2.0 » test » args » 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 » Aspect oriented » aspectwerkz 2.0 » test.args 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**************************************************************************************
002:         * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved.                 *
003:         * http://aspectwerkz.codehaus.org                                                    *
004:         * ---------------------------------------------------------------------------------- *
005:         * The software in this package is published under the terms of the LGPL license      *
006:         * a copy of which has been included with this distribution in the license.txt file.  *
007:         **************************************************************************************/package test.args;
008:
009:        import test.Loggable;
010:        import junit.framework.TestCase;
011:
012:        /**
013:         * Test for args() syntax and pointcut / advice with signatures.
014:         * Some tests to cover XML syntax.
015:         * TODO: test for CALL pc and ctor exe/call jp
016:         *
017:         * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
018:         */
019:        public class ArgsAdviceTest extends TestCase implements  Loggable {
020:
021:            private String m_logString = "";
022:            private static String s_logString = "";
023:
024:            // used for ctor call and static field set, else we use jp.getTarget()
025:            public static void logStatic(String s) {
026:                s_logString += s;
027:            }
028:
029:            // execution(* m(..)) && args(i)
030:            public void testSingleAndDotDot() {
031:                m_logString = "";
032:                singleAndDotDot(1);
033:                assertEquals("before 1 invocation ", m_logString);
034:            }
035:
036:            // all bounded :(long l, String s, int[][] matrix)
037:            public void testWithArray() {
038:                m_logString = "";
039:                int[][] iis = new int[][] { { 1, 2 }, { 3 } };
040:                withArray(1L, "h", iis);
041:                assertEquals("before 1 h 1-2-3- invocation ", m_logString);
042:            }
043:
044:            //args(String, String, long)
045:            public void testMatchAll() {
046:                m_logString = "";
047:                matchAll("a0", "a1", 2);
048:                assertEquals("before before1 invocation after1 after ",
049:                        m_logString);
050:                m_logString = "";
051:                matchAllXML("a0", "a1", 2);
052:                assertEquals("before before1 invocation after1 after ",
053:                        m_logString);
054:            }
055:
056:            //args(..)
057:            public void testMatchAllWithWildcard() {
058:                m_logString = "";
059:                matchAllWithWildcard("a0", "a1", 2);
060:                assertEquals("before before1 invocation after1 after ",
061:                        m_logString);
062:            }
063:
064:            //args(s, ..)
065:            public void testGetFirst() {
066:                m_logString = "";
067:                getFirst("a0", "a1", 2);
068:                assertEquals(
069:                        "before a0 before1 a0 invocation after1 a0 after a0 ",
070:                        m_logString);
071:                m_logString = "";
072:                getFirstXML("a0", "a1", 2);
073:                assertEquals(
074:                        "before a0 before1 a0 invocation after1 a0 after a0 ",
075:                        m_logString);
076:
077:            }
078:
079:            //args(s, ..) as anonymous pointcut
080:            public void testGetFirstAnonymous() {
081:                m_logString = "";
082:                getFirstAnonymous("a0", "a1", 2);
083:                assertEquals(
084:                        "before a0 before1 a0 invocation after1 a0 after a0 ",
085:                        m_logString);
086:                //TODO (low prio): anonymous pc with args() is not supported in XML - see notes in aop.xml
087:                //        m_logString = "";
088:                //        getFirstAnonymousXML("a0", "a1", 2);
089:                //        assertEquals("before a0 before1 a0 invocation after1 a0 after a0 ", m_logString);
090:            }
091:
092:            //args(String, s, long) and increment it
093:            public void testChangeArg() {
094:                m_logString = "";
095:                changeArg("a0", new StringBuffer("a1"), 2);
096:                // beware: using String won't work as for regular Java behavior
097:                assertEquals(
098:                        "before a1x before1 a1xx invocation after1 a1xxx after a1xxxx ",
099:                        m_logString);
100:            }
101:
102:            // args(s0, s1, long), with Pc signature reversed
103:            public void testOrderChangedInPointcutSignature() {
104:                m_logString = "";
105:                orderChangedInPointcutSignature("a0", "a1", 2);
106:                assertEquals(
107:                        "before a1 a0 before1 a1 a0 invocation after1 a1 a0 after a1 a0 ",
108:                        m_logString);
109:            }
110:
111:            // args(s0, s1, long), with Advice signature reversed
112:            public void testOrderChangedInAdviceSignature() {
113:                m_logString = "";
114:                orderChangedInAdviceSignature("a0", "a1", 2);
115:                assertEquals(
116:                        "before a1 a0 before1 a1 a0 invocation after1 a1 a0 after a1 a0 ",
117:                        m_logString);
118:            }
119:
120:            // args(s0, s1, long), with Pointcut and Advice signature reversed
121:            public void testOrderChangedInPointcutAndAdviceSignature() {
122:                m_logString = "";
123:                orderChangedInPointcutAndAdviceSignature("a0", "a1", 2);
124:                assertEquals(
125:                        "before a0 a1 before1 a0 a1 invocation after1 a0 a1 after a0 a1 ",
126:                        m_logString);
127:                m_logString = "";
128:                orderChangedInPointcutAndAdviceSignatureXML("a0", "a1", null);
129:                assertEquals(
130:                        "before a0 a1 before1 a0 a1 invocation after1 a0 a1 after a0 a1 ",
131:                        m_logString);
132:            }
133:
134:            //-- method call pointcuts
135:
136:            //args(l<long>, s<String[]>)
137:            public void testCallGetFirstAndSecond() {
138:                m_logString = "";
139:                callGetFirstAndSecond(1L, new String[] { "s0", "s1" });
140:                assertEquals(
141:                        "before 1 s0,s1 before1 1 s0,s1 invocation after1 1 s0,s1 after 1 s0,s1 ",
142:                        m_logString);
143:                m_logString = "";
144:                callGetFirstAndSecondXML(1L, new String[] { "s0", "s1" }, null);
145:                assertEquals(
146:                        "before 1 s0,s1 before1 1 s0,s1 invocation after1 1 s0,s1 after 1 s0,s1 ",
147:                        m_logString);
148:            }
149:
150:            //-- ctor execution
151:            //args(s)
152:            public void testCtorExecutionGetFirst() {
153:                //FIXME
154:                // looks like a bug for ctor executiona and inner class inheritance
155:                // see CtorLoggable and CtorExecution<init>, that has the call to CtorLoggable<init> corrupted
156:                m_logString = "";
157:                CtorExecution target = new CtorExecution("s");
158:                assertEquals("before s before1 s invocation after1 s after s ",
159:                        m_logString);
160:                m_logString = "";
161:                CtorExecutionXML target2 = new CtorExecutionXML("s");
162:                assertEquals("before s before1 s invocation after1 s after s ",
163:                        m_logString);
164:            }
165:
166:            //-- ctor call
167:            //args(s)
168:            public void testCtorCallGetFirst() {
169:                s_logString = "";
170:                CtorCall target = new CtorCall("s");
171:                assertEquals("before s before1 s invocation after1 s after s ",
172:                        s_logString);
173:                s_logString = "";
174:                CtorCallXML target2 = new CtorCallXML("s");
175:                assertEquals("before s before1 s invocation after1 s after s ",
176:                        s_logString);
177:            }
178:
179:            //-- field set
180:            private String m_field;
181:            private static String s_field;
182:
183:            public String getField() {
184:                return m_field;
185:            }
186:
187:            public static String getStaticField() {
188:                return s_field;
189:            }
190:
191:            //arg(s)
192:            public void testFieldSetArg() {
193:                try {
194:                    m_logString = "";
195:                    m_field = "s";
196:                    assertEquals(
197:                            "before null,s before1 null,s after1 s,changed after s,s ",
198:                            m_logString);
199:                    s_logString = "";
200:                    s_field = "s";
201:                    assertEquals(
202:                            "before null,s before1 null,s after1 s,changed after s,s ",
203:                            s_logString);
204:                } catch (Error e) {
205:                    e.printStackTrace();
206:                }
207:            }
208:
209:            //-- Implementation methods
210:            public void log(String s) {
211:                m_logString += s;
212:            }
213:
214:            public void singleAndDotDot(int i) {
215:                log("invocation ");
216:            }
217:
218:            public void withArray(long l, String s, int[][] matrix) {
219:                log("invocation ");
220:            }
221:
222:            public void matchAll(String a0, String a1, long a2) {
223:                log("invocation ");
224:            }
225:
226:            public void matchAllXML(String a0, String a1, long a2) {
227:                log("invocation ");
228:            }
229:
230:            public void matchAllWithWildcard(String a0, String a1, long a2) {
231:                log("invocation ");
232:            }
233:
234:            public void getFirst(String a0, String a1, long a2) {
235:                log("invocation ");
236:            }
237:
238:            public void getFirstXML(String a0, String a1, long a2) {
239:                log("invocation ");
240:            }
241:
242:            public void getFirstAnonymous(String a0, String a1, long a2) {
243:                log("invocation ");
244:            }
245:
246:            public void getFirstAnonymousXML(String a0, String a1, long a2) {
247:                log("invocation ");
248:            }
249:
250:            public void changeArg(String a0, StringBuffer a1, long a2) {
251:                log("invocation ");
252:            }
253:
254:            public void orderChangedInPointcutSignature(String a0, String a1,
255:                    long a2) {
256:                log("invocation ");
257:            }
258:
259:            public void orderChangedInAdviceSignature(String a0, String a1,
260:                    long a2) {
261:                log("invocation ");
262:            }
263:
264:            public void orderChangedInPointcutAndAdviceSignature(String a0,
265:                    String a1, long a2) {
266:                log("invocation ");
267:            }
268:
269:            public void orderChangedInPointcutAndAdviceSignatureXML(String a0,
270:                    String a1, Object[] a2) {
271:                log("invocation ");
272:            }
273:
274:            //-- method call
275:            public void callGetFirstAndSecond(long l, String[] s) {
276:                log("invocation ");
277:            }
278:
279:            public void callGetFirstAndSecondXML(long l, String[] s,
280:                    String[] ignore) {
281:                log("invocation ");
282:            }
283:
284:            class CtorLoggable implements  Loggable {
285:                public CtorLoggable() {
286:                }
287:
288:                public void log(String s) {
289:                    m_logString += s;
290:                }
291:            }
292:
293:            //-- ctor execution
294:            class CtorExecution extends CtorLoggable {
295:                public CtorExecution(String s) {
296:                    this .log("invocation ");
297:                }
298:            }
299:
300:            class CtorExecutionXML extends CtorLoggable {
301:                public CtorExecutionXML(String s) {
302:                    this .log("invocation ");
303:                }
304:            }
305:
306:            //-- ctor call
307:            class CtorCall extends CtorLoggable {
308:                public CtorCall(String s) {
309:                    logStatic("invocation ");
310:                }
311:            }
312:
313:            class CtorCallXML extends CtorLoggable {
314:                public CtorCallXML(String s) {
315:                    logStatic("invocation ");
316:                }
317:            }
318:
319:            //-- JUnit
320:            public static void main(String[] args) {
321:                junit.textui.TestRunner.run(suite());
322:            }
323:
324:            public static junit.framework.Test suite() {
325:                return new junit.framework.TestSuite(ArgsAdviceTest.class);
326:            }
327:
328:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.