m2 code review / polishing / simplification
- removed flow faces context factory, not needed, favoring simple creation of flow faces context from jsf view factory / jsf view instead - replace response state manager usage with state manager as discussed; allowed removal of custom render kit - removed flow lifecycle factory; not needed, favoring simple creation of flow lifecycle factory from view factory instead. this needs review, several tests still need updating - misc naming improvements - removed use of thread locals where possible
This commit is contained in:
@@ -16,7 +16,6 @@ import org.springframework.binding.message.MessageContext;
|
||||
import org.springframework.binding.message.MessageResolver;
|
||||
import org.springframework.binding.message.Severity;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
public class FlowFacesContextTests extends TestCase {
|
||||
|
||||
@@ -30,8 +29,7 @@ public class FlowFacesContextTests extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsf.setUp();
|
||||
facesContext = new FlowFacesContext(jsf.facesContext());
|
||||
RequestContextHolder.setRequestContext(requestContext);
|
||||
facesContext = new FlowFacesContext(requestContext, jsf.facesContext());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
@@ -48,6 +48,7 @@ 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 {
|
||||
|
||||
@@ -77,8 +78,8 @@ public class JSFFlowExecutionTests extends TestCase {
|
||||
|
||||
flow = Flow.create("jsf-flow", null);
|
||||
|
||||
ViewState view1 = new ViewState(flow, "viewState1", new JsfViewFactory(new TestLifecycle(jsf.lifecycle()),
|
||||
parser.parseExpression("/view1", RequestContext.class, String.class, null), 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")));
|
||||
|
||||
@@ -98,8 +99,8 @@ public class JSFFlowExecutionTests extends TestCase {
|
||||
String.class, null)));
|
||||
evalSomething.getTransitionSet().add(new Transition(on("success"), to("viewState2")));
|
||||
|
||||
ViewState viewState2 = new ViewState(flow, "viewState2", new JsfViewFactory(new TestLifecycle(jsf.lifecycle()),
|
||||
parser.parseExpression("/view2", RequestContext.class, String.class, null), null));
|
||||
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")));
|
||||
|
||||
@@ -114,7 +115,7 @@ public class JSFFlowExecutionTests extends TestCase {
|
||||
jsf = new JSFMockHelper();
|
||||
jsf.tearDown();
|
||||
jsf.setUp();
|
||||
FacesContext flowContext = new FlowFacesContext(jsf.facesContext());
|
||||
FacesContext flowContext = new FlowFacesContext(new MockRequestContext(), jsf.facesContext());
|
||||
org.apache.shale.test.mock.MockFacesContext.setCurrentInstance(flowContext);
|
||||
|
||||
viewHandler = new NoRenderViewHandler();
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.springframework.faces.webflow;
|
||||
import javax.faces.FactoryFinder;
|
||||
import javax.faces.application.Application;
|
||||
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;
|
||||
|
||||
@@ -29,9 +31,6 @@ public class JSFMockHelper {
|
||||
private JSFMock mock = new JSFMock();
|
||||
|
||||
public Application application() {
|
||||
if (mock.application() == null) {
|
||||
return mock.facesContext.getApplication();
|
||||
}
|
||||
return mock.application();
|
||||
}
|
||||
|
||||
@@ -43,11 +42,11 @@ public class JSFMockHelper {
|
||||
return mock.externalContext();
|
||||
}
|
||||
|
||||
public FlowFacesContext facesContext() {
|
||||
public FacesContext facesContext() {
|
||||
return mock.facesContext();
|
||||
}
|
||||
|
||||
public FlowFacesContextFactory facesContextFactory() {
|
||||
public FacesContextFactory facesContextFactory() {
|
||||
return mock.facesContextFactory();
|
||||
}
|
||||
|
||||
@@ -93,8 +92,8 @@ public class JSFMockHelper {
|
||||
super("JSFMock");
|
||||
}
|
||||
|
||||
FlowFacesContextFactory facesContextFactory;
|
||||
FlowFacesContext facesContext;
|
||||
FacesContextFactory facesContextFactory;
|
||||
FacesContext facesContext;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
|
||||
@@ -116,19 +115,18 @@ public class JSFMockHelper {
|
||||
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
|
||||
"org.springframework.faces.webflow.MockBaseFacesContextFactory");
|
||||
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
|
||||
"org.springframework.faces.webflow.FlowFacesContextFactory");
|
||||
"org.apache.shale.test.mock.MockFacesContextFactory");
|
||||
FactoryFinder
|
||||
.setFactory(FactoryFinder.LIFECYCLE_FACTORY, "org.apache.shale.test.mock.MockLifecycleFactory");
|
||||
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
|
||||
"org.apache.shale.test.mock.MockRenderKitFactory");
|
||||
|
||||
application = new MockApplication();
|
||||
externalContext = new MockExternalContext(servletContext, request, response);
|
||||
lifecycleFactory = (MockLifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
|
||||
lifecycle = (MockLifecycle) lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
|
||||
facesContextFactory = (FlowFacesContextFactory) FactoryFinder
|
||||
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
|
||||
facesContext = (FlowFacesContext) facesContextFactory.getFacesContext(servletContext, request, response,
|
||||
lifecycle);
|
||||
facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
|
||||
facesContext = facesContextFactory.getFacesContext(servletContext, request, response, lifecycle);
|
||||
externalContext = (MockExternalContext) facesContext.getExternalContext();
|
||||
UIViewRoot root = new UIViewRoot();
|
||||
root.setViewId("/viewId");
|
||||
@@ -171,11 +169,11 @@ public class JSFMockHelper {
|
||||
return externalContext;
|
||||
}
|
||||
|
||||
public FlowFacesContext facesContext() {
|
||||
public FacesContext facesContext() {
|
||||
return facesContext;
|
||||
}
|
||||
|
||||
public FlowFacesContextFactory facesContextFactory() {
|
||||
public FacesContextFactory facesContextFactory() {
|
||||
return facesContextFactory;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,16 +25,15 @@ import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.core.expression.el.WebFlowELExpressionParser;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.execution.ViewFactory;
|
||||
import org.springframework.webflow.test.MockExternalContext;
|
||||
|
||||
public class JsfRenderFinalResponseActionTests extends TestCase {
|
||||
public class JsfFinalResponseActionTests extends TestCase {
|
||||
|
||||
private static final String VIEW_ID = "/testView.xhtml";
|
||||
|
||||
private ViewFactory factory;
|
||||
private JsfViewFactory factory;
|
||||
|
||||
private JsfRenderFinalResponseAction finalResponseAction;
|
||||
private JsfFinalResponseAction finalResponseAction;
|
||||
|
||||
private JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
|
||||
@@ -67,9 +66,9 @@ public class JsfRenderFinalResponseActionTests extends TestCase {
|
||||
jsfMock.facesContext().setViewRoot(null);
|
||||
jsfMock.application().setViewHandler(viewHandler);
|
||||
lifecycle = new TestLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(lifecycle, parser.parseExpression("#{'" + VIEW_ID + "'}", RequestContext.class,
|
||||
String.class, null), null);
|
||||
finalResponseAction = new JsfRenderFinalResponseAction(factory);
|
||||
factory = new JsfViewFactory(parser.parseExpression("#{'" + VIEW_ID + "'}", RequestContext.class, String.class,
|
||||
null), null);
|
||||
finalResponseAction = new JsfFinalResponseAction(factory);
|
||||
RequestContextHolder.setRequestContext(context);
|
||||
ExternalContext ext = new MockExternalContext();
|
||||
EasyMock.expect(context.getExternalContext()).andStubReturn(ext);
|
||||
@@ -77,8 +77,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_Create() {
|
||||
|
||||
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(lifecycle, parser.parseExpression(VIEW_ID, RequestContext.class, String.class,
|
||||
null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
|
||||
UIViewRoot newRoot = new UIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
@@ -99,8 +98,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_Restore_NoEvent() {
|
||||
|
||||
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(lifecycle, parser.parseExpression(VIEW_ID, RequestContext.class, String.class,
|
||||
null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
@@ -121,8 +119,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_Restore_EventSignaled() {
|
||||
|
||||
lifecycle = new EventSignalingLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(lifecycle, parser.parseExpression(VIEW_ID, RequestContext.class, String.class,
|
||||
null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
@@ -173,8 +170,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public final void testGetView_ExternalViewRoot() {
|
||||
|
||||
lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(lifecycle, parser.parseExpression(VIEW_ID, RequestContext.class, String.class,
|
||||
null), null);
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID, RequestContext.class, String.class, null), null);
|
||||
|
||||
UIViewRoot newRoot = new UIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
|
||||
@@ -4,20 +4,15 @@ import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.FactoryFinder;
|
||||
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.render.RenderKitFactory;
|
||||
import javax.faces.render.Renderer;
|
||||
import javax.faces.render.ResponseStateManager;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.shale.test.mock.MockRenderKit;
|
||||
import org.apache.shale.test.mock.MockResponseWriter;
|
||||
import org.apache.shale.test.mock.MockStateManager;
|
||||
import org.easymock.EasyMock;
|
||||
@@ -25,7 +20,6 @@ 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.execution.RequestContextHolder;
|
||||
|
||||
public class JsfViewTests extends TestCase {
|
||||
|
||||
@@ -64,9 +58,6 @@ public class JsfViewTests extends TestCase {
|
||||
jsfMock.application().setStateManager(new TestStateManager());
|
||||
jsfMock.facesContext().setResponseWriter(new MockResponseWriter(output, null, null));
|
||||
|
||||
RenderKitFactory rkf = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
|
||||
rkf.addRenderKit("TEST_KIT", new TestRenderKit());
|
||||
|
||||
UIViewRoot viewToRender = new UIViewRoot();
|
||||
viewToRender.setRenderKitId("TEST_KIT");
|
||||
viewToRender.setViewId(VIEW_ID);
|
||||
@@ -81,9 +72,7 @@ public class JsfViewTests extends TestCase {
|
||||
form.getChildren().add(input);
|
||||
viewToRender.getChildren().add(form);
|
||||
|
||||
view = new JsfView(viewToRender, jsfMock.lifecycle());
|
||||
|
||||
RequestContextHolder.setRequestContext(requestContext);
|
||||
view = new JsfView(viewToRender, jsfMock.lifecycle(), requestContext);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
@@ -96,7 +85,6 @@ public class JsfViewTests extends TestCase {
|
||||
EasyMock.expect(requestContext.getFlowScope()).andStubReturn(flowMap);
|
||||
EasyMock.expect(requestContext.getFlowExecutionContext()).andStubReturn(flowExecutionContext);
|
||||
EasyMock.expect(flowExecutionContext.getKey()).andStubReturn(key);
|
||||
EasyMock.expect(flowMap.put(EasyMock.matches(JsfView.STATE_KEY), EasyMock.anyObject())).andStubReturn(null);
|
||||
EasyMock.expect(flashMap.put(EasyMock.matches("renderResponse"), EasyMock.anyObject())).andStubReturn(null);
|
||||
EasyMock.expect(flashMap.put(EasyMock.matches("responseComplete"), EasyMock.anyObject())).andStubReturn(null);
|
||||
|
||||
@@ -139,17 +127,4 @@ public class JsfViewTests extends TestCase {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
private class TestRenderKit extends MockRenderKit {
|
||||
Renderer renderer = new Renderer() {
|
||||
};
|
||||
|
||||
public Renderer getRenderer(String family, String rendererType) {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
public ResponseStateManager getResponseStateManager() {
|
||||
return new FlowResponseStateManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user