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