Integration testing fixes.
This commit is contained in:
@@ -18,8 +18,6 @@ public class CompositeFlowPropertyResolver extends ELDelegatingPropertyResolver
|
||||
private static final CompositeELResolver composite = new CompositeELResolver();
|
||||
|
||||
static {
|
||||
composite.add(new RequestContextELResolver());
|
||||
composite.add(new ScopeSearchingELResolver());
|
||||
composite.add(new MapAdaptableELResolver());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ package org.springframework.faces.expression;
|
||||
import javax.el.CompositeELResolver;
|
||||
import javax.faces.el.VariableResolver;
|
||||
|
||||
import org.springframework.binding.expression.el.MapAdaptableELResolver;
|
||||
import org.springframework.webflow.expression.el.ImplicitFlowVariableELResolver;
|
||||
import org.springframework.webflow.expression.el.RequestContextELResolver;
|
||||
import org.springframework.webflow.expression.el.ScopeSearchingELResolver;
|
||||
import org.springframework.webflow.expression.el.SpringBeanWebFlowELResolver;
|
||||
|
||||
/**
|
||||
* Assembles {@link RequestContextELResolver} and {@link ScopeSearchingELResolver} into a composite that may be used
|
||||
@@ -20,9 +20,9 @@ public class CompositeFlowVariableResolver extends ELDelegatingVariableResolver
|
||||
|
||||
static {
|
||||
composite.add(new RequestContextELResolver());
|
||||
composite.add(new SpringBeanWebFlowELResolver());
|
||||
composite.add(new ImplicitFlowVariableELResolver());
|
||||
composite.add(new ScopeSearchingELResolver());
|
||||
composite.add(new MapAdaptableELResolver());
|
||||
}
|
||||
|
||||
public CompositeFlowVariableResolver(VariableResolver nextResolver) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE faces-config PUBLIC
|
||||
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
|
||||
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
|
||||
|
||||
<faces-config>
|
||||
<application>
|
||||
<!-- Enables Facelets -->
|
||||
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
|
||||
</application>
|
||||
</faces-config>
|
||||
@@ -0,0 +1,55 @@
|
||||
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:ui="http://java.sun.com/jsf/facelets"
|
||||
xmlns:h="http://java.sun.com/jsf/html"
|
||||
xmlns:f="http://java.sun.com/jsf/core"
|
||||
xmlns:sf="http://www.springframework.org/tags/faces"
|
||||
template="/WEB-INF/layouts/standard.xhtml">
|
||||
|
||||
<ui:define name="content">
|
||||
|
||||
<h:form id="displayHotelsForm">
|
||||
<div class="section">
|
||||
<sf:commandLink ajaxEnabled="false" value="Return to Main" action="changeSearch"/>
|
||||
<h2>Hotel Results</h2>
|
||||
<p>
|
||||
<b>Search Criteria:</b> #{searchCriteria}<br/>
|
||||
<sf:commandLink value="Edit Criteria" action="changeSearch"/>
|
||||
</p>
|
||||
<ui:fragment id="searchResultsFragment">
|
||||
<div id="searchResults">
|
||||
<h:outputText id="noHotelsTxt" value="No Hotels Found" rendered="#{hotels.rowCount == 0}"/>
|
||||
<h:dataTable id="hotels" styleClass="summary" value="#{hotels}" var="hotel" rendered="#{hotels.rowCount > 0}">
|
||||
<h:column>
|
||||
<f:facet name="header">Name</f:facet>
|
||||
#{hotel.name}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">Address</f:facet>
|
||||
#{hotel.address}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">City, State</f:facet>
|
||||
#{hotel.city}, #{hotel.state}, #{hotel.country}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">Zip</f:facet>
|
||||
#{hotel.zip}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">Action</f:facet>
|
||||
<sf:commandLink id="viewHotelLink" value="View Hotel" action="selectHotel"/>
|
||||
</h:column>
|
||||
</h:dataTable>
|
||||
<div class="next">
|
||||
<sf:commandLink id="nextPageLink" value="More Results" action="next" rendered="#{not empty hotels and hotels.rowCount == searchCriteria.pageSize}"/>
|
||||
</div>
|
||||
<div class="prev">
|
||||
<sf:commandLink id="prevPageLink" value="Previous results" action="previous" rendered="#{searchCriteria.page > 0}"/>
|
||||
</div>
|
||||
</div>
|
||||
</ui:fragment>
|
||||
</div>
|
||||
</h:form>
|
||||
</ui:define>
|
||||
</ui:composition>
|
||||
@@ -29,7 +29,7 @@
|
||||
</h:selectOneMenu>
|
||||
</div>
|
||||
<div class="searchButton">
|
||||
<sf:commandButton id="findHotels" value="Find Hotels" processIds="hotelSearchFragment" action="findHotels"/>
|
||||
<sf:commandButton id="findHotels" value="Find Hotels" processIds="hotelSearchFragment" action="search"/>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
@@ -31,6 +31,14 @@
|
||||
<constructor-arg ref="flowExecutor" />
|
||||
</bean>
|
||||
|
||||
<bean name="/*" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
|
||||
|
||||
<bean id="jsfViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
|
||||
<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
|
||||
<property name="prefix" value="WEB-INF/" />
|
||||
<property name="suffix" value=".xhtml" />
|
||||
</bean>
|
||||
|
||||
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
|
||||
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
|
||||
<webflow:flow-execution-listeners>
|
||||
|
||||
@@ -23,13 +23,10 @@ public class ImplicitFlowVariableELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public Class getType(ELContext context, Object base, Object property) {
|
||||
if (base != null) {
|
||||
if (base != null || RequestContextHolder.getRequestContext() == null) {
|
||||
return null;
|
||||
}
|
||||
RequestContext requestContext = RequestContextHolder.getRequestContext();
|
||||
if (requestContext == null) {
|
||||
return null;
|
||||
}
|
||||
if (ImplicitVariables.matches(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return ImplicitVariables.value(context, requestContext, property).getClass();
|
||||
@@ -39,7 +36,7 @@ public class ImplicitFlowVariableELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public Object getValue(ELContext context, Object base, Object property) {
|
||||
if (base != null) {
|
||||
if (base != null || RequestContextHolder.getRequestContext() == null) {
|
||||
return null;
|
||||
}
|
||||
RequestContext requestContext = RequestContextHolder.getRequestContext();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ScopeSearchingELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public Class getType(ELContext elContext, Object base, Object property) {
|
||||
if (base != null) {
|
||||
if (base != null || RequestContextHolder.getRequestContext() == null) {
|
||||
return null;
|
||||
}
|
||||
RequestContext requestContext = RequestContextHolder.getRequestContext();
|
||||
@@ -51,7 +51,7 @@ public class ScopeSearchingELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public Object getValue(ELContext elContext, Object base, Object property) {
|
||||
if (base != null) {
|
||||
if (base != null || RequestContextHolder.getRequestContext() == null) {
|
||||
return null;
|
||||
}
|
||||
RequestContext requestContext = RequestContextHolder.getRequestContext();
|
||||
@@ -74,7 +74,7 @@ public class ScopeSearchingELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public boolean isReadOnly(ELContext elContext, Object base, Object property) {
|
||||
if (base != null) {
|
||||
if (base != null || RequestContextHolder.getRequestContext() == null) {
|
||||
return false;
|
||||
}
|
||||
RequestContext requestContext = RequestContextHolder.getRequestContext();
|
||||
@@ -97,7 +97,7 @@ public class ScopeSearchingELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public void setValue(ELContext elContext, Object base, Object property, Object value) {
|
||||
if (base != null) {
|
||||
if (base != null || RequestContextHolder.getRequestContext() == null) {
|
||||
return;
|
||||
}
|
||||
RequestContext requestContext = RequestContextHolder.getRequestContext();
|
||||
|
||||
@@ -4,14 +4,17 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELException;
|
||||
import javax.el.ELResolver;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.FunctionMapper;
|
||||
import javax.el.VariableMapper;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.binding.expression.el.DefaultELResolver;
|
||||
import org.springframework.binding.expression.el.ELContextFactory;
|
||||
import org.springframework.binding.expression.el.ELExpressionParser;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.webflow.core.collection.MutableAttributeMap;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
|
||||
@@ -23,6 +26,10 @@ import org.springframework.webflow.execution.RequestContext;
|
||||
*/
|
||||
public class WebFlowELExpressionParser extends ELExpressionParser {
|
||||
|
||||
private static final String EXPRESSION_FACTORY_PROPERTY = "javax.el.ExpressionFactory";
|
||||
|
||||
private static final String DEFAULT_EXPRESSION_FACTORY = "org.jboss.el.ExpressionFactoryImpl";
|
||||
|
||||
public WebFlowELExpressionParser(ExpressionFactory expressionFactory) {
|
||||
super(expressionFactory);
|
||||
putContextFactory(RequestContext.class, new RequestContextELContextFactory());
|
||||
@@ -34,10 +41,18 @@ public class WebFlowELExpressionParser extends ELExpressionParser {
|
||||
}
|
||||
|
||||
private static ExpressionFactory getDefaultExpressionFactory() {
|
||||
if (!System.getProperties().containsKey("javax.el.ExpressionFactory")) {
|
||||
System.setProperty("javax.el.ExpressionFactory", "org.jboss.el.ExpressionFactoryImpl");
|
||||
if (!System.getProperties().containsKey(EXPRESSION_FACTORY_PROPERTY)) {
|
||||
System.setProperty(EXPRESSION_FACTORY_PROPERTY, DEFAULT_EXPRESSION_FACTORY);
|
||||
}
|
||||
if (ReflectionUtils.findMethod(ExpressionFactory.class, "newInstance") != null) {
|
||||
return ExpressionFactory.newInstance();
|
||||
} else { // Fallback in case using an older version of el-api
|
||||
try {
|
||||
return (ExpressionFactory) BeanUtils.instantiateClass(Class.forName(DEFAULT_EXPRESSION_FACTORY));
|
||||
} catch (Exception e) {
|
||||
throw new ELException("Could not create the default ExpressionFactory", e);
|
||||
}
|
||||
}
|
||||
return ExpressionFactory.newInstance();
|
||||
}
|
||||
|
||||
private static class RequestContextELContextFactory implements ELContextFactory {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.webflow.engine.TransitionCriteria;
|
||||
import org.springframework.webflow.engine.WildcardTransitionCriteria;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.test.MockFlowBuilderContext;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
@@ -66,18 +67,11 @@ public class TextToTransitionCriteriaTests extends TestCase {
|
||||
}
|
||||
|
||||
/*
|
||||
public void testNonBooleanEvaluation() throws Exception {
|
||||
String expression = "${flowScope.foo}";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convert(expression);
|
||||
RequestContext ctx = getRequestContext();
|
||||
try {
|
||||
criterion.test(ctx);
|
||||
fail("Non-boolean evaluations are not allowed");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
*/
|
||||
* public void testNonBooleanEvaluation() throws Exception { String expression = "${flowScope.foo}";
|
||||
* TransitionCriteria criterion = (TransitionCriteria) converter.convert(expression); RequestContext ctx =
|
||||
* getRequestContext(); try { criterion.test(ctx); fail("Non-boolean evaluations are not allowed"); } catch
|
||||
* (IllegalArgumentException e) { // success } }
|
||||
*/
|
||||
|
||||
public void testInvalidSyntax() throws Exception {
|
||||
try {
|
||||
@@ -90,16 +84,12 @@ public class TextToTransitionCriteriaTests extends TestCase {
|
||||
}
|
||||
|
||||
/*
|
||||
public void testEventId() throws Exception {
|
||||
String expression = "${lastEvent.id == 'sample'}";
|
||||
TransitionCriteria criterion = (TransitionCriteria) converter.convert(expression);
|
||||
RequestContext ctx = getRequestContext();
|
||||
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
|
||||
expression = "${#result == 'sample'}";
|
||||
criterion = (TransitionCriteria) converter.convert(expression);
|
||||
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
|
||||
}
|
||||
*/
|
||||
* public void testEventId() throws Exception { String expression = "${lastEvent.id == 'sample'}";
|
||||
* TransitionCriteria criterion = (TransitionCriteria) converter.convert(expression); RequestContext ctx =
|
||||
* getRequestContext(); assertTrue("Criterion should evaluate to true", criterion.test(ctx)); expression =
|
||||
* "${#result == 'sample'}"; criterion = (TransitionCriteria) converter.convert(expression); assertTrue("Criterion
|
||||
* should evaluate to true", criterion.test(ctx)); }
|
||||
*/
|
||||
|
||||
public void testBean() {
|
||||
TransitionCriteria myTransitionCriteria = new TransitionCriteria() {
|
||||
@@ -115,6 +105,7 @@ public class TextToTransitionCriteriaTests extends TestCase {
|
||||
private RequestContext getRequestContext() {
|
||||
Flow flow = new Flow("id");
|
||||
MockRequestContext ctx = new MockRequestContext(flow);
|
||||
RequestContextHolder.setRequestContext(ctx);
|
||||
ctx.getFlowScope().put("foo", "bar");
|
||||
ctx.setLastEvent(new Event(this, "sample"));
|
||||
return ctx;
|
||||
|
||||
Reference in New Issue
Block a user