View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.travel;
17  
18  import org.kuali.rice.testtools.common.JiraAwareFailable;
19  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
20  import org.openqa.selenium.By;
21  import org.openqa.selenium.WebElement;
22  
23  /**
24   * Tests the Component section in Rice.
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public abstract class UifComponentValidationRegexPatternAftBase extends WebDriverLegacyITBase  {
29  
30      /**
31       * "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&readOnlyFields=field91"
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&readOnlyFields=field91";
34  
35      @Override
36      protected String getBookmarkUrl() {
37          return BOOKMARK_URL;
38      }
39  
40      protected void navigation() throws InterruptedException {
41          waitAndClickKRAD();
42          waitAndClickByXpath(KITCHEN_SINK_XPATH);
43          switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH);
44      }
45  
46      protected void testValidCharacterConstraintNav(JiraAwareFailable failable) throws Exception {
47          navigation();
48          testValidCharacterConstraint();
49          passed();
50      }
51  
52      protected void testValidCharacterConstraintBookmark(JiraAwareFailable failable) throws Exception {
53          testValidCharacterConstraint();
54          passed();
55      }
56  
57      protected void testValidCharacterConstraint() throws Exception {
58          waitAndClickByLinkText("Validation");
59          waitAndClickByLinkText("Validation - Regex");
60          waitAndClickById("UifCompView-Navigation4");
61  
62          //---------------------------------------------Fixed Point------------------------------//
63          assertInvalidValidFieldValues("field50", new String[]{"123.123", "1234.4", "1234.434"}, new String[]{"123.67"});
64  
65          //---------------------------------------------Floating Point------------------------------//
66          assertInvalidValidFieldValues("field51", new String[]{"127.", "1234()98"}, new String[]{"-123.67"});
67  
68          //---------------------------------------------Integer Pattern constraint------------------------------//
69          assertInvalidValidFieldValues("field77", new String[]{"127.", "1234.4123", "123E123"}, new String[]{"-123"});
70  
71          //---------------------------------------------Phone Text------------------------------//
72          assertInvalidValidFieldValues("field52", new String[]{"1271231234", "123-123-123", "12-12-123445", "1234-12-1234",
73                  "123.123.1234", "123-123-12345"}, new String[]{"123-123-1234"});
74  
75          //---------------------------------------------JavaClass Text------------------------------//
76          assertInvalidValidFieldValues("field53", new String[]{"127", "TestJava!@#Class", "Test JavaClass"}, new String[]{"TestJavaClass"});
77  
78          //---------------------------------------------Email Text------------------------------//
79          assertInvalidValidFieldValues("field54", new String[]{"123@123.123", "email.com@emailServer", "emailemailServer@.com"}, new String[]{"email@emailServer.com"});
80  
81          //---------------------------------------------URL pattern Text------------------------------//
82          assertInvalidValidFieldValues("field84", new String[]{"www.google.com", "https:www.google.com", "ftp://www.google.comsdfa123!#@",
83                  "ftp:/www.google.coms"}, new String[]{"ftp://www.google.com", "https://www.google.com", "http://www.google.com"});
84  
85          //---------------------------------------------Date pattern Text------------------------------//
86          assertInvalidValidFieldValues("field55", new String[]{"12/12/2112 12:12:87 am", "12-12-2112 12:12 am", "12-12-2112 12:12",
87                  "12/12/2112 12:12", "12-12-2112 12:12:78", "12 Sept", "Sept 12 12:12", "221299 12:12:13", "111222 12:12", "9/9/2012 12:12 am"},
88                  new String[]{"09/09/2012 12:12 pm", "090923", "Sept 12", "2034", "12/12/2012 23:12:59", "12-12-12 23:12:59", "121212 23:12:32",
89                          "Sept 12 23:45:50", "2011 12:23:32"});
90  
91  
92          //---------------------------------------------BasicDate pattern Text------------------------------//
93          assertInvalidValidFieldValues("field75", new String[]{"12122012", "13-12-34", "12:12:2034"}, new String[]{"12-12-2034"});
94  
95          //---------------------------------------------Time12H Pattern Text------------------------------//
96          assertInvalidValidFieldValues("field82", new String[]{"13:00:12", "09:00:", "3-00:12"}, new String[]{"3:00:34", "3:00"});
97  
98          //---------------------------------------------Time24H Pattern Text------------------------------//
99          assertInvalidValidFieldValues("field83", new String[]{"24:00:12", "14:00:", "13:00:76"}, new String[]{"13:00:23", "23:00:12"});
100 
101         //---------------------------------------------Timestamp pattern Text------------------------------//
102         assertInvalidValidFieldValues("field56", new String[]{"1000-12-12 12:12:12.103", "2000/12/12 12-12-12.87",
103                 "2000/12/12 12-12-12.87", "2011-08-12 12:12:12", /*"2999-12-12 12:12:12.103"*/ }, new String[]{"2099-12-12 12:12:12.103"});
104 
105         //---------------------------------------------Year Pattern Text------------------------------//
106         assertInvalidValidFieldValues("field57", new String[]{"1599", "2200",
107                 "20000", "-202"}, new String[]{"2000"});
108 
109         //---------------------------------------------Month Pattern Text------------------------------//
110         assertInvalidValidFieldValues("field58", new String[]{"0", "-12", "100"}, new String[]{"12"});
111 
112         //---------------------------------------------ZipCode Pattern Text------------------------------//
113         assertInvalidValidFieldValues("field61", new String[]{"123", "2341 12", "0-1231"}, new String[]{"12345"});
114 
115         //---------------------------------------------Alpha Numeric w/o options Text------------------------------//
116         assertInvalidValidFieldValues("field62", new String[]{"123 23 @#", "-asd123", "asd/123"}, new String[]{"asd123"});
117 
118         //---------------------------------------------Alpha Numeric with options Text------------------------------//
119         assertInvalidValidFieldValues("field63", new String[]{"123^we", "-123_asd", "123 23 @#"}, new String[]{"as_de 456/123"});
120 
121         //---------------------------------------------Alpha with Whitespace and commas Text------------------------------//
122         assertInvalidValidFieldValues("field64", new String[]{"123^we", "asd_pqr", "asd/def"}, new String[]{"asd ,pqr"});
123 
124         //---------------------------------------------AlphaPatterrn with disallowed charset Text------------------------------//
125         assertInvalidValidFieldValues("field76", new String[]{"123", "`abcd`", "|abcd|", "~abcd~"}, new String[]{" ab_c d_ef "});
126 
127         //---------------------------------------------Anything with No Whitespace Text------------------------------//
128         assertInvalidValidFieldValues("field65", new String[]{"123 ^we"}, new String[]{"123^we!@#^&*~:"});
129 
130         //---------------------------------------------CharacterSet Text------------------------------//
131         assertInvalidValidFieldValues("field66", new String[]{"123 ^we", "123_^we", "abc ABC"}, new String[]{"aAbBcC"});
132 
133         //---------------------------------------------Numeric Character Text------------------------------//
134         assertInvalidValidFieldValues("field67", new String[]{"123 ^we", "123/10", "(123.00)"}, new String[]{"(12-3)"});
135 
136         //---------------------------------------------Valid Chars Custom Text------------------------------//
137         assertInvalidValidFieldValues("field68", new String[]{ "123.123", "a.b", "123 qwe", "5.a", "a.0,b.4"}, new String[]{"a.0"});
138     }
139 
140     private boolean isErrorAttributeTrue(String fieldName) throws Exception {
141         Thread.sleep(500);
142         boolean valid = false;
143 
144         for (int second = 0; second < 5; second++) {
145             if ((valid = validateErrorAttribute(fieldName)) == true) {
146                 break;
147             }
148         }
149 
150         return valid;
151     }
152 
153     private boolean validateErrorAttribute(String fieldName) throws InterruptedException {
154         try {
155             WebElement field = findElement(By.name(fieldName));
156             return "true".equals(field.getAttribute("aria-invalid"));
157         } catch (Exception e) {
158             // don't fail here, we're in a loop let the caller decide when to fail
159         }
160 
161         Thread.sleep(1000);
162 
163         return false;
164     }
165 
166     private void assertInvalidValidFieldValues(String fieldNameToTest, String[] invalids, String[] valids) throws Exception {
167         for (String invalid : invalids) {
168             clearTextByName(fieldNameToTest);
169             waitAndTypeByName(fieldNameToTest, invalid);
170             fireEvent(fieldNameToTest, "blur");
171             if (!isErrorAttributeTrue(fieldNameToTest)) {
172                 jiraAwareFail(invalid + " expected to be invalid for field name " + fieldNameToTest);
173             }
174             clearTextByName(fieldNameToTest);
175         }
176 
177         for (String valid : valids) {
178             clearTextByName(fieldNameToTest);
179             waitAndTypeByName(fieldNameToTest, valid);
180             fireEvent(fieldNameToTest, "blur");
181             if (isErrorAttributeTrue(fieldNameToTest)) {
182                 jiraAwareFail(valid + " expected to be valid for field name " + fieldNameToTest);
183             }
184             clearTextByName(fieldNameToTest);
185         }
186     }
187 }