myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1461298 - in /myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test: base/ base/junit4/ mock/
Date Tue, 26 Mar 2013 20:23:52 GMT
Author: lu4242
Date: Tue Mar 26 20:23:51 2013
New Revision: 1461298

URL: http://svn.apache.org/r1461298
Log:
add MockClientWindow

Added:
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindow.java   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindowFactory.java   (with props)

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java?rev=1461298&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java Tue Mar 26 20:23:51 2013
@@ -0,0 +1,334 @@
+/*
+ * 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 org.apache.myfaces.test.base;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.UIViewRoot;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.render.RenderKitFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.myfaces.test.config.ResourceBundleVarNames;
+import org.apache.myfaces.test.mock.MockApplication;
+import org.apache.myfaces.test.mock.MockExternalContext;
+import org.apache.myfaces.test.mock.MockFacesContext;
+import org.apache.myfaces.test.mock.MockFacesContextFactory;
+import org.apache.myfaces.test.mock.MockHttpServletRequest;
+import org.apache.myfaces.test.mock.MockHttpServletResponse;
+import org.apache.myfaces.test.mock.MockHttpSession;
+import org.apache.myfaces.test.mock.MockRenderKit;
+import org.apache.myfaces.test.mock.MockServletConfig;
+import org.apache.myfaces.test.mock.MockServletContext;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
+
+/**
+ * <p>Abstract JUnit test case base class, which sets up the JavaServer Faces
+ * mock object environment for a particular simulated request.  The following
+ * protected variables are initialized in the <code>setUp()</code> method, and
+ * cleaned up in the <code>tearDown()</code> method:</p>
+ * <ul>
+ * <li><code>application</code> (<code>MockApplication</code>)</li>
+ * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+ * <li><code>externalContext</code> (<code>MockExternalContext</code>)</li>
+ * <li><code>facesContext</code> (<code>MockFacesContext</code>)</li>
+ * <li><code>lifecycle</code> (<code>MockLifecycle</code>)</li>
+ * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+ * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+ * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+ * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+ * </ul>
+ *
+ * <p>In addition, appropriate factory classes will have been registered with
+ * <code>javax.faces.FactoryFinder</code> for <code>Application</code> and
+ * <code>RenderKit</code> instances.  The created <code>FacesContext</code>
+ * instance will also have been registered in the proper thread local
+ * variable, to simulate what a servlet container would do.</p>
+ *
+ * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure
+ * your <code>setUp()</code> and <code>tearDown()</code> methods call
+ * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively,
+ * and that you implement your own <code>suite()</code> method that exposes
+ * the test methods for your test case.</p>
+ * 
+ * @since 1.0.0
+ */
+
+public abstract class AbstractJsfTestCase extends TestCase
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    /**
+     * <p>Construct a new instance of this test case.</p>
+     *
+     * @param name Name of this test case
+     */
+    public AbstractJsfTestCase(String name)
+    {
+        super(name);
+    }
+
+    // ---------------------------------------------------- Overall Test Methods
+
+    /**
+     * <p>Set up instance variables required by this test case.</p>
+     */
+    protected void setUp() throws Exception
+    {
+
+        // Set up a new thread context class loader
+        threadContextClassLoader = Thread.currentThread()
+                .getContextClassLoader();
+        Thread.currentThread()
+                .setContextClassLoader(
+                        new URLClassLoader(new URL[0], this.getClass()
+                                .getClassLoader()));
+
+        // Set up Servlet API Objects
+        setUpServletObjects();
+
+        // Set up JSF API Objects
+        FactoryFinder.releaseFactories();
+
+        setFactories();
+
+        setUpJSFObjects();
+    }
+
+    /**
+     * <p>Setup JSF object used for the test. By default it calls to the following
+     * methods in this order:</p>
+     * 
+     * <ul>
+     * <li><code>setUpExternalContext();</code></li>
+     * <li><code>setUpLifecycle();</code></li>
+     * <li><code>setUpFacesContext();</code></li>
+     * <li><code>setUpView();</code></li>
+     * <li><code>setUpApplication();</code></li>
+     * <li><code>setUpRenderKit();</code></li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpJSFObjects() throws Exception
+    {
+        setUpExternalContext();
+        setUpLifecycle();
+        setUpFacesContext();
+        setUpView();
+        setUpApplication();
+        setUpRenderKit();
+    }
+
+    /**
+     * <p>Setup servlet objects that will be used for the test:</p>
+     * 
+     * <ul>
+     * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+     * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+     * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+     * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+     * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpServletObjects() throws Exception
+    {
+        servletContext = new MockServletContext();
+        config = new MockServletConfig(servletContext);
+        session = new MockHttpSession();
+        session.setServletContext(servletContext);
+        request = new MockHttpServletRequest(session);
+        request.setServletContext(servletContext);
+        response = new MockHttpServletResponse();
+    }
+
+    /**
+     * <p>Set JSF factories using FactoryFinder method setFactory.</p>
+     * 
+     * @throws Exception
+     */
+    protected void setFactories() throws Exception
+    {
+        FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+                "org.apache.myfaces.test.mock.MockApplicationFactory");
+        FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockFacesContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
+                "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+        FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
+                "org.apache.myfaces.test.mock.MockRenderKitFactory");
+        FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
+                "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+        FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.CLIENT_WINDOW_FACTORY,
+                "org.apache.myfaces.test.mock.MockClientWindowFactory");
+    }
+
+    /**
+     * Setup the <code>externalContext</code> variable, using the 
+     * servlet variables already initialized.
+     * 
+     * @throws Exception
+     */
+    protected void setUpExternalContext() throws Exception
+    {
+        externalContext = new MockExternalContext(servletContext, request,
+                response);
+    }
+
+    /**
+     * Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
+     * variables.
+     * 
+     * @throws Exception
+     */
+    protected void setUpLifecycle() throws Exception
+    {
+        lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+                .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+        lifecycle = (MockLifecycle) lifecycleFactory
+                .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+    }
+
+    /**
+     * Setup the <code>facesContextFactory</code> and <code>facesContext</code>
+     * variable. Before end, by default it override <code>externalContext</code>
+     * variable from the value retrieved from facesContext.getExternalContext(),
+     * because sometimes it is possible facesContext overrides externalContext
+     * internally.
+     * 
+     * @throws Exception
+     */
+    protected void setUpFacesContext() throws Exception
+    {
+        facesContextFactory = (MockFacesContextFactory) FactoryFinder
+                .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+        facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+                servletContext, request, response, lifecycle);
+        if (facesContext.getExternalContext() != null)
+        {
+            externalContext = (MockExternalContext) facesContext
+                    .getExternalContext();
+        }
+    }
+
+    /**
+     * By default, create an instance of UIViewRoot, set its viewId as "/viewId"
+     * and assign it to the current facesContext.
+     * 
+     * @throws Exception
+     */
+    protected void setUpView() throws Exception
+    {
+        UIViewRoot root = new UIViewRoot();
+        root.setViewId("/viewId");
+        root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+        facesContext.setViewRoot(root);
+    }
+
+    /**
+     * Setup the <code>application</code> variable and before
+     * the end by default it is assigned to the <code>facesContext</code>
+     * variable, calling <code>facesContext.setApplication(application)</code>
+     * 
+     * @throws Exception
+     */
+    protected void setUpApplication() throws Exception
+    {
+        ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+                .getFactory(FactoryFinder.APPLICATION_FACTORY);
+        application = (MockApplication) applicationFactory.getApplication();
+        facesContext.setApplication(application);
+    }
+
+    /**
+     * Setup the <code>renderKit</code> variable. This is a good place to use
+     * <code>ConfigParser</code> to register converters, validators, components
+     * or renderkits.
+     * 
+     * @throws Exception
+     */
+    protected void setUpRenderKit() throws Exception
+    {
+        RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+                .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        renderKit = new MockRenderKit();
+        renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+                renderKit);
+    }
+
+    /**
+     * <p>Tear down instance variables required by this test case.</p>
+     */
+    protected void tearDown() throws Exception
+    {
+
+        application = null;
+        config = null;
+        externalContext = null;
+        if (facesContext != null)
+        {
+            facesContext.release();
+        }
+        facesContext = null;
+        lifecycle = null;
+        lifecycleFactory = null;
+        renderKit = null;
+        request = null;
+        response = null;
+        servletContext = null;
+        session = null;
+        FactoryFinder.releaseFactories();
+        ResourceBundleVarNames.resetNames();
+
+        Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+        threadContextClassLoader = null;
+
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    // Mock object instances for our tests
+    protected MockApplication application = null;
+    protected MockServletConfig config = null;
+    protected MockExternalContext externalContext = null;
+    protected MockFacesContext facesContext = null;
+    protected MockFacesContextFactory facesContextFactory = null;
+    protected MockLifecycle lifecycle = null;
+    protected MockLifecycleFactory lifecycleFactory = null;
+    protected MockRenderKit renderKit = null;
+    protected MockHttpServletRequest request = null;
+    protected MockHttpServletResponse response = null;
+    protected MockServletContext servletContext = null;
+    protected MockHttpSession session = null;
+
+    // Thread context class loader saved and restored after each test
+    private ClassLoader threadContextClassLoader = null;
+
+}

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java?rev=1461298&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java Tue Mar 26 20:23:51 2013
@@ -0,0 +1,336 @@
+/*
+ * 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 org.apache.myfaces.test.base.junit4;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+
+import org.apache.myfaces.test.config.ResourceBundleVarNames;
+import org.apache.myfaces.test.mock.MockExternalContext;
+import org.apache.myfaces.test.mock.MockFacesContext;
+import org.apache.myfaces.test.mock.MockHttpServletRequest;
+import org.apache.myfaces.test.mock.MockHttpServletResponse;
+import org.apache.myfaces.test.mock.MockHttpSession;
+import org.apache.myfaces.test.mock.MockRenderKit;
+import org.apache.myfaces.test.mock.MockServletConfig;
+import org.apache.myfaces.test.mock.MockServletContext;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * <p>Abstract JUnit 4.5 test case base class, which sets up the JavaServer Faces
+ * mock object environment for a particular simulated request.  The following
+ * protected variables are initialized in the <code>setUp()</code> method, and
+ * cleaned up in the <code>tearDown()</code> method:</p>
+ * <ul>
+ * <li><code>application</code> (<code>Application</code>)</li>
+ * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+ * <li><code>externalContext</code> (<code>ExternalContext</code>)</li>
+ * <li><code>facesContext</code> (<code>FacesContext</code>)</li>
+ * <li><code>lifecycle</code> (<code>Lifecycle</code>)</li>
+ * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+ * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+ * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+ * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+ * </ul>
+ *
+ * <p>In addition, appropriate factory classes will have been registered with
+ * <code>javax.faces.FactoryFinder</code> for <code>Application</code> and
+ * <code>RenderKit</code> instances.  The created <code>FacesContext</code>
+ * instance will also have been registered in the proper thread local
+ * variable, to simulate what a servlet container would do.</p>
+ *
+ * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure
+ * your <code>setUp()</code> and <code>tearDown()</code> methods call
+ * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively,
+ * and that you implement your own <code>suite()</code> method that exposes
+ * the test methods for your test case.</p>
+ * 
+ * @since 1.0.0
+ */
+
+public abstract class AbstractJsfConfigurableMockTestCase
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    /**
+     * <p>Construct a new instance of this test case.</p>
+     *
+     * @param name Name of this test case
+     */
+    public AbstractJsfConfigurableMockTestCase()
+    {
+    }
+
+    // ---------------------------------------------------- Overall Test Methods
+
+    /**
+     * <p>Set up instance variables required by this test case.</p>
+     */
+    @Before
+    public void setUp() throws Exception
+    {
+
+        // Set up a new thread context class loader
+        threadContextClassLoader = Thread.currentThread()
+                .getContextClassLoader();
+        Thread.currentThread()
+                .setContextClassLoader(
+                        new URLClassLoader(new URL[0], this.getClass()
+                                .getClassLoader()));
+
+        // Set up Servlet API Objects
+        setUpServletObjects();
+
+        // Set up JSF API Objects
+        FactoryFinder.releaseFactories();
+
+        setFactories();
+
+        setUpJSFObjects();
+    }
+
+    /**
+     * <p>Setup JSF object used for the test. By default it calls to the following
+     * methods in this order:</p>
+     * 
+     * <ul>
+     * <li><code>setUpExternalContext();</code></li>
+     * <li><code>setUpLifecycle();</code></li>
+     * <li><code>setUpFacesContext();</code></li>
+     * <li><code>setUpView();</code></li>
+     * <li><code>setUpApplication();</code></li>
+     * <li><code>setUpRenderKit();</code></li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpJSFObjects() throws Exception
+    {
+        setUpExternalContext();
+        setUpLifecycle();
+        setUpFacesContext();
+        setUpView();
+        setUpApplication();
+        setUpRenderKit();
+    }
+
+    /**
+     * <p>Setup servlet objects that will be used for the test:</p>
+     * 
+     * <ul>
+     * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+     * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+     * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+     * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+     * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpServletObjects() throws Exception
+    {
+        servletContext = new MockServletContext();
+        config = new MockServletConfig(servletContext);
+        session = new MockHttpSession();
+        session.setServletContext(servletContext);
+        request = new MockHttpServletRequest(session);
+        request.setServletContext(servletContext);
+        response = new MockHttpServletResponse();
+    }
+
+    /**
+     * <p>Set JSF factories using FactoryFinder method setFactory.</p>
+     * 
+     * @throws Exception
+     */
+    protected void setFactories() throws Exception
+    {
+        FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+                "org.apache.myfaces.test.mock.MockApplicationFactory");
+        FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockFacesContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
+                "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+        FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
+                "org.apache.myfaces.test.mock.MockRenderKitFactory");
+        FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
+                "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+        FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.CLIENT_WINDOW_FACTORY,
+                "org.apache.myfaces.test.mock.MockClientWindowFactory");
+    }
+
+    /**
+     * Setup the <code>externalContext</code> variable, using the 
+     * servlet variables already initialized.
+     * 
+     * @throws Exception
+     */
+    protected void setUpExternalContext() throws Exception
+    {
+        externalContext = new MockExternalContext(servletContext, request,
+                response);
+    }
+
+    /**
+     * Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
+     * variables.
+     * 
+     * @throws Exception
+     */
+    protected void setUpLifecycle() throws Exception
+    {
+        lifecycleFactory = (LifecycleFactory) FactoryFinder
+                .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+        lifecycle = lifecycleFactory
+                .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+    }
+
+    /**
+     * Setup the <code>facesContextFactory</code> and <code>facesContext</code>
+     * variable. Before end, by default it override <code>externalContext</code>
+     * variable from the value retrieved from facesContext.getExternalContext(),
+     * because sometimes it is possible facesContext overrides externalContext
+     * internally.
+     * 
+     * @throws Exception
+     */
+    protected void setUpFacesContext() throws Exception
+    {
+        facesContextFactory = (FacesContextFactory) FactoryFinder
+                .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+        facesContext = (FacesContext) facesContextFactory.getFacesContext(
+                servletContext, request, response, lifecycle);
+        if (facesContext.getExternalContext() != null)
+        {
+            externalContext = facesContext.getExternalContext();
+        }
+    }
+
+    /**
+     * By default, create an instance of UIViewRoot, set its viewId as "/viewId"
+     * and assign it to the current facesContext.
+     * 
+     * @throws Exception
+     */
+    protected void setUpView() throws Exception
+    {
+        UIViewRoot root = new UIViewRoot();
+        root.setViewId("/viewId");
+        root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+        facesContext.setViewRoot(root);
+    }
+
+    /**
+     * Setup the <code>application</code> variable and before
+     * the end by default it is assigned to the <code>facesContext</code>
+     * variable, calling <code>facesContext.setApplication(application)</code>
+     * 
+     * @throws Exception
+     */
+    protected void setUpApplication() throws Exception
+    {
+        ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+                .getFactory(FactoryFinder.APPLICATION_FACTORY);
+        application = applicationFactory.getApplication();
+        ((MockFacesContext) facesContext).setApplication(application);
+    }
+
+    /**
+     * Setup the <code>renderKit</code> variable. This is a good place to use
+     * <code>ConfigParser</code> to register converters, validators, components
+     * or renderkits.
+     * 
+     * @throws Exception
+     */
+    protected void setUpRenderKit() throws Exception
+    {
+        RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+                .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        renderKit = new MockRenderKit();
+        renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+                renderKit);
+    }
+
+    /**
+     * <p>Tear down instance variables required by this test case.</p>
+     */
+    @After
+    public void tearDown() throws Exception
+    {
+
+        application = null;
+        config = null;
+        externalContext = null;
+        if (facesContext != null)
+        {
+            facesContext.release();
+        }
+        facesContext = null;
+        lifecycle = null;
+        lifecycleFactory = null;
+        renderKit = null;
+        request = null;
+        response = null;
+        servletContext = null;
+        session = null;
+        FactoryFinder.releaseFactories();
+        ResourceBundleVarNames.resetNames();
+
+        Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+        threadContextClassLoader = null;
+
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    // Mock object instances for our tests
+    protected Application application = null;
+    protected MockServletConfig config = null;
+    protected ExternalContext externalContext = null;
+    protected FacesContext facesContext = null;
+    protected FacesContextFactory facesContextFactory = null;
+    protected Lifecycle lifecycle = null;
+    protected LifecycleFactory lifecycleFactory = null;
+    protected RenderKit renderKit = null;
+    protected MockHttpServletRequest request = null;
+    protected MockHttpServletResponse response = null;
+    protected MockServletContext servletContext = null;
+    protected MockHttpSession session = null;
+
+    // Thread context class loader saved and restored after each test
+    private ClassLoader threadContextClassLoader = null;
+
+}

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java?rev=1461298&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java Tue Mar 26 20:23:51 2013
@@ -0,0 +1,374 @@
+/*
+ * 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 org.apache.myfaces.test.base.junit4;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+
+import org.apache.myfaces.test.config.ResourceBundleVarNames;
+import org.apache.myfaces.test.mock.MockExternalContext;
+import org.apache.myfaces.test.mock.MockFacesContext;
+import org.apache.myfaces.test.mock.MockFacesContextFactory;
+import org.apache.myfaces.test.mock.MockHttpServletRequest;
+import org.apache.myfaces.test.mock.MockHttpServletResponse;
+import org.apache.myfaces.test.mock.MockHttpSession;
+import org.apache.myfaces.test.mock.MockRenderKit;
+import org.apache.myfaces.test.mock.MockServletConfig;
+import org.apache.myfaces.test.mock.MockServletContext;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * <p>Abstract JUnit 4.5 test case base class, which sets up the JavaServer Faces
+ * mock object environment for multiple simulated request.  The following
+ * protected variables are initialized in the <code>setUp()</code> method, and
+ * cleaned up in the <code>tearDown()</code> method:</p>
+ * <ul>
+ * <li><code>application</code> (<code>Application</code>)</li>
+ * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+ * <li><code>externalContext</code> (<code>ExternalContext</code>)</li>
+ * <li><code>facesContext</code> (<code>FacesContext</code>)</li>
+ * <li><code>lifecycle</code> (<code>Lifecycle</code>)</li>
+ * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+ * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+ * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+ * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+ * </ul>
+ *
+ * <p>In addition, appropriate factory classes will have been registered with
+ * <code>javax.faces.FactoryFinder</code> for <code>Application</code> and
+ * <code>RenderKit</code> instances.  The created <code>FacesContext</code>
+ * instance will also have been registered in the proper thread local
+ * variable, to simulate what a servlet container would do.</p>
+ *
+ * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure
+ * your <code>setUp()</code> and <code>tearDown()</code> methods call
+ * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively,
+ * and that you implement your own <code>suite()</code> method that exposes
+ * the test methods for your test case. Additionally, check on each test
+ * that setupRequest() and tearDownRequest() are called correctly.</p>
+ * 
+ * @since 1.0.3
+ */
+
+public abstract class AbstractJsfConfigurableMultipleRequestsTestCase
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    /**
+     * <p>Construct a new instance of this test case.</p>
+     *
+     * @param name Name of this test case
+     */
+    public AbstractJsfConfigurableMultipleRequestsTestCase()
+    {
+    }
+
+    // ---------------------------------------------------- Overall Test Methods
+
+    /**
+     * <p>Set up instance variables required by this test case.</p>
+     */
+    @Before
+    public void setUp() throws Exception
+    {
+
+        // Set up a new thread context class loader
+        threadContextClassLoader = Thread.currentThread()
+                .getContextClassLoader();
+        Thread.currentThread()
+                .setContextClassLoader(
+                        new URLClassLoader(new URL[0], this.getClass()
+                                .getClassLoader()));
+
+        // Set up JSF Factories
+        FactoryFinder.releaseFactories();
+
+        setFactories();
+
+        // Setup servlet context and session
+        setUpServletContextAndSession();
+        
+        setUpLifecycle();
+        
+        setUpApplication();
+        
+        setUpRenderKit();
+    }
+
+    /**
+     * This method initialize an new empty request.
+     */
+    public void setupRequest() throws Exception
+    {
+        // Set up Servlet API Objects
+        setUpServletRequestAndResponse();
+
+        setUpJSFRequestObjects();
+    }
+
+    /**
+     * <p>Setup JSF object used for the test. By default it calls to the following
+     * methods in this order:</p>
+     * 
+     * <ul>
+     * <li><code>setUpExternalContext();</code></li>
+     * <li><code>setUpLifecycle();</code></li>
+     * <li><code>setUpFacesContext();</code></li>
+     * <li><code>setUpView();</code></li>
+     * <li><code>setUpApplication();</code></li>
+     * <li><code>setUpRenderKit();</code></li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpJSFRequestObjects() throws Exception
+    {
+        setUpExternalContext();
+        setUpFacesContext();
+        setUpView();
+    }
+
+    /**
+     * <p>Setup servlet objects that will be used for the test:</p>
+     * 
+     * <ul>
+     * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+     * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+     * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+     * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+     * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpServletContextAndSession() throws Exception
+    {
+        servletContext = new MockServletContext();
+        config = new MockServletConfig(servletContext);
+        session = new MockHttpSession();
+        session.setServletContext(servletContext);
+    }
+
+    protected void setUpServletRequestAndResponse() throws Exception
+    {
+        request = new MockHttpServletRequest(session);
+        request.setServletContext(servletContext);
+        response = new MockHttpServletResponse();
+    }
+
+    /**
+     * <p>Set JSF factories using FactoryFinder method setFactory.</p>
+     * 
+     * @throws Exception
+     */
+    protected void setFactories() throws Exception
+    {
+        FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+                "org.apache.myfaces.test.mock.MockApplicationFactory");
+        FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockFacesContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
+                "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+        FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
+                "org.apache.myfaces.test.mock.MockRenderKitFactory");
+        FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
+                "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+        FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.CLIENT_WINDOW_FACTORY,
+                "org.apache.myfaces.test.mock.MockClientWindowFactory");
+    }
+
+    /**
+     * Setup the <code>externalContext</code> variable, using the 
+     * servlet variables already initialized.
+     * 
+     * @throws Exception
+     */
+    protected void setUpExternalContext() throws Exception
+    {
+        externalContext = new MockExternalContext(servletContext, request,
+                response);
+    }
+
+    /**
+     * Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
+     * variables.
+     * 
+     * @throws Exception
+     */
+    protected void setUpLifecycle() throws Exception
+    {
+        lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+                .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+        lifecycle = (MockLifecycle) lifecycleFactory
+                .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+    }
+
+    /**
+     * Setup the <code>facesContextFactory</code> and <code>facesContext</code>
+     * variable. Before end, by default it override <code>externalContext</code>
+     * variable from the value retrieved from facesContext.getExternalContext(),
+     * because sometimes it is possible facesContext overrides externalContext
+     * internally.
+     * 
+     * @throws Exception
+     */
+    protected void setUpFacesContext() throws Exception
+    {
+        facesContextFactory = (MockFacesContextFactory) FactoryFinder
+                .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+        facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+                servletContext, request, response, lifecycle);
+        if (facesContext.getExternalContext() != null)
+        {
+            externalContext = (MockExternalContext) facesContext
+                    .getExternalContext();
+        }
+        if (facesContext instanceof MockFacesContext)
+        {
+            ((MockFacesContext) facesContext).setApplication(application);
+        }
+    }
+
+    /**
+     * By default, create an instance of UIViewRoot, set its viewId as "/viewId"
+     * and assign it to the current facesContext.
+     * 
+     * @throws Exception
+     */
+    protected void setUpView() throws Exception
+    {
+        UIViewRoot root = new UIViewRoot();
+        root.setViewId("/viewId");
+        root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+        facesContext.setViewRoot(root);
+    }
+
+    /**
+     * Setup the <code>application</code> variable and before
+     * the end by default it is assigned to the <code>facesContext</code>
+     * variable, calling <code>facesContext.setApplication(application)</code>
+     * 
+     * @throws Exception
+     */
+    protected void setUpApplication() throws Exception
+    {
+        ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+                .getFactory(FactoryFinder.APPLICATION_FACTORY);
+        application = applicationFactory.getApplication();
+    }
+
+    /**
+     * Setup the <code>renderKit</code> variable. This is a good place to use
+     * <code>ConfigParser</code> to register converters, validators, components
+     * or renderkits.
+     * 
+     * @throws Exception
+     */
+    protected void setUpRenderKit() throws Exception
+    {
+        RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+                .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        renderKit = new MockRenderKit();
+        renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+            renderKit);
+    }
+
+    /**
+     * <p>Tear down instance variables required by this test case.</p>
+     */
+    @After
+    public void tearDown() throws Exception
+    {
+
+        application = null;
+        config = null;
+        externalContext = null;
+        if (facesContext != null)
+        {
+            facesContext.release();
+        }
+        facesContext = null;
+        lifecycle = null;
+        lifecycleFactory = null;
+        renderKit = null;
+        request = null;
+        response = null;
+        servletContext = null;
+        session = null;
+        FactoryFinder.releaseFactories();
+        ResourceBundleVarNames.resetNames();
+
+        Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+        threadContextClassLoader = null;
+    }
+
+    /**
+     * This method ends the current request.
+     */
+    public void tearDownRequest()
+    {
+        externalContext = null;
+        if (facesContext != null)
+        {
+            facesContext.release();
+        }
+        facesContext = null;
+        request = null;
+        response = null;
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    // Mock object instances for our tests
+    protected Application application = null;
+    protected MockServletConfig config = null;
+    protected ExternalContext externalContext = null;
+    protected FacesContext facesContext = null;
+    protected FacesContextFactory facesContextFactory = null;
+    protected Lifecycle lifecycle = null;
+    protected LifecycleFactory lifecycleFactory = null;
+    protected RenderKit renderKit = null;
+    protected MockHttpServletRequest request = null;
+    protected MockHttpServletResponse response = null;
+    protected MockServletContext servletContext = null;
+    protected MockHttpSession session = null;
+
+    // Thread context class loader saved and restored after each test
+    private ClassLoader threadContextClassLoader = null;
+
+}

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java?rev=1461298&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java Tue Mar 26 20:23:51 2013
@@ -0,0 +1,335 @@
+/*
+ * 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 org.apache.myfaces.test.base.junit4;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.UIViewRoot;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.render.RenderKitFactory;
+
+import org.apache.myfaces.test.config.ResourceBundleVarNames;
+import org.apache.myfaces.test.mock.MockApplication;
+import org.apache.myfaces.test.mock.MockExternalContext;
+import org.apache.myfaces.test.mock.MockFacesContext;
+import org.apache.myfaces.test.mock.MockFacesContextFactory;
+import org.apache.myfaces.test.mock.MockHttpServletRequest;
+import org.apache.myfaces.test.mock.MockHttpServletResponse;
+import org.apache.myfaces.test.mock.MockHttpSession;
+import org.apache.myfaces.test.mock.MockRenderKit;
+import org.apache.myfaces.test.mock.MockServletConfig;
+import org.apache.myfaces.test.mock.MockServletContext;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * <p>Abstract JUnit 4.5 test case base class, which sets up the JavaServer Faces
+ * mock object environment for a particular simulated request.  The following
+ * protected variables are initialized in the <code>setUp()</code> method, and
+ * cleaned up in the <code>tearDown()</code> method:</p>
+ * <ul>
+ * <li><code>application</code> (<code>MockApplication</code>)</li>
+ * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+ * <li><code>externalContext</code> (<code>MockExternalContext</code>)</li>
+ * <li><code>facesContext</code> (<code>MockFacesContext</code>)</li>
+ * <li><code>lifecycle</code> (<code>MockLifecycle</code>)</li>
+ * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+ * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+ * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+ * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+ * </ul>
+ *
+ * <p>In addition, appropriate factory classes will have been registered with
+ * <code>javax.faces.FactoryFinder</code> for <code>Application</code> and
+ * <code>RenderKit</code> instances.  The created <code>FacesContext</code>
+ * instance will also have been registered in the apppriate thread local
+ * variable, to simulate what a servlet container would do.</p>
+ *
+ * <p><strong>WARNING</strong> - If you choose to subclass this class, be sure
+ * your <code>setUp()</code> and <code>tearDown()</code> methods call
+ * <code>super.setUp()</code> and <code>super.tearDown()</code> respectively,
+ * and that you implement your own <code>suite()</code> method that exposes
+ * the test methods for your test case.</p>
+ * 
+ * @since 1.0.0
+ */
+
+public abstract class AbstractJsfTestCase
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    /**
+     * <p>Construct a new instance of this test case.</p>
+     *
+     * @param name Name of this test case
+     */
+    public AbstractJsfTestCase()
+    {
+    }
+
+    // ---------------------------------------------------- Overall Test Methods
+
+    /**
+     * <p>Set up instance variables required by this test case.</p>
+     */
+    @Before
+    public void setUp() throws Exception
+    {
+
+        // Set up a new thread context class loader
+        threadContextClassLoader = Thread.currentThread()
+                .getContextClassLoader();
+        Thread.currentThread()
+                .setContextClassLoader(
+                        new URLClassLoader(new URL[0], this.getClass()
+                                .getClassLoader()));
+
+        // Set up Servlet API Objects
+        setUpServletObjects();
+
+        // Set up JSF API Objects
+        FactoryFinder.releaseFactories();
+
+        setFactories();
+
+        setUpJSFObjects();
+    }
+
+    /**
+     * <p>Setup JSF object used for the test. By default it calls to the following
+     * methods in this order:</p>
+     * 
+     * <ul>
+     * <li><code>setUpExternalContext();</code></li>
+     * <li><code>setUpLifecycle();</code></li>
+     * <li><code>setUpFacesContext();</code></li>
+     * <li><code>setUpView();</code></li>
+     * <li><code>setUpApplication();</code></li>
+     * <li><code>setUpRenderKit();</code></li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpJSFObjects() throws Exception
+    {
+        setUpExternalContext();
+        setUpLifecycle();
+        setUpFacesContext();
+        setUpView();
+        setUpApplication();
+        setUpRenderKit();
+    }
+
+    /**
+     * <p>Setup servlet objects that will be used for the test:</p>
+     * 
+     * <ul>
+     * <li><code>config</code> (<code>MockServletConfig</code>)</li>
+     * <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
+     * <li><code>request</code> (<code>MockHttpServletRequest</code></li>
+     * <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
+     * <li><code>session</code> (<code>MockHttpSession</code>)</li>
+     * </ul>
+     * 
+     * @throws Exception
+     */
+    protected void setUpServletObjects() throws Exception
+    {
+        servletContext = new MockServletContext();
+        config = new MockServletConfig(servletContext);
+        session = new MockHttpSession();
+        session.setServletContext(servletContext);
+        request = new MockHttpServletRequest(session);
+        request.setServletContext(servletContext);
+        response = new MockHttpServletResponse();
+    }
+
+    /**
+     * <p>Set JSF factories using FactoryFinder method setFactory.</p>
+     * 
+     * @throws Exception
+     */
+    protected void setFactories() throws Exception
+    {
+        FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+                "org.apache.myfaces.test.mock.MockApplicationFactory");
+        FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockFacesContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
+                "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+        FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
+                "org.apache.myfaces.test.mock.MockRenderKitFactory");
+        FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
+                "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+        FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
+                "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+        FactoryFinder.setFactory(FactoryFinder.CLIENT_WINDOW_FACTORY,
+                "org.apache.myfaces.test.mock.MockClientWindowFactory");
+    }
+
+    /**
+     * Setup the <code>externalContext</code> variable, using the 
+     * servlet variables already initialized.
+     * 
+     * @throws Exception
+     */
+    protected void setUpExternalContext() throws Exception
+    {
+        externalContext = new MockExternalContext(servletContext, request,
+                response);
+    }
+
+    /**
+     * Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
+     * variables.
+     * 
+     * @throws Exception
+     */
+    protected void setUpLifecycle() throws Exception
+    {
+        lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+                .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+        lifecycle = (MockLifecycle) lifecycleFactory
+                .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+    }
+
+    /**
+     * Setup the <code>facesContextFactory</code> and <code>facesContext</code>
+     * variable. Before end, by default it override <code>externalContext</code>
+     * variable from the value retrieved from facesContext.getExternalContext(),
+     * because sometimes it is possible facesContext overrides externalContext
+     * internally.
+     * 
+     * @throws Exception
+     */
+    protected void setUpFacesContext() throws Exception
+    {
+        facesContextFactory = (MockFacesContextFactory) FactoryFinder
+                .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+        facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+                servletContext, request, response, lifecycle);
+        if (facesContext.getExternalContext() != null)
+        {
+            externalContext = (MockExternalContext) facesContext
+                    .getExternalContext();
+        }
+    }
+
+    /**
+     * By default, create an instance of UIViewRoot, set its viewId as "/viewId"
+     * and assign it to the current facesContext.
+     * 
+     * @throws Exception
+     */
+    protected void setUpView() throws Exception
+    {
+        UIViewRoot root = new UIViewRoot();
+        root.setViewId("/viewId");
+        root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+        facesContext.setViewRoot(root);
+    }
+
+    /**
+     * Setup the <code>application</code> variable and before
+     * the end by default it is assigned to the <code>facesContext</code>
+     * variable, calling <code>facesContext.setApplication(application)</code>
+     * 
+     * @throws Exception
+     */
+    protected void setUpApplication() throws Exception
+    {
+        ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+                .getFactory(FactoryFinder.APPLICATION_FACTORY);
+        application = (MockApplication) applicationFactory.getApplication();
+        facesContext.setApplication(application);
+    }
+
+    /**
+     * Setup the <code>renderKit</code> variable. This is a good place to use
+     * <code>ConfigParser</code> to register converters, validators, components
+     * or renderkits.
+     * 
+     * @throws Exception
+     */
+    protected void setUpRenderKit() throws Exception
+    {
+        RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+                .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        renderKit = new MockRenderKit();
+        renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+                renderKit);
+    }
+
+    /**
+     * <p>Tear down instance variables required by this test case.</p>
+     */
+    @After
+    public void tearDown() throws Exception
+    {
+
+        application = null;
+        config = null;
+        externalContext = null;
+        if (facesContext != null)
+        {
+            facesContext.release();
+        }
+        facesContext = null;
+        lifecycle = null;
+        lifecycleFactory = null;
+        renderKit = null;
+        request = null;
+        response = null;
+        servletContext = null;
+        session = null;
+        FactoryFinder.releaseFactories();
+        ResourceBundleVarNames.resetNames();
+
+        Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+        threadContextClassLoader = null;
+
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    // Mock object instances for our tests
+    protected MockApplication application = null;
+    protected MockServletConfig config = null;
+    protected MockExternalContext externalContext = null;
+    protected MockFacesContext facesContext = null;
+    protected MockFacesContextFactory facesContextFactory = null;
+    protected MockLifecycle lifecycle = null;
+    protected MockLifecycleFactory lifecycleFactory = null;
+    protected MockRenderKit renderKit = null;
+    protected MockHttpServletRequest request = null;
+    protected MockHttpServletResponse response = null;
+    protected MockServletContext servletContext = null;
+    protected MockHttpSession session = null;
+
+    // Thread context class loader saved and restored after each test
+    private ClassLoader threadContextClassLoader = null;
+
+}

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindow.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindow.java?rev=1461298&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindow.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindow.java Tue Mar 26 20:23:51 2013
@@ -0,0 +1,102 @@
+/*
+ * 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 org.apache.myfaces.test.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.ClientWindow;
+import javax.faces.render.ResponseStateManager;
+
+/**
+ * Mock ClientWindow implementation that by default set the id with "1".
+ * 
+ * @author Leonardo Uribe
+ */
+public class MockClientWindow extends ClientWindow
+{
+    private String windowId;
+    
+    private Map<String,String> queryParamsMap;
+
+    public MockClientWindow()
+    {
+    }
+    
+    @Override
+    public void decode(FacesContext context)
+    {
+        String windowId = calculateWindowId(context);
+
+        if (windowId != null)
+        {
+            // Store the current windowId.
+            setId(windowId);
+        }
+        else
+        {
+            //Generate a new windowId
+            setId("1");
+        }
+    }
+    
+    
+    protected String calculateWindowId(FacesContext context)
+    {
+        //1. If it comes as parameter, it takes precedence over any other choice, because
+        //   no browser is capable to do a POST and create a new window at the same time.
+        String windowId = context.getExternalContext().getRequestParameterMap().get(
+                ResponseStateManager.CLIENT_WINDOW_PARAM);
+        if (windowId != null)
+        {
+            return windowId;
+        }
+        windowId = context.getExternalContext().getRequestParameterMap().get(
+                ResponseStateManager.CLIENT_WINDOW_URL_PARAM);
+        if (windowId != null)
+        {
+            return windowId;
+        }
+        return null;
+    }
+
+    @Override
+    public String getId()
+    {
+        return this.windowId;
+    }
+    
+    public void setId(String id)
+    {
+        this.windowId = id;
+    }
+
+    @Override
+    public Map<String, String> getQueryURLParameters(FacesContext context)
+    {
+        if (queryParamsMap == null)
+        {
+            String id = context.getExternalContext().getClientWindow().getId();
+            if (id != null)
+            {
+                queryParamsMap = new HashMap<String, String>(2,1);
+                queryParamsMap.put(ResponseStateManager.CLIENT_WINDOW_URL_PARAM, id);
+            }
+        }
+        return queryParamsMap;
+    }
+}

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindow.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindowFactory.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindowFactory.java?rev=1461298&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindowFactory.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindowFactory.java Tue Mar 26 20:23:51 2013
@@ -0,0 +1,89 @@
+/*
+ * 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 org.apache.myfaces.test.mock;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.ClientWindow;
+import javax.faces.lifecycle.ClientWindowFactory;
+
+/**
+ *
+ * @author lu4242
+ */
+public class MockClientWindowFactory extends ClientWindowFactory
+{
+    private static final String WINDOW_MODE_NONE = "none";
+    private static final String WINDOW_MODE_MOCK = "mock";
+    
+    private String windowMode;
+
+    @Override
+    public ClientWindow getClientWindow(FacesContext facesContext)
+    {
+        if (WINDOW_MODE_NONE.equals(getWindowMode(facesContext)))
+        {
+            //No need to do anything
+            return null;
+        }
+        else
+        {
+            if (WINDOW_MODE_MOCK.equals(getWindowMode(facesContext)))
+            {
+                return new MockClientWindow();
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }    
+    
+    private String getWindowMode(FacesContext context)
+    {
+        if (windowMode == null)
+        {
+            windowMode = getStringInitParameter(
+                    context.getExternalContext(), 
+                    ClientWindow.CLIENT_WINDOW_MODE_PARAM_NAME, WINDOW_MODE_NONE);
+        }
+        return windowMode;
+    }
+    
+    private static String getStringInitParameter(ExternalContext context, String name, String defaultValue)
+    {
+        if (name == null)
+        {
+            throw new NullPointerException();
+        }
+        
+        String param = context.getInitParameter(name);
+        
+        if (param == null)
+        {
+            return defaultValue;
+        }
+
+        param = param.trim();
+        if (param.length() == 0)
+        {
+            return defaultValue;
+        }
+
+        return param;
+    }    
+}

Propchange: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockClientWindowFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message