用于循环 GET 请求并计算节点数的 Groovy 代码

发布于 2024-10-03 06:04:21 字数 13831 浏览 2 评论 0原文

渴望听到有关如何使其 A)不那么难看 B)至少坚持一些基本编码原则的反馈!我正在使用 SOAPUI,因此对属性的任何引用都意味着某些内容存储在测试用例属性步骤中。

我想使用字典,但不知道应该从哪里开始。我只知道下面的 if 语句会产生一些非常丑陋且容易出错的代码。

欢迎所有建议,无论多么重要。我渴望进步!

    import java.text.*
    import java.util.*

    def xmlSlurper = new groovy.util.XmlSlurper()  

    // Get the previous total for number of journals
    def journalCountProp = testRunner.testCase.getTestStepByName("Properties")
    def journalCountTotal = journalCountProp.getPropertyValue( "journalCount" )
    log.info " Previous JournalCount from last run: "+journalCountTotal

    def lastOffsetProp = testRunner.testCase.getTestStepByName("Properties")
    def lastOffsetHolder = lastOffsetProp.getPropertyValue( "offset" )
    log.info " Previous offset from last run: "+lastOffsetHolder

    // Get the response for a given timeline
    def response = xmlSlurper.parseText(context.expand('${GET Journal using Offset#Response}'));
    def currentJournalCount = response.Journals.Journal.size()
    log.info " Number of Journals in this Run: "+currentJournalCount

    //Getting the date from the last Journal (including an offset as the array count starts at 0)
    def lastDate = response.Journals.Journal[currentJournalCount-1].JournalDate
    log.info " Date from this response: "+lastDate

    //Add up the Journals total for a given date. 
    journalCountProp.setPropertyValue("journalQueryDate", String.valueOf(lastDate))

    def countJournalAsInt
    def offsetCountAsInt

    def accTypeBank = context.expand('${Properties#accTypeBankProp}').toInteger()
    //log.info "AccountType - BANK : "+accTypeBank
    def accTypeBankProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeBankTotal = accTypeBankProp.getPropertyValue( "accTypeBankProp" )

    def accTypeCURRENT =  context.expand('${Properties#accTypeCURRENTProp}').toInteger()
    //log.info "AccountType - Current : "+accTypeCURRENT
    def accTypeCURRENTProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeCURRENTTotal = accTypeCURRENTProp.getPropertyValue( "accTypeCURRENTProp" )

    def accTypeCURRLIAB = context.expand('${Properties#accTypeCURRLIABProp}').toInteger()
    //log.info "AccountType - CURRLIAB : "+accTypeCURRLIAB
    def accTypeCURRLIABProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeCURRLIABTotal = accTypeCURRLIABProp.getPropertyValue( "accTypeCURRLIABProp" )

    def accTypeDEPRECIATN = context.expand('${Properties#accTypeCURRLIABProp}').toInteger()
    //log.info "AccountType - DEPRECIATN : "+accTypeDEPRECIATN
    def accTypeDEPRECIATNProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeDEPRECIATNTotal = accTypeDEPRECIATNProp.getPropertyValue( "accTypeDEPRECIATNProp" )

    def accTypeDIRECTCOSTS = context.expand('${Properties#accTypeCURRLIABProp}').toInteger()
    //log.info "AccountType - DIRECTCOSTS : "+accTypeDIRECTCOSTS
    def accTypeDIRECTCOSTSProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeDIRECTCOSTSTotal = accTypeDIRECTCOSTSProp.getPropertyValue( "accTypeDIRECTCOSTSProp" )

    def accTypeEQUITY = context.expand('${Properties#accTypeEQUITYProp}').toInteger()
    //log.info "AccountType - EQUITY : "+accTypeEQUITY
    def accTypeEQUITYProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeEQUITYTotal = accTypeEQUITYProp.getPropertyValue( "accTypeEQUITYProp" )

    def accTypeEXPENSE = context.expand('${Properties#accTypeEXPENSEProp}').toInteger()
    //log.info "AccountType - EXPENSE : "+accTypeEXPENSE
    def accTypeEXPENSEProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeEXPENSETotal = accTypeEXPENSEProp.getPropertyValue( "accTypeCURRLIABProp" )

    def accTypeFIXED = context.expand('${Properties#accTypeFIXEDProp}').toInteger()
    //log.info "AccountType - FIXED : "+accTypeFIXED
    def accTypeFIXEDProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeFIXEDTotal = accTypeFIXEDProp.getPropertyValue( "accTypeFIXEDProp" )

    def accTypeLIABILITY = context.expand('${Properties#accTypeLIABILITYProp}').toInteger()
    //log.info "AccountType - LIABILITY : "+accTypeLIABILITY
    def accTypeLIABILITYProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeLIABILITYTotal = accTypeLIABILITYProp.getPropertyValue( "accTypeLIABILITYProp" )

    def accTypeOTHERINCOME = context.expand('${Properties#accTypeOTHERINCOMEProp}').toInteger()
    //log.info "AccountType - OTHERINCOME : "+accTypeOTHERINCOME
    def accTypeOTHERINCOMEProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeOTHERINCOMETotal = accTypeOTHERINCOMEProp.getPropertyValue( "accTypeOTHERINCOMEProp" )

    def accTypeOVERHEADS = context.expand('${Properties#accTypeOVERHEADSProp}').toInteger()
    //log.info "AccountType - OVERHEADS : "+accTypeOVERHEADS
    def accTypeOVERHEADSProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeOVERHEADSTotal = accTypeOVERHEADSProp.getPropertyValue( "accTypeOVERHEADSProp" )

    def accTypeREVENUE = context.expand('${Properties#accTypeREVENUEProp}').toInteger()
    //log.info "AccountType - REVENUE : "+accTypeREVENUE
    def accTypeREVENUEProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeREVENUETotal = accTypeREVENUEProp.getPropertyValue( "accTypeREVENUEProp" )

    def accTypeSALES = context.expand('${Properties#accTypeSALESProp}').toInteger()
    //log.info "AccountType - SALES : "+accTypeSALES
    def accTypeSALESProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeSALESTotal = accTypeSALESProp.getPropertyValue( "accTypeSALESProp" )

    def accTypeTERMLIAB = context.expand('${Properties#accTypeTERMLIABProp}').toInteger()
    //log.info "AccountType - TERMLIAB : "+accTypeTERMLIAB
    def accTypeTERMLIABProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeTERMLIABTotal = accTypeTERMLIABProp.getPropertyValue( "accTypeTERMLIABProp" )

    def journalLineItems = response.Journals.Journal.JournalLines

    if( currentJournalCount < 100)
       {
        log.info " Nothing to see here - looks like we've reached the end of the journals"
        //add existing total to current response total
        log.info " JournalCount: "+(journalCountTotal.toInteger() + currentJournalCount.toInteger())
        offsetCountAsInt =journalCountTotal.toInteger() + currentJournalCount.toInteger()
        journalCountProp.setPropertyValue("journalCount",String.valueOf(offsetCountAsInt))


        for (lineItem in journalLineItems.JournalLine)
        {
            log.info "NOTE: From <100 Loop: "+lineItem.AccountType
            if (lineItem.AccountType == 'BANK')
            {           
                accTypeBank++
                accTypeBankProp.setPropertyValue("accTypeBankProp",String.valueOf(accTypeBank))
                }
            if (lineItem.AccountType == 'CURRENT')
            {   
                accTypeCURRENT++    
                accTypeCURRENTProp.setPropertyValue("accTypeCURRENTProp",String.valueOf(accTypeCURRENT))        
                }
            if (lineItem.AccountType == 'CURRLIAB')
            {   accTypeCURRLIAB++
                accTypeCURRLIABProp.setPropertyValue("accTypeCURRLIABProp",String.valueOf(accTypeCURRENT))  
                }
            if (lineItem.AccountType == 'DEPRECIATN')
            {           
                accTypeDEPRECIATN++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDEPRECIATNProp",String.valueOf(accTypeDEPRECIATN))   
                }
            if (lineItem.AccountType == 'DIRECTCOSTS')
            {           
                accTypeDIRECTCOSTS++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDIRECTCOSTSProp",String.valueOf(accTypeDIRECTCOSTS)) 
            }
            if (lineItem.AccountType == 'EQUITY')
            {           
                accTypeEQUITY++
                accTypeEQUITYProp.setPropertyValue("accTypeEQUITYProp",String.valueOf(accTypeEQUITY))
                }
            if (lineItem.AccountType == 'EXPENSE')
            {           
                accTypeEXPENSE++
                accTypeEXPENSEProp.setPropertyValue("accTypeEXPENSEProp",String.valueOf(accTypeEXPENSE))
                }
            if (lineItem.AccountType == 'FIXED')
            {           
                accTypeFIXED++
                accTypeFIXEDProp.setPropertyValue("accTypeFIXEDProp",String.valueOf(accTypeFIXED))
            }
            if (lineItem.AccountType == 'LIABILITY')
            {           
                accTypeLIABILITY++
                accTypeLIABILITYProp.setPropertyValue("accTypeLIABILITYProp",String.valueOf(accTypeLIABILITY))
                }
            if (lineItem.AccountType == 'OTHERINCOME')
            {           
                accTypeOTHERINCOME++
                accTypeOTHERINCOMEProp.setPropertyValue("accTypeOTHERINCOMEProp",String.valueOf(accTypeOTHERINCOME))
                }
            if (lineItem.AccountType == 'OVERHEADS')
            {           
                accTypeOVERHEADS++
                accTypeOVERHEADSProp.setPropertyValue("accTypeOVERHEADSProp",String.valueOf(accTypeOVERHEADS))
            }
            if (lineItem.AccountType == 'REVENUE')
            {           
                accTypeREVENUE++
                accTypeREVENUEProp.setPropertyValue("accTypeREVENUEProp",String.valueOf(accTypeREVENUE))
                }
            if (lineItem.AccountType == 'SALES')
            {   
                accTypeSALES++
                accTypeSALESProp.setPropertyValue("accTypeSALESProp",String.valueOf(accTypeSALES))
                }
            if (lineItem.AccountType == 'TERMLIAB')
            {           
                accTypeTERMLIAB++
                accTypeTERMLIABProp.setPropertyValue("accTypeTERMLIABProp",String.valueOf(accTypeTERMLIAB))
                }

        }

       }
    else
       {
        countJournalAsInt = journalCountTotal.toInteger() + currentJournalCount.toInteger()
        journalCountProp.setPropertyValue("journalCount", String.valueOf(countJournalAsInt))

        log.info "last offset "+lastOffsetHolder
        offsetCountAsInt = lastOffsetHolder.toInteger()+100

        journalCountProp.setPropertyValue("offset",String.valueOf(offsetCountAsInt))

        for (lineItem in journalLineItems.JournalLine) 
        {
            log.info "NOTE: From main loop: "+lineItem.AccountType
            if (lineItem.AccountType == 'BANK')
            {           
                accTypeBank++
                accTypeBankProp.setPropertyValue("accTypeBankProp",String.valueOf(accTypeBank))
                }
            if (lineItem.AccountType == 'CURRENT')
            {   
                accTypeCURRENT++    
                accTypeCURRENTProp.setPropertyValue("accTypeCURRENTProp",String.valueOf(accTypeCURRENT))        
                }
            if (lineItem.AccountType == 'CURRLIAB')
            {   accTypeCURRLIAB++
                accTypeCURRLIABProp.setPropertyValue("accTypeCURRLIABProp",String.valueOf(accTypeCURRENT))  
                }
            if (lineItem.AccountType == 'DEPRECIATN')
            {           
                accTypeDEPRECIATN++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDEPRECIATNProp",String.valueOf(accTypeDEPRECIATN))   
                }
            if (lineItem.AccountType == 'DIRECTCOSTS')
            {           
                accTypeDIRECTCOSTS++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDIRECTCOSTSProp",String.valueOf(accTypeDIRECTCOSTS)) 
            }
            if (lineItem.AccountType == 'EQUITY')
            {           
                accTypeEQUITY++
                accTypeEQUITYProp.setPropertyValue("accTypeEQUITYProp",String.valueOf(accTypeEQUITY))
                }
            if (lineItem.AccountType == 'EXPENSE')
            {           
                accTypeEXPENSE++
                accTypeEXPENSEProp.setPropertyValue("accTypeEXPENSEProp",String.valueOf(accTypeEXPENSE))
                }
            if (lineItem.AccountType == 'FIXED')
            {           
                accTypeFIXED++
                accTypeFIXEDProp.setPropertyValue("accTypeFIXEDProp",String.valueOf(accTypeFIXED))
            }
            if (lineItem.AccountType == 'LIABILITY')
            {           
                accTypeLIABILITY++
                accTypeLIABILITYProp.setPropertyValue("accTypeLIABILITYProp",String.valueOf(accTypeLIABILITY))
                }
            if (lineItem.AccountType == 'OTHERINCOME')
            {           
                accTypeOTHERINCOME++
                accTypeOTHERINCOMEProp.setPropertyValue("accTypeOTHERINCOMEProp",String.valueOf(accTypeOTHERINCOME))
                }
            if (lineItem.AccountType == 'OVERHEADS')
            {           
                accTypeOVERHEADS++
                accTypeOVERHEADSProp.setPropertyValue("accTypeOVERHEADSProp",String.valueOf(accTypeOVERHEADS))
            }
            if (lineItem.AccountType == 'REVENUE')
            {           
                accTypeREVENUE++
                accTypeREVENUEProp.setPropertyValue("accTypeREVENUEProp",String.valueOf(accTypeREVENUE))
                }
            if (lineItem.AccountType == 'SALES')
            {   
                accTypeSALES++
                accTypeSALESProp.setPropertyValue("accTypeSALESProp",String.valueOf(accTypeSALES))
                }
            if (lineItem.AccountType == 'TERMLIAB')
            {           
                accTypeTERMLIAB++
                accTypeTERMLIABProp.setPropertyValue("accTypeTERMLIABProp",String.valueOf(accTypeTERMLIAB))
                }


        }


        testRunner.gotoStepByName("GET Journal using Offset")
       }

