Source Code Cross Referenced for IntakeServiceTest.java in  » Web-Framework » TURBINE » org » apache » turbine » services » intake » 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 » TURBINE » org.apache.turbine.services.intake 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.intake;
002:
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:
022:        import java.util.Calendar;
023:        import java.util.Date;
024:
025:        import junit.framework.TestSuite;
026:
027:        import org.apache.turbine.services.ServiceManager;
028:        import org.apache.turbine.services.TurbineServices;
029:        import org.apache.turbine.services.intake.model.Field;
030:        import org.apache.turbine.services.intake.model.Group;
031:        import org.apache.turbine.services.intake.validator.BooleanValidator;
032:        import org.apache.turbine.services.intake.validator.DateRangeValidator;
033:        import org.apache.turbine.services.intake.validator.IntegerRangeValidator;
034:        import org.apache.turbine.test.BaseTurbineTest;
035:        import org.apache.turbine.util.parser.DefaultParameterParser;
036:        import org.apache.turbine.util.parser.ParameterParser;
037:
038:        public class IntakeServiceTest extends BaseTurbineTest {
039:
040:            Group booleanTestGroup = null;
041:            Group rangeTestGroup = null;
042:            Group integerRangeTestGroup = null;
043:            Group requiredFalseTestGroup = null;
044:            Group requiredTrueTestGroup = null;
045:
046:            public IntakeServiceTest(String name) throws Exception {
047:                super (name, "conf/test/TurbineResourcesWithIntake.properties");
048:
049:                ServiceManager serviceManager = TurbineServices.getInstance();
050:                IntakeService intakeService = (IntakeService) serviceManager
051:                        .getService(IntakeService.SERVICE_NAME);
052:                booleanTestGroup = intakeService.getGroup("BooleanTest");
053:                rangeTestGroup = intakeService.getGroup("DateRangeTest");
054:                integerRangeTestGroup = intakeService.getGroup("IntRangeTest");
055:                requiredFalseTestGroup = intakeService
056:                        .getGroup("RequiredFalseTest");
057:                requiredTrueTestGroup = intakeService
058:                        .getGroup("RequiredTrueTest");
059:            }
060:
061:            public void testEmptyBooleanField() throws IntakeException {
062:                Field booleanField = booleanTestGroup
063:                        .get("EmptyBooleanTestField");
064:                assertTrue(
065:                        "The Default Validator of an intake Field type boolean should be BooleanValidator",
066:                        (booleanField.getValidator() instanceof  BooleanValidator));
067:                assertFalse(
068:                        "An Empty intake Field type boolean should not be required",
069:                        booleanField.isRequired());
070:            }
071:
072:            public void testBooleanField() throws IntakeException {
073:                Field booleanField = booleanTestGroup.get("BooleanTestField");
074:                assertTrue(
075:                        "The Default Validator of an intake Field type boolean should be BooleanValidator",
076:                        (booleanField.getValidator() instanceof  BooleanValidator));
077:                assertFalse(
078:                        "An intake Field type boolean, which is not required, should not be required",
079:                        booleanField.isRequired());
080:            }
081:
082:            public void testRequiredBooleanField() throws IntakeException {
083:                Field booleanField = booleanTestGroup
084:                        .get("RequiredBooleanTestField");
085:                assertTrue(
086:                        "The Default Validator of an intake Field type boolean should be BooleanValidator",
087:                        (booleanField.getValidator() instanceof  BooleanValidator));
088:                assertTrue(
089:                        "An intake Field type boolean, which is required, should be required",
090:                        booleanField.isRequired());
091:            }
092:
093:            public void testDateRangeValidator() throws IntakeException {
094:                ParameterParser pp = new DefaultParameterParser();
095:                pp.add("rt_0dmin", "05/11/2007");
096:                pp.add("rt_0dmax", "05/12/2007");
097:                pp.add("rt_0dmax2", "05/11/2007");
098:                rangeTestGroup.init(Group.NEW, pp);
099:
100:                Field dmax = rangeTestGroup.get("DateMax");
101:                Field dmax2 = rangeTestGroup.get("DateMax2");
102:
103:                assertTrue(
104:                        "The Validator of the field DateMax should be a DateRangeValidator",
105:                        (dmax.getValidator() instanceof  DateRangeValidator));
106:                assertTrue("The date range should be valid", dmax.isValid());
107:                assertFalse("The date range should not be valid", dmax2
108:                        .isValid());
109:            }
110:
111:            public void testIntegerRangeValidator() throws IntakeException {
112:                ParameterParser pp = new DefaultParameterParser();
113:                pp.add("irt_0imin", "1");
114:                pp.add("irt_0imax", "3");
115:                pp.add("irt_0imax2", "2");
116:                integerRangeTestGroup.init(Group.NEW, pp);
117:
118:                Field imax = integerRangeTestGroup.get("IntMax");
119:                Field imax2 = integerRangeTestGroup.get("IntMax2");
120:
121:                assertTrue(
122:                        "The Validator of the field IntMax should be an IntegerRangeValidator",
123:                        (imax.getValidator() instanceof  IntegerRangeValidator));
124:                assertTrue("The integer range should be valid", imax.isValid());
125:                assertFalse("The integer range should not be valid", imax2
126:                        .isValid());
127:            }
128:
129:            /**
130:             * This test verifies that an intake field returns true for isSet() even
131:             * when an empty field is submitted.
132:             *
133:             * @throws IntakeException
134:             */
135:            public void testRequiredFalse() throws IntakeException {
136:                ParameterParser pp = new DefaultParameterParser();
137:                pp.add("rft_0stringrf", "");
138:                pp.add("rft_0integerrf", "");
139:                pp.add("rft_0intrf", "");
140:                pp.add("rft_0daterf", "");
141:                requiredFalseTestGroup.init(Group.NEW, pp);
142:
143:                Field stringRF = requiredFalseTestGroup.get("StringRF");
144:                Field integerRF = requiredFalseTestGroup.get("IntegerRF");
145:                Field intRF = requiredFalseTestGroup.get("IntRF");
146:                Field dateRF = requiredFalseTestGroup.get("DateRF");
147:
148:                assertTrue("StringRF should be set", stringRF.isSet());
149:                assertTrue("StringRF should be valid", stringRF.isValid());
150:                assertNull(stringRF.getValue());
151:                assertTrue("IntegerRF should be set", integerRF.isSet());
152:                assertTrue("IntegerRF should be valid", integerRF.isValid());
153:                assertNull(integerRF.getValue());
154:                assertTrue("IntRF should be set", intRF.isSet());
155:                assertTrue("IntRF should be valid", intRF.isValid());
156:                assertNull(intRF.getValue()); // zero?
157:                assertTrue("DateRF should be set", dateRF.isSet());
158:                assertTrue("DateRF should be valid", dateRF.isValid());
159:                assertNull(dateRF.getValue());
160:            }
161:
162:            /**
163:             * This test verify that an empty field can be used to clear existing
164:             * values.
165:             *
166:             * @throws IntakeException
167:             */
168:            public void testClearValues() throws IntakeException {
169:                RequiredFalseGroupTestObject rfgto = new RequiredFalseGroupTestObject();
170:                rfgto.setStringRF("originalString");
171:                rfgto.setIntegerRF(new Integer(5));
172:                rfgto.setIntRF(6);
173:                Date testDate = new Date();
174:                rfgto.setDateRF(testDate);
175:
176:                ParameterParser pp = new DefaultParameterParser();
177:                pp.add("rft_0stringrf", "");
178:                pp.add("rft_0integerrf", "");
179:                pp.add("rft_0intrf", "");
180:                pp.add("rft_0daterf", "");
181:                requiredFalseTestGroup.init(Group.NEW, pp);
182:
183:                requiredFalseTestGroup.setProperties(rfgto);
184:                assertNull("String value should have been cleared.", rfgto
185:                        .getStringRF());
186:                assertNull("Date value should have been cleared.", rfgto
187:                        .getDateRF());
188:                assertEquals("int value should have been cleared to zero.", 0,
189:                        rfgto.getIntRF());
190:
191:                // The following commented out test fails.
192:                // The trouble is that the use of reflection forces Intake to use Integer rather than int
193:                // when invoking the setter method on the object to which the group is being mapped.
194:
195:                //assertNull("Integer value should have been cleared to null, but instead it is "
196:                //        + rfgto.getIntegerRF(), rfgto.getIntegerRF());
197:
198:                // The net result is that Intake is currently not well suited to validating
199:                // Integer fields where a null value needs to be distinguished from a zero.
200:            }
201:
202:            /**
203:             * This test attempts to verify that with that valid values coming from
204:             * intake map through to an object correctly.
205:             *
206:             * @throws IntakeException
207:             */
208:            public void testSetValues() throws IntakeException {
209:                Calendar cal = Calendar.getInstance();
210:                cal.setTime(new Date());
211:                cal.set(Calendar.HOUR_OF_DAY, 0);
212:                cal.set(Calendar.MINUTE, 0);
213:                cal.set(Calendar.SECOND, 0);
214:                cal.set(Calendar.MILLISECOND, 0);
215:                Date testDate = cal.getTime();
216:                // This is in dd/mm/yyyy format, as defined in the intake.xml for this group.
217:                String testDateString = cal.get(Calendar.DAY_OF_MONTH) + "/"
218:                        + (cal.get(Calendar.MONTH) + 1) + "/"
219:                        + (cal.get(Calendar.YEAR));
220:
221:                ParameterParser pp = new DefaultParameterParser();
222:                pp.add("rft_0stringrf", "ABC"); // rules require 3 characters.
223:                pp.add("rft_0integerrf", new Integer(10));
224:                pp.add("rft_0intrf", 11);
225:                pp.add("rft_0daterf", testDateString);
226:                requiredFalseTestGroup.init(Group.NEW, pp);
227:
228:                Field stringRF = requiredFalseTestGroup.get("StringRF");
229:                Field integerRF = requiredFalseTestGroup.get("IntegerRF");
230:                Field intRF = requiredFalseTestGroup.get("IntRF");
231:                Field dateRF = requiredFalseTestGroup.get("DateRF");
232:
233:                assertTrue("StringRF should be set", stringRF.isSet());
234:                assertTrue("StringRF should be valid", stringRF.isValid());
235:                assertEquals("ABC", stringRF.getValue());
236:                assertTrue("IntegerRF should be set", integerRF.isSet());
237:                assertTrue("IntegerRF should be valid", integerRF.isValid());
238:                assertEquals(new Integer(10), integerRF.getValue());
239:                assertTrue("IntRF should be set", intRF.isSet());
240:                assertTrue("IntRF should be valid", intRF.isValid());
241:                assertEquals(11, ((Integer) intRF.getValue()).intValue());
242:                assertTrue("DateRF should be set", dateRF.isSet());
243:                assertTrue("DateRF should be valid", dateRF.isValid());
244:                assertEquals(testDate, dateRF.getValue());
245:
246:                RequiredFalseGroupTestObject rfgto = new RequiredFalseGroupTestObject();
247:                requiredFalseTestGroup.setProperties(rfgto);
248:                assertEquals("ABC", rfgto.getStringRF());
249:                assertEquals(new Integer(10), rfgto.getIntegerRF());
250:                assertEquals(11, rfgto.getIntRF());
251:                assertEquals(testDate, rfgto.getDateRF());
252:            }
253:
254:            /**
255:             * Test that a required field with no value assigned is invalid.
256:             *
257:             * @throws IntakeException
258:             */
259:            public void testRequiredTrue() throws IntakeException {
260:                ParameterParser pp = new DefaultParameterParser();
261:                pp.add("rtt_0stringrt", "");
262:                requiredTrueTestGroup.init(Group.NEW, pp);
263:
264:                Field stringRT = requiredTrueTestGroup.get("StringRT");
265:
266:                assertTrue("StringRT should be set", stringRT.isSet());
267:                assertFalse("StringRT should not be valid", stringRT.isValid());
268:                assertEquals("", stringRT.getValue());
269:            }
270:
271:            /**
272:             * This test verifies that a newly created group is not initiated in an
273:             * error state.
274:             *
275:             * @throws IntakeException
276:             */
277:            public void testInitialErrorState() throws IntakeException {
278:                ParameterParser pp = new DefaultParameterParser();
279:                requiredFalseTestGroup.init(Group.NEW, pp);
280:
281:                Field stringRF = requiredFalseTestGroup.get("StringRF");
282:                Field integerRF = requiredFalseTestGroup.get("IntegerRF");
283:                Field intRF = requiredFalseTestGroup.get("IntRF");
284:                Field dateRF = requiredFalseTestGroup.get("DateRF");
285:
286:                assertFalse("StringRF should not be set", stringRF.isSet());
287:                assertTrue("StringRF should be valid", stringRF.isValid());
288:                assertEquals("StringRF should have no messages.", "", stringRF
289:                        .getMessage());
290:                assertNull(stringRF.getValue());
291:                assertFalse("IntegerRF should not be set", integerRF.isSet());
292:                assertTrue("IntegerRF should be valid", integerRF.isValid());
293:                assertEquals("IntegerRF should have no messages", "", integerRF
294:                        .getMessage());
295:                assertNull(integerRF.getValue());
296:                assertFalse("IntRF should not be set", intRF.isSet());
297:                assertTrue("IntRF should be valid", intRF.isValid());
298:                assertEquals("IntRF should have no messages", "", intRF
299:                        .getMessage());
300:                assertNull(intRF.getValue());
301:                assertFalse("DateRF should not be set", dateRF.isSet());
302:                assertTrue("DateRF should be valid", dateRF.isValid());
303:                assertEquals("DateRF should have no messages", "", dateRF
304:                        .getMessage());
305:                assertNull(dateRF.getValue());
306:
307:                requiredTrueTestGroup.init(Group.NEW, pp);
308:                Field stringRT = requiredTrueTestGroup.get("StringRT");
309:
310:                assertFalse("StringRT should not be set", stringRT.isSet());
311:                assertTrue("StringRT should be valid", stringRT.isValid());
312:                assertEquals("StringRT should have no messages.", "", stringRT
313:                        .getMessage());
314:                assertNull(stringRT.getValue());
315:            }
316:
317:            /**
318:             * Factory method for creating a TestSuite for this class.
319:             *
320:             * @return the test suite
321:             */
322:            public static TestSuite suite() {
323:                TestSuite suite = new TestSuite(IntakeServiceTest.class);
324:                return suite;
325:            }
326:
327:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.