Source Code Cross Referenced for ParameterTest.java in  » Library » Apache-commons-validator-1.3.1-src » org » apache » commons » validator » 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 commons validator 1.3.1 src » org.apache.commons.validator 
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:        package org.apache.commons.validator;
018:
019:        import java.io.IOException;
020:        import java.util.Locale;
021:
022:        import junit.framework.Test;
023:        import junit.framework.TestSuite;
024:
025:        import org.xml.sax.SAXException;
026:
027:        /**
028:         * This TestCase is a confirmation of the parameter of the validator's method.
029:         *
030:         * @version $Revision: 478345 $ $Date: 2006-11-22 22:25:19 +0000 (Wed, 22 Nov 2006) $
031:         */
032:        public class ParameterTest extends TestCommon {
033:
034:            private static final String FORM_KEY = "nameForm";
035:
036:            private static final String firstNameField = "firstName";
037:
038:            private static final String middleNameField = "middleName";
039:
040:            private static final String lastNameField = "lastName";
041:
042:            private String firstName;
043:
044:            private String middleName;
045:
046:            private String lastName;
047:
048:            /**
049:             * Constructor.
050:             */
051:            public ParameterTest(String name) {
052:                super (name);
053:            }
054:
055:            /**
056:             * Start the tests.
057:             * 
058:             * @param theArgs the arguments. Not used
059:             */
060:            public static void main(String[] theArgs) {
061:                junit.awtui.TestRunner.main(new String[] { ParameterTest.class
062:                        .getName() });
063:            }
064:
065:            /**
066:             * Create a Test Suite
067:             * @return a test suite (<code>TestSuite</code>) that includes all
068:             *         methods starting with "test"
069:             */
070:            public static Test suite() {
071:                return new TestSuite(ParameterTest.class);
072:            }
073:
074:            /**
075:             * Load <code>ValidatorResources</code> from
076:             * ValidatorResultsTest-config.xml.
077:             */
078:            protected void setUp() throws IOException, SAXException {
079:                // Load resources
080:                loadResources("ParameterTest-config.xml");
081:
082:                // initialize values
083:                firstName = "foo";
084:                middleName = "123";
085:                lastName = "456";
086:
087:            }
088:
089:            protected void tearDown() {
090:            }
091:
092:            /**
093:             * Test all validations ran and passed.
094:             */
095:            public void testAllValid() throws ValidatorException {
096:
097:                // Create bean to run test on.
098:                NameBean bean = createNameBean();
099:
100:                Validator validator = new Validator(resources, FORM_KEY);
101:
102:                // add the name bean to the validator as a resource
103:                // for the validations to be performed on.
104:                validator.setParameter(Validator.BEAN_PARAM, bean);
105:                validator.setParameter(Validator.LOCALE_PARAM, Locale
106:                        .getDefault());
107:
108:                // Get results of the validation.
109:                ValidatorResults results = null;
110:                try {
111:                    results = validator.validate();
112:                } catch (Exception e) {
113:                    fail("Validator.validate() threw " + e);
114:                }
115:                assertParameterValue(validator, Validator.BEAN_PARAM,
116:                        Object.class);
117:                assertParameterValue(validator, Validator.FIELD_PARAM,
118:                        Field.class);
119:                assertParameterValue(validator, Validator.FORM_PARAM,
120:                        Form.class);
121:                assertParameterValue(validator, Validator.LOCALE_PARAM,
122:                        Locale.class);
123:                assertParameterValue(validator,
124:                        Validator.VALIDATOR_ACTION_PARAM, ValidatorAction.class);
125:                assertParameterValue(validator, Validator.VALIDATOR_PARAM,
126:                        Validator.class);
127:                assertParameterValue(validator,
128:                        Validator.VALIDATOR_RESULTS_PARAM,
129:                        ValidatorResults.class);
130:            }
131:
132:            private void assertParameterValue(Validator validator, String name,
133:                    Class type) {
134:                Object value = validator.getParameterValue(name);
135:                assertNotNull("Expected '" + type.getName() + "' but was null",
136:                        value);
137:                assertTrue("Expected '" + type.getName() + "' but was '"
138:                        + value.getClass().getName() + "'", type
139:                        .isInstance(value));
140:            }
141:
142:            /**
143:             * Create a NameBean.
144:             */
145:            private NameBean createNameBean() {
146:                NameBean name = new NameBean();
147:                name.setFirstName(firstName);
148:                name.setMiddleName(middleName);
149:                name.setLastName(lastName);
150:                return name;
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.