You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/10/01 11:39:20 UTC

git commit: DELTASPIKE-266 remove MockViewContext

Updated Branches:
  refs/heads/master 909a80005 -> 76f3d4d81


DELTASPIKE-266 remove MockViewContext

we will replace this with a more flexible solution later


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/76f3d4d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/76f3d4d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/76f3d4d8

Branch: refs/heads/master
Commit: 76f3d4d81295e398da2d0cb0633a46ba17b3e72f
Parents: 909a800
Author: Mark Struberg <st...@apache.org>
Authored: Mon Oct 1 11:38:37 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Oct 1 11:38:37 2012 +0200

----------------------------------------------------------------------
 .../jsf/impl/scope/view/MockViewScopedContext.java |   75 ---------------
 .../jsf/impl/scope/view/ViewScopedExtension.java   |   23 +----
 2 files changed, 1 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/76f3d4d8/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/MockViewScopedContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/MockViewScopedContext.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/MockViewScopedContext.java
deleted file mode 100644
index 6410cf1..0000000
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/MockViewScopedContext.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.deltaspike.jsf.impl.scope.view;
-
-import javax.enterprise.inject.spi.BeanManager;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-
-/**
- * <p>This is a Mock version of the {@link ViewScopedContext}.
- * It will automatically get used instead of it's parent class
- * if we are in the
- * {@link javax.faces.application.ProjectStage#UnitTest}.</p>
- *
- * <p>There is of course no automatic cleaning if we transit over to the
- * next view! In this case you can use {@link #resetViewMap()} to clean
- * the mock ViewMap manually in your unit test.</p>
- *
- * <p><b>Attention:</b> The ViewMap is a shared static ConcurrentHashMap,
- * so this implementation is not able to emulate the behaviour of multiple views
- * at the same time!</p>
- */
-public class MockViewScopedContext extends ViewScopedContext
-{
-
-    private static Map<String, Object> mockViewMap = new ConcurrentHashMap<String, Object>();
-
-    public MockViewScopedContext(BeanManager beanManager)
-    {
-        super(beanManager);
-    }
-
-    /**
-     * Simply clear the mock ViewMap.
-     * This function should get called if the same unit test needs to test multiple
-     * views and also between different tests if the container doesn't get restarted
-     * in between.
-     */
-    public static void resetViewMap()
-    {
-        mockViewMap.clear();
-    }
-
-    @Override
-    protected Map<String, Object> getViewMap()
-    {
-        return mockViewMap;
-    }
-
-    /**
-     * @return always <code>true</code> since in a unit test it's always active.
-     */
-    @Override
-    public boolean isActive()
-    {
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/76f3d4d8/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedExtension.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedExtension.java
index c001da4..d5a2e30 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedExtension.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedExtension.java
@@ -26,10 +26,8 @@ import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
 import javax.faces.bean.ViewScoped;
 
-import org.apache.deltaspike.core.api.projectstage.ProjectStage;
 import org.apache.deltaspike.core.spi.activation.Deactivatable;
 import org.apache.deltaspike.core.util.ClassDeactivationUtils;
-import org.apache.deltaspike.core.util.ProjectStageProducer;
 
 
 /**
@@ -47,10 +45,6 @@ import org.apache.deltaspike.core.util.ProjectStageProducer;
  * ViewScoped. The {@link ViewScopedContext} is responsible for actually storing all our
  * &#064;ViewScoped contextual instances in the JSF ViewMap.</li>
  * </ol>
- *
- * <p>The extension automatically detects if we are in the
- * {@link ProjectStage#UnitTest} and uses
- * </p>
  */
 public class ViewScopedExtension implements Extension, Deactivatable
 {
@@ -77,22 +71,7 @@ public class ViewScopedExtension implements Extension, Deactivatable
 
         //X TODO check whether we still need this in EE6: CodiStartupBroadcaster.broadcastStartup();
         
-        // we need to do this manually because there is no dependency injection in place
-        // at this time
-        ProjectStageProducer psp = ProjectStageProducer.getInstance();
-
-        ProjectStage projectStage = psp.getProjectStage();
-
-        if (projectStage == ProjectStage.UnitTest)
-        {
-            // for unit tests, we use the mock context
-            afterBeanDiscovery.addContext(new MockViewScopedContext(beanManager));
-        }
-        else
-        {
-            // otherwise we use the real JSF ViewMap context
-            afterBeanDiscovery.addContext(new ViewScopedContext(beanManager));
-        }
+        afterBeanDiscovery.addContext(new ViewScopedContext(beanManager));
     }
 
 }