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