You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by cr...@apache.org on 2006/10/07 05:03:14 UTC

svn commit: r453841 - in /shale/framework/trunk: shale-apps/shale-sql-browser/src/main/java/org/apache/shale/examples/sqlbrowser/ shale-test/ shale-test/src/main/java/org/apache/shale/test/base/ shale-test/src/main/java/org/apache/shale/test/jmock/ sha...

Author: craigmcc
Date: Fri Oct  6 20:03:13 2006
New Revision: 453841

URL: http://svn.apache.org/viewvc?view=rev&rev=453841
Log:
First phase of making the test framework support JSF 1.2.
* Create 1.2 versions of MockApplication, MockExternalContext,
  and MockFacesContext that subclass their 1.1 versions
* Update MockApplicationFactory and MockFacesContextFactory to
  return the correct version, depending on which JSF runtime
  the tests are executing under.

In the convenience base classes, the data types of the constructed objects
are still the 1.1 compatible versions.  Test cases will need to cast to the
1.2 version in order to test 1.2-specific functionality.

There is currently *no* machinery to evaluate value expressions or
method expressions.  This will be the next phase, because it is quite
useful to have (at least limited) expression support in unit tests.

With these test classes, all of the following commands work (when
starting from the shale-apps directory):

  mvn clean install
  mvn -Djsf=ri clean install
  mvn -Djsf=ri12 clean install

The integration tests also work with MyFaces or the 1.1 RI, but these cannot
be run for 1.2 until we have a Cargo plugin for Glassfish or some other EE 5
server.  However, the sample apps all deploy successfully manually.

SHALE-304


Added:
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java   (with props)
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockELContext.java   (with props)
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExpressionFactory.java   (with props)
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext12.java   (with props)
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext12.java   (with props)
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFunctionMapper.java   (with props)
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockVariableMapper.java   (with props)
Modified:
    shale/framework/trunk/shale-apps/shale-sql-browser/src/main/java/org/apache/shale/examples/sqlbrowser/Query.java
    shale/framework/trunk/shale-test/pom.xml
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/base/AbstractJsfTestCase.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/jmock/AbstractJmockJsfTestCase.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java

Modified: shale/framework/trunk/shale-apps/shale-sql-browser/src/main/java/org/apache/shale/examples/sqlbrowser/Query.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-sql-browser/src/main/java/org/apache/shale/examples/sqlbrowser/Query.java?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-apps/shale-sql-browser/src/main/java/org/apache/shale/examples/sqlbrowser/Query.java (original)
+++ shale/framework/trunk/shale-apps/shale-sql-browser/src/main/java/org/apache/shale/examples/sqlbrowser/Query.java Fri Oct  6 20:03:13 2006
@@ -188,7 +188,7 @@
             results.setFirst(0);
 
             // Dynamically create columns as needed
