Source Code Cross Referenced for TestModuleConfig.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » config » 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 » Web Framework » struts 1.3.8 » org.apache.struts.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TestModuleConfig.java 471754 2006-11-06 14:55:09Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts.config;
022:
023:        import junit.framework.Test;
024:        import junit.framework.TestCase;
025:        import junit.framework.TestSuite;
026:
027:        import org.apache.commons.digester.Digester;
028:
029:        import java.io.InputStream;
030:
031:        /**
032:         * Unit tests for the <code>org.apache.struts.config</code> package.
033:         *
034:         * @version $Rev: 471754 $ $Date: 2005-03-01 20:26:14 -0500 (Tue, 01 Mar 2005)
035:         *          $
036:         */
037:        public class TestModuleConfig extends TestCase {
038:            // ----------------------------------------------------- Instance Variables
039:
040:            /**
041:             * The ModuleConfig we are testing.
042:             */
043:            protected ModuleConfig config = null;
044:
045:            // ----------------------------------------------------------- Constructors
046:
047:            /**
048:             * Construct a new instance of this test case.
049:             *
050:             * @param name Name of the test case
051:             */
052:            public TestModuleConfig(String name) {
053:                super (name);
054:            }
055:
056:            // --------------------------------------------------------- Public Methods
057:
058:            /**
059:             * Set up instance variables required by this test case.
060:             */
061:            public void setUp() {
062:                ModuleConfigFactory factoryObject = ModuleConfigFactory
063:                        .createFactory();
064:
065:                config = factoryObject.createModuleConfig("");
066:            }
067:
068:            /**
069:             * Return the tests included in this test suite.
070:             */
071:            public static Test suite() {
072:                return (new TestSuite(TestModuleConfig.class));
073:            }
074:
075:            /**
076:             * Tear down instance variables required by this test case.
077:             */
078:            public void tearDown() {
079:                config = null;
080:            }
081:
082:            // ------------------------------------------------ Individual Test Methods
083:            private void parseConfig(String publicId, String entityURL,
084:                    String strutsConfig) {
085:                // Prepare a Digester for parsing a struts-config.xml file
086:                Digester digester = new Digester();
087:
088:                digester.push(config);
089:                digester.setNamespaceAware(true);
090:                digester.setValidating(true);
091:                digester.addRuleSet(new ConfigRuleSet());
092:                digester.register(publicId, this .getClass().getResource(
093:                        entityURL).toString());
094:
095:                // Parse the test struts-config.xml file
096:                try {
097:                    InputStream input = this .getClass().getResourceAsStream(
098:                            strutsConfig);
099:
100:                    assertNotNull("Got an input stream for " + strutsConfig,
101:                            input);
102:                    digester.parse(input);
103:                    input.close();
104:                } catch (Throwable t) {
105:                    t.printStackTrace(System.out);
106:                    fail("Parsing threw exception:  " + t);
107:                }
108:            }
109:
110:            /**
111:             * Test parsing of a struts-config.xml file.
112:             */
113:            public void testParse() {
114:                testParseBase(
115:                        "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN",
116:                        "/org/apache/struts/resources/struts-config_1_2.dtd",
117:                        "/org/apache/struts/config/struts-config.xml");
118:            }
119:
120:            public void testParse1_1() {
121:                testParseBase(
122:                        "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN",
123:                        "/org/apache/struts/resources/struts-config_1_1.dtd",
124:                        "/org/apache/struts/config/struts-config-1.1.xml");
125:            }
126:
127:            public void testParseBase(String publicId, String entityURL,
128:                    String strutsConfig) {
129:                parseConfig(publicId, entityURL, strutsConfig);
130:
131:                // Perform assertion tests on the parsed information
132:                FormBeanConfig[] fbcs = config.findFormBeanConfigs();
133:
134:                assertNotNull("Found our form bean configurations", fbcs);
135:                assertEquals("Found three form bean configurations", 3,
136:                        fbcs.length);
137:
138:                ForwardConfig[] fcs = config.findForwardConfigs();
139:
140:                assertNotNull("Found our forward configurations", fcs);
141:                assertEquals("Found three forward configurations", 3,
142:                        fcs.length);
143:
144:                ActionConfig logon = config.findActionConfig("/logon");
145:
146:                assertNotNull("Found logon action configuration", logon);
147:                assertEquals("Found correct logon configuration", "logonForm",
148:                        logon.getName());
149:            }
150:
151:            /**
152:             * Tests a struts-config.xml that contains a custom mapping and property.
153:             */
154:            public void testCustomMappingParse() {
155:                // Prepare a Digester for parsing a struts-config.xml file
156:                testCustomMappingParseBase(
157:                        "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN",
158:                        "/org/apache/struts/resources/struts-config_1_2.dtd",
159:                        "/org/apache/struts/config/struts-config-custom-mapping.xml");
160:            }
161:
162:            /**
163:             * Tests a struts-config.xml that contains a custom mapping and property.
164:             */
165:            public void testCustomMappingParse1_1() {
166:                // Prepare a Digester for parsing a struts-config.xml file
167:                testCustomMappingParseBase(
168:                        "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN",
169:                        "/org/apache/struts/resources/struts-config_1_1.dtd",
170:                        "/org/apache/struts/config/struts-config-custom-mapping-1.1.xml");
171:            }
172:
173:            /**
174:             * Tests a struts-config.xml that contains a custom mapping and property.
175:             */
176:            private void testCustomMappingParseBase(String publicId,
177:                    String entityURL, String strutsConfig) {
178:                parseConfig(publicId, entityURL, strutsConfig);
179:
180:                // Perform assertion tests on the parsed information
181:                CustomMappingTest map = (CustomMappingTest) config
182:                        .findActionConfig("/editRegistration");
183:
184:                assertNotNull("Cannot find editRegistration mapping", map);
185:                assertTrue("The custom mapping attribute has not been set", map
186:                        .getPublic());
187:            }
188:
189:            /**
190:             * Test order of action mappings defined perserved.
191:             */
192:            public void testPreserveActionMappingsOrder() {
193:                parseConfig(
194:                        "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN",
195:                        "/org/apache/struts/resources/struts-config_1_2.dtd",
196:                        "/org/apache/struts/config/struts-config.xml");
197:
198:                String[] paths = new String[] { "/editRegistration",
199:                        "/editSubscription", "/logoff", "/logon",
200:                        "/saveRegistration", "/saveSubscription", "/tour" };
201:
202:                ActionConfig[] actions = config.findActionConfigs();
203:
204:                for (int x = 0; x < paths.length; x++) {
205:                    assertTrue("Action config out of order:"
206:                            + actions[x].getPath(), paths[x].equals(actions[x]
207:                            .getPath()));
208:                }
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.