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.leaveplan;
017    
018    import junit.framework.Assert;
019    
020    import org.apache.log4j.Logger;
021    import org.junit.Test;
022    import org.kuali.hr.test.KPMETestCase;
023    import org.kuali.hr.time.test.HtmlUnitUtil;
024    import org.kuali.hr.time.test.TkTestConstants;
025    
026    import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
027    import com.gargoylesoftware.htmlunit.html.HtmlInput;
028    import com.gargoylesoftware.htmlunit.html.HtmlPage;
029    
030    public class LeavePlanMaintTest extends KPMETestCase {
031        private static final Logger LOG = Logger.getLogger(LeavePlanMaintTest.class);
032            public static final String TEST_USER = "admin";
033            
034            
035            
036            @Test
037            public void testLeavePlanMonthsSave() throws Exception {
038                    
039                    //get the page with planning months
040                    HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_PLAN_MAINT_URL);
041                    LOG.debug("Leave plan text page is : " + leavePlan.asText());
042                    HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search");
043                    HtmlUnitUtil.createTempFile(resultPage);
044                    LOG.debug("Result page is : "+resultPage.asText());
045                    Assert.assertTrue("Maintenance page contains:\n" + "Testing Leave Plan Months", resultPage.asText().contains("Testing Leave Plan Months"));
046                    
047                    //submit a leave plan with planning months changed
048                    HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "5555");
049                    setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "LeavePlan change planningMonths - test");
050                    setFieldValue(leavePlanMaintPage, "document.newMaintainableObject.effectiveDate", "01/01/2013");
051                    HtmlInput planningMonthsText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.planningMonths");
052                    
053                    // KPME- Kagata - value is between 1 and 24 now
054                    planningMonthsText.setValueAttribute("999"); //max value
055                    HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
056                    HtmlUnitUtil.createTempFile(outputPage);
057                    //assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted"));
058                    //assertTrue("Maintenance page contains:\n" + "Planning Months changed to 999", outputPage.asText().contains("999"));
059                    Assert.assertTrue("Maintenance page text contains:\n" + "\'Planning Months\' should be between 1 and 24", outputPage.asText().contains("\'Planning Months\' should be between 1 and 24"));
060                    
061                    planningMonthsText.setValueAttribute("0"); 
062                    outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
063                    HtmlUnitUtil.createTempFile(outputPage);
064                    Assert.assertTrue("Maintenance page text contains:\n" + "\'Planning Months\' should be between 1 and 24", outputPage.asText().contains("\'Planning Months\' should be between 1 and 24"));
065                    
066                    planningMonthsText.setValueAttribute("24"); 
067                    outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
068                    HtmlUnitUtil.createTempFile(outputPage);
069                    Assert.assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted"));
070                    Assert.assertTrue("Maintenance page contains:\n" + "Planning Months changed to 24", outputPage.asText().contains("24"));
071                    
072            }
073            
074            // KPME-1250 Kagata
075            @Test
076            public void testInactivateLeavePlan() throws Exception {
077                    
078                    //get the page with planning months
079                    HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_PLAN_MAINT_URL);
080                    HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search");
081                    HtmlUnitUtil.createTempFile(resultPage);
082                    Assert.assertTrue("Maintenance page contains:\n" + "Testing LP Inactive Flag", resultPage.asText().contains("Testing LP Inactive Flag"));
083                    
084                    HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "2000");
085                    setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "LeavePlan change active flag");
086                    HtmlCheckBoxInput activeCheckbox = (HtmlCheckBoxInput) HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.active");
087                    activeCheckbox.setChecked(false);
088                            
089                    HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
090                    HtmlUnitUtil.createTempFile(outputPage);
091                    
092            }
093            
094            // KPME-1489 Kagata
095            @Test
096            public void testRequiredFields() throws Exception {
097                    
098                    //get the page with planning months
099                    HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_PLAN_MAINT_URL);
100                    HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search");
101                    HtmlUnitUtil.createTempFile(resultPage);
102                    Assert.assertTrue("Maintenance page contains:\n" + "Testing Leave Plan Months", resultPage.asText().contains("Testing Leave Plan Months"));
103                    
104                    HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "5555");
105                    //submit a leave plan with planning months changed
106                    setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "Testing required fields");
107                    HtmlInput planningMonthsText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.planningMonths");
108                    HtmlInput calendarYearStartText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.calendarYearStart");
109                    
110                    planningMonthsText.setValueAttribute("");
111                    calendarYearStartText.setValueAttribute("");
112                    HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
113                    HtmlUnitUtil.createTempFile(outputPage);
114                    Assert.assertTrue("Maintenance page text contains:\n" + "Planning Months (Planning Months) is a required field", outputPage.asText().contains("Planning Months (Planning Months) is a required field"));
115                    Assert.assertTrue("Maintenance page text contains:\n" + "Calendar Year Start (MM/DD) (Calendar Year Start (MM/DD)) is a required field", outputPage.asText().contains("Calendar Year Start (MM/DD) (Calendar Year Start (MM/DD)) is a required field"));
116                    
117                    setFieldValue(outputPage, "document.newMaintainableObject.effectiveDate", "");
118                    HtmlPage page = HtmlUnitUtil.clickInputContainingText(outputPage, "submit");
119                    Assert.assertTrue("Maintenance page text contains:\n" + "Effective Date (Effective Date) is a required field.", page.asText().contains("Effective Date (Effective Date) is a required field."));
120                    Assert.assertFalse("Maintenance page text contains:\n" + "Incident Report", page.asText().contains("Incident Report "));
121                    
122            }
123            
124            
125    }