From 90cdec76e73ae8809d05916cd0542e62e893e367 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Tue, 13 May 2008 15:05:31 +0000 Subject: [PATCH] mock transition criteria --- .../support/TextToTransitionCriteria.java | 10 +-- .../webflow/engine/ActionStateTests.java | 4 +- .../webflow/engine/DecisionStateTests.java | 10 +-- .../webflow/engine/EndStateTests.java | 4 +- .../webflow/engine/FlowTests.java | 4 +- .../webflow/engine/SubflowStateTests.java | 4 +- .../webflow/engine/ViewStateTests.java | 4 +- .../support/EventIdTransitionCriteria.java | 84 ------------------- .../EventIdTransitionCriteriaTests.java | 56 ------------- 9 files changed, 19 insertions(+), 161 deletions(-) delete mode 100644 spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteria.java delete mode 100644 spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteriaTests.java diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java index 19ea034b..387730d0 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java @@ -33,12 +33,10 @@ import org.springframework.webflow.execution.RequestContext; *

* This converter supports the following encoded forms: *

* * @see org.springframework.webflow.engine.TransitionCriteria diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/ActionStateTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/ActionStateTests.java index adcbb9df..ab85bc00 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/ActionStateTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/ActionStateTests.java @@ -18,7 +18,7 @@ package org.springframework.webflow.engine; import junit.framework.TestCase; import org.springframework.webflow.engine.support.DefaultTargetStateResolver; -import org.springframework.webflow.engine.support.EventIdTransitionCriteria; +import org.springframework.webflow.engine.support.MockTransitionCriteria; import org.springframework.webflow.execution.Action; import org.springframework.webflow.execution.TestAction; import org.springframework.webflow.test.MockRequestControlContext; @@ -81,7 +81,7 @@ public class ActionStateTests extends TestCase { } protected TransitionCriteria on(String event) { - return new EventIdTransitionCriteria(event); + return new MockTransitionCriteria(event); } protected TargetStateResolver to(String stateId) { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/DecisionStateTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/DecisionStateTests.java index 8a142d5b..d967384e 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/DecisionStateTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/DecisionStateTests.java @@ -18,7 +18,7 @@ package org.springframework.webflow.engine; import junit.framework.TestCase; import org.springframework.webflow.engine.support.DefaultTargetStateResolver; -import org.springframework.webflow.engine.support.EventIdTransitionCriteria; +import org.springframework.webflow.engine.support.MockTransitionCriteria; import org.springframework.webflow.execution.Event; import org.springframework.webflow.test.MockRequestControlContext; @@ -32,7 +32,7 @@ public class DecisionStateTests extends TestCase { public void testIfDecision() { Flow flow = new Flow("flow"); DecisionState state = new DecisionState(flow, "decisionState"); - state.getTransitionSet().add(new Transition(new EventIdTransitionCriteria("foo"), to("target"))); + state.getTransitionSet().add(new Transition(new MockTransitionCriteria("foo"), to("target"))); new EndState(flow, "target"); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentEvent(new Event(this, "foo")); @@ -43,7 +43,7 @@ public class DecisionStateTests extends TestCase { public void testElseDecision() { Flow flow = new Flow("flow"); DecisionState state = new DecisionState(flow, "decisionState"); - state.getTransitionSet().add(new Transition(new EventIdTransitionCriteria("foo"), to("invalid"))); + state.getTransitionSet().add(new Transition(new MockTransitionCriteria("foo"), to("invalid"))); state.getTransitionSet().add(new Transition(to("target"))); new EndState(flow, "target"); MockRequestControlContext context = new MockRequestControlContext(flow); @@ -55,8 +55,8 @@ public class DecisionStateTests extends TestCase { public void testCannotDecide() { Flow flow = new Flow("flow"); DecisionState state = new DecisionState(flow, "decisionState"); - state.getTransitionSet().add(new Transition(new EventIdTransitionCriteria("foo"), to("invalid"))); - state.getTransitionSet().add(new Transition(new EventIdTransitionCriteria("bar"), to("invalid"))); + state.getTransitionSet().add(new Transition(new MockTransitionCriteria("foo"), to("invalid"))); + state.getTransitionSet().add(new Transition(new MockTransitionCriteria("bar"), to("invalid"))); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentEvent(new Event(this, "bogus")); try { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/EndStateTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/EndStateTests.java index aa9da90f..1c0176bf 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/EndStateTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/EndStateTests.java @@ -26,7 +26,7 @@ import org.springframework.binding.mapping.impl.DefaultMapper; import org.springframework.binding.mapping.impl.DefaultMapping; import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.engine.support.DefaultTargetStateResolver; -import org.springframework.webflow.engine.support.EventIdTransitionCriteria; +import org.springframework.webflow.engine.support.MockTransitionCriteria; import org.springframework.webflow.execution.Action; import org.springframework.webflow.execution.Event; import org.springframework.webflow.execution.FlowExecutionException; @@ -103,7 +103,7 @@ public class EndStateTests extends TestCase { } protected static TransitionCriteria on(String event) { - return new EventIdTransitionCriteria(event); + return new MockTransitionCriteria(event); } protected static TargetStateResolver to(String stateId) { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/FlowTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/FlowTests.java index b11651eb..3b9f6acb 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/FlowTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/FlowTests.java @@ -30,7 +30,7 @@ import org.springframework.webflow.core.collection.AttributeMap; import org.springframework.webflow.core.collection.LocalAttributeMap; import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.engine.support.DefaultTargetStateResolver; -import org.springframework.webflow.engine.support.EventIdTransitionCriteria; +import org.springframework.webflow.engine.support.MockTransitionCriteria; import org.springframework.webflow.engine.support.TransitionExecutingFlowExecutionExceptionHandler; import org.springframework.webflow.execution.Event; import org.springframework.webflow.execution.FlowExecutionException; @@ -349,7 +349,7 @@ public class FlowTests extends TestCase { } public TransitionCriteria on(String eventId) { - return new EventIdTransitionCriteria(eventId); + return new MockTransitionCriteria(eventId); } protected TargetStateResolver to(String stateId) { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/SubflowStateTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/SubflowStateTests.java index 7aeea206..9dd10b85 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/SubflowStateTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/SubflowStateTests.java @@ -28,7 +28,7 @@ import org.springframework.webflow.core.collection.AttributeMap; import org.springframework.webflow.core.collection.LocalAttributeMap; import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.engine.support.DefaultTargetStateResolver; -import org.springframework.webflow.engine.support.EventIdTransitionCriteria; +import org.springframework.webflow.engine.support.MockTransitionCriteria; import org.springframework.webflow.execution.FlowExecutionException; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.test.MockRequestControlContext; @@ -118,7 +118,7 @@ public class SubflowStateTests extends TestCase { } protected TransitionCriteria on(String event) { - return new EventIdTransitionCriteria(event); + return new MockTransitionCriteria(event); } protected TargetStateResolver to(String stateId) { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java index 2ecbfff6..d33538c3 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java @@ -20,7 +20,7 @@ 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.engine.support.MockTransitionCriteria; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.execution.TestAction; import org.springframework.webflow.test.MockRequestControlContext; @@ -212,7 +212,7 @@ public class ViewStateTests extends TestCase { } protected TransitionCriteria on(String event) { - return new EventIdTransitionCriteria(event); + return new MockTransitionCriteria(event); } protected TargetStateResolver to(String stateId) { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteria.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteria.java deleted file mode 100644 index 02e2d617..00000000 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteria.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2004-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.webflow.engine.support; - -import java.io.Serializable; - -import org.springframework.util.Assert; -import org.springframework.webflow.engine.TransitionCriteria; -import org.springframework.webflow.execution.Event; -import org.springframework.webflow.execution.RequestContext; - -/** - * Simple transition criteria that matches on an eventId and nothing else. Specifically, if the id of the last event - * that occurred equals {@link #getEventId()} this criteria will return true. - * - * @see RequestContext#getCurrentEvent() - * - * @author Erwin Vervaet - * @author Keith Donald - */ -public class EventIdTransitionCriteria implements TransitionCriteria, Serializable { - - /** - * The event id to match. - */ - private String eventId; - - /** - * Whether or not to match case sensitively. Default is true. - */ - private boolean caseSensitive = true; - - /** - * Create a new event id matching criteria object. - * @param eventId the event id - */ - public EventIdTransitionCriteria(String eventId) { - Assert.hasText(eventId, "The event id is required"); - this.eventId = eventId; - } - - /** - * Returns the event id to match. - */ - public String getEventId() { - return eventId; - } - - /** - * Set whether or not the event id should be matched in a case sensitive manner. Defaults to true. - */ - public void setCaseSensitive(boolean caseSensitive) { - this.caseSensitive = caseSensitive; - } - - public boolean test(RequestContext context) { - Event currentEvent = context.getCurrentEvent(); - if (currentEvent == null) { - return false; - } - if (caseSensitive) { - return eventId.equals(currentEvent.getId()); - } else { - return eventId.equalsIgnoreCase(currentEvent.getId()); - } - } - - public String toString() { - return "[eventId = '" + eventId + "']"; - } -} \ No newline at end of file diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteriaTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteriaTests.java deleted file mode 100644 index c10ed90f..00000000 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/support/EventIdTransitionCriteriaTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2004-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.webflow.engine.support; - -import junit.framework.TestCase; - -import org.springframework.webflow.execution.Event; -import org.springframework.webflow.test.MockRequestContext; - -public class EventIdTransitionCriteriaTests extends TestCase { - public void testTestCriteria() { - EventIdTransitionCriteria c = new EventIdTransitionCriteria("foo"); - MockRequestContext context = new MockRequestContext(); - context.setCurrentEvent(new Event(this, "foo")); - assertEquals(true, c.test(context)); - context.setCurrentEvent(new Event(this, "FOO")); - assertEquals(false, c.test(context)); // case sensitive - context.setCurrentEvent(new Event(this, "bar")); - assertEquals(false, c.test(context)); - } - - public void testNullLastEventId() { - EventIdTransitionCriteria c = new EventIdTransitionCriteria("foo"); - MockRequestContext context = new MockRequestContext(); - context.setCurrentEvent(null); - assertEquals(false, c.test(context)); - } - - public void testIllegalArg() { - try { - new EventIdTransitionCriteria(null); - fail("was null"); - } catch (IllegalArgumentException e) { - - } - try { - new EventIdTransitionCriteria(""); - fail("was blank"); - } catch (IllegalArgumentException e) { - - } - } -}