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