Source Code Cross Referenced for StaticInitializationTest.java in  » Aspect-oriented » aspectwerkz-2.0 » test » staticinitialization » 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.staticinitialization 
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.staticinitialization;
008:
009:        import java.util.ArrayList;
010:        import java.util.List;
011:
012:        import junit.framework.TestCase;
013:
014:        import org.codehaus.aspectwerkz.joinpoint.EnclosingStaticJoinPoint;
015:        import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
016:        import org.codehaus.aspectwerkz.joinpoint.Rtti;
017:        import org.codehaus.aspectwerkz.joinpoint.Signature;
018:        import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
019:        import org.codehaus.aspectwerkz.joinpoint.impl.StaticInitializationRttiImpl;
020:        import org.codehaus.aspectwerkz.joinpoint.impl.StaticInitializerSignatureImpl;
021:        import org.codehaus.aspectwerkz.joinpoint.management.JoinPointType;
022:        import test.CallerSideAdviceTest;
023:
024:        /**
025:         * Test for staticinitialization pointcuts.
026:         * 
027:         * @author <a href="mailto:the_mindstorm@evolva.ro">Alex Popescu</a>
028:         */
029:        public class StaticInitializationTest extends TestCase {
030:            public static final String[] BEFORE_EXPECTED_MESSAGES = {
031:                    "beforeStaticinitialization",
032:                    "aroundStaticinitializationSJP",
033:                    "aroundStaticinitializationJP" };
034:
035:            public static final String[] AFTER_EXPECTED_MESSAGES = {
036:                    "afterReturningStaticinitialization",
037:                    "afterStaticinititalization" };
038:
039:            public static final String CLINIT_EXECUTION_MESSAGE = "<clinit>.execution";
040:
041:            public static List s_messages = new ArrayList();
042:            public static List s_staticJoinPoints = new ArrayList();
043:            public static List s_joinPoints = new ArrayList();
044:
045:            public void testStaticInitializer() throws ClassNotFoundException {
046:                Class reflectClazz = Class
047:                        .forName("test.staticinitialization.ClinitTarget");
048:                try {
049:                    // required to run the clinit on Java 1.5
050:                    reflectClazz.newInstance();
051:                } catch (Exception e) {
052:                    fail(e.toString());
053:                }
054:
055:                checkMessages();
056:
057:                checkStaticJoinPoints(reflectClazz, s_staticJoinPoints);
058:                checkStaticJoinPoints(reflectClazz, s_joinPoints);
059:
060:                checkJoinPoints(reflectClazz);
061:            }
062:
063:            private void checkMessages() {
064:                int messages = 3 * (BEFORE_EXPECTED_MESSAGES.length + AFTER_EXPECTED_MESSAGES.length) + 1;
065:
066:                assertEquals("logged messages should match", messages,
067:                        s_messages.size());
068:
069:                for (int i = 0; i < BEFORE_EXPECTED_MESSAGES.length; i++) {
070:                    for (int j = 0; j < 3; j++) {
071:                        assertEquals(BEFORE_EXPECTED_MESSAGES[i], s_messages
072:                                .get(i * 3 + j));
073:                    }
074:                }
075:
076:                int lastBeforeIndex = 3 * BEFORE_EXPECTED_MESSAGES.length;
077:
078:                assertEquals("clinit was expected to execute",
079:                        CLINIT_EXECUTION_MESSAGE, s_messages
080:                                .get(lastBeforeIndex));
081:
082:                lastBeforeIndex++;
083:
084:                for (int i = 0; i < AFTER_EXPECTED_MESSAGES.length; i++) {
085:                    for (int j = 0; j < 3; j++) {
086:                        assertEquals(AFTER_EXPECTED_MESSAGES[i], s_messages
087:                                .get(lastBeforeIndex + (i * 3) + j));
088:                    }
089:                }
090:            }
091:
092:            private void checkStaticJoinPoints(Class clazz, List data) {
093:                assertEquals("staticjoinpoints number does not match", 12, data
094:                        .size());
095:
096:                Class signatureClass = StaticInitializerSignatureImpl.class;
097:
098:                for (int i = 0; i < data.size(); i++) {
099:                    StaticJoinPoint sjp = (StaticJoinPoint) data.get(i);
100:
101:                    assertEquals(clazz, sjp.getCallerClass());
102:
103:                    assertEquals(clazz, sjp.getCalleeClass());
104:
105:                    assertEquals(JoinPointType.STATIC_INITIALIZATION, sjp
106:                            .getType());
107:
108:                    Signature signature = sjp.getSignature();
109:                    assertNotNull(signature);
110:
111:                    assertEquals(signatureClass, signature.getClass());
112:
113:                    assertEquals(clazz, signature.getDeclaringType());
114:
115:                    EnclosingStaticJoinPoint esjp = sjp
116:                            .getEnclosingStaticJoinPoint();
117:
118:                    assertNotNull(esjp);
119:
120:                    assertEquals(JoinPointType.STATIC_INITIALIZATION, esjp
121:                            .getType());
122:
123:                    Signature enclSig = esjp.getSignature();
124:
125:                    assertNotNull(enclSig);
126:
127:                    assertEquals(signatureClass, enclSig.getClass());
128:
129:                    assertEquals(clazz, enclSig.getDeclaringType());
130:
131:                }
132:            }
133:
134:            private void checkJoinPoints(Class clazz) {
135:                assertEquals("joinpoints number does not match", 12,
136:                        s_staticJoinPoints.size());
137:
138:                Class siRtti = StaticInitializationRttiImpl.class;
139:
140:                for (int i = 0; i < s_joinPoints.size(); i++) {
141:                    JoinPoint jp = (JoinPoint) s_joinPoints.get(i);
142:
143:                    assertNull(jp.getCaller());
144:
145:                    assertNull(jp.getThis());
146:
147:                    assertNull(jp.getCallee());
148:
149:                    assertNull(jp.getTarget());
150:
151:                    Rtti rtti = jp.getRtti();
152:
153:                    assertNotNull(rtti);
154:
155:                    assertEquals(siRtti, rtti.getClass());
156:
157:                    assertEquals(clazz, rtti.getDeclaringType());
158:
159:                    assertNull(rtti.getThis());
160:
161:                    assertNull(rtti.getTarget());
162:                }
163:            }
164:
165:            public static void main(String[] args) {
166:                junit.textui.TestRunner.run(suite());
167:            }
168:
169:            public static junit.framework.Test suite() {
170:                return new junit.framework.TestSuite(
171:                        StaticInitializationTest.class);
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.