001 /** 002 * Copyright 2004-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 */ 016 package org.kuali.hr.lm.leaveplan; 017 018 import junit.framework.Assert; 019 020 import org.junit.Test; 021 import org.kuali.hr.test.KPMETestCase; 022 import org.kuali.hr.time.test.HtmlUnitUtil; 023 import org.kuali.hr.time.test.TkTestConstants; 024 025 import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; 026 import com.gargoylesoftware.htmlunit.html.HtmlInput; 027 import com.gargoylesoftware.htmlunit.html.HtmlPage; 028 029 public class LeavePlanMaintTest extends KPMETestCase { 030 031 public static final String TEST_USER = "admin"; 032 033 034 035 @Test 036 public void testLeavePlanMonthsSave() throws Exception { 037 038 //get the page with planning months 039 HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_PLAN_MAINT_URL); 040 System.out.println("Leave plan text page is : "+leavePlan.asText()); 041 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search"); 042 HtmlUnitUtil.createTempFile(resultPage); 043 System.out.println("Result page is : "+resultPage.asText()); 044 Assert.assertTrue("Maintenance page contains:\n" + "Testing Leave Plan Months", resultPage.asText().contains("Testing Leave Plan Months")); 045 046 //submit a leave plan with planning months changed 047 HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "5555"); 048 setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "LeavePlan change planningMonths - test"); 049 setFieldValue(leavePlanMaintPage, "document.newMaintainableObject.effectiveDate", "01/01/2013"); 050 HtmlInput planningMonthsText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.planningMonths"); 051 052 // KPME- Kagata - value is between 1 and 24 now 053 planningMonthsText.setValueAttribute("999"); //max value 054 HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit"); 055 HtmlUnitUtil.createTempFile(outputPage); 056 //assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted")); 057 //assertTrue("Maintenance page contains:\n" + "Planning Months changed to 999", outputPage.asText().contains("999")); 058 Assert.assertTrue("Maintenance page text contains:\n" + "\'Planning Months\' should be between 1 and 24", outputPage.asText().contains("\'Planning Months\' should be between 1 and 24")); 059 060 planningMonthsText.setValueAttribute("0"); 061 outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit"); 062 HtmlUnitUtil.createTempFile(outputPage); 063 Assert.assertTrue("Maintenance page text contains:\n" + "\'Planning Months\' should be between 1 and 24", outputPage.asText().contains("\'Planning Months\' should be between 1 and 24")); 064 065 planningMonthsText.setValueAttribute("24"); 066 outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit"); 067 HtmlUnitUtil.createTempFile(outputPage); 068 Assert.assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted")); 069 Assert.assertTrue("Maintenance page contains:\n" + "Planning Months changed to 24", outputPage.asText().contains("24")); 070 071 } 072 073 // KPME-1250 Kagata 074 @Test 075 public void testInactivateLeavePlan() throws Exception { 076 077 //get the page with planning months 078 HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_PLAN_MAINT_URL); 079 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search"); 080 HtmlUnitUtil.createTempFile(resultPage); 081 Assert.assertTrue("Maintenance page contains:\n" + "Testing LP Inactive Flag", resultPage.asText().contains("Testing LP Inactive Flag")); 082 083 HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "2000"); 084 setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "LeavePlan change active flag"); 085 HtmlCheckBoxInput activeCheckbox = (HtmlCheckBoxInput) HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.active"); 086 activeCheckbox.setChecked(false); 087 088 HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit"); 089 HtmlUnitUtil.createTempFile(outputPage); 090 091 } 092 093 // KPME-1489 Kagata 094 @Test 095 public void testRequiredFields() throws Exception { 096 097 //get the page with planning months 098 HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_PLAN_MAINT_URL); 099 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search"); 100 HtmlUnitUtil.createTempFile(resultPage); 101 Assert.assertTrue("Maintenance page contains:\n" + "Testing Leave Plan Months", resultPage.asText().contains("Testing Leave Plan Months")); 102 103 HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "5555"); 104 //submit a leave plan with planning months changed 105 setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "Testing required fields"); 106 HtmlInput planningMonthsText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.planningMonths"); 107 HtmlInput calendarYearStartText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.calendarYearStart"); 108 109 planningMonthsText.setValueAttribute(""); 110 calendarYearStartText.setValueAttribute(""); 111 HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit"); 112 HtmlUnitUtil.createTempFile(outputPage); 113 Assert.assertTrue("Maintenance page text contains:\n" + "Planning Months (Planning Months) is a required field", outputPage.asText().contains("Planning Months (Planning Months) is a required field")); 114 Assert.assertTrue("Maintenance page text contains:\n" + "Calendar Year Start (MM/DD) (Calendar Year Start (MM/DD)) is a required field", outputPage.asText().contains("Calendar Year Start (MM/DD) (Calendar Year Start (MM/DD)) is a required field")); 115 116 setFieldValue(outputPage, "document.newMaintainableObject.effectiveDate", ""); 117 HtmlPage page = HtmlUnitUtil.clickInputContainingText(outputPage, "submit"); 118 Assert.assertTrue("Maintenance page text contains:\n" + "Effective Date (Effective Date) is a required field.", page.asText().contains("Effective Date (Effective Date) is a required field.")); 119 Assert.assertFalse("Maintenance page text contains:\n" + "Incident Report", page.asText().contains("Incident Report ")); 120 121 } 122 123 124 }