Source Code Cross Referenced for ReloadingClassLoaderTestCase.java in  » Library » apache-common-JCI » org » apache » commons » jci » 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 » Library » apache common JCI » org.apache.commons.jci 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.jci;
019:
020:        import java.io.File;
021:
022:        import org.apache.commons.jci.classes.ExtendedDump;
023:        import org.apache.commons.jci.classes.SimpleDump;
024:        import org.apache.commons.jci.listeners.ReloadingListener;
025:        import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:
029:        /**
030:         * 
031:         * @author tcurdt
032:         */
033:        public final class ReloadingClassLoaderTestCase extends
034:                AbstractTestCase {
035:
036:            private final Log log = LogFactory
037:                    .getLog(ReloadingClassLoaderTestCase.class);
038:
039:            private ReloadingClassLoader classloader;
040:            private ReloadingListener listener;
041:            private FilesystemAlterationMonitor fam;
042:
043:            private final byte[] clazzSimple1;
044:            private final byte[] clazzSimple2;
045:            private final byte[] clazzExtended;
046:
047:            public ReloadingClassLoaderTestCase() throws Exception {
048:                clazzSimple1 = SimpleDump.dump("Simple1");
049:                clazzSimple2 = SimpleDump.dump("Simple2");
050:                clazzExtended = ExtendedDump.dump();
051:                assertTrue(clazzSimple1.length > 0);
052:                assertTrue(clazzSimple2.length > 0);
053:                assertTrue(clazzExtended.length > 0);
054:            }
055:
056:            protected void setUp() throws Exception {
057:                super .setUp();
058:
059:                classloader = new ReloadingClassLoader(this .getClass()
060:                        .getClassLoader());
061:                listener = new ReloadingListener();
062:
063:                listener.addReloadNotificationListener(classloader);
064:
065:                fam = new FilesystemAlterationMonitor();
066:                fam.addListener(directory, listener);
067:                fam.start();
068:            }
069:
070:            public void testCreate() throws Exception {
071:                listener.waitForFirstCheck();
072:
073:                log.debug("creating class");
074:                writeFile("jci/Simple.class", clazzSimple1);
075:                listener.waitForCheck();
076:
077:                final Object simple = classloader.loadClass("jci.Simple")
078:                        .newInstance();
079:                assertEquals("Simple1", simple.toString());
080:            }
081:
082:            public void testChange() throws Exception {
083:                listener.waitForFirstCheck();
084:
085:                log.debug("creating class");
086:                writeFile("jci/Simple.class", clazzSimple1);
087:                listener.waitForCheck();
088:
089:                final Object simple1 = classloader.loadClass("jci.Simple")
090:                        .newInstance();
091:                assertEquals("Simple1", simple1.toString());
092:
093:                log.debug("changing class");
094:                writeFile("jci/Simple.class", clazzSimple2);
095:                listener.waitForEvent();
096:
097:                final Object simple2 = classloader.loadClass("jci.Simple")
098:                        .newInstance();
099:                assertEquals("Simple2", simple2.toString());
100:            }
101:
102:            public void testDelete() throws Exception {
103:                listener.waitForFirstCheck();
104:
105:                log.debug("creating class");
106:                writeFile("jci/Simple.class", clazzSimple1);
107:                listener.waitForCheck();
108:
109:                final Object simple = classloader.loadClass("jci.Simple")
110:                        .newInstance();
111:                assertEquals("Simple1", simple.toString());
112:
113:                log.debug("deleting class");
114:                assertTrue(new File(directory, "jci/Simple.class").delete());
115:                listener.waitForEvent();
116:
117:                try {
118:                    classloader.loadClass("jci.Simple").newInstance();
119:                    fail();
120:                } catch (final ClassNotFoundException e) {
121:                    assertEquals("jci.Simple", e.getMessage());
122:                }
123:            }
124:
125:            public void testDeleteDependency() throws Exception {
126:                listener.waitForFirstCheck();
127:
128:                log.debug("creating classes");
129:                writeFile("jci/Simple.class", clazzSimple1);
130:                writeFile("jci/Extended.class", clazzExtended);
131:                listener.waitForCheck();
132:
133:                final Object simple = classloader.loadClass("jci.Simple")
134:                        .newInstance();
135:                assertEquals("Simple1", simple.toString());
136:
137:                final Object extended = classloader.loadClass("jci.Extended")
138:                        .newInstance();
139:                assertEquals("Extended:Simple1", extended.toString());
140:
141:                log.debug("deleting class dependency");
142:                assertTrue(new File(directory, "jci/Simple.class").delete());
143:                listener.waitForEvent();
144:
145:                try {
146:                    classloader.loadClass("jci.Extended").newInstance();
147:                    fail();
148:                } catch (final NoClassDefFoundError e) {
149:                    assertEquals("jci/Simple", e.getMessage());
150:                }
151:            }
152:
153:            public void testClassNotFound() {
154:                try {
155:                    classloader.loadClass("bla");
156:                    fail();
157:                } catch (final ClassNotFoundException e) {
158:                }
159:            }
160:
161:            public void testDelegation() {
162:                classloader.clearAssertionStatus();
163:                classloader.setClassAssertionStatus(
164:                        "org.apache.commons.jci.ReloadingClassLoader", true);
165:                classloader.setDefaultAssertionStatus(false);
166:                classloader.setPackageAssertionStatus("org.apache.commons.jci",
167:                        true);
168:                // FIXME: compare with delegation
169:            }
170:
171:            protected void tearDown() throws Exception {
172:                fam.removeListener(listener);
173:                fam.stop();
174:                super.tearDown();
175:            }
176:
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.