1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.rice.kew.server; |
17 |
|
|
18 |
|
|
19 |
|
import org.apache.commons.lang.StringUtils; |
20 |
|
import org.custommonkey.xmlunit.XMLAssert; |
21 |
|
import org.junit.Test; |
22 |
|
import org.kuali.rice.core.xml.XmlException; |
23 |
|
import org.kuali.rice.kew.actionitem.ActionItem; |
24 |
|
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
25 |
|
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
26 |
|
import org.kuali.rice.kew.dto.*; |
27 |
|
import org.kuali.rice.kew.rule.TestRuleAttribute; |
28 |
|
import org.kuali.rice.kew.test.KEWTestCase; |
29 |
|
import org.kuali.rice.kew.util.KEWConstants; |
30 |
|
import org.kuali.rice.kim.bo.Group; |
31 |
|
import org.kuali.rice.kim.service.KIMServiceLocator; |
32 |
|
import org.kuali.rice.kim.util.KimConstants; |
33 |
|
|
34 |
|
import java.sql.Timestamp; |
35 |
|
import java.util.Date; |
36 |
|
|
37 |
|
import static org.junit.Assert.*; |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 146 (146) |
Complexity: 12 |
Complexity Density: 0.09 |
|
39 |
|
public class DTOConverterTest extends KEWTestCase { |
40 |
|
|
41 |
|
private static final String DOCUMENT_CONTENT = KEWConstants.DOCUMENT_CONTENT_ELEMENT; |
42 |
|
private static final String ATTRIBUTE_CONTENT = KEWConstants.ATTRIBUTE_CONTENT_ELEMENT; |
43 |
|
private static final String SEARCHABLE_CONTENT = KEWConstants.SEARCHABLE_CONTENT_ELEMENT; |
44 |
|
private static final String APPLICATION_CONTENT = KEWConstants.APPLICATION_CONTENT_ELEMENT; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 2 |
Complexity Density: 0.06 |
4
-
|
|
50 |
0
|
@Test public void testConvertDocumentContent() throws Exception {... |
51 |
|
|
52 |
|
|
53 |
0
|
String attributeContent = null; |
54 |
0
|
String searchableContent = null; |
55 |
0
|
String applicationContent = null; |
56 |
0
|
String xmlContent = constructContent(attributeContent, searchableContent, applicationContent); |
57 |
0
|
DocumentContentDTO contentVO = DTOConverter.convertDocumentContent(xmlContent, new Long(-1234)); |
58 |
0
|
assertFalse("Content cannot be empty.", org.apache.commons.lang.StringUtils.isEmpty(contentVO.getFullContent())); |
59 |
0
|
assertEquals("Attribute content is invalid.", "", contentVO.getAttributeContent()); |
60 |
0
|
assertEquals("Searchable content is invalid.", "", contentVO.getSearchableContent()); |
61 |
0
|
assertEquals("Application content is invalid.", "", contentVO.getApplicationContent()); |
62 |
0
|
assertEquals("Should have fake document id.", new Long(-1234), contentVO.getRouteHeaderId()); |
63 |
|
|
64 |
|
|
65 |
0
|
attributeContent = ""; |
66 |
0
|
searchableContent = ""; |
67 |
0
|
applicationContent = ""; |
68 |
0
|
contentVO = DTOConverter.convertDocumentContent(constructContent(attributeContent, searchableContent, applicationContent), null); |
69 |
0
|
assertContent(contentVO, attributeContent, searchableContent, applicationContent); |
70 |
|
|
71 |
|
|
72 |
0
|
attributeContent = "<iEnjoyFlexContent><id>1234</id></iEnjoyFlexContent>"; |
73 |
0
|
searchableContent = "<thisIdBeWarrenG>Warren G</thisIdBeWarrenG><whatsMyName>Snoop</whatsMyName>"; |
74 |
0
|
applicationContent = "<thisIsTotallyRad><theCoolestContentInTheWorld qualify=\"iSaidSo\">it's marvelous!</theCoolestContentInTheWorld></thisIsTotallyRad>"; |
75 |
0
|
contentVO = DTOConverter.convertDocumentContent(constructContent(attributeContent, searchableContent, applicationContent), null); |
76 |
0
|
assertContent(contentVO, attributeContent, searchableContent, applicationContent); |
77 |
|
|
78 |
0
|
attributeContent = "invalid<xml, I can't believe you would do such a thing<<<"; |
79 |
0
|
try { |
80 |
0
|
contentVO = DTOConverter.convertDocumentContent(constructContent(attributeContent, searchableContent, applicationContent), null); |
81 |
0
|
fail("Parsing bad xml should have thrown an XmlException."); |
82 |
|
} catch (XmlException e) { |
83 |
0
|
log.info("Expected XmlException was thrown."); |
84 |
|
|
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
0
|
String appSpecificXml = "<iAmAnOldSchoolApp><myDocContent type=\"custom\">is totally app specific</myDocContent><howIroll>old school, that's how I roll</howIroll></iAmAnOldSchoolApp>"; |
89 |
0
|
contentVO = DTOConverter.convertDocumentContent(appSpecificXml, null); |
90 |
0
|
assertContent(contentVO, "", "", appSpecificXml); |
91 |
|
|
92 |
|
|
93 |
0
|
String fleXml = "<flexdoc><meinAttribute>nein</meinAttribute></flexdoc>"; |
94 |
0
|
contentVO = DTOConverter.convertDocumentContent(fleXml, null); |
95 |
0
|
assertFalse("Content cannot be empty.", org.apache.commons.lang.StringUtils.isEmpty(contentVO.getFullContent())); |
96 |
0
|
assertEquals("Attribute content is invalid.", StringUtils.deleteWhitespace(fleXml), StringUtils.deleteWhitespace(contentVO.getAttributeContent())); |
97 |
0
|
assertEquals("Searchable content is invalid.", "", StringUtils.deleteWhitespace(contentVO.getSearchableContent())); |
98 |
0
|
assertEquals("Application content is invalid.", "", StringUtils.deleteWhitespace(contentVO.getApplicationContent())); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
4
-
|
|
107 |
0
|
@Test public void testBuildUpdatedDocumentContent() throws Exception {... |
108 |
0
|
String startContent = "<"+DOCUMENT_CONTENT+">"; |
109 |
0
|
String endContent = "</"+DOCUMENT_CONTENT+">"; |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
0
|
DocumentContentDTO contentVO = new DocumentContentDTO(); |
118 |
|
|
119 |
0
|
String content = DTOConverter.buildUpdatedDocumentContent(contentVO); |
120 |
0
|
assertEquals("Invalid content conversion.", StringUtils.deleteWhitespace(KEWConstants.DEFAULT_DOCUMENT_CONTENT), StringUtils.deleteWhitespace(content)); |
121 |
|
|
122 |
|
|
123 |
0
|
String attributeContent = "<attribute1><id value=\"3\"/></attribute1>"; |
124 |
0
|
String searchableContent = "<searchable1><data>hello</data></searchable1>"; |
125 |
0
|
contentVO = new DocumentContentDTO(); |
126 |
0
|
contentVO.setAttributeContent(constructContent(ATTRIBUTE_CONTENT, attributeContent)); |
127 |
0
|
contentVO.setSearchableContent(constructContent(SEARCHABLE_CONTENT, searchableContent)); |
128 |
0
|
content = DTOConverter.buildUpdatedDocumentContent(contentVO); |
129 |
0
|
String fullContent = startContent+"\n"+constructContent(ATTRIBUTE_CONTENT, attributeContent)+"\n"+constructContent(SEARCHABLE_CONTENT, searchableContent)+"\n"+endContent; |
130 |
0
|
assertEquals("Invalid content conversion.", StringUtils.deleteWhitespace(fullContent), StringUtils.deleteWhitespace(content)); |
131 |
|
|
132 |
|
|
133 |
0
|
String testAttributeContent = new TestRuleAttribute().getDocContent(); |
134 |
0
|
WorkflowAttributeDefinitionDTO attributeDefinition = new WorkflowAttributeDefinitionDTO(TestRuleAttribute.class.getName()); |
135 |
0
|
contentVO.addAttributeDefinition(attributeDefinition); |
136 |
0
|
content = DTOConverter.buildUpdatedDocumentContent(contentVO); |
137 |
0
|
fullContent = startContent+ |
138 |
|
constructContent(ATTRIBUTE_CONTENT, attributeContent+testAttributeContent)+ |
139 |
|
constructContent(SEARCHABLE_CONTENT, searchableContent)+ |
140 |
|
endContent; |
141 |
0
|
assertEquals("Invalid content conversion.", StringUtils.deleteWhitespace(fullContent), StringUtils.deleteWhitespace(content)); |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
144 |
0
|
private String constructContent(String type, String content) {... |
145 |
0
|
if (org.apache.commons.lang.StringUtils.isEmpty(content)) { |
146 |
0
|
return ""; |
147 |
|
} |
148 |
0
|
return "<"+type+">"+content+"</"+type+">"; |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
0
|
private String constructContent(String attributeContent, String searchableContent, String applicationContent) {... |
152 |
0
|
return "<"+DOCUMENT_CONTENT+">"+ |
153 |
|
constructContent(ATTRIBUTE_CONTENT, attributeContent)+ |
154 |
|
constructContent(SEARCHABLE_CONTENT, searchableContent)+ |
155 |
|
constructContent(APPLICATION_CONTENT, applicationContent)+ |
156 |
|
"</"+DOCUMENT_CONTENT+">"; |
157 |
|
} |
158 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
159 |
0
|
private void assertContent(DocumentContentDTO contentVO, String attributeContent, String searchableContent, String applicationContent) {... |
160 |
0
|
if (org.apache.commons.lang.StringUtils.isEmpty(attributeContent)) { |
161 |
0
|
attributeContent = ""; |
162 |
|
} else { |
163 |
0
|
attributeContent = "<"+ATTRIBUTE_CONTENT+">"+attributeContent+"</"+ATTRIBUTE_CONTENT+">"; |
164 |
|
} |
165 |
0
|
if (org.apache.commons.lang.StringUtils.isEmpty(searchableContent)) { |
166 |
0
|
searchableContent = ""; |
167 |
|
} else { |
168 |
0
|
searchableContent = "<"+SEARCHABLE_CONTENT+">"+searchableContent+"</"+SEARCHABLE_CONTENT+">"; |
169 |
|
} |
170 |
0
|
assertFalse("Content cannot be empty.", org.apache.commons.lang.StringUtils.isEmpty(contentVO.getFullContent())); |
171 |
0
|
assertEquals("Attribute content is invalid.", StringUtils.deleteWhitespace(attributeContent), StringUtils.deleteWhitespace(contentVO.getAttributeContent())); |
172 |
0
|
assertEquals("Searchable content is invalid.", StringUtils.deleteWhitespace(searchableContent), StringUtils.deleteWhitespace(contentVO.getSearchableContent())); |
173 |
0
|
assertEquals("Application content is invalid.", StringUtils.deleteWhitespace(applicationContent), StringUtils.deleteWhitespace(contentVO.getApplicationContent())); |
174 |
0
|
assertEquals("Incorrect number of attribute definitions.", 0, contentVO.getAttributeDefinitions().length); |
175 |
0
|
assertEquals("Incorrect number of searchable attribute definitions.", 0, contentVO.getSearchableDefinitions().length); |
176 |
|
} |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 49 (49) |
Complexity: 1 |
Complexity Density: 0.02 |
4
-
|
|
178 |
0
|
@Test public void testConvertActionItem() throws Exception {... |
179 |
|
|
180 |
0
|
String testWorkgroupName = "TestWorkgroup"; |
181 |
0
|
Group testWorkgroup = KIMServiceLocator.getIdentityManagementService().getGroupByName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, testWorkgroupName); |
182 |
0
|
String testWorkgroupId = testWorkgroup.getGroupId(); |
183 |
0
|
assertTrue("Test workgroup '" + testWorkgroupName + "' should have at least one user", KIMServiceLocator.getIdentityManagementService().getDirectGroupMemberPrincipalIds(testWorkgroup.getGroupId()).size() > 0); |
184 |
0
|
String workflowId = KIMServiceLocator.getIdentityManagementService().getDirectGroupMemberPrincipalIds(testWorkgroup.getGroupId()).get(0); |
185 |
0
|
assertNotNull("User from workgroup should not be null", workflowId); |
186 |
0
|
String actionRequestCd = KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ; |
187 |
0
|
Long actionRequestId = Long.valueOf(4); |
188 |
0
|
String docName = "dummy"; |
189 |
0
|
String roleName = "fakeRole"; |
190 |
0
|
Long routeHeaderId = Long.valueOf(23); |
191 |
0
|
Timestamp dateAssigned = new Timestamp(new Date().getTime()); |
192 |
0
|
String docHandlerUrl = "http://this.is.not.us"; |
193 |
0
|
String docTypeLabel = "Label Me"; |
194 |
0
|
String docTitle = "Title me"; |
195 |
0
|
Long responsibilityId = Long.valueOf(35); |
196 |
0
|
String delegationType = KEWConstants.DELEGATION_PRIMARY; |
197 |
|
|
198 |
|
|
199 |
0
|
ActionItem actionItem = new ActionItem(); |
200 |
0
|
actionItem.setActionRequestCd(actionRequestCd); |
201 |
0
|
actionItem.setActionRequestId(actionRequestId); |
202 |
0
|
actionItem.setDocName(docName); |
203 |
0
|
actionItem.setRoleName(roleName); |
204 |
0
|
actionItem.setPrincipalId(workflowId); |
205 |
0
|
actionItem.setRouteHeaderId(routeHeaderId); |
206 |
0
|
actionItem.setDateAssigned(dateAssigned); |
207 |
0
|
actionItem.setDocHandlerURL(docHandlerUrl); |
208 |
0
|
actionItem.setDocLabel(docTypeLabel); |
209 |
0
|
actionItem.setDocTitle(docTitle); |
210 |
0
|
actionItem.setGroupId(testWorkgroupId); |
211 |
0
|
actionItem.setResponsibilityId(responsibilityId); |
212 |
0
|
actionItem.setDelegationType(delegationType); |
213 |
0
|
actionItem.setDelegatorWorkflowId(workflowId); |
214 |
0
|
actionItem.setDelegatorGroupId(testWorkgroupId); |
215 |
|
|
216 |
|
|
217 |
0
|
ActionItemDTO actionItemVO = DTOConverter.convertActionItem(actionItem); |
218 |
0
|
assertEquals("Action Item VO object has incorrect value", actionRequestCd, actionItemVO.getActionRequestCd()); |
219 |
0
|
assertEquals("Action Item VO object has incorrect value", actionRequestId, actionItemVO.getActionRequestId()); |
220 |
0
|
assertEquals("Action Item VO object has incorrect value", docName, actionItemVO.getDocName()); |
221 |
0
|
assertEquals("Action Item VO object has incorrect value", roleName, actionItemVO.getRoleName()); |
222 |
0
|
assertEquals("Action Item VO object has incorrect value", workflowId, actionItemVO.getPrincipalId()); |
223 |
0
|
assertEquals("Action Item VO object has incorrect value", routeHeaderId, actionItemVO.getRouteHeaderId()); |
224 |
0
|
assertEquals("Action Item VO object has incorrect value", dateAssigned, actionItemVO.getDateAssigned()); |
225 |
0
|
assertEquals("Action Item VO object has incorrect value", docHandlerUrl, actionItemVO.getDocHandlerURL()); |
226 |
0
|
assertEquals("Action Item VO object has incorrect value", docTypeLabel, actionItemVO.getDocLabel()); |
227 |
0
|
assertEquals("Action Item VO object has incorrect value", docTitle, actionItemVO.getDocTitle()); |
228 |
0
|
assertEquals("Action Item VO object has incorrect value", "" + testWorkgroupId, actionItemVO.getGroupId()); |
229 |
0
|
assertEquals("Action Item VO object has incorrect value", responsibilityId, actionItemVO.getResponsibilityId()); |
230 |
0
|
assertEquals("Action Item VO object has incorrect value", delegationType, actionItemVO.getDelegationType()); |
231 |
0
|
assertEquals("Action Item VO object has incorrect value", workflowId, actionItemVO.getDelegatorPrincipalId()); |
232 |
0
|
assertEquals("Action Item VO object has incorrect value", testWorkgroupId, actionItemVO.getDelegatorGroupId()); |
233 |
|
} |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4
-
|
|
235 |
0
|
@Test public void testConvertActionRequest() throws Exception {... |
236 |
0
|
ActionRequestValue actionRequest = new ActionRequestValue(); |
237 |
0
|
ActionTakenValue actionTaken = new ActionTakenValue(); |
238 |
0
|
actionRequest.setActionTaken(actionTaken); |
239 |
0
|
actionTaken.getActionRequests().add(actionRequest); |
240 |
|
|
241 |
0
|
ActionRequestDTO convertedActionRequest = DTOConverter.convertActionRequest(actionRequest); |
242 |
0
|
assertNotNull("ActionTakenDTO object should be valid", convertedActionRequest); |
243 |
|
|
244 |
|
} |
245 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4
-
|
|
246 |
0
|
@Test public void testConvertActionTaken() throws Exception {... |
247 |
0
|
ActionRequestValue actionRequest = new ActionRequestValue(); |
248 |
0
|
ActionTakenValue actionTaken = new ActionTakenValue(); |
249 |
0
|
actionRequest.setActionTaken(actionTaken); |
250 |
0
|
actionTaken.getActionRequests().add(actionRequest); |
251 |
|
|
252 |
0
|
ActionTakenDTO convertedActionTaken = DTOConverter.convertActionTaken(actionTaken); |
253 |
0
|
assertNotNull("ActionTakenDTO object should be valid", convertedActionTaken); |
254 |
0
|
convertedActionTaken = DTOConverter.convertActionTakenWithActionRequests(actionTaken); |
255 |
0
|
assertNotNull("ActionTakenDTO object should be valid", convertedActionTaken); |
256 |
|
} |
257 |
|
} |