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