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 public class UniversityIdRoleAttributeTest extends KEWTestCase {
40
41 private static final String UNIVERSITY_ID_PROP = "universityId";
42
43 @Test
44 public void testUniversityIdAttribute() throws Exception {
45 loadXmlFile("UniversityIdRoleAttributeTestConfig.xml");
46
47
48
49
50
51
52
53 WorkflowDocument document = WorkflowDocumentFactory.createDocument("2001", "UniversityIdRoleAttributeTest");
54
55 WorkflowAttributeDefinition.Builder universityIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
56 PropertyDefinition universityIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
57 universityIdDef1.addPropertyDefinition(universityIdProp1);
58
59 WorkflowAttributeDefinition.Builder universityIdDef2 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
60 PropertyDefinition universityIdProp2 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2004");
61 universityIdDef2.addPropertyDefinition(universityIdProp2);
62
63 document.addAttributeDefinition(universityIdDef1.build());
64 document.addAttributeDefinition(universityIdDef2.build());
65
66 document.route("Routing!");
67
68
69
70 document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
71 assertTrue("Document should be ENROUTE", document.isEnroute());
72 assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
73
74
75 document = WorkflowDocumentFactory.loadDocument("2004", document.getDocumentId());
76 assertTrue("bmcgough should have an approve request.", document.isApprovalRequested());
77
78
79 document.approve("i approve");
80
81
82 document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
83 assertTrue("Document should be ENROUTE", document.isEnroute());
84 assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
85 document.approve("i also approve");
86
87
88 assertTrue("Document should be FINAL", document.isFinal());
89
90 }
91
92 @Test
93 public void testParameterizedUniversityIdAttribute() throws Exception {
94 loadXmlFile("ParameterizedUniversityIdRoleAttributeTestConfig.xml");
95
96 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "UniversityIdRoleAttributeTest");
97
98 WorkflowAttributeDefinition.Builder univIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
99 PropertyDefinition univIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
100 univIdDef1.addPropertyDefinition(univIdProp1);
101
102 document.addAttributeDefinition(univIdDef1.build());
103
104 document.route("Routing!");
105
106
107
108 document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
109 assertTrue("Document should be ENROUTE", document.isEnroute());
110 assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
111
112
113
114 XPath xPath = XPathHelper.newXPath();
115 assertTrue("Should have found the ID.", (Boolean)xPath.evaluate("//UniversityIdRoleAttribute/thisIdRocks", new InputSource(new StringReader(document.getDocumentContent().getFullContent())), XPathConstants.BOOLEAN));
116
117 }
118
119 }