0

I am using Grails 2.0.3 and webFlow 2.0.0.

I have a WebFlow definition in my controller that is working fine but I want to still add integration tests to facilitate future maintenance.

I am getting the following exception in my test whenever the controller attempts to add some value to the flow scope:

ERROR org.codehaus.groovy.grails.webflow.engine.builder.ClosureInvokingAction  - Exception occured invoking flow action: No such property: poInfo for class: org.springframework.webflow.core.collection.LocalAttributeMap 
groovy.lang.MissingPropertyException: No such property: poInfo for class: org.springframework.webflow.core.collection.LocalAttributeMap 
        at com.psswm.inboundcal.ReceivingEventController$_closure1_closure6_closure12.doCall(ReceivingEventController.groovy:83) 
        at grails.test.WebFlowTestCase.signalEvent(WebFlowTestCase.groovy:143) 
        at com.psswm.inboundcal.ReceivingEventCreationFlowTests.testAddPoInfoMissingPiecesPallets(ReceivingEventCreationFlowTests.groovy:32) 
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) 
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) 
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) 
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) 
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) 
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 
        at org.junit.runners.Suite.runChild(Suite.java:128) 
        at org.junit.runners.Suite.runChild(Suite.java:24) 
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 
        at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:290) 
        at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:248) 
        at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:195) 
        at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:184) 
        at TestApp$_run_closure1.doCall(TestApp.groovy:82) 
| Failure:  testAddPoInfoMissingPiecesPallets(com.psswm.inboundcal.ReceivingEventCreationFlowTests) 
|  org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing org.codehaus.groovy.grails.webflow.engine.builder.ClosureInvokingAction@3beff9ad in state 'addPO' of flow 'create' -- action execution attributes were 'map[[empty]]' 
        at grails.test.WebFlowTestCase.signalEvent(WebFlowTestCase.groovy:143) 
        at com.psswm.inboundcal.ReceivingEventCreationFlowTests.testAddPoInfoMissingPiecesPallets(ReceivingEventCreationFlowTests.groovy:32) 
Caused by: groovy.lang.MissingPropertyException: No such property: poInfo for class: org.springframework.webflow.core.collection.LocalAttributeMap 
        at com.psswm.inboundcal.ReceivingEventController$_closure1_closure6_closure12.doCall(ReceivingEventController.groovy:83) 
        ... 2 more

This is the part of My WebFlow code that I am trying to test:

def createFlow = { 
    initialize { 
        action { 
            if (params.eventId) { 
                flow.receivingEventId = params.eventId as int 
                ReceivingEvent existingReceivingEvent = ReceivingEvent.get(flow.receivingEventId) 
                flow.receivingEvent = new ReceivingEvent(branch:existingReceivingEvent.branch) 
            } 
        } 
        on ("success").to "addPO" 
    } 

    addPO { 
        on("add") { 
            log.debug("addPO") 
            // Initialize flow objects 
            flow.poInfo = new PoInfo(params) 
            if (flow.receivingEvent == null) { 
                flow.receivingEvent = new ReceivingEvent() 
            } 

            // validate and populate poInfo object 
            boolean objectIsValid = flow.poInfo.validateAndPopulate() 
            if(!objectIsValid) { 
                if(!flow.poInfo.hasErrors()) { 
                    flash.warning = 'poInfo.poNumber.unknown' 
                } 
                return error() 
            } 
            // add poInfo object to receivingEvent for additional processing/validation 
            String errorMessage = flow.receivingEvent.addPoInfo(flow.poInfo) 

            if(null != errorMessage) { 
                flash.warning = errorMessage 
                return error() 
            } else { 
                flow.poInfo = null 
            } 
        }.to("addPO") 

........


And this is my integration test:

class ReceivingEventCreationFlowTests extends WebFlowTestCase{ 

ReceivingEventController receivingEventController = new ReceivingEventController() 

void testInitializeFlow() { 
    startFlow() 
    assertCurrentStateEquals "addPO" 
} 

void testAddPoInfoMissingPiecesPallets() { 
    println("Hola mundo") 
    startFlow() 
    assertCurrentStateEquals "addPO" 

    receivingEventController.params.poNumber = '63055024UI1063' 
    receivingEventController.params.pro = '3' 
    println "flow scope: " + getFlowScope().getClass() 
    println ("Hola again") 
    signalEvent('add') 
    assertTrue getFlowScope().poInfo.hasErrors() 
    assertCurrentStateEquals "addPO" 
} 

@Override 
public Object getFlow() { 
    receivingEventController.createFlow 
} 

String getFlowId() { "create" } 
} 

Anybody has any ideas on what am I missing here? or if there are any known integration testing issues with webFlow 2.0.0 and grails 2.0.3?

I am following the guidelines from the book: Grails in Action, chapter 9.4: Testing WebFlows... and yet I keep getting the above error.

Thanks in advance,

Jorge Vasquez

Alidad
  • 5,463
  • 1
  • 24
  • 47
vanvasquez
  • 939
  • 1
  • 10
  • 18

1 Answers1

0

Grails in Action is a very good book but some old. I recomend you use unit test instead integration test. Documentation is almost inexistent but you can see a great example in grails source code:

WebFlow unit test code

You can see webflows with inputs, outputs, subflows, etc. (Inputs and outputs are newer that GIA book)

In examples Roeche use conversation scope, you can use flow scope instead.

AA.
  • 4,496
  • 31
  • 35
  • The link is currently down. – Daneo Aug 27 '13 at 21:09
  • Yep, my new recommendation: Do not use webflow. It's buggy and undocumented. – AA. Aug 27 '13 at 22:45
  • It looks like this might be the current link: https://github.com/grails/grails-core/blob/9560f8275abb76e3ba0afe94967ee196768d0af6/grails-plugin-testing/src/test/groovy/grails/test/mixin/WebFlowUnitTestMixinTests.groovy – Peter N. Steinmetz Nov 05 '13 at 20:04