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
40
41 public class PrincipalIdRoleAttributeTest extends KEWTestCase {
42
43 private static final String ATTRIBUTE_NAME = "PrincipalIdRoleAttribute";
44 private static final String PRINCIPAL_ID_PROP = "principalId";
45
46 @Test
47 public void testPrincipalIdAttribute() throws Exception {
48 loadXmlFile("PrincipalIdRoleAttributeTestConfig.xml");
49
50 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
51 "ewestfal"), "PrincipalIdRoleAttributeTest");
52
53 WorkflowAttributeDefinition.Builder principalIdDef1 = WorkflowAttributeDefinition.Builder.create(
54 "PrincipalIdRoleAttribute");
55 PropertyDefinition principalIdProp1 = PropertyDefinition.create(
56 PRINCIPAL_ID_PROP, KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
57 principalIdDef1.addPropertyDefinition(principalIdProp1);
58
59 WorkflowAttributeDefinition.Builder principalIdDef2 = WorkflowAttributeDefinition.Builder.create(
60 "PrincipalIdRoleAttribute");
61 PropertyDefinition principalIdProp2 = PropertyDefinition.create(
62 PRINCIPAL_ID_PROP, KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("bmcgough").getPrincipalId());
63 principalIdDef2.addPropertyDefinition(principalIdProp2);
64
65 document.addAttributeDefinition(principalIdDef1.build());
66 document.addAttributeDefinition(principalIdDef2.build());
67
68 document.route("Routing!");
69
70
71
72 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
73 .getDocumentId());
74 assertTrue("Document should be ENROUTE", document.isEnroute());
75 assertTrue("rkirkend should have an approve request.", document
76 .isApprovalRequested());
77
78
79 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document
80 .getDocumentId());
81 assertTrue("bmcgough should have an approve request.", document
82 .isApprovalRequested());
83
84
85 document.approve("i approve");
86
87
88 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
89 .getDocumentId());
90 assertTrue("Document should be ENROUTE", document.isEnroute());
91 assertTrue("rkirkend should have an approve request.", document
92 .isApprovalRequested());
93 document.approve("i also approve");
94
95
96 assertTrue("Document should be FINAL", document.isFinal());
97
98 }
99
100 @Test
101 public void testParameterizedPrincipalIdAttribute() throws Exception {
102 loadXmlFile("ParameterizedPrincipalIdRoleAttributeTestConfig.xml");
103
104 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
105 "ewestfal"), "PrincipalIdRoleAttributeTest");
106
107 WorkflowAttributeDefinition.Builder principalIdDef1 = WorkflowAttributeDefinition.Builder.create(
108 "PrincipalIdRoleAttribute");
109 PropertyDefinition principalIdProp1 = PropertyDefinition.create(
110 PRINCIPAL_ID_PROP, KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
111 principalIdDef1.addPropertyDefinition(principalIdProp1);
112
113 document.addAttributeDefinition(principalIdDef1.build());
114
115 document.route("Routing!");
116
117
118
119 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
120 .getDocumentId());
121 assertTrue("Document should be ENROUTE", document.isEnroute());
122 assertTrue("rkirkend should have an approve request.", document
123 .isApprovalRequested());
124
125
126
127 XPath xPath = XPathHelper.newXPath();
128 assertTrue("Should have found the ID.", (Boolean) xPath.evaluate(
129 "//" + ATTRIBUTE_NAME + "/thisIdRocks", new InputSource(
130 new StringReader(document.getDocumentContent()
131 .getFullContent())), XPathConstants.BOOLEAN));
132
133 }
134
135 }