| 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 21 public class IfTest extends TestCase { 22 public IfTest(String name) { 23 super(name); 24 } 25 26 public void testExecTrue() throws Exception { 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 { 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 |