KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.graph.exe;
2
3 import junit.framework.*;
4
5 import org.jbpm.graph.def.*;
6
7 public class TokenNameTest extends TestCase {
8   
9   public void testFindRoot() {
10     ProcessDefinition pd = new ProcessDefinition(
11       new String JavaDoc[]{"start-state start",
12                    "fork f1",
13                    "state a",
14                    "fork f2",
15                    "state b",
16                    "state c"},
17       new String JavaDoc[]{"start --> f1",
18                    "f1 --a--> a",
19                    "f1 --f2--> f2",
20                    "f2 --b--> b",
21                    "f2 --c--> c"});
22     
23     ProcessInstance pi = new ProcessInstance(pd);
24     pi.signal();
25
26     // now we have the following tree of tokens
27
// at the right, the full name of the token is presented.
28
//
29
// root-token --> /
30
// +- a --> /a
31
// +- f2 --> /f2
32
// +- b --> /f2/b
33
// +- c --> /f2/c
34

35     Token root = pi.getRootToken();
36     Token tokenA = root.getChild("a");
37     Token tokenF2 = root.getChild("f2");
38     Token tokenF2B = tokenF2.getChild("b");
39     Token tokenF2C = tokenF2.getChild("c");
40     
41     assertEquals("/", root.getFullName());
42     assertEquals("/a", tokenA.getFullName());
43     assertEquals("/f2", tokenF2.getFullName());
44     assertEquals("/f2/b", tokenF2B.getFullName());
45     assertEquals("/f2/c", tokenF2C.getFullName());
46     
47     assertSame( root, pi.findToken( "/" ) );
48     assertSame( root, pi.findToken( "" ) );
49     assertSame( root, pi.findToken( "." ) );
50     assertSame( root, tokenA.findToken( ".." ) );
51     assertSame( root, tokenA.findToken( "../." ) );
52
53     assertSame( tokenA, pi.findToken( "/a" ) );
54     assertSame( tokenA, tokenF2C.findToken( "/a" ) );
55     assertSame( tokenA, pi.findToken( "a" ) );
56
57     assertSame( tokenF2, pi.findToken( "f2" ) );
58     assertSame( tokenF2, pi.findToken( "/f2" ) );
59     assertSame( tokenF2, tokenF2C.findToken( ".." ) );
60
61     assertSame( tokenF2B, pi.findToken( "f2/b" ) );
62     assertSame( tokenF2B, pi.findToken( "/f2/b" ) );
63
64     assertNull( pi.findToken( null ) );
65     assertNull( pi.findToken( "non-existing-token-name" ) );
66     assertNull( pi.findToken( "/a/non-existing-token-name" ) );
67     assertNull( pi.findToken( ".." ) );
68     assertNull( pi.findToken( "/.." ) );
69   }
70 }
71
Popular Tags