Package org.skyscreamer.jsonassert

Examples of org.skyscreamer.jsonassert.JSONCompareResult


    }

    public boolean matches(String matched) {
        boolean result = false;

        JSONCompareResult jsonCompareResult = null;
        try {
            jsonCompareResult = compareJSON(matcher, matched, JSONCompareMode.LENIENT);

            if (jsonCompareResult.passed()) {
                result = true;
            }

            if (!result) {
                logger.trace("Failed to perform JSON match [{}] with [{}] because {}", matched, this.matcher, jsonCompareResult.getMessage());
            }
        } catch (Exception e) {
            logger.trace("Failed to perform JSON match [{}] with [{}] because {}", matched, this.matcher, e.getMessage());
        }
View Full Code Here


      }
    };
  }
 
    private boolean isEqualJson(String value) {
        JSONCompareResult result;
        try {
            result = compareJSON(equalToJson, value, Optional.fromNullable(jsonCompareMode).or(NON_EXTENSIBLE));
        } catch (JSONException e) {
            return false;
        }
        return result.passed();
    }
View Full Code Here

    }

    public static void assertEqualsJson(String expectedJson, String actualJson, JSONCompareMode compareMode) {

        try {
            JSONCompareResult result = compareJSON(expectedJson, actualJson, compareMode);

            if (result.failed()) {
                String failureMessage = result.getMessage();
                if (failureMessage != null) {
                    failureMessage = failureMessage.replaceAll(" ; ", "\n");
                }
                failureMessage = "\n================ Expected JSON ================"
                        + new JSONObject(expectedJson).toString(4)
View Full Code Here

        }
    }

    @Test
    public void testFullArrayComparison() throws Exception {
        JSONCompareResult compareResult = JSONCompare.compareJSON(
                "[{id:1}, {id:3}, {id:5}]",
                "[{id:1}, {id:3}, {id:6}, {id:7}]", new ArrayOfJsonObjectsComparator(JSONCompareMode.LENIENT)
        );

        Assert.assertTrue(compareResult.failed());
        String message = compareResult.getMessage().replaceAll("\n", "");
        Assert.assertTrue(message, message.matches(".*id=5.*Expected.*id=6.*Unexpected.*id=7.*Unexpected.*"));
    }
View Full Code Here

     * @param actual   JSONObject to compare
     * @throws JSONException
     */
    @Override
    public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException {
        JSONCompareResult result = new JSONCompareResult();
        compareJSON("", expected, actual, result);
        return result;
    }
View Full Code Here

     * @param actual   JSONArray to compare
     * @throws JSONException
     */
    @Override
    public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException {
        JSONCompareResult result = new JSONCompareResult();
        compareJSONArray("", expected, actual, result);
        return result;
    }
View Full Code Here

TOP

Related Classes of org.skyscreamer.jsonassert.JSONCompareResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.