You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mb...@apache.org on 2007/03/07 23:06:59 UTC

svn commit: r515800 - in /myfaces/core/branches/jsf12/api/src: main/java-templates/javax/faces/component/UIViewRootTemplate.java main/java/javax/faces/event/PhaseEvent.java test/java/javax/faces/component/UIViewRootTest.java

Author: mbr
Date: Wed Mar  7 14:06:59 2007
New Revision: 515800

URL: http://svn.apache.org/viewvc?view=rev&rev=515800
Log:
Implement phase listener logic in UIViewRoot
+locale of UIViewRoot is initialized and calculated in ViewHandler

Added:
    myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIViewRootTest.java   (with props)
Modified:
    myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIViewRootTemplate.java
    myfaces/core/branches/jsf12/api/src/main/java/javax/faces/event/PhaseEvent.java

Modified: myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIViewRootTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIViewRootTemplate.java?view=diff&rev=515800&r1=515799&r2=515800
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIViewRootTemplate.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIViewRootTemplate.java Wed Mar  7 14:06:59 2007
@@ -15,18 +15,26 @@
 */
 package javax.faces.component;
 
+import javax.faces.FactoryFinder;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.webapp.FacesServlet;
+import javax.el.MethodExpression;
 import javax.el.ValueExpression;
 import java.util.ArrayList;
 import java.util.ConcurrentModificationException;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * @author Andreas Berger (latest modification by $Author$)
