Fixing broken tests.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
|
||||
import org.springframework.faces.ui.AjaxViewRoot;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
|
||||
public class AjaxJsfView extends JsfView {
|
||||
|
||||
public AjaxJsfView(UIViewRoot viewRoot, Lifecycle facesLifecycle, RequestContext context) {
|
||||
super(new AjaxViewRoot(viewRoot), facesLifecycle, context);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import javax.faces.application.NavigationHandler;
|
||||
import javax.faces.component.ActionSource2;
|
||||
import javax.faces.component.ActionSource;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.AbortProcessingException;
|
||||
import javax.faces.event.ActionEvent;
|
||||
@@ -43,13 +43,13 @@ public class FlowActionListener implements ActionListener {
|
||||
|
||||
public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
ActionSource2 source = (ActionSource2) actionEvent.getSource();
|
||||
ActionSource source = (ActionSource) actionEvent.getSource();
|
||||
String result = null;
|
||||
if (source.getActionExpression() != null) {
|
||||
if (source.getAction() != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Invoking action expression " + source.getActionExpression());
|
||||
logger.debug("Invoking action " + source.getAction());
|
||||
}
|
||||
result = (String) source.getActionExpression().invoke(context.getELContext(), null);
|
||||
result = (String) source.getAction().invoke(context, null);
|
||||
}
|
||||
if (StringUtils.hasText(result)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.binding.message.Severity;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
/**
|
||||
* Custom {@link FacesContext} implementation that delegates all standard FacesContext messaging functionality to a
|
||||
@@ -196,11 +195,11 @@ public class FlowFacesContext extends FacesContext {
|
||||
private int currentIndex = -1;
|
||||
|
||||
protected FacesMessageIterator() {
|
||||
this.messages = RequestContextHolder.getRequestContext().getMessageContext().getMessages();
|
||||
this.messages = context.getMessageContext().getMessages();
|
||||
}
|
||||
|
||||
protected FacesMessageIterator(String clientId) {
|
||||
this.messages = RequestContextHolder.getRequestContext().getMessageContext().getMessages(clientId);
|
||||
this.messages = context.getMessageContext().getMessages(clientId);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
@@ -237,7 +236,7 @@ public class FlowFacesContext extends FacesContext {
|
||||
int currentIndex = -1;
|
||||
|
||||
protected ClientIdIterator() {
|
||||
this.messages = RequestContextHolder.getRequestContext().getMessageContext().getMessages();
|
||||
this.messages = context.getMessageContext().getMessages();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
|
||||
@@ -26,7 +26,6 @@ import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.FacesContextFactory;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
import javax.faces.lifecycle.LifecycleFactory;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -54,50 +53,70 @@ public class JsfViewFactory implements ViewFactory {
|
||||
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
public JsfViewFactory(Expression viewExpr, ResourceLoader resourceLoader) {
|
||||
private final Lifecycle lifecycle;
|
||||
|
||||
public JsfViewFactory(Expression viewExpr, ResourceLoader resourceLoader, Lifecycle lifecycle) {
|
||||
this.viewExpr = viewExpr;
|
||||
this.resourceLoader = resourceLoader;
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public View getView(RequestContext context) {
|
||||
Lifecycle lifecycle = createFlowFacesLifecycle();
|
||||
|
||||
FacesContext facesContext = createFlowFacesContext(context, lifecycle);
|
||||
try {
|
||||
boolean restored = false;
|
||||
|
||||
if (!facesContext.getRenderResponse()) {
|
||||
JsfUtils.notifyBeforeListeners(PhaseId.RESTORE_VIEW, lifecycle, facesContext);
|
||||
}
|
||||
|
||||
JsfView view;
|
||||
String viewName = resolveViewName(context);
|
||||
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
|
||||
viewHandler.initView(facesContext);
|
||||
UIViewRoot viewRoot = viewHandler.restoreView(facesContext, viewName);
|
||||
if (viewRoot != null) {
|
||||
|
||||
if (viewExists(facesContext, viewName)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("View root restored for '" + viewName + "'");
|
||||
logger.debug("Existing view root found for '" + viewName + "'");
|
||||
}
|
||||
facesContext.setViewRoot(viewRoot);
|
||||
processComponentBinding(facesContext, viewRoot);
|
||||
JsfUtils.notifyAfterListeners(PhaseId.RESTORE_VIEW, lifecycle, facesContext);
|
||||
lifecycle.execute(facesContext);
|
||||
return new JsfView(viewRoot, lifecycle, context);
|
||||
view = createJsfView(facesContext.getViewRoot(), lifecycle, context);
|
||||
restored = true;
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Creating view root for '" + viewName + "'");
|
||||
UIViewRoot viewRoot = viewHandler.restoreView(facesContext, viewName);
|
||||
if (viewRoot != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("View root restored for '" + viewName + "'");
|
||||
}
|
||||
view = createJsfView(viewRoot, lifecycle, context);
|
||||
facesContext.setViewRoot(viewRoot);
|
||||
processComponentBinding(facesContext, viewRoot);
|
||||
restored = true;
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Creating view root for '" + viewName + "'");
|
||||
}
|
||||
view = createJsfView(viewHandler.createView(facesContext, viewName), lifecycle, context);
|
||||
restored = false;
|
||||
}
|
||||
viewRoot = viewHandler.createView(facesContext, viewName);
|
||||
facesContext.setViewRoot(viewRoot);
|
||||
JsfUtils.notifyAfterListeners(PhaseId.RESTORE_VIEW, lifecycle, facesContext);
|
||||
return new JsfView(viewRoot, lifecycle, context);
|
||||
}
|
||||
|
||||
if (!facesContext.getRenderResponse()) {
|
||||
JsfUtils.notifyAfterListeners(PhaseId.RESTORE_VIEW, lifecycle, facesContext);
|
||||
}
|
||||
|
||||
if (restored && !facesContext.getResponseComplete() && !facesContext.getRenderResponse()) {
|
||||
lifecycle.execute(facesContext);
|
||||
facesContext.renderResponse();
|
||||
}
|
||||
|
||||
return view;
|
||||
} finally {
|
||||
facesContext.release();
|
||||
}
|
||||
}
|
||||
|
||||
private Lifecycle createFlowFacesLifecycle() {
|
||||
LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
|
||||
.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
|
||||
Lifecycle defaultLifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
|
||||
return new FlowLifecycle(defaultLifecycle);
|
||||
private JsfView createJsfView(UIViewRoot root, Lifecycle lifecycle, RequestContext context) {
|
||||
return new JsfView(root, lifecycle, context);
|
||||
}
|
||||
|
||||
private FacesContext createFlowFacesContext(RequestContext context, Lifecycle lifecycle) {
|
||||
@@ -119,13 +138,23 @@ public class JsfViewFactory implements ViewFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean viewExists(FacesContext facesContext, String viewId) {
|
||||
if (facesContext.getViewRoot() != null && facesContext.getViewRoot().getViewId().equals(viewId)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void processComponentBinding(FacesContext context, UIComponent component) {
|
||||
ValueExpression binding = component.getValueExpression("binding");
|
||||
if (binding != null) {
|
||||
binding.setValue(context.getELContext(), component);
|
||||
}
|
||||
for (Iterator<UIComponent> iter = component.getFacetsAndChildren(); iter.hasNext();) {
|
||||
processComponentBinding(context, iter.next());
|
||||
|
||||
Iterator i = component.getChildren().iterator();
|
||||
while (i.hasNext()) {
|
||||
UIComponent child = (UIComponent) i.next();
|
||||
processComponentBinding(context, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import javax.faces.FactoryFinder;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
import javax.faces.lifecycle.LifecycleFactory;
|
||||
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.webflow.engine.builder.ViewFactoryCreator;
|
||||
@@ -28,12 +32,25 @@ import org.springframework.webflow.execution.ViewFactory;
|
||||
*/
|
||||
public class JsfViewFactoryCreator implements ViewFactoryCreator {
|
||||
|
||||
private Lifecycle lifecycle;
|
||||
|
||||
public JsfViewFactoryCreator() {
|
||||
lifecycle = createFlowFacesLifecycle();
|
||||
}
|
||||
|
||||
public Action createFinalResponseAction(Expression viewName, ResourceLoader resourceLoader) {
|
||||
return new JsfFinalResponseAction(new JsfViewFactory(viewName, resourceLoader));
|
||||
return new JsfFinalResponseAction(new JsfViewFactory(viewName, resourceLoader, lifecycle));
|
||||
}
|
||||
|
||||
public ViewFactory createViewFactory(Expression viewName, ResourceLoader resourceLoader) {
|
||||
return new JsfViewFactory(viewName, resourceLoader);
|
||||
return new JsfViewFactory(viewName, resourceLoader, lifecycle);
|
||||
}
|
||||
|
||||
private Lifecycle createFlowFacesLifecycle() {
|
||||
LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
|
||||
.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
|
||||
Lifecycle defaultLifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
|
||||
return new FlowLifecycle(defaultLifecycle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,303 +0,0 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.el.CompositeELResolver;
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.el.ValueBinding;
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.event.PhaseListener;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.jboss.el.ExpressionFactoryImpl;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
import org.springframework.binding.method.MethodSignature;
|
||||
import org.springframework.binding.method.Parameter;
|
||||
import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
import org.springframework.webflow.action.AbstractBeanInvokingAction;
|
||||
import org.springframework.webflow.action.EvaluateAction;
|
||||
import org.springframework.webflow.action.SetAction;
|
||||
import org.springframework.webflow.context.ExternalContext;
|
||||
import org.springframework.webflow.context.ExternalContextHolder;
|
||||
import org.springframework.webflow.context.servlet.ServletExternalContext;
|
||||
import org.springframework.webflow.core.expression.el.RequestContextELResolver;
|
||||
import org.springframework.webflow.core.expression.el.ScopeSearchingELResolver;
|
||||
import org.springframework.webflow.core.expression.el.WebFlowELExpressionParser;
|
||||
import org.springframework.webflow.engine.ActionState;
|
||||
import org.springframework.webflow.engine.EndState;
|
||||
import org.springframework.webflow.engine.Flow;
|
||||
import org.springframework.webflow.engine.TargetStateResolver;
|
||||
import org.springframework.webflow.engine.Transition;
|
||||
import org.springframework.webflow.engine.TransitionCriteria;
|
||||
import org.springframework.webflow.engine.ViewState;
|
||||
import org.springframework.webflow.engine.impl.FlowExecutionImplFactory;
|
||||
import org.springframework.webflow.engine.support.DefaultTargetStateResolver;
|
||||
import org.springframework.webflow.engine.support.EventIdTransitionCriteria;
|
||||
import org.springframework.webflow.execution.Action;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.FlowExecution;
|
||||
import org.springframework.webflow.execution.FlowExecutionKey;
|
||||
import org.springframework.webflow.execution.FlowExecutionKeyFactory;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.ScopeType;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class JSFFlowExecutionTests extends TestCase {
|
||||
|
||||
JSFMockHelper jsf;
|
||||
JSFManagedBean jsfBean;
|
||||
JSFModel jsfModel;
|
||||
MockViewHandler viewHandler;
|
||||
MockService service;
|
||||
GenericWebApplicationContext ctx;
|
||||
TrackingPhaseListener trackingListener;
|
||||
|
||||
Flow flow;
|
||||
FlowExecution execution;
|
||||
|
||||
ExpressionParser parser = new WebFlowELExpressionParser(new ExpressionFactoryImpl());
|
||||
|
||||
/**
|
||||
* TODO - The management of the JSF mocks has gotten rather convoluted now that we are tearing down and rebuilding
|
||||
* the FacesContext multiple times per request. Consider enhancing JSFMockHelper to manage things more appropriately
|
||||
* for SWF usage.
|
||||
*/
|
||||
protected void setUp() throws Exception {
|
||||
service = EasyMock.createMock(MockService.class);
|
||||
|
||||
trackingListener = new TrackingPhaseListener();
|
||||
jsfRequestSetup();
|
||||
|
||||
flow = Flow.create("jsf-flow", null);
|
||||
|
||||
ViewState view1 = new ViewState(flow, "viewState1", new JsfViewFactory(parser.parseExpression("/view1",
|
||||
RequestContext.class, String.class, null), null));
|
||||
view1.getTransitionSet().add(new Transition(on("event1"), to("doSomething")));
|
||||
view1.getTransitionSet().add(new Transition(on("event2"), to("evalSomething")));
|
||||
|
||||
ActionState doSomething = new ActionState(flow, "doSomething");
|
||||
doSomething.getActionList().add(
|
||||
new StubBeanAction(new MethodSignature("doSomething", new Parameter(String.class, parser
|
||||
.parseExpression("#{JsfBean.prop1}", RequestContext.class, String.class, null)))));
|
||||
doSomething.getTransitionSet().add(new Transition(on("success"), to("viewState2")));
|
||||
|
||||
ActionState evalSomething = new ActionState(flow, "evalSomething");
|
||||
evalSomething.getEntryActionList().add(
|
||||
new SetAction(parser.parseExpression("#{requestContext.flowScope.jsfModel}", RequestContext.class,
|
||||
String.class, null), ScopeType.FLOW, parser.parseExpression("#{'foo'}", RequestContext.class,
|
||||
String.class, null)));
|
||||
evalSomething.getActionList().add(
|
||||
new EvaluateAction(parser.parseExpression("#{JsfBean.addValue(jsfModel)}", RequestContext.class,
|
||||
String.class, null)));
|
||||
evalSomething.getTransitionSet().add(new Transition(on("success"), to("viewState2")));
|
||||
|
||||
ViewState viewState2 = new ViewState(flow, "viewState2", new JsfViewFactory(parser.parseExpression("/view2",
|
||||
RequestContext.class, String.class, null), null));
|
||||
viewState2.getEntryActionList().add(new ViewState2SetupAction());
|
||||
viewState2.getTransitionSet().add(new Transition(on("event1"), to("endState1")));
|
||||
|
||||
new EndState(flow, "endState1");
|
||||
|
||||
FlowExecutionImplFactory factory = new FlowExecutionImplFactory();
|
||||
factory.setExecutionKeyFactory(new SimpleFlowExecutionKeyFactory());
|
||||
execution = factory.createFlowExecution(flow);
|
||||
}
|
||||
|
||||
private void jsfRequestSetup() throws Exception {
|
||||
jsf = new JSFMockHelper();
|
||||
jsf.tearDown();
|
||||
jsf.setUp();
|
||||
FacesContext flowContext = new FlowFacesContext(new MockRequestContext(), jsf.facesContext());
|
||||
org.apache.shale.test.mock.MockFacesContext.setCurrentInstance(flowContext);
|
||||
|
||||
viewHandler = new NoRenderViewHandler();
|
||||
jsf.application().setViewHandler(viewHandler);
|
||||
trackingListener.reset();
|
||||
jsf.lifecycle().addPhaseListener(trackingListener);
|
||||
|
||||
CompositeELResolver baseResolver = (CompositeELResolver) jsf.facesContext().getELContext().getELResolver();
|
||||
baseResolver.add(new RequestContextELResolver());
|
||||
baseResolver.add(new ScopeSearchingELResolver());
|
||||
|
||||
jsf.externalContext().getRequestMap().put("JsfBean", new JSFManagedBean());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsf.tearDown();
|
||||
}
|
||||
|
||||
public void testManagedBeanExpression() {
|
||||
ValueBinding vb = jsf.application().createValueBinding("#{JsfBean}");
|
||||
jsfBean = (JSFManagedBean) vb.getValue(jsf.facesContext());
|
||||
assertNotNull(jsfBean);
|
||||
}
|
||||
|
||||
/*
|
||||
* public void testBeanAction() throws Exception { startFlow();
|
||||
*
|
||||
* jsfRequestSetup();
|
||||
*
|
||||
* testManagedBeanExpression(); jsfBean.setProp1("arg"); service.doSomething(jsfBean.getProp1());
|
||||
* EasyMock.replay(new Object[] { service });
|
||||
*
|
||||
* jsf.externalContext().getRequestMap().put(JsfView.EVENT_KEY, "event1");
|
||||
*
|
||||
* UIViewRoot existingRoot = new UIViewRoot(); existingRoot.setViewId("view1");
|
||||
* viewHandler.setRestoreView(existingRoot);
|
||||
*
|
||||
* execution.resume(getExternalContext());
|
||||
*
|
||||
* EasyMock.verify(new Object[] { service });
|
||||
*
|
||||
* ViewState currentState = (ViewState) execution.getActiveSession().getState(); assertEquals("viewState2",
|
||||
* currentState.getId()); }
|
||||
*
|
||||
* public void testEvalAction() throws Exception { startFlow();
|
||||
*
|
||||
* jsfRequestSetup();
|
||||
*
|
||||
* testManagedBeanExpression();
|
||||
*
|
||||
* jsf.externalContext().getRequestMap().put(JsfView.EVENT_KEY, "event2");
|
||||
*
|
||||
* UIViewRoot existingRoot = new UIViewRoot(); existingRoot.setViewId("view1");
|
||||
* viewHandler.setRestoreView(existingRoot);
|
||||
*
|
||||
* execution.resume(getExternalContext());
|
||||
*
|
||||
* assertFalse(jsfBean.getValues().isEmpty()); String addedValue = jsfBean.getValues().get(0).toString();
|
||||
* assertEquals(addedValue, "foo");
|
||||
*
|
||||
* ViewState currentState = (ViewState) execution.getActiveSession().getState(); assertEquals("viewState2",
|
||||
* currentState.getId()); }
|
||||
*/
|
||||
private static TransitionCriteria on(String event) {
|
||||
return new EventIdTransitionCriteria(event);
|
||||
}
|
||||
|
||||
private static TargetStateResolver to(String stateId) {
|
||||
return new DefaultTargetStateResolver(stateId);
|
||||
}
|
||||
|
||||
private void startFlow() {
|
||||
UIViewRoot view = new UIViewRoot();
|
||||
view.setViewId("view1");
|
||||
viewHandler.setCreateView(view);
|
||||
execution.start(getExternalContext());
|
||||
}
|
||||
|
||||
private ExternalContext getExternalContext() {
|
||||
jsf.request().setPathElements("myApp", "", "/flow", null);
|
||||
ExternalContext ext = new ServletExternalContext(jsf.servletContext(), jsf.request(), jsf.response());
|
||||
ExternalContextHolder.setExternalContext(ext);
|
||||
return ext;
|
||||
}
|
||||
|
||||
private class TestLifecycle extends FlowLifecycle {
|
||||
|
||||
boolean executed = false;
|
||||
|
||||
public TestLifecycle(Lifecycle delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
public void execute(FacesContext context) throws FacesException {
|
||||
assertFalse("Lifecycle executed more than once", executed);
|
||||
super.execute(context);
|
||||
executed = true;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
executed = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class StubBeanAction extends AbstractBeanInvokingAction {
|
||||
|
||||
protected StubBeanAction(MethodSignature methodSignature) {
|
||||
super(methodSignature);
|
||||
}
|
||||
|
||||
protected Object getBean(RequestContext context) throws Exception {
|
||||
return service;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SimpleFlowExecutionKeyFactory implements FlowExecutionKeyFactory {
|
||||
public FlowExecutionKey getKey(FlowExecution execution) {
|
||||
return new FlowExecutionKey() {
|
||||
public String toString() {
|
||||
return "key";
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class NoRenderViewHandler extends MockViewHandler {
|
||||
|
||||
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
private class TrackingPhaseListener implements PhaseListener {
|
||||
|
||||
private List phaseCallbacks = new ArrayList();
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
String phaseCallback = "AFTER_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.", phaseCallbacks
|
||||
.contains(phaseCallback));
|
||||
phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
String phaseCallback = "BEFORE_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.", phaseCallbacks
|
||||
.contains(phaseCallback));
|
||||
phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public PhaseId getPhaseId() {
|
||||
return PhaseId.ANY_PHASE;
|
||||
}
|
||||
|
||||
public List getPhaseCallbacks() {
|
||||
return phaseCallbacks;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
phaseCallbacks.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ViewState2SetupAction implements Action {
|
||||
|
||||
public Event execute(RequestContext context) throws Exception {
|
||||
jsfRequestSetup();
|
||||
UIViewRoot newRoot = new UIViewRoot();
|
||||
newRoot.setViewId("view2");
|
||||
viewHandler.setCreateView(newRoot);
|
||||
return new Event(this, "success");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,8 +114,10 @@ public class JSFMockHelper {
|
||||
"org.apache.shale.test.mock.MockApplicationFactory");
|
||||
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
|
||||
"org.springframework.faces.webflow.MockBaseFacesContextFactory");
|
||||
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
|
||||
"org.apache.shale.test.mock.MockFacesContextFactory");
|
||||
/*
|
||||
* FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
|
||||
* "org.apache.shale.test.mock.MockFacesContextFactory");
|
||||
*/
|
||||
FactoryFinder
|
||||
.setFactory(FactoryFinder.LIFECYCLE_FACTORY, "org.apache.shale.test.mock.MockLifecycleFactory");
|
||||
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
|
||||
|
||||
@@ -64,10 +64,10 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
trackingListener = new TrackingPhaseListener();
|
||||
jsfMock.lifecycle().addPhaseListener(trackingListener);
|
||||
jsfMock.facesContext().setViewRoot(null);
|
||||
jsfMock.application().setViewHandler(viewHandler);
|
||||
jsfMock.facesContext().getApplication().setViewHandler(viewHandler);
|
||||
lifecycle = new TestLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression("#{'" + VIEW_ID + "'}", RequestContext.class, String.class,
|
||||
null), null);
|
||||
null), null, lifecycle);
|
||||
finalResponseAction = new JsfFinalResponseAction(factory);
|
||||
RequestContextHolder.setRequestContext(context);
|
||||
ExternalContext ext = new MockExternalContext();
|
||||
@@ -80,7 +80,7 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
|
||||
UIViewRoot newRoot = new UIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
newRoot.setRenderKitId("TEST_KIT");
|
||||
newRoot.setRenderKitId("HTML_BASIC");
|
||||
((MockViewHandler) viewHandler).setCreateView(newRoot);
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
@@ -141,6 +141,7 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
|
||||
rendered = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
trackingListener = new TrackingPhaseListener();
|
||||
jsfMock.lifecycle().addPhaseListener(trackingListener);
|
||||
jsfMock.facesContext().setViewRoot(null);
|
||||
jsfMock.application().setViewHandler(viewHandler);
|
||||
jsfMock.facesContext().getApplication().setViewHandler(viewHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,8 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_Create() {
|
||||
|
||||
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
|
||||
lifecycle);
|
||||
|
||||
UIViewRoot newRoot = new UIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
@@ -98,7 +99,8 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_Restore_NoEvent() {
|
||||
|
||||
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
|
||||
lifecycle);
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
@@ -119,7 +121,8 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_Restore_EventSignaled() {
|
||||
|
||||
lifecycle = new EventSignalingLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
|
||||
lifecycle);
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
@@ -170,7 +173,8 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_ExternalViewRoot() {
|
||||
|
||||
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null,
|
||||
lifecycle);
|
||||
|
||||
UIViewRoot newRoot = new UIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.webflow.core.collection.MutableAttributeMap;
|
||||
import org.springframework.webflow.execution.FlowExecutionContext;
|
||||
import org.springframework.webflow.execution.FlowExecutionKey;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.test.MockExternalContext;
|
||||
|
||||
public class JsfViewTests extends TestCase {
|
||||
|
||||
@@ -54,12 +55,12 @@ public class JsfViewTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
jsfMock.setUp();
|
||||
jsfMock.application().setViewHandler(new MockViewHandler());
|
||||
jsfMock.facesContext().getApplication().setViewHandler(new MockViewHandler());
|
||||
jsfMock.application().setStateManager(new TestStateManager());
|
||||
jsfMock.facesContext().setResponseWriter(new MockResponseWriter(output, null, null));
|
||||
|
||||
UIViewRoot viewToRender = new UIViewRoot();
|
||||
viewToRender.setRenderKitId("TEST_KIT");
|
||||
viewToRender.setRenderKitId("HTML_BASIC");
|
||||
viewToRender.setViewId(VIEW_ID);
|
||||
jsfMock.facesContext().setViewRoot(viewToRender);
|
||||
|
||||
@@ -81,6 +82,7 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
public final void testRender() {
|
||||
|
||||
EasyMock.expect(requestContext.getExternalContext()).andStubReturn(new MockExternalContext());
|
||||
EasyMock.expect(requestContext.getFlashScope()).andStubReturn(flashMap);
|
||||
EasyMock.expect(requestContext.getFlowScope()).andStubReturn(flowMap);
|
||||
EasyMock.expect(requestContext.getFlowExecutionContext()).andStubReturn(flowExecutionContext);
|
||||
@@ -94,11 +96,11 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
EasyMock.verify(new Object[] { requestContext, flowExecutionContext, flowMap, flashMap });
|
||||
assertNull("The FacesContext was not released", FacesContext.getCurrentInstance());
|
||||
assertTrue(output.getBuffer().toString().contains(key.toString()));
|
||||
}
|
||||
|
||||
public final void testRenderException() {
|
||||
|
||||
EasyMock.expect(requestContext.getExternalContext()).andStubReturn(new MockExternalContext());
|
||||
EasyMock.expect(requestContext.getFlashScope()).andStubReturn(flashMap);
|
||||
EasyMock.expect(flashMap.put(EasyMock.matches("renderResponse"), EasyMock.anyObject())).andStubReturn(null);
|
||||
EasyMock.expect(flashMap.put(EasyMock.matches("responseComplete"), EasyMock.anyObject())).andStubReturn(null);
|
||||
|
||||
@@ -16,10 +16,16 @@ public class MockBaseFacesContextFactory extends FacesContextFactory {
|
||||
public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle)
|
||||
throws FacesException {
|
||||
|
||||
ExternalContext ext = new MockExternalContext((ServletContext) context, (HttpServletRequest) request,
|
||||
(HttpServletResponse) response);
|
||||
if (FacesContext.getCurrentInstance() != null
|
||||
&& FacesContext.getCurrentInstance() instanceof MockBaseFacesContext) {
|
||||
return FacesContext.getCurrentInstance();
|
||||
} else {
|
||||
|
||||
return new MockBaseFacesContext(ext, lifecycle);
|
||||
ExternalContext ext = new MockExternalContext((ServletContext) context, (HttpServletRequest) request,
|
||||
(HttpServletResponse) response);
|
||||
|
||||
return new MockBaseFacesContext(ext, lifecycle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Locale;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.application.ViewHandler;
|
||||
import javax.faces.application.StateManager.SerializedView;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
@@ -70,8 +69,7 @@ public class MockViewHandler extends ViewHandler {
|
||||
*/
|
||||
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
|
||||
context.getViewRoot().encodeAll(context);
|
||||
SerializedView state = context.getApplication().getStateManager().saveSerializedView(context);
|
||||
context.getRenderKit().getResponseStateManager().writeState(context, state);
|
||||
|
||||
}
|
||||
|
||||
public UIViewRoot restoreView(FacesContext context, String viewId) {
|
||||
|
||||
Reference in New Issue
Block a user