You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2018/05/03 18:25:58 UTC

[myfaces-test] 11/21: Create test20 branch

This is an automated email from the ASF dual-hosted git repository.

deki pushed a commit to branch 1_0_0_alpha
in repository https://gitbox.apache.org/repos/asf/myfaces-test.git

commit 49e6d15727c47b3c111d8450739c7b095aa210ac
Author: Leonardo Uribe <lu...@apache.org>
AuthorDate: Sat Jul 11 02:46:06 2009 +0000

    Create test20 branch
---
 test12/pom.xml                                     |  16 +-
 test20/pom.xml                                     | 225 ++++++++--------
 .../apache/shale/test/mock/MockApplication20.java  | 295 +++++++++++++++++++++
 .../shale/test/mock/MockApplicationFactory.java    | 121 +++++++++
 .../shale/test/mock/MockExternalContext20.java     |  41 +++
 .../apache/shale/test/mock/MockFacesContext20.java |  91 +++++++
 .../shale/test/mock/MockFacesContextFactory.java   | 213 +++++++++++++++
 7 files changed, 880 insertions(+), 122 deletions(-)

diff --git a/test12/pom.xml b/test12/pom.xml
index 43e1c12..5fed3ad 100644
--- a/test12/pom.xml
+++ b/test12/pom.xml
@@ -95,6 +95,21 @@
 
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-source-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>attach-source</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
     <!-- Allow building with JDK 1.4 as well as JDK 1.5,
          the 1.4 profile caters only to JSF 1.1 -->
     <profiles>
@@ -216,5 +231,4 @@
         </profile>
 
     </profiles>
-
 </project>
diff --git a/test20/pom.xml b/test20/pom.xml
index 599f5d8..f0ac46f 100644
--- a/test20/pom.xml
+++ b/test20/pom.xml
@@ -31,7 +31,7 @@
     <artifactId>myfaces-test20</artifactId>
     <packaging>jar</packaging>
     <name>Myfaces Test Framework for JSF 2.0</name>
-
+    
     <dependencies>
 
         <!-- Required only for using the org.apache.shale.test.config package -->
@@ -93,128 +93,111 @@
             <scope>provided</scope>
         </dependency>
 
