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.earncode.validation;
17  
18  import java.math.BigDecimal;
19  import java.sql.Date;
20  import java.sql.Timestamp;
21  import java.text.DateFormat;
22  import java.text.SimpleDateFormat;
23  import java.util.List;
24  
25  import com.gargoylesoftware.htmlunit.html.*;
26  import org.joda.time.DateTime;
27  import org.junit.Assert;
28  import org.junit.Test;
29  import org.kuali.hr.test.KPMETestCase;
30  import org.kuali.hr.time.earncode.EarnCode;
31  import org.kuali.hr.time.test.HtmlUnitUtil;
32  import org.kuali.hr.time.test.TkTestConstants;
33  import org.kuali.hr.time.timeblock.TimeBlock;
34  import org.kuali.hr.time.util.TKUtils;
35  import org.kuali.hr.time.util.TkConstants;
36  import org.kuali.rice.krad.service.KRADServiceLocator;
37  
38  public class EarnCodeMaintenaceTest extends KPMETestCase {
39  	private static final java.sql.Date TEST_DATE = new Date((new DateTime(2009, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
40  	private static final String EARN_CODE = "RGN";
41  	private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
42  	
43  	private static String hrEarnCodeId;
44  	private static String timeBlockId;
45  	
46  	@Override
47  	public void setUp() throws Exception {
48  		super.setUp();
49  		EarnCode earnCode = new EarnCode();
50  		earnCode.setActive(true);
51  		earnCode.setEarnCode(EARN_CODE);
52  		earnCode.setEffectiveDate(TEST_DATE);
53  		earnCode.setRecordMethod("T");
54  		earnCode.setFractionalTimeAllowed("99");
55  		earnCode.setRoundingOption("T");
56  		earnCode.setAffectPay("Y");
57  		earnCode.setWorkmansComp("Y");
58  		earnCode.setEligibleForAccrual("Y");
59  		earnCode.setAllowScheduledLeave("Y");
60  		earnCode.setFmla("Y");
61  		earnCode.setAllowNegativeAccrualBalance("Y");
62  		earnCode.setDescription("RGN Test");
63  		earnCode.setOvtEarnCode(false);
64  		earnCode.setInflateMinHours(BigDecimal.ZERO);
65  		earnCode.setInflateFactor(BigDecimal.ZERO);		
66  
67  		KRADServiceLocator.getBusinessObjectService().save(earnCode);	
68  		hrEarnCodeId = earnCode.getHrEarnCodeId();
69  		
70  		TimeBlock timeBlock = new TimeBlock();
71  		timeBlock.setAmount(BigDecimal.ONE);
72  		timeBlock.setAssignmentKey("somedesc");
73  		timeBlock.setJobNumber(new Long(30));
74  		timeBlock.setBeginDate(new java.sql.Date(DATE_FORMAT.parse("01/01/2010").getTime()));
75  		timeBlock.setEndDate(new java.sql.Date(DATE_FORMAT.parse("01/03/2010").getTime()));
76  		timeBlock.setBeginTimestamp(Timestamp.valueOf("2010-01-01 00:00:00.0"));
77  		timeBlock.setEndTimestamp(Timestamp.valueOf("2010-01-03 00:00:00.0"));
78  		timeBlock.setEarnCode(EARN_CODE);
79  		timeBlock.setWorkArea(new Long(20));
80  		timeBlock.setTask(new Long(15));
81  		timeBlock.setLunchDeleted(false);
82  		timeBlock.setBeginTimestampTimezone("TZ");
83  		timeBlock.setTimestamp(Timestamp.valueOf("2010-01-01 00:00:00.0"));
84  		timeBlock.setUserPrincipalId("princ");
85  		timeBlock.setHours(BigDecimal.TEN);
86  		timeBlock.setClockLogCreated(true);
87  		timeBlock.setDocumentId("10039");
88  
89  		KRADServiceLocator.getBusinessObjectService().save(timeBlock);
90  		timeBlockId = timeBlock.getTkTimeBlockId();
91  	}
92  
93  	@Override
94  	public void tearDown() throws Exception {
95  		EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
96  		KRADServiceLocator.getBusinessObjectService().delete(earnCodeObj);
97  		TimeBlock timeBlockObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(TimeBlock.class, timeBlockId);
98  		KRADServiceLocator.getBusinessObjectService().delete(timeBlockObj);
99  		super.tearDown();
100 	}
101 	
102 	 
103 	@Test
104 	public void testEditExistingEarnCode() throws Exception {
105 		HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.EARN_CODE_MAINT_URL);
106 		List<HtmlElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
107 		for(HtmlElement e : lstElements) {
108 			HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
109 			if(e.getAttribute("title").equals("Show History - Yes")) {
110 				radioButton.setChecked(true);	// set show history to yes
111 				break;
112 			}
113 		}
114 		earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
115 		Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));		
116 		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
117 		Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
118 		HtmlTextInput text  = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
119 		text.setValueAttribute("test");
120 		HtmlElement element = maintPage.getElementByName("methodToCall.route");
121         HtmlPage finalPage = element.click();
122 
123         Assert.assertTrue("Maintenance Page doesn't return warning about later effective date", finalPage.asText().contains("A record for this object exists with a later effective date"));
124         HtmlElement yesButton = finalPage.getElementByName("methodToCall.processAnswer.button0");
125         finalPage = yesButton.click();
126         Assert.assertTrue("Maintenance Page contains error messages", finalPage.asText().contains("There is a newer version of this Earn Code."));
127 	}
128 	
129 	@Test
130 	public void testDeactivateEarnCodeWithActiveTimeBlock() throws Exception {
131 		
132 		EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
133 		
134 		HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.EARN_CODE_MAINT_URL);
135 		List<HtmlElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
136 		for(HtmlElement e : lstElements) {
137 			HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
138 			if(e.getAttribute("title").equals("Show History - Yes")) {
139 				radioButton.setChecked(true);	// set show history to yes
140 				break;
141 			}
142 		}
143 		earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
144 		Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));		
145 		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
146 		Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
147 		HtmlTextInput text  = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
148 		text.setValueAttribute("test");
149 		HtmlCheckBoxInput active = (HtmlCheckBoxInput) maintPage.getHtmlElementById("document.newMaintainableObject.active");
150 		active.setChecked(false);
151 		HtmlTextInput effectiveDate = (HtmlTextInput) maintPage.getHtmlElementById("document.newMaintainableObject.effectiveDate");
152 		effectiveDate.setValueAttribute("01/02/2010");
153 		HtmlElement element = maintPage.getElementByName("methodToCall.route");
154         HtmlPage finalPage = element.click();
155         Assert.assertTrue("Maintenance Page does not return warning about active timeblock existence.", finalPage.asText().contains("Can not inactivate earn code 'RGN'. It is used in active time blocks"));
156 	}
157 	
158 	@Test
159 	public void testDeactivateEarnCodeWithInActiveTimeBlock() throws Exception {
160 		
161 		EarnCode earnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCode.class, hrEarnCodeId);
162 		
163 		HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.EARN_CODE_MAINT_URL);
164 		List<HtmlElement> lstElements = earnCodeLookUp.getElementsByIdAndOrName("history");
165 		for(HtmlElement e : lstElements) {
166 			HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) e;
167 			if(e.getAttribute("title").equals("Show History - Yes")) {
168 				radioButton.setChecked(true);	// set show history to yes
169 				break;
170 			}
171 		}
172 		earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
173 		Assert.assertTrue("Page contains test Earn Code", earnCodeLookUp.asText().contains("RGN Test"));		
174 		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", hrEarnCodeId.toString());
175 		Assert.assertTrue("Maintenance Page contains Test ",maintPage.asText().contains("RGN Test"));
176 		HtmlTextInput text  = (HtmlTextInput) maintPage.getHtmlElementById("document.documentHeader.documentDescription");
177 		text.setValueAttribute("test");
178 		HtmlCheckBoxInput active = (HtmlCheckBoxInput) maintPage.getHtmlElementById("document.newMaintainableObject.active");
179 		active.setChecked(false);
180 		HtmlTextInput effectiveDate = (HtmlTextInput) maintPage.getHtmlElementById("document.newMaintainableObject.effectiveDate");
181 		effectiveDate.setValueAttribute("01/04/2010");
182 		HtmlElement element = maintPage.getElementByName("methodToCall.route");
183         HtmlPage finalPage = element.click();
184         Assert.assertTrue("Maintenance Page should not return warning about active timeblock existence.", !finalPage.asText().contains("Can not inactivate earn code 'RGN'. It is used in active time blocks"));
185 	}
186 	
187 }