Source Code Cross Referenced for LocaleTest.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:         * Performs Validation Test for locale validations.
029:         *
030:         * @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
031:         */
032:        public class LocaleTest extends TestCommon {
033:
034:            /**
035:             * The key used to retrieve the set of validation rules from the xml file.
036:             */
037:            protected static String FORM_KEY = "nameForm";
038:
039:            /** The key used to retrieve the validator action.  */
040:            protected static String ACTION = "required";
041:
042:            /**
043:             * Constructor for the LocaleTest object
044:             *
045:             * @param name  param
046:             */
047:            public LocaleTest(String name) {
048:                super (name);
049:            }
050:
051:            /**
052:             * Start the tests.
053:             *
054:             * @param theArgs  the arguments. Not used
055:             */
056:            public static void main(String[] theArgs) {
057:                junit.awtui.TestRunner.main(new String[] { LocaleTest.class
058:                        .getName() });
059:            }
060:
061:            /**
062:             * @return   a test suite (<code>TestSuite</code>) that includes all methods
063:             *      starting with "test"
064:             */
065:            public static Test suite() {
066:                // All methods starting with "test" will be executed in the test suite.
067:                return new TestSuite(LocaleTest.class);
068:            }
069:
070:            /**
071:             * Load <code>ValidatorResources</code> from validator-locale.xml.
072:             *
073:             * @exception IOException   If something goes wrong
074:             * @exception SAXException  If something goes wrong
075:             */
076:            protected void setUp() throws IOException, SAXException {
077:                // Load resources
078:                loadResources("LocaleTest-config.xml");
079:            }
080:
081:            /** The teardown method for JUnit */
082:            protected void tearDown() {
083:            }
084:
085:            /**
086:             * See what happens when we try to validate with a Locale, Country and
087:             * variant. Also check if the added locale validation field is getting used.
088:             *
089:             * @exception ValidatorException  If something goes wrong
090:             */
091:            public void testLocale1() throws ValidatorException {
092:                // Create bean to run test on.
093:                NameBean name = new NameBean();
094:                name.setFirstName("");
095:                name.setLastName("");
096:
097:                valueTest(name, new Locale("en", "US", "TEST1"), false, false,
098:                        false);
099:            }
100:
101:            /**
102:             * See what happens when we try to validate with a Locale, Country and
103:             * variant
104:             *
105:             * @exception ValidatorException  If something goes wrong
106:             */
107:            public void testLocale2() throws ValidatorException {
108:                // Create bean to run test on.
109:                NameBean name = new NameBean();
110:                name.setFirstName("");
111:                name.setLastName("");
112:
113:                valueTest(name, new Locale("en", "US", "TEST2"), true, false,
114:                        true);
115:            }
116:
117:            /**
118:             * See what happens when we try to validate with a Locale, Country and
119:             * variant
120:             *
121:             * @exception ValidatorException  If something goes wrong
122:             */
123:            public void testLocale3() throws ValidatorException {
124:                // Create bean to run test on.
125:                NameBean name = new NameBean();
126:                name.setFirstName("");
127:                name.setLastName("");
128:
129:                valueTest(name, new Locale("en", "UK"), false, true, true);
130:            }
131:
132:            /**
133:             * See if a locale of en_UK_TEST falls back to en_UK instead of default form
134:             * set. Bug #16920 states that this isn't happening, even though it is
135:             * passing this test. see #16920.
136:             *
137:             * @exception ValidatorException  If something goes wrong
138:             */
139:            public void testLocale4() throws ValidatorException {
140:                // Create bean to run test on.
141:                NameBean name = new NameBean();
142:                name.setFirstName("");
143:                name.setLastName("");
144:
145:                valueTest(name, new Locale("en", "UK", "TEST"), false, true,
146:                        true);
147:            }
148:
149:            /**
150:             * See if a locale of language=en falls back to default form set.
151:             *
152:             * @exception ValidatorException  If something goes wrong
153:             */
154:            public void testLocale5() throws ValidatorException {
155:                // Create bean to run test on.
156:                NameBean name = new NameBean();
157:                name.setFirstName("");
158:                name.setLastName("");
159:
160:                valueTest(name, new Locale("en", ""), false, false, true);
161:            }
162:
163:            /**
164:             * Utlity class to run a test on a value.
165:             *
166:             * @param name                    param
167:             * @param loc                     param
168:             * @param firstGood               param
169:             * @param lastGood                param
170:             * @param middleGood              param
171:             * @exception ValidatorException  If something goes wrong
172:             */
173:            private void valueTest(Object name, Locale loc, boolean firstGood,
174:                    boolean lastGood, boolean middleGood)
175:                    throws ValidatorException {
176:
177:                // Construct validator based on the loaded resources
178:                // and the form key
179:                Validator validator = new Validator(resources, FORM_KEY);
180:                // add the name bean to the validator as a resource
181:                // for the validations to be performed on.
182:                validator.setParameter(Validator.BEAN_PARAM, name);
183:                validator.setParameter(Validator.LOCALE_PARAM, loc);
184:                // Get results of the validation.
185:                ValidatorResults results = null;
186:
187:                // throws ValidatorException,
188:                // but we aren't catching for testing
189:                // since no validation methods we use
190:                // throw this
191:                results = validator.validate();
192:
193:                assertNotNull("Results are null.", results);
194:
195:                ValidatorResult resultlast = results
196:                        .getValidatorResult("lastName");
197:                ValidatorResult resultfirst = results
198:                        .getValidatorResult("firstName");
199:                ValidatorResult resultmiddle = results
200:                        .getValidatorResult("middleName");
201:
202:                if (firstGood) {
203:                    assertNull(resultfirst);
204:                } else {
205:                    assertNotNull(resultfirst);
206:                }
207:
208:                if (middleGood) {
209:                    assertNull(resultmiddle);
210:                } else {
211:                    assertNotNull(resultmiddle);
212:                }
213:
214:                if (lastGood) {
215:                    assertNull(resultlast);
216:                } else {
217:                    assertNotNull(resultlast);
218:                }
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.