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