View Javadoc
1   /**
2    * Copyright 2005-2013 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.samplu.krad.library.validation;
17  
18  import org.junit.Test;
19  
20  import edu.samplu.common.SmokeTestBase;
21  
22  /**
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  public class DemoLibraryValidationMustOccurConstraintsSmokeTest extends SmokeTestBase {
26  
27      /**
28       * /kr-krad/kradsampleapp?viewId=Demo-MustOccurConstraint-View&methodToCall=start
29       */
30      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-MustOccurConstraint-View&methodToCall=start";
31  
32      /**
33       *   1-2 of the following must occur: (Field 1A) OR (Field 2A and Field 2B)
34       */
35      private static final String EXAMPLE1_VALIDATION_MESSAGE="  1-2 of the following must occur: (Field 1A) OR (Field 2A and Field 2B)";
36      
37      /**
38       *   The following must occur: (Field 1A) OR (Field 2A and Field 2B)
39       */
40      private static final String EXAMPLE2_VALIDATION_MESSAGE="  The following must occur: (Field 1A) OR (Field 2A and Field 2B)";
41      
42      /**
43       *   1-2 of the following must occur: (Field 1A or Field 1B) OR (Field 2A and Field 2B)
44       */
45      private static final String EXAMPLE3_VALIDATION_MESSAGE="  1-2 of the following must occur: (Field 1A or Field 1B) OR (Field 2A and Field 2B)";
46      
47      /**
48       * //input[@name='inputField4' and @class='uif-textControl dependsOn-inputField1 dependsOn-inputField2 dependsOn-inputField3 dirty error']
49       */
50      private static final String EXAMPLE1_ERROR_XPATH="//input[@name='inputField4' and @class='uif-textControl dependsOn-inputField1 dependsOn-inputField2 dependsOn-inputField3 dirty error']";
51      
52      /**
53       * //input[@name='inputField8' and @class='uif-textControl dependsOn-inputField5 dependsOn-inputField6 dependsOn-inputField7 dirty error']
54       */
55      private static final String EXAMPLE2_ERROR_XPATH="//input[@name='inputField8' and @class='uif-textControl dependsOn-inputField5 dependsOn-inputField6 dependsOn-inputField7 dirty error']";
56      
57      /**
58       * //input[@name='inputField13' and @class='uif-textControl dependsOn-inputField9 dependsOn-inputField10 dependsOn-inputField11 dependsOn-inputField12 dirty error']
59       */
60      private static final String EXAMPLE3_ERROR_XPATH="//input[@name='inputField13' and @class='uif-textControl dependsOn-inputField9 dependsOn-inputField10 dependsOn-inputField11 dependsOn-inputField12 dirty error']";
61   
62      @Override
63      protected String getBookmarkUrl() {
64          return BOOKMARK_URL;
65      }
66  
67      @Override
68      protected void navigate() throws Exception {
69          waitAndClickById("Demo-LibraryLink", "");
70          waitAndClickByLinkText("Validation");
71          waitAndClickByLinkText("Must Occur Constraint");
72      }
73  
74      protected void testValidationMustOccurConstraintsExample1() throws Exception {
75         //Scenario-1
76         waitAndTypeByName("inputField4","a");
77         waitAndTypeByName("inputField1","");
78         assertElementPresentByXpath(EXAMPLE1_ERROR_XPATH);
79         fireMouseOverEventByName("inputField4");
80         assertTextPresent(EXAMPLE1_VALIDATION_MESSAGE);
81         
82         //Scenario-2
83         waitAndTypeByName("inputField1","a");
84         waitAndTypeByName("inputField2","");
85         if(isElementPresentByXpath(EXAMPLE1_ERROR_XPATH)) {
86             fail("Criteria Not Satisfied");
87         }
88         
89         //Scenario-3
90         clearTextByName("inputField1");
91         waitAndTypeByName("inputField2","a");
92         waitAndTypeByName("inputField1","");
93         assertElementPresentByXpath(EXAMPLE1_ERROR_XPATH);
94         fireMouseOverEventByName("inputField4");
95         assertTextPresent(EXAMPLE1_VALIDATION_MESSAGE);
96         
97         //Scenario-4
98         waitAndTypeByName("inputField3","a");
99         waitAndTypeByName("inputField1","");
100        if(isElementPresentByXpath(EXAMPLE1_ERROR_XPATH)) {
101            fail("Criteria Not Satisfied");
102        }
103     }
104     
105     protected void testValidationMustOccurConstraintsExample2() throws Exception {
106         waitAndClickByLinkText("Example 2");
107         
108         //Scenario-1
109         waitAndTypeByName("inputField8","a");
110         waitAndTypeByName("inputField5","");
111         assertElementPresentByXpath(EXAMPLE2_ERROR_XPATH);
112         fireMouseOverEventByName("inputField8");
113         assertTextPresent(EXAMPLE2_VALIDATION_MESSAGE);
114         
115         //Scenario-2
116         waitAndTypeByName("inputField5","a");
117         waitAndTypeByName("inputField6","");
118         if(isElementPresentByXpath(EXAMPLE2_ERROR_XPATH)) {
119             fail("Criteria Not Satisfied");
120         }
121         
122         //Scenario-3
123         clearTextByName("inputField5");
124         waitAndTypeByName("inputField6","a");
125         waitAndTypeByName("inputField5","");
126         assertElementPresentByXpath(EXAMPLE2_ERROR_XPATH);
127         fireMouseOverEventByName("inputField8");
128         assertTextPresent(EXAMPLE2_VALIDATION_MESSAGE);
129         
130         //Scenario-4
131         waitAndTypeByName("inputField7","a");
132         waitAndTypeByName("inputField5","");
133         if (isElementPresentByXpath(EXAMPLE2_ERROR_XPATH)){
134             fail("Criteria Not Satisfied");
135         }
136         
137         //Scenario-5
138         waitAndTypeByName("inputField5","a");
139         waitAndTypeByName("inputField8","a");
140         assertElementPresentByXpath(EXAMPLE2_ERROR_XPATH);
141         fireMouseOverEventByName("inputField8");
142         assertTextPresent(EXAMPLE1_VALIDATION_MESSAGE);
143     }
144 
145     protected void testValidationMustOccurConstraintsExample3() throws Exception {
146         waitAndClickByLinkText("Example 3");
147         
148         //Scenario-1
149         waitAndTypeByName("inputField13","a");
150         waitAndTypeByName("inputField9","");
151         Thread.sleep(1000);
152         assertElementPresentByXpath(EXAMPLE3_ERROR_XPATH);
153         fireMouseOverEventByName("inputField13");
154         assertTextPresent(EXAMPLE3_VALIDATION_MESSAGE);
155         
156         //Scenario-2
157         waitAndTypeByName("inputField9","a");
158         waitAndTypeByName("inputField13","");
159         if (isElementPresentByXpath(EXAMPLE3_ERROR_XPATH)) {
160             fail("Criteria Not Satisfied");
161         }
162         clearTextByName("inputField9");
163         
164         //Scenario-3
165         waitAndTypeByName("inputField10","a");
166         waitAndTypeByName("inputField13","");
167         if (isElementPresentByXpath(EXAMPLE3_ERROR_XPATH)) {
168             fail("Criteria Not Satisfied");
169         }
170         clearTextByName("inputField10");
171         
172         //Scenario-4
173         waitAndTypeByName("inputField11","a");
174         waitAndTypeByName("inputField12","a");
175         waitAndTypeByName("inputField13","");
176         if (isElementPresentByXpath(EXAMPLE3_ERROR_XPATH)) {
177             fail("Criteria Not Satisfied");
178         }
179     }
180     
181 
182     @Test
183     public void testValidationMustOccurConstraintsBookmark() throws Exception {
184         testValidationMustOccurConstraintsExample1();
185         testValidationMustOccurConstraintsExample2();
186         testValidationMustOccurConstraintsExample3();
187         passed();
188     }
189 
190     @Test
191     public void testValidationMustOccurConstraintsNav() throws Exception {
192         testValidationMustOccurConstraintsExample1();
193         testValidationMustOccurConstraintsExample2();
194         testValidationMustOccurConstraintsExample3();
195         passed();
196     }
197 }