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