001/**
002 * Copyright 2005-2013 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 */
016package edu.samplu.krad.library.validation;
017
018import org.junit.Test;
019
020import edu.samplu.common.SmokeTestBase;
021
022/**
023 * @author Kuali Rice Team (rice.collab@kuali.org)
024 */
025public class DemoLibraryValidationMustOccurConstraintsSmokeTest extends SmokeTestBase {
026
027    /**
028     * /kr-krad/kradsampleapp?viewId=Demo-MustOccurConstraint-View&methodToCall=start
029     */
030    public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-MustOccurConstraint-View&methodToCall=start";
031
032    /**
033     *   1-2 of the following must occur: (Field 1A) OR (Field 2A and Field 2B)
034     */
035    private static final String EXAMPLE1_VALIDATION_MESSAGE="  1-2 of the following must occur: (Field 1A) OR (Field 2A and Field 2B)";
036    
037    /**
038     *   The following must occur: (Field 1A) OR (Field 2A and Field 2B)
039     */
040    private static final String EXAMPLE2_VALIDATION_MESSAGE="  The following must occur: (Field 1A) OR (Field 2A and Field 2B)";
041    
042    /**
043     *   1-2 of the following must occur: (Field 1A or Field 1B) OR (Field 2A and Field 2B)
044     */
045    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)";
046    
047    /**
048     * //input[@name='inputField4' and @class='uif-textControl dependsOn-inputField1 dependsOn-inputField2 dependsOn-inputField3 dirty error']
049     */
050    private static final String EXAMPLE1_ERROR_XPATH="//input[@name='inputField4' and @class='uif-textControl dependsOn-inputField1 dependsOn-inputField2 dependsOn-inputField3 dirty error']";
051    
052    /**
053     * //input[@name='inputField8' and @class='uif-textControl dependsOn-inputField5 dependsOn-inputField6 dependsOn-inputField7 dirty error']
054     */
055    private static final String EXAMPLE2_ERROR_XPATH="//input[@name='inputField8' and @class='uif-textControl dependsOn-inputField5 dependsOn-inputField6 dependsOn-inputField7 dirty error']";
056    
057    /**
058     * //input[@name='inputField13' and @class='uif-textControl dependsOn-inputField9 dependsOn-inputField10 dependsOn-inputField11 dependsOn-inputField12 dirty error']
059     */
060    private static final String EXAMPLE3_ERROR_XPATH="//input[@name='inputField13' and @class='uif-textControl dependsOn-inputField9 dependsOn-inputField10 dependsOn-inputField11 dependsOn-inputField12 dirty error']";
061 
062    @Override
063    protected String getBookmarkUrl() {
064        return BOOKMARK_URL;
065    }
066
067    @Override
068    protected void navigate() throws Exception {
069        waitAndClickById("Demo-LibraryLink", "");
070        waitAndClickByLinkText("Validation");
071        waitAndClickByLinkText("Must Occur Constraint");
072    }
073
074    protected void testValidationMustOccurConstraintsExample1() throws Exception {
075       //Scenario-1
076       waitAndTypeByName("inputField4","a");
077       waitAndTypeByName("inputField1","");
078       assertElementPresentByXpath(EXAMPLE1_ERROR_XPATH);
079       fireMouseOverEventByName("inputField4");
080       assertTextPresent(EXAMPLE1_VALIDATION_MESSAGE);
081       
082       //Scenario-2
083       waitAndTypeByName("inputField1","a");
084       waitAndTypeByName("inputField2","");
085       if(isElementPresentByXpath(EXAMPLE1_ERROR_XPATH)) {
086           fail("Criteria Not Satisfied");
087       }
088       
089       //Scenario-3
090       clearTextByName("inputField1");
091       waitAndTypeByName("inputField2","a");
092       waitAndTypeByName("inputField1","");
093       assertElementPresentByXpath(EXAMPLE1_ERROR_XPATH);
094       fireMouseOverEventByName("inputField4");
095       assertTextPresent(EXAMPLE1_VALIDATION_MESSAGE);
096       
097       //Scenario-4
098       waitAndTypeByName("inputField3","a");
099       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}