Source Code Cross Referenced for RetrieveFormTest.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.io.InputStream;
021:        import java.util.Locale;
022:        import junit.framework.Test;
023:        import junit.framework.TestCase;
024:        import junit.framework.TestSuite;
025:        import org.xml.sax.SAXException;
026:
027:        /**
028:         * Tests retrieving forms using different Locales.
029:         *
030:         * @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
031:         */
032:        public class RetrieveFormTest extends TestCase {
033:
034:            /**
035:             * Resources used for validation tests.
036:             */
037:            private ValidatorResources resources = null;
038:
039:            /**
040:             * Prefix for the forms.
041:             */
042:            private static final String FORM_PREFIX = "testForm_";
043:
044:            /**
045:             * Prefix for the forms.
046:             */
047:            private static final Locale CANADA_FRENCH_XXX = new Locale("fr",
048:                    "CA", "XXX");
049:
050:            /**
051:             * @return a test suite (<code>TestSuite</code>) that includes all methods
052:             *         starting with "test"
053:             */
054:            public static Test suite() {
055:                // All methods starting with "test" will be executed in the test suite.
056:                return new TestSuite(RetrieveFormTest.class);
057:            }
058:
059:            /**
060:             * Constructor for FormTest.
061:             * @param name
062:             */
063:            public RetrieveFormTest(String name) {
064:                super (name);
065:            }
066:
067:            /** 
068:             * Load <code>ValidatorResources</code> from multiple xml files.
069:             */
070:            protected void setUp() throws IOException, SAXException {
071:                InputStream[] streams = new InputStream[] { this .getClass()
072:                        .getResourceAsStream("RetrieveFormTest-config.xml") };
073:
074:                this .resources = new ValidatorResources(streams);
075:
076:                for (int i = 0; i < streams.length; i++) {
077:                    streams[i].close();
078:                }
079:            }
080:
081:            /**
082:             * Test a form defined only in the "default" formset.
083:             */
084:            public void testDefaultForm() throws ValidatorException {
085:
086:                String formKey = FORM_PREFIX + "default";
087:
088:                // *** US locale ***
089:                checkForm(Locale.US, formKey, "default");
090:
091:                // *** French locale ***
092:                checkForm(Locale.FRENCH, formKey, "default");
093:
094:                // *** France locale ***
095:                checkForm(Locale.FRANCE, formKey, "default");
096:
097:                // *** Candian (English) locale ***
098:                checkForm(Locale.CANADA, formKey, "default");
099:
100:                // *** Candian French locale ***
101:                checkForm(Locale.CANADA_FRENCH, formKey, "default");
102:
103:                // *** Candian French Variant locale ***
104:                checkForm(CANADA_FRENCH_XXX, formKey, "default");
105:
106:            }
107:
108:            /**
109:             * Test a form defined in the "default" formset and formsets
110:             * where just the "language" is specified.
111:             */
112:            public void testLanguageForm() throws ValidatorException {
113:
114:                String formKey = FORM_PREFIX + "language";
115:
116:                // *** US locale ***
117:                checkForm(Locale.US, formKey, "default");
118:
119:                // *** French locale ***
120:                checkForm(Locale.FRENCH, formKey, "fr");
121:
122:                // *** France locale ***
123:                checkForm(Locale.FRANCE, formKey, "fr");
124:
125:                // *** Candian (English) locale ***
126:                checkForm(Locale.CANADA, formKey, "default");
127:
128:                // *** Candian French locale ***
129:                checkForm(Locale.CANADA_FRENCH, formKey, "fr");
130:
131:                // *** Candian French Variant locale ***
132:                checkForm(CANADA_FRENCH_XXX, formKey, "fr");
133:
134:            }
135:
136:            /**
137:             * Test a form defined in the "default" formset, formsets
138:             * where just the "language" is specified and formset where
139:             * the language and country are specified.
140:             */
141:            public void testLanguageCountryForm() throws ValidatorException {
142:
143:                String formKey = FORM_PREFIX + "language_country";
144:
145:                // *** US locale ***
146:                checkForm(Locale.US, formKey, "default");
147:
148:                // *** French locale ***
149:                checkForm(Locale.FRENCH, formKey, "fr");
150:
151:                // *** France locale ***
152:                checkForm(Locale.FRANCE, formKey, "fr_FR");
153:
154:                // *** Candian (English) locale ***
155:                checkForm(Locale.CANADA, formKey, "default");
156:
157:                // *** Candian French locale ***
158:                checkForm(Locale.CANADA_FRENCH, formKey, "fr_CA");
159:
160:                // *** Candian French Variant locale ***
161:                checkForm(CANADA_FRENCH_XXX, formKey, "fr_CA");
162:
163:            }
164:
165:            /**
166:             * Test a form defined in all the formsets
167:             */
168:            public void testLanguageCountryVariantForm()
169:                    throws ValidatorException {
170:
171:                String formKey = FORM_PREFIX + "language_country_variant";
172:
173:                // *** US locale ***
174:                checkForm(Locale.US, formKey, "default");
175:
176:                // *** French locale ***
177:                checkForm(Locale.FRENCH, formKey, "fr");
178:
179:                // *** France locale ***
180:                checkForm(Locale.FRANCE, formKey, "fr_FR");
181:
182:                // *** Candian (English) locale ***
183:                checkForm(Locale.CANADA, formKey, "default");
184:
185:                // *** Candian French locale ***
186:                checkForm(Locale.CANADA_FRENCH, formKey, "fr_CA");
187:
188:                // *** Candian French Variant locale ***
189:                checkForm(CANADA_FRENCH_XXX, formKey, "fr_CA_XXX");
190:
191:            }
192:
193:            /**
194:             * Test a form not defined
195:             */
196:            public void testFormNotFound() throws ValidatorException {
197:
198:                String formKey = "INVALID_NAME";
199:
200:                // *** US locale ***
201:                checkFormNotFound(Locale.US, formKey);
202:
203:                // *** French locale ***
204:                checkFormNotFound(Locale.FRENCH, formKey);
205:
206:                // *** France locale ***
207:                checkFormNotFound(Locale.FRANCE, formKey);
208:
209:                // *** Candian (English) locale ***
210:                checkFormNotFound(Locale.CANADA, formKey);
211:
212:                // *** Candian French locale ***
213:                checkFormNotFound(Locale.CANADA_FRENCH, formKey);
214:
215:                // *** Candian French Variant locale ***
216:                checkFormNotFound(CANADA_FRENCH_XXX, formKey);
217:
218:            }
219:
220:            private void checkForm(Locale locale, String formKey,
221:                    String expectedVarValue) {
222:
223:                // Retrieve the Form
224:                Form testForm = resources.getForm(locale, formKey);
225:                assertNotNull("Form '" + formKey + "' null for locale "
226:                        + locale, testForm);
227:
228:                // Validate the expected Form is retrieved by checking the "localeVar"
229:                // value of the field.
230:                Field testField = (Field) testForm.getField("testProperty");
231:                assertEquals("Incorrect Form '" + formKey + "' for locale '"
232:                        + locale + "'", expectedVarValue, testField
233:                        .getVarValue("localeVar"));
234:            }
235:
236:            private void checkFormNotFound(Locale locale, String formKey) {
237:
238:                // Retrieve the Form
239:                Form testForm = resources.getForm(locale, formKey);
240:                assertNull("Form '" + formKey + "' not null for locale "
241:                        + locale, testForm);
242:
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.