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.time.overtime.weekly;
017
018import java.math.BigDecimal;
019
020import org.joda.time.LocalDate;
021import org.junit.Assert;
022import org.junit.Test;
023import org.kuali.hr.KPMEWebTestCase;
024import org.kuali.hr.util.HtmlUnitUtil;
025import org.kuali.kpme.core.FunctionalTest;
026import org.kuali.kpme.core.util.TKUtils;
027import org.kuali.kpme.tklm.time.rules.overtime.weekly.WeeklyOvertimeRule;
028import org.kuali.kpme.tklm.utils.TkTestConstants;
029import org.kuali.rice.krad.service.KRADServiceLocator;
030
031import com.gargoylesoftware.htmlunit.html.HtmlElement;
032import com.gargoylesoftware.htmlunit.html.HtmlPage;
033import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
034
035@FunctionalTest
036public class WeeklyOvertimeRuleMaintenanceTest extends KPMEWebTestCase {
037        
038        protected static final String TEST_CODE="TST";
039        private static final BigDecimal TEST_NO=new BigDecimal(10);
040        private static String weeklyOvertimeRuleId;     
041        private static final LocalDate TEST_DATE = LocalDate.now();
042        
043        @Test
044        public void testWeeklyOvertimeRuleMaint() throws Exception {
045                HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_URL);
046                Assert.assertTrue("Maintenance Page contains test WeeklyOvertimeRule",maintPage.asText().contains(TEST_CODE));
047                
048                // test Convert from EarnCodeGroup has overtime earn codes error                
049                HtmlPage newMaintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_NEW_URL);
050                HtmlUnitUtil.setFieldValue(newMaintPage, "document.documentHeader.documentDescription", "Test");
051                HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.effectiveDate", "01/01/2010");
052                HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHoursEarnGroup", "REG");
053                HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertFromEarnGroup", "OVT");
054                HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertToEarnCode", "RGN");
055                HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.step", "1");
056                HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHours", "8");
057//              HtmlPage finalPage = HtmlUnitUtil.clickInputContainingText(newMaintPage, "add");
058                HtmlElement element = (HtmlElement)newMaintPage.getElementById("methodToCall.addLine.lstWeeklyOvertimeRules.(!!org.kuali.kpme.tklm.time.rules.overtime.weekly.WeeklyOvertimeRule!!)");
059        HtmlPage finalPage = element.click();
060                Assert.assertTrue("Maintenance Page should contains EarnCodeGroup has overtime earn code error",
061                                finalPage.asText().contains("Earn Group 'OVT' has overtime earn codes."));
062        }
063
064        @Override
065        public void setUp() throws Exception {
066                super.setUp();
067                WeeklyOvertimeRule weeklyOvertimeRule = new WeeklyOvertimeRule();
068                weeklyOvertimeRule.setActive(true);
069                weeklyOvertimeRule.setConvertFromEarnGroup(TEST_CODE);
070                weeklyOvertimeRule.setConvertToEarnCode(TEST_CODE);
071                weeklyOvertimeRule.setEffectiveLocalDate(TEST_DATE);
072                weeklyOvertimeRule.setMaxHours(TEST_NO);
073                weeklyOvertimeRule.setMaxHoursEarnGroup(TEST_CODE);
074                weeklyOvertimeRule.setStep(TEST_NO);
075                weeklyOvertimeRule.setTimestamp(TKUtils.getCurrentTimestamp());
076                weeklyOvertimeRule.setUserPrincipalId(TEST_CODE);       
077                KRADServiceLocatorWeb.getLegacyDataAdapter().save(weeklyOvertimeRule);
078                weeklyOvertimeRuleId=weeklyOvertimeRule.getTkWeeklyOvertimeRuleId();            
079        }
080
081        @Override
082        public void tearDown() throws Exception {       
083                //clean up
084                WeeklyOvertimeRule weeklyOvertimeRuleObj= KRADServiceLocatorWeb.getLegacyDataAdapter().findBySinglePrimaryKey(WeeklyOvertimeRule.class, weeklyOvertimeRuleId);
085                KRADServiceLocatorWeb.getLegacyDataAdapter().delete(weeklyOvertimeRuleObj);
086                super.tearDown();
087        }
088
089}