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