1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leaveCalendar;
17
18 import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
19 import com.gargoylesoftware.htmlunit.html.HtmlElement;
20 import com.gargoylesoftware.htmlunit.html.HtmlForm;
21 import com.gargoylesoftware.htmlunit.html.HtmlPage;
22 import org.apache.commons.lang.StringUtils;
23 import org.joda.time.DateTime;
24 import org.json.simple.JSONArray;
25 import org.json.simple.JSONObject;
26 import org.json.simple.JSONValue;
27 import org.junit.Assert;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.kuali.hr.TestAutoLoginFilter;
31 import org.kuali.hr.util.HtmlUnitUtil;
32 import org.kuali.kpme.core.FunctionalTest;
33 import org.kuali.kpme.core.api.assignment.Assignment;
34 import org.kuali.kpme.core.api.assignment.AssignmentDescriptionKey;
35 import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
36 import org.kuali.kpme.core.api.earncode.EarnCode;
37 import org.kuali.kpme.core.calendar.entry.CalendarEntryBo;
38 import org.kuali.kpme.core.service.HrServiceLocator;
39 import org.kuali.kpme.core.util.HrContext;
40 import org.kuali.kpme.core.util.TKUtils;
41 import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
42 import org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarWSForm;
43 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
44
45 import java.util.ArrayList;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Map;
49
50 import static org.junit.Assert.assertTrue;
51
52 @FunctionalTest
53 public class LeaveCalendarWorkflowIntegrationTest extends LeaveCalendarWebTestBase {
54
55 public static final String USER_PRINCIPAL_ID = "admin";
56 private DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
57
58 @Ignore
59 @Test
60
61
62
63
64
65
66
67
68
69
70
71 public void testLeaveCalendarSubmissionIntegration() throws Exception {
72 DateTime asOfDate = new DateTime(2011, 3, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone());
73 CalendarEntry pcd = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDatesForLeaveCalendar(USER_PRINCIPAL_ID, asOfDate);
74 Assert.assertNotNull("No CalendarEntry", pcd);
75 LeaveCalendarDocument tdoc = LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument(USER_PRINCIPAL_ID, pcd);
76 String tdocId = tdoc.getDocumentId();
77 HtmlPage page = loginAndGetLeaveCalendarHtmlPage("admin", tdocId, true);
78
79
80 Assignment assignment = HrServiceLocator.getAssignmentService().getAssignment(HrContext.getPrincipalId(), AssignmentDescriptionKey.get("IU-BL_30_30_30"), JAN_AS_OF_DATE.toLocalDate());
81 EarnCode earnCode = HrServiceLocator.getEarnCodeService().getEarnCode("VAC", JAN_AS_OF_DATE.toLocalDate());
82
83
84
85 DateTime start = new DateTime(2011, 3, 2, 8, 0, 0, 0, TKUtils.getSystemDateTimeZone());
86 DateTime end = new DateTime(2011, 3, 2, 16, 0, 0, 0, TKUtils.getSystemDateTimeZone());
87
88 HtmlForm form = page.getFormByName("LeaveCalendarForm");
89 Assert.assertNotNull(form);
90
91
92
93 LeaveCalendarWSForm tdaf = LeaveCalendarTestUtils.buildLeaveCalendarForm(tdoc, assignment, earnCode, start, end, null, true);
94 LeaveCalendarTestUtils.setTimeBlockFormDetails(form, tdaf);
95 page = LeaveCalendarTestUtils.submitLeaveCalendar(getWebClient(), getLeaveCalendarUrl(tdocId), tdaf);
96 Assert.assertNotNull(page);
97 HtmlUnitUtil.createTempFile(page, "LeaveBlockPresent");
98
99
100 String pageAsText = page.asText();
101
102
103
104
105
106
107 String dataText = page.getElementById("leaveBlockString").getFirstChild().getNodeValue();
108 JSONArray jsonData = (JSONArray)JSONValue.parse(dataText);
109 final JSONObject jsonDataObject = (JSONObject) jsonData.get(0);
110 Assert.assertTrue("leaveBlock Data Missing.", checkJSONValues(new JSONObject() {{ put("outer", jsonDataObject); }},
111 new ArrayList<Map<String, Object>>() {{
112 add(new HashMap<String, Object>() {{
113 put("earnCode", "VAC");
114 put("leaveAmount", "-8");
115 put("earnCode", "VAC");
116 put("leaveDate", "03/02/2011");
117
118 put("title", "SDR1 Work Area");
119 put("assignment", "IU-BL_30_30_30");
120 }});
121 }},
122 new HashMap<String, Object>() {{ }}
123 ));
124
125
126 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("SDR1 Work Area-SDR1 task"));
127 Assert.assertTrue("TimeBlock not Present.", pageAsText.contains("VAC (-8)"));
128
129
130
131
132
133
134 HtmlButtonInput routeButton = (HtmlButtonInput)page.getElementById("ts-route-button");
135 String routeHref = HtmlUnitUtil.getOnClickHref(routeButton);
136
137 page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getBaseURL() + "/" + routeHref);
138
139 pageAsText = page.asText();
140
141 Assert.assertTrue("Wrong Document Loaded.", pageAsText.contains(tdocId));
142 Assert.assertTrue("Document not routed.", pageAsText.contains("Enroute"));
143 routeButton = (HtmlButtonInput)page.getElementById("ts-route-button");
144 Assert.assertNull("Route button should not be present.", routeButton);
145 HtmlElement approveButton = (HtmlButtonInput)page.getElementById("ts-approve-button");
146 Assert.assertNull("Approval button should not be present.", approveButton);
147
148
149
150 page = loginAndGetLeaveCalendarHtmlPage("eric", tdocId, true);
151
152 pageAsText = page.asText();
153 Assert.assertTrue("Document not routed.", pageAsText.contains("Enroute"));
154 approveButton = (HtmlButtonInput)page.getElementById("ts-approve-button");
155 Assert.assertNotNull("No approval button present.", approveButton);
156
157
158
159
160 routeHref = HtmlUnitUtil.getOnClickHref(approveButton);
161 TestAutoLoginFilter.OVERRIDE_ID = "eric";
162 page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getBaseURL() + "/" + routeHref);
163 TestAutoLoginFilter.OVERRIDE_ID = "";
164
165 pageAsText = page.asText();
166 Assert.assertTrue("Wrong Document Loaded.", pageAsText.contains(tdocId));
167 Assert.assertTrue("Login info not present.", pageAsText.contains("Employee Id:"));
168 Assert.assertTrue("Login info not present.", pageAsText.contains("eric, eric"));
169 Assert.assertTrue("Document not routed.", pageAsText.contains("Final"));
170 approveButton = (HtmlElement)page.getElementById("ts-approve-button");
171 Assert.assertNull("Approval button should not be present.", approveButton);
172 }
173
174 @Ignore
175 @Test
176 public void testRedirectionForBalanceTransferOnLeaveApprove() throws Exception {
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 assertTrue("Dummy assertion 2", true);
227
228 }
229
230
231
232
233
234
235
236
237
238
239 public static boolean checkJSONValues(JSONObject json, List<Map<String,Object>> thdList, Map<String,Object> checkValues) {
240 boolean contains = false;
241
242 for(Object eso : json.entrySet()) {
243
244 Map.Entry e = (Map.Entry)eso;
245 JSONObject innerMap = (JSONObject)e.getValue();
246 boolean localContains = true;
247 for (Map.Entry<String,Object> cve : checkValues.entrySet()) {
248 Object joValue = innerMap.get(cve.getKey());
249 Object cvValue = cve.getValue();
250
251
252 if (cvValue == null && joValue == null)
253 localContains &= true;
254 else if (joValue == null || cvValue == null)
255 localContains = false;
256 else
257 localContains &= StringUtils.equals(joValue.toString(), cvValue.toString());
258 }
259
260 contains |= localContains;
261 }
262
263 return contains;
264 }
265
266 public static boolean checkJSONValues(String json, List<Map<String,Object>> thdList, Map<String,Object> checkValues) {
267 return checkJSONValues((JSONObject)JSONValue.parse(json), thdList, checkValues);
268 }
269 }