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.paycalendar.validation;
017    
018    import org.junit.Assert;
019    import org.junit.Test;
020    import org.kuali.hr.test.KPMETestCase;
021    import org.kuali.hr.time.test.HtmlUnitUtil;
022    import org.kuali.hr.time.test.TkTestConstants;
023    
024    import com.gargoylesoftware.htmlunit.html.HtmlElement;
025    import com.gargoylesoftware.htmlunit.html.HtmlPage;
026    import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
027    
028    public class PayCalendarEntriesMaintenaceTest extends KPMETestCase {
029            @Override
030            public void setUp() throws Exception {
031                    super.setUp();
032            }
033            
034            @Override
035            public void tearDown() throws Exception {
036                    super.tearDown();
037            }
038            
039            @Test
040            //tests PayCalendarEntriesRule
041            public void testSubmitPayCalendarEntriesMaint() throws Exception {
042            //String baseUrl = HtmlUnitUtil.getBaseURL() + "/kr/maintenance.do?businessObjectClassName=org.kuali.hr.time.paycalendar.PayCalendarEntries&methodToCall=start";
043                    String baseUrl = TkTestConstants.Urls.PAY_CALENDAR_ENTRIES_MAINT_NEW_URL;
044            HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
045            Assert.assertNotNull(page);
046    
047                    HtmlTextInput text  = (HtmlTextInput) page.getHtmlElementById("document.documentHeader.documentDescription");
048                    text.setValueAttribute("test");
049                    HtmlUnitUtil.createTempFile(page);
050                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "calendarName");
051                    text.setValueAttribute("TTT");  // set an invalid pay calendar          
052                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "beginPeriodDate");
053                    text.setValueAttribute("02/21/2011");           
054                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "beginPeriodTime");
055                    text.setValueAttribute("08:00 am");             
056                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "endPeriodDate");
057                    text.setValueAttribute("02/28/2011");           
058                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "endPeriodTime");
059                    text.setValueAttribute("08:00 am");    
060                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchInitiateDate");
061                    text.setValueAttribute("02/16/2011");           
062                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchInitiateTime");
063                    text.setValueAttribute("08:00 am");             
064                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchEndPayPeriodDate");
065                    text.setValueAttribute("02/21/2011");           
066                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchEndPayPeriodTime");
067                    text.setValueAttribute("08:00 am"); 
068                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchEmployeeApprovalDate");
069                    text.setValueAttribute("02/17/2011");           
070                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchEmployeeApprovalTime");
071                    text.setValueAttribute("08:00 am");
072                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchSupervisorApprovalDate");
073                    text.setValueAttribute("02/18/2011");           
074                    text  = (HtmlTextInput) page.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "batchSupervisorApprovalTime");
075                    text.setValueAttribute("08:00 am");
076                    
077                    HtmlElement element = page.getElementByName("methodToCall.route");
078            HtmlPage page1 = element.click();
079            HtmlUnitUtil.createTempFile(page1);
080                    // error for invalid pay calendar
081            Assert.assertTrue("Maintenance Page contains error messages", page1.asText().contains("You must specify a valid Calendar."));
082    
083                    text  = (HtmlTextInput) page1.getHtmlElementById(TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "calendarName");
084                    text.setValueAttribute("BW-CAL");       // set a valid pay calendar     
085            
086                    element = page1.getElementByName("methodToCall.route");
087            HtmlPage page2 = element.click();
088            Assert.assertTrue("Maintenance page is submitted successfully", page2.asText().contains("Document was successfully submitted."));
089            Assert.assertTrue("Maintenance page is submitted successfully", page2.asText().contains("Status:         FINAL"));
090            }
091    }