KickJava   Java API By Example, From Geeks To Geeks.

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


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 IfTest extends TestCase {
22   public IfTest(String JavaDoc name) {
23     super(name);
24   }
25
26   public void testExecTrue() throws Exception JavaDoc {
27     If ifStep = new If();
28     TestStep step1 = new TestStep(true);
29
30     ifStep.addExecutable(step1);
31     ifStep.setTest("key == 'value'");
32
33     ContextImpl ctx;
34     Result st = new Result(new StateMachine(), ctx = new ContextImpl());
35     Scope sc = new MapScope();
36     sc.putVal("key", "value");
37     ctx.addScope("test", sc);
38     ifStep.execute(st);
39     super.assertTrue(step1.exec);
40   }
41
42   public void testExecFalse() throws Exception JavaDoc {
43     If ifStep = new If();
44
45     TestStep step1 = new TestStep(true);
46
47     ifStep.addExecutable(step1);
48     ifStep.setTest("key == 'value'");
49
50     ContextImpl ctx;
51     Result st = new Result(new StateMachine(), ctx = new ContextImpl());
52     Scope sc = new MapScope();
53     ctx.addScope("test", sc);
54     ifStep.execute(st);
55     super.assertTrue(!step1.exec);
56   }
57 }
58
Popular Tags