You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/05/24 03:43:28 UTC

svn commit: r1485919 - in /myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock: MockExternalContext22.java MockFacesContext22.java MockFacesContextFactory.java

Author: lu4242
Date: Fri May 24 01:43:27 2013
New Revision: 1485919

URL: http://svn.apache.org/r1485919
Log:
Implement MockFacesContext22 and MockExternalContext22 classes

Added:
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockExternalContext22.java   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContext22.java   (with props)
    myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java   (with props)

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockExternalContext22.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockExternalContext22.java?rev=1485919&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockExternalContext22.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockExternalContext22.java Fri May 24 01:43:27 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.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 2.2.</p>
+ * 
+ * @author Leonardo Uribe
+ * @since 1.0.0
+ *
+ */
+public class MockExternalContext22 extends MockExternalContext20
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    public MockExternalContext22(ServletContext context,
+            HttpServletRequest request, HttpServletResponse response)
+    {
+        super(context, request, response);
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    // ----------------------------------------------------- Mock Object Methods
+
+    // ------------------------------------------------- ExternalContext Methods
+    
+}

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

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContext22.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContext22.java?rev=1485919&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContext22.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContext22.java Fri May 24 01:43:27 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.faces.context.ExternalContext;
+import javax.faces.lifecycle.Lifecycle;
+
+/**
+ * <p>Mock implementation of <code>FacesContext</code> that includes the semantics
+ * added by JavaServer Faces 2.0.</p>
+ * 
+ * @author Leonardo Uribe
+ * @since 1.0.0
+ *
+ */
+public class MockFacesContext22 extends MockFacesContext20
+{
+
+    // ------------------------------------------------------------ Constructors
+
+    public MockFacesContext22()
+    {
+        super();
+        setCurrentInstance(this);
+    }
+
+    public MockFacesContext22(ExternalContext externalContext)
+    {
+        super(externalContext);
+    }
+
+    public MockFacesContext22(ExternalContext externalContext,
+            Lifecycle lifecycle)
+    {
+        super(externalContext, lifecycle);
+    }
+
+    // ------------------------------------------------------ Instance Variables
+
+    private List<String> _resourceLibraryContracts;
+    
+    // ----------------------------------------------------- Mock Object Methods   
+
+    @Override
+    public List<String> getResourceLibraryContracts()
+    {
+        if (_resourceLibraryContracts == null)
+        {
+            return Collections.emptyList();
+        }
+        else
+        {
+            return _resourceLibraryContracts;
+        }
+    }
+    
+    @Override
+    public void setResourceLibraryContracts(List<String> contracts)
+    {
+        if (contracts == null)
+        {
+            _resourceLibraryContracts = null;
+        }
+        else if (contracts.isEmpty())
+        {
+            _resourceLibraryContracts = null;
+        }
+        else
+        {
+            _resourceLibraryContracts = new ArrayList<String>(contracts);
+        }
+    }
+
+    // ------------------------------------------------- ExternalContext Methods
+
+}

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

Added: myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java?rev=1485919&view=auto
==============================================================================
--- myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java (added)
+++ myfaces/test/trunk/test22/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java Fri May 24 01:43:27 2013
@@ -0,0 +1,313 @@
+/*
+ * 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.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: MockFacesContextFactory.java 990408 2010-08-28 18:59:21Z lu4242 $
+ * @since 1.0.0
+ */
+
+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.2 version of our mock FacesContext class
+        try
+        {
+            clazz = this.getClass().getClassLoader().loadClass(
+                    "org.apache.myfaces.test.mock.MockFacesContext22");
+            constructor = clazz.getConstructor(facesContextSignature);
+            jsf22 = 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 2.0 version of our mock FacesContext class
+        try
+        {
+            if (clazz == null)
+            {
+                clazz = this.getClass().getClassLoader().loadClass(
+                        "org.apache.myfaces.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.myfaces.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.myfaces.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;
+    
+    /**
+     * <p>Flag indicating that we are running in a JSF 2.2 environment.</p>
+     */
+    private boolean jsf22 = 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 (jsf22)
+        {
+            try
+            {
+                clazz = this.getClass().getClassLoader().loadClass(
+                        "org.apache.myfaces.test.mock.MockExternalContext22");
+            }
+            catch (RuntimeException e)
+            {
+                throw e;
+            }
+            catch (Exception e)
+            {
+                throw new FacesException(e);
+            }
+        }
+        
+        if (jsf20)
+        {
+            try
+            {
+                clazz = this.getClass().getClassLoader().loadClass(
+                        "org.apache.myfaces.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.myfaces.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);
+        }
+
+    }
+
+}

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