001    /*
002     * Copyright 2006-2012 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    
017    package edu.samplu.krad.compview;
018    
019    import com.thoughtworks.selenium.Selenium;
020    import junit.framework.Assert;
021    import org.openqa.selenium.firefox.FirefoxDriver;
022    import org.openqa.selenium.WebDriver;
023    import org.openqa.selenium.WebDriverBackedSelenium;
024    import org.junit.After;
025    import org.junit.Before;
026    import org.junit.Test;
027    
028    public class ContraintsIT {
029        private Selenium selenium;
030    
031        @Before
032        public void setUp() throws Exception {
033            WebDriver driver = new FirefoxDriver();
034            selenium = new WebDriverBackedSelenium(driver,
035                    "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3");
036    
037            // Login
038            selenium.open(
039                    "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3");
040            Assert.assertEquals("Login", selenium.getTitle());
041            selenium.type("__login_user", "admin");
042            selenium.click("//input[@value='Login']");
043            selenium.waitForPageToLoad("30000");
044        }
045    
046        @Test
047        public void testContraintsIT() throws Exception {
048            selenium.focus("name=field9");
049            selenium.type("name=field9", "1");
050            selenium.fireEvent("name=field9", "blur");
051            Assert.assertTrue(selenium.getAttribute("name=field9@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
052            selenium.focus("name=field9");
053            selenium.type("name=field9", "12345");
054            selenium.fireEvent("name=field9", "blur");
055            Assert.assertTrue(selenium.getAttribute("name=field9@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
056            selenium.focus("name=field10");
057            selenium.type("name=field10", "2");
058            selenium.fireEvent("name=field10", "blur");
059            Assert.assertTrue(selenium.getAttribute("name=field10@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
060            selenium.focus("name=field10");
061            selenium.type("name=field10", "51");
062            selenium.fireEvent("name=field10", "blur");
063            Assert.assertTrue(selenium.getAttribute("name=field10@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
064            selenium.focus("name=field10");
065            selenium.type("name=field10", "25");
066            selenium.fireEvent("name=field10", "blur");
067            Assert.assertTrue(selenium.getAttribute("name=field10@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
068            selenium.focus("name=field6");
069            selenium.type("name=field6", "A");
070            selenium.fireEvent("name=field6", "blur");
071            selenium.fireEvent("name=field7", "blur");
072            Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
073            selenium.type("name=field7", "B");
074            selenium.fireEvent("name=field7", "blur");
075            Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
076            selenium.fireEvent("name=field8", "blur");
077            Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
078            selenium.type("name=field8", "C");
079            selenium.fireEvent("name=field8", "blur");
080            Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
081            selenium.type("name=field6", "");
082            selenium.fireEvent("name=field6", "blur");
083            Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
084            selenium.type("name=field7", "");
085            selenium.fireEvent("name=field7", "blur");
086            Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
087            selenium.type("name=field8", "");
088            selenium.fireEvent("name=field8", "blur");
089            Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
090            Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
091            Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
092            selenium.type("name=field8", "C");
093            selenium.fireEvent("name=field8", "blur");
094            Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
095            Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
096            Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
097            selenium.type("name=field6", "A");
098            selenium.fireEvent("name=field6", "blur");
099            Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
100            Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
101            Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
102            selenium.type("name=field14", "A");
103            selenium.fireEvent("name=field14", "blur");
104            Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
105            selenium.type("name=field11", "A");
106            selenium.fireEvent("name=field11", "blur");
107            Assert.assertTrue(selenium.getAttribute("name=field11@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
108            Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
109            selenium.type("name=field11", "");
110            selenium.fireEvent("name=field11", "blur");
111            Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
112            selenium.type("name=field12", "A");
113            selenium.fireEvent("name=field12", "blur");
114            Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
115            selenium.type("name=field13", "A");
116            selenium.fireEvent("name=field13", "blur");
117            Assert.assertTrue(selenium.getAttribute("name=field13@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
118            Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
119            selenium.type("name=field11", "A");
120            selenium.fireEvent("name=field11", "blur");
121            Assert.assertTrue(selenium.getAttribute("name=field11@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
122            Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
123            selenium.type("name=field18", "A");
124            selenium.fireEvent("name=field18", "blur");
125            Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
126            selenium.type("name=field15", "A");
127            selenium.fireEvent("name=field15", "blur");
128            Assert.assertTrue(selenium.getAttribute("name=field15@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
129            Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
130            selenium.type("name=field15", "");
131            selenium.fireEvent("name=field15", "blur");
132            Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
133            selenium.type("name=field16", "A");
134            selenium.fireEvent("name=field16", "blur");
135            Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
136            selenium.type("name=field17", "A");
137            selenium.fireEvent("name=field17", "blur");
138            Assert.assertTrue(selenium.getAttribute("name=field17@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
139            Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
140            selenium.type("name=field15", "A");
141            selenium.fireEvent("name=field15", "blur");
142            Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
143            selenium.type("name=field23", "A");
144            selenium.fireEvent("name=field23", "blur");
145            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
146            selenium.type("name=field19", "A");
147            selenium.fireEvent("name=field19", "blur");
148            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
149            selenium.type("name=field19", "");
150            selenium.fireEvent("name=field19", "blur");
151            selenium.type("name=field20", "B");
152            selenium.fireEvent("name=field20", "blur");
153            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
154            selenium.type("name=field20", "");
155            selenium.fireEvent("name=field20", "blur");
156            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
157            selenium.type("name=field21", "C");
158            selenium.fireEvent("name=field21", "blur");
159            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
160            selenium.type("name=field22", "D");
161            selenium.fireEvent("name=field22", "blur");
162            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
163            selenium.type("name=field19", "D");
164            selenium.fireEvent("name=field19", "blur");
165            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
166            selenium.type("name=field20", "D");
167            selenium.fireEvent("name=field20", "blur");
168            Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
169            selenium.check("name=field24 value=case1");
170            selenium.type("name=field25", "");
171            selenium.fireEvent("name=field25", "blur");
172            Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
173            selenium.check("name=field24 value=case4");
174            selenium.fireEvent("name=field24", "blur");
175            for (int second = 0; ; second++) {
176                if (second >= 60) {
177                    Assert.fail("timeout");
178                }
179                try {
180                    if (selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
181                        break;
182                    }
183                } catch (Exception e) {
184                }
185                Thread.sleep(1000);
186            }
187    
188            Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
189            selenium.check("name=field24 value=case1");
190            selenium.fireEvent("name=field24", "blur");
191            selenium.type("name=field25", "$100");
192            selenium.fireEvent("name=field25", "blur");
193            for (int second = 0; ; second++) {
194                if (second >= 60) {
195                    Assert.fail("timeout");
196                }
197                try {
198                    if (selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
199                        break;
200                    }
201                } catch (Exception e) {
202                }
203                Thread.sleep(1000);
204            }
205    
206            Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
207            selenium.check("name=field24 value=case2");
208            selenium.fireEvent("name=field24", "blur");
209            for (int second = 0; ; second++) {
210                if (second >= 60) {
211                    Assert.fail("timeout");
212                }
213                try {
214                    if (selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
215                        break;
216                    }
217                } catch (Exception e) {
218                }
219                Thread.sleep(1000);
220            }
221    
222            Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
223            selenium.type("name=field25", "A100");
224            selenium.fireEvent("name=field25", "blur");
225            Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
226            selenium.check("name=field24 value=case3");
227            selenium.fireEvent("name=field24", "blur");
228            selenium.type("name=field26", "6000");
229            selenium.fireEvent("name=field26", "blur");
230            for (int second = 0; ; second++) {
231                if (second >= 60) {
232                    Assert.fail("timeout");
233                }
234                try {
235                    if (selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
236                        break;
237                    }
238                } catch (Exception e) {
239                }
240                Thread.sleep(1000);
241            }
242    
243            Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
244            selenium.type("name=field26", "501");
245            selenium.fireEvent("name=field26", "blur");
246            Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
247            selenium.type("name=field26", "499");
248            selenium.fireEvent("name=field26", "blur");
249            Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
250            selenium.type("name=field26", "6000");
251            selenium.fireEvent("name=field26", "blur");
252            selenium.check("name=field24 value=case3");
253            selenium.fireEvent("name=field24", "blur");
254            for (int second = 0; ; second++) {
255                if (second >= 60) {
256                    Assert.fail("timeout");
257                }
258                try {
259                    if (selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
260                        break;
261                    }
262                } catch (Exception e) {
263                }
264                Thread.sleep(1000);
265            }
266    
267            Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
268            selenium.check("name=field24 value=case4");
269            selenium.type("name=field27", "A");
270            selenium.fireEvent("name=field27", "blur");
271            selenium.type("name=field28", "");
272            selenium.fireEvent("name=field28", "blur");
273            for (int second = 0; ; second++) {
274                if (second >= 60) {
275                    Assert.fail("timeout");
276                }
277                try {
278                    if (selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
279                        break;
280                    }
281                } catch (Exception e) {
282                }
283                Thread.sleep(1000);
284            }
285    
286            Assert.assertTrue(selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
287            selenium.check("name=field24 value=case3");
288            selenium.fireEvent("name=field24", "blur");
289            for (int second = 0; ; second++) {
290                if (second >= 60) {
291                    Assert.fail("timeout");
292                }
293                try {
294                    if (selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
295                        break;
296                    }
297                } catch (Exception e) {
298                }
299                Thread.sleep(1000);
300            }
301    
302            Assert.assertTrue(selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
303            selenium.type("name=field28", "B");
304            selenium.fireEvent("name=field28", "blur");
305            selenium.check("name=field24 value=case4");
306            selenium.fireEvent("name=field24", "blur");
307            for (int second = 0; ; second++) {
308                if (second >= 60) {
309                    Assert.fail("timeout");
310                }
311                try {
312                    if (selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
313                        break;
314                    }
315                } catch (Exception e) {
316                }
317                Thread.sleep(1000);
318            }
319    
320            Assert.assertTrue(selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
321            selenium.type("name=field31", "B");
322            selenium.type("name=field32", "B");
323            selenium.fireEvent("name=field33", "blur");
324            Assert.assertTrue(selenium.getAttribute("name=field33@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
325            selenium.type("name=field33", "B");
326            selenium.fireEvent("name=field33", "blur");
327            Assert.assertTrue(selenium.getAttribute("name=field33@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
328            selenium.type("name=field32", "A");
329            selenium.type("name=field33", "");
330            selenium.fireEvent("name=field33", "blur");
331            Assert.assertTrue(selenium.getAttribute("name=field33@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
332        }
333    
334        @After
335        public void tearDown() throws Exception {
336            selenium.stop();
337        }
338    }