groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Wagenleitner <john.wagenleit...@gmail.com>
Subject Re: "continue" does not continue the while loop after an assertion fails
Date Tue, 12 Jan 2016 01:04:47 GMT
The code never reaches the continue because the assert will throw an
AssertionError since the expression in the if statement proves it will
fail.  If you remove the assert it should work.  Also may want to remove
the assert in your else branch, unless it is meant to abort the program if
it's reached and fails.  In those cases log.error may be a good choice.

On Mon, Jan 11, 2016 at 4:50 PM, Deng, Lea <Lea.Deng@ccc.govt.nz> wrote:

> I'm using Soap UI and Groovy Script to go through a xml response with many
> Decision elements.
> My Groovy Script refers to a DataSource 'Decision Exclusion List
> RMA/2010/33789' for a list of exlusion text to search for in the xml
> response.
> I search for each DecisionCode read from the DataSource, then extract the
> xml lines for this DecisionCode element, then look for the exlusion text
> within them.
> If the DecisionCode can not be found within the xml text, then I assert a
> failure, and continue the loop.
> However, the test does not continue. It stops after the failed assertion.
>
> Is that because "continue" does not work from within if { } ?
> Thanks,
> Lea
>
> Please see my code below:
>
> --------------------------------------------------
>
> //(singleConsentString contains the xml text to search through)
>
> def exlusionList = testRunner.testCase.testSteps['Decision Exclusion List
> RMA/2010/33789'] // refer to another DataSource test step to get a list of
> exlusion text
>
>
> def counter = 0
> while(exlusionList.next(testRunner,context)){
>         counter ++
>         log.info("counter for decision exlusion list: " + counter)
>         decisionCode = exlusionList.getPropertyValue('PathwayDecisionCode')
>         decisionDescription =
> exlusionList.getPropertyValue('PathwayDecisionDescription')
>
>         // search for the DecisionCode in xml text
>         int startIndexDecision =
> singleConsentString.indexOf('<a:DecisionCode>'+decisionCode+'</a:DecisionCode>')
>         log.info('logging start index of Decision:  ' +
> startIndexDecision)
>
>         // if DecisionCode is not found, assert a failure, and continue
> the loop;
>         if (startIndexDecision < 0){
>                 log.info('Check Decision Code Failed because Pathway data
> does not contain Decision Code: '+decisionCode)
>                 assert startIndexDecision >= 0, "Failed because
> "+decisionCode+" is not found in Pathway data, thus index is less than 0"
>                 continue // this does not work
>         }
>
>         // if DecisionCode is found, then extract the xml lines for this
> DecisionCode, and check for DecisionDescription as well.
>         else {
>                 String subStringDecision =
> singleConsentString.substring(startIndexDecision)
>                 int endIndexDecision =
> subStringDecision.indexOf('</a:DecisionEntity>')
>                 singleDecisionString =
> subStringDecision.substring(0,endIndexDecision)
>                 log.info('logging singe decision:  '+
> singleDecisionString)
>
>                 assert singleDecisionString.contains(decisionCode)&&
> singleConsentString.contains(decisionDescription)
>         }
> }
>
>
> **********************************************************************
> This electronic email and any files transmitted with it are intended
> solely for the use of the individual or entity to whom they are addressed.
>
> The views expressed in this message are those of the individual sender
> and may not necessarily reflect the views of the Christchurch City Council.
>
> If you are not the correct recipient of this email please advise the
> sender and delete.
>
> Christchurch City Council
> http://www.ccc.govt.nz
> **********************************************************************
>

Mime
View raw message