Я использую Jmeter для проверки объекта ответа моего restful API, где мне нужно проверить данные, а также структуру возвращаемого объекта. Я пытаюсь сделать это с JsonSlurper, но это не кажется хорошим подходом, так как он не сканирует отклик. Какой другой вариант я могу использовать для сканирования полного ответа? Любая помощь?
import groovy.json.JsonSlurper;
JsonSlurper JSON = new JsonSlurper ();
def expected = new groovy.json.JsonSlurper().parseText('''{
"data": {
"MND": "2019-12-29T00:00:00Z",
"Months": [
{
"SD": "01\/01\/2020",
"T": [
{
"PTG": 0.0,
"NA": false,
"S": null,
"VL": "20.00",
"MI": 100
},
{
"PTG": 0.0,
"NA": false,
"S": null,
"VL": "0.20",
"MI": 101
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 102
},
{
"PTG": 0.0,
"NA": false,
"S": null,
"VL": "0.20",
"MI": 103
}
],
"MR": [
{
"PTG": 1.0,
"NA": false,
"S": "danger",
"VL": "1,536.00",
"MI": 100
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 101
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 102
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 103
}
],
"MDN": "January 2020",
"H": [
{
"MN": "API Automation Testing Lower the better Metric-Sum",
"RT": "s",
"GL": "B",
"MI": 100,
"DS": "%"
},
{
"MN": "API Automation Testing Higher the better Metric-Sum",
"RT": "s",
"GL": "A",
"MI": 101,
"DS": "%"
},
{
"MN": "API Automation Testing Higher the better Metric-AVG",
"RT": "a",
"GL": "A",
"MI": 102,
"DS": "s"
},
{
"MN": "API Automation Testing Lower the better Metric-Number-AVG",
"RT": "a",
"GL": "B",
"MI": 103,
"DS": "s"
}
],
"Id": 0,
"WR": [
{
"DT": [
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 100
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 101
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 102
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 103
}
],
"SD": "29\/12\/2019",
"WN": 1,
"ED": "04\/01\/2020"
},
{
"DT": [
{
"PTG": 1.0,
"NA": false,
"S": "danger",
"VL": "1,536.00",
"MI": 100
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 101
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 102
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 103
}
],
"SD": "05\/01\/2020",
"WN": 2,
"ED": "11\/01\/2020"
},
{
"DT": [
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 100
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 101
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 102
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 103
}
],
"SD": "12\/01\/2020",
"WN": 3,
"ED": "18\/01\/2020"
},
{
"DT": [
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 100
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 101
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 102
},
{
"PTG": 0.0,
"NA": true,
"S": null,
"VL": "0.00",
"MI": 103
}
],
"SD": "19\/01\/2020",
"WN": 4,
"ED": "25\/01\/2020"
}
],
"ED": "31\/01\/2020"
}
],
"MXD": "2020-01-25T00:00:00Z"
},
"success": true,
"error": null
} '' ');
def parsedJson1 = new groovy.json.JsonSlurper().parseText(response1.getResponseBodyContent())
if (parsedJson1 != actual) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Mismatch between expected and actual JSON')
}
IAm получает эту ошибку:
Assertion error: true
Assertion failure: false
Assertion failure message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: response1 for class: Script72