1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21
22 import org.junit.Test;
23 import org.kuali.rice.kew.api.WorkflowDocument;
24 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
25 import org.kuali.rice.kew.api.action.ActionRequest;
26 import org.kuali.rice.kew.api.action.ActionTaken;
27 import org.kuali.rice.kew.api.exception.WorkflowException;
28 import org.kuali.rice.kew.engine.node.Branch;
29 import org.kuali.rice.kew.engine.node.BranchState;
30 import org.kuali.rice.kew.test.KEWTestCase;
31
32
33
34
35
36
37 public class VariablesTest extends KEWTestCase {
38
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(VariablesTest.class);
40
41 protected void loadTestData() throws Exception {
42 loadXmlFile("ActionsConfig.xml");
43 }
44
45 private void dumpInfoAboutDoc(WorkflowDocument doc) throws WorkflowException {
46 LOG.info("\tDoc: class=" + doc.getDocumentTypeName() + " title=" + doc.getTitle() + " status=" + doc.getStatus());
47 LOG.info("\tActionRequests:");
48 for (ActionRequest ar: doc.getRootActionRequests()) {
49 LOG.info("\t\tId: " + ar.getId() + " PrincipalId: " + ar.getPrincipalId() + " ActionRequested: " + ar.getActionRequested() + " ActionTaken: " + (ar.getActionTaken() != null ? ar.getActionTaken().getActionTaken() : null) + " NodeName: " + ar.getNodeName() + " Status:" + ar.getStatus());
50 }
51 LOG.info("\tActionTakens:");
52 for (ActionTaken at: doc.getActionsTaken()) {
53 LOG.info("\t\tId: " + at.getId() + " PrincipalId: " + at.getPrincipalId() + " ActionTaken: " + at.getActionTaken());
54 }
55 LOG.info("\tNodeNames:");
56 for (String name: doc.getNodeNames()) {
57 LOG.info("\t\t" + name);
58 }
59 }
60
61 public void dumpBranch(Branch b) {
62 LOG.info("Branch: " + b.getBranchId() + " " + b.getName());
63 for (BranchState bs: b.getBranchState()) {
64 LOG.info(bs.getBranchStateId() + " " + bs.getKey() + " " + bs.getValue());
65 }
66 }
67
68 @Test public void testVariables() throws Exception {
69 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "VariablesTest");
70 doc.route("");
71
72
73 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), doc.getDocumentId());
74 dumpInfoAboutDoc(doc);
75 doc.setVariable("myexcellentvariable", "righton");
76 doc.approve("");
77 assertEquals("startedVariableValue", doc.getVariableValue("started"));
78 assertEquals("startedVariableValue", doc.getVariableValue("copiedVar"));
79
80 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user2"), doc.getDocumentId());
81 assertEquals("righton", doc.getVariableValue("myexcellentvariable"));
82 doc.setVariable("vartwo", "two");
83 doc.setVariable("myexcellentvariable", "ichangedit");
84 doc.acknowledge("");
85
86 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user3"), doc.getDocumentId());
87 assertEquals("ichangedit", doc.getVariableValue("myexcellentvariable"));
88 assertEquals("two", doc.getVariableValue("vartwo"));
89 doc.setVariable("another", "another");
90 doc.setVariable("vartwo", null);
91 doc.complete("");
92
93
94 doc = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), doc.getDocumentId());
95 assertEquals("ichangedit", doc.getVariableValue("myexcellentvariable"));
96 assertEquals(null, doc.getVariableValue("vartwo"));
97 assertEquals("another", doc.getVariableValue("another"));
98 doc.approve("");
99
100 assertEquals("endedVariableValue", doc.getVariableValue("ended"));
101 assertNotNull(doc.getVariableValue("google"));
102 LOG.info(doc.getVariableValue("google"));
103 assertEquals("documentContentendedVariableValue", doc.getVariableValue("xpath"));
104 LOG.info(doc.getVariableValue("xpath"));
105
106 assertEquals("aNewStartedVariableValue", doc.getVariableValue("started"));
107
108 assertTrue("the document should be final", doc.isFinal());
109 }
110 }