以下是我点击网址时收到的JSON响应:
{"status":"success","body":[{"id":1,"name":"ALL"},{"id":2,"name":"VW_CMPNY"},{"id":3,"name":"EDT_CMPNY"},{"id":4,"name":"ADD_CMPNY"},{"id":5,"name":"DLT_CMPNY"},{"id":6,"name":"VW_GRP"},{"id":7,"name":"EDT_GRP"},{"id":8,"name":"ADD_GRP"},{"id":9,"name":"DLT_GRP"},{"id":10,"name":"VW_ACCNT"},{"id":11,"name":"EDT_ACCNT"},{"id":12,"name":"ADD_ACCNT"},{"id":13,"name":"DLT_ACCNT"},{"id":14,"name":"VW_INVC"},{"id":15,"name":"EDT_INVC"},{"id":16,"name":"ADD_INVC"},{"id":17,"name":"DLT_INVC"},{"id":18,"name":"ON_RCRD"},{"id":19,"name":"OFF_RCRD"}]}
我检查JSON响应是否等于我拥有的.json文件;这是我的代码:
URI permissionsUri = new URI(permissionsUrl);
JSONParser jsonParser = new JSONParser();
Object obj = jsonParser.parse(new FileReader("\\db\\seed\\permission.json));
JSONArray expectedJson = (JSONArray) obj;
String expectedStatus = "success";
get(permissionsUri).then().assertThat().body("status", equalTo(expectedStatus)).and().body("body", equalTo(expectedJson));
但我收到以下错误:
java.lang.AssertionError: JSON path body doesn't match.
Expected: <[{"id":1,"name":"ALL"},{"id":2,"name":"VW_CMPNY"},{"id":3,"name":"EDT_CMPNY"},{"id":4,"name":"ADD_CMPNY"},{"id":5,"name":"DLT_CMPNY"},{"id":6,"name":"VW_GRP"},{"id":7,"name":"EDT_GRP"},{"id":8,"name":"ADD_GRP"},{"id":9,"name":"DLT_GRP"},{"id":10,"name":"VW_ACCNT"},{"id":11,"name":"EDT_ACCNT"},{"id":12,"name":"ADD_ACCNT"},{"id":13,"name":"DLT_ACCNT"},{"id":14,"name":"VW_INVC"},{"id":15,"name":"EDT_INVC"},{"id":16,"name":"ADD_INVC"},{"id":17,"name":"DLT_INVC"},{"id":18,"name":"ON_RCRD"},{"id":19,"name":"OFF_RCRD"}]>
Actual: [{id=1, name=ALL}, {id=2, name=VW_CMPNY}, {id=3, name=EDT_CMPNY}, {id=4, name=ADD_CMPNY}, {id=5, name=DLT_CMPNY}, {id=6, name=VW_GRP}, {id=7, name=EDT_GRP}, {id=8, name=ADD_GRP}, {id=9, name=DLT_GRP}, {id=10, name=VW_ACCNT}, {id=11, name=EDT_ACCNT}, {id=12, name=ADD_ACCNT}, {id=13, name=DLT_ACCNT}, {id=14, name=VW_INVC}, {id=15, name=EDT_INVC}, {id=16, name=ADD_INVC}, {id=17, name=DLT_INVC}, {id=18, name=ON_RCRD}, {id=19, name=OFF_RCRD}]
我不知道为什么我会=
取代:
。我该如何解决这个问题?
答案 0 :(得分:1)
&#34;实际&#34; part看起来像集合或数组上的toString调用。您正在将JSONArray类的内容与实际的JSON文档进行比较。在将JSONArray与服务的响应进行比较之前,必须将JSONArray序列化为JSON文档。