protected void setUp() throws Exception { requestContext = new MockRequestControlContext(); eventId = "userEvent"; modelName = "model"; codesResolver = new DefaultMessageCodesResolver(); }
public void testStartWithoutStartState() { MockRequestControlContext context = new MockRequestControlContext(flow); try { Flow empty = new Flow("empty"); empty.start(context, null); fail("should have failed"); } catch (IllegalStateException e) { } }
public void testOnEventNullCurrentState() { MockRequestControlContext context = new MockRequestControlContext(flow); Event event = new Event(this, "foo"); try { context.setCurrentEvent(event); flow.handleEvent(context); } catch (IllegalStateException e) { } }
public void testStart() { MockRequestControlContext context = new MockRequestControlContext(flow); flow.start(context, new LocalAttributeMap<>()); assertEquals("Wrong start state", "myState1", context.getCurrentState().getId()); }
public void testCouldNotHandleException() { FlowExecutionException e = new FlowExecutionException(flow.getId(), state.getId(), "Whatev"); MockRequestControlContext context = new MockRequestControlContext(flow); assertFalse(state.handleException(e, context)); }
public void testOnEventInvalidCurrentState() { MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState2")); Event event = new Event(this, "submit"); context.setCurrentEvent(event); try { context.setCurrentEvent(event); flow.handleEvent(context); } catch (IllegalStateException e) { } }
public void testEnterEndStateTerminateFlowExecution() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "end"); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertFalse("Active", context.getFlowExecutionContext().isActive()); }
public void testStartWithVariables() { MockRequestControlContext context = new MockRequestControlContext(flow); flow.addVariable(new FlowVariable("var1", new VariableValueFactory() { public Object createInitialValue(RequestContext context) { return new ArrayList<>(); } public void restoreReferences(Object value, RequestContext context) { } })); flow.start(context, new LocalAttributeMap<>()); context.getFlowScope().getRequired("var1", ArrayList.class); }
public void testStateEnter() { assertEquals("myState", state.getId()); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertEquals(state, context.getCurrentState()); assertTrue(entered); }
public void testEnd() { TestAction action = new TestAction(); flow.getEndActionList().add(action); MockRequestControlContext context = new MockRequestControlContext(flow); LocalAttributeMap<Object> sessionOutput = new LocalAttributeMap<>(); flow.end(context, "finish", sessionOutput); assertEquals(1, action.getExecutionCount()); }
public void testEnterEndStateWithFinalResponseRendererResponseAlreadyComplete() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "end"); StubFinalResponseAction action = new StubFinalResponseAction(); state.setFinalResponseAction(action); MockRequestControlContext context = new MockRequestControlContext(flow); context.getExternalContext().recordResponseComplete(); state.enter(context); assertFalse(action.executeCalled); }
public void testStartWithAction() { MockRequestControlContext context = new MockRequestControlContext(flow); TestAction action = new TestAction(); flow.getStartActionList().add(action); flow.start(context, new LocalAttributeMap<>()); assertEquals("Wrong start state", "myState1", context.getCurrentState().getId()); assertEquals(1, action.getExecutionCount()); }
public void testStateEnterWithEntryAction() { TestAction action = new TestAction(); state.getEntryActionList().add(action); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertEquals(state, context.getCurrentState()); assertTrue(action.isExecuted()); assertTrue(entered); assertEquals(1, action.getExecutionCount()); }
public void testIfDecision() { Flow flow = new Flow("flow"); DecisionState state = new DecisionState(flow, "decisionState"); state.getTransitionSet().add(new Transition(new MockTransitionCriteria("foo"), to("target"))); new EndState(flow, "target"); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentEvent(new Event(this, "foo")); state.enter(context); assertFalse(context.getFlowExecutionContext().isActive()); }
public void testEnterViewStateWithAlwaysRedirectOnPause() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); context.getFlashScope().put("foo", "bar"); context.setAlwaysRedirectOnPause(true); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getFlashScope().contains("foo")); }
public void testHandleException() { flow.getExceptionHandlerSet().add( new TransitionExecutingFlowExecutionExceptionHandler().add(TestException.class, "myState2")); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState1")); FlowExecutionException e = new FlowExecutionException(flow.getId(), flow.getStartState().getId(), "Oops!", new TestException()); flow.handleException(e, context); assertFalse(context.getFlowExecutionContext().isActive()); }
public void testEnterViewStateWithNoLocalRedirect() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(false); MockRequestControlContext context = new MockRequestControlContext(flow); context.getFlashScope().put("foo", "bar"); state.enter(context); assertTrue("Render called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); }
public void testEnterViewStateRedirectResponseAlreadyComplete() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); context.getExternalContext().requestFlowExecutionRedirect(); context.getFlashScope().put("foo", "bar"); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getFlashScope().contains("foo")); }
public void testEnterViewStateRenderResponse() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); context.getFlashScope().put("foo", "bar"); state.enter(context); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); }
public void testElseDecision() { Flow flow = new Flow("flow"); DecisionState state = new DecisionState(flow, "decisionState"); state.getTransitionSet().add(new Transition(new MockTransitionCriteria("foo"), to("invalid"))); state.getTransitionSet().add(new Transition(to("target"))); new EndState(flow, "target"); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentEvent(new Event(this, "bogus")); state.enter(context); assertFalse(context.getFlowExecutionContext().isActive()); }