-    </dependencies>
+        <dependency>
+            <groupId>org.apache.myfaces.core</groupId>
+            <artifactId>myfaces-api</artifactId>
+            <version>${jsf-myfaces.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.myfaces.core</groupId>
+            <artifactId>myfaces-impl</artifactId>
+            <version>${jsf-myfaces.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet.jsp</groupId>
+            <artifactId>jsp-api</artifactId>
+            <version>2.1</version>
+            <scope>provided</scope>
+        </dependency>
 
-    <!-- Allow building with JDK 1.4 as well as JDK 1.5,
-         the 1.4 profile caters only to JSF 1.1 -->
-    <profiles>
+    </dependencies>
 
-        <profile>
-            <id>myfaces-test-jdk14</id>
-            <activation>
-                <jdk>1.4</jdk>
-            </activation>
-            <dependencies>
-                <dependency>
-                    <groupId>org.apache.myfaces.core</groupId>
-                    <artifactId>myfaces-api</artifactId>
-                    <version>1.1.4</version>
-                    <scope>provided</scope>
-                </dependency>
-                <dependency>
-                    <groupId>org.apache.myfaces.core</groupId>
-                    <artifactId>myfaces-impl</artifactId>
-                    <version>1.1.4</version>
-                    <scope>test</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.servlet</groupId>
-                    <artifactId>servlet-api</artifactId>
-                    <version>2.4</version>
-                    <scope>provided</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.servlet</groupId>
-                    <artifactId>jsp-api</artifactId>
-                    <version>2.0</version>
-                    <scope>provided</scope>
-                </dependency>
-            </dependencies>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-compiler-plugin</artifactId>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-source-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>attach-source</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <!-- 
+                  - Add a new source directory to the compile path. 
+                  -
+                  -   test12_sources: contains all the source code from the "main" branch of test,
+                  -   which is written to be JSF1.2 and JSF1.1-compatible.
+                  -->
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
                         <configuration>
-                            <excludes>
-                                <exclude>org/apache/shale/test/el/**</exclude>
-                                <exclude>org/apache/shale/test/mock/*12.java</exclude>
-                            </excludes>
-                            <testExcludes>
-                                <testExclude>org/apache/shale/test/el/**</testExclude>
-                            </testExcludes>
+                            <sources>
+                                <source>
+                                    ${project.build.directory}/test12_sources
+                                </source>
+                            </sources>
                         </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-
-        <profile>
-            <id>myfaces-test-jdk15</id>
-            <activation>
-                <jdk>1.5</jdk>
-            </activation>
-            <dependencies>
-                <dependency>
-                    <groupId>javax.faces</groupId>
-                    <artifactId>jsf-api</artifactId>
-                    <version>1.2_03</version>
-                    <scope>provided</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.faces</groupId>
-                    <artifactId>jsf-impl</artifactId>
-                    <version>1.2_03</version>
-                    <scope>test</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.servlet</groupId>
-                    <artifactId>servlet-api</artifactId>
-                    <version>2.5</version>
-                    <scope>provided</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.servlet.jsp</groupId>
-                    <artifactId>jsp-api</artifactId>
-                    <version>2.1</version>
-                    <scope>provided</scope>
-                </dependency>
-            </dependencies>
-        </profile>
-
-        <profile>
-            <id>myfaces-test-jdk16</id>
-            <activation>
-                <jdk>1.6</jdk>
-            </activation>
-            <dependencies>
-                <dependency>
-                    <groupId>javax.faces</groupId>
-                    <artifactId>jsf-api</artifactId>
-                    <version>1.2_03</version>
-                    <scope>provided</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.faces</groupId>
-                    <artifactId>jsf-impl</artifactId>
-                    <version>1.2_03</version>
-                    <scope>test</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.servlet</groupId>
-                    <artifactId>servlet-api</artifactId>
-                    <version>2.5</version>
-                    <scope>provided</scope>
-                </dependency>
-                <dependency>
-                    <groupId>javax.servlet.jsp</groupId>
-                    <artifactId>jsp-api</artifactId>
-                    <version>2.1</version>
-                    <scope>provided</scope>
-                </dependency>
-            </dependencies>
-        </profile>
-
-    </profiles>
-
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.myfaces.buildtools</groupId>
+                <artifactId>myfaces-builder-plugin</artifactId>
+                <version>1.0.3</version>
+                <executions>
+                  <execution>
+                    <id>unpack-test12</id>
+                    <phase>generate-sources</phase>
+                    <goals>
+                      <goal>unpack</goal>
+                    </goals>
+                    <configuration>
+                      <scanModel>false</scanModel>
+                      <artifactItems>
+                        <artifactItem>
+                          <groupId>org.apache.myfaces.test</groupId>
+                          <artifactId>myfaces-test12</artifactId>
+                          <version>${pom.version}</version>
+                          <classifier>sources</classifier>                   
+                          <outputDirectory>${project.build.directory}/test12_sources</outputDirectory>
+                          <includes>**/*.java</includes>
+                          <excludes>**/*.class,**/META-INF/**</excludes>
+                        </artifactItem>
+                      </artifactItems>
+                    </configuration>
+                  </execution>
+                </executions>
+            </plugin>            
+        </plugins>    
+    </build>
+    <properties>
+        <jsf-ri.version>2.0.0-SNAPSHOT</jsf-ri.version>
+        <jsf-myfaces.version>2.0.0-SNAPSHOT</jsf-myfaces.version>
+    </properties>
 </project>
diff --git a/test20/src/main/java/org/apache/shale/test/mock/MockApplication20.java b/test20/src/main/java/org/apache/shale/test/mock/MockApplication20.java
new file mode 100644
index 0000000..614bc13
--- /dev/null
+++ b/test20/src/main/java/org/apache/shale/test/mock/MockApplication20.java
@@ -0,0 +1,295 @@
+/*
+ * 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.shale.test.mock;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+import javax.faces.event.SystemEventListenerHolder;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class MockApplication20 extends MockApplication12
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    public MockApplication20()
+    {
+        super();
+    }
+
+    private static class SystemListenerEntry
+    {
+        private List<SystemEventListener> _lstSystemEventListener;
+        private Map<Class<?>, List<SystemEventListener>> _sourceClassMap;
+
+        public SystemListenerEntry()
+        {
+        }
+
+        public void addListener(SystemEventListener listener)
+        {
+            assert listener != null;
+
+            addListenerNoDuplicate(getAnySourceListenersNotNull(), listener);
+        }
+
+        public void addListener(SystemEventListener listener, Class<?> source)
+        {
+            assert listener != null;
+
+            if (source == null)
+            {
+                addListener(listener);
+            }
+            else
+            {
+                addListenerNoDuplicate(
+                        getSpecificSourceListenersNotNull(source), listener);
+            }
+        }
+
+        public void removeListener(SystemEventListener listener)
+        {
+            assert listener != null;
+
+            if (_lstSystemEventListener != null)
+            {
+                _lstSystemEventListener.remove(listener);
+            }
+        }
+
+        public void removeListener(SystemEventListener listener,
+                Class<?> sourceClass)
+        {
+            assert listener != null;
+
+            if (sourceClass == null)
+            {
+                removeListener(listener);
+            }
+            else
+            {
+                if (_sourceClassMap != null)
+                {
+                    List<SystemEventListener> listeners = _sourceClassMap
+                            .get(sourceClass);
+                    if (listeners != null)
+                    {
+                        listeners.remove(listener);
+                    }
+                }
+            }
+        }
+
+        public void publish(Class<? extends SystemEvent> systemEventClass,
+                Class<?> classSource, Object source, SystemEvent event)
+        {
+            if (source != null && _sourceClassMap != null)
+            {
+                event = _traverseListenerList(_sourceClassMap.get(classSource),
+                        systemEventClass, source, event);
+            }
+
+            _traverseListenerList(_lstSystemEventListener, systemEventClass,
+                    source, event);
+        }
+
+        private void addListenerNoDuplicate(
+                List<SystemEventListener> listeners,
+                SystemEventListener listener)
+        {
+            if (!listeners.contains(listener))
+            {
+                listeners.add(listener);
+            }
+        }
+
+        private synchronized List<SystemEventListener> getAnySourceListenersNotNull()
+        {
+            if (_lstSystemEventListener == null)
+            {
+                /*
+                 * TODO: Check if modification occurs often or not, might have to use a synchronized list instead.
+                 * 
+                 * Registrations found:
+                 */
+                _lstSystemEventListener = new CopyOnWriteArrayList<SystemEventListener>();
+            }
+
+            return _lstSystemEventListener;
+        }
+
+        private synchronized List<SystemEventListener> getSpecificSourceListenersNotNull(
+                Class<?> sourceClass)
+        {
+            if (_sourceClassMap == null)
+            {
+                _sourceClassMap = new ConcurrentHashMap<Class<?>, List<SystemEventListener>>();
+            }
+
+            List<SystemEventListener> list = _sourceClassMap.get(sourceClass);
+            if (list == null)
+            {
+                /*
+                 * TODO: Check if modification occurs often or not, might have to use a synchronized list instead.
+                 * 
+                 * Registrations found:
+                 */
+                list = new CopyOnWriteArrayList<SystemEventListener>();
+                _sourceClassMap.put(sourceClass, list);
+            }
+
+            return list;
+        }
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    private static final Log log = LogFactory.getLog(MockApplication20.class);
+    
+    private final Map<Class<? extends SystemEvent>, SystemListenerEntry> _systemEventListenerClassMap = new ConcurrentHashMap<Class<? extends SystemEvent>, SystemListenerEntry>();
+
+    // ----------------------------------------------------- Mock Object Methods
+
+    private static SystemEvent _traverseListenerList(
+            List<? extends SystemEventListener> listeners,
+            Class<? extends SystemEvent> systemEventClass, Object source,
+            SystemEvent event)
+    {
+        if (listeners != null && !listeners.isEmpty())
+        {
+            for (SystemEventListener listener : listeners)
+            {
+                // Call SystemEventListener.isListenerForSource(java.lang.Object), passing the source argument.
+                // If this returns false, take no action on the listener.
+                if (listener.isListenerForSource(source))
+                {
+                    // Otherwise, if the event to be passed to the listener instances has not yet been constructed,
+                    // construct the event, passing source as the argument to the one-argument constructor that takes
+                    // an Object. This same event instance must be passed to all listener instances.
+                    event = _createEvent(systemEventClass, source, event);
+
+                    // Call SystemEvent.isAppropriateListener(javax.faces.event.FacesListener), passing the listener
+                    // instance as the argument. If this returns false, take no action on the listener.
+                    if (event.isAppropriateListener(listener))
+                    {
+                        // Call SystemEvent.processListener(javax.faces.event.FacesListener), passing the listener
+                        // instance.
+                        event.processListener(listener);
+                    }
+                }
+            }
+        }
+
+        return event;
+    }
+
+    private static SystemEvent _createEvent(
+            Class<? extends SystemEvent> systemEventClass, Object source,
+            SystemEvent event)
+    {
+        if (event == null)
+        {
+            try
+            {
+                Constructor<? extends SystemEvent> constructor = systemEventClass
+                        .getConstructor(Object.class);
+                event = constructor.newInstance(source);
+            }
+            catch (Exception e)
+            {
+                throw new FacesException(
+                        "Couldn't instanciate system event of type "
+                                + systemEventClass.getName(), e);
+            }
+        }
+
+        return event;
+    }
+    
+    private void checkNull(final Object param, final String paramName)
+    {
+        if (param == null)
+        {
+            throw new NullPointerException(paramName + " cannot be null.");
+        }
+    }
+
+    private void checkEmpty(final String param, final String paramName)
+    {
+        if (param.length() == 0)
+        {
+            throw new NullPointerException("String " + paramName + " cannot be empty.");
+        }
+    }
+    
+    @Override
+    public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent> systemEventClass, Class<?> sourceBaseType, Object source)
+    {
+        checkNull(systemEventClass, "systemEventClass");
+        checkNull(source, "source");
+
+        try
+        {
+            SystemEvent event = null;
+            if (source instanceof SystemEventListenerHolder)
+            {
+                SystemEventListenerHolder holder = (SystemEventListenerHolder) source;
+    
+                // If the source argument implements SystemEventListenerHolder, call 
+                // SystemEventListenerHolder.getListenersForEventClass(java.lang.Class) on it, passing the systemEventClass 
+                // argument. If the list is not empty, perform algorithm traverseListenerList on the list.
+                event = _traverseListenerList(holder.getListenersForEventClass(systemEventClass), systemEventClass, source,
+                                              event);
+            }
+    
+            SystemListenerEntry systemListenerEntry = _systemEventListenerClassMap.get(systemEventClass);
+            if (systemListenerEntry != null)
+            {
+                systemListenerEntry.publish(systemEventClass, sourceBaseType, source, event);
+            }
+        }
+        catch (AbortProcessingException e)
+        {
+            // If the act of invoking the processListener method causes an AbortProcessingException to be thrown, 
+            // processing of the listeners must be aborted, no further processing of the listeners for this event must 
+            // take place, and the exception must be logged with Level.SEVERE.
+            log.error("Event processing was aborted", e);
+        }
+    }
+
+    @Override
+    public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent> systemEventClass, Object source)
+    {
+        publishEvent(facesContext, systemEventClass, source.getClass(), source);
+    }
+    
+    // ------------------------------------------------- ExternalContext Methods
+
+}
diff --git a/test20/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java b/test20/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java
new file mode 100644
index 0000000..94a724a
--- /dev/null
+++ b/test20/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java
@@ -0,0 +1,121 @@
+/*
+ * 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.shale.test.mock;
+
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+
+/**
+ * <p>Mock implementation of <code>ApplicationFactory</code>.</p>
+ *
+ * $Id$
+ */
+
+public class MockApplicationFactory extends ApplicationFactory {
+
+
+    // ------------------------------------------------------------ Constructors
+
+
+    /**
+     * <p>Construct a default instance.</p>
+     */
+    public MockApplicationFactory() {
+
+    }
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    /**
+     * <p>The <code>Application</code> instance to be returned by
+     * this factory.</p>
+     */
+    private Application application = null;
+
+
+    // --------------------------------------------- AppolicationFactory Methods
+
+
+    /** {@inheritDoc} */
+    public Application getApplication() {
+
+        if (this.application == null) {
+            Class clazz = null;
+            
+            try {
+                clazz = this.getClass().getClassLoader().loadClass
+                  ("org.apache.shale.test.mock.MockApplication20");
+                this.application = (MockApplication) clazz.newInstance();
+            } catch (NoClassDefFoundError e) {
+                clazz = null; // We are not running in a JSF 1.2 environment
+            } catch (ClassNotFoundException e) {
+                clazz = null; // Same as above
+            } catch (RuntimeException e) {
+                throw e;
+            } catch (Exception e) {
+                throw new FacesException(e);
+            }
+            
+            if (clazz == null)
+            {
+                try {
+                    clazz = this.getClass().getClassLoader().loadClass
+                      ("org.apache.shale.test.mock.MockApplication12");
+                    this.application = (MockApplication) clazz.newInstance();
+                } catch (NoClassDefFoundError e) {
+                    clazz = null; // We are not running in a JSF 1.2 environment
+                } catch (ClassNotFoundException e) {
+                    clazz = null; // Same as above
+                } catch (RuntimeException e) {
+                    throw e;
+                } catch (Exception e) {
+                    throw new FacesException(e);
+                }
+            }
+            if (clazz == null) {
+                try {
+                    clazz = this.getClass().getClassLoader().loadClass
+                      ("org.apache.shale.test.mock.MockApplication");
+                    this.application = (MockApplication) clazz.newInstance();
+                } catch (RuntimeException e) {
+                    throw e;
+                } catch (Exception e) {
+                    throw new FacesException(e);
+                }
+            }
+        }
+        return this.application;
+
+    }
+
+
+    /** {@inheritDoc} */
+    public void setApplication(Application application) {
+
+        this.application = application;
+
+    }
+
+
+}
diff --git a/test20/src/main/java/org/apache/shale/test/mock/MockExternalContext20.java b/test20/src/main/java/org/apache/shale/test/mock/MockExternalContext20.java
new file mode 100644
index 0000000..523440c
--- /dev/null
+++ b/test20/src/main/java/org/apache/shale/test/mock/MockExternalContext20.java
@@ -0,0 +1,41 @@
+/*
+ * 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.shale.test.mock;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class MockExternalContext20 extends MockExternalContext12
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    public MockExternalContext20(ServletContext context,
+            HttpServletRequest request, HttpServletResponse response)
+    {
+        super(context, request, response);
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    // ----------------------------------------------------- Mock Object Methods
+
+    // ------------------------------------------------- ExternalContext Methods
+
+}
diff --git a/test20/src/main/java/org/apache/shale/test/mock/MockFacesContext20.java b/test20/src/main/java/org/apache/shale/test/mock/MockFacesContext20.java
new file mode 100644
index 0000000..985767e
--- /dev/null
+++ b/test20/src/main/java/org/apache/shale/test/mock/MockFacesContext20.java
@@ -0,0 +1,91 @@
+/*
+ * 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.shale.test.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.event.PhaseId;
+import javax.faces.lifecycle.Lifecycle;
+
+public class MockFacesContext20 extends MockFacesContext12 {
+
+    // ------------------------------------------------------------ Constructors
+
+    public MockFacesContext20() {
+        super();
+        setCurrentInstance(this);
+    }
+
+
+    public MockFacesContext20(ExternalContext externalContext) {
+        super(externalContext);
+    }
+
+
+    public MockFacesContext20(ExternalContext externalContext, Lifecycle lifecycle) {
+        super(externalContext, lifecycle);
+    }
+
+    // ----------------------------------------------------- Mock Object Methods
+
+    // ------------------------------------------------------ Instance Variables
+
+    // ----------------------------------------------------- Mock Object Methods
+
+    private boolean postback;
+
+    @Override
+    public boolean isPostback()
+    {
+        return postback;
+    }
+    
+    public void setPostback(boolean value)
+    {
+        postback = value;
+    }
+
+    private PhaseId _currentPhaseId = PhaseId.RESTORE_VIEW;
+    
+    public PhaseId getCurrentPhaseId()
+    {
+        return _currentPhaseId;
+    }
+    
+    public void setCurrentPhaseId(PhaseId _currentPhaseId)
+    {
+        this._currentPhaseId = _currentPhaseId;
+    }
+    
+    private Map<Object,Object> attributes;
+
+    @Override
+    public Map<Object, Object> getAttributes()
+    {
+        if (attributes == null)
+        {
+            attributes = new HashMap<Object,Object>();
+        }
+        return attributes;
+    }
+    
+    // ------------------------------------------------- ExternalContext Methods
+
+}
diff --git a/test20/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java b/test20/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java
new file mode 100644
index 0000000..1a61532
--- /dev/null
+++ b/test20/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java
@@ -0,0 +1,213 @@
+/*
+ * 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.shale.test.mock;
+
+import java.lang.reflect.Constructor;
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * <p>Mock implementation of <code>FacesContextFactory</code>.</p>
+ *
+ * $Id$
+ */
+
+public class MockFacesContextFactory extends FacesContextFactory {
+
+
+    // ------------------------------------------------------------ Constructors
+
+
+    /**
+     * <p>Look up the constructor we will use for creating <code>MockFacesContext</code>
+     * instances.</p>
+     */
+    public MockFacesContextFactory() {
+
+        Class clazz = null;
+
+        // Try to load the 2.0 version of our mock FacesContext class
+        try {
+            clazz = this.getClass().getClassLoader().loadClass("org.apache.shale.test.mock.MockFacesContext20");
+            constructor = clazz.getConstructor(facesContextSignature);
+            jsf20 = true;
+        } catch (NoClassDefFoundError e) {
+            // We are not running on JSF 2.0, so go to our fallback
+            clazz = null;
+            constructor = null;
+        } catch (ClassNotFoundException e) {
+            // Same as above
+            clazz = null;
+            constructor = null;
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }        
+        
+        // Try to load the 1.2 version of our mock FacesContext class
+        try {
+            if (clazz == null)
+            {
+                clazz = this.getClass().getClassLoader().loadClass("org.apache.shale.test.mock.MockFacesContext12");
+                constructor = clazz.getConstructor(facesContextSignature);
+                jsf12 = true;
+            }
+        } catch (NoClassDefFoundError e) {
+            // We are not running on JSF 1.2, so go to our fallback
+            clazz = null;
+            constructor = null;
+        } catch (ClassNotFoundException e) {
+            // Same as above
+            clazz = null;
+            constructor = null;
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+        // Fall back to the 1.1 version if we could not load the 1.2 version
+        try {
+            if (clazz == null) {
+                clazz = this.getClass().getClassLoader().loadClass("org.apache.shale.test.mock.MockFacesContext");
+                constructor = clazz.getConstructor(facesContextSignature);
+                jsf12 = false;
+            }
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+    }
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    /**
+     * <p>The constructor for creating a <code>FacesContext</code> instance,
+     * taking an <code>ExternalContext</code> and <code>Lifecycle</code>.</p>
+     */
+    private Constructor constructor = null;
+
+
+    /**
+     * <p>The parameter signature of the ExternalContext constructor we wish to call.</p>
+     */
+    private static Class[] externalContextSignature = new Class[] {
+        ServletContext.class, HttpServletRequest.class, HttpServletResponse.class
+    };
+
+
+    /**
+     * <p>The parameter signature of the FacesContext constructor we wish to call.</p>
+     */
+    private static Class[] facesContextSignature = new Class[] {
+        ExternalContext.class, Lifecycle.class
+    };
+
+
+    /**
+     * <p>Flag indicating that we are running in a JSF 1.2 environment.</p>
+     */
+    private boolean jsf12 = false;
+
+    /**
+     * <p>Flag indicating that we are running in a JSF 2.0 environment.</p>
+     */
+    private boolean jsf20 = false;
+    
+    // --------------------------------------------- FacesContextFactory Methods
+
+
+    /** {@inheritDoc} */
+    public FacesContext getFacesContext(Object context, Object request,
+                                        Object response,
+                                        Lifecycle lifecycle) throws FacesException {
+
+        // Select the appropriate MockExternalContext implementation class
+        Class clazz = MockExternalContext.class;
+        
+        if (jsf20) {
+            try {
+                clazz = this.getClass().getClassLoader().loadClass
+                  ("org.apache.shale.test.mock.MockExternalContext20");
+            } catch (RuntimeException e) {
+                throw e;
+            } catch (Exception e) {
+                throw new FacesException(e);
+            }
+        }
+        
+        if (jsf12) {
+            try {
+                clazz = this.getClass().getClassLoader().loadClass
+                  ("org.apache.shale.test.mock.MockExternalContext12");
+            } catch (RuntimeException e) {
+                throw e;
+            } catch (Exception e) {
+                throw new FacesException(e);
+            }
+        }
+
+        // Select the constructor we wish to call
+        Constructor mecConstructor = null;
+        try {
+            mecConstructor = clazz.getConstructor(externalContextSignature);
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+        // Construct an appropriate MockExternalContext instance
+        MockExternalContext externalContext = null;
+        try {
+            externalContext = (MockExternalContext) mecConstructor.newInstance
+              (new Object[] { context, request, response });
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+        // Construct an appropriate MockFacesContext instance and return it
+        try {
+            return (MockFacesContext)
+              constructor.newInstance(new Object[] { externalContext, lifecycle });
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
+
+    }
+
+
+}

-- 
To stop receiving notification emails like this one, please contact
deki@apache.org.