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

svn commit: r930685 - in /myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src: main/java/org/apache/myfaces/scripting/jsf/ test/java/org/apache/myfaces/scripting/jsf/

Author: werpu
Date: Sun Apr  4 13:09:11 2010
New Revision: 930685

URL: http://svn.apache.org/viewvc?rev=930685&view=rev
Log:
http://issues.apache.org/jira/browse/EXTSCRIPT-109

adding basic refresh listener tests

Added:
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListenerTest.java   (with props)
Modified:
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListener.java

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListener.java?rev=930685&r1=930684&r2=930685&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListener.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListener.java Sun Apr  4 13:09:11 2010
@@ -39,7 +39,20 @@ import java.util.Map;
  */
 
 public class RefreshPhaseListener implements PhaseListener {
-    static final String EQ_KEY = "RefreshPhaseListenerDone";
+
+    public static final String EQ_KEY = "RefreshPhaseListenerDone";
+
+    /**
+     * this eases testing, because in our
+     * absence of intelligence we have
+     * not done yet the WeavingContext as singleton
+     * like it should be
+     */
+    static Runnable _action = new Runnable() {
+        public void run() {
+              WeavingContext.doRequestRefreshes();
+        }
+    };
 
     public void afterPhase(PhaseEvent event) {
     }
@@ -52,12 +65,16 @@ public class RefreshPhaseListener implem
         if (requestMap.containsKey(EQ_KEY)) return;
         requestMap.put(EQ_KEY, Boolean.TRUE);
 
-        WeavingContext.doRequestRefreshes();
-
+       RefreshPhaseListener._action.run();
     }
 
     public PhaseId getPhaseId() {
         return PhaseId.ANY_PHASE;
     }
 
+    @SuppressWarnings("unused")
+    public static void applyAction(Runnable newAction) {
+        _action = newAction;
+    }
+
 }

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListenerTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListenerTest.java?rev=930685&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListenerTest.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListenerTest.java Sun Apr  4 13:09:11 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.scripting.jsf;
+
+import org.apache.myfaces.scripting.core.support.MockServletContext;
+import org.apache.myfaces.scripting.core.util.WeavingContextInitializer;
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RefreshPhaseListenerTest extends AbstractJsfTestCase {
+    MockServletContext context;
+
+    boolean executed = false;
+    Runnable runner;
+
+    RefreshPhaseListener probe;
+
+
+    public RefreshPhaseListenerTest() {
+        super(RefreshPhaseListenerTest.class.getName());
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        probe = new RefreshPhaseListener();
+        context = new MockServletContext();
+        WeavingContextInitializer.initWeavingContext(context);
+
+        runner = new Runnable() {
+            public void run() {
+                executed = true;
+            }
+        };
+    }
+
+    public void testCalling1() throws Exception {
+        RefreshPhaseListener.applyAction(runner);
+
+        assertTrue(probe.getPhaseId() == PhaseId.ANY_PHASE);
+        probe.beforePhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, new MockLifecycle()));
+        assertTrue(executed);
+        executed = false;
+        probe.beforePhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES,  new MockLifecycle()));
+        assertFalse(executed);
+
+    }
+
+    public void testAfterPhase() {
+        probe.afterPhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, new MockLifecycle()));
+    }
+
+}

Propchange: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListenerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/scripting/jsf/RefreshPhaseListenerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL