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