Added test for resolving flow scoped beans from the ApplicationContext.

This commit is contained in:
Jeremy Grelle
2007-08-01 19:17:48 +00:00
parent a2ac2bc857
commit 37267b60f4
3 changed files with 50 additions and 22 deletions

View File

@@ -6,9 +6,11 @@ import javax.faces.el.ValueBinding;
import org.easymock.EasyMock;
import org.jboss.el.ExpressionFactoryImpl;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.jsf.DelegatingVariableResolver;
import org.springframework.webflow.definition.registry.FlowDefinitionResource;
import org.springframework.webflow.execution.FlowExecutionException;
import org.springframework.webflow.execution.ViewSelection;
@@ -23,6 +25,7 @@ public class JSF11ManagedBeanAccessTests extends AbstractXmlFlowExecutionTests {
FlowPhaseListener flowPhaseListener;
FlowNavigationHandler flowNavigationHandler;
MockService service;
GenericWebApplicationContext ctx;
protected void setUp() throws Exception {
super.setUp();
@@ -33,8 +36,8 @@ public class JSF11ManagedBeanAccessTests extends AbstractXmlFlowExecutionTests {
}
private void configureJSFForSWF() {
DelegatingFlowVariableResolver dfvr = new DelegatingFlowVariableResolver(jsf.application()
.getVariableResolver());
DelegatingVariableResolver dvr = new DelegatingVariableResolver(jsf.application().getVariableResolver());
DelegatingFlowVariableResolver dfvr = new DelegatingFlowVariableResolver(dvr);
FlowVariableResolver fvr = new FlowVariableResolver(dfvr);
jsf.application().setVariableResolver(fvr);
FlowPropertyResolver fpr = new FlowPropertyResolver(jsf.application().getPropertyResolver());
@@ -66,7 +69,7 @@ public class JSF11ManagedBeanAccessTests extends AbstractXmlFlowExecutionTests {
assertNotNull(jsfModel);
}
public void testManagedBeanProperyAsArgument() {
public void testManagedBeanPropertyAsArgument() {
testManagedBeanExpression();
jsfBean.setProp1("arg");
service.doSomething(jsfBean.getProp1());
@@ -95,14 +98,11 @@ public class JSF11ManagedBeanAccessTests extends AbstractXmlFlowExecutionTests {
}
public void testSWFScopedPropertyInjection() {
// testManagedBeanExpression();
// startFlow();
startFlow();
// TODO - Add a flow scoped bean definition to the test application context
// ValueBinding propBinding = jsf.application().createValueBinding("#{flowScopedModel}");
// jsfModel = (JSFModel) propBinding.getValue(jsf.facesContext());
// assertNotNull("This test won't pass until custom scopes are implemented.", jsfModel);
// jsfBean.setModel(jsfModel);
ValueBinding propBinding = jsf.application().createValueBinding("#{flowScopedModel}");
jsfModel = (JSFModel) propBinding.getValue(jsf.facesContext());
assertNotNull("This test won't pass until custom scopes are implemented.", jsfModel);
}
protected ViewSelection startFlow() throws FlowExecutionException {
@@ -126,9 +126,14 @@ public class JSF11ManagedBeanAccessTests extends AbstractXmlFlowExecutionTests {
protected void registerMockServices(MockFlowServiceLocator serviceRegistry) {
serviceRegistry.setExpressionParser(new Jsf11ELExpressionParser(new ExpressionFactoryImpl()));
serviceRegistry.registerBean("serviceBean", service);
StaticWebApplicationContext ctx = new StaticWebApplicationContext();
ctx.registerPrototype("jsfModel", JSFModel.class);
jsf.externalContext().getApplicationMap()
.put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
ctx = new GenericWebApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
xmlReader.loadBeanDefinitions(new ClassPathResource(
"org/springframework/webflow/executor/jsf/jsf-flow-beans.xml"));
ctx.refresh();
jsf.externalContext().getApplicationMap().put(
GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
}
}

View File

@@ -1,8 +1,9 @@
package org.springframework.webflow.executor.jsf;
import org.jboss.el.ExpressionFactoryImpl;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.webflow.test.MockFlowServiceLocator;
public class JSF12ManagedBeanAccessTests extends JSF11ManagedBeanAccessTests {
@@ -10,10 +11,15 @@ public class JSF12ManagedBeanAccessTests extends JSF11ManagedBeanAccessTests {
protected void registerMockServices(MockFlowServiceLocator serviceRegistry) {
serviceRegistry.setExpressionParser(new Jsf12ELExpressionParser(new ExpressionFactoryImpl()));
serviceRegistry.registerBean("serviceBean", service);
StaticWebApplicationContext ctx = new StaticWebApplicationContext();
ctx.registerPrototype("jsfModel", JSFModel.class);
jsf.externalContext().getApplicationMap()
.put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
ctx = new GenericWebApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
xmlReader.loadBeanDefinitions(new ClassPathResource(
"org/springframework/webflow/executor/jsf/jsf-flow-beans.xml"));
ctx.refresh();
jsf.externalContext().getApplicationMap().put(
GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.1.xsd">
<flow:enable-scopes/>
<bean name="jsfModel" class="org.springframework.webflow.executor.jsf.JSFModel" scope="prototype"/>
<bean name="flowScopedModel" class="org.springframework.webflow.executor.jsf.JSFModel" scope="flow"/>
</beans>