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