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