1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
25
26
27
28 public abstract class UifComponentValidationRegexPatternAftBase extends WebDriverLegacyITBase {
29
30
31
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
63 assertInvalidValidFieldValues("field50", new String[]{"123.123", "1234.4", "1234.434"}, new String[]{"123.67"});
64
65
66 assertInvalidValidFieldValues("field51", new String[]{"127.", "1234()98"}, new String[]{"-123.67"});
67
68
69 assertInvalidValidFieldValues("field77", new String[]{"127.", "1234.4123", "123E123"}, new String[]{"-123"});
70
71
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
76 assertInvalidValidFieldValues("field53", new String[]{"127", "TestJava!@#Class", "Test JavaClass"}, new String[]{"TestJavaClass"});
77
78
79 assertInvalidValidFieldValues("field54", new String[]{"123@123.123", "email.com@emailServer", "emailemailServer@.com"}, new String[]{"email@emailServer.com"});
80
81
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
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
93 assertInvalidValidFieldValues("field75", new String[]{"12122012", "13-12-34", "12:12:2034"}, new String[]{"12-12-2034"});
94
95
96 assertInvalidValidFieldValues("field82", new String[]{"13:00:12", "09:00:", "3-00:12"}, new String[]{"3:00:34", "3:00"});
97
98
99 assertInvalidValidFieldValues("field83", new String[]{"24:00:12", "14:00:", "13:00:76"}, new String[]{"13:00:23", "23:00:12"});
100
101
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", }, new String[]{"2099-12-12 12:12:12.103"});
104
105
106 assertInvalidValidFieldValues("field57", new String[]{"1599", "2200",
107 "20000", "-202"}, new String[]{"2000"});
108
109
110 assertInvalidValidFieldValues("field58", new String[]{"0", "-12", "100"}, new String[]{"12"});
111
112
113 assertInvalidValidFieldValues("field61", new String[]{"123", "2341 12", "0-1231"}, new String[]{"12345"});
114
115
116 assertInvalidValidFieldValues("field62", new String[]{"123 23 @#", "-asd123", "asd/123"}, new String[]{"asd123"});
117
118
119 assertInvalidValidFieldValues("field63", new String[]{"123^we", "-123_asd", "123 23 @#"}, new String[]{"as_de 456/123"});
120
121
122 assertInvalidValidFieldValues("field64", new String[]{"123^we", "asd_pqr", "asd/def"}, new String[]{"asd ,pqr"});
123
124
125 assertInvalidValidFieldValues("field76", new String[]{"123", "`abcd`", "|abcd|", "~abcd~"}, new String[]{" ab_c d_ef "});
126
127
128 assertInvalidValidFieldValues("field65", new String[]{"123 ^we"}, new String[]{"123^we!@#^&*~:"});
129
130
131 assertInvalidValidFieldValues("field66", new String[]{"123 ^we", "123_^we", "abc ABC"}, new String[]{"aAbBcC"});
132
133
134 assertInvalidValidFieldValues("field67", new String[]{"123 ^we", "123/10", "(123.00)"}, new String[]{"(12-3)"});
135
136
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
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 }