From c2276ee13457feab079237dc2b593720e920ad45 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 5 Mar 2008 21:28:25 +0000 Subject: [PATCH] test --- .../support/ActionTransitionCriteria.java | 29 +++++++---- .../ActionTransitionCriteriaTests.java | 51 ++++++++----------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/support/ActionTransitionCriteria.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/support/ActionTransitionCriteria.java index e4672f12..7edd5c67 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/support/ActionTransitionCriteria.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/support/ActionTransitionCriteria.java @@ -15,7 +15,6 @@ */ package org.springframework.webflow.engine.support; -import org.springframework.util.Assert; import org.springframework.webflow.engine.ActionExecutor; import org.springframework.webflow.engine.TransitionCriteria; import org.springframework.webflow.execution.Action; @@ -39,7 +38,7 @@ public class ActionTransitionCriteria implements TransitionCriteria { /** * The result event id that should map to a true return value. */ - private String trueEventId = "success"; + private String[] trueEventIds = new String[] { "success", "yes", "true" }; /** * The action to execute when the criteria is tested, annotated with usage attributes. @@ -55,21 +54,20 @@ public class ActionTransitionCriteria implements TransitionCriteria { } /** - * Returns the action result eventId that should cause this criteria to return true (it will return + * Returns the action result eventIds that should cause this criteria to return true (it will return * false otherwise). Defaults to "success". */ - public String getTrueEventId() { - return trueEventId; + public String[] getTrueEventIds() { + return trueEventIds; } /** - * Sets the action result eventId that should cause this precondition to return true (it will return + * Sets the action result eventIds that should cause this precondition to return true (it will return * false otherwise). - * @param trueEventId the true result event ID + * @param trueEventIds the true result event IDs */ - public void setTrueEventId(String trueEventId) { - Assert.notNull(trueEventId, "The trueEventId is required"); - this.trueEventId = trueEventId; + public void setTrueEventIds(String[] trueEventIds) { + this.trueEventIds = trueEventIds; } /** @@ -82,6 +80,15 @@ public class ActionTransitionCriteria implements TransitionCriteria { public boolean test(RequestContext context) { Event result = ActionExecutor.execute(getAction(), context); - return result != null && getTrueEventId().equals(result.getId()); + return result != null && isTrueEvent(result.getId()); + } + + private boolean isTrueEvent(String eventId) { + for (int i = 0; i < trueEventIds.length; i++) { + if (trueEventIds[i].equals(eventId)) { + return true; + } + } + return false; } } \ No newline at end of file diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/support/ActionTransitionCriteriaTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/support/ActionTransitionCriteriaTests.java index 845bfa87..1eaa6fcf 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/support/ActionTransitionCriteriaTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/support/ActionTransitionCriteriaTests.java @@ -17,50 +17,41 @@ package org.springframework.webflow.engine.support; import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.springframework.webflow.execution.Action; -import org.springframework.webflow.execution.Event; +import org.springframework.webflow.test.MockAction; import org.springframework.webflow.test.MockRequestContext; -/** - * Unit tests for the ActionTransitionCriteria class. - * - * @author Ulrik Sandberg - */ public class ActionTransitionCriteriaTests extends TestCase { - private Action actionMock; + private MockAction action; - private ActionTransitionCriteria tested; + private ActionTransitionCriteria criteria; protected void setUp() throws Exception { - super.setUp(); - actionMock = (Action) EasyMock.createMock(Action.class); - tested = new ActionTransitionCriteria(actionMock); + action = new MockAction(); + criteria = new ActionTransitionCriteria(action); } - public void testGetTrueEventId() { - String id = tested.getTrueEventId(); - assertEquals("success", id); + public void testExecuteSuccessResult() throws Exception { + MockRequestContext context = new MockRequestContext(); + assertTrue(criteria.test(context)); } - public void testSetTrueEventId() { - tested.setTrueEventId("something"); - String id = tested.getTrueEventId(); - assertEquals("something", id); + public void testExecuteTrueResult() throws Exception { + action.setResultEventId("true"); + MockRequestContext context = new MockRequestContext(); + assertTrue(criteria.test(context)); } - public void testGetAction() { - Action action = tested.getAction(); - assertSame(actionMock, action); + public void testExecuteYesResult() throws Exception { + action.setResultEventId("yes"); + MockRequestContext context = new MockRequestContext(); + assertTrue(criteria.test(context)); } - public void testTest() throws Exception { - MockRequestContext mockRequestContext = new MockRequestContext(); - EasyMock.expect(actionMock.execute(mockRequestContext)).andReturn(new Event(this, "success")); - EasyMock.replay(new Object[] { actionMock }); - boolean result = tested.test(mockRequestContext); - EasyMock.verify(new Object[] { actionMock }); - assertEquals(true, result); + public void testExecuteErrorResult() throws Exception { + action.setResultEventId("whatever"); + MockRequestContext context = new MockRequestContext(); + assertFalse(criteria.test(context)); } + } \ No newline at end of file