1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.labs.kitchensink;
17
18 import org.junit.Test;
19 import org.openqa.selenium.By;
20 import org.openqa.selenium.WebElement;
21
22
23
24
25 public class LabsValidationRegexAft extends LabsKitchenSinkBase {
26
27
28
29
30 public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&pageId=UifCompView-Page4#UifCompView-Page4";
31
32 @Override
33 protected String getBookmarkUrl() {
34 return BOOKMARK_URL;
35 }
36
37 @Override
38 protected void navigate() throws Exception {
39 navigateToKitchenSink("Validation - Regex");
40 }
41
42 @Test
43 public void testValidationRegexBookmark() throws Exception {
44 testValidationRegex();
45 passed();
46 }
47
48 @Test
49 public void testValidationRegexNav() throws Exception {
50 testValidationRegex();
51 passed();
52 }
53
54 protected void testValidationRegex() throws Exception {
55 testValidationRegex_FixedPoint();
56 testValidationRegex_FloatingPoint();
57 testValidationRegex_Integer();
58 testValidationRegex_PhoneNumber();
59 testValidationRegex_JavaClass();
60 testValidationRegex_EmailAddress();
61 testValidationRegex_Url();
62 testValidationRegex_Date();
63 testValidationRegex_DateBasic();
64 testValidationRegex_Time();
65 testValidationRegex_Time24H();
66 testValidationRegex_Timestamp();
67 testValidationRegex_Year();
68 testValidationRegex_Month();
69 testValidationRegex_ZipCode();
70 testValidationRegex_AlphaNumeric();
71 testValidationRegex_AlphaNumericOptions();
72 testValidationRegex_AlphaWhitespaceCommas();
73 testValidationRegex_AlphaAllAllowable();
74 testValidationRegex_NoWhitespace();
75 testValidationRegex_Charset();
76 testValidationRegex_Numeric();
77 testValidationRegex_Custom();
78 }
79
80 protected void testValidationRegex_FixedPoint() throws Exception {
81 assertFocusTypeBlurError("field50","1qqqqq.qqqqqq");
82 assertInvalidValidFieldValues("field50", new String[]{"123.123", "1234.4", "1234.434"}, new String[]{"123.67"});
83 }
84
85 protected void testValidationRegex_FloatingPoint() throws Exception {
86 assertFocusTypeBlurError("field51","-1.0E");
87 assertInvalidValidFieldValues("field51", new String[]{"127.", "1234()98"}, new String[]{"-123.67"});
88 }
89
90 protected void testValidationRegex_Integer() throws Exception {
91 assertFocusTypeBlurError("field77","1.2");
92 assertInvalidValidFieldValues("field77", new String[]{"127.", "1234.4123", "123E123"}, new String[]{"-123"});
93 }
94
95 protected void testValidationRegex_PhoneNumber() throws Exception {
96 assertFocusTypeBlurError("field52","asddffgghj");
97 assertInvalidValidFieldValues("field52",
98 new String[]{"1271231234", "123-123-123", "12-12-123445", "1234-12-1234", "123.123.1234", "123-123-12345"},
99 new String[]{"123-123-1234"});
100 }
101
102 protected void testValidationRegex_JavaClass() throws Exception {
103 assertFocusTypeBlurError("field53"," :_");
104 assertInvalidValidFieldValues("field53",
105 new String[]{"127", "TestJava!@#Class", "Test JavaClass"}, new String[]{"TestJavaClass"});
106 }
107
108 protected void testValidationRegex_EmailAddress() throws Exception {
109 assertFocusTypeBlurError("field54","as");
110 assertInvalidValidFieldValues("field54",
111 new String[]{"123@123.123", "email.com@emailServer", "emailemailServer@.com"}, new String[]{"email@emailServer.com"});
112 }
113
114 protected void testValidationRegex_Url() throws Exception {
115 assertFocusTypeBlurError("field84","kuali.org");
116 assertInvalidValidFieldValues("field84",
117 new String[]{"www.google.com", "https:www.google.com", "ftp://www.google.comsdfa123!#@", "ftp:/www.google.coms"},
118 new String[]{"ftp://www.google.com", "https://www.google.com", "http://www.google.com"});
119 }
120
121 protected void testValidationRegex_Date() throws Exception {
122 assertFocusTypeBlurError("field55","1234");
123 assertInvalidValidFieldValues("field55",
124 new String[]{"12/12/2112 12:12:87 am", "12-12-2112 12:12 am", "12-12-2112 12:12", "12/12/2112 12:12",
125 "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"},
126 new String[]{"09/09/2012 12:12 pm", "090923", "Sept 12", "2034", "12/12/2012 23:12:59", "12-12-12 23:12:59",
127 "121212 23:12:32", "Sept 12 23:45:50", "2011 12:23:32"});
128 }
129
130 protected void testValidationRegex_DateBasic() throws Exception {
131 assertFocusTypeBlurError("field75","aws");
132 assertInvalidValidFieldValues("field75", new String[]{"12122012", "13-12-34", "12:12:2034"}, new String[]{"12-12-2034"});
133 }
134
135 protected void testValidationRegex_Time() throws Exception {
136 assertFocusTypeBlurError("field82","12");
137 assertInvalidValidFieldValues("field82", new String[]{"13:00:12", "09:00:", "3-00:12"}, new String[]{"3:00:34", "3:00"});
138 }
139
140 protected void testValidationRegex_Time24H() throws Exception {
141 assertFocusTypeBlurError("field83","24");
142 assertInvalidValidFieldValues("field83", new String[]{"24:00:12", "14:00:", "13:00:76"}, new String[]{"13:00:23", "23:00:12"});
143 }
144
145 protected void testValidationRegex_Timestamp() throws Exception {
146 assertFocusTypeBlurError("field56", "1000");
147 assertInvalidValidFieldValues("field56",
148 new String[]{"1000-12-12 12:12:12.103", "2000/12/12 12-12-12.87", "2000/12/12 12-12-12.87", "2011-08-12 12:12:12"},
149 new String[]{"2099-12-12 12:12:12.103"});
150 }
151
152 protected void testValidationRegex_Year() throws Exception {
153 assertFocusTypeBlurError("field57","1599");
154 assertInvalidValidFieldValues("field57", new String[]{"1599", "2200", "20000", "-202"}, new String[]{"2000"});
155 }
156
157 protected void testValidationRegex_Month() throws Exception {
158 assertFocusTypeBlurError("field58","0");
159 assertInvalidValidFieldValues("field58", new String[]{"0", "-12", "100"}, new String[]{"12"});
160 }
161
162 protected void testValidationRegex_ZipCode() throws Exception {
163 assertFocusTypeBlurError("field61","360001");
164 assertInvalidValidFieldValues("field61", new String[]{"123", "2341 12", "0-1231"}, new String[]{"12345"});
165 }
166
167 protected void testValidationRegex_AlphaNumeric() throws Exception {
168 assertFocusTypeBlurError("field62","@#");
169 assertInvalidValidFieldValues("field62", new String[]{"123 23 @#", "-asd123", "asd/123"}, new String[]{"asd123"});
170 }
171
172 protected void testValidationRegex_AlphaNumericOptions() throws Exception {
173 assertFocusTypeBlurError("field63","2a#");
174 assertInvalidValidFieldValues("field63", new String[]{"123^we", "-123_asd", "123 23 @#"}, new String[]{"as_de 456/123"});
175 }
176
177 protected void testValidationRegex_AlphaWhitespaceCommas() throws Exception {
178 assertFocusTypeBlurError("field64","1@");
179 assertInvalidValidFieldValues("field64", new String[]{"123^we", "asd_pqr", "asd/def"}, new String[]{"asd ,pqr"});
180 }
181
182 protected void testValidationRegex_AlphaAllAllowable() throws Exception {
183 assertFocusTypeBlurError("field76","a2");
184 assertInvalidValidFieldValues("field76", new String[]{"123", "`abcd`", "|abcd|", "~abcd~"}, new String[]{" ab_c d_ef "});
185 }
186
187 protected void testValidationRegex_NoWhitespace() throws Exception {
188 assertFocusTypeBlurError("field65","a e");
189 assertInvalidValidFieldValues("field65", new String[]{"123 ^we"}, new String[]{"123^we!@#^&*~:"});
190 }
191
192 protected void testValidationRegex_Charset() throws Exception {
193 assertFocusTypeBlurError("field66","sdfa");
194 assertInvalidValidFieldValues("field66", new String[]{"123 ^we", "123_^we", "abc ABC"}, new String[]{"aAbBcC"});
195 }
196
197 protected void testValidationRegex_Numeric() throws Exception {
198 assertFocusTypeBlurError("field67","1234-a");
199 assertInvalidValidFieldValues("field67", new String[]{"123 ^we", "123/10", "(123.00)"}, new String[]{"(12-3)"});
200 }
201
202 protected void testValidationRegex_Custom() throws Exception {
203 assertFocusTypeBlurError("field68","4.a");
204 assertInvalidValidFieldValues("field68", new String[]{ "123.123", "a.b", "123 qwe", "5.a", "a.0,b.4"}, new String[]{"a.0"});
205 }
206
207 private void assertInvalidValidFieldValues(String fieldNameToTest, String[] invalids, String[] valids) throws Exception {
208 for (String invalid : invalids) {
209 clearTextByName(fieldNameToTest);
210 waitAndTypeByName(fieldNameToTest, invalid);
211 fireEvent(fieldNameToTest, "blur");
212 if (!isErrorAttributeTrue(fieldNameToTest)) {
213 jiraAwareFail(invalid + " expected to be invalid for field name " + fieldNameToTest);
214 }
215 clearTextByName(fieldNameToTest);
216 }
217
218 for (String valid : valids) {
219 clearTextByName(fieldNameToTest);
220 waitAndTypeByName(fieldNameToTest, valid);
221 fireEvent(fieldNameToTest, "blur");
222 if (isErrorAttributeTrue(fieldNameToTest)) {
223 jiraAwareFail(valid + " expected to be valid for field name " + fieldNameToTest);
224 }
225 clearTextByName(fieldNameToTest);
226 }
227 }
228
229 private boolean isErrorAttributeTrue(String fieldName) throws Exception {
230 Thread.sleep(500);
231 boolean valid = false;
232
233 for (int second = 0; second < 5; second++) {
234 if ((valid = validateErrorAttribute(fieldName)) == true) {
235 break;
236 }
237 }
238
239 return valid;
240 }
241
242 private boolean validateErrorAttribute(String fieldName) throws InterruptedException {
243 try {
244 WebElement field = findElement(By.name(fieldName));
245 return "true".equals(field.getAttribute("aria-invalid"));
246 } catch (Exception e) {
247
248 }
249
250 Thread.sleep(1000);
251
252 return false;
253 }
254
255 }