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.time.overtime.daily.rule;
017    
018    
019    import java.math.BigDecimal;
020    import java.util.HashMap;
021    
022    import org.junit.Assert;
023    import org.junit.Test;
024    import org.kuali.hr.test.KPMETestCase;
025    import org.kuali.hr.time.test.HtmlUnitUtil;
026    import org.kuali.hr.time.test.TkTestConstants;
027    import org.kuali.hr.time.util.TKUtils;
028    import org.kuali.rice.krad.service.KRADServiceLocator;
029    
030    import com.gargoylesoftware.htmlunit.html.HtmlInput;
031    import com.gargoylesoftware.htmlunit.html.HtmlPage;
032    
033    public class DailyOvertimeRuleMaintenanceTest extends KPMETestCase{
034                    
035            private static final String TEST_CODE="BL";             
036            private static String TEST_CODE_INVALID_DEPT_ID ="INVALID";
037            private static Long TEST_CODE_INVALID_TASK_ID =-1L;
038            private static Long TEST_CODE_INVALID_WORK_AREA_ID =-1L;        
039            private static String dailyOvertimeRuleId = "5";
040            
041            @Test
042            public void testDailyOvertimeRuleMaint() throws Exception {
043                    DailyOvertimeRule dor = new DailyOvertimeRule();
044                    HtmlPage dailyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.DAILY_OVERTIME_RULE_MAINT_URL);
045                    dailyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(dailyOvertimeRuleLookUp, "search");
046                    HtmlUnitUtil.createTempFile(dailyOvertimeRuleLookUp);
047                    Assert.assertTrue("Page contains test DailyOvertimeRule", dailyOvertimeRuleLookUp.asText().contains(TEST_CODE.toString()));             
048                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(dailyOvertimeRuleLookUp, "edit",dailyOvertimeRuleId.toString());            
049                    Assert.assertTrue("Maintenance Page contains test DailyOvertimeRule",maintPage.asText().contains(TEST_CODE.toString()));                
050            }
051            
052            @Test
053            public void testDailyOvertimeRuleMaintForErrorMessages() throws Exception {
054                    HtmlPage dailyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.DAILY_OVERTIME_RULE_MAINT_URL);
055                    dailyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(dailyOvertimeRuleLookUp, "search");
056                    Assert.assertTrue("Page contains test DailyOvertimeRule", dailyOvertimeRuleLookUp.asText().contains(TEST_CODE.toString()));             
057                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(dailyOvertimeRuleLookUp, "edit",dailyOvertimeRuleId.toString());            
058                    Assert.assertTrue("Maintenance Page contains test DailyOvertimeRule",maintPage.asText().contains(TEST_CODE.toString()));
059                    
060                    HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
061                                    maintPage, "* Document Description");
062                    inputForDescription.setValueAttribute("Test_Description");
063                    HtmlPage resultantPageAfterEdit = HtmlUnitUtil
064                                    .clickInputContainingText(maintPage, "submit");
065                    System.out.println(resultantPageAfterEdit.asText());
066                    Assert.assertTrue("Maintenance Page contains test deptErrormessage",
067                                    resultantPageAfterEdit.asText().contains(
068                                                    "The specified department '"
069                                                                    + TEST_CODE_INVALID_DEPT_ID
070                                                                    + "' does not exist."));
071                    
072                    // test Convert from EarnCodeGroup has overtime earn codes error
073                    setFieldValue(resultantPageAfterEdit, "document.newMaintainableObject.fromEarnGroup", "OVT");
074                    HtmlPage finalPage = HtmlUnitUtil.clickInputContainingText(resultantPageAfterEdit, "submit");
075                    Assert.assertTrue("Maintenance Page should contains EarnCodeGroup has overtime earn code error",
076                                    finalPage.asText().contains("Earn Group 'OVT' has overtime earn codes."));
077                    
078            }
079    
080            @Override
081            public void setUp() throws Exception {
082                    // TODO Auto-generated method stub
083                    super.setUp();
084                    DailyOvertimeRule dor = new DailyOvertimeRule();
085                    dor.setLocation("BL");
086                    dor.setPaytype("HR");
087                    dor.setEffectiveDate(TKUtils.getCurrentDate());
088                    dor.setUserPrincipalId("admin");
089                    dor.setDept(TEST_CODE_INVALID_DEPT_ID);
090                    dor.setWorkArea(TEST_CODE_INVALID_WORK_AREA_ID);
091                    dor.setMaxGap(new BigDecimal(1.0));
092                    dor.setMinHours(new BigDecimal(2));
093                    dor.setActive(true);
094                    dor.setFromEarnGroup("RGN");
095                    dor.setEarnCode("OVT");
096                    
097                    KRADServiceLocator.getBusinessObjectService().save(dor);
098                    dailyOvertimeRuleId = dor.getTkDailyOvertimeRuleId();
099            }
100    
101            @Override
102            public void tearDown() throws Exception {
103                    KRADServiceLocator.getBusinessObjectService().deleteMatching(DailyOvertimeRule.class, new HashMap());
104                    super.tearDown();
105            }
106    }
107