0

I am pretty new to SOAP UI and Groovy and I am trying for days now to solve it but I can't make it happen. Someone knows how to format it properly?

I need the "Preis" node correctly appended to this format and get rid of the "VOKey" Node.

I need the reponse in the following output format:

enter image description here

At the moment I get it like that:

enter image description here

My XML Reponse:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns1:calculateOfferteResponse xmlns:ns1="http://www.testtest.wsdl/OfferteWebservice">
         <ns162:returnValue xmlns:ns162="http://www.testtest.wsdl/OfferteWebservice">   
         <Mutationsgrund>-1</Mutationsgrund>
            <ParamAttribute>
               <VOKey id="1234" type="-500388"/>
               <ParamAttrDef>BP</ParamAttrDef>
            </ParamAttribute>
            <ParamAttribute>
               <VOKey id="1243"-500388"/>
               <ParamAttrDef>DATUM</ParamAttrDef>
            </ParamAttribute>
            <ParamAttribute>
               <VOKey id="1122" type="-500388"/>
               <ParamAttrDef>STATUS</ParamAttrDef>
            </ParamAttribute>
            <ParamAttribute>
               <VOKey id="2222" type="-500388"/>
               <ParamAttrDef>AZ1</ParamAttrDef>
            </ParamAttribute>
            <ParamAttribute>
               <VOKey id="3333" type="-500388"/>
               <ParamAttrDef>ADR_CO</ParamAttrDef>
            </ParamAttribute>
            <MessageContainer/>
            <Offerte>
               <ParamAttribute>
                  <VOKey id="4444" type="-500393"/>
                  <ParamAttrDef>MAKLERNR</ParamAttrDef>
                  <Wert>MAK37856378</Wert>
               </ParamAttribute>
               <Produktsparte>KUNDE</Produktsparte>
               <RahmenvertragNr>K110106</RahmenvertragNr>
               <Preis>204.83</Preis>
               <VersicherteObjekte>
                  <VOKey id="5555" type="-500183"/>
                  <ParamAttribute>
                     <VOKey id="6666" type="-500392"/>
                     <ParamAttrDef>VERSICHERUNG</ParamAttrDef>
                     <Wert>112233445</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="1232" type="-500392"/>
                     <ParamAttrDef>KUENDIGUNG</ParamAttrDef>
                     <Wert>Nein</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="4456" type="-500392"/>
                     <ParamAttrDef>BEITRAGSFREI</ParamAttrDef>
                     <Wert>Nein</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="1654" type="-500392"/>
                     <ParamAttrDef>BERUFSBEZEICHNUNG_FREITEXT</ParamAttrDef>
                     <Wert>Wirt</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="4423 type="-500392"/>
                     <ParamAttrDef>BEZ_ZUM_VN</ParamAttrDef>
                     <Wert>VN</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="9898" type="-500392"/>
                     <ParamAttrDef>BERECHTIGUNG</ParamAttrDef>
                     <Wert>FOLGE</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="7203" type="-500392"/>
                     <ParamAttrDef>DYNAMIK</ParamAttrDef>
                     <Wert>Nein</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="4200" type="-500392"/>
                     <ParamAttrDef>VALIDE</ParamAttrDef>
                     <Wert>150000</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="7365" type="-500392"/>
                     <ParamAttrDef>VERMITTLER</ParamAttrDef>
                     <Wert>0</Wert>
                  </ParamAttribute>
                  <ParamAttribute>
                     <VOKey id="9324" type="-500392"/>
                     <ParamAttrDef>VORNAME</ParamAttrDef>
                     <Wert>Patty</Wert>
                  </ParamAttribute>
               </VersicherteObjekte>
            </Offerte>
         </ns162:returnValue>
      </ns1:calculateOfferteResponse>
   </soapenv:Body>
</soapenv:Envelope>

That is my groovy script assertion:

 //Change file name as needed
def fileName = 'N:/test.csv'
def delimiter = ';' 

assert context.response, 'Response is empty or null'

def xml = new XmlSlurper().parseText(context.response)
def xmlp = new XmlSlurper().parseText(context.response)


def personalInfos = xml.'**'.findAll { it.name() == 'ParamAttribute' }
def preis = xmlp.'**'.findAll { it.name() == 'Preis' }

//get all childen from ParamAttribute
def list = personalInfos.collect {info -> info.children()*.name().collectEntries{[(it): info."$it"] } }


def sb = new StringBuffer(list[0].keySet().join(delimiter))

sb.append('\n')


list.collect { sb.append(it.values().join(delimiter)).append('\n')}
log.info "Data going to be written into file: \n ${sb.toString()}"


new File(fileName).append(sb.toString())
new File(fileName).append(preis.toString())



new File(fileName).with{
    append(sb.toString())
    append(preis.toString())
    }

Thanks in advance!

1 Answer 1

2
assert context.response, 'Response is empty or null'

def xml = new XmlSlurper().parseText(context.response)
def personalInfos = xml.'**'.findAll { it.name() == 'ParamAttribute' }
def listOfMaps = personalInfos.collect {info -> 
    info.children().collectEntries{[it.name(), it.text()] }
}
def headers = listOfMaps.collectMany{it.keySet()}.unique().findAll{it!='VOKey'}
def csv = listOfMaps.collect{li-> headers.collect{h->li[h]?:''}.join(';') }.join('\n')

new File(fileName).append(csv)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.