Source Code Cross Referenced for WeavedTestCase.java in  » Aspect-oriented » aspectwerkz-2.0 » org » codehaus » aspectwerkz » 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 » org.codehaus.aspectwerkz 
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 org.codehaus.aspectwerkz;
008:
009:        import junit.framework.TestCase;
010:        import org.codehaus.aspectwerkz.exception.WrappedRuntimeException;
011:        import org.codehaus.aspectwerkz.hook.impl.WeavingClassLoader;
012:
013:        import java.io.File;
014:        import java.io.IOException;
015:        import java.lang.reflect.Constructor;
016:        import java.lang.reflect.Method;
017:        import java.net.URL;
018:        import java.util.ArrayList;
019:        import java.util.StringTokenizer;
020:
021:        /**
022:         * Transparently runs TestCase with an embedded online mode Write a JUnit test case and extends WeaverTestCase.
023:         *
024:         * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
025:         */
026:        public class WeavedTestCase extends TestCase {
027:            /**
028:             * the test runner that runs the test thru reflection in a weaving ClassLoader
029:             */
030:            private static WeaverTestRunner s_runner = new WeaverTestRunner();
031:
032:            public WeavedTestCase() {
033:                super ();
034:            }
035:
036:            public WeavedTestCase(String name) {
037:                super (name);
038:            }
039:
040:            /**
041:             * Overrides JUnit runBare() to run thru the weaverTestRunner This allow WeaverTestCase to be regular TestCase
042:             *
043:             * @throws java.lang.Throwable
044:             */
045:            public void runBare() throws Throwable {
046:                s_runner.runTest(this .getClass().getName(), getName());
047:            }
048:
049:            /**
050:             * Callback the regulare JUnit runBare()
051:             *
052:             * @throws java.lang.Throwable
053:             */
054:            public void runBareAfterWeaving() throws Throwable {
055:                super .runBare();
056:            }
057:
058:            /**
059:             * Allow to run WeaverTestCase thru a weaving ClassLoader
060:             */
061:            public static class WeaverTestRunner {
062:                /**
063:                 * Weaving classloader
064:                 */
065:                private WeavingClassLoader cl;
066:
067:                /**
068:                 * Build weavin classloader with system class path and ext. classloader as parent
069:                 */
070:                public WeaverTestRunner() {
071:                    try {
072:                        String path = System.getProperty("java.class.path");
073:                        ArrayList paths = new ArrayList();
074:                        StringTokenizer st = new StringTokenizer(path,
075:                                File.pathSeparator);
076:                        while (st.hasMoreTokens()) {
077:                            paths.add((new File(st.nextToken()))
078:                                    .getCanonicalFile().toURL());
079:                        }
080:                        cl = new WeavingClassLoader((URL[]) paths
081:                                .toArray(new URL[] {}), ClassLoader
082:                                .getSystemClassLoader().getParent());
083:                    } catch (IOException e) {
084:                        throw new WrappedRuntimeException(e);
085:                    }
086:                }
087:
088:                /**
089:                 * Runs a single test (testXX) Takes care of not using the weaving class loader is online mode or
090:                 * weavingClassLoader.main() is already used (might fail under JRockit MAPI)
091:                 *
092:                 * @param testClassName  test class
093:                 * @param testMethodName test method
094:                 * @throws java.lang.Throwable
095:                 */
096:                public void runTest(String testClassName, String testMethodName)
097:                        throws Throwable {
098:                    // skip test embedded weaving if online mode / weavingClassLoader.main() is already used
099:                    if ((cl.getClass().getClassLoader() == null)
100:                            || (cl.getClass().getClassLoader().getClass()
101:                                    .getName().indexOf("hook.impl.Weaving") > 0)) {
102:                        ;
103:                    } else {
104:                        Thread.currentThread().setContextClassLoader(cl); // needed for Aspect loading
105:                    }
106:                    Class testClass = Class.forName(testClassName, true, Thread
107:                            .currentThread().getContextClassLoader());
108:
109:                    //)cl.loadClass(testClassName);
110:                    Constructor ctor = null;
111:                    Object testInstance = null;
112:                    try {
113:                        // new junit style
114:                        ctor = testClass.getConstructor(new Class[] {});
115:                        testInstance = ctor.newInstance(new Object[] {});
116:                        Method setNameMethod = testClass.getMethod(
117:                                "setExpression", new Class[] { String.class });
118:                        setNameMethod.invoke(testInstance,
119:                                new Object[] { testMethodName });
120:                    } catch (NoSuchMethodException e) {
121:                        ctor = testClass
122:                                .getConstructor(new Class[] { String.class });
123:                        testInstance = ctor
124:                                .newInstance(new Object[] { testMethodName });
125:                    }
126:                    Method runAfterWeavingMethod = testClass.getMethod(
127:                            "runBareAfterWeaving", new Class[] {});
128:                    runAfterWeavingMethod.invoke(testInstance, new Object[] {});
129:                }
130:            }
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.