Forum Discussion

Apoorva6's avatar
Apoorva6
Frequent Contributor
8 years ago
Solved

Need help in groovy script to fetch proper response.

I need help in below issue. I have 2 attributes in request orderComponentId and orderDataType. orderDataType can take 2 values (TTTN and PORT) and orderComponentId can take any value. I have 2 p...
  • nmrao's avatar
    nmrao
    8 years ago

    Apoorva6,

     

    Can you try below script ? Note that I could not test before providing as I do not have artifacts.

     

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
    def soNumber = holder.getNodeValue("//*:InquireEnterpriseTNOrderDataRequest/*:orderComponentId")
    def orderType = holder.getNodeValue("//*:InquireEnterpriseTNOrderDataRequest/*:orderDataType")
    def prefix = "${groovyUtils.projectPath}/MOCK/CSI/IETN/"
    
    def getPrefix = {  orderType == 'PORT' ? ("${prefix}PORTEDTN/" as String) : prefix }
    
    def getFileName = {
      def fileName = "${getPrefix()}${soNumber}.xml" as String
      def file = new File(fileName)
      file.exists() ? fileName : ("${getPrefix()}soapFault.xml" as String)
    }
    
    def getResponseContent = { new File(getFileName()).text }
    
    context.content = getResponseContent()
    log.info "Response content is set to : ${context.content}"