1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.timesheet.web;
17
18 import java.sql.Date;
19 import java.util.*;
20
21 import org.joda.time.DateTime;
22 import org.json.simple.JSONArray;
23 import org.json.simple.JSONObject;
24 import org.json.simple.JSONValue;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.kuali.hr.time.assignment.Assignment;
28 import org.kuali.hr.time.calendar.CalendarEntries;
29 import org.kuali.hr.time.detail.web.TimeDetailActionFormBase;
30 import org.kuali.hr.time.earncode.EarnCode;
31 import org.kuali.hr.time.service.base.TkServiceLocator;
32 import org.kuali.hr.time.test.HtmlUnitUtil;
33 import org.kuali.hr.time.test.TkTestConstants;
34 import org.kuali.hr.time.test.TkTestUtils;
35 import org.kuali.hr.time.timesheet.TimesheetDocument;
36 import org.kuali.hr.time.util.*;
37 import org.kuali.hr.time.web.TkLoginFilter;
38
39 import com.gargoylesoftware.htmlunit.html.HtmlElement;
40 import com.gargoylesoftware.htmlunit.html.HtmlForm;
41 import com.gargoylesoftware.htmlunit.html.HtmlPage;
42 import org.kuali.hr.util.filter.TestAutoLoginFilter;
43
44 public class TimesheetWorkflowIntegrationTest extends TimesheetWebTestBase {
45
46 public static final String USER_PRINCIPAL_ID = "admin";
47 private Date JAN_AS_OF_DATE = new Date((new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
48
49
50
51
52
53 public void setUp() throws Exception {
54 super.setUp();
55
56
57
58
59
60 }
61
62 public void tearDown() throws Exception {
63 super.tearDown();
64 }
65
66 @Test
67
68
69
70
71
72
73
74
75
76
77
78 public void testTimesheetSubmissionIntegration() throws Exception {
79 Date asOfDate = new Date((new DateTime(2011, 3, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
80 CalendarEntries pcd = TkServiceLocator.getCalendarService().getCurrentCalendarDates(USER_PRINCIPAL_ID, asOfDate);
81 Assert.assertNotNull("No PayCalendarDates", pcd);
82 TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().openTimesheetDocument(USER_PRINCIPAL_ID, pcd);
83 String tdocId = tdoc.getDocumentId();
84 HtmlPage page = loginAndGetTimeDetailsHtmlPage("admin", tdocId, true);
85
86
87 List<Assignment> assignments = TkServiceLocator.getAssignmentService().getAssignments(TKContext.getPrincipalId(), JAN_AS_OF_DATE);
88 Assignment assignment = assignments.get(0);
89
90 List<EarnCode> earnCodes = TkServiceLocator.getEarnCodeService().getEarnCodes(assignment, JAN_AS_OF_DATE);
91 EarnCode earnCode = earnCodes.get(0);
92
93
94
95 DateTime start = new DateTime(2011, 3, 2, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone());
96 DateTime end = new DateTime(2011, 3, 3, 16, 0, 0, 0, TKUtils.getSystemDateTimeZone());
97
98 HtmlForm form = page.getFormByName("TimeDetailActionForm");
99 Assert.assertNotNull(form);
100
101
102
103 TimeDetailActionFormBase tdaf = TimeDetailTestUtils.buildDetailActionForm(tdoc, assignment, earnCode, start, end, null, true, null, true);
104 List<String> errors = TimeDetailTestUtils.setTimeBlockFormDetails(form, tdaf);
105
106 Assert.assertEquals("There should be no errors in this time detail submission", 0, errors.size());
107
108 page = TimeDetailTestUtils.submitTimeDetails(TimesheetWebTestBase.getTimesheetDocumentUrl(tdocId), tdaf);
109 Assert.assertNotNull(page);
110
111
112
113 String pageAsText = page.asText();
114
115
116
117
118
119
120 String dataText = page.getElementById("timeBlockString").getFirstChild().getNodeValue();
121 JSONArray jsonData = (JSONArray)JSONValue.parse(dataText);
122 final JSONObject jsonDataObject = (JSONObject) jsonData.get(0);
123 Assert.assertTrue("TimeBlock Data Missing.", checkJSONValues(new JSONObject() {{ put("outer", jsonDataObject); }},
124 new ArrayList<Map<String, Object>>() {{
125 add(new HashMap<String, Object>() {{
126 put("earnCode", "RGN");
127 put("hours", "8.0");
128 put("amount", null);
129 }});
130 }},
131 new HashMap<String, Object>() {{
132 put("earnCode", "RGN");
133 put("startNoTz", "2011-03-02T08:00:00");
134 put("endNoTz", "2011-03-02T16:00:00");
135 put("title", "SDR1 Work Area");
136 put("assignment", "30_30_30");
137 }}
138 ));
139
140
141 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("08:00 AM - 04:00 PM"));
142 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("RGN - 8.00 hours"));
143
144
145
146
147
148
149 HtmlElement routeButton = page.getElementById("ts-route-button");
150 String routeHref = TkTestUtils.getOnClickHref(routeButton);
151
152 page = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.BASE_URL + "/" + routeHref);
153
154 pageAsText = page.asText();
155
156 Assert.assertTrue("Wrong Document Loaded.", pageAsText.contains(tdocId));
157 Assert.assertTrue("Document not routed.", pageAsText.contains("Enroute"));
158 routeButton = page.getElementById("ts-route-button");
159 Assert.assertNull("Route button should not be present.", routeButton);
160 HtmlElement approveButton = page.getElementById("ts-approve-button");
161 Assert.assertNull("Approval button should not be present.", approveButton);
162
163
164
165 page = TimesheetWebTestBase.loginAndGetTimeDetailsHtmlPage("eric", tdocId, true);
166
167 pageAsText = page.asText();
168 Assert.assertTrue("Document not routed.", pageAsText.contains("Enroute"));
169 approveButton = page.getElementById("ts-approve-button");
170 Assert.assertNotNull("No approval button present.", approveButton);
171
172
173
174
175 routeHref = TkTestUtils.getOnClickHref(approveButton);
176 TestAutoLoginFilter.OVERRIDE_ID = "eric";
177 page = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.BASE_URL + "/" + routeHref);
178 TestAutoLoginFilter.OVERRIDE_ID = "";
179
180 pageAsText = page.asText();
181 Assert.assertTrue("Wrong Document Loaded.", pageAsText.contains(tdocId));
182 Assert.assertTrue("Login info not present.", pageAsText.contains("Employee Id:"));
183 Assert.assertTrue("Login info not present.", pageAsText.contains("eric, eric"));
184 Assert.assertTrue("Document not routed.", pageAsText.contains("Final"));
185 approveButton = page.getElementById("ts-approve-button");
186 Assert.assertNull("Approval button should not be present.", approveButton);
187 }
188
189 }