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 static org.junit.Assert.assertTrue;
19
20 import java.io.StringReader;
21
22 import javax.xml.xpath.XPath;
23 import javax.xml.xpath.XPathConstants;
24
25 import org.junit.Test;
26 import org.kuali.rice.kew.api.WorkflowDocument;
27 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
28 import org.kuali.rice.kew.api.document.PropertyDefinition;
29 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
30 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
31 import org.kuali.rice.kew.test.KEWTestCase;
32 import org.xml.sax.InputSource;
33
34
35
36
37
38
39
40
41 public class NetworkIdRoleAttributeTest extends KEWTestCase {
42
43 private static final String ATTRIBUTE_NAME = "NetworkIdRoleAttribute";
44 private static final String NETWORK_ID_PROP = "networkId";
45
46 @Test
47 public void testNetworkIdAttribute() throws Exception {
48 loadXmlFile("NetworkIdRoleAttributeTestConfig.xml");
49
50 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
51 "ewestfal"), "NetworkIdRoleAttributeTest");
52
53 WorkflowAttributeDefinition.Builder networkIdDef1 = WorkflowAttributeDefinition.Builder.create("NetworkIdRoleAttribute");
54 PropertyDefinition networkIdProp1 = PropertyDefinition.create(
55 NETWORK_ID_PROP, "rkirkend");
56 networkIdDef1.addPropertyDefinition(networkIdProp1);
57
58 WorkflowAttributeDefinition.Builder networkIdDef2 = WorkflowAttributeDefinition.Builder.create(
59 "NetworkIdRoleAttribute");
60 PropertyDefinition networkIdProp2 = PropertyDefinition.create(
61 NETWORK_ID_PROP, "bmcgough");
62 networkIdDef2.addPropertyDefinition(networkIdProp2);
63
64 document.addAttributeDefinition(networkIdDef1.build());
65 document.addAttributeDefinition(networkIdDef2.build());
66
67 document.route("Routing!");
68
69
70
71 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
72 .getDocumentId());
73 assertTrue("Document should be ENROUTE", document.isEnroute());
74 assertTrue("rkirkend should have an approve request.", document
75 .isApprovalRequested());
76
77
78 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document
79 .getDocumentId());
80 assertTrue("bmcgough should have an approve request.", document
81 .isApprovalRequested());
82
83
84 document.approve("i approve");
85
86
87 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
88 .getDocumentId());
89 assertTrue("Document should be ENROUTE", document.isEnroute());
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.isFinal());
96
97 }
98
99 @Test
100 public void testParameterizedNetworkIdAttribute() throws Exception {
101 loadXmlFile("ParameterizedNetworkIdRoleAttributeTestConfig.xml");
102
103 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
104 "ewestfal"), "NetworkIdRoleAttributeTest");
105
106 WorkflowAttributeDefinition.Builder networkIdDef1 = WorkflowAttributeDefinition.Builder.create(
107 "NetworkIdRoleAttribute");
108 PropertyDefinition networkIdProp1 = PropertyDefinition.create(
109 NETWORK_ID_PROP, "rkirkend");
110 networkIdDef1.addPropertyDefinition(networkIdProp1);
111
112 document.addAttributeDefinition(networkIdDef1.build());
113
114 document.route("Routing!");
115
116
117
118 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
119 .getDocumentId());
120 assertTrue("Document should be ENROUTE", document.isEnroute());
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 }