From: tcofoegbu Date: Thu, 26 Mar 2015 15:15:39 +0000 (+0000) Subject: JAL-1667 updated parseJsonExceptionString method in PDBRestClient.java and its equiva... X-Git-Tag: Jalview_2_9~71^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ffeatures%2FJAL-1667_PDBe_Search_API;p=jalview.git JAL-1667 updated parseJsonExceptionString method in PDBRestClient.java and its equivalent test case in PDBRestClientTest.java --- diff --git a/src/jalview/ws/dbsources/PDBRestClient.java b/src/jalview/ws/dbsources/PDBRestClient.java index 1ab6125..f406702 100644 --- a/src/jalview/ws/dbsources/PDBRestClient.java +++ b/src/jalview/ws/dbsources/PDBRestClient.java @@ -107,22 +107,30 @@ public class PDBRestClient */ public static String parseJsonExceptionString(String jsonErrorResponse) { - String errorMessage = "RunTime error"; + StringBuilder errorMessage = new StringBuilder( + "\n============= PDB Rest Client RunTime error =============\n"); try { JSONParser jsonParser = new JSONParser(); JSONObject jsonObj = (JSONObject) jsonParser.parse(jsonErrorResponse); JSONObject errorResponse = (JSONObject) jsonObj.get("error"); - errorMessage = errorResponse.get("msg").toString(); - JSONObject responseHeader = (JSONObject) jsonObj .get("responseHeader"); - errorMessage += responseHeader.get("params").toString(); + JSONObject paramsObj = (JSONObject) responseHeader.get("params"); + String status = responseHeader.get("status").toString(); + String message = errorResponse.get("msg").toString(); + String query = paramsObj.get("q").toString(); + String fl = paramsObj.get("fl").toString(); + + errorMessage.append("Status: ").append(status).append("\n"); + errorMessage.append("Message: ").append(message).append("\n"); + errorMessage.append("query: ").append(query).append("\n"); + errorMessage.append("fl: ").append(fl).append("\n"); } catch (ParseException e) { e.printStackTrace(); } - return errorMessage; + return errorMessage.toString(); } /** diff --git a/test/jalview/ws/dbsources/PDBRestClientTest.java b/test/jalview/ws/dbsources/PDBRestClientTest.java index ba07562..c35cbe9 100644 --- a/test/jalview/ws/dbsources/PDBRestClientTest.java +++ b/test/jalview/ws/dbsources/PDBRestClientTest.java @@ -61,9 +61,12 @@ public class PDBRestClientTest wantedFields.add(PDBDocField.GENUS); wantedFields.add(PDBDocField.GENE_NAME); wantedFields.add(PDBDocField.TITLE); - assertEquals("molecule_type,pdb_id,genus,gene_name,title", - PDBRestClient - .getPDBDocFieldsAsCommaDelimitedString(wantedFields)); + + String expectedResult = "molecule_type,pdb_id,genus,gene_name,title"; + String actualResult = PDBRestClient + .getPDBDocFieldsAsCommaDelimitedString(wantedFields); + + assertEquals("", expectedResult, actualResult); } @Test @@ -94,8 +97,13 @@ public class PDBRestClientTest String parsedErrorResponse = PDBRestClient .parseJsonExceptionString(jsonErrorResponse); - String expectedErrorMsg = "org.apache.solr.search.SyntaxError: Cannot parse 'text:abc OR text:go:abc AND molecule_sequence:['' TO *]': Encountered \" \":\" \": \"\" at line 1, column 19.{\"q\":\"text:abc OR text:go:abc AND molecule_sequence:['' TO *]\",\"fl\":\"pdb_id\",\"sort\":\"\",\"rows\":\"100\",\"wt\":\"json\"}"; + System.out.println(parsedErrorResponse); + String expectedErrorMsg = "\n============= PDB Rest Client RunTime error =============\n" + + "Status: 400\n" + + "Message: org.apache.solr.search.SyntaxError: Cannot parse 'text:abc OR text:go:abc AND molecule_sequence:['' TO *]': Encountered \" \":\" \": \"\" at line 1, column 19.\n" + + "query: text:abc OR text:go:abc AND molecule_sequence:['' TO *]\n" + + "fl: pdb_id\n"; assertEquals(expectedErrorMsg, parsedErrorResponse); }