ngoyal
6 years agoOccasional Contributor
How to pick minimum value of an attribute from soap response and pick next node value based on it
From below response I am trying to pick minimum value of AmountAfterTax and also value of corresponding HotelCode and ChainCode.
Response XML -
<soap:Envelope xmlns:soap="http://schemas.xmls...
- 6 years ago
//Using this expectedStayInfo just for testing def expectedStayInfo = [AmountAfterTax: 144.06, HotelCode: '03062', ChainCode: 'ABC' ] def xml = new XmlSlurper().parseText(response) def stays = xml.'**'.findAll {it.name() == 'RoomStay'} def actualStayInfo = [AmountAfterTax: 0, HotelCode: null, ChainCode: null] def updateActualStayInfo = { node, rate -> def isUpdate = false if ((0 == actualStayInfo.AmountAfterTax) || (actualStayInfo.AmountAfterTax > rate)) { isUpdate = true } if (isUpdate) { def info = node.'**'.find{'BasicPropertyInfo' == it.name()} actualStayInfo.AmountAfterTax = rate actualStayInfo.HotelCode = info.@HotelCode.text() actualStayInfo.ChainCode = info.@ChainCode.text() } }
stays.each { stay -> def tempMin = stay.'**'.findAll{it.name() == 'Base'}*.@AmountAfterTax.collect{it.toBigDecimal()}.min() updateActualStayInfo(stay, tempMin) } //test if the actual value of xml is matching assert actualStayInfo == expectedStayInfo