-            List<Object> children = results.getChildren();
+            List children = results.getChildren();
             children.clear();
             for (int i = 1; i <= rsmd.getColumnCount(); i++) { // SQL stuff is one-relative
                 UIColumn column = new UIColumn();

Modified: shale/framework/trunk/shale-test/pom.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/pom.xml?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-test/pom.xml (original)
+++ shale/framework/trunk/shale-test/pom.xml Fri Oct  6 20:03:13 2006
@@ -40,6 +40,27 @@
         </dependency>
 
         <dependency>
+            <groupId>javax.faces</groupId>
+            <artifactId>jsf-api</artifactId>
+            <version>1.2_02</version>
+            <scope>provided</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>
+
+        <dependency>
             <groupId>jmock</groupId>
             <artifactId>jmock</artifactId>
             <version>1.0.1</version>
@@ -60,12 +81,6 @@
             <artifactId>junit</artifactId>
             <version>3.8.1</version>
             <scope>compile</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.myfaces.core</groupId>
-            <artifactId>myfaces-api</artifactId>
-            <scope>provided</scope>
         </dependency>
 
         <dependency>

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/base/AbstractJsfTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/base/AbstractJsfTestCase.java?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/base/AbstractJsfTestCase.java (original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/base/AbstractJsfTestCase.java Fri Oct  6 20:03:13 2006
@@ -139,9 +139,8 @@
         root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
         facesContext.setViewRoot(root);
         ApplicationFactory applicationFactory = (ApplicationFactory)
-        FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
-        application = new MockApplication();
-        applicationFactory.setApplication(application);
+          FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+        application = (MockApplication) applicationFactory.getApplication();
         facesContext.setApplication(application);
         RenderKitFactory renderKitFactory = (RenderKitFactory)
         FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/jmock/AbstractJmockJsfTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/jmock/AbstractJmockJsfTestCase.java?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/jmock/AbstractJmockJsfTestCase.java (original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/jmock/AbstractJmockJsfTestCase.java Fri Oct  6 20:03:13 2006
@@ -133,9 +133,8 @@
         root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
         facesContext.setViewRoot(root);
         ApplicationFactory applicationFactory = (ApplicationFactory)
-        FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
-        application = new MockApplication();
-        applicationFactory.setApplication(application);
+          FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+        application = (MockApplication) applicationFactory.getApplication();
         facesContext.setApplication(application);
         RenderKitFactory renderKitFactory = (RenderKitFactory)
         FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);

Added: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java?view=auto&rev=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java (added)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java Fri Oct  6 20:03:13 2006
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import javax.el.CompositeELResolver;
+import javax.el.ELContextListener;
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+/**
+ * <p>Mock implementation of <code>ExternalContext</code> that includes the semantics
+ * added by JavaServer Faces 1.2.</p>
+ *
+ * $Id$
+ */
+public class MockApplication12 extends MockApplication {
+    
+
+    // ------------------------------------------------------------ Constructors
+
+
+    /**
+     * <p>Construct a default instance.</p>
+     */
+    public MockApplication12() {
+
+        super();
+
+        // Configure our expression factory and EL resolvers
+        expressionFactory = new MockExpressionFactory();
+        // FIXME - configure elResolvers list with standard resolvers
+
+    }
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    /**
+     * <p>The set of configured ELContextListener instances.</p>
+     */
+    private List elContextListeners = new ArrayList();
+
+
+    /**
+     * <p>Expression factory for this instance.</p>
+     */
+    private ExpressionFactory expressionFactory = null;
+
+
+    /**
+     * <p>The configured composite resolver to be returned by <code>getELResolver()</code>.
+     * This value is lazily instantiated.</p>
+     */
+    private ELResolver resolver = null;
+
+
+    /**
+     * <p>The set of ELResolver instances configured on this instance.</p>
+     */
+    private List resolvers = new ArrayList();
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+    // ----------------------------------------------------- Application Methods
+
+
+    /** {@inheritDoc} */
+    public void addELContextListener(ELContextListener listener) {
+
+        elContextListeners.add(listener);
+
+    }
+
+
+    /** {@inheritDoc} */
+    public void addELResolver(ELResolver resolver) {
+
+        // Simulate the restriction that you cannot add resolvers after
+        // the first request has been processed.
+        if (resolver != null) {
+            throw new IllegalStateException("Cannot add resolvers now");
+        }
+
+        resolvers.add(resolver);
+
+    }
+
+
+    /** {@inheritDoc} */
+    public UIComponent createComponent(ValueExpression expression,
+                                       FacesContext context,
+                                       String componentType) {
+
+        throw new UnsupportedOperationException();
+
+    }
+
+
+    /** {@inheritDoc} */
+    public ELContextListener[] getELContextListeners() {
+
+        return (ELContextListener[])
+          elContextListeners.toArray(new ELContextListener[elContextListeners.size()]);
+
+    }
+
+
+    /** {@inheritDoc} */
+    public ELResolver getELResolver() {
+
+        if (resolver == null) {
+            CompositeELResolver composite = new CompositeELResolver();
+            Iterator items = resolvers.iterator();
+            while (items.hasNext()) {
+                composite.add((ELResolver) items.next());
+            }
+            resolver = composite;
+        }
+        return resolver;
+
+    }
+
+
+    /** {@inheritDoc} */
+    public ExpressionFactory getExpressionFactory() {
+
+        return this.expressionFactory;
+
+    }
+
+
+    /** {@inheritDoc} */
+    public ResourceBundle getResourceBundle(FacesContext context, String name) {
+
+        if ((context == null) || (name == null)) {
+            throw new NullPointerException();
+        }
+        Locale locale = null;
+        UIViewRoot viewRoot = context.getViewRoot();
+        if (viewRoot != null) {
+            locale = viewRoot.getLocale();
+        }
+        if (locale == null) {
+            locale = Locale.getDefault();
+        }
+        return ResourceBundle.getBundle(name, locale);
+
+    }
+
+
+    /** {@inheritDoc} */
+    public void removeELContextListener(ELContextListener listener) {
+
+        elContextListeners.remove(listener);
+
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java (original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockApplicationFactory.java Fri Oct  6 20:03:13 2006
@@ -16,6 +16,7 @@
 
 package org.apache.shale.test.mock;
 
+import javax.faces.FacesException;
 import javax.faces.application.Application;
 import javax.faces.application.ApplicationFactory;
 
@@ -59,7 +60,29 @@
     public Application getApplication() {
 
         if (this.application == null) {
-            this.application = new MockApplication();
+            Class 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 (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;
 

Added: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockELContext.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockELContext.java?view=auto&rev=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockELContext.java (added)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockELContext.java Fri Oct  6 20:03:13 2006
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.Locale;
+import java.util.Map;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+
+/**
+ * <p>Mock implementation of <code>ELContext</code>.</p>
+ *
+ * $Id$
+ */
+
+public class MockELContext extends ELContext {
+    
+
+    // ------------------------------------------------------------ Constructors
+
+
+    /** Creates a new instance of MockELContext */
+    public MockELContext() {
+    }
+    
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    private Map contexts = new HashMap();
+    private ELResolver elResolver; // FIXME - initialize this!
+    private FunctionMapper functionMapper = new MockFunctionMapper();
+    private Locale locale = Locale.getDefault();
+    private boolean propertyResolved;
+    private VariableMapper variableMapper = new MockVariableMapper();
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+
+    // ------------------------------------------------------- ELContext Methods
+
+
+    /** {@inheritDoc} */
+    public Object getContext(Class key) {
+        if (key == null) {
+            throw new NullPointerException();
+        }
+        return contexts.get(key);
+    }
+
+
+    /** {@inheritDoc} */
+    public ELResolver getELResolver() {
+        return this.elResolver;
+    }
+
+
+    /** {@inheritDoc} */
+    public FunctionMapper getFunctionMapper() {
+        return this.functionMapper;
+    }
+
+
+    /** {@inheritDoc} */
+    public Locale getLocale() {
+        return this.locale;
+    }
+
+
+    /** {@inheritDoc} */
+    public boolean isPropertyResolved() {
+        return this.propertyResolved;
+    }
+
+
+    /** {@inheritDoc} */
+    public void putContext(Class key, Object value) {
+        if ((key == null) || (value == null)) {
+            throw new NullPointerException();
+        }
+        contexts.put(key, value);
+    }
+
+
+    /** {@inheritDoc} */
+    public void setPropertyResolved(boolean propertyResolved) {
+        this.propertyResolved = propertyResolved;
+    }
+
+
+    /** {@inheritDoc} */
+    public VariableMapper getVariableMapper() {
+        return this.variableMapper;
+    }
+
+
+    /** {@inheritDoc} */
+    public void setLocale(Locale locale) {
+        this.locale = locale;
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockELContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockELContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExpressionFactory.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExpressionFactory.java?view=auto&rev=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExpressionFactory.java (added)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExpressionFactory.java Fri Oct  6 20:03:13 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+
+/**
+ * <p>Mock implementation of <code>ExpressionFactory</code>.</p>
+ */
+public class MockExpressionFactory extends ExpressionFactory {
+    
+
+    // ------------------------------------------------------------ Constructors
+
+
+    /** Creates a new instance of MockExpressionFactory */
+    public MockExpressionFactory() {
+    }
+    
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+
+    // ----------------------------------------------- ExpressionFactory Methods
+
+
+    /** {@inheritDoc} */
+    public Object coerceToType(Object object, Class targetType) {
+        throw new UnsupportedOperationException(); // FIXME - coerceToType()
+    }
+
+
+    /** {@inheritDoc} */
+    public MethodExpression createMethodExpression(ELContext context,
+                                                   String expression,
+                                                   Class expectedType,
+                                                   Class[] signature) {
+        throw new UnsupportedOperationException(); // FIXME - createMethodExpression()
+    }
+
+
+    /** {@inheritDoc} */
+    public ValueExpression createValueExpression(ELContext context,
+                                                 String expression,
+                                                 Class expectedType) {
+        throw new UnsupportedOperationException(); // FIXME - createValueExpression()
+    }
+
+
+    /** {@inheritDoc} */
+    public ValueExpression createValueExpression(Object instance,
+                                                 Class expectedType) {
+        throw new UnsupportedOperationException(); // FIXME - createValueExpression()
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExpressionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExpressionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java (original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java Fri Oct  6 20:03:13 2006
@@ -76,9 +76,9 @@
 
     private Map applicationMap = null;
     private ServletContext context = null;
-    private HttpServletRequest request = null;
+    protected HttpServletRequest request = null;
     private Map requestMap = null;
-    private HttpServletResponse response = null;
+    protected HttpServletResponse response = null;
     private Map sessionMap = null;
     private Map requestCookieMap = new HashMap();
     private Map requestParameterMap = new HashMap();

Added: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext12.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext12.java?view=auto&rev=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext12.java (added)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext12.java Fri Oct  6 20:03:13 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.io.UnsupportedEncodingException;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * <p>Mock implementation of <code>ExternalContext</code> that includes the semantics
+ * added by JavaServer Faces 1.2.</p>
+ *
+ * $Id$
+ */
+
+public class MockExternalContext12 extends MockExternalContext {
+
+
+    // ------------------------------------------------------------ Constructors
+
+
+    public MockExternalContext12(ServletContext context,
+                                 HttpServletRequest request,
+                                 HttpServletResponse response) {
+        super(context, request, response);
+    }
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+    // ------------------------------------------------- ExternalContext Methods
+
+
+    /** {@inheritDoc} */
+    public String getRequestCharacterEncoding() {
+
+        return this.request.getCharacterEncoding();
+
+    }
+
+
+    /** {@inheritDoc} */
+    public String getRequestContentType() {
+
+        return this.request.getContentType();
+
+    }
+
+
+    /** {@inheritDoc} */
+    public void setRequest(Object request) {
+
+        this.request = (HttpServletRequest) request;
+
+    }
+
+
+    /** {@inheritDoc} */
+    public void setRequestCharacterEncoding(String encoding) throws UnsupportedEncodingException {
+
+        this.request.setCharacterEncoding(encoding);
+
+    }
+
+
+    /** {@inheritDoc} */
+    public void setResponse(Object response) {
+
+        this.response = (HttpServletResponse) response;
+
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext12.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext12.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java (original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java Fri Oct  6 20:03:13 2006
@@ -62,6 +62,7 @@
 
     public MockFacesContext(ExternalContext externalContext, Lifecycle lifecycle) {
         this(externalContext);
+        this.lifecycle = lifecycle;
     }
 
 
@@ -109,6 +110,7 @@
 
     private Application application = null;
     private ExternalContext externalContext = null;
+    private Lifecycle lifecycle = null;
     private Map messages = new HashMap();
     private boolean renderResponse = false;
     private boolean responseComplete = false;

Added: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext12.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext12.java?view=auto&rev=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext12.java (added)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext12.java Fri Oct  6 20:03:13 2006
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.ELContext;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.Lifecycle;
+
+/**
+ * <p>Mock implementation of <code>FacesContext</code> that includes the semantics
+ * added by JavaServer Faces 1.2.</p>
+ *
+ * $Id$
+ */
+
+public class MockFacesContext12 extends MockFacesContext {
+
+
+    // ------------------------------------------------------------ Constructors
+
+
+    public MockFacesContext12() {
+        super();
+        setCurrentInstance(this);
+    }
+
+
+    public MockFacesContext12(ExternalContext externalContext) {
+        super(externalContext);
+    }
+
+
+    public MockFacesContext12(ExternalContext externalContext, Lifecycle lifecycle) {
+        super(externalContext, lifecycle);
+    }
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+    /**
+     * <p>Set the <code>ELContext</code> instance for this instance.</p>
+     *
+     * @param elContext The new ELContext
+     */
+    public void setELContext(ELContext elContext) {
+
+        this.elContext = elContext;
+
+    }
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    private ELContext elContext = null;
+
+
+    // ---------------------------------------------------- FacesContext Methods
+
+
+    /** {@inheritDoc} */
+    public ELContext getELContext() {
+
+        if (this.elContext == null) {
+            this.elContext = new MockELContext();
+            this.elContext.putContext(FacesContext.class, this);
+            // FIXME - Call Application.getELContextListeners() and send event if needed
+        }
+
+        return this.elContext;
+
+    }
+
+
+    /** {@inheritDoc} */
+    public void release() {
+        super.release();
+        this.elContext = null;
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext12.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext12.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java?view=diff&rev=453841&r1=453840&r2=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java (original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContextFactory.java Fri Oct  6 20:03:13 2006
@@ -16,7 +16,9 @@
 
 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;
@@ -37,9 +39,42 @@
 
 
     /**
-     * <p>Return a default instance.</p>
+     * <p>Look up the constructor we will use for creating <code>MockFacesContext</code>
+     * instances.</p>
      */
-    public MockFacesContextFactory() { }
+    public MockFacesContextFactory() {
+
+        Class clazz = null;
+
+        // Try to load the 1.2 version of our mock FacesContext class
+        try {
+            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 (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
@@ -48,6 +83,35 @@
     // ------------------------------------------------------ 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;
+
+
     // --------------------------------------------- FacesContextFactory Methods
 
 
@@ -56,11 +120,49 @@
                                         Object response,
                                         Lifecycle lifecycle) throws FacesException {
 
-        MockExternalContext externalContext =
-          new MockExternalContext((ServletContext) context,
-                                  (HttpServletRequest) request,
-                                  (HttpServletResponse) response);
-        return new MockFacesContext(externalContext, lifecycle);
+        // Select the appropriate MockExternalContext implementation class
+        Class clazz = MockExternalContext.class;
+        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);
+        }
 
     }
 

Added: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFunctionMapper.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFunctionMapper.java?view=auto&rev=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFunctionMapper.java (added)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFunctionMapper.java Fri Oct  6 20:03:13 2006
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.Method;
+import java.util.HashMap;
+import java.util.Map;
+import javax.el.FunctionMapper;
+
+/**
+ * <p>Mock implementation of <code>FunctionMapper</code>.</p>
+ *
+ * $Id$
+ */
+
+public class MockFunctionMapper extends FunctionMapper {
+    
+
+    // ------------------------------------------------------------ Constructors
+
+
+    /** Creates a new instance of MockFunctionMapper */
+    public MockFunctionMapper() {
+    }
+    
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    /**
+     * <p>Map of <code>Method</code> descriptors for static methods, keyed by
+     * a string composed of the prefix (or "" if none), a ":", and the local name.</p>
+     */
+    private Map functions = new HashMap();
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+    /**
+     * <p>Store a mapping of the specified prefix and localName to the
+     * specified method, which must be static.</p>
+     */
+    public void mapFunction(String prefix, String localName, Method method) {
+
+        functions.put(prefix + ":" + localName, method);
+
+    }
+
+
+    // -------------------------------------------------- FunctionMapper Methods
+
+
+    /** {@inheritDoc} */
+    public Method resolveFunction(String prefix, String localName) {
+
+        return (Method) functions.get(prefix + ":" + localName);
+
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFunctionMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFunctionMapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockVariableMapper.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockVariableMapper.java?view=auto&rev=453841
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockVariableMapper.java (added)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockVariableMapper.java Fri Oct  6 20:03:13 2006
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.ValueExpression;
+import javax.el.VariableMapper;
+
+/**
+ * <p>Mock implementation of <code>VariableMapper</code>.</p>
+ *
+ * $Id$
+ */
+
+public class MockVariableMapper extends VariableMapper {
+    
+
+    // ------------------------------------------------------------ Constructors
+
+
+    /** Creates a new instance of MockVariableMapper */
+    public MockVariableMapper() {
+    }
+    
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    /**
+     * <p>Map of <code>ValueExpression</code>s, keyed by variable name.</p>
+     */
+    private Map expressions = new HashMap();
+
+
+    // ----------------------------------------------------- Mock Object Methods
+
+
+    // -------------------------------------------------- FunctionMapper Methods
+
+
+    /** {@inheritDoc} */
+    public ValueExpression resolveVariable(String variable) {
+
+        return (ValueExpression) expressions.get(variable);
+
+    }
+
+
+    /** {@inheritDoc} */
+    public ValueExpression setVariable(String variable, ValueExpression expression) {
+
+        ValueExpression original = (ValueExpression) expressions.get(variable);
+        if (expression == null) {
+            expressions.remove(variable);
+        } else {
+            expressions.put(variable, expression);
+        }
+        return original;
+
+    }
+
+
+}

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockVariableMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockVariableMapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL