View Javadoc
1   /**
2    * Copyright 2005-2014 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.sampleu.main;
17  
18  import org.apache.commons.lang3.StringUtils;
19  import org.junit.Test;
20  import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
21  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
22  import org.kuali.rice.testtools.selenium.WebDriverUtils;
23  import org.openqa.selenium.Keys;
24  
25  /**
26   * test that checks that rules can be added to agendas
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class AgendaEditorAddRuleAft extends WebDriverLegacyITBase {
31  
32      public static String KRAD_PORTAL_BASE = "/kr-krad/";
33      public static String AGENDA_EDITOR_BASE = "krmsAgendaEditor";
34  
35      public static String NEW_DATA_OBJ_PATH = "document.newMaintainableObject.dataObject.";
36  
37      public static final String BOOKMARK_URL =
38              AutomatedFunctionalTestUtils.PORTAL
39                      + "?channelTitle=Agenda%20Lookup&channelUrl="
40                      + WebDriverUtils.getBaseUrlString()
41                      + AutomatedFunctionalTestUtils.KRAD_LOOKUP_METHOD
42                      + "org.kuali.rice.krms.impl.repository.AgendaBo"
43                      + AutomatedFunctionalTestUtils.SHOW_MAINTENANCE_LINKS
44                      + "&returnLocation="
45                      + AutomatedFunctionalTestUtils.PORTAL_URL
46                      + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
47  
48      @Override
49      protected String getBookmarkUrl() {
50          return BOOKMARK_URL;
51      }
52  
53      @Override
54      protected void navigate() throws Exception {
55          waitAndClickByLinkText(AGENDA_LOOKUP_LINK_TEXT);
56          waitForPageToLoad();
57      }
58  
59      protected void testAgendaEditorAddRuleWithSimpleProposition() throws Exception {
60          String uniqId = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits();
61          String agendaName = "AgendaEditorAddRuleAft " + uniqId;
62          String ruleName = "AgendaEditorAddRuleAft Rule " + "1" + " " + uniqId;
63  
64          selectFrameIframePortlet();
65          waitAndClickLinkContainingText("Create New");
66  
67          // add agenda information
68          waitForPageToLoad();
69          addNewAgendaInformation(agendaName, "Kuali Rules Test", "Context1");
70          // dynamic agenda details
71          Thread.sleep(500); // tab is happening to fast
72          unfocusElement();
73          waitAndTypeByName(NEW_DATA_OBJ_PATH + "agenda.typeId", "Campus Agenda");
74          unfocusElement();
75          waitAndTypeByName(NEW_DATA_OBJ_PATH + "customAttributesMap[Campus]", "BL");
76          waitAndClickButtonByText("Add Rule");
77  
78          // add agenda rule information
79          waitForPageToLoad();
80          addNewAgendaRuleInformation("Validation Rule", "", ruleName);
81          waitAndClickButtonByExactText("Add"); // add proposition button
82          addRulePropositionInfo("0", "Campus must have students", "", "Bloomington Campus Size", ">", "1");
83          addNewRuleActionInformation("KrmsActionResolverType", "test", "test");
84          waitAndClickButtonByText("Add Rule");
85  
86          // validate rule exists
87          waitForPageToLoad();
88          assertTextPresent(ruleName);
89          waitAndClickLinkContainingText("Cancel");
90          passed();
91      }
92  
93  
94      protected void addNewAgendaInformation(String agendaName, String agendaNamespace, String agendaContext) throws Exception {
95          waitAndSelectByName(NEW_DATA_OBJ_PATH + "namespace", agendaNamespace);
96          waitAndTypeByName(NEW_DATA_OBJ_PATH + "agenda.name", agendaName);
97          waitAndTypeByName(NEW_DATA_OBJ_PATH + "contextName", agendaContext);
98      }
99  
100     protected void addNewAgendaRuleInformation(String ruleType, String ruleTypeCode, String ruleName) throws Exception {
101         waitAndSelectByName(NEW_DATA_OBJ_PATH + "agendaItemLine.rule.typeId", ruleType);
102 
103         if (StringUtils.isNotBlank(ruleTypeCode)) {
104             waitAndSelectByName(NEW_DATA_OBJ_PATH + "customRuleAttributesMap[ruleTypeCode]", ruleTypeCode);
105         }
106 
107         // validate that Type selected is Validation Rule
108         assertTrue("Expected ruleTypeCode dropdown value not found ",isElementPresentByXpath(
109                 "//option[@selected='selected' and @value='1002']"));
110 
111         waitAndTypeByName(NEW_DATA_OBJ_PATH + "agendaItemLine.rule.name", ruleName);
112     }
113 
114     protected void addRulePropositionInfo(String childIndex, String description, String category, String propTerm,
115             String propComparison, String propositionValue) throws Exception {
116         String propTreeRootPath = NEW_DATA_OBJ_PATH + "agendaItemLine.rule.propositionTree.rootElement.";
117         String propTreeChildPath = propTreeRootPath + "children[" + childIndex + "].";
118         String propositionPath = propTreeChildPath + "data.proposition.";
119 
120         if (StringUtils.isNoneBlank(description)) {
121             waitAndTypeByName(propositionPath + "description", description);
122         }
123 
124         if (StringUtils.isNoneBlank(category)) {
125             waitAndSelectByName(propositionPath + "categoryId", category);
126         }
127 
128         if (StringUtils.isNoneBlank(propTerm)) {
129             waitAndSelectByName(propositionPath + "parameters[0].value", propTerm);
130         }
131 
132         if (StringUtils.isNoneBlank(propComparison)) {
133             waitAndSelectByName(propositionPath + "parameters[2].value", propComparison);
134             unfocusElement();
135             Thread.sleep(1500); // need time for next input to be reloaded
136         }
137 
138         if (StringUtils.isNoneBlank(propositionValue)) {
139             waitAndTypeByName(propositionPath + "parameters[1].value", propositionValue);
140         }
141     }
142 
143     protected void addNewRuleActionInformation(String actionType, String actionName,
144             String actionDescription) throws Exception {
145         // select action elements
146         waitAndSelectByName(NEW_DATA_OBJ_PATH + "agendaItemLineRuleAction.typeId", actionType);
147         waitAndTypeByName(NEW_DATA_OBJ_PATH + "agendaItemLineRuleAction.name", actionName);
148         waitAndTypeByName(NEW_DATA_OBJ_PATH + "agendaItemLineRuleAction.description", actionDescription);
149     }
150 
151 
152     protected void unfocusElement() {
153         driver.switchTo().activeElement().sendKeys(Keys.TAB);
154     }
155 
156     /**
157      * test that a rule can be added to an agenda
158      */
159     @Test
160     public void testAgendaEditorAddRuleNav() throws Exception {
161         testAgendaEditorAddRuleWithSimpleProposition();
162     }
163 
164 }
165