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