KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > control > ChooseTest


1 package org.sapia.soto.state.control;
2
3 import junit.framework.TestCase;
4
5 import org.sapia.soto.state.ContextImpl;
6 import org.sapia.soto.state.MapScope;
7 import org.sapia.soto.state.Result;
8 import org.sapia.soto.state.Scope;
9 import org.sapia.soto.state.StateMachine;
10 import org.sapia.soto.state.TestStep;
11
12
13 /**
14  * @author Yanick Duchesne
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class ChooseTest extends TestCase {
22   public ChooseTest(String JavaDoc name) {
23     super(name);
24   }
25
26   public void testFirstCase() throws Exception JavaDoc {
27     Choose choose = new Choose();
28     TestStep step1 = new TestStep(true);
29     TestStep step2 = new TestStep(true);
30     Choose.When case1 = choose.createWhen();
31     case1.setTest("key == 'value'");
32     case1.addExecutable(step1);
33
34     Choose.Otherwise other = choose.createOtherwise();
35     other.addExecutable(step2);
36
37     ContextImpl ctx;
38     Result st = new Result(new StateMachine(), ctx = new ContextImpl());
39     Scope sc = new MapScope();
40     sc.putVal("key", "value");
41     ctx.addScope("test", sc);
42     choose.execute(st);
43     super.assertTrue(step1.exec);
44     super.assertTrue(!step2.exec);
45   }
46
47   public void testSecondCase() throws Exception JavaDoc {
48     Choose choose = new Choose();
49     TestStep step1 = new TestStep(true);
50     TestStep step2 = new TestStep(true);
51     TestStep step3 = new TestStep(true);
52     Choose.When case1 = choose.createWhen();
53     case1.setTest("key == 'foo'");
54     case1.addExecutable(step1);
55
56     Choose.When case2 = choose.createWhen();
57     case2.setTest("key == 'value'");
58     case2.addExecutable(step2);
59
60     Choose.Otherwise other = choose.createOtherwise();
61     other.addExecutable(step3);
62
63     ContextImpl ctx;
64     Result st = new Result(new StateMachine(), ctx = new ContextImpl());
65     Scope sc = new MapScope();
66     sc.putVal("key", "value");
67     ctx.addScope("test", sc);
68     choose.execute(st);
69     super.assertTrue(!step1.exec);
70     super.assertTrue(step2.exec);
71     super.assertTrue(!step3.exec);
72   }
73
74   public void testOtherwise() throws Exception JavaDoc {
75     Choose choose = new Choose();
76     TestStep step1 = new TestStep(true);
77     TestStep step2 = new TestStep(true);
78     TestStep step3 = new TestStep(true);
79     Choose.When case1 = choose.createWhen();
80     case1.setTest("key == 'foo'");
81     case1.addExecutable(step1);
82
83     Choose.When case2 = choose.createWhen();
84     case2.setTest("key == 'bar'");
85     case2.addExecutable(step2);
86
87     Choose.Otherwise other = choose.createOtherwise();
88     other.addExecutable(step3);
89
90     ContextImpl ctx;
91     Result st = new Result(new StateMachine(), ctx = new ContextImpl());
92     Scope sc = new MapScope();
93     sc.putVal("key", "value");
94     ctx.addScope("test", sc);
95     choose.execute(st);
96     super.assertTrue(!step1.exec);
97     super.assertTrue(!step2.exec);
98     super.assertTrue(step3.exec);
99   }
100 }
101
Popular Tags