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