Add Java config option for configuring Spring Web Flow

Issue: SWF-1548
This commit is contained in:
Rossen Stoyanchev
2014-02-24 17:43:57 -05:00
parent 5359ff7110
commit 921220be27
28 changed files with 1891 additions and 392 deletions

View File

@@ -0,0 +1,126 @@
package org.springframework.faces.config;
import junit.framework.TestCase;
import org.springframework.binding.convert.ConversionException;
import org.springframework.binding.convert.ConversionExecutionException;
import org.springframework.binding.convert.ConversionExecutor;
import org.springframework.binding.convert.ConversionExecutorNotFoundException;
import org.springframework.binding.convert.ConversionService;
import org.springframework.binding.expression.Expression;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.spel.SpringELExpressionParser;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.faces.model.converter.FacesConversionService;
import org.springframework.faces.webflow.FacesSpringELExpressionParser;
import org.springframework.faces.webflow.JSFMockHelper;
import org.springframework.faces.webflow.JsfViewFactoryCreator;
import org.springframework.validation.Validator;
import org.springframework.webflow.engine.builder.BinderConfiguration;
import org.springframework.webflow.engine.builder.ViewFactoryCreator;
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;
import org.springframework.webflow.execution.ViewFactory;
import org.springframework.webflow.expression.spel.WebFlowSpringELExpressionParser;
import org.springframework.webflow.validation.ValidationHintResolver;
public abstract class AbstractFacesFlowBuilderServicesConfigurationTests extends TestCase {
protected ApplicationContext context;
protected FlowBuilderServices builderServices;
protected final JSFMockHelper jsf = new JSFMockHelper();
public void setUp() throws Exception {
this.jsf.setUp();
this.context = initApplicationContext();
}
protected abstract ApplicationContext initApplicationContext();
protected void tearDown() throws Exception {
this.jsf.tearDown();
}
public void testConfigureDefaults() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesDefault");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getExpressionParser() instanceof SpringELExpressionParser);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
assertTrue(this.builderServices.getConversionService() instanceof FacesConversionService);
assertFalse(this.builderServices.getDevelopment());
}
public void testEnableManagedBeans() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesLegacy");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getExpressionParser() instanceof FacesSpringELExpressionParser);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
assertTrue(this.builderServices.getConversionService() instanceof FacesConversionService);
assertFalse(this.builderServices.getDevelopment());
}
public void testFlowBuilderServicesAllCustomized() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesAllCustom");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof TestViewFactoryCreator);
assertTrue(this.builderServices.getConversionService() instanceof TestConversionService);
assertTrue(this.builderServices.getDevelopment());
}
public void testFlowBuilderServicesConversionServiceCustomized() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesConversionServiceCustom");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getConversionService() instanceof TestConversionService);
assertTrue(this.builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
assertTrue(((SpringELExpressionParser) this.builderServices.getExpressionParser()).getConversionService() instanceof TestConversionService);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
assertFalse(this.builderServices.getDevelopment());
}
public static class TestViewFactoryCreator implements ViewFactoryCreator {
public ViewFactory createViewFactory(Expression viewIdExpression, ExpressionParser expressionParser,
ConversionService conversionService, BinderConfiguration binderConfiguration,
Validator validator, ValidationHintResolver validationHintResolver) {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public String getViewIdByConvention(String viewStateId) {
return viewStateId;
}
}
public static class TestConversionService implements ConversionService {
public Object executeConversion(Object source, Class<?> targetClass) throws ConversionException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public Object executeConversion(String converterId, Object source, Class<?> targetClass) {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public ConversionExecutor getConversionExecutor(Class<?> sourceClass, Class<?> targetClass)
throws ConversionExecutionException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public ConversionExecutor getConversionExecutor(String id, Class<?> sourceClass, Class<?> targetClass)
throws ConversionExecutorNotFoundException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public Class<?> getClassForAlias(String name) throws ConversionExecutionException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public org.springframework.core.convert.ConversionService getDelegateConversionService() {
throw new UnsupportedOperationException("Auto-generated method stub");
}
}
}

View File

@@ -0,0 +1,45 @@
package org.springframework.faces.config;
import java.util.Map;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.faces.webflow.JsfResourceRequestHandler;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
public abstract class AbstractResourcesConfigurationTests extends TestCase {
protected ApplicationContext context;
public void setUp() throws Exception {
this.context = initApplicationContext();
}
protected abstract ApplicationContext initApplicationContext();
protected void tearDown() throws Exception {
}
public void testConfigureDefaults() {
Map<String, ?> map = this.context.getBeansOfType(HttpRequestHandlerAdapter.class);
assertEquals(1, map.values().size());
Object resourceHandler = this.context.getBean(ResourcesBeanDefinitionParser.SERVLET_RESOURCE_HANDLER_BEAN_NAME);
assertNotNull(resourceHandler);
assertTrue(resourceHandler instanceof JsfResourceRequestHandler);
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/**"));
assertEquals(0, handlerMapping.getOrder());
}
public void testConfigurePortlet() {
Object resourceHandler = this.context.getBean(ResourcesBeanDefinitionParser.PORTLET_RESOURCE_HANDLER_BEAN_NAME);
assertNotNull(resourceHandler);
assertTrue(resourceHandler instanceof org.springframework.faces.webflow.context.portlet.JsfResourceRequestHandler);
}
}

View File

@@ -1,120 +1,15 @@
package org.springframework.faces.config;
import junit.framework.TestCase;
import org.springframework.binding.convert.ConversionException;
import org.springframework.binding.convert.ConversionExecutionException;
import org.springframework.binding.convert.ConversionExecutor;
import org.springframework.binding.convert.ConversionExecutorNotFoundException;
import org.springframework.binding.convert.ConversionService;
import org.springframework.binding.expression.Expression;
import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.spel.SpringELExpressionParser;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.faces.model.converter.FacesConversionService;
import org.springframework.faces.webflow.FacesSpringELExpressionParser;
import org.springframework.faces.webflow.JSFMockHelper;
import org.springframework.faces.webflow.JsfViewFactoryCreator;
import org.springframework.validation.Validator;
import org.springframework.webflow.engine.builder.BinderConfiguration;
import org.springframework.webflow.engine.builder.ViewFactoryCreator;
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;
import org.springframework.webflow.execution.ViewFactory;
import org.springframework.webflow.expression.spel.WebFlowSpringELExpressionParser;
import org.springframework.webflow.validation.ValidationHintResolver;
public class FacesFlowBuilderServicesBeanDefinitionParserTests extends TestCase {
public class FacesFlowBuilderServicesBeanDefinitionParserTests
extends AbstractFacesFlowBuilderServicesConfigurationTests {
private ClassPathXmlApplicationContext context;
private FlowBuilderServices builderServices;
private final JSFMockHelper jsf = new JSFMockHelper();
public void setUp() throws Exception {
this.jsf.setUp();
this.context = new ClassPathXmlApplicationContext("org/springframework/faces/config/flow-builder-services.xml");
@Override
protected ApplicationContext initApplicationContext() {
return new ClassPathXmlApplicationContext("org/springframework/faces/config/flow-builder-services.xml");
}
protected void tearDown() throws Exception {
this.jsf.tearDown();
}
public void testConfigureDefaults() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesDefault");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getExpressionParser() instanceof SpringELExpressionParser);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
assertTrue(this.builderServices.getConversionService() instanceof FacesConversionService);
assertFalse(this.builderServices.getDevelopment());
}
public void testEnableManagedBeans() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesLegacy");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getExpressionParser() instanceof FacesSpringELExpressionParser);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
assertTrue(this.builderServices.getConversionService() instanceof FacesConversionService);
assertFalse(this.builderServices.getDevelopment());
}
public void testFlowBuilderServicesAllCustomized() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesAllCustom");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof TestViewFactoryCreator);
assertTrue(this.builderServices.getConversionService() instanceof TestConversionService);
assertTrue(this.builderServices.getDevelopment());
}
public void testFlowBuilderServicesConversionServiceCustomized() {
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesConversionServiceCustom");
assertNotNull(this.builderServices);
assertTrue(this.builderServices.getConversionService() instanceof TestConversionService);
assertTrue(this.builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
assertTrue(((SpringELExpressionParser) this.builderServices.getExpressionParser()).getConversionService() instanceof TestConversionService);
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
assertFalse(this.builderServices.getDevelopment());
}
public static class TestViewFactoryCreator implements ViewFactoryCreator {
public ViewFactory createViewFactory(Expression viewIdExpression, ExpressionParser expressionParser,
ConversionService conversionService, BinderConfiguration binderConfiguration,
Validator validator, ValidationHintResolver validationHintResolver) {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public String getViewIdByConvention(String viewStateId) {
return viewStateId;
}
}
public static class TestConversionService implements ConversionService {
public Object executeConversion(Object source, Class<?> targetClass) throws ConversionException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public Object executeConversion(String converterId, Object source, Class<?> targetClass) {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public ConversionExecutor getConversionExecutor(Class<?> sourceClass, Class<?> targetClass)
throws ConversionExecutionException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public ConversionExecutor getConversionExecutor(String id, Class<?> sourceClass, Class<?> targetClass)
throws ConversionExecutorNotFoundException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public Class<?> getClassForAlias(String name) throws ConversionExecutionException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public org.springframework.core.convert.ConversionService getDelegateConversionService() {
throw new UnsupportedOperationException("Auto-generated method stub");
}
}
}

View File

@@ -0,0 +1,65 @@
package org.springframework.faces.config;
import org.springframework.binding.convert.ConversionService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.webflow.engine.builder.ViewFactoryCreator;
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;
import org.springframework.webflow.expression.spel.WebFlowSpringELExpressionParser;
public class FacesFlowBuilderServicesJavaConfigTests extends AbstractFacesFlowBuilderServicesConfigurationTests {
@Override
protected ApplicationContext initApplicationContext() {
return new AnnotationConfigApplicationContext(FacesFlowConfig.class);
}
static class FacesFlowConfig extends AbstractFacesFlowConfiguration {
@Bean
public FlowBuilderServices flowBuilderServicesDefault() {
return getFlowBuilderServicesBuilder().build();
}
@Bean
public FlowBuilderServices flowBuilderServicesLegacy() {
return getFlowBuilderServicesBuilder().setEnableManagedBeans(true).build();
}
@Bean
public FlowBuilderServices flowBuilderServicesAllCustom() {
return getFlowBuilderServicesBuilder()
.setExpressionParser(customExpressionParser())
.setViewFactoryCreator(customViewFactoryCreator())
.setConversionService(customConversionService())
.setDevelopmentMode(true)
.build();
}
@Bean
public FlowBuilderServices flowBuilderServicesConversionServiceCustom() {
return getFlowBuilderServicesBuilder().setConversionService(customConversionService()).build();
}
@Bean
public WebFlowSpringELExpressionParser customExpressionParser() {
return new WebFlowSpringELExpressionParser(new SpelExpressionParser());
}
@Bean
public ViewFactoryCreator customViewFactoryCreator() {
return new TestViewFactoryCreator();
}
@Bean
public ConversionService customConversionService() {
return new TestConversionService();
}
}
}

View File

@@ -1,44 +1,14 @@
package org.springframework.faces.config;
import java.util.Map;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.faces.webflow.JsfResourceRequestHandler;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
public class ResourcesBeanDefinitionParserTests extends TestCase {
public class ResourcesBeanDefinitionParserTests extends AbstractResourcesConfigurationTests {
private ClassPathXmlApplicationContext context;
public void setUp() throws Exception {
this.context = new ClassPathXmlApplicationContext("org/springframework/faces/config/resources.xml");
@Override
protected ApplicationContext initApplicationContext() {
return new ClassPathXmlApplicationContext("org/springframework/faces/config/resources.xml");
}
protected void tearDown() throws Exception {
}
public void testConfigureDefaults() {
Map<String, ?> map = this.context.getBeansOfType(HttpRequestHandlerAdapter.class);
assertEquals(1, map.values().size());
Object resourceHandler = this.context.getBean(ResourcesBeanDefinitionParser.SERVLET_RESOURCE_HANDLER_BEAN_NAME);
assertNotNull(resourceHandler);
assertTrue(resourceHandler instanceof JsfResourceRequestHandler);
map = this.context.getBeansOfType(SimpleUrlHandlerMapping.class);
assertEquals(1, map.values().size());
SimpleUrlHandlerMapping handlerMapping = (SimpleUrlHandlerMapping) map.values().iterator().next();
assertEquals(ResourcesBeanDefinitionParser.SERVLET_RESOURCE_HANDLER_BEAN_NAME,
handlerMapping.getUrlMap().get("/javax.faces.resource/**"));
assertEquals(0, handlerMapping.getOrder());
}
public void testConfigurePortlet() {
Object resourceHandler = this.context.getBean(ResourcesBeanDefinitionParser.PORTLET_RESOURCE_HANDLER_BEAN_NAME);
assertNotNull(resourceHandler);
assertTrue(resourceHandler instanceof org.springframework.faces.webflow.context.portlet.JsfResourceRequestHandler);
}
}

View File

@@ -0,0 +1,20 @@
package org.springframework.faces.config;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
public class ResourcesJavaConfigTests extends AbstractResourcesConfigurationTests {
@Override
protected ApplicationContext initApplicationContext() {
return new AnnotationConfigApplicationContext(FacesFlowConfig.class);
}
@Configuration
static class FacesFlowConfig extends AbstractFacesPortletFlowConfiguration {
}
}

View File

@@ -26,8 +26,10 @@
</constructor-arg>
</bean>
<bean id="customViewFactoryCreator" class="org.springframework.faces.config.FacesFlowBuilderServicesBeanDefinitionParserTests$TestViewFactoryCreator"/>
<bean id="customViewFactoryCreator"
class="org.springframework.faces.config.AbstractFacesFlowBuilderServicesConfigurationTests$TestViewFactoryCreator"/>
<bean id="customConversionService" class="org.springframework.faces.config.FacesFlowBuilderServicesBeanDefinitionParserTests$TestConversionService"/>
<bean id="customConversionService"
class="org.springframework.faces.config.AbstractFacesFlowBuilderServicesConfigurationTests$TestConversionService"/>
</beans>