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