Keen to hear feedback on how to make this A) less ugly B) adhere to atleast some basic coding principles! I'm using SOAPUI so any reference to properties means that something is getting stored in a test case property step.

I'd like to use a dictionary but am lost as to where I should start. I just know that the if statements below made for some very ugly and error prone code.

All advice, however critical is welcome. I'm keen to improve!

    import java.text.*
    import java.util.*

    def xmlSlurper = new groovy.util.XmlSlurper()  

    // Get the previous total for number of journals
    def journalCountProp = testRunner.testCase.getTestStepByName("Properties")
    def journalCountTotal = journalCountProp.getPropertyValue( "journalCount" )
    log.info " Previous JournalCount from last run: "+journalCountTotal

    def lastOffsetProp = testRunner.testCase.getTestStepByName("Properties")
    def lastOffsetHolder = lastOffsetProp.getPropertyValue( "offset" )
    log.info " Previous offset from last run: "+lastOffsetHolder

    // Get the response for a given timeline
    def response = xmlSlurper.parseText(context.expand('${GET Journal using Offset#Response}'));
    def currentJournalCount = response.Journals.Journal.size()
    log.info " Number of Journals in this Run: "+currentJournalCount

    //Getting the date from the last Journal (including an offset as the array count starts at 0)
    def lastDate = response.Journals.Journal[currentJournalCount-1].JournalDate
    log.info " Date from this response: "+lastDate

    //Add up the Journals total for a given date. 
    journalCountProp.setPropertyValue("journalQueryDate", String.valueOf(lastDate))

    def countJournalAsInt
    def offsetCountAsInt

    def accTypeBank = context.expand('${Properties#accTypeBankProp}').toInteger()
    //log.info "AccountType - BANK : "+accTypeBank
    def accTypeBankProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeBankTotal = accTypeBankProp.getPropertyValue( "accTypeBankProp" )

    def accTypeCURRENT =  context.expand('${Properties#accTypeCURRENTProp}').toInteger()
    //log.info "AccountType - Current : "+accTypeCURRENT
    def accTypeCURRENTProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeCURRENTTotal = accTypeCURRENTProp.getPropertyValue( "accTypeCURRENTProp" )

    def accTypeCURRLIAB = context.expand('${Properties#accTypeCURRLIABProp}').toInteger()
    //log.info "AccountType - CURRLIAB : "+accTypeCURRLIAB
    def accTypeCURRLIABProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeCURRLIABTotal = accTypeCURRLIABProp.getPropertyValue( "accTypeCURRLIABProp" )

    def accTypeDEPRECIATN = context.expand('${Properties#accTypeCURRLIABProp}').toInteger()
    //log.info "AccountType - DEPRECIATN : "+accTypeDEPRECIATN
    def accTypeDEPRECIATNProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeDEPRECIATNTotal = accTypeDEPRECIATNProp.getPropertyValue( "accTypeDEPRECIATNProp" )

    def accTypeDIRECTCOSTS = context.expand('${Properties#accTypeCURRLIABProp}').toInteger()
    //log.info "AccountType - DIRECTCOSTS : "+accTypeDIRECTCOSTS
    def accTypeDIRECTCOSTSProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeDIRECTCOSTSTotal = accTypeDIRECTCOSTSProp.getPropertyValue( "accTypeDIRECTCOSTSProp" )

    def accTypeEQUITY = context.expand('${Properties#accTypeEQUITYProp}').toInteger()
    //log.info "AccountType - EQUITY : "+accTypeEQUITY
    def accTypeEQUITYProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeEQUITYTotal = accTypeEQUITYProp.getPropertyValue( "accTypeEQUITYProp" )

    def accTypeEXPENSE = context.expand('${Properties#accTypeEXPENSEProp}').toInteger()
    //log.info "AccountType - EXPENSE : "+accTypeEXPENSE
    def accTypeEXPENSEProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeEXPENSETotal = accTypeEXPENSEProp.getPropertyValue( "accTypeCURRLIABProp" )

    def accTypeFIXED = context.expand('${Properties#accTypeFIXEDProp}').toInteger()
    //log.info "AccountType - FIXED : "+accTypeFIXED
    def accTypeFIXEDProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeFIXEDTotal = accTypeFIXEDProp.getPropertyValue( "accTypeFIXEDProp" )

    def accTypeLIABILITY = context.expand('${Properties#accTypeLIABILITYProp}').toInteger()
    //log.info "AccountType - LIABILITY : "+accTypeLIABILITY
    def accTypeLIABILITYProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeLIABILITYTotal = accTypeLIABILITYProp.getPropertyValue( "accTypeLIABILITYProp" )

    def accTypeOTHERINCOME = context.expand('${Properties#accTypeOTHERINCOMEProp}').toInteger()
    //log.info "AccountType - OTHERINCOME : "+accTypeOTHERINCOME
    def accTypeOTHERINCOMEProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeOTHERINCOMETotal = accTypeOTHERINCOMEProp.getPropertyValue( "accTypeOTHERINCOMEProp" )

    def accTypeOVERHEADS = context.expand('${Properties#accTypeOVERHEADSProp}').toInteger()
    //log.info "AccountType - OVERHEADS : "+accTypeOVERHEADS
    def accTypeOVERHEADSProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeOVERHEADSTotal = accTypeOVERHEADSProp.getPropertyValue( "accTypeOVERHEADSProp" )

    def accTypeREVENUE = context.expand('${Properties#accTypeREVENUEProp}').toInteger()
    //log.info "AccountType - REVENUE : "+accTypeREVENUE
    def accTypeREVENUEProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeREVENUETotal = accTypeREVENUEProp.getPropertyValue( "accTypeREVENUEProp" )

    def accTypeSALES = context.expand('${Properties#accTypeSALESProp}').toInteger()
    //log.info "AccountType - SALES : "+accTypeSALES
    def accTypeSALESProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeSALESTotal = accTypeSALESProp.getPropertyValue( "accTypeSALESProp" )

    def accTypeTERMLIAB = context.expand('${Properties#accTypeTERMLIABProp}').toInteger()
    //log.info "AccountType - TERMLIAB : "+accTypeTERMLIAB
    def accTypeTERMLIABProp = testRunner.testCase.getTestStepByName("Properties")
    def accTypeTERMLIABTotal = accTypeTERMLIABProp.getPropertyValue( "accTypeTERMLIABProp" )

    def journalLineItems = response.Journals.Journal.JournalLines

    if( currentJournalCount < 100)
       {
        log.info " Nothing to see here - looks like we've reached the end of the journals"
        //add existing total to current response total
        log.info " JournalCount: "+(journalCountTotal.toInteger() + currentJournalCount.toInteger())
        offsetCountAsInt =journalCountTotal.toInteger() + currentJournalCount.toInteger()
        journalCountProp.setPropertyValue("journalCount",String.valueOf(offsetCountAsInt))


        for (lineItem in journalLineItems.JournalLine)
        {
            log.info "NOTE: From <100 Loop: "+lineItem.AccountType
            if (lineItem.AccountType == 'BANK')
            {           
                accTypeBank++
                accTypeBankProp.setPropertyValue("accTypeBankProp",String.valueOf(accTypeBank))
                }
            if (lineItem.AccountType == 'CURRENT')
            {   
                accTypeCURRENT++    
                accTypeCURRENTProp.setPropertyValue("accTypeCURRENTProp",String.valueOf(accTypeCURRENT))        
                }
            if (lineItem.AccountType == 'CURRLIAB')
            {   accTypeCURRLIAB++
                accTypeCURRLIABProp.setPropertyValue("accTypeCURRLIABProp",String.valueOf(accTypeCURRENT))  
                }
            if (lineItem.AccountType == 'DEPRECIATN')
            {           
                accTypeDEPRECIATN++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDEPRECIATNProp",String.valueOf(accTypeDEPRECIATN))   
                }
            if (lineItem.AccountType == 'DIRECTCOSTS')
            {           
                accTypeDIRECTCOSTS++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDIRECTCOSTSProp",String.valueOf(accTypeDIRECTCOSTS)) 
            }
            if (lineItem.AccountType == 'EQUITY')
            {           
                accTypeEQUITY++
                accTypeEQUITYProp.setPropertyValue("accTypeEQUITYProp",String.valueOf(accTypeEQUITY))
                }
            if (lineItem.AccountType == 'EXPENSE')
            {           
                accTypeEXPENSE++
                accTypeEXPENSEProp.setPropertyValue("accTypeEXPENSEProp",String.valueOf(accTypeEXPENSE))
                }
            if (lineItem.AccountType == 'FIXED')
            {           
                accTypeFIXED++
                accTypeFIXEDProp.setPropertyValue("accTypeFIXEDProp",String.valueOf(accTypeFIXED))
            }
            if (lineItem.AccountType == 'LIABILITY')
            {           
                accTypeLIABILITY++
                accTypeLIABILITYProp.setPropertyValue("accTypeLIABILITYProp",String.valueOf(accTypeLIABILITY))
                }
            if (lineItem.AccountType == 'OTHERINCOME')
            {           
                accTypeOTHERINCOME++
                accTypeOTHERINCOMEProp.setPropertyValue("accTypeOTHERINCOMEProp",String.valueOf(accTypeOTHERINCOME))
                }
            if (lineItem.AccountType == 'OVERHEADS')
            {           
                accTypeOVERHEADS++
                accTypeOVERHEADSProp.setPropertyValue("accTypeOVERHEADSProp",String.valueOf(accTypeOVERHEADS))
            }
            if (lineItem.AccountType == 'REVENUE')
            {           
                accTypeREVENUE++
                accTypeREVENUEProp.setPropertyValue("accTypeREVENUEProp",String.valueOf(accTypeREVENUE))
                }
            if (lineItem.AccountType == 'SALES')
            {   
                accTypeSALES++
                accTypeSALESProp.setPropertyValue("accTypeSALESProp",String.valueOf(accTypeSALES))
                }
            if (lineItem.AccountType == 'TERMLIAB')
            {           
                accTypeTERMLIAB++
                accTypeTERMLIABProp.setPropertyValue("accTypeTERMLIABProp",String.valueOf(accTypeTERMLIAB))
                }

        }

       }
    else
       {
        countJournalAsInt = journalCountTotal.toInteger() + currentJournalCount.toInteger()
        journalCountProp.setPropertyValue("journalCount", String.valueOf(countJournalAsInt))

        log.info "last offset "+lastOffsetHolder
        offsetCountAsInt = lastOffsetHolder.toInteger()+100

        journalCountProp.setPropertyValue("offset",String.valueOf(offsetCountAsInt))

        for (lineItem in journalLineItems.JournalLine) 
        {
            log.info "NOTE: From main loop: "+lineItem.AccountType
            if (lineItem.AccountType == 'BANK')
            {           
                accTypeBank++
                accTypeBankProp.setPropertyValue("accTypeBankProp",String.valueOf(accTypeBank))
                }
            if (lineItem.AccountType == 'CURRENT')
            {   
                accTypeCURRENT++    
                accTypeCURRENTProp.setPropertyValue("accTypeCURRENTProp",String.valueOf(accTypeCURRENT))        
                }
            if (lineItem.AccountType == 'CURRLIAB')
            {   accTypeCURRLIAB++
                accTypeCURRLIABProp.setPropertyValue("accTypeCURRLIABProp",String.valueOf(accTypeCURRENT))  
                }
            if (lineItem.AccountType == 'DEPRECIATN')
            {           
                accTypeDEPRECIATN++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDEPRECIATNProp",String.valueOf(accTypeDEPRECIATN))   
                }
            if (lineItem.AccountType == 'DIRECTCOSTS')
            {           
                accTypeDIRECTCOSTS++
                accTypeDEPRECIATNProp.setPropertyValue("accTypeDIRECTCOSTSProp",String.valueOf(accTypeDIRECTCOSTS)) 
            }
            if (lineItem.AccountType == 'EQUITY')
            {           
                accTypeEQUITY++
                accTypeEQUITYProp.setPropertyValue("accTypeEQUITYProp",String.valueOf(accTypeEQUITY))
                }
            if (lineItem.AccountType == 'EXPENSE')
            {           
                accTypeEXPENSE++
                accTypeEXPENSEProp.setPropertyValue("accTypeEXPENSEProp",String.valueOf(accTypeEXPENSE))
                }
            if (lineItem.AccountType == 'FIXED')
            {           
                accTypeFIXED++
                accTypeFIXEDProp.setPropertyValue("accTypeFIXEDProp",String.valueOf(accTypeFIXED))
            }
            if (lineItem.AccountType == 'LIABILITY')
            {           
                accTypeLIABILITY++
                accTypeLIABILITYProp.setPropertyValue("accTypeLIABILITYProp",String.valueOf(accTypeLIABILITY))
                }
            if (lineItem.AccountType == 'OTHERINCOME')
            {           
                accTypeOTHERINCOME++
                accTypeOTHERINCOMEProp.setPropertyValue("accTypeOTHERINCOMEProp",String.valueOf(accTypeOTHERINCOME))
                }
            if (lineItem.AccountType == 'OVERHEADS')
            {           
                accTypeOVERHEADS++
                accTypeOVERHEADSProp.setPropertyValue("accTypeOVERHEADSProp",String.valueOf(accTypeOVERHEADS))
            }
            if (lineItem.AccountType == 'REVENUE')
            {           
                accTypeREVENUE++
                accTypeREVENUEProp.setPropertyValue("accTypeREVENUEProp",String.valueOf(accTypeREVENUE))
                }
            if (lineItem.AccountType == 'SALES')
            {   
                accTypeSALES++
                accTypeSALESProp.setPropertyValue("accTypeSALESProp",String.valueOf(accTypeSALES))
                }
            if (lineItem.AccountType == 'TERMLIAB')
            {           
                accTypeTERMLIAB++
                accTypeTERMLIABProp.setPropertyValue("accTypeTERMLIABProp",String.valueOf(accTypeTERMLIAB))
                }


        }


        testRunner.gotoStepByName("GET Journal using Offset")
       }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2024-10-10 06:04:21

一项改进可以是:

def testRunnerMap = testRunner.testCase.getTestStepByName("Properties").with {
  // Add all properties you want to get from the testRuner to this array
  [ 'journalCount', 'offset', 'accTypeBankProp', 'accTypeCURRENTProp' ].collectEntries { prop ->
    [ "$prop":getPropertyValue( prop ) ]
  }
}

One improvement could be to do:

def testRunnerMap = testRunner.testCase.getTestStepByName("Properties").with {
  // Add all properties you want to get from the testRuner to this array
  [ 'journalCount', 'offset', 'accTypeBankProp', 'accTypeCURRENTProp' ].collectEntries { prop ->
    [ "$prop":getPropertyValue( prop ) ]
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文