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.lm.timeoff;
17  
18  import java.text.SimpleDateFormat;
19  import java.util.Calendar;
20  
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.hr.test.KPMETestCase;
24  import org.kuali.hr.time.test.HtmlUnitUtil;
25  import org.kuali.hr.time.test.TkTestConstants;
26  
27  import com.gargoylesoftware.htmlunit.html.HtmlElement;
28  import com.gargoylesoftware.htmlunit.html.HtmlForm;
29  import com.gargoylesoftware.htmlunit.html.HtmlInput;
30  import com.gargoylesoftware.htmlunit.html.HtmlPage;
31  
32  public class SystemScheduledTimeOffMaintTest extends KPMETestCase{
33  	private static final String EFFECTIVE_DATE_REQUIRED = "Effective Date (Effective Date) is a required field.";
34  	private static final String LEAVE_PLAN_REQUIRED = "Leave Plan (Leave Plan) is a required field.";
35  	private static final String ACCRUAL_CATEGORY_REQUIRED = "Accrual Category (Accrual Category) is a required field.";
36  	private static final String EARN_CODE_REQUIRED = "Earn Code (Earn Code) is a required field.";
37  	private static final String ACCRUED_DATE_REQUIRED = "Accrued Date (Accrued Date) is a required field.";
38  	private static final String LOCATION_REQUIRED = "Location (Location) is a required field.";
39  	private static final String DESCRIPTION_REQUIRED = "Description (Desc) is a required field.";
40  	private static final String AMOUNT_OF_TIME_REQUIRED = "Amount of Time (Amount of Time) is a required field.";
41  	private static final String PREMIUM_HOLIDAY_REQUIRED = "Premium Holiday (Premium Holiday) is a required field.";
42  	private static final String ACCRUED_DATE_PAST_ERROR = "'Accrued Date' needs to be a future date.";
43  	private static final String SCHEDULED_TO_DATE_PAST_ERROR = "'Scheduled Time Off Date' needs to be a future date.";
44  	private static final String SUCCESS_MESSAGE = "Document was successfully submitted.";
45  	private static final String ERROR_LEAVE_CODE = "The specified earnCode 'testLCL' does not exist";
46  	
47  	@Test
48  	public void testRequiredFields() throws Exception {
49  	  	String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
50  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
51  	  	Assert.assertNotNull(page);
52  	 
53  	  	HtmlForm form = page.getFormByName("KualiForm");
54  	  	Assert.assertNotNull("Search form was missing from page.", form);
55  	  	
56  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
57  	  	Assert.assertNotNull("Could not locate submit button", input);
58  	  	//default value for premium holiday is no
59  	  	Assert.assertTrue("Preminum Holiday is not default to No", page.getHtmlElementById("document.newMaintainableObject.premiumHolidayNo").asText().equals("checked"));
60  	  		  	
61  	  	HtmlElement element = page.getElementByName("methodToCall.route");
62  	  	page = element.click();
63  	  	Assert.assertTrue("page text does not contain:\n" + EFFECTIVE_DATE_REQUIRED, page.asText().contains(EFFECTIVE_DATE_REQUIRED));
64  	    Assert.assertTrue("page text does not contain:\n" + LEAVE_PLAN_REQUIRED, page.asText().contains(LEAVE_PLAN_REQUIRED));
65  	    Assert.assertTrue("page text does not contain:\n" + ACCRUAL_CATEGORY_REQUIRED, page.asText().contains(ACCRUAL_CATEGORY_REQUIRED));
66  	    Assert.assertTrue("page text does not contain:\n" + EARN_CODE_REQUIRED, page.asText().contains(EARN_CODE_REQUIRED));
67  	    
68  	    Assert.assertTrue("page text does not contain:\n" + ACCRUED_DATE_REQUIRED, page.asText().contains(ACCRUED_DATE_REQUIRED));
69  	    Assert.assertTrue("page text does not contain:\n" + LOCATION_REQUIRED, page.asText().contains(LOCATION_REQUIRED));
70  	    Assert.assertTrue("page text does not contain:\n" + DESCRIPTION_REQUIRED, page.asText().contains(DESCRIPTION_REQUIRED));
71  	    Assert.assertTrue("page text does not contain:\n" + AMOUNT_OF_TIME_REQUIRED, page.asText().contains(AMOUNT_OF_TIME_REQUIRED));
72  	    //there should be a default value for premium holiday
73  	    Assert.assertFalse("page text contains:\n" + PREMIUM_HOLIDAY_REQUIRED, page.asText().contains(PREMIUM_HOLIDAY_REQUIRED));
74  	}
75  	
76  	@Test
77  	public void testLookupPage() throws Exception {	 
78  		HtmlPage sstoLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.TIME_OFF_MAINT_URL);
79  		sstoLookup = HtmlUnitUtil.clickInputContainingText(sstoLookup, "search");
80  		HtmlUnitUtil.createTempFile(sstoLookup);
81  		Assert.assertTrue("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("TLC"));
82  		Assert.assertTrue("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("EC"));
83  		Assert.assertFalse("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("InactiveLP"));
84  
85  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(sstoLookup, "edit");
86  		Assert.assertTrue("Maintenance Page contains test SystemScheduledTimeOff",maintPage.asText().contains("EC"));	
87  	}
88  	
89  	@Test
90  	public void testErrorMessages() throws Exception {
91  	  	String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
92  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
93  	  	Assert.assertNotNull(page);
94  	 
95  	  	HtmlForm form = page.getFormByName("KualiForm");
96  	  	Assert.assertNotNull("Search form was missing from page.", form);
97  	  	setFieldValue(page, "document.documentHeader.documentDescription", "System Scheduled Time Off - test");
98  	  	// use past dates
99  	    setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2011");
100 	    setFieldValue(page, "document.newMaintainableObject.accruedDate", "04/01/2011");
101 	    setFieldValue(page, "document.newMaintainableObject.scheduledTimeOffDate", "04/01/2011");
102 	  	
103 	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
104 	  	Assert.assertNotNull("Could not locate submit button", input);
105 	  	HtmlElement element = page.getElementByName("methodToCall.route");
106 	  	page = element.click();
107 	  	Assert.assertTrue("page text does not contain:\n" + TkTestConstants.EFFECTIVE_DATE_ERROR, page.asText().contains(TkTestConstants.EFFECTIVE_DATE_ERROR));
108 	  	Assert.assertTrue("page text does not contain:\n" + ACCRUED_DATE_PAST_ERROR, page.asText().contains(ACCRUED_DATE_PAST_ERROR));
109 	  	Assert.assertTrue("page text does not contain:\n" + SCHEDULED_TO_DATE_PAST_ERROR, page.asText().contains(SCHEDULED_TO_DATE_PAST_ERROR));
110 	}
111 	
112 	@Test
113 	// test for jiar1363
114 	public void testGetLeavePlanAccrualCategoryFromSelectedEarnCode() throws Exception {
115 	  	String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
116 	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
117 	  	Assert.assertNotNull(page);
118 	 
119 	  	HtmlForm form = page.getFormByName("KualiForm");
120 	  	Assert.assertNotNull("Search form was missing from page.", form); 	
121 	  	
122 	  	Calendar validDate = Calendar.getInstance();
123 	  	// add 150 days in the future, need to add dates instead of month 
124 	  	// because if we happen to be running the test on the 31 of a month, some future months do not have 31st 
125 	  	validDate.add(Calendar.DATE, 150);   	
126 	  	String validDateString = new SimpleDateFormat("MM/dd/yyyy").format(validDate.getTime());
127 
128         setFieldValue(page, "document.documentHeader.documentDescription", "something clever...");
129 	  	setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString);
130 	    setFieldValue(page, "document.newMaintainableObject.earnCode", "EC");
131         setFieldValue(page, "document.newMaintainableObject.descr", "this is my description");
132         setFieldValue(page, "document.newMaintainableObject.amountofTime", "8");
133         setFieldValue(page, "document.newMaintainableObject.location", "CST");
134         setFieldValue(page, "document.newMaintainableObject.accruedDate", validDateString);
135 	    
136 	    page = ((HtmlElement)page.getElementByName("methodToCall.route")).click();
137 	    HtmlUnitUtil.createTempFile(page);
138 	    Assert.assertTrue("page text contains:\n" + "testLP", page.asText().contains("testLP"));
139 	    Assert.assertTrue("page text contains:\n" + "testAC", page.asText().contains("testAC"));
140 	}
141 	
142 	@Test
143 	//test for jiar1363
144 	public void testValidateLeaveCode() throws Exception {
145 	  	String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
146 	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
147 	  	Assert.assertNotNull(page);
148 	 
149 	  	HtmlForm form = page.getFormByName("KualiForm");
150 	  	Assert.assertNotNull("Search form was missing from page.", form); 	
151 	  	
152 	  	Calendar validDate = Calendar.getInstance();
153 	  	// add 150 days in the future, need to add dates instead of month 
154 	  	// because if we happen to be running the test on the 31 of a month, some future months do not have 31st 
155 	  	validDate.add(Calendar.DATE, 150);   	
156 	  	String validDateString = new SimpleDateFormat("MM/dd/yyyy").format(validDate.getTime());
157 	  	
158 	  	setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString);
159 	  	setFieldValue(page, "document.newMaintainableObject.earnCode", "testLCL"); 
160 	    
161 	    page = ((HtmlElement)page.getElementByName("methodToCall.route")).click();
162 	    HtmlUnitUtil.createTempFile(page);
163 	    Assert.assertTrue("page text does not contain:\n" + ERROR_LEAVE_CODE, page.asText().contains(ERROR_LEAVE_CODE));
164 	}
165 }