@@ -38,24 +46,24 @@
 {
     private static final int ANY_PHASE_ORDINAL = PhaseId.ANY_PHASE.getOrdinal();
     public static final String UNIQUE_ID_PREFIX = "j_id";
+    
+    private final Logger logger = Logger.getLogger(UIViewRootTemplate.class.getName());
 
     // todo: is it right to save the state of _events and _phaseListeners?
     /**/ // removes the generated methods so only state saving stays
-    /**///getEvents
-    /**///setEvents
-    /**///getUniqueIdCounter
-    /**///setUniqueIdCounter
-    /**///getPhaseListeners
+    /**/// getEvents
+    /**/// setEvents
+    /**/// getUniqueIdCounter
+    /**/// setUniqueIdCounter
+    /**/// getPhaseListeners
     /**/private List<FacesEvent> _events = null;
     /**/private long _uniqueIdCounter = 0;
-    /**/private Locale _locale;
+    
+    private transient Lifecycle _lifecycle = null;
 
     public void queueEvent(FacesEvent event)
     {
-        if (event == null)
-        {
-            throw new NullPointerException("event");
-        }
+        checkNull(event, "event");
         if (_events == null)
         {
             _events = new ArrayList<FacesEvent>();
@@ -63,6 +71,167 @@
         _events.add(event);
     }
 
+
+    public void processDecodes(final FacesContext context)
+    {
+        checkNull(context, "context");
+        process(context, PhaseId.APPLY_REQUEST_VALUES, new Processor() 
+        {
+            public void process()
+            {
+                UIViewRootTemplate.super.processDecodes(context);
+            }
+        }, true);
+    }
+
+    public void processValidators(final FacesContext context)
+    {
+        checkNull(context, "context");
+        process(context, PhaseId.PROCESS_VALIDATIONS, new Processor() 
+        {
+            public void process()
+            {
+                UIViewRootTemplate.super.processValidators(context);
+            }
+        }, true);
+    }
+
+    public void processUpdates(final FacesContext context)
+    {
+        checkNull(context, "context");
+        process(context, PhaseId.UPDATE_MODEL_VALUES, new Processor() 
+        {
+            public void process()
+            {
+                UIViewRootTemplate.super.processUpdates(context);
+            }
+        }, true);
+    }
+
+    public void processApplication(final FacesContext context)
+    {
+        checkNull(context, "context");
+        process(context, PhaseId.INVOKE_APPLICATION, null, true);
+    }
+
+    public void encodeBegin(FacesContext context)
+            throws java.io.IOException
+    {
+        checkNull(context, "context");
+        
+        boolean skipPhase = false;
+
+        try 
+        {
+            skipPhase = notifyListeners(context, PhaseId.RENDER_RESPONSE, getBeforePhaseListener(), true);
+        }
+        catch (Exception e)
+        {
+            // following the spec we have to swallow the exception
+            logger.log(Level.SEVERE, "Exception while processing phase listener: " + e.getMessage(), e);
+        }
+        
+        if(!skipPhase)
+        {
+            super.encodeBegin(context);
+        }
+    }
+    
+    public void encodeEnd(FacesContext context) throws java.io.IOException
+    {
+        checkNull(context, "context");
+        super.encodeEnd(context);     
+        try
+        {
+            notifyListeners(context, PhaseId.RENDER_RESPONSE, getAfterPhaseListener(), false);
+        } 
+        catch (Exception e)
+        {
+            // following the spec we have to swallow the exception
+            logger.log(Level.SEVERE, "Exception while processing phase listener: " + e.getMessage(), e);
+        }
+    }
+
+    /*
+     * Provides a unique id for this component instance.
+     */
+    public String createUniqueId()
+    {
+        ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
+        return extCtx.encodeNamespace(UNIQUE_ID_PREFIX + _uniqueIdCounter++);
+    }
+    
+    private boolean process(FacesContext context, PhaseId phaseId, Processor processor, boolean broadcast) 
+    {      
+        if(!notifyListeners(context, phaseId, getBeforePhaseListener(), true))
+        {
+            if(processor != null)
+                processor.process();
+            
+            if(broadcast)
+            {
+                _broadcastForPhase(phaseId);
+                if (context.getRenderResponse() || context.getResponseComplete())
+                {
+                    clearEvents();
+                }
+            }
+        }
+        return notifyListeners(context, phaseId, getAfterPhaseListener(), false);
+    }
+    
+    private boolean notifyListeners(FacesContext context, PhaseId phaseId, MethodExpression listener, boolean beforePhase)
+    {
+        boolean skipPhase = false;
+        
+        if(listener != null || (_phaseListeners != null && !_phaseListeners.isEmpty()))
+        {
+            PhaseEvent event = createEvent(context, phaseId);
+            
+            if(listener != null) 
+            {
+                listener.invoke(context.getELContext(), new Object[] { event });
+                skipPhase = context.getResponseComplete() || context.getRenderResponse();
+            }
+            
+            if(_phaseListeners != null && !_phaseListeners.isEmpty()) 
+            {
+                for(PhaseListener phaseListener : _phaseListeners)
+                {
+                    PhaseId listenerPhaseId = phaseListener.getPhaseId();
+                    if(phaseId.equals(listenerPhaseId) || PhaseId.ANY_PHASE.equals(listenerPhaseId))
+                    {
+                        if(beforePhase)
+                        {
+                            phaseListener.beforePhase(event);
+                        }
+                        else
+                        {
+                            phaseListener.afterPhase(event);
+                        }
+                        skipPhase = context.getResponseComplete() || context.getRenderResponse();
+                    }
+                }
+            }
+        }
+        
+        return skipPhase;
+    }
+    
+    private PhaseEvent createEvent(FacesContext context, PhaseId phaseId)
+    {
+        if (_lifecycle == null)
+        {
+            LifecycleFactory factory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+            String id = context.getExternalContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
+            if(id == null) {
+                id = LifecycleFactory.DEFAULT_LIFECYCLE;
+            }
+            _lifecycle = factory.getLifecycle(id);
+        }
+        return new PhaseEvent(context, phaseId, _lifecycle);
+    }
+    
     private void _broadcastForPhase(PhaseId phaseId)
     {
         if (_events == null)
@@ -89,12 +258,12 @@
                 {
                     // abort event processing
                     // Page 3-30 of JSF 1.1 spec: "Throw an AbortProcessingException, to tell the JSF implementation
-                    //  that no further broadcast of this event, or any further events, should take place."
+                    // that no further broadcast of this event, or any further events, should take place."
                     abort = true;
                     break;
-                } finally
+                } 
+                finally
                 {
-
                     try
                     {
                         listiterator.remove();
@@ -121,160 +290,18 @@
     {
         _events = null;
     }
-
-
-    public void processDecodes(FacesContext context)
-    {
-        if (context == null)
-        {
-            throw new NullPointerException("context");
-        }
-        super.processDecodes(context);
-        _broadcastForPhase(PhaseId.APPLY_REQUEST_VALUES);
-        if (context.getRenderResponse() || context.getResponseComplete())
-        {
-            clearEvents();
-        }
-    }
-
-    public void processValidators(FacesContext context)
-    {
-        if (context == null)
-        {
-            throw new NullPointerException("context");
-        }
-        super.processValidators(context);
-        _broadcastForPhase(PhaseId.PROCESS_VALIDATIONS);
-        if (context.getRenderResponse() || context.getResponseComplete())
-        {
-            clearEvents();
-        }
-    }
-
-    public void processUpdates(FacesContext context)
-    {
-        if (context == null)
-        {
-            throw new NullPointerException("context");
-        }
-        super.processUpdates(context);
-        _broadcastForPhase(PhaseId.UPDATE_MODEL_VALUES);
-        if (context.getRenderResponse() || context.getResponseComplete())
-        {
-            clearEvents();
-        }
-    }
-
-    public void processApplication(FacesContext context)
+    
+    private void checkNull(Object value, String valueLabel)
     {
-        if (context == null)
-        {
-            throw new NullPointerException("context");
-        }
-        _broadcastForPhase(PhaseId.INVOKE_APPLICATION);
-        if (context.getRenderResponse() || context.getResponseComplete())
+        if(value == null)
         {
-            clearEvents();
+            throw new NullPointerException(valueLabel + " is null");
         }
     }
 
-    public void encodeBegin(FacesContext context)
-            throws java.io.IOException
-    {
-        clearEvents();
-        super.encodeBegin(context);
-    }
-
-    /* Provides a unique id for this component instance.
-    */
-    public String createUniqueId()
+    private interface Processor
     {
-        ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
-        return extCtx.encodeNamespace(UNIQUE_ID_PREFIX + _uniqueIdCounter++);
+        void process();
     }
 
-    /**
-     * Gets The locale for this ViewRoot.
-     *
-     * @return the new locale value
-     */
-    /**///getLocale
-    public Locale getLocale()
-    {
-        if (_locale != null)
-        {
-            return _locale;
-        }
-        ValueExpression expression = getValueExpression("locale");
-        FacesContext facesContext = getFacesContext();
-        if (expression == null)
-        {
-            return facesContext.getApplication().getViewHandler().calculateLocale(facesContext);
-        }
-        Object locale = expression.getValue(getFacesContext().getELContext());
-        if (locale == null)
-        {
-            return facesContext.getApplication().getViewHandler().calculateLocale(facesContext);
-        }
-        if (locale instanceof Locale)
-        {
-            return (Locale) locale;
-        } else if (locale instanceof String)
-        {
-            return getLocale((String) locale);
-        } else
-        {
-            //TODO: not specified!?
-            throw new IllegalArgumentException("locale binding");
-        }
-    }
-
-
-    /**
-     * Create Locale from String representation.
-     * <p/>
-     * http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html
-     *
-     * @param locale locale representation in String.
-     * @return Locale instance
-     */
-    private static Locale getLocale(String locale)
-    {
-        int cnt = 0;
-        int pos = 0;
-        int prev = 0;
-
-        // store locale variation.
-        // ex. "ja_JP_POSIX"
-        //  lv[0] : language(ja)
-        //  lv[1] : country(JP)
-        //  lv[2] : variant(POSIX)
-        String[] lv = new String[3];
-        Locale l = null;
-
-        while ((pos = locale.indexOf('_', prev)) != -1)
-        {
-            lv[cnt++] = locale.substring(prev, pos);
-            prev = pos + 1;
-        }
-
-        lv[cnt++] = locale.substring(prev, locale.length());
-
-        switch (cnt)
-        {
-            case 1:
-                // create Locale from language.
-                l = new Locale(lv[0]);
-                break;
-            case 2:
-                // create Locale from language and country.
-                l = new Locale(lv[0], lv[1]);
-                break;
-            case 3:
-                // create Locale from language, country and variant.
-                l = new Locale(lv[0], lv[1], lv[2]);
-                break;
-        }
-        return l;
-    }   
 }

Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/event/PhaseEvent.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/event/PhaseEvent.java?view=diff&rev=515800&r1=515799&r2=515800
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/event/PhaseEvent.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/event/PhaseEvent.java Wed Mar  7 14:06:59 2007
@@ -55,4 +55,51 @@
 		return _phaseId;
 	}
 
+    @Override
+    public int hashCode()
+    {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + ((source == null) ? 0 : source.hashCode());
+        result = PRIME * result + ((_facesContext == null) ? 0 : _facesContext.hashCode());
+        result = PRIME * result + ((_phaseId == null) ? 0 : _phaseId.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final PhaseEvent other = (PhaseEvent) obj;
+        if (source == null)
+        {
+            if (other.source != null)
+                return false;
+        }
+        else if (!source.equals(other.source))
+            return false;
+        if (_facesContext == null)
+        {
+            if (other._facesContext != null)
+                return false;
+        }
+        else if (!_facesContext.equals(other._facesContext))
+            return false;
+        if (_phaseId == null)
+        {
+            if (other._phaseId != null)
+                return false;
+        }
+        else if (!_phaseId.equals(other._phaseId))
+            return false;
+        return true;
+    }
+    
+
+    
 }

Added: myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIViewRootTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIViewRootTest.java?view=auto&rev=515800
==============================================================================
--- myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIViewRootTest.java (added)
+++ myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIViewRootTest.java Wed Mar  7 14:06:59 2007
@@ -0,0 +1,538 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package javax.faces.component;
+
+import static org.easymock.EasyMock.*;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.MethodExpression;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.context.ExternalContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.webapp.FacesServlet;
+
+import junit.framework.TestCase;
+
+import org.apache.myfaces.TestRunner;
+import org.apache.shale.test.mock.MockFacesContext12;
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class UIViewRootTest extends TestCase
+{
+    private Map<PhaseId, Class<? extends PhaseListener>> phaseListenerClasses;
+    private IMocksControl _mocksControl;
+    private MockFacesContext12 _facesContext;
+    private UIViewRoot _testimpl;
+    private ExternalContext _externalContext;
+    private Application _application;
+    private Lifecycle _lifecycle;
+    private LifecycleFactory _lifecycleFactory;
+    private ELContext _elContext;
+
+    private static ThreadLocal<LifecycleFactory> LIFECYCLEFACTORY = new ThreadLocal<LifecycleFactory>();
+
+    protected void setUp() throws Exception
+    {
+        phaseListenerClasses = new HashMap<PhaseId, Class<? extends PhaseListener>>();
+        phaseListenerClasses.put(PhaseId.APPLY_REQUEST_VALUES, ApplyRequesValuesPhaseListener.class);
+        phaseListenerClasses.put(PhaseId.PROCESS_VALIDATIONS, ProcessValidationsPhaseListener.class);
+        phaseListenerClasses.put(PhaseId.UPDATE_MODEL_VALUES, UpdateModelValuesPhaseListener.class);
+        phaseListenerClasses.put(PhaseId.INVOKE_APPLICATION, InvokeApplicationPhaseListener.class);
+        phaseListenerClasses.put(PhaseId.RENDER_RESPONSE, RenderResponsePhaseListener.class);
+
+        _mocksControl = EasyMock.createControl();
+        _externalContext = _mocksControl.createMock(ExternalContext.class);
+        _facesContext = new MockFacesContext12(_externalContext);
+        _application = _mocksControl.createMock(Application.class);
+        _lifecycleFactory = _mocksControl.createMock(LifecycleFactory.class);
+        _testimpl = new UIViewRoot();
+        _lifecycle = _mocksControl.createMock(Lifecycle.class);
+        _elContext = _mocksControl.createMock(ELContext.class);
+        _facesContext.setELContext(_elContext);
+
+        LIFECYCLEFACTORY.set(_lifecycleFactory);
+        FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, MockLifeCycleFactory.class.getName());
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        FactoryFinder.releaseFactories();
+    }
+
+    public void testSuperClass() throws Exception
+    {
+        assertEquals(UIComponentBase.class, UIViewRoot.class.getSuperclass());
+    }
+
+    public void testComponentType() throws Exception
+    {
+        assertEquals("javax.faces.ViewRoot", UIViewRoot.COMPONENT_TYPE);
+    }
+
+    public void testLocale() throws Exception
+    {
+        _mocksControl.replay();
+        assertNull(_testimpl.getLocale());
+        _testimpl.setLocale(Locale.JAPANESE);
+        assertEquals(Locale.JAPANESE, _testimpl.getLocale());
+        _mocksControl.verify();
+    }
+
+    /**
+     * Test method for {@link javax.faces.component.UIViewRoot#createUniqueId()}.
+     */
+    public void testCreateUniqueId()
+    {
+        expect(_externalContext.encodeNamespace((String) anyObject())).andAnswer(new IAnswer<String>()
+        {
+            public String answer() throws Throwable
+            {
+                return (String) getCurrentArguments()[0];
+            }
+        }).anyTimes();
+        _mocksControl.replay();
+        Collection createdIds = new HashSet();
+        for (int i = 0; i < 10000; i++)
+        {
+            if (!createdIds.add(_testimpl.createUniqueId()))
+            {
+                fail("duplicate id created");
+            }
+        }
+        _mocksControl.verify();
+    }
+
+    /**
+     * Test method for {@link javax.faces.component.UIViewRoot#processDecodes(javax.faces.context.FacesContext)}.
+     * 
+     * @throws Throwable
+     */
+    public void testProcessDecodes() throws Throwable
+    {
+        testProcessXXX(new TestRunner()
+        {
+            public void run() throws Throwable
+            {
+                _testimpl.processDecodes(_facesContext);
+            }
+        }, PhaseId.APPLY_REQUEST_VALUES, false, true, true);
+    }
+
+    /**
+     * Test method for {@link javax.faces.component.UIViewRoot#processValidators(javax.faces.context.FacesContext)}.
+     * 
+     * @throws Throwable
+     */
+    public void testProcessValidators() throws Throwable
+    {
+        testProcessXXX(new TestRunner()
+        {
+            public void run() throws Throwable
+            {
+                _testimpl.processValidators(_facesContext);
+            }
+        }, PhaseId.PROCESS_VALIDATIONS, false, true, true);
+    }
+
+    /**
+     * Test method for {@link javax.faces.component.UIViewRoot#processUpdates(javax.faces.context.FacesContext)}.
+     * 
+     * @throws Throwable
+     */
+    public void testProcessUpdates() throws Throwable
+    {
+        testProcessXXX(new TestRunner()
+        {
+            public void run() throws Throwable
+            {
+                _testimpl.processUpdates(_facesContext);
+            }
+        }, PhaseId.UPDATE_MODEL_VALUES, false, true, true);
+    }
+
+    /**
+     * Test method for {@link javax.faces.component.UIViewRoot#processApplication(javax.faces.context.FacesContext)}.
+     * 
+     * @throws Throwable
+     */
+    public void testProcessApplication() throws Throwable
+    {
+        testProcessXXX(new TestRunner()
+        {
+            public void run() throws Throwable
+            {
+                _testimpl.processApplication(_facesContext);
+            }
+        }, PhaseId.INVOKE_APPLICATION, false, true, true);
+    }
+
+    /**
+     * Test method for {@link javax.faces.component.UIViewRoot#encodeBegin(javax.faces.context.FacesContext)}.
+     * 
+     * @throws Throwable
+     */
+    public void testEncodeBegin() throws Throwable
+    {
+        testProcessXXX(new TestRunner()
+        {
+            public void run() throws Throwable
+            {
+                _testimpl.encodeBegin(_facesContext);
+            }
+        }, PhaseId.RENDER_RESPONSE, false, true, false);
+    }
+
+    /**
+     * Test method for {@link javax.faces.component.UIViewRoot#encodeEnd(javax.faces.context.FacesContext)}.
+     * 
+     * @throws Throwable
+     */
+    public void testEncodeEnd() throws Throwable
+    {
+        testProcessXXX(new TestRunner()
+        {
+            public void run() throws Throwable
+            {
+                _testimpl.encodeEnd(_facesContext);
+            }
+        }, PhaseId.RENDER_RESPONSE, false, false, true);
+    }
+
+    public void testEventQueue() throws Exception
+    {
+        FacesEvent event = _mocksControl.createMock(FacesEvent.class);
+        expect(event.getPhaseId()).andReturn(PhaseId.APPLY_REQUEST_VALUES).anyTimes();
+        UIComponent component = _mocksControl.createMock(UIComponent.class);
+        expect(event.getComponent()).andReturn(component).anyTimes();
+        component.broadcast(same(event));
+        _testimpl.queueEvent(event);
+
+        event = _mocksControl.createMock(FacesEvent.class);
+        expect(event.getPhaseId()).andReturn(PhaseId.PROCESS_VALIDATIONS).anyTimes();
+        _testimpl.queueEvent(event);
+
+        _mocksControl.replay();
+        _testimpl.processDecodes(_facesContext);
+        _mocksControl.verify();
+    }
+
+    public void testEventQueueWithAbortExcpetion() throws Exception
+    {
+        FacesEvent event = _mocksControl.createMock(FacesEvent.class);
+        expect(event.getPhaseId()).andReturn(PhaseId.INVOKE_APPLICATION).anyTimes();
+        UIComponent component = _mocksControl.createMock(UIComponent.class);
+        expect(event.getComponent()).andReturn(component).anyTimes();
+        component.broadcast(same(event));
+        expectLastCall().andThrow(new AbortProcessingException());
+        _testimpl.queueEvent(event);
+
+        event = _mocksControl.createMock(FacesEvent.class);
+        expect(event.getPhaseId()).andReturn(PhaseId.INVOKE_APPLICATION).anyTimes();
+        _testimpl.queueEvent(event);
+
+        _mocksControl.replay();
+        _testimpl.processApplication(_facesContext);
+        _mocksControl.verify();
+    }
+
+    //
+    //
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#saveState(javax.faces.context.FacesContext)}.
+    // */
+    // public void testSaveState()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for
+    // * {@link javax.faces.component.UIViewRoot#restoreState(javax.faces.context.FacesContext, java.lang.Object)}.
+    // */
+    // public void testRestoreState()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#UIViewRoot()}.
+    // */
+    // public void testUIViewRoot()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#setLocale(java.util.Locale)}.
+    // */
+    // public void testSetLocale()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#getRenderKitId()}.
+    // */
+    // public void testGetRenderKitId()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#setRenderKitId(java.lang.String)}.
+    // */
+    // public void testSetRenderKitId()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#getViewId()}.
+    // */
+    // public void testGetViewId()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#setViewId(java.lang.String)}.
+    // */
+    // public void testSetViewId()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#addPhaseListener(javax.faces.event.PhaseListener)}.
+    // */
+    // public void testAddPhaseListener()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#removePhaseListener(javax.faces.event.PhaseListener)}.
+    // */
+    // public void testRemovePhaseListener()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#getBeforePhaseListener()}.
+    // */
+    // public void testGetBeforePhaseListener()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#setBeforePhaseListener(javax.el.MethodExpression)}.
+    // */
+    // public void testSetBeforePhaseListener()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#getAfterPhaseListener()}.
+    // */
+    // public void testGetAfterPhaseListener()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#setAfterPhaseListener(javax.el.MethodExpression)}.
+    // */
+    // public void testSetAfterPhaseListener()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+    // /**
+    // * Test method for {@link javax.faces.component.UIViewRoot#getFamily()}.
+    // */
+    // public void testGetFamily()
+    // {
+    // fail("Not yet implemented"); // TODO
+    // }
+    //
+
+    private void testProcessXXX(TestRunner runner, PhaseId phaseId, boolean expectSuperCall, boolean checkBefore,
+            boolean checkAfter) throws Throwable
+    {
+        expect(_lifecycleFactory.getLifecycle(eq(LifecycleFactory.DEFAULT_LIFECYCLE))).andReturn(_lifecycle);
+        expect(_externalContext.getInitParameter(eq(FacesServlet.LIFECYCLE_ID_ATTR))).andReturn(null).anyTimes();
+
+        PhaseEvent event = new PhaseEvent(_facesContext, phaseId, _lifecycle);
+
+        if (expectSuperCall)
+            _testimpl = _mocksControl.createMock(UIViewRoot.class, new Method[] { UIViewRoot.class.getMethod(
+                    "isRendered", new Class[0]) });
+
+        MethodExpression beforeListener = _mocksControl.createMock(MethodExpression.class);
+        _testimpl.setBeforePhaseListener(beforeListener);
+
+        MethodExpression afterListener = _mocksControl.createMock(MethodExpression.class);
+        _testimpl.setAfterPhaseListener(afterListener);
+
+        Method[] mockedMethods = new Method[] {
+                PhaseListener.class.getMethod("beforePhase", new Class[] { PhaseEvent.class }),
+                PhaseListener.class.getMethod("afterPhase", new Class[] { PhaseEvent.class }) };
+        PhaseListener phaseListener = _mocksControl.createMock(phaseListenerClasses.get(phaseId), mockedMethods);
+        _testimpl.addPhaseListener(phaseListener);
+
+        PhaseListener anyPhaseListener = _mocksControl.createMock(AnyPhasePhaseListener.class, mockedMethods);
+        _testimpl.addPhaseListener(anyPhaseListener);
+
+        PhaseListener restoreViewPhaseListener = _mocksControl.createMock(RestoreViewPhasePhaseListener.class,
+                mockedMethods);
+        _testimpl.addPhaseListener(restoreViewPhaseListener);
+
+        _mocksControl.checkOrder(true);
+
+        if (checkBefore)
+        {
+            expect(beforeListener.invoke(eq(_facesContext.getELContext()), aryEq(new Object[] { event }))).andReturn(
+                    null);
+            phaseListener.beforePhase(eq(event));
+            anyPhaseListener.beforePhase(eq(event));
+        }
+
+        if (expectSuperCall)
+            expect(_testimpl.isRendered()).andReturn(false);
+
+        if (checkAfter)
+        {
+            expect(afterListener.invoke(eq(_facesContext.getELContext()), aryEq(new Object[] { event }))).andReturn(
+                    null);
+            phaseListener.afterPhase(eq(event));
+            anyPhaseListener.afterPhase(eq(event));
+        }
+
+        _mocksControl.replay();
+        runner.run();
+        _mocksControl.verify();
+    }
+
+    public static class MockLifeCycleFactory extends LifecycleFactory
+    {
+
+        @Override
+        public void addLifecycle(String lifecycleId, Lifecycle lifecycle)
+        {
+            LIFECYCLEFACTORY.get().addLifecycle(lifecycleId, lifecycle);
+        }
+
+        @Override
+        public Lifecycle getLifecycle(String lifecycleId)
+        {
+            return LIFECYCLEFACTORY.get().getLifecycle(lifecycleId);
+        }
+
+        @Override
+        public Iterator<String> getLifecycleIds()
+        {
+            return LIFECYCLEFACTORY.get().getLifecycleIds();
+        }
+
+    }
+
+    public static abstract class ApplyRequesValuesPhaseListener implements PhaseListener
+    {
+        public PhaseId getPhaseId()
+        {
+            return PhaseId.APPLY_REQUEST_VALUES;
+        }
+    }
+
+    public static abstract class ProcessValidationsPhaseListener implements PhaseListener
+    {
+        public PhaseId getPhaseId()
+        {
+            return PhaseId.PROCESS_VALIDATIONS;
+        }
+    }
+
+    public static abstract class UpdateModelValuesPhaseListener implements PhaseListener
+    {
+        public PhaseId getPhaseId()
+        {
+            return PhaseId.UPDATE_MODEL_VALUES;
+        }
+    }
+
+    public static abstract class InvokeApplicationPhaseListener implements PhaseListener
+    {
+        public PhaseId getPhaseId()
+        {
+            return PhaseId.INVOKE_APPLICATION;
+        }
+    }
+
+    public static abstract class AnyPhasePhaseListener implements PhaseListener
+    {
+        public PhaseId getPhaseId()
+        {
+            return PhaseId.ANY_PHASE;
+        }
+    }
+
+    public static abstract class RestoreViewPhasePhaseListener implements PhaseListener
+    {
+        public PhaseId getPhaseId()
+        {
+            return PhaseId.RESTORE_VIEW;
+        }
+    }
+
+    public static abstract class RenderResponsePhaseListener implements PhaseListener
+    {
+        public PhaseId getPhaseId()
+        {
+            return PhaseId.RENDER_RESPONSE;
+        }
+    }
+
+}

Propchange: myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIViewRootTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIViewRootTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL