View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.department.lunch;
17  import org.apache.log4j.Logger;
18  import org.junit.Assert;
19  import org.junit.Test;
20  import org.kuali.hr.KPMEWebTestCase;
21  import org.kuali.hr.util.HtmlUnitUtil;
22  import org.kuali.kpme.core.FunctionalTest;
23  import org.kuali.kpme.core.util.HrTestConstants;
24  import org.kuali.kpme.tklm.utils.TkTestConstants;
25  
26  import com.gargoylesoftware.htmlunit.html.HtmlInput;
27  import com.gargoylesoftware.htmlunit.html.HtmlPage;
28  
29  @FunctionalTest
30  public class DepartmentLunchRuleMaintTest extends KPMEWebTestCase {
31      private static final Logger LOG = Logger.getLogger(DepartmentLunchRuleMaintTest.class);
32      private static final String TEST_CODE = "admin";
33  	private static String TEST_CODE_DEPT_INVALID = "INVALID";
34  	private static Long TEST_CODE_WORKAREA_INVALID = 9999L;
35  	
36  	private static Long deptLunchRuleIdWithInvalidDept = 1L;	
37  	private static Long deptLunchRuleIdWithInvalidWorkArea = 2L;
38  
39  	/**
40  	 * Test to check whether it is showing error message for Department on maintenance screen
41  	 * if we supply non exist deptId
42  	 * 
43  	 * @throws Exception
44  	 */
45  	@Test
46  	public void testDepartmentLunchRuleMaintForDeptErrorMessage()
47  			throws Exception {
48  		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
49  				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
50  		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
51  				departmentLunchRuleLookUp, "search");
52  		Assert.assertTrue("Page contains test DepartmentLunchRule",
53  				departmentLunchRuleLookUp.asText().contains(TEST_CODE));
54  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
55  				departmentLunchRuleLookUp, "edit",
56  				deptLunchRuleIdWithInvalidDept.toString());
57  		HtmlUnitUtil.createTempFile(maintPage);
58  		
59  		HtmlInput inputForDept = HtmlUnitUtil.getInputContainingText(maintPage,
60  				"newMaintainableObject.dept");
61  		inputForDept.setValueAttribute(TEST_CODE_DEPT_INVALID);
62  		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
63  				maintPage, "* Document Description");
64  		inputForDescription.setValueAttribute("Description");
65  		HtmlPage resultantPageAfterEdit = HtmlUnitUtil
66  				.clickInputContainingText(maintPage, "submit");
67  		LOG.debug(resultantPageAfterEdit.asText());
68  		Assert.assertTrue("Maintenance Page contains error message for dept",
69  				resultantPageAfterEdit.asText().contains(
70  						"The specified department '" + TEST_CODE_DEPT_INVALID
71  								+ "' does not exist."));
72  	}
73  
74  	/**
75  	 * Test to check whether it is showing error message for WorkArea on maintenance screen
76  	 * if we supply non exist workArea
77  	 * 
78  	 * @throws Exception
79  	 */
80  	@Test
81  	public void testDepartmentLunchRuleMaintForWorkAreaErrorMessage()
82  			throws Exception {
83  		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
84  				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
85  		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
86  				departmentLunchRuleLookUp, "search");
87  		Assert.assertTrue("Page contains test DepartmentLunchRule",
88  				departmentLunchRuleLookUp.asText().contains(TEST_CODE));
89  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
90  				departmentLunchRuleLookUp, "edit",
91  				deptLunchRuleIdWithInvalidWorkArea.toString());
92  		HtmlUnitUtil.createTempFile(maintPage);
93  		
94  		HtmlUnitUtil.setFieldValue(maintPage, "document.newMaintainableObject.workArea", Long.toString(TEST_CODE_WORKAREA_INVALID));
95  //		HtmlInput inputForWorkArea = HtmlUnitUtil.getInputContainingText(maintPage,
96  //				"newMaintainableObject.workArea");
97  //		inputForWorkArea.setValueAttribute(Long.toString(TEST_CODE_WORKAREA_INVALID));
98  		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
99  				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 }