Announcement Announcement Module
Collapse
No announcement yet.
JUnit testing with SWF 2.0.7 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JUnit testing with SWF 2.0.7

    Hello all,

    I'm kind of new to Spring Web Flow, been playing around with it casually for around 6 - 8 months or so, and this is my first post here... glad to be part of this community!
    Now I've just updated one of my applications from SWF 1.0.5 to 2.0.7 and I've just started trying to implement some unit testing into my application(had no previous unit testing).

    Now I'm using JUnit as well. I've read through the webflow-reference pdf but to no avail.

    I'm running the following unit test: (note: I've created a stub for my EJB calls as shown below)

    Code:
    protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
    		return resourceFactory.createFileResource("web/WEB-INF/flow/resetPassword-flow.xml");
    	}
    	
    	protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) {
    	    builderContext.registerBean("ejbBean", new StubEjbBean());
    	}
    
    	protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
    	   return new FlowDefinitionResource[] { resourceFactory.createFileResource("file:/src/test/applicationContext-flow-junit.xml"), resourceFactory.createFileResource("file:/src/test/applicationContext-junit.xml") };
    	}
    
    	public void testResetPasswordFlow() {
    
    	    MutableAttributeMap input = new LocalAttributeMap();
    	    MockExternalContext context = new MockExternalContext();
    	    
    	    startFlow(input, context);
    	    
    	    System.out.println("End of JUnit Test [testResetPasswordFlow]");
    	}
    and here is simple flow I'm trying to test

    Code:
    <?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">
    	
    	<action-state id="initialFlowAction">
    		<evaluate expression="initialFlowAction" />
    		<transition on="success" to="resetPasswordUserId"/>
    	</action-state>
    <view-state id="resetPasswordUserId" view="resetPasswordUserId">
    		<on-entry>
                <evaluate expression="resetPasswordUserForm.setupForm"/>
            </on-entry>
    		<transition on="continue" to="finalView">
    			<evaluate expression="resetPasswordUserForm.bindAndValidate"/>
    		</transition>
    	</view-state>
    
    <end-state id="finalView" view="finalView"/>
    </flow>
    and finally this is the exception I get.

    Code:
    org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@63fe63fe targetAction = [EvaluateAction@66006600 expression = initialFlowAction, resultExposer = [null]], attributes = map[[empty]]] in state 'initialFlowAction' of flow 'resetPassword-flow' -- action execution attributes were 'map[[empty]]'
    	at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:60)
    	at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:101)
    	at org.springframework.webflow.engine.State.enter(State.java:194)
    	at org.springframework.webflow.engine.Flow.start(Flow.java:535)
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:364)
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:222)
    	at org.springframework.webflow.test.execution.AbstractFlowExecutionTests.startFlow(AbstractFlowExecutionTests.java:121)
    	at my.package.tests.ResetPasswordFlowExecutionTests.testResetPasswordFlow(ResetPasswordFlowExecutionTests.java:30)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:618)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: org.springframework.binding.expression.PropertyNotFoundException: Property not found
    	at org.springframework.binding.expression.ognl.OgnlExpression.getValue(OgnlExpression.java:87)
    	at org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:77)
    	at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
    	at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145)
    	at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
    	... 23 more
    Caused by: ognl.NoSuchPropertyException: org.springframework.webflow.engine.impl.RequestControlContextImpl.initialFlowAction
    	at ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:123)
    	at org.springframework.webflow.expression.WebFlowOgnlExpressionParser$RequestContextPropertyAccessor.getProperty(WebFlowOgnlExpressionParser.java:118)
    	at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1616)
    	at ognl.ASTProperty.getValueBody(ASTProperty.java:96)
    	at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
    	at ognl.SimpleNode.getValue(SimpleNode.java:210)
    	at ognl.Ognl.getValue(Ognl.java:333)
    	at org.springframework.binding.expression.ognl.OgnlExpression.getValue(OgnlExpression.java:85)
    	... 27 more
    Any help would be greatly appreciated. Thanks guys.

  • #2
    Hey all,
    I've just upped the logging on org.springframework.level to ALL and this is the result I get.

    Code:
    4/06/2009 09:32:33 org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing [email protected]434c4: display name [Flow ApplicationContext [resetPassword-flow]]; startup date [Thu Jun 04 09:32:33 EST 2009]; parent: [email protected]2c28
    4/06/2009 09:32:33 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [[email protected]434c4]: org.springframework.beans.factory.support.DefaultListableBeanFactory@39883988
    4/06/2009 09:32:33 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    FINE: 2 beans defined in [email protected]434c4: display name [Flow ApplicationContext [resetPassword-flow]]; startup date [Thu Jun 04 09:32:33 EST 2009]; parent: [email protected]2c28
    4/06/2009 09:32:33 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry getSingleton
    FINE: Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1 run
    FINE: Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory doCreateBean
    FINE: Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Getting BeanInfo for class [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Caching PropertyDescriptors for class [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'autowiredAnnotationType' of type [java.lang.Class]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'order' of type [int]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'beanFactory' of type [org.springframework.beans.factory.BeanFactory]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'requiredParameterName' of type [java.lang.String]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'requiredParameterValue' of type [boolean]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'class' of type [java.lang.Class]
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1 run
    FINE: Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry getSingleton
    FINE: Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1 run
    FINE: Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory doCreateBean
    FINE: Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Getting BeanInfo for class [org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Caching PropertyDescriptors for class [org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'class' of type [java.lang.Class]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'order' of type [int]
    4/06/2009 09:32:33 org.springframework.beans.CachedIntrospectionResults <init>
    FINEST: Found bean property 'requiredAnnotationType' of type [java.lang.Class]
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1 run
    FINE: Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.context.support.AbstractApplicationContext initMessageSource
    FINE: Unable to locate MessageSource with name 'messageSource': using default [[email protected]5ae]
    4/06/2009 09:32:33 org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
    FINE: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@7bc47bc4]
    4/06/2009 09:32:33 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@39883988: defining beans [org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@498a498a
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractBeanFactory doGetBean
    FINE: Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.beans.factory.support.AbstractBeanFactory doGetBean
    FINE: Returning cached instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
    4/06/2009 09:32:33 org.springframework.context.support.AbstractApplicationContext publishEvent
    FINEST: Publishing event in context [[email protected]434c4]: org.springframework.context.event.ContextRefreshedEvent[source=[email protected]434c4: display name [Flow ApplicationContext [resetPassword-flow]]; startup date [Thu Jun 04 09:32:33 EST 2009]; parent: [email protected]2c28]
    4/06/2009 09:32:33 org.springframework.context.support.AbstractApplicationContext publishEvent
    FINEST: Publishing event in context [[email protected]2c28]: org.springframework.context.event.ContextRefreshedEvent[source=[email protected]434c4: display name [Flow ApplicationContext [resetPassword-flow]]; startup date [Thu Jun 04 09:32:33 EST 2009]; parent: [email protected]2c28]
    4/06/2009 09:32:33 org.springframework.webflow.engine.impl.FlowExecutionImplFactory createFlowExecution
    FINE: Creating new execution of 'resetPassword-flow'
    4/06/2009 09:32:33 org.springframework.webflow.engine.impl.FlowExecutionImpl start
    FINE: Starting in org.springframework.webflow.test.MockExternalContext@1b441b44 with input map[[empty]]
    4/06/2009 09:32:33 org.springframework.webflow.engine.State enter
    FINE: Entering state 'initialFlowAction' of flow 'resetPassword-flow'
    4/06/2009 09:32:33 org.springframework.webflow.execution.ActionExecutor execute
    FINE: Executing [EvaluateAction@5a205a20 expression = initialFlowAction, resultExposer = [null]]
    4/06/2009 09:32:33 org.springframework.webflow.execution.AnnotatedAction execute
    FINE: Putting action execution attributes map[[empty]]
    4/06/2009 09:32:33 org.springframework.webflow.execution.AnnotatedAction execute
    FINE: Clearing action execution attributes map[[empty]]
    4/06/2009 09:32:33 org.springframework.webflow.engine.impl.FlowExecutionImpl handleException
    FINE: Attempting to handle [org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@34903490 targetAction = [EvaluateAction@5a205a20 expression = initialFlowAction, resultExposer = [null]], attributes = map[[empty]]] in state 'initialFlowAction' of flow 'resetPassword-flow' -- action execution attributes were 'map[[empty]]'] with root cause [ognl.NoSuchPropertyException: org.springframework.webflow.engine.impl.RequestControlContextImpl.initialFlowAction]
    4/06/2009 09:32:33 org.springframework.webflow.engine.impl.FlowExecutionImpl handleException
    FINE: Rethrowing unhandled flow execution exception
    Am I meant to be putting something into the 'action execution attributes'?

    Comment


    • #3
      consider giving mock values to flow variables

      I guess you can try giving mock values to your Flow Scope or any scope variables when u start the flow..

      something like this
      MutableAttributeMap input = new LocalAttributeMap();
      input.put("initialFlowActionResult", "any value you wish");
      then start flow with
      startFlow(input, context);

      Comment

      Working...
      X