View Javadoc

1   /**
2    * Copyright 2004-2013 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.apache.log4j.Logger;
18  import org.junit.Assert;
19  import org.junit.Test;
20  import org.kuali.hr.test.KPMETestCase;
21  import org.kuali.hr.time.test.HtmlUnitUtil;
22  import org.kuali.hr.time.test.TkTestConstants;
23  
24  import com.gargoylesoftware.htmlunit.html.HtmlInput;
25  import com.gargoylesoftware.htmlunit.html.HtmlPage;
26  
27  public class DepartmentLunchRuleMaintTest extends KPMETestCase {
28      private static final Logger LOG = Logger.getLogger(DepartmentLunchRuleMaintTest.class);
29      private static final String TEST_CODE = "admin";
30  	private static String TEST_CODE_DEPT_INVALID = "INVALID";
31  	private static Long TEST_CODE_WORKAREA_INVALID = 9999L;
32  	
33  	private static Long deptLunchRuleIdWithInvalidDept = 1L;	
34  	private static Long deptLunchRuleIdWithInvalidWorkArea = 3L;
35  
36  	/**
37  	 * Test to check whether it is showing error message for Department on maintenance screen
38  	 * if we supply non exist deptId
39  	 * 
40  	 * @throws Exception
41  	 */
42  	@Test
43  	public void testDepartmentLunchRuleMaintForDeptErrorMessage()
44  			throws Exception {
45  		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
46  				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
47  		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
48  				departmentLunchRuleLookUp, "search");
49  		Assert.assertTrue("Page contains test DepartmentLunchRule",
50  				departmentLunchRuleLookUp.asText().contains(TEST_CODE));
51  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
52  				departmentLunchRuleLookUp, "edit",
53  				deptLunchRuleIdWithInvalidDept.toString());
54  		HtmlInput inputForDept = HtmlUnitUtil.getInputContainingText(maintPage,
55  				TEST_CODE_DEPT_INVALID);
56  		inputForDept.setValueAttribute(TEST_CODE_DEPT_INVALID);
57  		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
58  				maintPage, "* Document Description");
59  		inputForDescription.setValueAttribute("Description");
60  		HtmlPage resultantPageAfterEdit = HtmlUnitUtil
61  				.clickInputContainingText(maintPage, "submit");
62  		LOG.debug(resultantPageAfterEdit.asText());
63  		Assert.assertTrue("Maintenance Page contains error message for dept",
64  				resultantPageAfterEdit.asText().contains(
65  						"The specified department '" + TEST_CODE_DEPT_INVALID
66  								+ "' does not exist."));
67  	}
68  
69  	/**
70  	 * Test to check whether it is showing error message for WorkArea on maintenance screen
71  	 * if we supply non exist workArea
72  	 * 
73  	 * @throws Exception
74  	 */
75  	@Test
76  	public void testDepartmentLunchRuleMaintForWorkAreaErrorMessage()
77  			throws Exception {
78  		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
79  				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
80  		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
81  				departmentLunchRuleLookUp, "search");
82  		Assert.assertTrue("Page contains test DepartmentLunchRule",
83  				departmentLunchRuleLookUp.asText().contains(TEST_CODE));
84  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
85  				departmentLunchRuleLookUp, "edit",
86  				deptLunchRuleIdWithInvalidWorkArea.toString());
87  		HtmlUnitUtil.createTempFile(maintPage);
88  		
89  		HtmlInput inputForWorkArea = HtmlUnitUtil.getInputContainingText(maintPage,
90  				"newMaintainableObject.workArea");
91  		inputForWorkArea.setValueAttribute(Long.toString(TEST_CODE_WORKAREA_INVALID));
92  		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
93  				maintPage, "* Document Description");
94  		inputForDescription.setValueAttribute("Description");
95  		HtmlPage resultantPageAfterEdit = HtmlUnitUtil
96  				.clickInputContainingText(maintPage, "submit");		
97  		HtmlUnitUtil.createTempFile(resultantPageAfterEdit);
98  		Assert.assertTrue("Maintenance Page contains contains error message for workarea",
99  				resultantPageAfterEdit.asText().contains(
100 						"The specified workArea '" + TEST_CODE_WORKAREA_INVALID
101 								+ "' does not exist."));
102 	}
103 
104 	@Test
105 	public void testDepartmentLunchRuleMaintForMaxShiftHourErrorMessage() throws Exception {
106 		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
107 				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
108 		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
109 				departmentLunchRuleLookUp, "search");
110 		Assert.assertTrue("Page contains test DepartmentLunchRule",
111 				departmentLunchRuleLookUp.asText().contains(TEST_CODE));
112 		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
113 				departmentLunchRuleLookUp, "edit",
114 				deptLunchRuleIdWithInvalidWorkArea.toString());
115 		
116 		setFieldValue(maintPage, TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "shiftHours", "34");
117 		setFieldValue(maintPage, "document.documentHeader.documentDescription", "test");
118 		HtmlPage resultantPageAfterEdit = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");		
119 		HtmlUnitUtil.createTempFile(resultantPageAfterEdit);
120 		Assert.assertTrue("Maintenance Page contains contains error message for Shift Hours",
121 				resultantPageAfterEdit.asText().contains("Shift Hour cannot be greater than 24."));
122 	}
123 	
124 	@Test
125 	public void testDepartmentLunchRuleMaint() throws Exception {
126 		HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil
127 				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL);
128 		departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText(
129 				departmentLunchRuleLookUp, "search");
130 		Assert.assertTrue("Page contains test DepartmentLunchRule",
131 				departmentLunchRuleLookUp.asText().contains(
132 						TEST_CODE.toString()));
133 		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(
134 				departmentLunchRuleLookUp, "edit",
135 				deptLunchRuleIdWithInvalidDept.toString());
136 		Assert.assertTrue("Maintenance Page contains test DepartmentLunchRule",
137 				maintPage.asText().contains(TEST_CODE.toString()));
138 	}
139 }