1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  
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;
49  	private static Long jobNumber = 5L;
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(getWebClient(), 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 		
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 		
129 		
130 	}
131 
132 	@Test
133 	public void testMaintenancePageNew() throws Exception {
134 		
135 		
136 		
137 	}
138 
139 	@Test
140 	public void testMaintenancePageEdit() throws Exception {
141 		HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.JOB_MAINT_URL);
142 		lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
143 		HtmlPage editPage = HtmlUnitUtil.clickAnchorContainingText(lookupPage, "edit", jobId.toString());
144 		
145 		
146 		
147 
148 		
149 		
150 		
151 
152 	}
153 }
154