1 16 package org.springframework.webflow.test.execution; 17 18 import java.io.File ; 19 20 import org.springframework.core.io.FileSystemResource; 21 import org.springframework.core.io.Resource; 22 import org.springframework.webflow.core.collection.AttributeMap; 23 import org.springframework.webflow.definition.FlowDefinition; 24 import org.springframework.webflow.definition.registry.FlowDefinitionResource; 25 import org.springframework.webflow.engine.Flow; 26 import org.springframework.webflow.engine.builder.FlowAssembler; 27 import org.springframework.webflow.engine.builder.FlowBuilder; 28 import org.springframework.webflow.engine.builder.FlowServiceLocator; 29 import org.springframework.webflow.engine.impl.FlowExecutionImplFactory; 30 import org.springframework.webflow.execution.FlowExecutionListener; 31 import org.springframework.webflow.execution.factory.StaticFlowExecutionListenerLoader; 32 import org.springframework.webflow.test.MockFlowServiceLocator; 33 34 41 public abstract class AbstractExternalizedFlowExecutionTests extends AbstractFlowExecutionTests { 42 43 46 private static FlowDefinition cachedFlowDefinition; 47 48 52 private boolean cacheFlowDefinition = false; 53 54 58 private FlowExecutionImplFactory getFlowExecutionImplFactory() { 59 return (FlowExecutionImplFactory)getFlowExecutionFactory(); 60 } 61 62 65 protected boolean isCacheFlowDefinition() { 66 return cacheFlowDefinition; 67 } 68 69 74 protected void setCacheFlowDefinition(boolean cacheFlowDefinition) { 75 this.cacheFlowDefinition = cacheFlowDefinition; 76 } 77 78 84 protected void setFlowExecutionAttributes(AttributeMap executionAttributes) { 85 getFlowExecutionImplFactory().setExecutionAttributes(executionAttributes); 86 } 87 88 94 protected void setFlowExecutionListener(FlowExecutionListener executionListener) { 95 getFlowExecutionImplFactory().setExecutionListenerLoader( 96 new StaticFlowExecutionListenerLoader(executionListener)); 97 } 98 99 protected final FlowDefinition getFlowDefinition() { 100 if (isCacheFlowDefinition() && cachedFlowDefinition != null) { 101 return cachedFlowDefinition; 102 } 103 FlowServiceLocator flowServiceLocator = createFlowServiceLocator(); 104 Flow flow = createFlow(getFlowDefinitionResource(), flowServiceLocator); 105 if (isCacheFlowDefinition()) { 106 cachedFlowDefinition = flow; 107 } 108 return flow; 109 } 110 111 120 protected FlowServiceLocator createFlowServiceLocator() { 121 MockFlowServiceLocator serviceLocator = new MockFlowServiceLocator(); 122 registerMockServices(serviceLocator); 123 return serviceLocator; 124 } 125 126 133 protected void registerMockServices(MockFlowServiceLocator serviceRegistry) { 134 } 135 136 145 protected final Flow createFlow(FlowDefinitionResource resource, FlowServiceLocator serviceLocator) { 146 FlowBuilder builder = createFlowBuilder(resource.getLocation(), serviceLocator); 147 FlowAssembler assembler = new FlowAssembler(resource.getId(), resource.getAttributes(), builder); 148 return assembler.assembleFlow(); 149 } 150 151 163 protected abstract FlowDefinitionResource getFlowDefinitionResource(); 164 165 172 protected abstract FlowBuilder createFlowBuilder(Resource resource, FlowServiceLocator serviceLocator); 173 174 181 protected final FlowDefinitionResource createFlowDefinitionResource(String filePath) { 182 return createFlowDefinitionResource(new File (filePath)); 183 } 184 185 193 protected final FlowDefinitionResource createFlowDefinitionResource(String fileDirectory, String fileName) { 194 return createFlowDefinitionResource(new File (fileDirectory, fileName)); 195 } 196 197 203 protected FlowDefinitionResource createFlowDefinitionResource(File file) { 204 return new FlowDefinitionResource(new FileSystemResource(file)); 205 } 206 } | Popular Tags |