|
From: Keith D. <kd...@us...> - 2006-04-30 19:25:39
|
Update of /cvsroot/springframework/spring-projects/spring-webflow/src/test/org/springframework/webflow In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4007/src/test/org/springframework/webflow Modified Files: FlowTests.java Log Message: polish / tests Index: FlowTests.java =================================================================== RCS file: /cvsroot/springframework/spring-projects/spring-webflow/src/test/org/springframework/webflow/FlowTests.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** FlowTests.java 30 Apr 2006 16:44:28 -0000 1.36 --- FlowTests.java 30 Apr 2006 19:25:35 -0000 1.37 *************** *** 16,27 **** --- 16,33 ---- package org.springframework.webflow; + import java.util.ArrayList; + import junit.framework.TestCase; import org.springframework.binding.expression.support.StaticExpression; + import org.springframework.context.support.StaticApplicationContext; import org.springframework.webflow.action.TestMultiAction; import org.springframework.webflow.builder.MyCustomException; import org.springframework.webflow.support.ApplicationView; import org.springframework.webflow.support.ApplicationViewSelector; + import org.springframework.webflow.support.BeanFactoryFlowVariable; import org.springframework.webflow.support.DefaultTargetStateResolver; + import org.springframework.webflow.support.EventIdTransitionCriteria; + import org.springframework.webflow.support.SimpleFlowVariable; import org.springframework.webflow.support.TransitionExecutingStateExceptionHandler; import org.springframework.webflow.test.MockFlowExecutionControlContext; *************** *** 40,46 **** ViewState state1 = new ViewState(flow, "myState1"); state1.setViewSelector(new ApplicationViewSelector(new StaticExpression("myView"))); ! state1.getTransitionSet().add(new Transition(to("myState2"))); EndState state2 = new EndState(flow, "myState2"); state2.setViewSelector(new ApplicationViewSelector(new StaticExpression("myView2"))); return flow; } --- 46,53 ---- ViewState state1 = new ViewState(flow, "myState1"); state1.setViewSelector(new ApplicationViewSelector(new StaticExpression("myView"))); ! state1.getTransitionSet().add(new Transition(on("submit"), to("myState2"))); EndState state2 = new EndState(flow, "myState2"); state2.setViewSelector(new ApplicationViewSelector(new StaticExpression("myView2"))); + flow.getGlobalTransitionSet().add(new Transition(on("globalEvent"), to("myState2"))); return flow; } *************** *** 162,166 **** Transition t = new Transition(new DefaultTargetStateResolver("myState2")); flow.getGlobalTransitionSet().add(t); ! assertSame(t, flow.getGlobalTransitionSet().toArray()[0]); } --- 169,173 ---- Transition t = new Transition(new DefaultTargetStateResolver("myState2")); flow.getGlobalTransitionSet().add(t); ! assertSame(t, flow.getGlobalTransitionSet().toArray()[1]); } *************** *** 180,183 **** --- 187,256 ---- } + public void testStartWithVariables() { + MockFlowExecutionControlContext context = new MockFlowExecutionControlContext(flow); + flow.addVariable(new SimpleFlowVariable("var1", ArrayList.class)); + StaticApplicationContext beanFactory = new StaticApplicationContext(); + beanFactory.registerPrototype("bean", ArrayList.class); + flow.addVariable(new BeanFactoryFlowVariable("var2", "bean", beanFactory)); + flow.start(context, new AttributeMap()); + assertEquals(2, context.getFlowScope().size()); + context.getFlowScope().getRequired("var1", ArrayList.class); + context.getFlowScope().getRequired("var2", ArrayList.class); + } + + public void testOnEventNullCurrentState() { + MockFlowExecutionControlContext context = new MockFlowExecutionControlContext(flow); + Event event = new Event(this, "foo"); + try { + flow.onEvent(event, context); + } catch (IllegalStateException e) { + + } + } + + public void testOnEventInvalidCurrentState() { + MockFlowExecutionControlContext context = new MockFlowExecutionControlContext(flow); + context.setCurrentState(flow.getState("myState2")); + Event event = new Event(this, "submit"); + context.setLastEvent(event); + try { + flow.onEvent(event, context); + } catch (IllegalStateException e) { + + } + } + + public void testOnEvent() { + MockFlowExecutionControlContext context = new MockFlowExecutionControlContext(flow); + context.setCurrentState(flow.getState("myState1")); + Event event = new Event(this, "submit"); + context.setLastEvent(event); + assertTrue(context.getFlowExecutionContext().isActive()); + flow.onEvent(event, context); + assertTrue(!context.getFlowExecutionContext().isActive()); + } + + public void testOnEventGlobalTransition() { + MockFlowExecutionControlContext context = new MockFlowExecutionControlContext(flow); + context.setCurrentState(flow.getState("myState1")); + Event event = new Event(this, "globalEvent"); + context.setLastEvent(event); + assertTrue(context.getFlowExecutionContext().isActive()); + flow.onEvent(event, context); + assertTrue(!context.getFlowExecutionContext().isActive()); + } + + public void testOnEventNoTransition() { + MockFlowExecutionControlContext context = new MockFlowExecutionControlContext(flow); + context.setCurrentState(flow.getState("myState1")); + Event event = new Event(this, "bogus"); + context.setLastEvent(event); + try { + flow.onEvent(event, context); + } catch (NoMatchingTransitionException e) { + + } + } + public void testEnd() { TestAction action = new TestAction(); *************** *** 212,215 **** --- 285,292 ---- } + public static TransitionCriteria on(String eventId) { + return new EventIdTransitionCriteria(eventId); + } + public static TargetStateResolver to(String stateId) { return new DefaultTargetStateResolver(stateId); |