001/** 002 * Copyright 2004-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 org.kuali.hr.lm.timeoff; 017 018import org.joda.time.LocalDate; 019import org.junit.Assert; 020import org.junit.Test; 021import org.kuali.hr.KPMEWebTestCase; 022import org.kuali.hr.util.HtmlUnitUtil; 023import org.kuali.kpme.core.FunctionalTest; 024import org.kuali.kpme.core.util.HrTestConstants; 025import org.kuali.kpme.core.util.TKUtils; 026import org.kuali.kpme.tklm.utils.TkTestConstants; 027 028import com.gargoylesoftware.htmlunit.html.HtmlElement; 029import com.gargoylesoftware.htmlunit.html.HtmlForm; 030import com.gargoylesoftware.htmlunit.html.HtmlInput; 031import com.gargoylesoftware.htmlunit.html.HtmlPage; 032 033@FunctionalTest 034public class SystemScheduledTimeOffMaintTest extends KPMEWebTestCase{ 035 private static final String EFFECTIVE_DATE_REQUIRED = "Effective Date (Effective Date) is a required field."; 036 private static final String LEAVE_PLAN_REQUIRED = "Leave Plan (Leave Plan) is a required field."; 037 private static final String ACCRUAL_CATEGORY_REQUIRED = "Accrual Category (Accrual Category) is a required field."; 038 private static final String EARN_CODE_REQUIRED = "Earn Code (Earn Code) is a required field."; 039 private static final String ACCRUED_DATE_REQUIRED = "Accrued Date (Accrued Date) is a required field."; 040 private static final String LOCATION_REQUIRED = "Location (Location) is a required field."; 041 private static final String DESCRIPTION_REQUIRED = "Description (Desc) is a required field."; 042 private static final String AMOUNT_OF_TIME_REQUIRED = "Amount of Time (Amount of Time) is a required field."; 043 private static final String PREMIUM_HOLIDAY_REQUIRED = "Premium Holiday (Premium Holiday) is a required field."; 044 private static final String ACCRUED_DATE_PAST_ERROR = "'Accrued Date' needs to be a future date."; 045 private static final String SCHEDULED_TO_DATE_PAST_ERROR = "'Scheduled Time Off Date' needs to be a future date."; 046 private static final String SUCCESS_MESSAGE = "Document was successfully submitted."; 047 private static final String ERROR_LEAVE_CODE = "The specified earnCode 'testLCL' does not exist"; 048 049 @Test 050 public void testRequiredFields() throws Exception { 051 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL; 052 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 053 Assert.assertNotNull(page); 054 055 HtmlForm form = page.getFormByName("KualiForm"); 056 Assert.assertNotNull("Search form was missing from page.", form); 057 058 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 059 Assert.assertNotNull("Could not locate submit button", input); 060 //default value for premium holiday is no 061 Assert.assertTrue("Preminum Holiday is not default to No", page.getHtmlElementById("document.newMaintainableObject.premiumHolidayNo").asText().equals("checked")); 062 063 HtmlElement element = page.getElementByName("methodToCall.route"); 064 page = element.click(); 065 Assert.assertTrue("page text does not contain:\n" + EFFECTIVE_DATE_REQUIRED, page.asText().contains(EFFECTIVE_DATE_REQUIRED)); 066 Assert.assertTrue("page text does not contain:\n" + LEAVE_PLAN_REQUIRED, page.asText().contains(LEAVE_PLAN_REQUIRED)); 067 Assert.assertTrue("page text does not contain:\n" + ACCRUAL_CATEGORY_REQUIRED, page.asText().contains(ACCRUAL_CATEGORY_REQUIRED)); 068 Assert.assertTrue("page text does not contain:\n" + EARN_CODE_REQUIRED, page.asText().contains(EARN_CODE_REQUIRED)); 069 070 Assert.assertTrue("page text does not contain:\n" + ACCRUED_DATE_REQUIRED, page.asText().contains(ACCRUED_DATE_REQUIRED)); 071 Assert.assertTrue("page text does not contain:\n" + LOCATION_REQUIRED, page.asText().contains(LOCATION_REQUIRED)); 072 Assert.assertTrue("page text does not contain:\n" + DESCRIPTION_REQUIRED, page.asText().contains(DESCRIPTION_REQUIRED)); 073 Assert.assertTrue("page text does not contain:\n" + AMOUNT_OF_TIME_REQUIRED, page.asText().contains(AMOUNT_OF_TIME_REQUIRED)); 074 //there should be a default value for premium holiday 075 Assert.assertFalse("page text contains:\n" + PREMIUM_HOLIDAY_REQUIRED, page.asText().contains(PREMIUM_HOLIDAY_REQUIRED)); 076 } 077 078 @Test 079 public void testLookupPage() throws Exception { 080 HtmlPage sstoLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.TIME_OFF_MAINT_URL); 081 sstoLookup = HtmlUnitUtil.clickInputContainingText(sstoLookup, "search"); 082 HtmlUnitUtil.createTempFile(sstoLookup); 083 Assert.assertTrue("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("TLC")); 084 Assert.assertTrue("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("EC")); 085 Assert.assertFalse("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("InactiveLP")); 086 087 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(sstoLookup, "edit"); 088 Assert.assertTrue("Maintenance Page contains test SystemScheduledTimeOff",maintPage.asText().contains("EC")); 089 } 090 091 @Test 092 public void testErrorMessages() throws Exception { 093 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL; 094 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 095 Assert.assertNotNull(page); 096 097 HtmlForm form = page.getFormByName("KualiForm"); 098 Assert.assertNotNull("Search form was missing from page.", form); 099 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "System Scheduled Time Off - test"); 100 // use past dates 101 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2011"); 102 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.accruedDate", "04/01/2011"); 103 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.scheduledTimeOffDate", "04/01/2011"); 104 105 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 106 Assert.assertNotNull("Could not locate submit button", input); 107 HtmlElement element = page.getElementByName("methodToCall.route"); 108 page = element.click(); 109 Assert.assertTrue("page text does not contain:\n" + HrTestConstants.EFFECTIVE_DATE_ERROR, page.asText().contains(HrTestConstants.EFFECTIVE_DATE_ERROR)); 110 Assert.assertTrue("page text does not contain:\n" + ACCRUED_DATE_PAST_ERROR, page.asText().contains(ACCRUED_DATE_PAST_ERROR)); 111 Assert.assertTrue("page text does not contain:\n" + SCHEDULED_TO_DATE_PAST_ERROR, page.asText().contains(SCHEDULED_TO_DATE_PAST_ERROR)); 112 } 113 114 @Test 115 // test for jiar1363 116 public void testGetLeavePlanAccrualCategoryFromSelectedEarnCode() throws Exception { 117 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL; 118 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 119 Assert.assertNotNull(page); 120 121 HtmlForm form = page.getFormByName("KualiForm"); 122 Assert.assertNotNull("Search form was missing from page.", form); 123 124 // add 150 days in the future, need to add dates instead of month 125 // because if we happen to be running the test on the 31 of a month, some future months do not have 31st 126 LocalDate validDate = LocalDate.now().plusDays(150); 127 String validDateString = TKUtils.formatDate(validDate); 128 129 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "something clever..."); 130 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString); 131 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "EC"); 132 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.descr", "this is my description"); 133 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountofTime", "8"); 134 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "CST"); 135 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.accruedDate", validDateString); 136 137 page = ((HtmlElement)page.getElementByName("methodToCall.route")).click(); 138 HtmlUnitUtil.createTempFile(page); 139 Assert.assertTrue("page text contains:\n" + "testLP", page.asText().contains("testLP")); 140 Assert.assertTrue("page text contains:\n" + "testAC", page.asText().contains("testAC")); 141 } 142 143 @Test 144 //test for jiar1363 145 public void testValidateLeaveCode() throws Exception { 146 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL; 147 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 148 Assert.assertNotNull(page); 149 150 HtmlForm form = page.getFormByName("KualiForm"); 151 Assert.assertNotNull("Search form was missing from page.", form); 152 153 // add 150 days in the future, need to add dates instead of month 154 // because if we happen to be running the test on the 31 of a month, some future months do not have 31st 155 LocalDate validDate = LocalDate.now().plusDays(150); 156 String validDateString = TKUtils.formatDate(validDate); 157 158 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString); 159 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "testLCL"); 160 161 page = ((HtmlElement)page.getElementByName("methodToCall.route")).click(); 162 HtmlUnitUtil.createTempFile(page); 163 Assert.assertTrue("page text does not contain:\n" + ERROR_LEAVE_CODE, page.asText().contains(ERROR_LEAVE_CODE)); 164 } 165}