org.apache.myfaces.extensions.cdi.jsf2.impl.scope.view
Class MockViewScopedContext

java.lang.Object
  extended by org.apache.myfaces.extensions.cdi.jsf2.impl.scope.view.ViewScopedContext
      extended by org.apache.myfaces.extensions.cdi.jsf2.impl.scope.view.MockViewScopedContext
All Implemented Interfaces:
EventListener, javax.enterprise.context.spi.Context, javax.faces.event.FacesListener, javax.faces.event.SystemEventListener

public class MockViewScopedContext
extends ViewScopedContext

This is a Mock version of the ViewScopedContext. It will automatically get used instead of it's parent class if we are in the ProjectStage.UnitTest.

There is of course no automatic cleaning if we transit over to the next view! In this case you can use resetViewMap() to clean the mock ViewMap manually in your unit test.

Attention: The ViewMap is a shared static ConcurrentHashMap, so this implementation is not able to emulate the behaviour of multiple views at the same time!


Constructor Summary
MockViewScopedContext()
           
 
Method Summary
protected  Map<String,Object> getViewMap()
           
 boolean isActive()
          The view context is active if a valid ViewRoot could be detected.
static void resetViewMap()
          Simply clear the mock ViewMap.
 
Methods inherited from class org.apache.myfaces.extensions.cdi.jsf2.impl.scope.view.ViewScopedContext
get, get, getScope, getViewRoot, isListenerForSource, processEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockViewScopedContext

public MockViewScopedContext()
Method Detail

resetViewMap

public static void resetViewMap()
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.


getViewMap

protected Map<String,Object> getViewMap()
Overrides:
getViewMap in class ViewScopedContext

isActive

public boolean isActive()
Description copied from class: ViewScopedContext
The view context is active if a valid ViewRoot could be detected.

Specified by:
isActive in interface javax.enterprise.context.spi.Context
Overrides:
isActive in class ViewScopedContext
Returns:
always true since in a unit test it's always active.


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.