@Test public void testParseTwoResultsWithOneTimedOut() { FrequentlyRelatedItemSearchResponse[] responses = parser.parse(TWO_RESULTS_ONE_TIMED_OUT); assertEquals("Should only have two results",2,responses.length); assertEquals("Result should have 4 terms",4,responses[0].getNumberOfFacets()); assertEquals("Result should have 3 terms with term 1 of '4'","4",responses[0].getFacetResult(0).name); assertEquals("Result should have 3 terms with term 2 of '4'","15",responses[0].getFacetResult(1).name); assertEquals("Result should have 3 terms with term 3 of '4'","3",responses[0].getFacetResult(2).name); assertEquals("Result should have 3 terms with term 4 of '4'","2",responses[0].getFacetResult(3).name); assertEquals("Result should have 1st term with count of '1'",721,responses[0].getFacetResult(0).count); assertEquals("Result should have 2nd term with count of '1'",163,responses[0].getFacetResult(1).count); assertEquals("Result should have 3rd term with count of '1'",1,responses[0].getFacetResult(2).count); assertEquals("Result should have 3rd term with count of '1'",1,responses[0].getFacetResult(3).count); assertFalse("Result should not be an error", responses[0].hasErrored()); assertTrue("Result should timed out", responses[0].hasTimedOut()); assertFalse("Result should not be an error", responses[1].hasErrored()); assertFalse("Result should timed out", responses[1].hasTimedOut()); assertEquals("Result should have 3 terms with term 1 of '4'","1",responses[1].getFacetResult(0).name); assertEquals("Result should have 3 terms with term 2 of '4'","15",responses[1].getFacetResult(1).name); assertEquals("Result should have 3 terms with term 3 of '4'","3",responses[1].getFacetResult(2).name); assertEquals("Result should have 3 terms with term 4 of '4'","2",responses[1].getFacetResult(3).name); assertEquals("Result should have 1st term with count of '1'",1002,responses[1].getFacetResult(0).count); assertEquals("Result should have 2nd term with count of '1'",1001,responses[1].getFacetResult(1).count); assertEquals("Result should have 3rd term with count of '1'",1,responses[1].getFacetResult(2).count); assertEquals("Result should have 3rd term with count of '1'",1,responses[1].getFacetResult(3).count); }
@Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } JsonSmartFrequentlyRelatedItemHttpResponseParser(Configuration configuration); }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } JsonSmartFrequentlyRelatedItemHttpResponseParser(Configuration configuration); @Override FrequentlyRelatedItemSearchResponse[] parse(String json); }
JsonSmartFrequentlyRelatedItemHttpResponseParser implements FrequentlyRelatedItemHttpResponseParser { @Override public FrequentlyRelatedItemSearchResponse[] parse(String json) { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); try { JSONObject object = (JSONObject)parser.parse(json); Object responses = object.get(RESPONSES_KEY); if(responses==null) return parseError; else { JSONArray responsesArray = (JSONArray)responses; int numberOfResponses = responsesArray.size(); FrequentlyRelatedItemSearchResponse[] results = new FrequentlyRelatedItemSearchResponse[numberOfResponses]; for(int i=0;i<numberOfResponses;i++) { Object response = (responsesArray).get(i); if(response instanceof JSONObject) { results[i] = parseResponseObject((JSONObject)response); } else { results[i] = FrequentlyRelatedItemSearchResponse.JSON_RESPONSE_PARSING_ERROR; } } return results; } } catch (Exception e){ return parseError; } } JsonSmartFrequentlyRelatedItemHttpResponseParser(Configuration configuration); @Override FrequentlyRelatedItemSearchResponse[] parse(String json);  }