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