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 com.thoughtworks.selenium.SeleneseTestCase;
021    import junit.framework.Assert;
022    import org.openqa.selenium.firefox.FirefoxDriver;
023    import org.openqa.selenium.WebDriver;
024    import org.openqa.selenium.WebDriverBackedSelenium;
025    import org.junit.After;
026    import org.junit.Before;
027    import org.junit.Test;
028    import java.util.regex.Pattern;
029    
030    public class ValidCharsConstraintIT{
031        private Selenium selenium;
032        @Before
033        public void setUp() throws Exception {
034            WebDriver driver = new FirefoxDriver();
035            selenium = new WebDriverBackedSelenium(driver,
036                    "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page4");
037    
038            // Login
039            selenium.open("http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page4");
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 testValidCharsConstraintIT() throws Exception {
048                    selenium.focus("name=field50");
049                    selenium.type("name=field50", "12.333");
050                    selenium.fireEvent("name=field50", "blur");
051                    Assert.assertTrue(selenium.getAttribute("name=field50@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
052                    selenium.focus("name=field50");
053                    selenium.type("name=field50", "123.33");
054                    selenium.fireEvent("name=field50", "blur");
055                    Assert.assertTrue(selenium.getAttribute("name=field50@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
056                    selenium.focus("name=field51");
057                    selenium.type("name=field51", "A");
058                    selenium.fireEvent("name=field51", "blur");
059                    Assert.assertTrue(selenium.getAttribute("name=field51@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
060                    selenium.focus("name=field51");
061                    selenium.type("name=field51", "-123.33");
062                    selenium.fireEvent("name=field51", "blur");
063                    Assert.assertTrue(selenium.getAttribute("name=field51@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
064                    selenium.focus("name=field77");
065                    selenium.type("name=field77", "1.1");
066                    selenium.fireEvent("name=field77", "blur");
067                    Assert.assertTrue(selenium.getAttribute("name=field77@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
068                    selenium.focus("name=field77");
069                    selenium.type("name=field77", "12");
070                    selenium.fireEvent("name=field77", "blur");
071                    Assert.assertTrue(selenium.getAttribute("name=field77@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
072                    selenium.focus("name=field52");
073                    selenium.type("name=field52", "5551112222");
074                    selenium.fireEvent("name=field52", "blur");
075                    Assert.assertTrue(selenium.getAttribute("name=field52@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
076                    selenium.focus("name=field52");
077                    selenium.type("name=field52", "555-111-1111");
078                    selenium.fireEvent("name=field52", "blur");
079                    Assert.assertTrue(selenium.getAttribute("name=field52@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
080                    selenium.focus("name=field53");
081                    selenium.type("name=field53", "1ClassName.java");
082                    selenium.fireEvent("name=field53", "blur");
083                    Assert.assertTrue(selenium.getAttribute("name=field53@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
084                    selenium.focus("name=field53");
085                    selenium.type("name=field53", "ClassName.java");
086                    selenium.fireEvent("name=field53", "blur");
087                    Assert.assertTrue(selenium.getAttribute("name=field53@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
088                    selenium.focus("name=field54");
089                    selenium.type("name=field54", "aaaaa");
090                    selenium.fireEvent("name=field54", "blur");
091                    Assert.assertTrue(selenium.getAttribute("name=field54@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
092                    selenium.focus("name=field54");
093                    selenium.type("name=field54", "aaaaa@kuali.org");
094                    selenium.fireEvent("name=field54", "blur");
095                    Assert.assertTrue(selenium.getAttribute("name=field54@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
096                    selenium.focus("name=field84");
097                    selenium.type("name=field84", "aaaaa");
098                    selenium.fireEvent("name=field84", "blur");
099                    Assert.assertTrue(selenium.getAttribute("name=field84@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
100                    selenium.focus("name=field84");
101                    selenium.type("name=field84", "http://www.kuali.org");
102                    selenium.fireEvent("name=field84", "blur");
103                    Assert.assertTrue(selenium.getAttribute("name=field84@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
104                    selenium.focus("name=field55");
105                    selenium.type("name=field55", "023512");
106                    selenium.fireEvent("name=field55", "blur");
107                    Assert.assertTrue(selenium.getAttribute("name=field55@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
108                    selenium.focus("name=field55");
109                    selenium.type("name=field55", "022812");
110                    selenium.fireEvent("name=field55", "blur");
111                    Assert.assertTrue(selenium.getAttribute("name=field55@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
112                    selenium.focus("name=field75");
113                    selenium.type("name=field75", "02/35/12");
114                    selenium.fireEvent("name=field75", "blur");
115                    Assert.assertTrue(selenium.getAttribute("name=field75@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
116                    selenium.focus("name=field75");
117                    selenium.type("name=field75", "02/28/12");
118                    selenium.fireEvent("name=field75", "blur");
119                    Assert.assertTrue(selenium.getAttribute("name=field75@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
120                    selenium.focus("name=field82");
121                    selenium.type("name=field82", "13:22");
122                    selenium.fireEvent("name=field82", "blur");
123                    Assert.assertTrue(selenium.getAttribute("name=field82@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
124                    selenium.focus("name=field82");
125                    selenium.type("name=field82", "02:33");
126                    selenium.fireEvent("name=field82", "blur");
127                    Assert.assertTrue(selenium.getAttribute("name=field82@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
128                    selenium.focus("name=field83");
129                    selenium.type("name=field83", "25:22");
130                    selenium.fireEvent("name=field83", "blur");
131                    Assert.assertTrue(selenium.getAttribute("name=field83@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
132                    selenium.focus("name=field83");
133                    selenium.type("name=field83", "14:33");
134                    selenium.fireEvent("name=field83", "blur");
135                    Assert.assertTrue(selenium.getAttribute("name=field83@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
136                    selenium.focus("name=field57");
137                    selenium.type("name=field57", "0");
138                    selenium.fireEvent("name=field57", "blur");
139                    Assert.assertTrue(selenium.getAttribute("name=field57@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
140                    selenium.focus("name=field57");
141                    selenium.type("name=field57", "2020");
142                    selenium.fireEvent("name=field57", "blur");
143                    Assert.assertTrue(selenium.getAttribute("name=field57@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
144                    selenium.focus("name=field58");
145                    selenium.type("name=field58", "13");
146                    selenium.fireEvent("name=field58", "blur");
147                    Assert.assertTrue(selenium.getAttribute("name=field58@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
148                    selenium.focus("name=field58");
149                    selenium.type("name=field58", "12");
150                    selenium.fireEvent("name=field58", "blur");
151                    Assert.assertTrue(selenium.getAttribute("name=field58@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
152                    selenium.focus("name=field61");
153                    selenium.type("name=field61", "5555-444");
154                    selenium.fireEvent("name=field61", "blur");
155                    Assert.assertTrue(selenium.getAttribute("name=field61@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
156                    selenium.focus("name=field61");
157                    selenium.type("name=field61", "55555-4444");
158                    selenium.fireEvent("name=field61", "blur");
159                    Assert.assertTrue(selenium.getAttribute("name=field61@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
160                    selenium.focus("name=field62");
161                    selenium.type("name=field62", "aa5bb6_a");
162                    selenium.fireEvent("name=field62", "blur");
163                    Assert.assertTrue(selenium.getAttribute("name=field62@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
164                    selenium.focus("name=field62");
165                    selenium.type("name=field62", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890");
166                    selenium.fireEvent("name=field62", "blur");
167                    Assert.assertTrue(selenium.getAttribute("name=field62@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
168                    selenium.focus("name=field63");
169                    selenium.type("name=field63", "fff555$");
170                    selenium.fireEvent("name=field63", "blur");
171                    Assert.assertTrue(selenium.getAttribute("name=field63@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
172                    selenium.focus("name=field63");
173                    selenium.type("name=field63", "aa22 _/");
174                    selenium.fireEvent("name=field63", "blur");
175                    Assert.assertTrue(selenium.getAttribute("name=field63@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
176                    selenium.focus("name=field64");
177                    selenium.type("name=field64", "AABB55");
178                    selenium.fireEvent("name=field64", "blur");
179                    Assert.assertTrue(selenium.getAttribute("name=field64@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
180                    selenium.focus("name=field64");
181                    selenium.type("name=field64", "ABCDEFGHIJKLMNOPQRSTUVWXY,Z abcdefghijklmnopqrstuvwxy,z");
182                    selenium.fireEvent("name=field64", "blur");
183                    Assert.assertTrue(selenium.getAttribute("name=field64@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
184                    selenium.focus("name=field76");
185                    selenium.type("name=field76", "AA~BB%");
186                    selenium.fireEvent("name=field76", "blur");
187                    Assert.assertTrue(selenium.getAttribute("name=field76@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
188                    selenium.focus("name=field76");
189                    selenium.type("name=field76", "abcABC %$#@&<>\\{}[]*-+!=.()/\"\"',:;?");
190                    selenium.fireEvent("name=field76", "blur");
191                    Assert.assertTrue(selenium.getAttribute("name=field76@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
192                    selenium.focus("name=field65");
193                    selenium.type("name=field65", "sdfs$#$# dsffs");
194                    selenium.fireEvent("name=field65", "blur");
195                    Assert.assertTrue(selenium.getAttribute("name=field65@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
196                    selenium.focus("name=field65");
197                    selenium.type("name=field65", "sdfs$#$#sffs");
198                    selenium.fireEvent("name=field65", "blur");
199                    Assert.assertTrue(selenium.getAttribute("name=field65@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
200                    selenium.focus("name=field66");
201                    selenium.type("name=field66", "abcABCD");
202                    selenium.fireEvent("name=field66", "blur");
203                    Assert.assertTrue(selenium.getAttribute("name=field66@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
204                    selenium.focus("name=field66");
205                    selenium.type("name=field66", "ABCabc");
206                    selenium.fireEvent("name=field66", "blur");
207                    Assert.assertTrue(selenium.getAttribute("name=field66@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
208                    selenium.focus("name=field67");
209                    selenium.type("name=field67", "(111)B-(222)A");
210                    selenium.fireEvent("name=field67", "blur");
211                    Assert.assertTrue(selenium.getAttribute("name=field67@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
212                    selenium.focus("name=field67");
213                    selenium.type("name=field67", "(12345)-(67890)");
214                    selenium.fireEvent("name=field67", "blur");
215                    Assert.assertTrue(selenium.getAttribute("name=field67@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
216                    selenium.focus("name=field68");
217                    selenium.type("name=field68", "A.66");
218                    selenium.fireEvent("name=field68", "blur");
219                    Assert.assertTrue(selenium.getAttribute("name=field68@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
220                    selenium.focus("name=field68");
221                    selenium.type("name=field68", "a.4");
222                    selenium.fireEvent("name=field68", "blur");
223                    Assert.assertTrue(selenium.getAttribute("name=field68@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
224                    selenium.focus("name=field56");
225                    selenium.type("name=field56", "2020-06-02");
226                    selenium.fireEvent("name=field56", "blur");
227                    Assert.assertTrue(selenium.getAttribute("name=field56@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
228                    selenium.focus("name=field56");
229                    selenium.type("name=field56", "2020-06-02 03:30:30.22");
230                    selenium.fireEvent("name=field56", "blur");
231                    Assert.assertTrue(selenium.getAttribute("name=field56@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
232            }
233    
234            @After
235            public void tearDown() throws Exception {
236                    selenium.stop();
237            }
238    }