Search in sources :

Example 1 with MockExternalContext

use of com.sun.faces.mock.MockExternalContext 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);
}
Also used : MockFacesContext(com.sun.faces.mock.MockFacesContext) MockLifecycle(com.sun.faces.mock.MockLifecycle) MockExternalContext(com.sun.faces.mock.MockExternalContext) HashMap(java.util.HashMap) MockHttpServletRequest(com.sun.faces.mock.MockHttpServletRequest) FacesContextFactory(jakarta.faces.context.FacesContextFactory) LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory) MockServletConfig(com.sun.faces.mock.MockServletConfig) Method(java.lang.reflect.Method) MockServletContext(com.sun.faces.mock.MockServletContext) MockHttpSession(com.sun.faces.mock.MockHttpSession) ApplicationFactory(jakarta.faces.application.ApplicationFactory) HashMap(java.util.HashMap) Map(java.util.Map) MockHttpServletResponse(com.sun.faces.mock.MockHttpServletResponse)

Example 2 with MockExternalContext

use of com.sun.faces.mock.MockExternalContext in project mojarra by eclipse-ee4j.

the class UICommandTestCase method PENDING_FIXME_testActionOrder.

// ------------------------------------------------- Individual Test Methods
// Test order of action listener calls with actionListener also
public void PENDING_FIXME_testActionOrder() throws Exception {
    RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    RenderKit renderKit = renderKitFactory.getRenderKit(facesContext, RenderKitFactory.HTML_BASIC_RENDER_KIT);
    renderKit.addRenderer(UICommand.COMPONENT_FAMILY, "jakarta.faces.Button", new ButtonRenderer());
    UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null);
    root.getChildren().add(component);
    UICommand command = (UICommand) component;
    command.setId("command");
    command.addActionListener(new CommandActionListenerTestImpl("l1"));
    command.addActionListener(new CommandActionListenerTestImpl("l2"));
    command.setImmediate(true);
    request.setAttribute("l3", new CommandActionListenerTestImpl("l3"));
    // Override the default action listener to test ordering
    ActionListener oldDefaultActionListener = facesContext.getApplication().getActionListener();
    facesContext.getApplication().setActionListener(new CommandActionListenerTestImpl("14"));
    Map map = new HashMap();
    map.put(command.getClientId(facesContext), "");
    MockExternalContext econtext = (MockExternalContext) facesContext.getExternalContext();
    econtext.setRequestParameterMap(map);
    CommandActionListenerTestImpl.trace(null);
    root.processDecodes(facesContext);
    assertEquals("/l1/l2/l3", CommandActionListenerTestImpl.trace());
    // Restore the default action listener
    facesContext.getApplication().setActionListener(oldDefaultActionListener);
}
Also used : MockExternalContext(com.sun.faces.mock.MockExternalContext) ActionListener(jakarta.faces.event.ActionListener) HashMap(java.util.HashMap) RenderKit(jakarta.faces.render.RenderKit) HashMap(java.util.HashMap) Map(java.util.Map) RenderKitFactory(jakarta.faces.render.RenderKitFactory)

Example 3 with MockExternalContext

use of com.sun.faces.mock.MockExternalContext in project mojarra by eclipse-ee4j.

the class UIComponentBaseAttachedStateTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    component = new UIOutput();
    facesContext = new MockFacesContext();
    servletContext = new MockServletContext();
    servletContext.addInitParameter("appParamName", "appParamValue");
    servletContext.setAttribute("appScopeName", "appScopeValue");
    request = new MockHttpServletRequest(null);
    request.setAttribute("reqScopeName", "reqScopeValue");
    response = new MockHttpServletResponse();
    // Create something to stand-in as the InitFacesContext
    new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle());
}
Also used : MockFacesContext(com.sun.faces.mock.MockFacesContext) MockLifecycle(com.sun.faces.mock.MockLifecycle) MockExternalContext(com.sun.faces.mock.MockExternalContext) MockHttpServletRequest(com.sun.faces.mock.MockHttpServletRequest) MockServletContext(com.sun.faces.mock.MockServletContext) MockHttpServletResponse(com.sun.faces.mock.MockHttpServletResponse)

Example 4 with MockExternalContext

use of com.sun.faces.mock.MockExternalContext in project mojarra by eclipse-ee4j.

the class UIOutputAttachedObjectStateTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    facesContext = new MockFacesContext();
    facesContext = new MockFacesContext();
    servletContext = new MockServletContext();
    servletContext.addInitParameter("appParamName", "appParamValue");
    servletContext.setAttribute("appScopeName", "appScopeValue");
    request = new MockHttpServletRequest(null);
    request.setAttribute("reqScopeName", "reqScopeValue");
    response = new MockHttpServletResponse();
    // Create something to stand-in as the InitFacesContext
    new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle());
}
Also used : MockFacesContext(com.sun.faces.mock.MockFacesContext) MockLifecycle(com.sun.faces.mock.MockLifecycle) MockExternalContext(com.sun.faces.mock.MockExternalContext) MockHttpServletRequest(com.sun.faces.mock.MockHttpServletRequest) MockServletContext(com.sun.faces.mock.MockServletContext) MockHttpServletResponse(com.sun.faces.mock.MockHttpServletResponse)

Aggregations

MockExternalContext (com.sun.faces.mock.MockExternalContext)4 MockFacesContext (com.sun.faces.mock.MockFacesContext)3 MockHttpServletRequest (com.sun.faces.mock.MockHttpServletRequest)3 MockHttpServletResponse (com.sun.faces.mock.MockHttpServletResponse)3 MockLifecycle (com.sun.faces.mock.MockLifecycle)3 MockServletContext (com.sun.faces.mock.MockServletContext)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MockHttpSession (com.sun.faces.mock.MockHttpSession)1 MockServletConfig (com.sun.faces.mock.MockServletConfig)1 ApplicationFactory (jakarta.faces.application.ApplicationFactory)1 FacesContextFactory (jakarta.faces.context.FacesContextFactory)1 ActionListener (jakarta.faces.event.ActionListener)1 LifecycleFactory (jakarta.faces.lifecycle.LifecycleFactory)1 RenderKit (jakarta.faces.render.RenderKit)1 RenderKitFactory (jakarta.faces.render.RenderKitFactory)1 Method (java.lang.reflect.Method)1