KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > exe > CommentDbTest


1 package org.jbpm.graph.exe;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.jbpm.db.AbstractDbTestCase;
7 import org.jbpm.graph.def.ProcessDefinition;
8 import org.jbpm.security.Authentication;
9 import org.jbpm.taskmgmt.exe.TaskInstance;
10 import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
11
12 public class CommentDbTest extends AbstractDbTestCase {
13   
14   public void testComments() {
15     ProcessInstance processInstance = null;
16     
17     Authentication.pushAuthenticatedActorId("miketyson");
18     try {
19       ProcessDefinition processDefinition = new ProcessDefinition();
20       jbpmSession.getGraphSession().saveProcessDefinition(processDefinition);
21       
22       processInstance = new ProcessInstance(processDefinition);
23       Token token = processInstance.getRootToken();
24       token.addComment("first");
25       token.addComment("second");
26       token.addComment("third");
27       
28       processInstance = saveAndReload(processInstance);
29       
30     } finally {
31       Authentication.popAuthenticatedActorId();
32     }
33     
34     Token token = processInstance.getRootToken();
35     List JavaDoc comments = token.getComments();
36     
37     assertNotNull(comments);
38     assertEquals(3, comments.size());
39
40     assertEquals("miketyson", ((Comment)comments.get(0)).getActorId());
41     assertNotNull(((Comment)comments.get(0)).getTime());
42     assertEquals("first", ((Comment)comments.get(0)).getMessage());
43     
44     assertEquals("miketyson", ((Comment)comments.get(1)).getActorId());
45     assertNotNull(((Comment)comments.get(1)).getTime());
46     assertEquals("second", ((Comment)comments.get(1)).getMessage());
47
48     assertEquals("miketyson", ((Comment)comments.get(2)).getActorId());
49     assertNotNull(((Comment)comments.get(2)).getTime());
50     assertEquals("third", ((Comment)comments.get(2)).getMessage());
51   }
52   
53   public void testCommentsOnDifferentTokens() {
54     Token token = new Token();
55     token.addComment("one");
56     token.addComment("two");
57     token.addComment("three");
58     jbpmSession.getSession().save(token);
59     long firstTokenId = token.getId();
60     
61     token = new Token();
62     token.addComment("first");
63     token.addComment("second");
64     token.addComment("third");
65     jbpmSession.getSession().save(token);
66     long secondTokenId = token.getId();
67     
68     newTransaction();
69     
70     token = (Token) jbpmSession.getSession().load(Token.class, new Long JavaDoc(firstTokenId));
71     List JavaDoc comments = token.getComments();
72     assertEquals(3, comments.size());
73     assertEquals("one", ((Comment)comments.get(0)).getMessage());
74     assertEquals("two", ((Comment)comments.get(1)).getMessage());
75     assertEquals("three", ((Comment)comments.get(2)).getMessage());
76
77     token = (Token) jbpmSession.getSession().load(Token.class, new Long JavaDoc(secondTokenId));
78     comments = token.getComments();
79     assertEquals(3, comments.size());
80     assertEquals("first", ((Comment)comments.get(0)).getMessage());
81     assertEquals("second", ((Comment)comments.get(1)).getMessage());
82     assertEquals("third", ((Comment)comments.get(2)).getMessage());
83   }
84   
85   public void testTaskInstanceComment() {
86     TaskInstance taskInstance = new TaskInstance();
87     taskInstance.addComment("one");
88     taskInstance.addComment("two");
89     taskInstance.addComment("three");
90     jbpmSession.getSession().save(taskInstance);
91     
92     newTransaction();
93     
94     taskInstance = (TaskInstance) jbpmSession.getSession().load(TaskInstance.class, new Long JavaDoc(taskInstance.getId()));
95     List JavaDoc comments = taskInstance.getComments();
96     assertEquals(3, comments.size());
97     
98     Comment comment = (Comment)comments.get(0);
99     assertEquals("one", comment.getMessage());
100     assertSame(taskInstance, comment.getTaskInstance());
101     
102     assertEquals("two", ((Comment)comments.get(1)).getMessage());
103     assertEquals("three", ((Comment)comments.get(2)).getMessage());
104   }
105
106   public void testCommentToTokenAndTaskInstance() {
107     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
108       "<process-definition>" +
109       " <start-state>" +
110       " <transition to='a' />" +
111       " </start-state>" +
112       " <task-node name='a'>" +
113       " <task name='clean ceiling' />" +
114       " </task-node>" +
115       "</process-definition>"
116     );
117     jbpmSession.getGraphSession().saveProcessDefinition(processDefinition);
118     
119     ProcessInstance processInstance = new ProcessInstance(processDefinition);
120     processInstance.signal();
121     
122     processInstance = saveAndReload(processInstance);
123     
124     TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
125     TaskInstance taskInstance = (TaskInstance) tmi.getTaskInstances().iterator().next();
126     taskInstance.addComment("one");
127     taskInstance.addComment("two");
128     taskInstance.addComment("three");
129     
130     processInstance = saveAndReload(processInstance);
131     Token rootToken = processInstance.getRootToken();
132     
133     taskInstance = (TaskInstance) processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
134     assertEquals(3, taskInstance.getComments().size());
135     assertEquals(3, rootToken.getComments().size());
136     
137     ArrayList JavaDoc tokenComments = new ArrayList JavaDoc(rootToken.getComments());
138     ArrayList JavaDoc taskComments = new ArrayList JavaDoc(taskInstance.getComments());
139     assertEquals(tokenComments, taskComments);
140   }
141 }
142
Popular Tags