Search in sources :

Example 1 with MockHttpServletResponse

use of com.sun.faces.mock.MockHttpServletResponse 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 MockHttpServletResponse

use of com.sun.faces.mock.MockHttpServletResponse 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 3 with MockHttpServletResponse

use of com.sun.faces.mock.MockHttpServletResponse 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)

Example 4 with MockHttpServletResponse

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

the class FactoryFinderTestCase method testNoFacesContextInitially.

public void testNoFacesContextInitially() throws Exception {
    assertNull(FacesContext.getCurrentInstance());
    FactoryFinder.releaseFactories();
    FactoryFinder.setFactory(FACTORIES[0][0], FACTORIES[0][1]);
    FactoryFinder.setFactory(FACTORIES[1][0], FACTORIES[1][1]);
    FactoryFinder.setFactory(FACTORIES[2][0], FACTORIES[2][1]);
    FactoryFinder.setFactory(FACTORIES[3][0], FACTORIES[3][1]);
    FactoryFinder.setFactory(FACTORIES[4][0], FACTORIES[4][1]);
    FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Object request = new MockHttpServletRequest();
    Object response = new MockHttpServletResponse();
    Object containerContext = new MockServletContext();
    Lifecycle l = lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    FacesContext context = fcFactory.getFacesContext(containerContext, request, response, l);
    ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    Application app = aFactory.getApplication();
    FactoryFinder.releaseFactories();
}
Also used : FacesContext(jakarta.faces.context.FacesContext) MockHttpServletRequest(com.sun.faces.mock.MockHttpServletRequest) FacesContextFactory(jakarta.faces.context.FacesContextFactory) LifecycleFactory(jakarta.faces.lifecycle.LifecycleFactory) Lifecycle(jakarta.faces.lifecycle.Lifecycle) ApplicationFactory(jakarta.faces.application.ApplicationFactory) Application(jakarta.faces.application.Application) MockHttpServletResponse(com.sun.faces.mock.MockHttpServletResponse) MockServletContext(com.sun.faces.mock.MockServletContext)

Example 5 with MockHttpServletResponse

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

the class ELUtilsTest method setUp.

@Before
public void setUp() {
    MockServletContext mockServletContext = new MockServletContext() {

        @Override
        public URL getResource(String path) {
            return null;
        }
    };
    mockServletContext.addInitParameter("appParamName", "appParamValue");
    mockServletContext.setAttribute("appScopeName", "appScopeValue");
    ExternalContextImpl externalContext = new ExternalContextImpl(mockServletContext, new MockHttpServletRequest(), new MockHttpServletResponse());
    FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, "com.sun.faces.mock.MockRenderKitFactory");
    new FacesContextImpl(externalContext, new LifecycleImpl());
    new ApplicationImpl();
    applicationAssociate = (ApplicationAssociate) externalContext.getApplicationMap().get(RIConstants.FACES_PREFIX + "ApplicationAssociate");
    FacesContext.getCurrentInstance().getAttributes().put(RIConstants.CDI_BEAN_MANAGER, new MockBeanManager());
}
Also used : FacesContextImpl(com.sun.faces.context.FacesContextImpl) MockHttpServletRequest(com.sun.faces.mock.MockHttpServletRequest) ApplicationImpl(com.sun.faces.application.ApplicationImpl) MockBeanManager(com.sun.faces.mock.MockBeanManager) ExternalContextImpl(com.sun.faces.context.ExternalContextImpl) LifecycleImpl(com.sun.faces.lifecycle.LifecycleImpl) MockServletContext(com.sun.faces.mock.MockServletContext) MockHttpServletResponse(com.sun.faces.mock.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

MockHttpServletRequest (com.sun.faces.mock.MockHttpServletRequest)5 MockHttpServletResponse (com.sun.faces.mock.MockHttpServletResponse)5 MockServletContext (com.sun.faces.mock.MockServletContext)5 MockExternalContext (com.sun.faces.mock.MockExternalContext)3 MockFacesContext (com.sun.faces.mock.MockFacesContext)3 MockLifecycle (com.sun.faces.mock.MockLifecycle)3 ApplicationFactory (jakarta.faces.application.ApplicationFactory)2 FacesContextFactory (jakarta.faces.context.FacesContextFactory)2 LifecycleFactory (jakarta.faces.lifecycle.LifecycleFactory)2 ApplicationImpl (com.sun.faces.application.ApplicationImpl)1 ExternalContextImpl (com.sun.faces.context.ExternalContextImpl)1 FacesContextImpl (com.sun.faces.context.FacesContextImpl)1 LifecycleImpl (com.sun.faces.lifecycle.LifecycleImpl)1 MockBeanManager (com.sun.faces.mock.MockBeanManager)1 MockHttpSession (com.sun.faces.mock.MockHttpSession)1 MockServletConfig (com.sun.faces.mock.MockServletConfig)1 Application (jakarta.faces.application.Application)1 FacesContext (jakarta.faces.context.FacesContext)1 Lifecycle (jakarta.faces.lifecycle.Lifecycle)1 Method (java.lang.reflect.Method)1