View Javadoc

1   /**
2    * Copyright 2004-2012 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.rule;
17  import org.junit.Assert;
18  import org.junit.Test;
19  import org.kuali.hr.test.KPMETestCase;
20  import org.kuali.hr.time.test.HtmlUnitUtil;
21  import org.kuali.hr.time.test.TkTestConstants;
22  
23  import com.gargoylesoftware.htmlunit.html.HtmlInput;
24  import com.gargoylesoftware.htmlunit.html.HtmlPage;
25  
26  public class DepartmentLunchRuleMaintTest extends KPMETestCase {
27  	
28  	private static final String TEST_CODE = "admin";		
29  	private static String TEST_CODE_DEPT_INVALID = "INVALID";
30  	private static Long TEST_CODE_WORKAREA_INVALID = 9999L;
31  	
32  	private static Long deptLunchRuleIdWithInvalidDept = 1L;	
33  	private static Long deptLunchRuleIdWithInvalidWorkArea = 3L;
34  
35  	/**
36  	 * Test to check whether it is showing error message for Department on maintenance screen
37  	 * if we supply non exist deptId
38  	 * 
39  	 * @throws Exception
40  	 */
41  	@Test
42  	public void testDepartmentLunchRuleMaintForDeptErrorMessage()
43  			throws Exception {
44  		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
45  				.gotoPageAndLogin(TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
46  		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
47  				departmentLunchRuleLookUp, "search");
48  		Assert.assertTrue("Page contains test DepartmentLunchRule",
49  				departmentLunchRuleLookUp.asText().contains(TEST_CODE));
50  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
51  				departmentLunchRuleLookUp, "edit",
52  				deptLunchRuleIdWithInvalidDept.toString());
53  		HtmlInput inputForDept = HtmlUnitUtil.getInputContainingText(maintPage,
54  				TEST_CODE_DEPT_INVALID);
55  		inputForDept.setValueAttribute(TEST_CODE_DEPT_INVALID);
56  		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
57  				maintPage, "* Document Description");
58  		inputForDescription.setValueAttribute("Description");
59  		HtmlPage resultantPageAfterEdit = HtmlUnitUtil
60  				.clickInputContainingText(maintPage, "submit");
61  		System.out.println(resultantPageAfterEdit.asText());
62  		Assert.assertTrue("Maintenance Page contains error message for dept",
63  				resultantPageAfterEdit.asText().contains(
64  						"The specified department '" + TEST_CODE_DEPT_INVALID
65  								+ "' does not exist."));
66  	}
67  
68  	/**
69  	 * Test to check whether it is showing error message for WorkArea on maintenance screen
70  	 * if we supply non exist workArea
71  	 * 
72  	 * @throws Exception
73  	 */
74  	@Test
75  	public void testDepartmentLunchRuleMaintForWorkAreaErrorMessage()
76  			throws Exception {
77  		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
78  				.gotoPageAndLogin(TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
79  		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
80  				departmentLunchRuleLookUp, "search");
81  		Assert.assertTrue("Page contains test DepartmentLunchRule",
82  				departmentLunchRuleLookUp.asText().contains(TEST_CODE));
83  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
84  				departmentLunchRuleLookUp, "edit",
85  				deptLunchRuleIdWithInvalidWorkArea.toString());
86  		HtmlUnitUtil.createTempFile(maintPage);
87  		
88  		HtmlInput inputForWorkArea = HtmlUnitUtil.getInputContainingText(maintPage,
89  				"newMaintainableObject.workArea");
90  		inputForWorkArea.setValueAttribute(Long.toString(TEST_CODE_WORKAREA_INVALID));
91  		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
92  				maintPage, "* Document Description");
93  		inputForDescription.setValueAttribute("Description");
94  		HtmlPage resultantPageAfterEdit = HtmlUnitUtil
95  				.clickInputContainingText(maintPage, "submit");		
96  		HtmlUnitUtil.createTempFile(resultantPageAfterEdit);
97  		Assert.assertTrue("Maintenance Page contains contains error message for workarea",
98  				resultantPageAfterEdit.asText().contains(
99  						"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 }