@SuppressWarnings("serial")
@Test
public void testSeamPhaseListenerLongRunning()
{
MockFacesContext facesContext = createFacesContext();
getPageMap(facesContext).put( getPrefix() + Seam.getComponentName(FacesPage.class), new FacesPage() { @Override public String getConversationId() { return "2"; } });
List<String> conversationIdStack = new ArrayList<String>();
conversationIdStack.add("2");
ConversationEntries entries = new ConversationEntries();
entries.createConversationEntry("2", conversationIdStack);
SessionContext sessionContext = new SessionContext( new ServletRequestSessionMap( (HttpServletRequest) facesContext.getExternalContext().getRequest() ) );
sessionContext.set( Seam.getComponentName(ConversationEntries.class), entries );
SeamPhaseListener phases = new SeamPhaseListener();
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isApplicationContextActive();
assert !Contexts.isConversationContextActive();
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
assert !Contexts.isConversationContextActive();
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
assert Contexts.isConversationContextActive();
assert Manager.instance().isLongRunningConversation();
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
assert Manager.instance().isLongRunningConversation();
facesContext.getViewRoot().getAttributes().clear();
phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isApplicationContextActive();
assert Contexts.isConversationContextActive();
facesContext.getApplication().getStateManager().saveView(facesContext);
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() + Seam.getComponentName(FacesPage.class) ) ).getConversationId().equals("2");