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 java.io.StringReader;
19
20 import javax.xml.xpath.XPath;
21 import javax.xml.xpath.XPathConstants;
22
23 import org.junit.Test;
24 import org.kuali.rice.kew.dto.NetworkIdDTO;
25 import org.kuali.rice.kew.dto.PropertyDefinitionDTO;
26 import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO;
27 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
28 import org.kuali.rice.kew.service.WorkflowDocument;
29 import org.kuali.rice.kew.test.KEWTestCase;
30 import org.kuali.rice.kim.service.KIMServiceLocator;
31 import org.xml.sax.InputSource;
32
33
34
35
36
37
38
39
40 public class PrincipalIdRoleAttributeTest extends KEWTestCase {
41
42 private static final String ATTRIBUTE_NAME = "PrincipalIdRoleAttribute";
43 private static final String PRINCIPAL_ID_PROP = "principalId";
44
45 @Test
46 public void testPrincipalIdAttribute() throws Exception {
47 loadXmlFile("PrincipalIdRoleAttributeTestConfig.xml");
48
49 WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO(
50 "ewestfal"), "PrincipalIdRoleAttributeTest");
51
52 WorkflowAttributeDefinitionDTO principalIdDef1 = new WorkflowAttributeDefinitionDTO(
53 "PrincipalIdRoleAttribute");
54 PropertyDefinitionDTO principalIdProp1 = new PropertyDefinitionDTO(
55 PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
56 principalIdDef1.addProperty(principalIdProp1);
57
58 WorkflowAttributeDefinitionDTO principalIdDef2 = new WorkflowAttributeDefinitionDTO(
59 "PrincipalIdRoleAttribute");
60 PropertyDefinitionDTO principalIdProp2 = new PropertyDefinitionDTO(
61 PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("bmcgough").getPrincipalId());
62 principalIdDef2.addProperty(principalIdProp2);
63
64 document.addAttributeDefinition(principalIdDef1);
65 document.addAttributeDefinition(principalIdDef2);
66
67 document.routeDocument("Routing!");
68
69
70
71 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document
72 .getRouteHeaderId());
73 assertTrue("Document should be ENROUTE", document.stateIsEnroute());
74 assertTrue("rkirkend should have an approve request.", document
75 .isApprovalRequested());
76
77
78 document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document
79 .getRouteHeaderId());
80 assertTrue("bmcgough should have an approve request.", document
81 .isApprovalRequested());
82
83
84 document.approve("i approve");
85
86
87 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document
88 .getRouteHeaderId());
89 assertTrue("Document should be ENROUTE", document.stateIsEnroute());
90 assertTrue("rkirkend should have an approve request.", document
91 .isApprovalRequested());
92 document.approve("i also approve");
93
94
95 assertTrue("Document should be FINAL", document.stateIsFinal());
96
97 }
98
99 @Test
100 public void testParameterizedPrincipalIdAttribute() throws Exception {
101 loadXmlFile("ParameterizedPrincipalIdRoleAttributeTestConfig.xml");
102
103 WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO(
104 "ewestfal"), "PrincipalIdRoleAttributeTest");
105
106 WorkflowAttributeDefinitionDTO principalIdDef1 = new WorkflowAttributeDefinitionDTO(
107 "PrincipalIdRoleAttribute");
108 PropertyDefinitionDTO principalIdProp1 = new PropertyDefinitionDTO(
109 PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
110 principalIdDef1.addProperty(principalIdProp1);
111
112 document.addAttributeDefinition(principalIdDef1);
113
114 document.routeDocument("Routing!");
115
116
117
118 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document
119 .getRouteHeaderId());
120 assertTrue("Document should be ENROUTE", document.stateIsEnroute());
121 assertTrue("rkirkend should have an approve request.", document
122 .isApprovalRequested());
123
124
125
126 XPath xPath = XPathHelper.newXPath();
127 assertTrue("Should have found the ID.", (Boolean) xPath.evaluate(
128 "//" + ATTRIBUTE_NAME + "/thisIdRocks", new InputSource(
129 new StringReader(document.getDocumentContent()
130 .getFullContent())), XPathConstants.BOOLEAN));
131
132 }
133
134 }