Я пытаюсь проверить JSON моего API с помощью следующего кода, но он не работает. В чем может быть причина?
import groovy.json.*
JSONObject obj1 = '''{"success":true,"error":null,"data":{"Months":[{"Id":0,"MDN":"January 2020","H":[{"MI":100,"MN":"API Automation Testing Lower the better Metric-Sum","GL":"B","DS":"%","RT":"s"},{"MI":101,"MN":"API Automation Testing Higher the better Metric-Sum","GL":"A","DS":"%","RT":"s"},{"MI":102,"MN":"API Automation Testing Higher the better Metric-AVG","GL":"A","DS":"s","RT":"a"},{"MI":103,"MN":"API Automation Testing Lower the better Metric-Number-AVG","GL":"B","DS":"s","RT":"a"}],"T":[{"MI":100,"VL":"20.00","NA":false,"PTG":0.0,"S":null},{"MI":101,"VL":"0.20","NA":false,"PTG":0.0,"S":null},{"MI":102,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":103,"VL":"0.20","NA":false,"PTG":0.0,"S":null}],"MR":[{"MI":100,"VL":"1,536.00","NA":false,"PTG":1.0,"S":"danger"},{"MI":101,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":102,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":103,"VL":"0.00","NA":true,"PTG":0.0,"S":null}],"WR":[{"WN":1,"DT":[{"MI":100,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":101,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":102,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":103,"VL":"0.00","NA":true,"PTG":0.0,"S":null}],"SD":"29/12/2019","ED":"04/01/2020"},{"WN":2,"DT":[{"MI":100,"VL":"1,536.00","NA":false,"PTG":1.0,"S":"danger"},{"MI":101,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":102,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":103,"VL":"0.00","NA":true,"PTG":0.0,"S":null}],"SD":"05/01/2020","ED":"11/01/2020"},{"WN":3,"DT":[{"MI":100,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":101,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":102,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":103,"VL":"0.00","NA":true,"PTG":0.0,"S":null}],"SD":"12/01/2020","ED":"18/01/2020"},{"WN":4,"DT":[{"MI":100,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":101,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":102,"VL":"0.00","NA":true,"PTG":0.0,"S":null},{"MI":103,"VL":"0.00","NA":true,"PTG":0.0,"S":null}],"SD":"19/01/2020","ED":"25/01/2020"}],"SD":"01/01/2020","ED":"31/01/2020"}],"MND":"2019-12-29T00:00:00Z","MXD":"2020-01-25T00:00:00Z"}}'''
JSONObject obj2 = prev.getResponseDataasString()
ObjectMapper mapper = new ObjectMapper();
JsonNode expected = mapper.readTree(obj1.toString());
JsonNode actual = mapper.readTree(obj2.toString());
if (!expected.equals(actual)) {
AssertionResult.setFailure(true)
}
ОШИБКА:
Ошибка подтверждения: true Ошибка подтверждения: false Сообщение об ошибке подтверждения: javax.script.ScriptException: org.codehaus. groovy .control .MultipleCompilationErrorsException: запуск не выполнен: Script36. groovy: 6: невозможно разрешить класс JSONObject @ строка 6, столбец 12. JSONObject obj1 = '' '{"success": true, "error": null, "data": { "Месяцы": [{"Id": 0, "MDN": "Январь 2020", "H": [{"MI": 100, "MN": "Тестирование автоматизации API Чем ниже, тем лучше Метри c -сумма" "," GL ":" B "," DS ":"% "," RT ":" s "}, {" MI ": 101," MN ":" Тестирование API автоматизации Чем выше, тем лучше Метри c - Сумма "," GL ":" A "," DS ":"% "," RT ":" s "}, {" MI ": 102," MN ":" Тестирование автоматизации API Чем выше, тем лучше Метри c -AVG "," GL ":" A "," DS ":" s "," RT ":" a "}, {" MI ": 103," MN ":" Тестирование автоматизации API Чем ниже, тем лучше Метри c -Количество-AVG " "GL": "B", "DS": "s", "RT": "а"}], "Т": [{ "МИ": 100, "VL":" 20.00" , "НС" ложь "ПТГ": 0,0, "S": нулевой}, { "МИ": 101, "VL": "0,20", "НС" ложь "ПТГ": 0.0» S ": нулевой}, {" МИ ": 102," VL ":" 0,00" , "НС": правда, "ПТГ": 0.0, "S": п лный}, { "МИ": 103, "VL": "0,20", "НС" ложь "ПТГ": 0.0, "S": нулевой}], "MR": [{ "МИ": 100, "VL": "1,536.00", "НС" ложь "ПТГ": 1,0, "S": "опасность"}, { "МИ": 101, "VL": "0,00", "НС": правда, "ПТГ": 0.0, "S": нулевой}, { "МИ": 102, "VL": "0,00", "НС": правда, "ПТГ": 0,0, "S": нулевой}, { "М.И. ": 103," VL ":" 0,00" , "НС": правда, "ПТГ": 0.0, "S": нулевой}], "WR": [{ "WN": 1, "DT": [{ "МИ": 100, "VL": "0,00", "НС": правда, "ПТГ": 0,0, "S": нулевой}, { "МИ": 101, "VL": "0,00", "Н.А. ": правда," ПТГ ": 0,0," S ": нулевой}, {" МИ ": 102," VL ":" 0,00" , "НС": правда, "ПТГ": 0,0, "S": NULL} , { "МИ": 103, "VL": "0,00", "НС": правда, "ПТГ": 0.0, "S": нулевой}], "SD": "29/12/2019", "ЭД ":" 04/01/2020 "}, {" WN ": 2" DT ": [{" МИ ": 100," VL ":" 1,536.00" , "НС" ложь "ПТГ": 1,0, "S": "опасность"}, { "МИ": 101, "VL": "0,00", "НС": правда, "ПТГ": 0,0, "S": нулевой}, { "МИ": 102, "VL": "0,00", "НС": правда, "ПТГ": 0,0, "S": нулевой}, { "МИ": 103, "VL": "0,00", "НС": правда, "ПТГ ": 0.0," S ": нулевой}]," SD ":" 05/01/2020" , "ЭД": "11/01/2020"}, { "WN": 3, "DT": [{ "МИ": 100, "VL": "0,00", "НС": правда, "ПТГ": 0,0, "S": нулевой}, { "МИ": 101, "VL": "0,00", "Н.А. ": правда," ПТГ ": 0,0," S ": нулевой}, {" МИ ": 102," VL ":" 0,00" , "НС": правда, "ПТГ": 0,0, "S": NULL} , { "МИ": 103, "V L ":" 0,00" , "НС": правда, "ПТГ": 0.0, "S": нулевой}], "SD": "12/01/2020", "ЭД": "18/01/2020" }, { "WN": 4, "DT": [{ "МИ": 100, "VL": "0,00", "НС": правда, "ПТГ": 0,0, "S": нулевой}, {» МИ ": 101," VL ":" 0,00" , "НС": правда, "ПТГ": 0,0, "S": нулевой}, { "МИ": 102, "VL": "0,00", "НС" : правда, "ПТГ": 0,0, "S": нулевой}, { "МИ": 103, "VL": "0,00", "НС": правда, "ПТГ": 0.0, "S": нулевой}] , "SD": "19/01/2020", "ЭД": "25/01/2020"}], "SD": "01/01/2020", "ЭД": "31/01/2020" }], "MND": "2019-12-29T00: 00: 00Z", "MXD": "2020-01-25T00: 00: 00Z"}} '' '*
Script36. groovy: 7: невозможно разрешить класс JSONObject @ строка 7, столбец 12. JSONObject obj2 = prev.getResponseDataasString () ^
Script36. groovy: 8: невозможно разрешить класс ObjectMapper @ строка 8, столбец 14 . ObjectMapper mapper = new ObjectMapper (); ^
Script36. groovy: 8: невозможно разрешить класс ObjectMapper @ строка 8, столбец 23. ObjectMapper mapper = new ObjectMapper (); ^
Script36. groovy: 9: невозможно разрешить класс JsonNode @ строка 9, столбец 10. Ожидается JsonNode = mapper.readTree (obj1.toString ()); ^
Script36. groovy: 10: невозможно разрешить класс JsonNode @ строка 10, столбец 10. JsonNode actual = mapper.readTree (obj2.toString ()); ^
6 ошибок