myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdud...@apache.org
Subject svn commit: r330375 - in /myfaces/impl/trunk/src/test/org/apache/myfaces: el/TestConverter.java lifecycle/InstrumentingPhaseListener.java lifecycle/LifecycleImplCactus.java
Date Wed, 02 Nov 2005 22:13:08 GMT
Author: bdudney
Date: Wed Nov  2 14:13:03 2005
New Revision: 330375

URL: http://svn.apache.org/viewcvs?rev=330375&view=rev
Log:
fixing merge

Added:
    myfaces/impl/trunk/src/test/org/apache/myfaces/el/TestConverter.java
Modified:
    myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/InstrumentingPhaseListener.java
    myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/LifecycleImplCactus.java

Added: myfaces/impl/trunk/src/test/org/apache/myfaces/el/TestConverter.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/test/org/apache/myfaces/el/TestConverter.java?rev=330375&view=auto
==============================================================================
--- myfaces/impl/trunk/src/test/org/apache/myfaces/el/TestConverter.java (added)
+++ myfaces/impl/trunk/src/test/org/apache/myfaces/el/TestConverter.java Wed Nov  2 14:13:03
2005
@@ -0,0 +1,31 @@
+package org.apache.myfaces.el;
+
+import java.io.Serializable;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+public class TestConverter implements Converter, Serializable {
+	private static final long serialVersionUID = 8573936507630310334L;
+
+	public Object getAsObject(FacesContext context, UIComponent component,
+			String value) throws ConverterException {
+		return new Integer(value);
+	}
+
+	public String getAsString(FacesContext context, UIComponent component,
+			Object value) throws ConverterException {
+		String asString = null;
+		if(value == null) {
+			asString = "";
+		} else if(value instanceof String) {
+			asString = value.toString();
+		} else {
+			asString = ((Integer)value).intValue() + "";
+		}
+		return asString;
+	}
+
+}

