Skip to content

Commit

Permalink
fixed FacesServletTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Mar 23, 2024
1 parent 072cc9c commit 01c1fbc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import java.util.HashMap;
import java.util.Map;

import jakarta.enterprise.inject.spi.CDI;
import jakarta.faces.FactoryFinder;
import jakarta.faces.application.ApplicationFactory;
import jakarta.faces.context.FacesContextFactory;
import jakarta.faces.lifecycle.LifecycleFactory;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

Expand All @@ -34,12 +40,6 @@
import com.sun.faces.mock.MockServletConfig;
import com.sun.faces.mock.MockServletContext;

import jakarta.enterprise.inject.spi.CDI;
import jakarta.faces.FactoryFinder;
import jakarta.faces.application.ApplicationFactory;
import jakarta.faces.context.FacesContextFactory;
import jakarta.faces.lifecycle.LifecycleFactory;

public class JUnitFacesTestCaseBase {

protected MockApplication application = null;
Expand Down Expand Up @@ -78,6 +78,8 @@ public void setUp() throws Exception {
new MockFacesContext(new MockExternalContext(servletContext, request, response),
new MockLifecycle());

FactoryFinder.setFactory(FactoryFinder.FACES_SERVLET_FACTORY,
"com.sun.faces.mock.MockFacesServletFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
"com.sun.faces.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
Expand Down
47 changes: 47 additions & 0 deletions impl/src/test/java/com/sun/faces/mock/MockFacesServletFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.faces.mock;

import jakarta.faces.FactoryFinder;
import jakarta.faces.webapp.FacesServletFactory;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;

import com.sun.faces.webapp.FacesServletImpl;

public class MockFacesServletFactory extends FacesServletFactory {
public MockFacesServletFactory() {
System.setProperty(FactoryFinder.FACES_SERVLET_FACTORY, this.getClass().getName());
}

@Override
public Servlet getFacesServlet(ServletConfig config) {
Servlet facesServlet = new FacesServletImpl();
try {
facesServlet.init(config);
} catch (ServletException e) {
throw new IllegalStateException(e);
}
return facesServlet;
}

@Override
public FacesServletFactory getWrapped() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.sun.faces.junit.JUnitFacesTestCaseBase;
import com.sun.faces.mock.MockRenderKit;

import jakarta.faces.FactoryFinder;
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.render.RenderKit;
import jakarta.faces.render.RenderKitFactory;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.sun.faces.junit.JUnitFacesTestCaseBase;
import com.sun.faces.mock.MockRenderKit;

public class FacesServletTestCase extends JUnitFacesTestCaseBase {

// this is private in FacesServlet to not break backwards compatibility
Expand Down

0 comments on commit 01c1fbc

Please sign in to comment.