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.shiftdiff.rule;
17  
18  import java.math.BigDecimal;
19  import java.sql.Date;
20  import java.util.Calendar;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.kuali.hr.test.KPMETestCase;
25  import org.kuali.hr.time.test.HtmlUnitUtil;
26  import org.kuali.hr.time.test.TkTestConstants;
27  import org.kuali.rice.krad.service.KRADServiceLocator;
28  
29  import com.gargoylesoftware.htmlunit.html.HtmlElement;
30  import com.gargoylesoftware.htmlunit.html.HtmlForm;
31  import com.gargoylesoftware.htmlunit.html.HtmlInput;
32  import com.gargoylesoftware.htmlunit.html.HtmlPage;
33  
34  public class ShiftDifferentialRuleMaintTest extends KPMETestCase{
35  	private static final String TEST_CODE="_T";
36  		
37  	private static final BigDecimal TEST_NO=new BigDecimal(2);
38  	private static String shiftDifferentialRuleId;
39  
40  	
41  	
42  	@Test
43  	public void testShiftDifferentialRuleMaint() throws Exception {	 
44  		HtmlPage shiftDifferentialRuleLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.SHIFT_DIFFERENTIAL_RULE_MAINT_URL);
45  		shiftDifferentialRuleLookup = HtmlUnitUtil.clickInputContainingText(shiftDifferentialRuleLookup, "search");
46  		Assert.assertTrue("Page contains test Shift Differential Rule", shiftDifferentialRuleLookup.asText().contains(TEST_CODE.toString()));
47  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(shiftDifferentialRuleLookup, "edit",shiftDifferentialRuleId.toString());
48  		Assert.assertTrue("Maintenance Page contains test ShiftDifferentialRule",maintPage.asText().contains(TEST_CODE));	 
49  	}
50  	
51  	@Test
52  	public void testRequiredFields() throws Exception {
53  	  	String baseUrl = TkTestConstants.Urls.SHIFT_DIFFERENTIAL_RULE_MAINT_NEW_URL;
54  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
55  	  	Assert.assertNotNull(page);
56  	 
57  	  	HtmlForm form = page.getFormByName("KualiForm");
58  	  	Assert.assertNotNull("Search form was missing from page.", form);
59  	  	
60  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
61  	  	Assert.assertNotNull("Could not locate submit button", input);
62  	  	
63  	  	HtmlElement element = page.getElementByName("methodToCall.route");
64  	  	page = element.click();
65  	  	// the following fields should have default values
66  	  	String errorMessage = "Min. Hours (Min. Hours) is a required field.";
67  	  	Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
68  	    errorMessage = "Begin Time (00:00 AM) (Begin Time) is a required field.";
69  	    Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
70  	    errorMessage = "End Time (00:00 AM) (End Time) is a required field.";
71  	    Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
72  	    errorMessage = "Max. Gap Minutes (Max. Gap Minutes) is a required field.";
73  	    Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
74  	  	
75  	    //remove the default values
76  	  	setFieldValue(page, "document.newMaintainableObject.minHours", "");
77  	  	setFieldValue(page, "document.newMaintainableObject.beginTime", "");
78  	  	setFieldValue(page, "document.newMaintainableObject.endTime", "");
79  	  	setFieldValue(page, "document.newMaintainableObject.maxGap", "");
80  	  	element = page.getElementByName("methodToCall.route");
81  	  	HtmlPage nextPage = element.click();
82  	  	errorMessage = "Effective Date (Effective Date) is a required field.";
83  	  	Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
84  	    errorMessage = "Location (Location) is a required field.";
85  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
86  	    errorMessage = "Salary Group (Salary Group) is a required field.";
87  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
88  	    errorMessage = "Pay Grade (Pay Grade) is a required field.";
89  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
90  	    errorMessage = "Earn Code (Earn Code) is a required field.";
91  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
92  	    errorMessage = "From Earn Group (From Earn Group) is a required field.";
93  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
94  	    errorMessage = "Begin Time (00:00 AM) (Begin Time) is a required field.";
95  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
96  	    errorMessage = "End Time (00:00 AM) (End Time) is a required field.";
97  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
98  	    errorMessage = "Max. Gap Minutes (Max. Gap Minutes) is a required field.";
99  	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
100 	    errorMessage = "Pay Calendar Group (Pay Calendar Group) is a required field.";
101 	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
102 	    errorMessage = "Min. Hours (Min. Hours) is a required field.";
103 	    Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
104 	}
105 
106 
107 	@Override
108 	public void setUp() throws Exception {
109 		super.setUp();
110         Calendar yesterday = Calendar.getInstance();
111         yesterday.add(Calendar.DATE, -1);
112         Date testDate = new Date(yesterday.getTimeInMillis());
113 		ShiftDifferentialRule shiftDifferentialRule = new ShiftDifferentialRule();
114 		shiftDifferentialRule.setActive(true);
115 		//shiftDifferentialRule.setBeginTime(TEST_TIME);
116 		shiftDifferentialRule.setEarnCode(TEST_CODE);
117 		shiftDifferentialRule.setEffectiveDate(testDate);
118 		//shiftDifferentialRule.setEndTime(TEST_TIME);
119 		shiftDifferentialRule.setLocation(TEST_CODE);
120 		shiftDifferentialRule.setMaxGap(new BigDecimal(2));
121 		shiftDifferentialRule.setMinHours(TEST_NO);
122 		shiftDifferentialRule.setPayGrade(TEST_CODE);	
123 		shiftDifferentialRule.setPyCalendarGroup("BW-CAL");
124 		shiftDifferentialRule.setSunday(true);	
125 		shiftDifferentialRule.setMonday(true);
126 		shiftDifferentialRule.setTuesday(true);
127 		shiftDifferentialRule.setWednesday(true);
128 		shiftDifferentialRule.setThursday(true);
129 		shiftDifferentialRule.setFriday(true);
130 		shiftDifferentialRule.setSaturday(true);
131 		shiftDifferentialRule.setPyCalendarGroup("TEST");
132 		
133 		ShiftDifferentialRule rule = KRADServiceLocator.getBusinessObjectService().save(shiftDifferentialRule);
134 		shiftDifferentialRuleId = rule.getTkShiftDiffRuleId();
135 	}
136 
137 	@Override
138 	public void tearDown() throws Exception {				
139 		ShiftDifferentialRule shiftDifferentialRuleObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(ShiftDifferentialRule.class, shiftDifferentialRuleId);		 
140 		KRADServiceLocator.getBusinessObjectService().delete(shiftDifferentialRuleObj);
141 		super.tearDown();
142 	}
143 }
144