Source Code Cross Referenced for LenyaTestCase.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » 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 » Content Management System » apache lenya 2.0 » org.apache.lenya.cms 
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.lenya.cms;
019:
020:        import java.io.File;
021:        import java.io.FileInputStream;
022:        import java.util.Arrays;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:
026:        import org.apache.avalon.framework.container.ContainerUtil;
027:        import org.apache.avalon.framework.context.DefaultContext;
028:        import org.apache.cocoon.Constants;
029:        import org.apache.cocoon.components.ContextHelper;
030:        import org.apache.cocoon.core.container.ContainerTestCase;
031:        import org.apache.cocoon.environment.Context;
032:        import org.apache.cocoon.environment.ObjectModelHelper;
033:        import org.apache.cocoon.environment.Request;
034:        import org.apache.cocoon.environment.commandline.CommandLineContext;
035:        import org.apache.cocoon.environment.commandline.CommandLineRequest;
036:        import org.apache.cocoon.environment.mock.MockEnvironment;
037:        import org.apache.cocoon.util.IOUtils;
038:        import org.apache.commons.lang.SystemUtils;
039:        import org.apache.excalibur.source.SourceResolver;
040:
041:        /**
042:         * Base class for Lenya tests which need the context information.
043:         */
044:        public class LenyaTestCase extends ContainerTestCase {
045:
046:            protected DefaultContext context;
047:
048:            protected void addContext(DefaultContext context) {
049:                super .addContext(context);
050:
051:                this .context = context;
052:
053:                String tempPath = System.getProperty("tempDir",
054:                        "build/lenya/temp");
055:                String contextRoot = System.getProperty("contextRoot",
056:                        "build/lenya/webapp");
057:                getLogger().info(
058:                        "Adding context root entry [" + contextRoot + "]");
059:
060:                File contextRootDir = new File(contextRoot);
061:                context.put("context-root", contextRootDir);
062:
063:                String testPath = System.getProperty("testPath", "build/test");
064:                File testRootDir = new File(testPath);
065:                context.put("test-path", testRootDir);
066:
067:                Context envContext = new CommandLineContext(contextRoot);
068:                ContainerUtil.enableLogging(envContext, getLogger());
069:                context.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, envContext);
070:
071:                File tempDir = new File(tempPath);
072:
073:                File workDir = new File(tempDir, "work");
074:                context.put("work-directory", workDir);
075:
076:                File cacheDir = new File(tempDir, "cache");
077:                context.put(Constants.CONTEXT_CACHE_DIR, cacheDir);
078:
079:                File uploadDir = new File(tempDir, "upload");
080:                context.put(Constants.CONTEXT_UPLOAD_DIR, uploadDir);
081:
082:                context.put(Constants.CONTEXT_CLASS_LOADER, LenyaTestCase.class
083:                        .getClassLoader());
084:                context.put(Constants.CONTEXT_CLASSPATH,
085:                        getClassPath(contextRoot));
086:                // context.put(Constants.CONTEXT_CONFIG_URL, conf.toURL());
087:                context.put(Constants.CONTEXT_DEFAULT_ENCODING, "ISO-8859-1");
088:            }
089:
090:            private Request request = null;
091:
092:            protected Request getRequest() {
093:                return this .request;
094:            }
095:
096:            protected void prepare() throws Exception {
097:                File testPath = new File("build/test");
098:                final String resourceName = LenyaTestCase.class.getName()
099:                        .replace('.', '/')
100:                        + ".xtest";
101:                File resourceFile = new File(testPath, resourceName.replace(
102:                        '/', File.separatorChar));
103:
104:                if (resourceFile.isFile()) {
105:                    getLogger().debug(
106:                            "Loading resource "
107:                                    + resourceFile.getAbsolutePath());
108:                    prepare(new FileInputStream(resourceFile));
109:                } else {
110:                    getLogger().debug("Resource not found " + resourceName);
111:                }
112:
113:                SourceResolver resolver = (SourceResolver) getManager().lookup(
114:                        SourceResolver.ROLE);
115:                MockEnvironment env = new MockEnvironment(resolver);
116:
117:                String pathInfo = getWebappUrl();
118:
119:                this .request = new CommandLineRequest(env, "", "", pathInfo,
120:                        new HashMap(), getRequestParameters());
121:                context.put("object-model.request", this .request);
122:
123:                Map objectModel = new HashMap();
124:                objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
125:                Context envContext = (Context) context
126:                        .get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
127:                objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, envContext);
128:                context.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel);
129:
130:            }
131:
132:            protected String getWebappUrl() {
133:                return "/test/authoring/index.html";
134:            }
135:
136:            protected Map getRequestParameters() {
137:                return new HashMap();
138:            }
139:
140:            /**
141:             * This builds the important ClassPath used by this class. It does so in a neutral way. It
142:             * iterates in alphabetical order through every file in the lib directory and adds it to the
143:             * classpath.
144:             * 
145:             * Also, we add the files to the ClassLoader for the Cocoon system. In order to protect
146:             * ourselves from skitzofrantic classloaders, we need to work with a known one.
147:             * 
148:             * @param context The context path
149:             * @return a <code>String</code> value
150:             */
151:            protected String getClassPath(final String context) {
152:                StringBuffer buildClassPath = new StringBuffer();
153:
154:                String classDir = context + "/WEB-INF/classes";
155:                buildClassPath.append(classDir);
156:
157:                File root = new File(context + "/WEB-INF/lib");
158:                if (root.isDirectory()) {
159:                    File[] libraries = root.listFiles();
160:                    Arrays.sort(libraries);
161:                    for (int i = 0; i < libraries.length; i++) {
162:                        if (libraries[i].getAbsolutePath().endsWith(".jar")) {
163:                            buildClassPath
164:                                    .append(File.pathSeparatorChar)
165:                                    .append(
166:                                            IOUtils
167:                                                    .getFullFilename(libraries[i]));
168:                        }
169:                    }
170:                }
171:
172:                buildClassPath.append(File.pathSeparatorChar).append(
173:                        SystemUtils.JAVA_CLASS_PATH);
174:
175:                // Extra class path is necessary for non-classloader-aware java compilers to compile XSPs
176:                // buildClassPath.append(File.pathSeparatorChar)
177:                // .append(getExtraClassPath(context));
178:
179:                getLogger().info("Context classpath: " + buildClassPath);
180:                return buildClassPath.toString();
181:            }
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.