Update spring-faces to Jakarta EE
FlowResourceResolver.java is removed, since it was deprecated, see https://github.com/jakartaee/faces/issues/1583 See gh-1794
This commit is contained in:
committed by
rstoyanchev
parent
c0173e54d5
commit
bce7f0cc91
@@ -42,7 +42,7 @@ public abstract class AbstractResourcesConfigurationTests {
|
||||
map = this.context.getBeansOfType(SimpleUrlHandlerMapping.class);
|
||||
assertEquals(1, map.values().size());
|
||||
SimpleUrlHandlerMapping handlerMapping = (SimpleUrlHandlerMapping) map.values().iterator().next();
|
||||
assertSame(resourceHandler, handlerMapping.getHandlerMap().get("/javax.faces.resource/**"));
|
||||
assertSame(resourceHandler, handlerMapping.getHandlerMap().get("/jakarta.faces.resource/**"));
|
||||
assertEquals(0, handlerMapping.getOrder());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.faces.model;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -8,16 +9,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.component.UIColumn;
|
||||
import javax.faces.component.UICommand;
|
||||
import javax.faces.component.UIData;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.AbortProcessingException;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.event.ActionListener;
|
||||
|
||||
|
||||
import org.apache.myfaces.test.mock.MockFacesContext;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -27,6 +18,15 @@ import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.sun.faces.facelets.component.UIRepeat;
|
||||
|
||||
import jakarta.faces.component.UIColumn;
|
||||
import jakarta.faces.component.UICommand;
|
||||
import jakarta.faces.component.UIData;
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
import jakarta.faces.event.AbortProcessingException;
|
||||
import jakarta.faces.event.ActionEvent;
|
||||
import jakarta.faces.event.ActionListener;
|
||||
|
||||
public class SelectionTrackingActionListenerTests {
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public class SelectionTrackingActionListenerTests {
|
||||
|
||||
this.dataModel.setRowIndex(2);
|
||||
assertFalse(this.dataModel.isCurrentRowSelected());
|
||||
assertTrue(this.dataModel.getSelectedRow() != this.dataModel.getRowData());
|
||||
assertNotSame(this.dataModel.getSelectedRow(), this.dataModel.getRowData());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,14 +120,14 @@ public class SelectionTrackingActionListenerTests {
|
||||
|
||||
ReflectionUtils.invokeMethod(indexMutator, uiRepeat, new MockFacesContext(), 2);
|
||||
assertFalse(this.dataModel.isCurrentRowSelected());
|
||||
assertTrue(this.dataModel.getSelectedRow() != this.dataModel.getRowData());
|
||||
assertNotSame(this.dataModel.getSelectedRow(), this.dataModel.getRowData());
|
||||
}
|
||||
|
||||
private class TestRowData {
|
||||
private static class TestRowData {
|
||||
|
||||
}
|
||||
|
||||
private class TestDelegateActionListener implements ActionListener {
|
||||
private static class TestDelegateActionListener implements ActionListener {
|
||||
|
||||
public boolean processedEvent = false;
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.model.DataModel;
|
||||
import javax.faces.model.ListDataModel;
|
||||
import jakarta.faces.model.DataModel;
|
||||
import jakarta.faces.model.ListDataModel;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.convert.converters.Converter;
|
||||
|
||||
@@ -3,12 +3,12 @@ package org.springframework.faces.model.converter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.model.DataModel;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
|
||||
import jakarta.faces.model.DataModel;
|
||||
|
||||
public class FacesConversionServiceTests {
|
||||
private FacesConversionService service;
|
||||
|
||||
|
||||
@@ -7,9 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -22,6 +19,9 @@ import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.web.servlet.view.UrlBasedViewResolver;
|
||||
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
|
||||
public class JsfViewTests {
|
||||
|
||||
UrlBasedViewResolver resolver;
|
||||
@@ -59,7 +59,7 @@ public class JsfViewTests {
|
||||
view.render(new HashMap<>(), new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
private class ResourceCheckingViewHandler extends MockViewHandler {
|
||||
private static class ResourceCheckingViewHandler extends MockViewHandler {
|
||||
|
||||
public UIViewRoot createView(FacesContext context, String viewId) {
|
||||
assertNotNull(viewId);
|
||||
|
||||
@@ -4,12 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.MethodExpression;
|
||||
import javax.el.MethodInfo;
|
||||
import javax.faces.component.UICommand;
|
||||
import javax.faces.event.ActionEvent;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -20,6 +14,12 @@ import org.springframework.webflow.engine.ViewState;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
import jakarta.el.ELContext;
|
||||
import jakarta.el.MethodExpression;
|
||||
import jakarta.el.MethodInfo;
|
||||
import jakarta.faces.component.UICommand;
|
||||
import jakarta.faces.event.ActionEvent;
|
||||
|
||||
public class FlowActionListenerTests {
|
||||
|
||||
FlowActionListener listener;
|
||||
@@ -78,7 +78,7 @@ public class FlowActionListenerTests {
|
||||
"An unexpected event was signaled");
|
||||
}
|
||||
|
||||
private class MethodExpressionStub extends MethodExpression {
|
||||
private static class MethodExpressionStub extends MethodExpression {
|
||||
|
||||
String result;
|
||||
|
||||
@@ -117,7 +117,7 @@ public class FlowActionListenerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private class MockViewState extends ViewState {
|
||||
private static class MockViewState extends ViewState {
|
||||
|
||||
public MockViewState() {
|
||||
super(new Flow("mockFlow"), "mockView", context -> {
|
||||
|
||||
@@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import jakarta.el.ELContext;
|
||||
|
||||
import org.apache.myfaces.test.el.MockELContext;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
@@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -14,8 +15,8 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import jakarta.faces.application.FacesMessage;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -44,7 +45,7 @@ public class FlowFacesContextTests {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.jsf.setUp();
|
||||
this.requestContext = (RequestContext) EasyMock.createMock(RequestContext.class);
|
||||
this.requestContext = EasyMock.createMock(RequestContext.class);
|
||||
this.facesContext = new FlowFacesContext(this.requestContext, this.jsf.facesContext());
|
||||
setupMessageContext();
|
||||
}
|
||||
@@ -286,7 +287,7 @@ public class FlowFacesContextTests {
|
||||
|
||||
this.facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_ERROR, "foo", "bar"));
|
||||
|
||||
assertEquals(true, this.facesContext.isValidationFailed());
|
||||
assertTrue(this.facesContext.isValidationFailed());
|
||||
}
|
||||
|
||||
private void setupMessageContext() {
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.context.PartialViewContext;
|
||||
import javax.faces.context.PartialViewContextWrapper;
|
||||
import jakarta.faces.context.PartialViewContext;
|
||||
import jakarta.faces.context.PartialViewContextWrapper;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class FlowResponseStateManagerTests {
|
||||
|
||||
assertEquals(state, viewMap.get(FlowResponseStateManager.FACES_VIEW_STATE));
|
||||
assertEquals(
|
||||
"<input type=\"hidden\" name=\"javax.faces.ViewState\" id=\"javax.faces.ViewState\" value=\"e1s1\" />",
|
||||
"<input type=\"hidden\" name=\"jakarta.faces.ViewState\" id=\"jakarta.faces.ViewState\" value=\"e1s1\" />",
|
||||
this.jsfMock.contentAsString());
|
||||
EasyMock.verify(this.flowExecutionContext, this.requestContext);
|
||||
}
|
||||
|
||||
@@ -4,16 +4,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import javax.faces.FactoryFinder;
|
||||
import javax.faces.application.Application;
|
||||
import javax.faces.application.ApplicationFactory;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.FacesContextFactory;
|
||||
import javax.faces.lifecycle.LifecycleFactory;
|
||||
import javax.faces.render.RenderKitFactory;
|
||||
|
||||
import org.apache.myfaces.test.base.AbstractJsfTestCase;
|
||||
import org.apache.myfaces.test.base.junit.AbstractJsfTestCase;
|
||||
import org.apache.myfaces.test.mock.MockApplicationFactory;
|
||||
import org.apache.myfaces.test.mock.MockExternalContext;
|
||||
import org.apache.myfaces.test.mock.MockHttpServletRequest;
|
||||
@@ -30,6 +21,15 @@ import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
|
||||
import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
|
||||
import org.apache.myfaces.test.mock.visit.MockVisitContextFactory;
|
||||
|
||||
import jakarta.faces.FactoryFinder;
|
||||
import jakarta.faces.application.Application;
|
||||
import jakarta.faces.application.ApplicationFactory;
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
import jakarta.faces.context.FacesContextFactory;
|
||||
import jakarta.faces.lifecycle.LifecycleFactory;
|
||||
import jakarta.faces.render.RenderKitFactory;
|
||||
|
||||
/**
|
||||
* Helper for using the mock JSF environment provided by shale-test inside unit tests that do not extend
|
||||
* {@link AbstractJsfTestCase}
|
||||
@@ -106,7 +106,7 @@ public class JSFMockHelper {
|
||||
private ClassLoader threadContextClassLoader;
|
||||
|
||||
public JSFMock() {
|
||||
super("JSFMock");
|
||||
super();
|
||||
}
|
||||
|
||||
FacesContext facesContext;
|
||||
|
||||
@@ -8,20 +8,11 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.application.ViewHandler;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.event.PhaseListener;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
|
||||
import org.apache.el.ExpressionFactoryImpl;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.apache.el.ExpressionFactoryImpl;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
import org.springframework.binding.expression.support.FluentParserContext;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -35,6 +26,15 @@ import org.springframework.webflow.execution.View;
|
||||
import org.springframework.webflow.expression.el.WebFlowELExpressionParser;
|
||||
import org.springframework.webflow.test.MockExternalContext;
|
||||
|
||||
import jakarta.faces.FacesException;
|
||||
import jakarta.faces.application.ViewHandler;
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
import jakarta.faces.event.PhaseEvent;
|
||||
import jakarta.faces.event.PhaseId;
|
||||
import jakarta.faces.event.PhaseListener;
|
||||
import jakarta.faces.lifecycle.Lifecycle;
|
||||
|
||||
public class JsfFinalResponseActionTests {
|
||||
|
||||
private static final String VIEW_ID = "/testView.xhtml";
|
||||
@@ -47,10 +47,6 @@ public class JsfFinalResponseActionTests {
|
||||
|
||||
private final ViewHandler viewHandler = new NoRenderViewHandler();
|
||||
|
||||
private TestLifecycle lifecycle;
|
||||
|
||||
private PhaseListener trackingListener;
|
||||
|
||||
ExpressionParser parser = new WebFlowELExpressionParser(new ExpressionFactoryImpl());
|
||||
|
||||
@BeforeEach
|
||||
@@ -68,13 +64,13 @@ public class JsfFinalResponseActionTests {
|
||||
|
||||
this.jsfMock.setUp();
|
||||
|
||||
this.trackingListener = new TrackingPhaseListener();
|
||||
this.jsfMock.lifecycle().addPhaseListener(this.trackingListener);
|
||||
PhaseListener trackingListener = new TrackingPhaseListener();
|
||||
this.jsfMock.lifecycle().addPhaseListener(trackingListener);
|
||||
this.jsfMock.facesContext().setViewRoot(null);
|
||||
this.jsfMock.facesContext().getApplication().setViewHandler(this.viewHandler);
|
||||
this.lifecycle = new TestLifecycle(this.jsfMock.lifecycle());
|
||||
TestLifecycle lifecycle = new TestLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression("#{'" + VIEW_ID + "'}", new FluentParserContext()
|
||||
.template().evaluate(RequestContext.class).expectResult(String.class)), this.lifecycle);
|
||||
.template().evaluate(RequestContext.class).expectResult(String.class)), lifecycle);
|
||||
RequestContextHolder.setRequestContext(this.context);
|
||||
MockExternalContext ext = new MockExternalContext();
|
||||
ext.setNativeContext(new MockServletContext());
|
||||
@@ -97,7 +93,7 @@ public class JsfFinalResponseActionTests {
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(false);
|
||||
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
EasyMock.replay(this.context);
|
||||
|
||||
View view = this.factory.getView(this.context);
|
||||
((JsfView) view).getViewRoot().setTransient(true);
|
||||
@@ -107,7 +103,7 @@ public class JsfFinalResponseActionTests {
|
||||
assertTrue(((NoRenderViewHandler) this.viewHandler).rendered);
|
||||
}
|
||||
|
||||
private class TestLifecycle extends FlowLifecycle {
|
||||
private static class TestLifecycle extends FlowLifecycle {
|
||||
|
||||
boolean executed = false;
|
||||
|
||||
@@ -123,7 +119,7 @@ public class JsfFinalResponseActionTests {
|
||||
|
||||
}
|
||||
|
||||
private class TrackingPhaseListener implements PhaseListener {
|
||||
private static class TrackingPhaseListener implements PhaseListener {
|
||||
|
||||
private final List<String> phaseCallbacks = new ArrayList<>();
|
||||
|
||||
@@ -146,10 +142,10 @@ public class JsfFinalResponseActionTests {
|
||||
}
|
||||
}
|
||||
|
||||
private class NoRenderViewHandler extends MockViewHandler {
|
||||
private static class NoRenderViewHandler extends MockViewHandler {
|
||||
boolean rendered = false;
|
||||
|
||||
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
|
||||
public void renderView(FacesContext context, UIViewRoot viewToRender) throws FacesException {
|
||||
this.rendered = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,27 +4,27 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.application.ApplicationFactory;
|
||||
import javax.faces.context.FacesContextFactory;
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.event.PhaseListener;
|
||||
import javax.faces.lifecycle.LifecycleFactory;
|
||||
import javax.faces.render.RenderKitFactory;
|
||||
|
||||
import org.apache.myfaces.test.base.AbstractJsfTestCase;
|
||||
import org.apache.myfaces.test.base.junit.AbstractJsfTestCase;
|
||||
import org.apache.myfaces.test.mock.MockApplicationFactory;
|
||||
import org.apache.myfaces.test.mock.MockFacesContext20;
|
||||
import org.apache.myfaces.test.mock.MockFacesContext;
|
||||
import org.apache.myfaces.test.mock.MockFacesContextFactory;
|
||||
import org.apache.myfaces.test.mock.MockRenderKitFactory;
|
||||
import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
|
||||
import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import jakarta.faces.application.ApplicationFactory;
|
||||
import jakarta.faces.context.FacesContextFactory;
|
||||
import jakarta.faces.event.PhaseEvent;
|
||||
import jakarta.faces.event.PhaseId;
|
||||
import jakarta.faces.event.PhaseListener;
|
||||
import jakarta.faces.lifecycle.LifecycleFactory;
|
||||
import jakarta.faces.render.RenderKitFactory;
|
||||
|
||||
public class JsfUtilsTests extends AbstractJsfTestCase {
|
||||
|
||||
public JsfUtilsTests(String name) {
|
||||
super(name);
|
||||
public JsfUtilsTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -37,7 +37,7 @@ public class JsfUtilsTests extends AbstractJsfTestCase {
|
||||
lifecycle.addPhaseListener(listener2);
|
||||
PhaseListener listener3 = new OrderVerifyingPhaseListener(null, list);
|
||||
lifecycle.addPhaseListener(listener3);
|
||||
JsfUtils.notifyBeforeListeners(PhaseId.ANY_PHASE, lifecycle, new MockFacesContext20());
|
||||
JsfUtils.notifyBeforeListeners(PhaseId.ANY_PHASE, lifecycle, new MockFacesContext());
|
||||
assertEquals(listener1, list.get(0));
|
||||
assertEquals(listener2, list.get(1));
|
||||
assertEquals(listener3, list.get(2));
|
||||
@@ -53,7 +53,7 @@ public class JsfUtilsTests extends AbstractJsfTestCase {
|
||||
lifecycle.addPhaseListener(listener2);
|
||||
PhaseListener listener3 = new OrderVerifyingPhaseListener(list, null);
|
||||
lifecycle.addPhaseListener(listener3);
|
||||
JsfUtils.notifyAfterListeners(PhaseId.ANY_PHASE, lifecycle, new MockFacesContext20());
|
||||
JsfUtils.notifyAfterListeners(PhaseId.ANY_PHASE, lifecycle, new MockFacesContext());
|
||||
assertEquals(listener3, list.get(0));
|
||||
assertEquals(listener2, list.get(1));
|
||||
assertEquals(listener1, list.get(2));
|
||||
@@ -78,7 +78,7 @@ public class JsfUtilsTests extends AbstractJsfTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private class OrderVerifyingPhaseListener implements PhaseListener {
|
||||
private static class OrderVerifyingPhaseListener implements PhaseListener {
|
||||
|
||||
private final List<OrderVerifyingPhaseListener> afterPhaseList;
|
||||
private final List<OrderVerifyingPhaseListener> beforePhaseList;
|
||||
|
||||
@@ -10,23 +10,6 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.application.ViewHandler;
|
||||
import javax.faces.component.UIInput;
|
||||
import javax.faces.component.UIOutput;
|
||||
import javax.faces.component.UIPanel;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.AbortProcessingException;
|
||||
import javax.faces.event.ComponentSystemEvent;
|
||||
import javax.faces.event.ExceptionQueuedEvent;
|
||||
import javax.faces.event.ExceptionQueuedEventContext;
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.event.PhaseListener;
|
||||
import javax.faces.event.PostRestoreStateEvent;
|
||||
import javax.faces.event.SystemEvent;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
|
||||
import org.apache.el.ExpressionFactoryImpl;
|
||||
import org.apache.myfaces.test.mock.MockApplication20;
|
||||
@@ -51,6 +34,24 @@ import org.springframework.webflow.execution.ViewFactory;
|
||||
import org.springframework.webflow.expression.el.WebFlowELExpressionParser;
|
||||
import org.springframework.webflow.test.MockExternalContext;
|
||||
|
||||
import jakarta.faces.FacesException;
|
||||
import jakarta.faces.application.ViewHandler;
|
||||
import jakarta.faces.component.UIInput;
|
||||
import jakarta.faces.component.UIOutput;
|
||||
import jakarta.faces.component.UIPanel;
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
import jakarta.faces.event.AbortProcessingException;
|
||||
import jakarta.faces.event.ComponentSystemEvent;
|
||||
import jakarta.faces.event.ExceptionQueuedEvent;
|
||||
import jakarta.faces.event.ExceptionQueuedEventContext;
|
||||
import jakarta.faces.event.PhaseEvent;
|
||||
import jakarta.faces.event.PhaseId;
|
||||
import jakarta.faces.event.PhaseListener;
|
||||
import jakarta.faces.event.PostRestoreStateEvent;
|
||||
import jakarta.faces.event.SystemEvent;
|
||||
import jakarta.faces.lifecycle.Lifecycle;
|
||||
|
||||
public class JsfViewFactoryTests {
|
||||
|
||||
private static final String VIEW_ID = "/testView.xhtml";
|
||||
@@ -184,10 +185,15 @@ public class JsfViewFactoryTests {
|
||||
UIPanel panel = new UIPanel();
|
||||
panel.setId("panel1");
|
||||
UIOutput output = new UIOutput();
|
||||
output.setValueBinding("binding", this.jsfMock.facesContext().getApplication().createValueBinding("#{myBean.output}"));
|
||||
FacesContext facesContext = this.jsfMock.facesContext();
|
||||
output.setValueExpression("binding",
|
||||
facesContext.getApplication().getExpressionFactory().createValueExpression(
|
||||
facesContext.getELContext(), "#{myBean.output}", UIOutput.class));
|
||||
output.setId("output1");
|
||||
UIInput input = new UIInput();
|
||||
input.setValueBinding("binding", this.jsfMock.facesContext().getApplication().createValueBinding("#{myBean.input}"));
|
||||
input.setValueExpression("binding",
|
||||
facesContext.getApplication().getExpressionFactory().createValueExpression(
|
||||
facesContext.getELContext(), "#{myBean.input}", UIInput.class));
|
||||
input.setId("input1");
|
||||
|
||||
existingRoot.getChildren().add(panel);
|
||||
@@ -245,7 +251,7 @@ public class JsfViewFactoryTests {
|
||||
|
||||
assertNotNull(restoredView, "A View was not restored");
|
||||
assertTrue(restoredView instanceof JsfView, "A JsfView was expected");
|
||||
assertTrue(((JsfView) restoredView).getViewRoot() != null, "An ViewRoot was not set");
|
||||
assertNotNull(((JsfView) restoredView).getViewRoot(), "An ViewRoot was not set");
|
||||
assertEquals(VIEW_ID, ((JsfView) restoredView).getViewRoot().getViewId(), "View name did not match");
|
||||
assertFalse(restoredView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
assertTrue(existingRoot.isPostRestoreStateEventSeen(), "The PostRestoreViewEvent was not seen");
|
||||
@@ -302,7 +308,7 @@ public class JsfViewFactoryTests {
|
||||
application.getExceptionQueuedEventContext().getException(), "Expected same exception");
|
||||
}
|
||||
|
||||
private class NoExecutionLifecycle extends FlowLifecycle {
|
||||
private static class NoExecutionLifecycle extends FlowLifecycle {
|
||||
|
||||
public NoExecutionLifecycle(Lifecycle delegate) {
|
||||
super(delegate);
|
||||
@@ -313,7 +319,7 @@ public class JsfViewFactoryTests {
|
||||
}
|
||||
}
|
||||
|
||||
private class TrackingPhaseListener implements PhaseListener {
|
||||
private static class TrackingPhaseListener implements PhaseListener {
|
||||
|
||||
private final List<String> phaseCallbacks = new ArrayList<>();
|
||||
|
||||
@@ -336,7 +342,7 @@ public class JsfViewFactoryTests {
|
||||
}
|
||||
}
|
||||
|
||||
private class NormalViewState implements StateDefinition {
|
||||
private static class NormalViewState implements StateDefinition {
|
||||
|
||||
public boolean isViewState() {
|
||||
return true;
|
||||
@@ -363,7 +369,7 @@ public class JsfViewFactoryTests {
|
||||
}
|
||||
}
|
||||
|
||||
protected class TestBean {
|
||||
public static class TestBean {
|
||||
|
||||
UIOutput output;
|
||||
UIInput input;
|
||||
|
||||
@@ -6,14 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.component.UIForm;
|
||||
import javax.faces.component.UIInput;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.component.html.HtmlForm;
|
||||
import javax.faces.component.html.HtmlInputText;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
|
||||
import org.apache.myfaces.test.mock.MockResponseWriter;
|
||||
import org.easymock.EasyMock;
|
||||
@@ -28,6 +20,15 @@ import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.test.MockExternalContext;
|
||||
import org.springframework.webflow.test.MockParameterMap;
|
||||
|
||||
import jakarta.faces.FacesException;
|
||||
import jakarta.faces.component.UIForm;
|
||||
import jakarta.faces.component.UIInput;
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.component.html.HtmlForm;
|
||||
import jakarta.faces.component.html.HtmlInputText;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
import jakarta.faces.lifecycle.Lifecycle;
|
||||
|
||||
public class JsfViewTests {
|
||||
|
||||
private static final String VIEW_ID = "testView.xhtml";
|
||||
@@ -44,9 +45,7 @@ public class JsfViewTests {
|
||||
|
||||
private final RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
private final FlowExecutionContext flowExecutionContext = EasyMock.createMock(FlowExecutionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
private final MutableAttributeMap<Object> flashScope = EasyMock.createMock(MutableAttributeMap.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
private final MutableAttributeMap<Object> flowMap = EasyMock.createMock(MutableAttributeMap.class);
|
||||
|
||||
private final FlowExecutionKey key = new FlowExecutionKey() {
|
||||
@@ -130,7 +129,7 @@ public class JsfViewTests {
|
||||
|
||||
try {
|
||||
this.view.render();
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +144,7 @@ public class JsfViewTests {
|
||||
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
.andStubReturn(null);
|
||||
|
||||
Lifecycle lifecycle = new NoEventLifecycle(this.jsfMock.lifecycle());
|
||||
NoEventLifecycle lifecycle = new NoEventLifecycle(this.jsfMock.lifecycle());
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
@@ -157,7 +156,7 @@ public class JsfViewTests {
|
||||
restoredView.processUserEvent();
|
||||
|
||||
assertFalse(restoredView.hasFlowEvent(), "An unexpected event was signaled,");
|
||||
assertTrue(((NoEventLifecycle) lifecycle).executed, "The lifecycle should have been invoked");
|
||||
assertTrue(lifecycle.executed, "The lifecycle should have been invoked");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +170,7 @@ public class JsfViewTests {
|
||||
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
.andStubReturn(null);
|
||||
|
||||
Lifecycle lifecycle = new EventSignalingLifecycle(this.jsfMock.lifecycle());
|
||||
EventSignalingLifecycle lifecycle = new EventSignalingLifecycle(this.jsfMock.lifecycle());
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
@@ -184,7 +183,7 @@ public class JsfViewTests {
|
||||
|
||||
assertTrue(restoredView.hasFlowEvent(), "No event was signaled,");
|
||||
assertEquals(this.event, restoredView.getFlowEvent().getId(), "Event should be " + this.event);
|
||||
assertTrue(((EventSignalingLifecycle) lifecycle).executed, "The lifecycle should have been invoked");
|
||||
assertTrue(lifecycle.executed, "The lifecycle should have been invoked");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,7 +204,7 @@ public class JsfViewTests {
|
||||
public final void testUserEventQueued_FormSubmitted() {
|
||||
|
||||
this.jsfMock.request().addParameter("execution", "e1s1");
|
||||
this.jsfMock.request().addParameter("javax.faces.ViewState", "e1s1");
|
||||
this.jsfMock.request().addParameter("jakarta.faces.ViewState", "e1s1");
|
||||
|
||||
EasyMock.replay(this.context, this.flowExecutionContext, this.flowMap, this.flashScope);
|
||||
|
||||
@@ -214,13 +213,13 @@ public class JsfViewTests {
|
||||
assertTrue(createdView.userEventQueued(), "User event should be queued");
|
||||
}
|
||||
|
||||
private class ExceptionalViewHandler extends MockViewHandler {
|
||||
private static class ExceptionalViewHandler extends MockViewHandler {
|
||||
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
|
||||
throw new IOException("Rendering blew up");
|
||||
}
|
||||
}
|
||||
|
||||
private class NoEventLifecycle extends FlowLifecycle {
|
||||
private static class NoEventLifecycle extends FlowLifecycle {
|
||||
|
||||
boolean executed = false;
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ package org.springframework.faces.webflow;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.FactoryFinder;
|
||||
import javax.faces.application.Application;
|
||||
import javax.faces.application.ApplicationFactory;
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
|
||||
import org.apache.myfaces.test.mock.MockFacesContext20;
|
||||
|
||||
import jakarta.faces.FactoryFinder;
|
||||
import jakarta.faces.application.Application;
|
||||
import jakarta.faces.application.ApplicationFactory;
|
||||
import jakarta.faces.context.ExternalContext;
|
||||
import jakarta.faces.lifecycle.Lifecycle;
|
||||
|
||||
public class MockBaseFacesContext extends MockFacesContext20 {
|
||||
|
||||
private Application application;
|
||||
@@ -30,6 +30,11 @@ public class MockBaseFacesContext extends MockFacesContext20 {
|
||||
return super.getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lifecycle getLifecycle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Application getApplication() {
|
||||
if (this.application == null) {
|
||||
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.FacesContextFactory;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.myfaces.test.mock.MockExternalContext20;
|
||||
import org.apache.myfaces.test.mock.MockExternalContext;
|
||||
import org.apache.myfaces.test.mock.MockHttpServletResponse;
|
||||
|
||||
import jakarta.faces.FacesException;
|
||||
import jakarta.faces.context.ExternalContext;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
import jakarta.faces.context.FacesContextFactory;
|
||||
import jakarta.faces.lifecycle.Lifecycle;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
public class MockBaseFacesContextFactory extends FacesContextFactory {
|
||||
|
||||
public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle)
|
||||
@@ -22,7 +22,7 @@ public class MockBaseFacesContextFactory extends FacesContextFactory {
|
||||
return FacesContext.getCurrentInstance();
|
||||
} else {
|
||||
|
||||
ExternalContext ext = new MockExternalContext20((ServletContext) context, (HttpServletRequest) request,
|
||||
ExternalContext ext = new MockExternalContext((ServletContext) context, (HttpServletRequest) request,
|
||||
(HttpServletResponse) response) {
|
||||
|
||||
public void setResponseBufferSize(int size) {
|
||||
@@ -33,6 +33,10 @@ public class MockBaseFacesContextFactory extends FacesContextFactory {
|
||||
((MockHttpServletResponse) getResponse()).setContentLength(length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
}
|
||||
|
||||
public void setResponseContentType(String contentType) {
|
||||
((MockHttpServletResponse) getResponse()).setContentType(contentType);
|
||||
}
|
||||
|
||||
@@ -17,15 +17,16 @@ package org.springframework.faces.webflow;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.faces.application.Application;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.application.FacesMessage.Severity;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseStream;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.render.RenderKit;
|
||||
import jakarta.faces.application.Application;
|
||||
import jakarta.faces.application.FacesMessage;
|
||||
import jakarta.faces.application.FacesMessage.Severity;
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.context.ExternalContext;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
import jakarta.faces.context.ResponseStream;
|
||||
import jakarta.faces.context.ResponseWriter;
|
||||
import jakarta.faces.lifecycle.Lifecycle;
|
||||
import jakarta.faces.render.RenderKit;
|
||||
|
||||
/**
|
||||
* Mock implementation of the <code>FacesContext</code> class to facilitate standalone Action unit tests.
|
||||
@@ -35,7 +36,7 @@ import javax.faces.render.RenderKit;
|
||||
* Fowler's</a> reasoning. This class is called <i>Mock</i>FacesContext to be consistent with the naming convention in
|
||||
* the rest of the Spring framework (e.g. MockHttpServletRequest, ...).
|
||||
*
|
||||
* @see javax.faces.context.FacesContext
|
||||
* @see jakarta.faces.context.FacesContext
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@@ -62,6 +63,11 @@ public class MockFacesContext extends FacesContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lifecycle getLifecycle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExternalContext getExternalContext() {
|
||||
return this.externalContext;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.security.Principal;
|
||||
@@ -27,7 +26,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.faces.context.ExternalContext;
|
||||
import jakarta.faces.context.ExternalContext;
|
||||
|
||||
public class MockJsfExternalContext extends ExternalContext {
|
||||
|
||||
@@ -39,7 +38,7 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
|
||||
private Map<String, String> requestParameterMap = Collections.emptyMap();
|
||||
|
||||
public void dispatch(String arg0) throws IOException {
|
||||
public void dispatch(String arg0) {
|
||||
}
|
||||
|
||||
public String encodeActionURL(String arg0) {
|
||||
@@ -54,6 +53,11 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeWebsocketURL(String url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, Object> getApplicationMap() {
|
||||
return this.applicationMap;
|
||||
}
|
||||
@@ -70,7 +74,7 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, Object> getInitParameterMap() {
|
||||
public Map<String, String> getInitParameterMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -184,6 +188,11 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
public void log(String arg0, Throwable arg1) {
|
||||
}
|
||||
|
||||
public void redirect(String arg0) throws IOException {
|
||||
public void redirect(String arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.faces.webflow;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.application.ViewHandler;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import jakarta.faces.FacesException;
|
||||
import jakarta.faces.application.ViewHandler;
|
||||
import jakarta.faces.component.UIViewRoot;
|
||||
import jakarta.faces.context.FacesContext;
|
||||
|
||||
public class MockViewHandler extends ViewHandler {
|
||||
private UIViewRoot createViewRoot;
|
||||
@@ -68,6 +68,11 @@ public class MockViewHandler extends ViewHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWebsocketURL(FacesContext context, String channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Really simple implementation to exercise rendering and state saving
|
||||
*/
|
||||
@@ -82,4 +87,4 @@ public class MockViewHandler extends ViewHandler {
|
||||
|
||||
public void writeState(FacesContext context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user