[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-1822) BaseSeamTest does not properly emulateJsfLifecycle does not handle phase listeners per the jsf 1.2 spec.

Sam Roberton (JIRA) jira-events at lists.jboss.org
Tue Sep 25 05:32:36 EDT 2007


    [ http://jira.jboss.com/jira/browse/JBSEAM-1822?page=comments#action_12378508 ] 
            
Sam Roberton commented on JBSEAM-1822:
--------------------------------------

Shane, sorry I haven't given you a test case yet --- unfortunately, other work commitments are getting in the way of me paying real attention to this.

Nonetheless, even without a test case, isn't it clear from visual inspection of the code that the BaseSeamTest$Request.emulateJsfLifecycle() method is incorrectly implemented?  It definitely doesn't handle exceptions raised by, say, the invokeApplication() method, even though in order to test Seam's actual behaviour in these circumstances, it needs to (at least) ensure that the phase listener's 'after phase' event is called.

In any case, I'll try a bit harder to free up some time to get you a decent test case (or set of test cases), and once I do that, I'll re-open this issue.

> BaseSeamTest does not properly emulateJsfLifecycle does not handle phase listeners per the jsf 1.2 spec.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JBSEAM-1822
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-1822
>             Project: JBoss Seam
>          Issue Type: Bug
>          Components: Test Harness
>    Affects Versions: 2.0.0.BETA1
>            Reporter: Chris Rudd
>         Assigned To: Shane Bryzak
>             Fix For: 2.0.0.GA
>
>
> Under the 1.2 JSF spec, all phase listeners are called with the after phase events reguarless of if an exception was thrown during the phase processing.
> The resulting issue is that when Init.isTransactionMangementEnabled is true, and and an exception (or an AssertionError) is thrown from within the phase method, the SeamPhase listner does not get a chance to handle the condition and rollback the transaction. This leaves the transaction open, and all further tests run for that class are now "tainted" as there is a transaction running that will never be completed.
> Wrapping code in the phase methods (restoreViewPhase,applyRequestValuesPhase,processValidationsPhase,updateModelValuesPhase,invokeApplicationsPhase, renderResponsePhase) like this will resolve the issue :
>       private void renderResponsePhase() throws Exception
>       {
>          phases.beforePhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE,
>                   MockLifecycle.INSTANCE));
> +        try
> +        {         
>           updateConversationId();
>          
>           renderResponseBegun = true;
>   
>           renderResponse();
>   
>           renderResponseComplete = true;
>   
>           facesContext.getApplication().getStateManager().saveView(facesContext);
>   
>           updateConversationId();
>  +      }
>  +      finally
>  +      {
>          phases.afterPhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE,
>                   MockLifecycle.INSTANCE));
> +       }
>       }
> it may be cleaner to refactor the phase methods into PhaseExection classes. (remove firing of phase events from the phase methods )
> 	public class PhaseExecution {
> 		private PhaseId phaseId;
> 		
> 		public PhaseExecution(PhaseId phaseId)
> 		{
> 			this.phaseId = phaseId;
> 		}
> 		
> 		protected abstract void execute() throws Exception
> 		
> 		public void run() throws Exception {
> 			fireBefore();
> 			try
> 			{
> 				execute();
> 			}
> 			finally
> 			{
> 				afterPhase();
> 			}
> 		}
> 		
> 		protected void fireBefore()
> 		{
> 			 phases.beforePhase(new PhaseEvent(facesContext, phaseId,
> 	                  MockLifecycle.INSTANCE));
> 		}
> 		protected void fireAfter()
> 		{
> 			 phases.afterPhase(new PhaseEvent(facesContext, phaseId,
> 	                  MockLifecycle.INSTANCE));
> 		}
> 	}
> 	
> 	final private PhaseExcecution RESTORE_VIEW_PHASE= new PhaseExecution(PhaseId.RESTORE_VIEW) {
> 		protected void execute() throws Exception {
> 			restoreViewPhase();
> 		}
> 	};
> 	
> 	final private PhaseExcecution RENDER_RESPONSE_PHASE= new PhaseExecution(PhaseId.RENDER_RESPONSE) {
> 		protected void execute() throws Exception {
> 			renderResponsePhase();
> 		}
> 	};
> 	...
> 	
>     /**
>      * @return true if a response was rendered
>      */
>     private boolean emulateJsfLifecycle() throws Exception
>     {
>        RESTORE_VIEW_PHASE.run();
>        if ( !isGetRequest() && !skipToRender() )
>        {
>           APPLY_REQUEST_VALUES_PHASE.run();
>           if (!skipToRender())
>           {
>              PROCESS_VALIDATIONS_PHASE.run();
>              if ( !skipToRender() )
>              {
>                 UPDATE_MODEL_VALUES_PHASE.run();
>                 if ( !skipToRender() )
>                 {
>                    INVOKE_APPLICATION_PHASE.run();
>                 }
>              }
>           }
>        }
>        
>        if ( skipRender() )
>        {
>           // we really should look at redirect parameters here!
>           return false;
>        }
>        else
>        {
>           RENDER_RESPONSE_PHASE.run();
>           return true;
>        }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list