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