use of com.sun.faces.mock.MockServletConfig in project mojarra by eclipse-ee4j.
the class JUnitFacesTestCaseBase method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Set up Servlet API Objects
servletContext = new MockServletContext();
servletContext.addInitParameter("appParamName", "appParamValue");
servletContext.setAttribute("appScopeName", "appScopeValue");
config = new MockServletConfig(servletContext);
session = new MockHttpSession();
session.setAttribute("sesScopeName", "sesScopeValue");
request = new MockHttpServletRequest(session);
request.setAttribute("reqScopeName", "reqScopeValue");
response = new MockHttpServletResponse();
// Set up Faces API Objects
FactoryFinder.releaseFactories();
Method reInitializeFactoryManager = FactoryFinder.class.getDeclaredMethod("reInitializeFactoryManager", (Class<?>[]) null);
reInitializeFactoryManager.setAccessible(true);
reInitializeFactoryManager.invoke(null, (Object[]) null);
// Create something to stand-in as the InitFacesContext
new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle());
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, "com.sun.faces.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, "com.sun.faces.mock.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, "com.sun.faces.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, "com.sun.faces.mock.MockRenderKitFactory");
FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
lifecycle = (MockLifecycle) lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext = (MockFacesContext) fcFactory.getFacesContext(servletContext, request, response, lifecycle);
externalContext = (MockExternalContext) facesContext.getExternalContext();
Map map = new HashMap();
externalContext.setRequestParameterMap(map);
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
Aggregations