Announcement Announcement Module
Collapse
No announcement yet.
Spring Webflow testing using JUNIT Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Webflow testing using JUNIT

    Hi,

    We are trying to test the webflow of our application and we are getting the following error. Can anyone point out why the error occurs.

    Our flow is from JSP --> Controller --> Service Facade --> back to controller --> back to JSP.

    org.springframework.webflow.execution.ActionExecut ionException: Exception thrown executing [AnnotatedAction@1498436 targetAction = [EvaluateAction@186fe17 expression = userManagementController.registerNewUser(userRegis trationDTO), resultExpression = [null]], attributes = map[[empty]]] in state 'userRegistration' of flow 'ru-flow' -- action execution attributes were 'map[[empty]]'
    at org.springframework.webflow.execution.ActionExecut or.execute(ActionExecutor.java:60)
    at org.springframework.webflow.engine.support.ActionT ransitionCriteria.test(ActionTransitionCriteria.ja va:82)
    at org.springframework.webflow.engine.support.Transit ionCriteriaChain.test(TransitionCriteriaChain.java :71)
    at org.springframework.webflow.engine.Transition.canE xecute(Transition.java:195)
    7)
    Caused by: org.springframework.binding.expression.PropertyNot FoundException: Property not found
    at org.springframework.binding.expression.spel.Spring ELExpression.getValue(SpringELExpression.java:87)
    at org.springframework.webflow.action.EvaluateAction. doExecute(EvaluateAction.java:75)
    at org.springframework.webflow.action.AbstractAction. execute(AbstractAction.java:188)
    at org.springframework.webflow.execution.AnnotatedAct ion.execute(AnnotatedAction.java:145)
    at org.springframework.webflow.execution.ActionExecut or.execute(ActionExecutor.java:51)
    ... 35 more
    Caused by: org.springframework.expression.spel.SpelEvaluation Exception: EL1008Epos 25): Field or property 'userRegistrationDTO' cannot be found on object of type 'org.springframework.webflow.engine.impl.RequestCo ntrolContextImpl'
    at org.springframework.expression.spel.ast.PropertyOr FieldReference.readProperty(PropertyOrFieldReferen ce.java:207)
    at org.springframework.expression.spel.ast.PropertyOr FieldReference.getValueInternal(PropertyOrFieldRef erence.java:71)
    at org.springframework.expression.spel.ast.MethodRefe rence.getValueInternal(MethodReference.java:64)
    at org.springframework.expression.spel.ast.CompoundEx pression.getValueInternal(CompoundExpression.java: 57)
    at org.springframework.expression.spel.ast.SpelNodeIm pl.getTypedValue(SpelNodeImpl.java:102)
    at org.springframework.expression.spel.standard.SpelE xpression.getValue(SpelExpression.java:97)
    at org.springframework.binding.expression.spel.Spring ELExpression.getValue(SpringELExpression.java:84)
    ... 39 more

    Our Test case code
    -------------------
    public class SuperUserFlowTest extends AbstractXmlFlowExecutionTests {

    private UserManagementController userManagementController;
    protected void setUp() {
    userManagementController = EasyMock.createMock(UserManagementController.class );
    }
    @Override
    protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
    return resourceFactory.createFileResource("src/main/webapp/WEB-INF/spring/flows/su-flow.xml");
    }
    @Override
    protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) {
    builderContext.registerBean("UserManagementControl ler", userManagementController);
    }
    @Test
    public void testGetUsers()
    {
    setCurrentState("userList");
    List<UserDetail> users = new ArrayList<UserDetail>();
    users.add(new UserDetail());
    try
    {
    EasyMock.expect(userManagementController.getUsersL ist()).andReturn("success");
    EasyMock.replay(userManagementController);
    }
    catch(Exception e)
    {
    e.getMessage();
    }
    MockExternalContext externalContext = new MockExternalContext();
    startFlow(externalContext);
    EasyMock.verify(userManagementController);
    }
    @Test
    public void testchangepasswordTransition()
    {
    setCurrentState("userList");
    MockExternalContext context = new MockExternalContext();
    context.setEventId("changepswd");
    resumeFlow(context);
    assertCurrentStateEquals("changePassword");
    }
    }

    **** whereever we test only tansition, the test is getting passed. for ex. "testchangepasswordTransition" gets passed, but when we have a controller method call, the test gets failed. Ex "testGetUsers" metod fails with the above mentioned exception.

    Our Flow.xml
    --------------
    <?xml version="1.0" encoding="UTF-8"?>
    <flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow
    http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

    <!-- <secured attributes="ROLE_SUPER_USER_SA,ROLE_END_USER_SA" match="any"/> -->
    <var name="returnValue" class="java.lang.String" />
    <view-state id="userList">
    <on-entry>
    <evaluate result="returnValue" expression="userManagementController.getUsersList( )" />
    </on-entry>
    <transition on="username" to="userDetails" />
    <transition on="navigate" to="summary"/>
    <transition on="changepswd" to="changePassword" />
    <transition on="logout" to="loginPage" />
    <transition on="create" to="createNewEndUser" />
    </view-state>

    <end-state id="endState" />
    </flow>

    Our Controller
    -------------
    @Controller
    public class UserManagementController extends BaseController {

    private static final int ROWS_PER_PAGE = 5;
    private static final int PAGE_LINK_SIZE = 5;

    @Autowired
    private UserManagementFacade userManagementFacade;

    public void setuserManagementFacade(UserManagementFacade userManagementFacade) {
    this.userManagementFacade = userManagementFacade;
    }


    public String getUsersList() throws MalformedURLException {
    String userId = "test";
    List<UserDetail> userList = userManagementFacade.getUserList(userId);
    PageContext pageContext = new PageContext();
    pageContext.initialize("User List", userList.size(), ROWS_PER_PAGE, PAGE_LINK_SIZE);
    getConversationScope().put("userList", userList);
    getConversationScope().put("userListPageContext", pageContext);
    return "success";
    }
Working...
X