001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package edu.samplu.travel.krad.test;
017    
018    import edu.samplu.common.UpgradedSeleniumITBase;
019    import org.junit.Assert;
020    import org.junit.Test;
021    
022    /**
023     * tests that regex validation works as expected on input fields where it is configured
024     * 
025     * @author Kuali Rice Team (rice.collab@kuali.org)
026     */
027    public class UIFComponentValidationRegexPatternIT extends UpgradedSeleniumITBase {
028        
029        @Override
030        public String getTestUrl() {
031            return "/kr-krad/uicomponents?viewId=UifCompView_KNS&methodToCall=start&readOnlyFields=field91";
032        }
033    
034        @Test
035        public void testValidCharacterConstraint() throws Exception {
036    
037            /*
038             *  Timestamp pattern validation message says it allows years from 1900 - 2099 
039             *  In fact it also allows 2999 as the upper limit. This needs to be sorted out.
040             *  Test failing this condition is commented in the below code section for Timestamp Validation. Once resolved can be uncommented  
041             *  
042             */
043         
044            waitAndClick("//a[contains(text(),'Validation - Regex')]");
045    
046            //---------------------------------------------Fixed Point------------------------------//
047    
048           
049            waitAndType("name=field50", "123.123");
050            fireEvent("name=field50", "blur");
051            validateErrorImage(true);
052    
053            waitAndType("//input[@name='field50']", "1234.4");
054            fireEvent("name=field50", "blur");
055            validateErrorImage(true);
056    
057         
058            waitAndType("//input[@name='field50']", "1234.434");
059            fireEvent("name=field50", "blur");
060            validateErrorImage(true);
061    
062            waitAndType("//input[@name='field50']", "123.67");
063            fireEvent("name=field50", "blur");
064            validateErrorImage(false);
065    
066            //---------------------------------------------Floating Point------------------------------//
067           
068            waitAndType("//input[@name='field51']", "127.");
069            fireEvent("//input[@name='field51']", "blur");
070            validateErrorImage(true);
071             
072            waitAndType("//input[@name='field51']", "1234()98");
073            fireEvent("//input[@name='field51']", "blur");
074            validateErrorImage(true);
075            
076            waitAndType("//input[@name='field51']", "-123.67");
077            fireEvent("//input[@name='field51']", "blur");
078            validateErrorImage(false);
079    
080            //---------------------------------------------Integer Pattern constraint------------------------------//
081            
082            waitAndType("//input[@name='field77']", "127.");
083            fireEvent("//input[@name='field77']", "blur");
084            validateErrorImage(true);
085    
086            waitAndType("//input[@name='field77']", "1234.4123");
087            fireEvent("//input[@name='field77']", "blur");
088            validateErrorImage(true);
089    
090            waitAndType("//input[@name='field77']", "123E123");
091            fireEvent("//input[@name='field77']", "blur");
092            validateErrorImage(true);
093    
094            waitAndType("//input[@name='field77']", "-123");
095            fireEvent("//input[@name='field77']", "blur");
096            validateErrorImage(false);
097    
098            //---------------------------------------------Phone Text------------------------------//
099            waitAndType("//input[@name='field52']", "1271231234");
100            fireEvent("//input[@name='field52']", "blur");
101            validateErrorImage(true);
102    
103            waitAndType("//input[@name='field52']", "123-123-123");
104            fireEvent("//input[@name='field52']", "blur");
105            validateErrorImage(true);
106    
107            waitAndType("//input[@name='field52']", "12-12-123445");
108            fireEvent("//input[@name='field52']", "blur");
109            validateErrorImage(true);
110    
111            waitAndType("//input[@name='field52']", "1234-12-1234");
112            fireEvent("//input[@name='field52']", "blur");
113            validateErrorImage(true);
114    
115            waitAndType("//input[@name='field52']", "123.123.1234");
116            fireEvent("//input[@name='field52']", "blur");
117            validateErrorImage(true);
118    
119            waitAndType("//input[@name='field52']", "123-123-12345");
120            fireEvent("//input[@name='field52']", "blur");
121            validateErrorImage(true);
122    
123            waitAndType("//input[@name='field52']", "123-123-1234");
124            fireEvent("//input[@name='field52']", "blur");
125            validateErrorImage(false);
126    
127            //---------------------------------------------JavaClass Text------------------------------//
128            waitAndType("//input[@name='field53']", "127");
129            fireEvent("//input[@name='field53']", "blur");
130            validateErrorImage(true);
131    
132            waitAndType("//input[@name='field53']", "TestJava!@#Class");
133            fireEvent("//input[@name='field53']", "blur");
134            validateErrorImage(true);
135    
136            waitAndType("//input[@name='field53']", "Test JavaClass");
137            fireEvent("//input[@name='field53']", "blur");
138            validateErrorImage(true);
139    
140            waitAndType("//input[@name='field53']", "Test JavaClass");
141            fireEvent("//input[@name='field53']", "blur");
142            validateErrorImage(true);
143    
144            waitAndType("//input[@name='field53']", "TestJavaClass");
145            fireEvent("//input[@name='field53']", "blur");
146            validateErrorImage(false);
147    
148            //---------------------------------------------Email Text------------------------------//
149            waitAndType("//input[@name='field54']", "123@123.123");
150            fireEvent("//input[@name='field54']", "blur");
151            validateErrorImage(true);
152    
153            waitAndType("//input[@name='field54']", "email.com@emailServer");
154            fireEvent("//input[@name='field54']", "blur");
155            validateErrorImage(true);
156    
157            waitAndType("//input[@name='field54']", "emailemailServer@.com");
158            fireEvent("//input[@name='field54']", "blur");
159            validateErrorImage(true);
160    
161            waitAndType("//input[@name='field54']", "email@emailServercom");
162            fireEvent("//input[@name='field54']", "blur");
163            validateErrorImage(true);
164    
165            waitAndType("//input[@name='field54']", "email@emailServer.com");
166            fireEvent("//input[@name='field54']", "blur");
167            validateErrorImage(false);
168    
169            //---------------------------------------------URL pattern Text------------------------------//
170            waitAndType("//input[@name='field84']", "www.google.com");
171            fireEvent("//input[@name='field84']", "blur");
172            validateErrorImage(true);
173    
174            waitAndType("//input[@name='field84']", "https:www.google.com");
175            fireEvent("//input[@name='field84']", "blur");
176            validateErrorImage(true);
177    
178            waitAndType("//input[@name='field84']", "ftp://www.google.comsdfa123!#@");
179            fireEvent("//input[@name='field84']", "blur");
180            validateErrorImage(true);
181    
182            waitAndType("//input[@name='field84']", "ftp:/www.google.coms");
183            fireEvent("//input[@name='field84']", "blur");
184            validateErrorImage(true);
185    
186            waitAndType("//input[@name='field84']", "ftp://www.google.com");
187            fireEvent("//input[@name='field84']", "blur");
188            validateErrorImage(false);
189    
190            waitAndType("//input[@name='field84']", "https://www.google.com");
191            fireEvent("//input[@name='field84']", "blur");
192            validateErrorImage(false);
193    
194            waitAndType("//input[@name='field84']", "http://www.google.com");
195            fireEvent("//input[@name='field84']", "blur");
196            validateErrorImage(false);
197           
198    
199            //---------------------------------------------Date pattern Text------------------------------//
200            //-------------invalid formats
201            waitAndType("//input[@name='field55']", "12/12/2112 12:12:87 am");
202            fireEvent("//input[@name='field55']", "blur");
203            validateErrorImage(true);
204    
205            waitAndType("//input[@name='field55']", "12-12-2112 12:12 am");
206            fireEvent("//input[@name='field55']", "blur");
207            validateErrorImage(true);
208    
209            waitAndType("//input[@name='field55']", "12-12-2112 12:12");
210            fireEvent("//input[@name='field55']", "blur");
211            validateErrorImage(true);
212    
213            waitAndType("//input[@name='field55']", "12/12/2112 12:12");
214            fireEvent("//input[@name='field55']", "blur");
215            validateErrorImage(true);
216    
217            waitAndType("//input[@name='field55']", "12-12-2112 12:12:78");
218            fireEvent("//input[@name='field55']", "blur");
219            validateErrorImage(true);
220    
221            waitAndType("//input[@name='field55']", "12 Sept");
222            fireEvent("//input[@name='field55']", "blur");
223            validateErrorImage(true);
224    
225            waitAndType("//input[@name='field55']", "Sept 12 12:12");
226            fireEvent("//input[@name='field55']", "blur");
227            validateErrorImage(true);
228    
229            waitAndType("//input[@name='field55']", "221299 12:12:13");
230            fireEvent("//input[@name='field55']", "blur");
231            validateErrorImage(true);
232    
233            waitAndType("//input[@name='field55']", "111222 12:12");
234            fireEvent("//input[@name='field55']", "blur");
235            validateErrorImage(true);
236    
237            waitAndType("//input[@name='field55']", "9/9/2012 12:12 am");
238            fireEvent("//input[@name='field55']", "blur");
239            validateErrorImage(true);
240    
241            //-------------valid formats      
242            waitAndType("//input[@name='field55']", "09/09/2012 12:12 pm");
243            fireEvent("//input[@name='field55']", "blur");
244            validateErrorImage(false);
245    
246            waitAndType("//input[@name='field55']", "090923");
247            fireEvent("//input[@name='field55']", "blur");
248            validateErrorImage(false);
249            
250            
251            waitAndType("//input[@name='field55']", "Sept 12");
252            fireEvent("//input[@name='field55']", "blur");
253            validateErrorImage(false);
254            
255            waitAndType("//input[@name='field55']", "2034");
256            fireEvent("//input[@name='field55']", "blur");
257            validateErrorImage(false);
258    
259            waitAndType("//input[@name='field55']", "12/12/2012 23:12:59");
260            fireEvent("//input[@name='field55']", "blur");
261            validateErrorImage(false);
262            
263            waitAndType("//input[@name='field55']", "12-12-12 23:12:59");
264            fireEvent("//input[@name='field55']", "blur");
265            validateErrorImage(false);
266            
267            waitAndType("//input[@name='field55']", "121212 23:12:32");
268            fireEvent("//input[@name='field55']", "blur");
269            validateErrorImage(false);
270            
271            waitAndType("//input[@name='field55']", "Sept 12 23:45:50");
272            fireEvent("//input[@name='field55']", "blur");
273            validateErrorImage(false);
274    
275            waitAndType("//input[@name='field55']", "2011 12:23:32");
276            fireEvent("//input[@name='field55']", "blur");
277            validateErrorImage(false);
278            
279            //---------------------------------------------BasicDate pattern Text------------------------------//
280            waitAndType("//input[@name='field75']", "12122012");
281            fireEvent("//input[@name='field75']", "blur");
282            validateErrorImage(true);
283            
284            waitAndType("//input[@name='field75']", "13-12-34");
285            fireEvent("//input[@name='field75']", "blur");
286            validateErrorImage(true);
287    
288            waitAndType("//input[@name='field75']", "12:12:2034");
289            fireEvent("//input[@name='field75']", "blur");
290            validateErrorImage(true);
291    
292            waitAndType("//input[@name='field75']", "12-12-2034");
293            fireEvent("//input[@name='field75']", "blur");
294            validateErrorImage(false);
295     
296            //---------------------------------------------Time12H Pattern Text------------------------------//
297            waitAndType("//input[@name='field82']", "13:00:12");
298            fireEvent("//input[@name='field82']", "blur");
299            validateErrorImage(true);
300    
301            waitAndType("//input[@name='field82']", "09:00:");
302            fireEvent("//input[@name='field82']", "blur");
303            validateErrorImage(true);
304    
305            waitAndType("//input[@name='field82']", "3-00:12");
306            fireEvent("//input[@name='field82']", "blur");
307            validateErrorImage(true);
308            
309            waitAndType("//input[@name='field82']", "3:00:34");
310            fireEvent("//input[@name='field82']", "blur");
311            validateErrorImage(false);
312    
313            waitAndType("//input[@name='field82']", "3:00");
314            fireEvent("//input[@name='field82']", "blur");
315            validateErrorImage(false);
316    
317            //---------------------------------------------Time24H Pattern Text------------------------------//
318            waitAndType("//input[@name='field83']", "24:00:12");
319            fireEvent("//input[@name='field83']", "blur");
320            validateErrorImage(true);
321    
322            waitAndType("//input[@name='field83']", "14:00:");
323            fireEvent("//input[@name='field83']", "blur");
324            validateErrorImage(true);
325            
326            waitAndType("//input[@name='field83']", "13:00:76");
327            fireEvent("//input[@name='field83']", "blur");
328            validateErrorImage(true);
329    
330            waitAndType("//input[@name='field83']", "13:00:23");
331            fireEvent("//input[@name='field83']", "blur");
332            validateErrorImage(false);
333    
334            waitAndType("//input[@name='field83']", "23:00:12");
335            fireEvent("//input[@name='field83']", "blur");
336            validateErrorImage(false);
337    
338            //---------------------------------------------Timestamp pattern Text------------------------------//
339            waitAndType("//input[@name='field56']", "1000-12-12 12:12:12.103");
340            fireEvent("//input[@name='field56']", "blur");
341            validateErrorImage(true);
342    
343            waitAndType("//input[@name='field56']", "2000/12/12 12-12-12.87");
344            fireEvent("//input[@name='field56']", "blur");
345            validateErrorImage(true);
346    
347            waitAndType("//input[@name='field56']", "2000/12/12 12-12-12.87");
348            fireEvent("//input[@name='field56']", "blur");
349            validateErrorImage(true);
350    
351            waitAndType("//input[@name='field56']", "2011-08-12 12:12:12");
352            fireEvent("//input[@name='field56']", "blur");
353            validateErrorImage(true);
354    
355            //--------this should not be allowed
356            /*
357            clearTimeStampText();
358            waitAndType("//input[@name='field56']", "2999-12-12 12:12:12.103");
359            focus("//input[@name='field57']");
360            Thread.sleep(100);
361            assertTrue(isTextPresent("Must be a date/time in the format of yyyy-mm-dd hh:mm:ss.ms, between the years of 1900 and 2099, inclusive. \"ms\" represents milliseconds, and must be included."));
362            
363            */
364            waitAndType("//input[@name='field56']", "2099-12-12 12:12:12.103");
365            fireEvent("//input[@name='field56']", "blur");
366            validateErrorImage(false);
367    
368            //---------------------------------------------Year Pattern Text------------------------------//
369            waitAndType("//input[@name='field57']", "1599");
370            fireEvent("//input[@name='field57']", "blur");
371            validateErrorImage(true);
372    
373            waitAndType("//input[@name='field57']", "2200");
374            fireEvent("//input[@name='field57']", "blur");
375            validateErrorImage(true);
376    
377            waitAndType("//input[@name='field57']", "20000");
378            fireEvent("//input[@name='field57']", "blur");
379            validateErrorImage(true);
380    
381            waitAndType("//input[@name='field57']", "-202");
382            fireEvent("//input[@name='field57']", "blur");
383            validateErrorImage(true);
384    
385            waitAndType("//input[@name='field57']", "2000");
386            fireEvent("//input[@name='field57']", "blur");
387            validateErrorImage(false);
388    
389            //---------------------------------------------Month Pattern Text------------------------------//
390            waitAndType("//input[@name='field58']", "0");
391            fireEvent("//input[@name='field58']", "blur");
392            validateErrorImage(true);
393    
394            waitAndType("//input[@name='field58']", "-12");
395            fireEvent("//input[@name='field58']", "blur");
396            validateErrorImage(true);
397    
398            waitAndType("//input[@name='field58']", "100");
399            fireEvent("//input[@name='field58']", "blur");
400            validateErrorImage(true);
401    
402            waitAndType("//input[@name='field58']", "12");
403            fireEvent("//input[@name='field58']", "blur");
404            validateErrorImage(false);
405    
406            //---------------------------------------------ZipCode Pattern Text------------------------------//
407    
408            waitAndType("//input[@name='field61']", "123");
409            fireEvent("//input[@name='field61']", "blur");
410            validateErrorImage(true);
411    
412            waitAndType("//input[@name='field61']", "2341 12");
413            fireEvent("//input[@name='field61']", "blur");
414            validateErrorImage(true);
415    
416            waitAndType("//input[@name='field61']", "0-1231");
417            fireEvent("//input[@name='field61']", "blur");
418            validateErrorImage(true);
419    
420            waitAndType("//input[@name='field61']", "12345");
421            fireEvent("//input[@name='field61']", "blur");
422            validateErrorImage(false);
423    
424            //---------------------------------------------Alpha Numeric w/o options Text------------------------------//
425            waitAndType("//input[@name='field62']", "123 23 @#");
426            fireEvent("//input[@name='field62']", "blur");
427            validateErrorImage(true);
428    
429            waitAndType("//input[@name='field62']", "-asd123");
430            fireEvent("//input[@name='field62']", "blur");
431            validateErrorImage(true);
432    
433            waitAndType("//input[@name='field62']", "asd/123");
434            fireEvent("//input[@name='field62']", "blur");
435            validateErrorImage(true);
436    
437            waitAndType("//input[@name='field62']", "asd123");
438            fireEvent("//input[@name='field62']", "blur");
439            validateErrorImage(false);
440    
441            //---------------------------------------------Alpha Numeric with options Text------------------------------//
442            waitAndType("//input[@name='field63']", "123^we");
443            fireEvent("//input[@name='field63']", "blur");
444            validateErrorImage(true);
445    
446            waitAndType("//input[@name='field63']", "-123_asd");
447            fireEvent("//input[@name='field63']", "blur");
448            validateErrorImage(true);
449            
450            waitAndType("//input[@name='field63']", "123 23 @#");
451            fireEvent("//input[@name='field63']", "blur");
452    
453            waitAndType("//input[@name='field63']", "as_de 456/123");
454            fireEvent("//input[@name='field63']", "blur");
455            validateErrorImage(false);
456    
457            //---------------------------------------------Alpha with Whitespace and commas Text------------------------------//
458            waitAndType("//input[@name='field64']", "123^we");
459            fireEvent("//input[@name='field64']", "blur");
460            validateErrorImage(true);
461    
462            waitAndType("//input[@name='field64']", "asd_pqr");
463            fireEvent("//input[@name='field64']", "blur");
464            validateErrorImage(true);
465    
466            waitAndType("//input[@name='field64']", "asd/def");
467            fireEvent("//input[@name='field64']", "blur");
468            validateErrorImage(true);
469    
470            waitAndType("//input[@name='field64']", "asd ,pqr");
471            fireEvent("//input[@name='field64']", "blur");
472            validateErrorImage(false);
473    
474            //---------------------------------------------AlphaPatterrn with disallowed charset Text------------------------------//
475            waitAndType("//input[@name='field76']", "123");
476            fireEvent("//input[@name='field76']", "blur");
477            validateErrorImage(true);
478    
479            waitAndType("//input[@name='field76']", "`abcd`");
480            fireEvent("//input[@name='field76']", "blur");
481            validateErrorImage(true);
482    
483            waitAndType("//input[@name='field76']", "|abcd|");
484            fireEvent("//input[@name='field76']", "blur");
485            validateErrorImage(true);
486    
487            waitAndType("//input[@name='field76']", "~abcd~");
488            fireEvent("//input[@name='field76']", "blur");
489            validateErrorImage(true);
490    
491            waitAndType("//input[@name='field76']", " ab_c d_ef ");
492            fireEvent("//input[@name='field76']", "blur");
493            validateErrorImage(false);
494    
495            //---------------------------------------------Anything with No Whitespace Text------------------------------//
496            waitAndType("//input[@name='field65']", "123 ^we");
497            fireEvent("//input[@name='field65']", "blur");
498            validateErrorImage(true);
499    
500            waitAndType("//input[@name='field65']", "123^we!@#^&*~:");
501            fireEvent("//input[@name='field65']", "blur");
502            validateErrorImage(false);
503            
504            //---------------------------------------------CharacterSet Text------------------------------//
505            waitAndType("//input[@name='field66']", "123 ^we");
506            fireEvent("//input[@name='field66']", "blur");
507            validateErrorImage(true);
508            
509            waitAndType("//input[@name='field66']", "123_^we");
510            fireEvent("//input[@name='field66']", "blur");
511            validateErrorImage(true);
512            
513            waitAndType("//input[@name='field66']", "abc ABC");
514            fireEvent("//input[@name='field66']", "blur");
515            validateErrorImage(true);
516            
517            waitAndType("//input[@name='field66']", "aAbBcC");
518            fireEvent("//input[@name='field66']", "blur");
519            validateErrorImage(false);
520            
521            //---------------------------------------------Numeric Character Text------------------------------//
522            waitAndType("//input[@name='field67']", "123 ^we");
523            fireEvent("//input[@name='field67']", "blur");
524            validateErrorImage(true);
525            
526            waitAndType("//input[@name='field67']", "123/10");
527            fireEvent("//input[@name='field67']", "blur");
528            validateErrorImage(true);
529            
530            waitAndType("//input[@name='field67']", "(123.00)");
531            fireEvent("//input[@name='field67']", "blur");
532            validateErrorImage(true);
533            
534            waitAndType("//input[@name='field67']", "(12-3)");
535            fireEvent("//input[@name='field67']", "blur");
536            validateErrorImage(false);
537            
538            //---------------------------------------------Valid Chars Custom Text------------------------------//
539            waitAndType("//input[@name='field68']", "123.123");
540            fireEvent("//input[@name='field68']", "blur");
541            validateErrorImage(true);
542            
543            waitAndType("//input[@name='field68']", "a.b");
544            fireEvent("//input[@name='field68']", "blur");
545            validateErrorImage(true);
546            
547            waitAndType("//input[@name='field68']", "123 qwe");
548            fireEvent("//input[@name='field68']", "blur");
549            validateErrorImage(true);
550            
551            waitAndType("//input[@name='field68']", "5.a");
552            fireEvent("//input[@name='field68']", "blur");
553            validateErrorImage(true);
554            
555            waitAndType("//input[@name='field68']", "a.0,b.4");
556            fireEvent("//input[@name='field68']", "blur");
557            validateErrorImage(true);
558            
559            waitAndType("//input[@name='field68']", "a.0");
560            fireEvent("//input[@name='field68']", "blur");
561            validateErrorImage(false);
562            
563        }
564            
565        public void validateErrorImage(boolean validateVisible) throws Exception {
566            Thread.sleep(500);
567            for (int second = 0;; second++) {
568                if (second >= 5)
569                    Assert.fail("timeout");
570                try {
571                    if (validateVisible) {
572                        
573                        if (isVisible("css=img.uif-validationImage"));
574                            break;
575                    } else {
576                        
577                        if (! isVisible("css=img.uif-validationImage"))
578                            break;
579                    }
580    
581                } catch (Exception e) {}
582                Thread.sleep(1000);
583            }
584            if (validateVisible) {
585                Assert.assertTrue(isVisible("css=img.uif-validationImage"));
586            } else {
587                Assert.assertTrue(! isVisible("css=img.uif-validationImage"));
588            }        
589        }
590    }