Modified: myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/InstrumentingPhaseListener.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/InstrumentingPhaseListener.java?rev=330375&r1=330374&r2=330375&view=diff
==============================================================================
--- myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/InstrumentingPhaseListener.java
(original)
+++ myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/InstrumentingPhaseListener.java
Wed Nov  2 14:13:03 2005
@@ -9,8 +9,10 @@
 
 public class InstrumentingPhaseListener implements PhaseListener {
 	private static final long serialVersionUID = -3222250142846233648L;
-	private PhaseId phaseId = null;
+	private PhaseId listenPhaseId = null;
+	private PhaseId eventPhaseId = null;
 	private boolean before = true;
+	private boolean after = true;
 	private boolean render = false;
 	private boolean complete = false;
 	private List afterPhases = new ArrayList();
@@ -19,16 +21,16 @@
 	public InstrumentingPhaseListener() {
 	}
 
-	public InstrumentingPhaseListener(PhaseId interestingPhase) {
-		this.phaseId = interestingPhase;
+	public InstrumentingPhaseListener(PhaseId interestingPhaseId) {
+		this.listenPhaseId = interestingPhaseId;
 	}
 	
 	public void afterPhase(PhaseEvent event) {
 		afterPhases.add(event.getPhaseId());
-		if(null != phaseId && event.getPhaseId().equals(phaseId)) {
-			if(!before && render) {
+		if(null != eventPhaseId && event.getPhaseId().equals(eventPhaseId)) {
+			if(after && render) {
 				event.getFacesContext().renderResponse();
-			} else if(!before && complete) {
+			} else if(after && complete) {
 				event.getFacesContext().responseComplete();
 			}
 		}
@@ -36,7 +38,7 @@
 
 	public void beforePhase(PhaseEvent event) {
 		beforePhases.add(event.getPhaseId());
-		if(null != phaseId && event.getPhaseId().equals(phaseId)) {
+		if(null != eventPhaseId && event.getPhaseId().equals(eventPhaseId)) {
 			if(before && render) {
 				event.getFacesContext().renderResponse();
 			} else if(before && complete) {
@@ -53,6 +55,14 @@
 		this.before = before;
 	}
 
+	public boolean isAfter() {
+		return after;
+	}
+
+	public void setAfter(boolean after) {
+		this.after = after;
+	}
+
 	public boolean isComplete() {
 		return complete;
 	}
@@ -70,14 +80,14 @@
 	}
 
 	public PhaseId getPhaseId() {
-		if(null == phaseId) {
+		if(null == listenPhaseId) {
 			return PhaseId.ANY_PHASE;
 		}
-		return phaseId;
+		return listenPhaseId;
 	}
 
-	public void setPhaseId(PhaseId phaseId) {
-		this.phaseId = phaseId;
+	public void setEventPhaseId(PhaseId phaseId) {
+		this.eventPhaseId = phaseId;
 	}
 
 	public List getAfterPhases() {

Modified: myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/LifecycleImplCactus.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/LifecycleImplCactus.java?rev=330375&r1=330374&r2=330375&view=diff
==============================================================================
--- myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/LifecycleImplCactus.java (original)
+++ myfaces/impl/trunk/src/test/org/apache/myfaces/lifecycle/LifecycleImplCactus.java Wed
Nov  2 14:13:03 2005
@@ -1,7 +1,7 @@
 package org.apache.myfaces.lifecycle;
 
 import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
+import javax.faces.application.StateManager;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
@@ -9,36 +9,38 @@
 import javax.faces.event.PhaseId;
 import javax.faces.lifecycle.Lifecycle;
 import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.webapp.FacesServlet;
 
 import org.apache.cactus.ServletTestCase;
 import org.apache.cactus.WebRequest;
 
 public class LifecycleImplCactus extends ServletTestCase {
+	private FacesServlet servlet;
+
 	private FacesContext facesContext;
+
 	private Lifecycle lifecycle;
 
 	protected void setUp() throws Exception {
 		super.setUp();
-		FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder
-				.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+		servlet = new FacesServlet();
+		servlet.init(this.config);
 		LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
 				.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
-		lifecycle = lifecycleFactory
-				.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
-		for(int i = 0;i < lifecycle.getPhaseListeners().length; i++) {
-			if(lifecycle.getPhaseListeners()[i] instanceof InstrumentingPhaseListener) {
+		String lifecycleId = this.config.getServletContext().getInitParameter(
+				FacesServlet.LIFECYCLE_ID_ATTR);
+		lifecycleId = (lifecycleId != null ? lifecycleId
+				: LifecycleFactory.DEFAULT_LIFECYCLE);
+		lifecycle = lifecycleFactory.getLifecycle(lifecycleId);
+		for (int i = 0; i < lifecycle.getPhaseListeners().length; i++) {
+			if (lifecycle.getPhaseListeners()[i] instanceof InstrumentingPhaseListener) {
 				lifecycle.removePhaseListener(lifecycle.getPhaseListeners()[i]);
 			}
 		}
+		FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder
+				.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
 		facesContext = facesContextFactory.getFacesContext(this.config
 				.getServletContext(), request, response, lifecycle);
-		assertNotNull(facesContext);
-		Application application = facesContext.getApplication();
-		ViewHandler viewHandler = application.getViewHandler();
-		String viewId = "/index.jsp";
-		UIViewRoot viewRoot = viewHandler.createView(facesContext, viewId);
-		viewRoot.setViewId(viewId);
-		facesContext.setViewRoot(viewRoot);
 	}
 
 	protected void tearDown() throws Exception {
@@ -50,37 +52,672 @@
 	 * 'javax.faces.lifecycle.Lifecycle.addPhaseListener(PhaseListener)'
 	 */
 	public void testAddPhaseListenerPhaseListener() {
+	}
 
+	public void beginExecuteRestoreViewRenderBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
 	}
 
-	/*
-	 * Test method for 'javax.faces.lifecycle.Lifecycle.execute(FacesContext)'
-	 */
-	public void testExecuteFacesContextRestoreViewRenderBefore() {
-		InstrumentingPhaseListener listener = new InstrumentingPhaseListener(PhaseId.RESTORE_VIEW);
+	public void testExecuteRestoreViewRenderBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.RESTORE_VIEW);
 		listener.setBefore(true);
 		listener.setRender(true);
 		lifecycle.addPhaseListener(listener);
-		lifecycle.execute(facesContext);
+		servlet.service(this.request, this.response);
+		assertEquals(2, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases().get(1));
+		assertEquals(2, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases().get(1));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteRestoreViewRenderAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteRestoreViewRenderAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.RESTORE_VIEW);
+		listener.setAfter(true);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(2, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases().get(1));
+		assertEquals(2, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases().get(1));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteRestoreViewCompleteBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteRestoreViewCompleteBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.RESTORE_VIEW);
+		listener.setBefore(true);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
 		assertEquals(1, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
 		assertEquals(0, listener.getAfterPhases().size());
 		lifecycle.removePhaseListener(listener);
 	}
 
-	public void beforeExecute(WebRequest request) {
+	public void beginExecuteRestoreViewCompleteAfter(WebRequest request) {
 		request.addParameter("foo", "bar");
-		request.setURL("localhost:8080", "test-app", "faces", "test.jsp", null);
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
 	}
-	
-	public void testExecute() {
+
+	public void testExecuteRestoreViewCompleteAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
 		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.RESTORE_VIEW);
+		listener.setAfter(true);
 		listener.setBefore(false);
-		// build the viewId and serialzed view
+		listener.setComplete(true);
 		lifecycle.addPhaseListener(listener);
-		lifecycle.execute(facesContext);
-		// only goes through the restore view phase
+		servlet.service(this.request, this.response);
 		assertEquals(1, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
 		assertEquals(1, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteApplyRequestValuesRenderBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteApplyRequestValuesRenderBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+		listener.setBefore(true);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(3, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases().get(2));
+		assertEquals(3, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases().get(2));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteApplyRequestValuesRenderAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteApplyRequestValuesRenderAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+		listener.setAfter(true);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(3, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases().get(2));
+		assertEquals(3, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases().get(2));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteApplyRequestValuesCompleteBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteApplyRequestValuesCompleteBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+		listener.setBefore(true);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(2, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(1, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteApplyRequestValuesCompleteAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteApplyRequestValuesCompleteAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+		listener.setAfter(true);
+		listener.setBefore(false);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(2, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(2, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteProcessValidationsRenderBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteProcessValidationsRenderBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.PROCESS_VALIDATIONS);
+		listener.setBefore(true);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(4, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases()
+				.get(3));
+		assertEquals(4, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getAfterPhases()
+				.get(2));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases()
+				.get(3));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteProcessValidationsRenderAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteProcessValidationsRenderAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.PROCESS_VALIDATIONS);
+		listener.setAfter(true);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(4, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases()
+				.get(3));
+		assertEquals(4, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getAfterPhases()
+				.get(2));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases()
+				.get(3));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteProcessValidationsCompleteBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteProcessValidationsCompleteBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.PROCESS_VALIDATIONS);
+		listener.setBefore(true);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(3, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(2, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteProcessValidationsCompleteAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteProcessValidationsCompleteAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we would go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.PROCESS_VALIDATIONS);
+		listener.setAfter(true);
+		listener.setBefore(false);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		assertEquals(3, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(3, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getAfterPhases()
+				.get(2));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteUpdateModelValuesRenderBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteUpdateModelValuesRenderBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.UPDATE_MODEL_VALUES);
+		listener.setBefore(true);
+		listener.setAfter(false);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(5, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(PhaseId.UPDATE_MODEL_VALUES, listener.getBeforePhases()
+				.get(3));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases()
+				.get(4));
+		assertEquals(5, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getAfterPhases()
+				.get(2));
+		assertEquals(PhaseId.UPDATE_MODEL_VALUES, listener.getAfterPhases()
+				.get(3));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases()
+				.get(4));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteUpdateModelValuesRenderAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteUpdateModelValuesRenderAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.UPDATE_MODEL_VALUES);
+		listener.setBefore(false);
+		listener.setAfter(true);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(5, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(PhaseId.UPDATE_MODEL_VALUES, listener.getBeforePhases()
+				.get(3));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getBeforePhases()
+				.get(4));
+		assertEquals(5, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getAfterPhases()
+				.get(2));
+		assertEquals(PhaseId.UPDATE_MODEL_VALUES, listener.getAfterPhases()
+				.get(3));
+		assertEquals(PhaseId.RENDER_RESPONSE, listener.getAfterPhases()
+				.get(4));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteUpdateModelValuesCompleteBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteUpdateModelValuesCompleteBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.UPDATE_MODEL_VALUES);
+		listener.setBefore(true);
+		listener.setAfter(false);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(4, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(PhaseId.UPDATE_MODEL_VALUES, listener.getBeforePhases()
+				.get(3));
+		assertEquals(3, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getAfterPhases()
+				.get(2));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteUpdateModelValuesCompleteAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteUpdateModelValuesCompleteAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.UPDATE_MODEL_VALUES);
+		listener.setBefore(false);
+		listener.setAfter(true);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(4, listener.getBeforePhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getBeforePhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getBeforePhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getBeforePhases()
+				.get(2));
+		assertEquals(PhaseId.UPDATE_MODEL_VALUES, listener.getBeforePhases()
+				.get(3));
+		assertEquals(4, listener.getAfterPhases().size());
+		assertEquals(PhaseId.RESTORE_VIEW, listener.getAfterPhases().get(0));
+		assertEquals(PhaseId.APPLY_REQUEST_VALUES, listener.getAfterPhases()
+				.get(1));
+		assertEquals(PhaseId.PROCESS_VALIDATIONS, listener.getAfterPhases()
+				.get(2));
+		assertEquals(PhaseId.UPDATE_MODEL_VALUES, listener.getAfterPhases()
+				.get(3));
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteInvokeApplicationRenderBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteInvokeApplicationRenderBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.INVOKE_APPLICATION);
+		listener.setBefore(true);
+		listener.setAfter(false);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(6, listener.getBeforePhases().size());
+		assertEquals(6, listener.getAfterPhases().size());
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteInvokeApplicationRenderAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteInvokeApplicationRenderAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.INVOKE_APPLICATION);
+		listener.setBefore(false);
+		listener.setAfter(true);
+		listener.setRender(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(6, listener.getBeforePhases().size());
+		assertEquals(6, listener.getAfterPhases().size());
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteInvokeApplicationCompleteBefore(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteInvokeApplicationCompleteBefore() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.INVOKE_APPLICATION);
+		listener.setBefore(true);
+		listener.setAfter(false);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(5, listener.getBeforePhases().size());
+		assertEquals(4, listener.getAfterPhases().size());
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecuteInvokeApplicationCompleteAfter(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecuteInvokeApplicationCompleteAfter() throws Exception {
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		listener.setEventPhaseId(PhaseId.INVOKE_APPLICATION);
+		listener.setBefore(false);
+		listener.setAfter(true);
+		listener.setComplete(true);
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(5, listener.getBeforePhases().size());
+		assertEquals(5, listener.getAfterPhases().size());
+		lifecycle.removePhaseListener(listener);
+	}
+
+	public void beginExecute(WebRequest request) {
+		request.addParameter("foo", "bar");
+		request.setURL("localhost:8080", "/test-app", "/faces", "/index.jsp",
+				null);
+	}
+
+	public void testExecute() throws Exception {
+		// set the view root
+		setViewRoot("/index.jsp");
+		// simulate that this is the 2nd request for this page
+		// so that we will go through all 6 phases
+		StateManager stateManager = facesContext.getApplication()
+				.getStateManager();
+		stateManager.saveSerializedView(facesContext);
+		InstrumentingPhaseListener listener = new InstrumentingPhaseListener();
+		lifecycle.addPhaseListener(listener);
+		servlet.service(this.request, this.response);
+		// assert the phases were hit
+		assertEquals(6, listener.getBeforePhases().size());
+		assertEquals(6, listener.getAfterPhases().size());
 		lifecycle.removePhaseListener(listener);
 	}
 
@@ -104,6 +741,14 @@
 	 */
 	public void testRenderFacesContext() {
 
+	}
+
+	private void setViewRoot(String viewId) {
+		ViewHandler viewHandler = facesContext.getApplication()
+				.getViewHandler();
+		UIViewRoot viewRoot = viewHandler.createView(facesContext, viewId);
+		viewRoot.setViewId(viewId);
+		facesContext.setViewRoot(viewRoot);
 	}
 
 }



Mime
View raw message