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.job;
17  
18  import java.sql.Date;
19  import java.sql.Time;
20  import java.sql.Timestamp;
21  import java.util.List;
22  
23  import junit.framework.Assert;
24  
25  import org.joda.time.DateTime;
26  import org.joda.time.DateTimeZone;
27  import org.junit.Test;
28  import org.kuali.hr.test.KPMETestCase;
29  import org.kuali.hr.time.calendar.Calendar;
30  import org.kuali.hr.time.calendar.CalendarEntries;
31  import org.kuali.hr.time.paytype.PayType;
32  import org.kuali.hr.time.service.base.TkServiceLocator;
33  import org.kuali.hr.time.test.HtmlUnitUtil;
34  import org.kuali.hr.time.test.TkTestConstants;
35  import org.kuali.hr.time.util.TKUtils;
36  import org.kuali.rice.krad.service.KRADServiceLocator;
37  
38  import com.gargoylesoftware.htmlunit.html.HtmlPage;
39  
40  /**
41   * This class needs refactored - the name job test implies that it should unit test on the Job object, especially considering it's package location.
42   *
43   *
44   */
45  public class JobTest extends KPMETestCase {
46  
47  	private static final String CALENDAR_GROUP = "BWN-CAL";
48  	private static Long jobId = 23L;//id entered in the bootstrap SQL
49  	private static Long jobNumber = 5L;//number entered in the bootstrap SQL
50  	public static final String TEST_USER = "admin";
51  
52  
53  	@Test
54  	public void testInsertPayCalendar() throws Exception {
55  		Calendar payCalendar = new Calendar();
56  		payCalendar.setHrCalendarId("1001");
57  		payCalendar.setCalendarName(CALENDAR_GROUP);
58  
59  		payCalendar.setFlsaBeginDay("Sun");
60  		payCalendar.setFlsaBeginTime(Time.valueOf("0:00:00"));
61          payCalendar.setCalendarDescriptions("Test Description");
62  
63  		KRADServiceLocator.getBusinessObjectService().save(payCalendar);
64  		Assert.assertTrue(TkServiceLocator.getCalendarService().getCalendar(payCalendar.getHrCalendarId()) != null);
65  
66  	}
67  
68  	@Test
69  	public void testInsertPayCalendarDates() throws Exception {
70  		CalendarEntries payCalendarDates = new CalendarEntries();
71  		payCalendarDates.setHrCalendarEntriesId("1001");
72  		payCalendarDates.setHrCalendarId("1001");
73  
74  		java.util.Calendar cal = java.util.Calendar.getInstance();
75  		cal.set(java.util.Calendar.MONTH, 7);
76  		cal.set(java.util.Calendar.DATE, 1);
77  		cal.set(java.util.Calendar.YEAR, 2010);
78  
79  		payCalendarDates.setBeginPeriodDateTime(new java.sql.Date(cal.getTime().getTime()));
80  		payCalendarDates.setCalendarName(CALENDAR_GROUP);
81  		cal.set(java.util.Calendar.DATE, 14);
82  		payCalendarDates.setEndPeriodDateTime(new java.sql.Date(cal.getTime().getTime()));
83  
84  		KRADServiceLocator.getBusinessObjectService().save(payCalendarDates);
85  		Assert.assertTrue(TkServiceLocator.getCalendarEntriesService().getCalendarEntries(payCalendarDates.getHrCalendarEntriesId()) != null);
86  
87  	}
88  
89  	@Test
90  	public void testInsertPayType() throws Exception {
91  
92  		long currentTimestamp = java.util.Calendar.getInstance().getTime().getTime();
93  
94  		PayType payType = new PayType();
95  		payType.setHrPayTypeId("1001");
96  		payType.setPayType("BW");
97  		payType.setRegEarnCode("RGN");
98  		payType.setEffectiveDate(new java.sql.Date(currentTimestamp));
99  		payType.setTimestamp(new Timestamp(currentTimestamp));
100 
101 		KRADServiceLocator.getBusinessObjectService().save(payType);
102 		Assert.assertTrue(TkServiceLocator.getPayTypeService().getPayType(payType.getPayType(), payType.getEffectiveDate()) != null);
103 	}
104 
105 	@Test
106 	public void jobMaintenancePage() throws Exception{
107 		HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.JOB_MAINT_URL);
108 		lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
109 		HtmlUnitUtil.createTempFile(lookupPage);
110 		Assert.assertTrue("Page contains admin entry", lookupPage.asText().contains("admin"));
111 		// xichen, changed to edit jobId 23, because clickAnchorContainingText() is a wild search. The test was editing jobId 1, it returned the first entry whose jobId starts with 1.
112 		HtmlPage editPage = HtmlUnitUtil.clickAnchorContainingText(lookupPage, "edit", jobId.toString());
113 		HtmlUnitUtil.createTempFile(editPage);
114 		Assert.assertTrue("Maintenance Page contains the correct job number", editPage.asText().contains(jobNumber.toString()));
115 	}
116 
117 	@Test
118 	public void testGetJobs() {
119 		Date payPeriodEndDate = new Date((new DateTime(2010,7,30,1,0,0,0, TKUtils.getSystemDateTimeZone())).getMillis());
120 		List<Job> jobs = TkServiceLocator.getJobService().getJobs(TEST_USER, payPeriodEndDate);
121 		Assert.assertNotNull("Jobs was null", jobs);
122 		Assert.assertEquals("Incorrect number of jobs", 2, jobs.size());
123 	}
124 
125 
126 	@Test
127 	public void testSaveAndFetchObject() throws Exception{
128 		//Confirming the save and fetch
129 		//save an object and confirm that it can be fetched
130 	}
131 
132 	@Test
133 	public void testMaintenancePageNew() throws Exception {
134 		//create new
135 		//input the data
136 		//confirm submit works
137 	}
138 
139 	@Test
140 	public void testMaintenancePageEdit() throws Exception {
141 		HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.JOB_MAINT_URL);
142 		lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
143 		HtmlPage editPage = HtmlUnitUtil.clickAnchorContainingText(lookupPage, "edit", jobId.toString());
144 		//input bad dept, sal group, job location, pay type, pay grade
145 		//submit
146 		//confirm each error shows up
147 
148 		//use each of the above lookups to populate the page
149 		//submit
150 		//confirm submit worked
151 
152 	}
153 }
154