1 package org.sapia.soto.state.util; 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 11 12 20 public class FormStepTest extends TestCase { 21 public FormStepTest(String name) { 22 super(name); 23 } 24 25 public void testExecute() { 26 ContextImpl ctx; 27 Result res = new Result(new StateMachine(), ctx = new ContextImpl()); 28 Scope sc = new MapScope(); 29 sc.putVal("firstName", "foo"); 30 sc.putVal("lastName", "bar"); 31 sc.putVal("age", "25"); 32 ctx.addScope("test", sc); 33 34 FormStep step = new FormStep(); 35 step.createParam().setFrom("firstName").setTo("firstName"); 36 step.createParam().setFrom("lastName").setTo("lastName"); 37 step.createParam().setFrom("age").setTo("age"); 38 step.setClass(TestFormBean.class.getName()); 39 step.execute(res); 40 41 TestFormBean bean = (TestFormBean) ctx.pop(); 42 super.assertEquals("foo", bean.getFirstName()); 43 super.assertEquals("bar", bean.getLastName()); 44 super.assertEquals(25, bean.getAge()); 45 46 step = new FormStep(); 47 step.createParam().setFrom("firstName").setTo("firstName").setScopes("test"); 48 step.createParam().setFrom("lastName").setTo("lastName").setScopes("test"); 49 step.createParam().setFrom("age").setTo("age").setScopes("test"); 50 step.setClass(TestFormBean.class.getName()); 51 step.execute(res); 52 bean = (TestFormBean) ctx.pop(); 53 super.assertEquals("foo", bean.getFirstName()); 54 super.assertEquals("bar", bean.getLastName()); 55 super.assertEquals(25, bean.getAge()); 56 } 57 } 58 | Popular Tags |