You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/04/21 15:12:36 UTC

svn commit: r936293 - in /myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp: ./ JspViewDeclarationLanguageTest.java

Author: jakobk
Date: Wed Apr 21 13:12:35 2010
New Revision: 936293

URL: http://svn.apache.org/viewvc?rev=936293&view=rev
Log:
MYFACES-2665 Legacy ViewHandler doesn't work in back compatibility mode for JSP pages (test case)

Added:
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java   (with props)

Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java?rev=936293&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java Wed Apr 21 13:12:35 2010
@@ -0,0 +1,173 @@
+/*
+ * 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.view.jsp;
+
+import java.io.IOException;
+
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+
+/**
+ * Test class for JspViewDeclarationLanguage.
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class JspViewDeclarationLanguageTest extends AbstractJsfTestCase
+{
+
+    private TrackingJspViewDeclarationLanguage jspVdl;
+    
+    public JspViewDeclarationLanguageTest(String name)
+    {
+        super(name);
+    }
+    
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        jspVdl = new TrackingJspViewDeclarationLanguage();
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        jspVdl = null;
+        
+        super.tearDown();
+    }
+
+    /**
+     * Tests if renderView() implicitly calls buildView() if there was no call
+     * to buildView() for the given UIViewRoot yet. This is needed in order to
+     * support legacy ViewHandlers which return null on getViewDeclarationLanguage()
+     * and thus vdl.buildView() was not called yet when renderView() is invoked.
+     */
+    public void testBuildViewCalledBeforeViewRendered() 
+    {
+        try
+        {
+            jspVdl.renderView(facesContext, facesContext.getViewRoot());
+        }
+        catch (Exception e)
+        {
+            // we're not testing the real behavior here, so Exceptions may occur
+        }
+        
+        // assert that buildView() was implicitly called once (by renderView())
+        assertEquals(1, jspVdl._buildViewCalled);
+    }
+    
+    /**
+     * Tests if buildView() is not called twice if it has already been called
+     * before renderView() is invoked.
+     * This test is related to testBuildViewCalledBeforeViewRendered.
+     */
+    public void testBuildViewNotCalledTwiceInRenderView()
+    {
+        try
+        {
+            jspVdl.buildView(facesContext, facesContext.getViewRoot());
+        }
+        catch (Exception e)
+        {
+            // we're not testing the real behavior here, so Exceptions may occur
+        }
+        try
+        {
+            jspVdl.renderView(facesContext, facesContext.getViewRoot());
+        }
+        catch (Exception e)
+        {
+            // we're not testing the real behavior here, so Exceptions may occur
+        }
+        
+        // assert that buildView() was only called once
+        assertEquals(1, jspVdl._buildViewCalled);
+    }
+    
+    /**
+     * Tests if the direct/implicit calls to builView() work correctly
+     * for different views.
+     * This test is related to testBuildViewCalledBeforeViewRendered
+     * and testBuildViewNotCalledTwiceInRenderView.
+     */
+    public void testBuildViewRenderViewContractForDifferentViews()
+    {
+        UIViewRoot firstView = facesContext.getViewRoot();
+        UIViewRoot secondView = new UIViewRoot();
+        
+        try
+        {
+            jspVdl.buildView(facesContext, firstView);
+        }
+        catch (Exception e)
+        {
+            // we're not testing the real behavior here, so Exceptions may occur
+        }
+        try
+        {
+            jspVdl.renderView(facesContext, firstView);
+        }
+        catch (Exception e)
+        {
+            // we're not testing the real behavior here, so Exceptions may occur
+        }
+        try
+        {
+            jspVdl.renderView(facesContext, secondView);
+        }
+        catch (Exception e)
+        {
+            // we're not testing the real behavior here, so Exceptions may occur
+        }
+        
+        // assert that buildView() was called twice:
+        // the first time directly by jspVdl.buildView() for firstView
+        // the second time implicitly by jspVdl.renderView() for secondView
+        assertEquals(2, jspVdl._buildViewCalled);
+    }
+    
+    
+    /**
+     * Extends JspViewDeclarationLanguage to count the calls to buildView().
+     * 
+     * @author Jakob Korherr
+     */
+    private class TrackingJspViewDeclarationLanguage extends JspViewDeclarationLanguage
+    {
+
+        private int _buildViewCalled = 0;
+        
+        @Override
+        public void buildView(FacesContext context, UIViewRoot view)
+                throws IOException
+        {
+            _buildViewCalled++;
+            
+            super.buildView(context, view);
+        }
+        
+    }
+    
+}

Propchange: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain