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     */
016    package org.kuali.hr.time.overtime.weekly;
017    
018    import java.math.BigDecimal;
019    
020    import org.joda.time.LocalDate;
021    import org.junit.Assert;
022    import org.junit.Test;
023    import org.kuali.hr.KPMEWebTestCase;
024    import org.kuali.hr.util.HtmlUnitUtil;
025    import org.kuali.kpme.core.FunctionalTest;
026    import org.kuali.kpme.core.util.TKUtils;
027    import org.kuali.kpme.tklm.time.rules.overtime.weekly.WeeklyOvertimeRule;
028    import org.kuali.kpme.tklm.utils.TkTestConstants;
029    import org.kuali.rice.krad.service.KRADServiceLocator;
030    
031    import com.gargoylesoftware.htmlunit.html.HtmlElement;
032    import com.gargoylesoftware.htmlunit.html.HtmlPage;
033    
034    @FunctionalTest
035    public 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    }