Source Code Cross Referenced for EmbeddedPluginClassLoaderTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » plugin » 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 » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.plugin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         * 
004:         * 
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         * http://www.opensource.org/licenses/ecl1.php
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:        package edu.iu.uis.eden.plugin;
018:
019:        import java.io.BufferedReader;
020:        import java.io.File;
021:        import java.io.InputStream;
022:        import java.io.InputStreamReader;
023:        import java.net.URL;
024:
025:        import junit.framework.TestCase;
026:
027:        import org.junit.Test;
028:
029:        public class EmbeddedPluginClassLoaderTest extends TestCase {
030:
031:            @Test
032:            public void testLoadEmbeddedResources() throws Exception {
033:                // load the embedded-test.jar
034:                File embeddedJar = new File(
035:                        "test/src/edu/iu/uis/eden/plugin/embedded-test.jar");
036:                assertTrue(embeddedJar.exists());
037:                assertTrue(embeddedJar.isFile());
038:                URL embeddedURL = embeddedJar.toURL();
039:                PluginClassLoader pluginClassLoader = new PluginClassLoader();
040:                pluginClassLoader.addURL(embeddedURL);
041:
042:                // first test that we can load the META-INF/embedded-workflow.xml file
043:                URL embeddedWFXml = pluginClassLoader
044:                        .getResource("embedded/META-INF/embedded-workflow.xml");
045:                assertNotNull("should be able to find embedded-workflow.xml",
046:                        embeddedWFXml);
047:
048:                InputStream stream = embeddedWFXml.openStream();
049:                int numBytes = 0;
050:                while (stream.read() != -1) {
051:                    numBytes++;
052:                }
053:                assertTrue(
054:                        "There should be more than 0 bytes in the embedded-workflow.xml file.",
055:                        numBytes > 0);
056:
057:                // test that we can load the classes-test.txt file
058:                URL classesTestUrl = pluginClassLoader
059:                        .getResource("embedded/classes/classes-test.txt");
060:                assertNotNull("Failed to load the classes-test.txt file.",
061:                        classesTestUrl);
062:
063:                // now create the embedded classloader, it's important that the pluginClassLoader is that parent
064:                // because that allows us to pull the embedded plugin out of the jar at 
065:                // test/src/edu/iu/uis/eden/plugin/embedded-test.jar 
066:                // This jar has some special files in it that we use to verify the jar in this test case.
067:                EmbeddedPluginClassLoader embeddedCL = new EmbeddedPluginClassLoader(
068:                        pluginClassLoader, "embedded");
069:
070:                // try to load the AxisClient class which should originate in a jar
071:                String axisClientClassName = "org.apache.axis.client.AxisClient";
072:                try {
073:                    Class axisClientClass = embeddedCL
074:                            .loadClass(axisClientClassName);
075:                    assertEquals("Wrong classloader.", embeddedCL,
076:                            axisClientClass.getClassLoader());
077:                } catch (ClassNotFoundException e) {
078:                    fail("Could not load the axis client.");
079:                }
080:                // assert that, even after loading the class, it's still possible to access the .class file as a resource
081:                String axisClientClassResourceName = axisClientClassName
082:                        .replace(".", "/").concat(".class");
083:                URL axisClientClassURL = embeddedCL
084:                        .getResource(axisClientClassResourceName);
085:                assertNotNull(axisClientClassURL);
086:                // also test that we can load the resource, even if it has a / at the beginning
087:                axisClientClassURL = embeddedCL.getResource("/"
088:                        + axisClientClassResourceName);
089:                assertNotNull(axisClientClassURL);
090:
091:                // try to load the WorkflowUtilityServiceEndpoint which should be in the embedded/classes directory
092:                try {
093:                    Class endpointClass = embeddedCL
094:                            .loadClass("edu.iu.uis.eden.server.WorkflowUtilityServiceEndpoint");
095:                    assertEquals("Wrong classloader.", embeddedCL,
096:                            endpointClass.getClassLoader());
097:                } catch (ClassNotFoundException e) {
098:                    fail("Could not load the workflow utility service endpoint.");
099:                }
100:
101:                // now try loading the same class as a resource
102:                URL endpointUrl = embeddedCL
103:                        .getResource("edu/iu/uis/eden/server/WorkflowUtilityServiceEndpoint.class");
104:                assertNotNull(
105:                        "Failed to locate the WorkflowUtilityServiceEndpoint class in the classloader.",
106:                        endpointUrl);
107:
108:                // try to find a resource that shouldn't be in our embedded classloader (instead it's parent)
109:                URL testSpringUrl = embeddedCL.findResource("TestSpring.xml");
110:                assertNull("Shouldn't have been able to find TestSpring.xml",
111:                        testSpringUrl);
112:                // however, if we call getResource it should look in the parent classloader as well
113:                testSpringUrl = embeddedCL.getResource("TestSpring.xml");
114:                assertNotNull("Should have been able to find TestSpring.xml",
115:                        testSpringUrl);
116:
117:                // try to load the Spring.xml resource
118:                URL springUrl = embeddedCL.getResource("Spring.xml");
119:                assertNotNull("Could not locate Spring.xml", springUrl);
120:                springUrl = embeddedCL.findResource("Spring.xml");
121:                assertNotNull("Could not find Spring.xml", springUrl);
122:
123:                // try to load the classes-test.txt resource
124:                classesTestUrl = embeddedCL.getResource("classes-test.txt");
125:                assertNotNull(
126:                        "Could not locate the classes-test.txt resource.",
127:                        classesTestUrl);
128:                BufferedReader reader = new BufferedReader(
129:                        new InputStreamReader(classesTestUrl.openStream()));
130:                String line = reader.readLine();
131:                reader.close();
132:                assertEquals("classes-test", line);
133:
134:                // try to load the lib-test.txt resource
135:                URL libTestUrl = embeddedCL.getResource("lib-test.txt");
136:                assertNotNull("Could not locate the lib-test.txt resource.",
137:                        libTestUrl);
138:                reader = new BufferedReader(new InputStreamReader(libTestUrl
139:                        .openStream()));
140:                line = reader.readLine();
141:                reader.close();
142:                assertEquals("lib-test", line);
143:
144:                // test with a slash at the beginning
145:                libTestUrl = embeddedCL.getResource("/lib-test.txt");
146:                assertNotNull("Could not locate the lib-test.txt resource.",
147:                        libTestUrl);
148:                reader = new BufferedReader(new InputStreamReader(libTestUrl
149:                        .openStream()));
150:                line = reader.readLine();
151:                reader.close();
152:                assertEquals("lib-test", line);
153:
154:            }
155:
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.