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