/** * @param input Object structure to parse and test against * @param pathAndExpected JSON path expression + '==' + expected value * @param delta tollerance allowed in comparing float/double values */ public static String matchObj(Object input, String pathAndExpected, double delta) throws Exception { int pos = pathAndExpected.indexOf("=="); String path = pos>=0 ? pathAndExpected.substring(0,pos) : null; String expected = pos>=0 ? pathAndExpected.substring(pos+2) : pathAndExpected; Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected); return matchObj(path, input, expectObj, delta); }
public static Long deleteAndGetVersion(String id, SolrParams params) throws Exception { if (params==null || params.get("versions") == null) { ModifiableSolrParams mparams = new ModifiableSolrParams(params); mparams.set("versions","true"); params = mparams; } String response = updateJ(jsonDelId(id), params); Map rsp = (Map)ObjectBuilder.fromJSON(response); List lst = (List)rsp.get("deletes"); if (lst == null || lst.size() == 0) return null; return (Long) lst.get(1); }
public static Long addAndGetVersion(SolrInputDocument sdoc, SolrParams params) throws Exception { if (params==null || params.get("versions") == null) { ModifiableSolrParams mparams = new ModifiableSolrParams(params); mparams.set("versions","true"); params = mparams; } String response = updateJ(jsonAdd(sdoc), params); Map rsp = (Map)ObjectBuilder.fromJSON(response); List lst = (List)rsp.get("adds"); if (lst == null || lst.size() == 0) return null; return (Long) lst.get(1); }
public static Long deleteByQueryAndGetVersion(String q, SolrParams params) throws Exception { if (params==null || params.get("versions") == null) { ModifiableSolrParams mparams = new ModifiableSolrParams(params); mparams.set("versions","true"); params = mparams; } String response = updateJ(jsonDelQ(q), params); Map rsp = (Map)ObjectBuilder.fromJSON(response); List lst = (List)rsp.get("deleteByQuery"); if (lst == null || lst.size() == 0) return null; return (Long) lst.get(1); }
public static void compare(SolrQueryRequest req, String path, Object model, Map<Comparable, Doc> fullModel) throws Exception { String strResponse = h.query(req); Object realResponse = ObjectBuilder.fromJSON(strResponse); String err = JSONTestUtil.matchObj(path, realResponse, model); if (err != null) { log.error("RESPONSE MISMATCH: " + err + "\n\trequest="+req + "\n\tresult="+strResponse + "\n\texpected="+ JSONUtil.toJSON(model) + "\n\tmodel="+ fullModel ); // re-execute the request... good for putting a breakpoint here for debugging String rsp = h.query(req); fail(err); } }
/** * @param path JSON path expression * @param input JSON Structure to parse and test against * @param expected expected value of path * @param delta tollerance allowed in comparing float/double values */ public static String match(String path, String input, String expected, double delta) throws Exception { Object inputObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(input)).getVal() : ObjectBuilder.fromJSON(input); Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected); return matchObj(path, inputObj, expectObj, delta); }
Map jsonObj = null; try { jsonObj = (Map)ObjectBuilder.fromJSON(line); } catch (Exception jsonErr) { if (beVerbose) {
Object response = ObjectBuilder.fromJSON(responseStr);