1 16 package org.springframework.webflow.test; 17 18 import org.springframework.webflow.core.collection.AttributeMap; 19 import org.springframework.webflow.core.collection.LocalAttributeMap; 20 import org.springframework.webflow.core.collection.MutableAttributeMap; 21 import org.springframework.webflow.definition.FlowDefinition; 22 import org.springframework.webflow.engine.Flow; 23 import org.springframework.webflow.execution.FlowExecutionContext; 24 import org.springframework.webflow.execution.FlowSession; 25 26 33 public class MockFlowExecutionContext implements FlowExecutionContext { 34 35 private FlowDefinition flow; 36 37 private FlowSession activeSession; 38 39 private MutableAttributeMap conversationScope = new LocalAttributeMap(); 40 41 private MutableAttributeMap attributes = new LocalAttributeMap(); 42 43 47 public MockFlowExecutionContext() { 48 activeSession = new MockFlowSession(); 49 this.flow = activeSession.getDefinition(); 50 } 51 52 56 public MockFlowExecutionContext(Flow rootFlow) { 57 this.flow = rootFlow; 58 activeSession = new MockFlowSession(rootFlow); 59 } 60 61 public String getCaption() { 62 return "Mock flow execution context"; 63 } 64 65 67 public FlowDefinition getDefinition() { 68 return flow; 69 } 70 71 public boolean isActive() { 72 return activeSession != null; 73 } 74 75 public FlowSession getActiveSession() throws IllegalStateException { 76 if (activeSession == null) { 77 throw new IllegalStateException ("No flow session is active"); 78 } 79 return activeSession; 80 } 81 82 public MutableAttributeMap getConversationScope() { 83 return conversationScope; 84 } 85 86 public AttributeMap getAttributes() { 87 return attributes; 88 } 89 90 92 95 public void setFlow(Flow rootFlow) { 96 this.flow = rootFlow; 97 } 98 99 102 public void setActiveSession(FlowSession activeSession) { 103 this.activeSession = activeSession; 104 } 105 106 109 public void setConversationScope(MutableAttributeMap scope) { 110 this.conversationScope = scope; 111 } 112 113 115 118 public MockFlowSession getMockActiveSession() { 119 return (MockFlowSession)activeSession; 120 } 121 122 126 public MutableAttributeMap getAttributeMap() { 127 return attributes; 128 } 129 130 135 public void putAttribute(String attributeName, Object attributeValue) { 136 attributes.put(attributeName, attributeValue); 137 } 138 } | Popular Tags |