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.leavecode;
017    
018    import java.text.SimpleDateFormat;
019    import java.util.Calendar;
020    
021    import junit.framework.Assert;
022    
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    
028    import com.gargoylesoftware.htmlunit.html.HtmlElement;
029    import com.gargoylesoftware.htmlunit.html.HtmlForm;
030    import com.gargoylesoftware.htmlunit.html.HtmlPage;
031    
032    public class LeaveCodeMaintTest extends KPMETestCase{
033            private static final String SUCCESS_MESSAGE = "Document was successfully submitted.";
034            private static final String ERROR_MESSAGE_ALLOW_NEGATIVE_ACC_BAN_REQUIRED = "Allow Negative Accrual Balance (Allow Negative Accrual Balance) is a required field";//KPME-1350
035            
036            @Test
037            public void testLookupPage() throws Exception {  
038                    HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_CODE_MAINT_URL);
039                    lcLookup = HtmlUnitUtil.clickInputContainingText(lcLookup, "search");
040                    Assert.assertTrue("Page contains test Leave Code", lcLookup.asText().contains("testLC"));
041                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(lcLookup, "edit");
042                    Assert.assertTrue("Maintenance Page contains test Leave Code",maintPage.asText().contains("testLC"));    
043            }
044            
045            /*@Test
046             * do not need this test, KPME1466
047            public void testFutureEffectiveDate() throws Exception {
048                    this.futureEffectiveDateValidation(TkTestConstants.Urls.LEAVE_CODE_MAINT_NEW_URL);
049            }*/
050    
051            @Test
052            public void testGetLeavePlanBasedOnAccrualCategory() throws Exception {
053                    String baseUrl = TkTestConstants.Urls.LEAVE_CODE_MAINT_NEW_URL;
054                    HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
055                    Assert.assertNotNull(page);
056             
057                    HtmlForm form = page.getFormByName("KualiForm");
058                    Assert.assertNotNull("Search form was missing from page.", form);
059                    Assert.assertTrue("page text contains:\n" + "Leave Code Maintenance", page.asText().contains("Leave Code Maintenance"));
060                    Assert.assertTrue("page text contains:\n" + "Allow Scheduled Leave", page.asText().contains("Allow Scheduled Leave"));
061                    
062                    Calendar validDate = Calendar.getInstance();
063                    // add 150 days in the future, need to add dates instead of month 
064                    // because if we happen to be running the test on the 31 of a month, some future months do not have 31st 
065                    validDate.add(Calendar.DATE, 150);      
066                    String validDateString = new SimpleDateFormat("MM/dd/yyyy").format(validDate.getTime());
067                    
068                    setFieldValue(page, "document.documentHeader.documentDescription", "Leave Code - test");
069                setFieldValue(page, "document.newMaintainableObject.defaultAmountofTime", "25"); // a wrong default amount of time
070                setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString); // jira1360
071                setFieldValue(page, "document.newMaintainableObject.accrualCategory", "AC1"); // jira1360
072                
073                HtmlElement element = page.getElementByName("methodToCall.route");
074                    page = element.click();
075                    HtmlUnitUtil.createTempFile(page);
076                    Assert.assertTrue("page text contains:\n" + "should be between 0 and 24", page.asText().contains("should be between 0 and 24"));
077                    Assert.assertTrue("page text contains:\n" + "IU-SM", page.asText().contains("IU-SM"));
078                    Assert.assertTrue("page text contains:\n" + "IU-SM", page.asText().contains("Affect Pay"));
079            }
080    }