001/** 002 * Copyright 2005-2014 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.sampleu.main; 017 018import org.apache.commons.lang3.StringUtils; 019import org.junit.Test; 020import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils; 021import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 022import org.kuali.rice.testtools.selenium.WebDriverUtils; 023import org.openqa.selenium.Keys; 024 025/** 026 * test that checks that rules can be added to agendas 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030public class AgendaEditorAddRuleAft extends WebDriverLegacyITBase { 031 032 public static String KRAD_PORTAL_BASE = "/kr-krad/"; 033 public static String AGENDA_EDITOR_BASE = "krmsAgendaEditor"; 034 035 public static String NEW_DATA_OBJ_PATH = "document.newMaintainableObject.dataObject."; 036 037 public static final String BOOKMARK_URL = 038 AutomatedFunctionalTestUtils.PORTAL 039 + "?channelTitle=Agenda%20Lookup&channelUrl=" 040 + WebDriverUtils.getBaseUrlString() 041 + AutomatedFunctionalTestUtils.KRAD_LOOKUP_METHOD 042 + "org.kuali.rice.krms.impl.repository.AgendaBo" 043 + AutomatedFunctionalTestUtils.SHOW_MAINTENANCE_LINKS 044 + "&returnLocation=" 045 + AutomatedFunctionalTestUtils.PORTAL_URL 046 + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK; 047 048 @Override 049 protected String getBookmarkUrl() { 050 return BOOKMARK_URL; 051 } 052 053 @Override 054 protected void navigate() throws Exception { 055 waitAndClickByLinkText(AGENDA_LOOKUP_LINK_TEXT); 056 waitForPageToLoad(); 057 } 058 059 protected void testAgendaEditorAddRuleWithSimpleProposition() throws Exception { 060 String uniqId = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits(); 061 String agendaName = "AgendaEditorAddRuleAft " + uniqId; 062 String ruleName = "AgendaEditorAddRuleAft Rule " + "1" + " " + uniqId; 063 064 selectFrameIframePortlet(); 065 waitAndClickLinkContainingText("Create New"); 066 067 // add agenda information 068 String docId = waitForAgendaDocId(); 069 addNewAgendaInformation(agendaName, "Kuali Rules Test", "Context1"); 070 // dynamic agenda details 071 Thread.sleep(500); // tab is happening to fast 072 unfocusElement(); 073 unfocusElement(); 074 waitAndTypeByName(NEW_DATA_OBJ_PATH + "agenda.typeId", "Campus Agenda"); 075 unfocusElement(); 076 waitAndTypeByName(NEW_DATA_OBJ_PATH + "customAttributesMap[Campus]", "BL"); 077 waitAndClickButtonByText("Add Rule"); 078 079 // add agenda rule information 080 waitForPageToLoad(); 081 addNewAgendaRuleInformation("Validation Rule", "", ruleName); 082 waitAndClickButtonByExactText("Add"); // add proposition button 083 addRulePropositionInfo("0", "Campus must have students", "", "Bloomington Campus Size", ">", "1"); 084 addNewRuleActionInformation("KrmsActionResolverType", "test", "test"); 085 waitAndClickButtonByText("Add Rule"); 086 087 // validate rule exists 088 waitForTextPresent(ruleName); 089 waitAndClickSubmitByText(); 090 waitAndClickConfirmationOk(); 091 waitForTextPresent("Document was successfully submitted", WebDriverUtils.configuredImplicityWait() * 2); 092 assertDocSearch(docId, "FINAL"); 093 passed(); 094 } 095 096 097 protected void addNewAgendaInformation(String agendaName, String agendaNamespace, String agendaContext) throws Exception { 098 waitAndSelectByName(NEW_DATA_OBJ_PATH + "namespace", agendaNamespace); 099 waitAndTypeByName(NEW_DATA_OBJ_PATH + "agenda.name", agendaName); 100 waitAndTypeByName(NEW_DATA_OBJ_PATH + "contextName", agendaContext); 101 } 102 103 protected void addNewAgendaRuleInformation(String ruleType, String ruleTypeCode, String ruleName) throws Exception { 104 waitAndSelectByName(NEW_DATA_OBJ_PATH + "agendaItemLine.rule.typeId", ruleType); 105 106 if (StringUtils.isNotBlank(ruleTypeCode)) { 107 waitAndSelectByName(NEW_DATA_OBJ_PATH + "customRuleAttributesMap[ruleTypeCode]", ruleTypeCode); 108 } 109 110 // validate that Type selected is Validation Rule 111 assertTrue("Expected ruleTypeCode dropdown value not found ",isElementPresentByXpath( 112 "//option[@selected='selected' and @value='1002']")); 113 114 waitAndTypeByName(NEW_DATA_OBJ_PATH + "agendaItemLine.rule.name", ruleName); 115 } 116 117 protected void addRulePropositionInfo(String childIndex, String description, String category, String propTerm, 118 String propComparison, String propositionValue) throws Exception { 119 String propTreeRootPath = NEW_DATA_OBJ_PATH + "agendaItemLine.rule.propositionTree.rootElement."; 120 String propTreeChildPath = propTreeRootPath + "children[" + childIndex + "]."; 121 String propositionPath = propTreeChildPath + "data.proposition."; 122 123 if (StringUtils.isNoneBlank(description)) { 124 waitAndTypeByName(propositionPath + "description", description); 125 } 126 127 if (StringUtils.isNoneBlank(category)) { 128 waitAndSelectByName(propositionPath + "categoryId", category); 129 } 130 131 if (StringUtils.isNoneBlank(propTerm)) { 132 waitAndSelectByName(propositionPath + "parameters[0].value", propTerm); 133 } 134 135 if (StringUtils.isNoneBlank(propComparison)) { 136 waitAndSelectByName(propositionPath + "parameters[2].value", propComparison); 137 unfocusElement(); 138 Thread.sleep(3000); // need time for next input to be reloaded 139 } 140 141 if (StringUtils.isNoneBlank(propositionValue)) { 142 waitAndTypeByName(propositionPath + "parameters[1].value", propositionValue); 143 } 144 } 145 146 protected void addNewRuleActionInformation(String actionType, String actionName, 147 String actionDescription) throws Exception { 148 // select action elements 149 waitAndSelectByName(NEW_DATA_OBJ_PATH + "agendaItemLineRuleAction.typeId", actionType); 150 waitAndTypeByName(NEW_DATA_OBJ_PATH + "agendaItemLineRuleAction.name", actionName); 151 waitAndTypeByName(NEW_DATA_OBJ_PATH + "agendaItemLineRuleAction.description", actionDescription); 152 } 153 154 155 protected void unfocusElement() { 156 typeTab(); 157 } 158 159 /** 160 * test that a rule can be added to an agenda 161 */ 162 @Test 163 public void testAgendaEditorAddRuleNav() throws Exception { 164 testAgendaEditorAddRuleWithSimpleProposition(); 165 } 166 167} 168