view state tests
polish
This commit is contained in:
@@ -1,17 +1,8 @@
|
||||
package org.springframework.binding.message;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CachingMapDecorator;
|
||||
|
||||
/**
|
||||
* Default message context factory that simply stores messages indexed in a map by their source. Suitable for use in
|
||||
@@ -34,55 +25,6 @@ public class DefaultMessageContextFactory implements MessageContextFactory {
|
||||
}
|
||||
|
||||
public StateManageableMessageContext createMessageContext() {
|
||||
return new MessageContextImpl(messageSource);
|
||||
}
|
||||
|
||||
private static class MessageContextImpl implements StateManageableMessageContext {
|
||||
|
||||
private MessageSource messageSource;
|
||||
|
||||
private Map objectMessages = new CachingMapDecorator() {
|
||||
protected Object create(Object objectId) {
|
||||
return new ArrayList();
|
||||
}
|
||||
};
|
||||
|
||||
public MessageContextImpl(MessageSource messageSource) {
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public Serializable createMessagesMemento() {
|
||||
return new HashMap(objectMessages);
|
||||
}
|
||||
|
||||
public void restoreMessages(Serializable messagesMemento) {
|
||||
this.objectMessages.putAll((Map) messagesMemento);
|
||||
}
|
||||
|
||||
public void addMessage(MessageResolver messageResolver) {
|
||||
Locale currentLocale = LocaleContextHolder.getLocale();
|
||||
Message message = messageResolver.resolveMessage(messageSource, currentLocale);
|
||||
List messages = (List) objectMessages.get(message.getSource());
|
||||
messages.add(message);
|
||||
}
|
||||
|
||||
public Message[] getMessages() {
|
||||
List messages = new ArrayList();
|
||||
Iterator i = objectMessages.keySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
messages.addAll((List) objectMessages.get(i.next()));
|
||||
}
|
||||
return (Message[]) messages.toArray(new Message[messages.size()]);
|
||||
}
|
||||
|
||||
public Message[] getMessages(Object source) {
|
||||
List messages = (List) objectMessages.get(source);
|
||||
return (Message[]) messages.toArray(new Message[messages.size()]);
|
||||
}
|
||||
|
||||
public void clearMessages() {
|
||||
objectMessages.clear();
|
||||
}
|
||||
|
||||
return new DefaultMessageContext(messageSource);
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,11 @@ package org.springframework.webflow.engine;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.webflow.TestBean;
|
||||
import org.springframework.webflow.engine.support.ActionTransitionCriteria;
|
||||
import org.springframework.webflow.engine.support.DefaultTargetStateResolver;
|
||||
import org.springframework.webflow.engine.support.EventIdTransitionCriteria;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.TestAction;
|
||||
import org.springframework.webflow.test.MockRequestControlContext;
|
||||
|
||||
/**
|
||||
@@ -166,6 +168,24 @@ public class ViewStateTests extends TestCase {
|
||||
assertFalse(context.getFlowExecutionContext().isActive());
|
||||
}
|
||||
|
||||
public void testResumeViewStateForEventStateNotExited() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
ViewState state = new ViewState(flow, "viewState", viewFactory);
|
||||
Transition t = new Transition(on("submit"), null);
|
||||
TestAction action = new TestAction();
|
||||
t.setExecutionCriteria(new ActionTransitionCriteria(action));
|
||||
state.getTransitionSet().add(t);
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
state.enter(context);
|
||||
context = new MockRequestControlContext(context.getFlowExecutionContext());
|
||||
context.putRequestParameter("_eventId", "submit");
|
||||
state.resume(context);
|
||||
assertTrue(context.getFlowExecutionContext().isActive());
|
||||
assertEquals(1, action.getExecutionCount());
|
||||
assertTrue("Render not called", context.getFlowScope().contains("renderCalled"));
|
||||
}
|
||||
|
||||
public void testResumeViewStateForEventDestroyVariables() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
StubViewFactory viewFactory = new StubViewFactory();
|
||||
|
||||
Reference in New Issue
Block a user