1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.server;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.joda.time.DateTime;
20 import org.junit.Test;
21 import org.kuali.rice.core.api.delegation.DelegationType;
22 import org.kuali.rice.kew.actionitem.ActionItem;
23 import org.kuali.rice.kew.api.document.DocumentContentUpdate;
24 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
25 import org.kuali.rice.kew.dto.DTOConverter;
26 import org.kuali.rice.kew.rule.TestRuleAttribute;
27 import org.kuali.rice.kew.test.KEWTestCase;
28 import org.kuali.rice.kew.api.KewApiConstants;
29 import org.kuali.rice.kim.api.KimConstants;
30 import org.kuali.rice.kim.api.group.Group;
31 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32
33 import java.sql.Timestamp;
34 import java.util.Date;
35
36 import static org.junit.Assert.*;
37
38 public class DTOConverterTest extends KEWTestCase {
39
40 private static final String DOCUMENT_CONTENT = KewApiConstants.DOCUMENT_CONTENT_ELEMENT;
41 private static final String ATTRIBUTE_CONTENT = KewApiConstants.ATTRIBUTE_CONTENT_ELEMENT;
42 private static final String SEARCHABLE_CONTENT = KewApiConstants.SEARCHABLE_CONTENT_ELEMENT;
43 private static final String APPLICATION_CONTENT = KewApiConstants.APPLICATION_CONTENT_ELEMENT;
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 @Test public void testBuildUpdatedDocumentContent() throws Exception {
107 String startContent = "<"+DOCUMENT_CONTENT+">";
108 String endContent = "</"+DOCUMENT_CONTENT+">";
109
110
111
112
113
114
115
116 DocumentContentUpdate contentUpdate = DocumentContentUpdate.Builder.create().build();
117
118 String content = DTOConverter.buildUpdatedDocumentContent(KewApiConstants.DEFAULT_DOCUMENT_CONTENT, contentUpdate,
119 null);
120 assertEquals("Invalid content conversion.", StringUtils.deleteWhitespace(KewApiConstants.DEFAULT_DOCUMENT_CONTENT), StringUtils.deleteWhitespace(content));
121
122
123 String attributeContent = "<attribute1><id value=\"3\"/></attribute1>";
124 String searchableContent = "<searchable1><data>hello</data></searchable1>";
125 DocumentContentUpdate.Builder contentUpdateBuilder = DocumentContentUpdate.Builder.create();
126 contentUpdateBuilder.setAttributeContent(constructContent(ATTRIBUTE_CONTENT, attributeContent));
127 contentUpdateBuilder.setSearchableContent(constructContent(SEARCHABLE_CONTENT, searchableContent));
128 content = DTOConverter.buildUpdatedDocumentContent(KewApiConstants.DEFAULT_DOCUMENT_CONTENT, contentUpdateBuilder.build(), null);
129 String fullContent = startContent+"\n"+constructContent(ATTRIBUTE_CONTENT, attributeContent)+"\n"+constructContent(SEARCHABLE_CONTENT, searchableContent)+"\n"+endContent;
130 assertEquals("Invalid content conversion.", StringUtils.deleteWhitespace(fullContent), StringUtils.deleteWhitespace(content));
131
132
133 String testAttributeContent = new TestRuleAttribute().getDocContent();
134 WorkflowAttributeDefinition attributeDefinition = WorkflowAttributeDefinition.Builder.create("TestRuleAttribute").build();
135 contentUpdateBuilder.getAttributeDefinitions().add(attributeDefinition);
136 content = DTOConverter.buildUpdatedDocumentContent(KewApiConstants.DEFAULT_DOCUMENT_CONTENT, contentUpdateBuilder.build(), null);
137 fullContent = startContent+
138 constructContent(ATTRIBUTE_CONTENT, attributeContent+testAttributeContent)+
139 constructContent(SEARCHABLE_CONTENT, searchableContent)+
140 endContent;
141 assertEquals("Invalid content conversion.", StringUtils.deleteWhitespace(fullContent), StringUtils.deleteWhitespace(content));
142 }
143
144 private String constructContent(String type, String content) {
145 if (org.apache.commons.lang.StringUtils.isEmpty(content)) {
146 return "";
147 }
148 return "<"+type+">"+content+"</"+type+">";
149 }
150
151 private String constructContent(String attributeContent, String searchableContent, String applicationContent) {
152 return "<"+DOCUMENT_CONTENT+">"+
153 constructContent(ATTRIBUTE_CONTENT, attributeContent)+
154 constructContent(SEARCHABLE_CONTENT, searchableContent)+
155 constructContent(APPLICATION_CONTENT, applicationContent)+
156 "</"+DOCUMENT_CONTENT+">";
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178 @Test public void testConvertActionItem() throws Exception {
179
180 String testWorkgroupName = "TestWorkgroup";
181 Group testWorkgroup = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(
182 KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, testWorkgroupName);
183 String testWorkgroupId = testWorkgroup.getId();
184 assertTrue("Test workgroup '" + testWorkgroupName + "' should have at least one user", KimApiServiceLocator.getGroupService().getDirectMemberPrincipalIds(
185 testWorkgroup.getId()).size() > 0);
186 String workflowId = KimApiServiceLocator.getGroupService().getDirectMemberPrincipalIds(testWorkgroup.getId()).get(0);
187 assertNotNull("User from workgroup should not be null", workflowId);
188 String actionRequestCd = KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ;
189 String actionRequestId = "4";
190 String docName = "dummy";
191 String roleName = "fakeRole";
192 String documentId = "23";
193 Timestamp dateAssigned = new Timestamp(new Date().getTime());
194 String docHandlerUrl = "http://this.is.not.us";
195 String docTypeLabel = "Label Me";
196 String docTitle = "Title me";
197 String responsibilityId = "35";
198 DelegationType delegationType = DelegationType.PRIMARY;
199
200
201 ActionItem actionItem = new ActionItem();
202 actionItem.setActionRequestCd(actionRequestCd);
203 actionItem.setActionRequestId(actionRequestId);
204 actionItem.setDocName(docName);
205 actionItem.setRoleName(roleName);
206 actionItem.setPrincipalId(workflowId);
207 actionItem.setDocumentId(documentId);
208 actionItem.setDateAssigned(dateAssigned);
209 actionItem.setDocHandlerURL(docHandlerUrl);
210 actionItem.setDocLabel(docTypeLabel);
211 actionItem.setDocTitle(docTitle);
212 actionItem.setGroupId(testWorkgroupId);
213 actionItem.setResponsibilityId(responsibilityId);
214 actionItem.setDelegationType(delegationType);
215 actionItem.setDelegatorPrincipalId(workflowId);
216 actionItem.setDelegatorGroupId(testWorkgroupId);
217
218
219 org.kuali.rice.kew.api.action.ActionItem actionItemVO = ActionItem.to(actionItem);
220 assertEquals("Action Item VO object has incorrect value", actionRequestCd, actionItemVO.getActionRequestCd());
221 assertEquals("Action Item VO object has incorrect value", actionRequestId, actionItemVO.getActionRequestId());
222 assertEquals("Action Item VO object has incorrect value", docName, actionItemVO.getDocName());
223 assertEquals("Action Item VO object has incorrect value", roleName, actionItemVO.getRoleName());
224 assertEquals("Action Item VO object has incorrect value", workflowId, actionItemVO.getPrincipalId());
225 assertEquals("Action Item VO object has incorrect value", documentId, actionItemVO.getDocumentId());
226 assertEquals("Action Item VO object has incorrect value", new DateTime(dateAssigned.getTime()), actionItemVO.getDateTimeAssigned());
227 assertEquals("Action Item VO object has incorrect value", docHandlerUrl, actionItemVO.getDocHandlerURL());
228 assertEquals("Action Item VO object has incorrect value", docTypeLabel, actionItemVO.getDocLabel());
229 assertEquals("Action Item VO object has incorrect value", docTitle, actionItemVO.getDocTitle());
230 assertEquals("Action Item VO object has incorrect value", "" + testWorkgroupId, actionItemVO.getGroupId());
231 assertEquals("Action Item VO object has incorrect value", responsibilityId, actionItemVO.getResponsibilityId());
232 assertEquals("Action Item VO object has incorrect value", delegationType, actionItemVO.getDelegationType());
233 assertEquals("Action Item VO object has incorrect value", workflowId, actionItemVO.getDelegatorPrincipalId());
234 assertEquals("Action Item VO object has incorrect value", testWorkgroupId, actionItemVO.getDelegatorGroupId());
235 }
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 }