1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.detail.web;
17
18 import java.sql.Date;
19 import java.util.List;
20
21 import org.joda.time.DateTime;
22 import org.junit.Assert;
23 import org.junit.Test;
24 import org.kuali.hr.test.KPMETestCase;
25 import org.kuali.hr.time.assignment.Assignment;
26 import org.kuali.hr.time.assignment.AssignmentDescriptionKey;
27 import org.kuali.hr.time.calendar.CalendarEntries;
28 import org.kuali.hr.time.earncode.EarnCode;
29 import org.kuali.hr.time.service.base.TkServiceLocator;
30 import org.kuali.hr.time.test.HtmlUnitUtil;
31 import org.kuali.hr.time.test.TkTestConstants;
32 import org.kuali.hr.time.timesheet.TimesheetDocument;
33 import org.kuali.hr.time.util.TKUtils;
34 import org.kuali.hr.time.util.TimeDetailTestUtils;
35
36 import com.gargoylesoftware.htmlunit.html.HtmlForm;
37 import com.gargoylesoftware.htmlunit.html.HtmlPage;
38
39 public class SimpleTimeEntryValidationTest extends KPMETestCase {
40
41 public static final String USER_PRINCIPAL_ID = "admin";
42 private Date JAN_AS_OF_DATE = new Date((new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
43 private Date CALENDAR_ENTRY_DATE = new Date((new DateTime(2011, 1, 15, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
44
45 @Test
46
47
48
49
50 public void testExample1ShouldBeValidationErrors() throws Exception {
51 CalendarEntries calendarEntry = TkServiceLocator.getCalendarService().getCurrentCalendarDates(USER_PRINCIPAL_ID, CALENDAR_ENTRY_DATE);
52 TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().openTimesheetDocument(USER_PRINCIPAL_ID, calendarEntry);
53
54 String baseUrl = TkTestConstants.Urls.TIME_DETAIL_URL + "?documentId=" + timesheetDocument.getDocumentId();
55 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
56 Assert.assertNotNull(page);
57 String pageAsText = page.asText();
58
59 Assert.assertTrue("Login info not present.", pageAsText.contains("Employee Id:"));
60 Assert.assertTrue("Login info not present.", pageAsText.contains("admin, admin"));
61
62 HtmlForm form = page.getFormByName("TimeDetailActionForm");
63 Assert.assertNotNull(form);
64
65
66 Assignment assignment = TkServiceLocator.getAssignmentService().getAssignment(USER_PRINCIPAL_ID, new AssignmentDescriptionKey("30_30_30"), JAN_AS_OF_DATE);
67 EarnCode earnCode = TkServiceLocator.getEarnCodeService().getEarnCode("RGN", JAN_AS_OF_DATE);
68
69
70
71
72 DateTime start = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
73 DateTime end = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
74
75
76
77 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(timesheetDocument, assignment, earnCode, start, end, null, false, null, true);
78 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
79
80
81 Assert.assertEquals("There should be 1 error in this time detail submission", 1, errors.size());
82 Assert.assertEquals("Error String Unexpected", "The start date/time is outside the pay period", errors.get(0));
83 }
84
85
86 @Test
87
88
89
90
91 public void testExample2AddValidTimeBlock() throws Exception {
92 CalendarEntries calendarEntry = TkServiceLocator.getCalendarService().getCurrentCalendarDates(USER_PRINCIPAL_ID, CALENDAR_ENTRY_DATE);
93 TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().openTimesheetDocument(USER_PRINCIPAL_ID, calendarEntry);
94
95 String baseUrl = TkTestConstants.Urls.TIME_DETAIL_URL + "?documentId=" + timesheetDocument.getDocumentId();
96 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
97 Assert.assertNotNull(page);
98
99 String pageAsText = page.asText();
100 Assert.assertTrue("Login info not present.", pageAsText.contains("Employee Id:"));
101 Assert.assertTrue("Login info not present.", pageAsText.contains("admin, admin"));
102
103 HtmlForm form = page.getFormByName("TimeDetailActionForm");
104 Assert.assertNotNull(form);
105
106
107 Assignment assignment = TkServiceLocator.getAssignmentService().getAssignment(USER_PRINCIPAL_ID, new AssignmentDescriptionKey("30_30_30"), JAN_AS_OF_DATE);
108 EarnCode earnCode = TkServiceLocator.getEarnCodeService().getEarnCode("RGN", JAN_AS_OF_DATE);
109
110
111
112 DateTime start = new DateTime(2011, 1, 18, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone());
113 DateTime end = new DateTime(2011, 1, 18, 10, 0, 0, 0, TKUtils.getSystemDateTimeZone());
114
115
116
117 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(timesheetDocument, assignment, earnCode, start, end, null, false, null, true);
118 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
119
120
121 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
122
123
124
125 page = TimeDetailTestUtils.submitTimeDetails(getWebClient(), baseUrl, tdaf);
126 Assert.assertNotNull(page);
127
128
129
130 pageAsText = page.asText();
131 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("08:00 AM - 10:00 AM"));
132 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("RGN - 2.00 hours"));
133 }
134
135
136 }