KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > def > ArrivingTransitionsTest


1 package org.jbpm.graph.def;
2
3 import java.util.Collection JavaDoc;
4 import java.util.HashSet JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.Set JavaDoc;
7
8 import junit.framework.TestCase;
9
10 public class ArrivingTransitionsTest extends TestCase {
11
12   private Node n = new Node("n");
13   private Transition t = new Transition("t");
14
15   public void testAddArrivingTransition() {
16     n.addArrivingTransition( t );
17     assertSame( n, t.getTo() );
18     assertEquals( 1, n.getArrivingTransitions().size() );
19     assertEquals( t, n.getArrivingTransitions().iterator().next() );
20   }
21
22   public void testRemoveArrivingTransition() {
23     n.addArrivingTransition( t );
24     n.removeArrivingTransition( t );
25     assertNull( t.getTo() );
26     assertEquals( 0, n.getArrivingTransitions().size() );
27   }
28
29   public void testArrivingTransitions() {
30     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
31       "<process-definition>" +
32       " <state name='a'>" +
33       " <transition name='to-c' to='c' />" +
34       " </state>" +
35       " <state name='b'>" +
36       " <transition name='to-c' to='c' />" +
37       " </state>" +
38       " <state name='c'/>" +
39       "</process-definition>"
40     );
41           
42     Collection JavaDoc arrivingTransitions = processDefinition.getNode("c").getArrivingTransitions();
43     assertEquals(2, arrivingTransitions.size());
44     
45     Set JavaDoc fromNodes = new HashSet JavaDoc();
46     Iterator JavaDoc iter = arrivingTransitions.iterator();
47     while (iter.hasNext()) {
48       Transition transition = (Transition) iter.next();
49       fromNodes.add( transition.getFrom() );
50       assertEquals("to-c", transition.getName());
51     }
52     
53     Set JavaDoc expectedFromNodes = new HashSet JavaDoc();
54     expectedFromNodes.add( processDefinition.getNode("a") );
55     expectedFromNodes.add( processDefinition.getNode("b") );
56     
57     assertEquals(expectedFromNodes, fromNodes);
58   }
59 }
60
Popular Tags