1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import org.junit.Test;
19 import org.kuali.rice.kew.api.WorkflowDocument;
20 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
21 import org.kuali.rice.kew.api.document.PropertyDefinition;
22 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
23 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
24 import org.kuali.rice.kew.test.KEWTestCase;
25 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26 import org.xml.sax.InputSource;
27
28 import javax.xml.xpath.XPath;
29 import javax.xml.xpath.XPathConstants;
30 import java.io.StringReader;
31
32 import static org.junit.Assert.assertTrue;
33
34
35
36
37
38
39 public class PrincipalIdRoleAttributeTest extends KEWTestCase {
40
41 private static final String ATTRIBUTE_NAME = "PrincipalIdRoleAttribute";
42 private static final String PRINCIPAL_ID_PROP = "principalId";
43
44 @Test
45 public void testPrincipalIdAttribute() throws Exception {
46 loadXmlFile("PrincipalIdRoleAttributeTestConfig.xml");
47
48 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
49 "ewestfal"), "PrincipalIdRoleAttributeTest");
50
51 WorkflowAttributeDefinition.Builder principalIdDef1 = WorkflowAttributeDefinition.Builder.create(
52 "PrincipalIdRoleAttribute");
53 PropertyDefinition principalIdProp1 = PropertyDefinition.create(
54 PRINCIPAL_ID_PROP, KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
55 principalIdDef1.addPropertyDefinition(principalIdProp1);
56
57 WorkflowAttributeDefinition.Builder principalIdDef2 = WorkflowAttributeDefinition.Builder.create(
58 "PrincipalIdRoleAttribute");
59 PropertyDefinition principalIdProp2 = PropertyDefinition.create(
60 PRINCIPAL_ID_PROP, KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("bmcgough").getPrincipalId());
61 principalIdDef2.addPropertyDefinition(principalIdProp2);
62
63 document.addAttributeDefinition(principalIdDef1.build());
64 document.addAttributeDefinition(principalIdDef2.build());
65
66 document.route("Routing!");
67
68
69
70 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
71 .getDocumentId());
72 assertTrue("Document should be ENROUTE", document.isEnroute());
73 assertTrue("rkirkend should have an approve request.", document
74 .isApprovalRequested());
75
76
77 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document
78 .getDocumentId());
79 assertTrue("bmcgough should have an approve request.", document
80 .isApprovalRequested());
81
82
83 document.approve("i approve");
84
85
86 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
87 .getDocumentId());
88 assertTrue("Document should be ENROUTE", document.isEnroute());
89 assertTrue("rkirkend should have an approve request.", document
90 .isApprovalRequested());
91 document.approve("i also approve");
92
93
94 assertTrue("Document should be FINAL", document.isFinal());
95
96 }
97
98 @Test
99 public void testParameterizedPrincipalIdAttribute() throws Exception {
100 loadXmlFile("ParameterizedPrincipalIdRoleAttributeTestConfig.xml");
101
102 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
103 "ewestfal"), "PrincipalIdRoleAttributeTest");
104
105 WorkflowAttributeDefinition.Builder principalIdDef1 = WorkflowAttributeDefinition.Builder.create(
106 "PrincipalIdRoleAttribute");
107 PropertyDefinition principalIdProp1 = PropertyDefinition.create(
108 PRINCIPAL_ID_PROP, KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
109 principalIdDef1.addPropertyDefinition(principalIdProp1);
110
111 document.addAttributeDefinition(principalIdDef1.build());
112
113 document.route("Routing!");
114
115
116
117 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
118 .getDocumentId());
119 assertTrue("Document should be ENROUTE", document.isEnroute());
120 assertTrue("rkirkend should have an approve request.", document
121 .isApprovalRequested());
122
123
124
125 XPath xPath = XPathHelper.newXPath();
126 assertTrue("Should have found the ID.", (Boolean) xPath.evaluate(
127 "//" + ATTRIBUTE_NAME + "/thisIdRocks", new InputSource(
128 new StringReader(document.getDocumentContent()
129 .getFullContent())), XPathConstants.BOOLEAN));
130
131 }
132
133 }