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