1 16 package org.springframework.webflow.test; 17 18 import org.springframework.webflow.context.ExternalContext; 19 import org.springframework.webflow.core.collection.AttributeMap; 20 import org.springframework.webflow.core.collection.LocalAttributeMap; 21 import org.springframework.webflow.core.collection.MutableAttributeMap; 22 import org.springframework.webflow.core.collection.ParameterMap; 23 import org.springframework.webflow.definition.FlowDefinition; 24 import org.springframework.webflow.definition.StateDefinition; 25 import org.springframework.webflow.definition.TransitionDefinition; 26 import org.springframework.webflow.engine.Flow; 27 import org.springframework.webflow.engine.Transition; 28 import org.springframework.webflow.execution.Event; 29 import org.springframework.webflow.execution.FlowExecutionContext; 30 import org.springframework.webflow.execution.FlowSession; 31 import org.springframework.webflow.execution.RequestContext; 32 33 43 public class MockRequestContext implements RequestContext { 44 45 private FlowExecutionContext flowExecutionContext = new MockFlowExecutionContext(); 46 47 private ExternalContext externalContext = new MockExternalContext(); 48 49 private MutableAttributeMap requestScope = new LocalAttributeMap(); 50 51 private Event lastEvent; 52 53 private Transition lastTransition; 54 55 private MutableAttributeMap attributes = new LocalAttributeMap(); 56 57 67 public MockRequestContext() { 68 } 69 70 79 public MockRequestContext(Flow flow) { 80 flowExecutionContext = new MockFlowExecutionContext(flow); 81 } 82 83 91 public MockRequestContext(ParameterMap requestParameterMap) { 92 externalContext = new MockExternalContext(requestParameterMap); 93 } 94 95 97 public FlowDefinition getActiveFlow() { 98 return getFlowExecutionContext().getActiveSession().getDefinition(); 99 } 100 101 public StateDefinition getCurrentState() { 102 return getFlowExecutionContext().getActiveSession().getState(); 103 } 104 105 public MutableAttributeMap getRequestScope() { 106 return requestScope; 107 } 108 109 public MutableAttributeMap getFlashScope() { 110 return getMockFlowExecutionContext().getActiveSession().getFlashMap(); 111 } 112 113 public MutableAttributeMap getFlowScope() { 114 return getFlowExecutionContext().getActiveSession().getScope(); 115 } 116 117 public MutableAttributeMap getConversationScope() { 118 return getMockFlowExecutionContext().getConversationScope(); 119 } 120 121 public ParameterMap getRequestParameters() { 122 return externalContext.getRequestParameterMap(); 123 } 124 125 public ExternalContext getExternalContext() { 126 return externalContext; 127 } 128 129 public FlowExecutionContext getFlowExecutionContext() { 130 return flowExecutionContext; 131 } 132 133 public Event getLastEvent() { 134 return lastEvent; 135 } 136 137 public TransitionDefinition getLastTransition() { 138 return lastTransition; 139 } 140 141 public AttributeMap getAttributes() { 142 return attributes; 143 } 144 145 public void setAttributes(AttributeMap attributes) { 146 this.attributes.replaceWith(attributes); 147 } 148 149 public AttributeMap getModel() { 150 return getConversationScope().union(getFlowScope()).union(getFlashScope()).union(getRequestScope()); 151 } 152 153 155 160 public void setActiveSession(FlowSession flowSession) { 161 getMockFlowExecutionContext().setActiveSession(flowSession); 162 } 163 164 167 public void setExternalContext(ExternalContext externalContext) { 168 this.externalContext = externalContext; 169 } 170 171 174 public void setFlowExecutionContext(FlowExecutionContext flowExecutionContext) { 175 this.flowExecutionContext = flowExecutionContext; 176 } 177 178 182 public void setLastEvent(Event lastEvent) { 183 this.lastEvent = lastEvent; 184 } 185 186 190 public void setLastTransition(Transition lastTransition) { 191 this.lastTransition = lastTransition; 192 } 193 194 199 public void setAttribute(String attributeName, Object attributeValue) { 200 attributes.put(attributeName, attributeValue); 201 } 202 203 207 public void removeAttribute(String attributeName) { 208 attributes.remove(attributeName); 209 } 210 211 213 218 public MutableAttributeMap getAttributeMap() { 219 return attributes; 220 } 221 222 225 public MockFlowExecutionContext getMockFlowExecutionContext() { 226 return (MockFlowExecutionContext)flowExecutionContext; 227 } 228 229 232 public MockExternalContext getMockExternalContext() { 233 return (MockExternalContext)externalContext; 234 } 235 236 241 public void putRequestParameter(String parameterName, String parameterValue) { 242 getMockExternalContext().putRequestParameter(parameterName, parameterValue); 243 } 244 245 250 public void putRequestParameter(String parameterName, String [] parameterValues) { 251 getMockExternalContext().putRequestParameter(parameterName, parameterValues); 252 } 253 } | Popular Tags |