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.time.department.lunch;
017    import org.apache.log4j.Logger;
018    import org.junit.Assert;
019    import org.junit.Test;
020    import org.kuali.hr.KPMEWebTestCase;
021    import org.kuali.hr.util.HtmlUnitUtil;
022    import org.kuali.kpme.core.FunctionalTest;
023    import org.kuali.kpme.core.util.HrTestConstants;
024    import org.kuali.kpme.tklm.utils.TkTestConstants;
025    
026    import com.gargoylesoftware.htmlunit.html.HtmlInput;
027    import com.gargoylesoftware.htmlunit.html.HtmlPage;
028    
029    @FunctionalTest
030    public class DepartmentLunchRuleMaintTest extends KPMEWebTestCase {
031        private static final Logger LOG = Logger.getLogger(DepartmentLunchRuleMaintTest.class);
032        private static final String TEST_CODE = "admin";
033            private static String TEST_CODE_DEPT_INVALID = "INVALID";
034            private static Long TEST_CODE_WORKAREA_INVALID = 9999L;
035            
036            private static Long deptLunchRuleIdWithInvalidDept = 1L;        
037            private static Long deptLunchRuleIdWithInvalidWorkArea = 2L;
038    
039            /**
040             * Test to check whether it is showing error message for Department on maintenance screen
041             * if we supply non exist deptId
042             * 
043             * @throws Exception
044             */
045            @Test
046            public void testDepartmentLunchRuleMaintForDeptErrorMessage()
047                            throws Exception {
048                    HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
049                                    .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
050                    departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
051                                    departmentLunchRuleLookUp, "search");
052                    Assert.assertTrue("Page contains test DepartmentLunchRule",
053                                    departmentLunchRuleLookUp.asText().contains(TEST_CODE));
054                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
055                                    departmentLunchRuleLookUp, "edit",
056                                    deptLunchRuleIdWithInvalidDept.toString());
057                    HtmlUnitUtil.createTempFile(maintPage);
058                    
059                    HtmlInput inputForDept = HtmlUnitUtil.getInputContainingText(maintPage,
060                                    "newMaintainableObject.dept");
061                    inputForDept.setValueAttribute(TEST_CODE_DEPT_INVALID);
062                    HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
063                                    maintPage, "* Document Description");
064                    inputForDescription.setValueAttribute("Description");
065                    HtmlPage resultantPageAfterEdit = HtmlUnitUtil
066                                    .clickInputContainingText(maintPage, "submit");
067                    LOG.debug(resultantPageAfterEdit.asText());
068                    Assert.assertTrue("Maintenance Page contains error message for dept",
069                                    resultantPageAfterEdit.asText().contains(
070                                                    "The specified department '" + TEST_CODE_DEPT_INVALID
071                                                                    + "' does not exist."));
072            }
073    
074            /**
075             * Test to check whether it is showing error message for WorkArea on maintenance screen
076             * if we supply non exist workArea
077             * 
078             * @throws Exception
079             */
080            @Test
081            public void testDepartmentLunchRuleMaintForWorkAreaErrorMessage()
082                            throws Exception {
083                    HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
084                                    .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
085                    departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
086                                    departmentLunchRuleLookUp, "search");
087                    Assert.assertTrue("Page contains test DepartmentLunchRule",
088                                    departmentLunchRuleLookUp.asText().contains(TEST_CODE));
089                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
090                                    departmentLunchRuleLookUp, "edit",
091                                    deptLunchRuleIdWithInvalidWorkArea.toString());
092                    HtmlUnitUtil.createTempFile(maintPage);
093                    
094                    HtmlUnitUtil.setFieldValue(maintPage, "document.newMaintainableObject.workArea", Long.toString(TEST_CODE_WORKAREA_INVALID));
095    //              HtmlInput inputForWorkArea = HtmlUnitUtil.getInputContainingText(maintPage,
096    //                              "newMaintainableObject.workArea");
097    //              inputForWorkArea.setValueAttribute(Long.toString(TEST_CODE_WORKAREA_INVALID));
098                    HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
099                                    maintPage, "* Document Description");
100                    inputForDescription.setValueAttribute("Description");
101                    HtmlPage resultantPageAfterEdit = HtmlUnitUtil
102                                    .clickInputContainingText(maintPage, "submit");         
103                    HtmlUnitUtil.createTempFile(resultantPageAfterEdit);
104                    Assert.assertTrue("Maintenance Page contains contains error message for workarea",
105                                    resultantPageAfterEdit.asText().contains(
106                                                    "The specified workArea '" + TEST_CODE_WORKAREA_INVALID
107                                                                    + "' does not exist."));
108            }
109    
110            @Test
111            public void testDepartmentLunchRuleMaintForMaxShiftHourErrorMessage() throws Exception {
112                    HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
113                                    .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
114                    departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
115                                    departmentLunchRuleLookUp, "search");
116                    Assert.assertTrue("Page contains test DepartmentLunchRule",
117                                    departmentLunchRuleLookUp.asText().contains(TEST_CODE));
118                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
119                                    departmentLunchRuleLookUp, "edit",
120                                    deptLunchRuleIdWithInvalidWorkArea.toString());
121                    
122                    HtmlUnitUtil.setFieldValue(maintPage, HrTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "shiftHours", "34");
123                    HtmlUnitUtil.setFieldValue(maintPage, "document.documentHeader.documentDescription", "test");
124                    HtmlPage resultantPageAfterEdit = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");           
125                    HtmlUnitUtil.createTempFile(resultantPageAfterEdit);
126                    Assert.assertTrue("Maintenance Page contains contains error message for Shift Hours",
127                                    resultantPageAfterEdit.asText().contains("Shift Hour cannot be greater than 24."));
128            }
129            
130            @Test
131            public void testDepartmentLunchRuleMaint() throws Exception {
132                    HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
133                                    .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
134                    departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
135                                    departmentLunchRuleLookUp, "search");
136                    Assert.assertTrue("Page contains test DepartmentLunchRule",
137                                    departmentLunchRuleLookUp.asText().contains(
138                                                    TEST_CODE.toString()));
139                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
140                                    departmentLunchRuleLookUp, "edit",
141                                    deptLunchRuleIdWithInvalidDept.toString());
142                    Assert.assertTrue("Maintenance Page contains test DepartmentLunchRule",
143                                    maintPage.asText().contains(TEST_CODE.toString()));
144            }
145    }