markwhitton
7 years agoNew Contributor
SOAPUI 5.4.0 JSON Assertion of Double Values Ending .00
I have a script assertion which asserts double values for a JSON response. These asserts have been working until the latest release of SOAPUI (5.4.0). It would appear that JsonSlurper is truncating...
- 7 years ago
I am running SoapUI 5.3.0 and I confirm that your script does not give an assertion error for me.
assert GroovySystem.version == "2.1.7"
def slurper = new JsonSlurper() def json = slurper.parseText '{"accountBalance":{"value":125755.00,"currency":"CAD","amountType":"DEBIT"}}' assert json.accountBalance.value.toString() == "125755.00"It looks like JsonSlurper had significant work done to it in Groovy version 2.3 (http://groovy-lang.org/releasenotes/groovy-2.3.html). Then the below using the groovy console at https://groovyconsole.appspot.com/
assert GroovySystem.version == "2.4.4" import groovy.json.JsonSlurper def slurper = new JsonSlurper() def json = slurper.parseText '{"accountBalance":{"value":125755.00,"currency":"CAD","amountType":"DEBIT"}}' assert json.accountBalance.value.toString() == "125755.00"
Assertion failed: assert json.accountBalance.value.toString() == "125755.00" | | | | | | | | 125755 false | | 125755 | [amountType:DEBIT, currency:CAD, value:125755] [accountBalance:[amountType:DEBIT, currency:CAD, value:125755]] at Script1.run(Script1.groovy:5)
I would suggest that the newer behaviour is probably still correct. The JSON data defines a number, not a string. In theory, all we should care about is
assert json.accountBalance.value == 125755
If the application you are testing really does care about the decimal places, that would be non standard. Otherwise the data should be a string. But since it isn't, you might need to do some non standard parsing.
def json = '{"accountBalance":{"value":125755.00,"currency":"CAD","amountType":"DEBIT"}}' assert json =~ /"value"\s*:\s*125755.00/