01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.webflow.test.execution;
17:
18: import org.springframework.beans.factory.config.ConfigurableBeanFactory;
19: import org.springframework.core.io.Resource;
20: import org.springframework.webflow.engine.Flow;
21: import org.springframework.webflow.engine.builder.FlowBuilder;
22: import org.springframework.webflow.engine.builder.FlowServiceLocator;
23: import org.springframework.webflow.engine.builder.xml.XmlFlowBuilder;
24:
25: /**
26: * Base class for flow integration tests that verify an XML flow definition
27: * executes as expected.
28: * <p>
29: * Example usage:
30: *
31: * <pre>
32: * public class SearchFlowExecutionTests extends AbstractXmlFlowExecutionTests {
33: *
34: * protected FlowDefinitionResource getFlowDefinitionResource() {
35: * return createFlowDefinitionResource("src/main/webapp/WEB-INF/flows/search-flow.xml");
36: * }
37: *
38: * public void testStartFlow() {
39: * startFlow();
40: * assertCurrentStateEquals("displaySearchCriteria");
41: * }
42: *
43: * public void testDisplayCriteriaSubmitSuccess() {
44: * startFlow();
45: * MockParameterMap parameters = new MockParameterMap();
46: * parameters.put("firstName", "Keith");
47: * parameters.put("lastName", "Donald");
48: * ViewSelection view = signalEvent("search", parameters);
49: * assertCurrentStateEquals("displaySearchResults");
50: * assertModelAttributeCollectionSize(1, "results", view);
51: * }
52: * }
53: * </pre>
54: *
55: * @author Keith Donald
56: * @author Erwin Vervaet
57: */
58: public abstract class AbstractXmlFlowExecutionTests extends
59: AbstractExternalizedFlowExecutionTests {
60:
61: /**
62: * Constructs a default XML flow execution test.
63: * @see #setName(String)
64: */
65: public AbstractXmlFlowExecutionTests() {
66: super ();
67: }
68:
69: /**
70: * Constructs an XML flow execution test with given name.
71: * @param name the name of the test
72: * @since 1.0.2
73: */
74: public AbstractXmlFlowExecutionTests(String name) {
75: super (name);
76: }
77:
78: protected FlowBuilder createFlowBuilder(Resource resource,
79: FlowServiceLocator flowServiceLocator) {
80: return new XmlFlowBuilder(resource, flowServiceLocator) {
81: protected void registerLocalBeans(Flow flow,
82: ConfigurableBeanFactory beanFactory) {
83: registerLocalMockServices(flow, beanFactory);
84: }
85: };
86: }
87:
88: /**
89: * Template method subclasses may override to register mock implementations of
90: * services used locally by the flow being tested.
91: * @param flow the flow to register the services for
92: * @param beanFactory the local flow service registry; register mock services with it
93: * using {@link ConfigurableBeanFactory#registerSingleton(String, Object)}
94: * @since 1.0.4
95: */
96: protected void registerLocalMockServices(Flow flow,
97: ConfigurableBeanFactory beanFactory) {
98: }
99: }
|