Code review and cleanup.

This commit is contained in:
Erwin Vervaet
2007-06-13 08:02:35 +00:00
parent 33795c1fe1
commit 7e8bc9a962
5 changed files with 90 additions and 63 deletions

View File

@@ -113,7 +113,11 @@ public class FlowExecutionHolderUtils {
}
}
private static String getFlowExecutionHolderKey() {
/**
* Returns the key used to index the flow execution holder in the request
* attributes.
*/
static String getFlowExecutionHolderKey() {
return FlowExecutionHolder.class.getName();
}
}

View File

@@ -28,11 +28,11 @@ import org.springframework.webflow.context.ExternalContextHolder;
import org.springframework.webflow.execution.FlowExecutionContextHolder;
/**
* A servlet filter used to guarantee that webflow context information is
* A servlet filter used to guarantee that web flow context information is
* cleaned up in a JSF environment.
*
* @author Ben Hale
* @since 1.1
* @since 1.0.4
*/
public class FlowSystemCleanupFilter extends OncePerRequestFilter {
@@ -40,7 +40,8 @@ public class FlowSystemCleanupFilter extends OncePerRequestFilter {
throws ServletException, IOException {
try {
chain.doFilter(request, response);
} finally {
}
finally {
cleanupCurrentFlowExecution(request);
ExternalContextHolder.setExternalContext(null);
}
@@ -58,7 +59,7 @@ public class FlowSystemCleanupFilter extends OncePerRequestFilter {
if (isFlowExecutionRestored(request)) {
FlowExecutionContextHolder.setFlowExecutionContext(null);
getFlowExecutionHolder(request).unlockFlowExecutionIfNecessary();
request.removeAttribute(getFlowExecutionHolderKey());
request.removeAttribute(FlowExecutionHolderUtils.getFlowExecutionHolderKey());
}
}
@@ -78,11 +79,6 @@ public class FlowSystemCleanupFilter extends OncePerRequestFilter {
* @return the flow execution holder, or <code>null</code> if none set.
*/
private FlowExecutionHolder getFlowExecutionHolder(ServletRequest request) {
return (FlowExecutionHolder) request.getAttribute(getFlowExecutionHolderKey());
return (FlowExecutionHolder) request.getAttribute(FlowExecutionHolderUtils.getFlowExecutionHolderKey());
}
private static String getFlowExecutionHolderKey() {
return FlowExecutionHolder.class.getName();
}
}

View File

@@ -32,10 +32,9 @@ import org.springframework.webflow.execution.factory.StaticFlowExecutionListener
import org.springframework.webflow.test.MockFlowServiceLocator;
/**
* Base class for flow integration tests that verify an externalized flow
* definition executes as expected. Supports caching of the flow definition
* built from an externalized resource to speed up test execution.
*
* Base class for flow integration tests that verify an externalized flow definition executes as expected. Supports
* caching of the flow definition built from an externalized resource to speed up test execution.
*
* @author Keith Donald
*/
public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlowExecutionTests {
@@ -46,8 +45,8 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
private static FlowDefinition cachedFlowDefinition;
/**
* The flag indicating if the flow definition built from an externalized
* resource as part of this test should be cached.
* The flag indicating if the flow definition built from an externalized resource as part of this test should be
* cached.
*/
private boolean cacheFlowDefinition = false;
@@ -58,7 +57,7 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
public AbstractExternalizedFlowExecutionTests() {
super();
}
/**
* Constructs an externalized flow execution test with given name.
* @param name the name of the test
@@ -69,13 +68,13 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Internal helper that return the flow execution factory used by the
* test cast to a {@link FlowExecutionImplFactory}.
* Internal helper that returns the flow execution factory used by the test cast to a
* {@link FlowExecutionImplFactory}.
*/
private FlowExecutionImplFactory getFlowExecutionImplFactory() {
return (FlowExecutionImplFactory)getFlowExecutionFactory();
return (FlowExecutionImplFactory) getFlowExecutionFactory();
}
/**
* Returns if flow definition caching is turned on.
*/
@@ -84,18 +83,16 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Sets the flag indicating if the flow definition built from an
* externalized resource as part of this test should be cached.
* Default is false.
* Sets the flag indicating if the flow definition built from an externalized resource as part of this test should
* be cached. Default is false.
*/
protected void setCacheFlowDefinition(boolean cacheFlowDefinition) {
this.cacheFlowDefinition = cacheFlowDefinition;
}
/**
* Sets system attributes to be associated with the flow execution the next
* time one is {@link #startFlow() started} by this test. Useful for
* assigning attributes that influence flow execution behavior.
* Sets system attributes to be associated with the flow execution the next time one is {@link #startFlow() started}
* by this test. Useful for assigning attributes that influence flow execution behavior.
* @param executionAttributes the system attributes to assign
*/
protected void setFlowExecutionAttributes(AttributeMap executionAttributes) {
@@ -103,27 +100,29 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Set the listener to be attached to the flow execution the next time one
* is {@link #startFlow() started} by this test. Useful for attaching a
* listener that does test assertions during the execution of the flow.
* Set a single listener to be attached to the flow execution the next time one is {@link #startFlow() started} by
* this test. Useful for attaching a listener that does test assertions during the execution of the flow.
* @param executionListener the listener to attach
*/
protected void setFlowExecutionListener(FlowExecutionListener executionListener) {
getFlowExecutionImplFactory().setExecutionListenerLoader(
new StaticFlowExecutionListenerLoader(executionListener));
}
/**
* Set the listeners to be attached to the flow execution the next time one
* is {@link #startFlow() started} by this test. Useful for attaching
* listeners that do test assertions during the execution of the flow.
* Set the listeners to be attached to the flow execution the next time one is {@link #startFlow() started} by this
* test. Useful for attaching listeners that do test assertions during the execution of the flow.
* @param executionListeners the listeners to attach
* @since 1.0.4
*/
protected void setFlowExecutionListeners(FlowExecutionListener[] executionListeners) {
getFlowExecutionImplFactory().setExecutionListenerLoader(
new StaticFlowExecutionListenerLoader(executionListeners));
}
/**
* Returns the flow definition being tested.
*/
protected final FlowDefinition getFlowDefinition() {
if (isCacheFlowDefinition() && cachedFlowDefinition != null) {
return cachedFlowDefinition;
@@ -137,12 +136,11 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Returns the flow artifact factory to use during flow definition
* construction time for accessing externally managed flow artifacts such as
* actions and flows to be used as subflows.
* Returns the flow service locator to use during flow definition construction time for accessing externally
* managed flow artifacts such as actions and flows to be used as subflows.
* <p>
* This implementation just creates a {@link MockFlowServiceLocator} and
* populates it with services by calling {@link #registerMockServices(MockFlowServiceLocator)}.
* This implementation just creates a {@link MockFlowServiceLocator} and populates it with services by calling
* {@link #registerMockServices(MockFlowServiceLocator)}.
* @return the flow artifact factory
*/
protected FlowServiceLocator createFlowServiceLocator() {
@@ -152,20 +150,18 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Template method called by {@link #createFlowServiceLocator()} to allow
* registration of mock implementations of services needed to test the flow
* execution. Useful when testing flow definitions in execution in isolation
* from flows and middle-tier services. Subclasses may override.
* Template method called by {@link #createFlowServiceLocator()} to allow registration of mock implementations of
* services needed to test the flow execution. Useful when testing flow definitions in execution in isolation from
* flows and middle-tier services. Subclasses may override.
* @param serviceRegistry the mock service registry (and locator)
*/
protected void registerMockServices(MockFlowServiceLocator serviceRegistry) {
}
/**
* Factory method to assemble another flow definition from a resource.
* Called by {@link #getFlowDefinition()} to create the "main" flow to test.
* May also be called by subclasses to create subflow definitions whose
* executions should also be exercised by this test.
* Factory method to assemble a flow definition from a resource. Called by {@link #getFlowDefinition()} to
* create the "main" flow to test. May also be called by subclasses to create subflow definitions whose executions
* should also be exercised by this test.
* @param resource the flow definition resource
* @return the built flow definition, ready for execution
* @see #createFlowBuilder(Resource, FlowServiceLocator)
@@ -177,22 +173,25 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Returns the pointer to the resource that houses the definition of the
* flow to be tested. Subclasses must implement.
* Returns the pointer to the resource that houses the definition of the flow to be tested. Subclasses must
* implement.
* <p>
* Example usage:
* <pre class="code">
* protected FlowDefinitionResource getFlowDefinitionResource() {
* return createFlowDefinitionResource(&quot;/WEB-INF/flows/order-flow.xml&quot;);
* }
* protected FlowDefinitionResource getFlowDefinitionResource() {
* return createFlowDefinitionResource(&quot;/WEB-INF/flows/order-flow.xml&quot;);
* }
* </pre>
* @return the flow definition resource
*/
protected abstract FlowDefinitionResource getFlowDefinitionResource();
/**
* Factory method to create the builder that will build the flow whose
* execution will be tested. Subclasses must override.
* Factory method to create the builder that will build the flow definition whose execution will be tested.
* Subclasses must implement.
* <p>
* A subclass may return a builder that sets up mock implementations of services needed locally by the flow
* definition at runtime.
* @param resource the externalized flow definition resource location
* @param serviceLocator the flow service locator
* @return the flow builder that will build the flow to be tested
@@ -200,9 +199,8 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
protected abstract FlowBuilder createFlowBuilder(Resource resource, FlowServiceLocator serviceLocator);
/**
* Convenient factory method that creates a {@link FlowDefinitionResource}
* from a file path. Typically called by subclasses overriding
* {@link #getFlowDefinitionResource()}.
* Convenient factory method that creates a {@link FlowDefinitionResource} from a file path. Typically called by
* subclasses overriding {@link #getFlowDefinitionResource()}.
* @param filePath the full path to the externalized flow definition file
* @return the flow definition resource
*/
@@ -211,9 +209,8 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Convenient factory method that creates a {@link FlowDefinitionResource}
* from a file in a directory. Typically called by subclasses overriding
* {@link #getFlowDefinitionResource()}.
* Convenient factory method that creates a {@link FlowDefinitionResource} from a file in a directory. Typically
* called by subclasses overriding {@link #getFlowDefinitionResource()}.
* @param fileDirectory the directory containing the file
* @param fileName the short file name
* @return the flow definition resource pointing to the file
@@ -223,8 +220,8 @@ public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlo
}
/**
* Convenient factory method that creates a {@link FlowDefinitionResource}
* from a file.
* Convenient factory method that creates a {@link FlowDefinitionResource} from a file. Typically
* called by subclasses overriding {@link #getFlowDefinitionResource()}.
* @param file the file
* @return the flow definition resource
*/

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2004-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.webflow.executor.jsf;
import java.io.IOException;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2004-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.webflow.support.persistence;
public class TestBean {