View Javadoc

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