• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JSONCompareResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.skyscreamer.jsonassert.JSONCompareResult的典型用法代码示例。如果您正苦于以下问题:Java JSONCompareResult类的具体用法?Java JSONCompareResult怎么用?Java JSONCompareResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JSONCompareResult类属于org.skyscreamer.jsonassert包,在下文中一共展示了JSONCompareResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: assertEqualsJson

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
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)
                        + "\n================= Actual JSON ================="
                        + new JSONObject(actualJson).toString(4)
                        + "\n================= Error List ==================\n"
                        + failureMessage + "\n\n";
                fail(failureMessage);
            }
        } catch (JSONException e) {
            throw new RuntimeException("JSON completely failed to parse json", e);
        }
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:JsonAssert.java


示例2: jsonDiff

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
public Map<String, Object> jsonDiff() throws IOException, JSONException {
    Map<String, Object> jsonDiffResults = new HashMap<>();
    JSONCompareResult jsonCompareResult;
    JSONCompareMode jsonCompareMode = JSONCompareMode.LENIENT;
    if ("R2".equals(getModelType())) {
        // Comparing R2 data model with a model converted from DD4T
        jsonCompareResult = compareJSON(getJsonObject(getR2JsonUrl()), getJsonObject(getDd4tJsonUrl()), jsonCompareMode);
    } else {
        // Comparing DD4T data model with a model converted from R2
        jsonCompareResult = compareJSON(getJsonObject(getDd4tJsonUrl()), getJsonObject(getR2JsonUrl()), jsonCompareMode);
    }
    jsonDiffResults.put("testPassed", String.valueOf(jsonCompareResult.passed()));
    jsonDiffResults.put("compareMessage", jsonCompareResult.getMessage().split(";"));
    jsonDiffResults.put("fieldFailures", jsonCompareResult.getFieldFailures());
    jsonDiffResults.put("fieldMissing", jsonCompareResult.getFieldMissing());
    jsonDiffResults.put("fieldUnexpected", jsonCompareResult.getFieldUnexpected());
    return jsonDiffResults;
}
 
开发者ID:sdl,项目名称:dxa-modules,代码行数:19,代码来源:DataConverterModel.java


示例3: logInconsistencyUsingJSONCompare

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
private void logInconsistencyUsingJSONCompare(final String parentThreadName, final String legacyJson, final String lightblueJson, final MethodCallStringifier callToLogInCaseOfInconsistency) {
    try {
        Timer t = new Timer("ConsistencyCheck (JSONCompare)");

        JSONCompareResult result = JSONCompare.compareJSON(legacyJson, lightblueJson, JSONCompareMode.NON_EXTENSIBLE);

        long jiffConsistencyCheckTook = t.complete();

        if (inconsistencyLog.isDebugEnabled()) {
            inconsistencyLog.debug(String.format("[%s] JSONCompare consistency check took: %dms", parentThreadName, jiffConsistencyCheckTook));
            inconsistencyLog.debug(String.format("[%s] JSONCompare consistency check passed: true", parentThreadName));
        }

        if (result.passed()) {
            inconsistencyLog.error(String.format("[%s] Jiff consistency check found an inconsistency but JSONCompare didn't! Happened in %s", parentThreadName, callToLogInCaseOfInconsistency.toString()));
            return;
        }

        // log nice diff
        logInconsistency(parentThreadName, callToLogInCaseOfInconsistency.toString(), legacyJson, lightblueJson, result.getMessage().replaceAll("\n", ","));
    } catch (Exception e) {
        inconsistencyLog.error("JSONCompare consistency check failed for " + callToLogInCaseOfInconsistency, e);
    }
}
 
开发者ID:lightblue-platform,项目名称:lightblue-migrator,代码行数:25,代码来源:ConsistencyChecker.java


示例4: compareValues

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException {
	if (JsonCompareKeywords.SKIP.getKey().equals(expectedValue.toString())) {
		// do nothing
	} else if (expectedValue != null && expectedValue.toString().startsWith(JsonCompareKeywords.TYPE.getKey())) {
		String expType = expectedValue.toString().replace(JsonCompareKeywords.TYPE.getKey(), "");
		if (!expType.equals(actualValue.getClass().getSimpleName())) {
			result.fail(String.format("%s\nValue type '%s' doesn't match to expected type '%s'\n", prefix, actualValue.getClass()
					.getSimpleName(), expType));
		}
	} else if (expectedValue != null && expectedValue.toString().startsWith(JsonCompareKeywords.REGEX.getKey())) {
		if (actualValue instanceof Number || actualValue instanceof String) {
			String actualStr = actualValue.toString();
			String regex = expectedValue.toString().replace(JsonCompareKeywords.REGEX.getKey(), "");
			Matcher m = Pattern.compile(regex).matcher(actualStr);
			if (!m.find()) {
				result.fail(String.format("%s\nActual value '%s' doesn't match to expected regex '%s'\n", prefix, actualStr, regex));
			}
		} else {
			super.compareValues(prefix, expectedValue, actualValue, result);
		}
	} else {
		super.compareValues(prefix, expectedValue, actualValue, result);
	}
}
 
开发者ID:qaprosoft,项目名称:carina,代码行数:26,代码来源:JsonKeywordsComparator.java


示例5: compareJSONArrayForSimpleTypeWContains

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
private void compareJSONArrayForSimpleTypeWContains(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException {
	if(expected.length() == 1 && JsonCompareKeywords.SKIP.getKey().equals(expected.get(0).toString())){
		return;
	}
	for (int i = 0; i < expected.length(); ++i) {
		boolean isEquals = false;
		
		for (int j = 0; j < actual.length(); ++j) {
			if(expected.get(i).equals(actual.get(j))){
				isEquals = true;
				break;
			}
		}
		
		if (!isEquals) {
			result.fail(String.format("%s\nExpected array item '"+expected.get(i)+"' is missed in actual array\n", prefix));
		}
	}
}
 
开发者ID:qaprosoft,项目名称:carina,代码行数:20,代码来源:JsonKeywordsComparator.java


示例6: isDifferenceInDefinition

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
private boolean isDifferenceInDefinition(String currentIndex, String definition){
		
	try {
		JSONCompareResult result = JSONCompare.compareJSON(definition, currentIndex, JSONCompareMode.STRICT);
		return result.passed();
		
	} catch (JSONException ex){
		logger.error("Failed while checking indexes", ex);
	}
	
	return false;
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:13,代码来源:MongoPersistentEntityIndexCreator.java


示例7: compare

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
private JSONCompareResult compare(CharSequence expectedJson,
		JSONCompareMode compareMode) {
	if (this.actual == null) {
		return compareForNull(expectedJson);
	}
	return JSONCompare.compareJSON(
			(expectedJson == null ? null : expectedJson.toString()),
			this.actual.toString(), compareMode);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:JsonContentAssert.java


示例8: compareForNull

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
private JSONCompareResult compareForNull(CharSequence expectedJson) {
	JSONCompareResult result = new JSONCompareResult();
	result.passed();
	if (expectedJson != null) {
		result.fail("Expected null JSON");
	}
	return result;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:JsonContentAssert.java


示例9: logFailure

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
public static void logFailure(final String errorText, final JSONCompareResult jsonResult) {
    final List<FieldComparisonFailure> failureList = jsonResult.getFieldFailures();

    for (FieldComparisonFailure failure : failureList) {
        Log.warnFormatted(errorText, failure.getField(), failure.getExpected(), failure.getActual());
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:8,代码来源:UaiJsonFieldFailureLogger.java


示例10: checkJsonObjectKeysExpectedInActual

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Override
protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) throws JSONException {
    final Set<String> expectedKeys = getKeys(expected);
    for (String key : expectedKeys) {
        final Object expectedValue = expected.get(key);
        if (actual.has(key)) {
            final Object actualValue = actual.get(key);
            compareValues(qualify(prefix, key), expectedValue, actualValue, result);
        } else {
            result.missing(prefix, key);
            result.fail(key, expectedValue, "we did not received the value");
        }
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:15,代码来源:UaiJSONComparator.java


示例11: checkJsonObjectKeysActualInExpected

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Override
protected void checkJsonObjectKeysActualInExpected(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) {
    final Set<String> actualKeys = getKeys(actual);

    for (String key : actualKeys) {
        if (!expected.has(key)) {
            result.unexpected(prefix, key);
            final Object actualValue = actual.opt(key);
            result.fail(key, actualValue, String.format("The [%s] is not mapped", key));
        }
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:13,代码来源:UaiJSONComparator.java


示例12: compareJSON

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator){
    try {
        return JSONCompare.compareJSON(expectedStr, actualStr, comparator);
    } catch (JSONException ex) {
        throw new IllegalStateException(ex);
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:8,代码来源:UaiJSONCompareWrapper.java


示例13: isListingMoreThanOneNotPresentAttribute

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Test
public void isListingMoreThanOneNotPresentAttribute() {
    final JSONCompareResult jsonCompareResult = UaiJSONCompareWrapper.compareJSON("{id:1, age:1, aNumber:1}", "{name:\"JC\"}", STRICT_COMPARATOR);

    final List<FieldComparisonFailure> failureList = jsonCompareResult.getFieldFailures();

    assertTrue("all the missing fields should be present", failureList.size() > 1);
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:9,代码来源:UaiJSONComparatorErrorTest.java


示例14: isListingErrorWithWrongValueInAttribute

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Test
public void isListingErrorWithWrongValueInAttribute() {
    final JSONCompareResult jsonCompareResult = UaiJSONCompareWrapper.compareJSON("{id:1}", "{id:2}", STRICT_COMPARATOR);

    final List<FieldComparisonFailure> failureList = jsonCompareResult.getFieldFailures();

    assertTrue("all the missing fields should be present", failureList.size() == 1);
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:9,代码来源:UaiJSONComparatorErrorTest.java


示例15: isComparingWithLine

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Test
public void isComparingWithLine() {
    final String jsonWithoutLines = "{id:1,age:33}";
    final String jsonWithLines = "" +
            "{" +
            "   id:1," +
            "   age:33" +
            "}";
    final JSONCompareResult jsonCompareResult = UaiJSONCompareWrapper.compareJSON(jsonWithoutLines, jsonWithLines, STRICT_COMPARATOR);

    final List<FieldComparisonFailure> failureList = jsonCompareResult.getFieldFailures();

    assertTrue("Should not have any error", failureList.isEmpty());
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:15,代码来源:UaiJSONComparatorErrorTest.java


示例16: isComparingWithSuccess

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Test
public void isComparingWithSuccess() {
    final JSONCompareResult jsonCompareResult = UaiJSONCompareWrapper.compareJSON("{id:1}", "{id:1}", STRICT_COMPARATOR);

    final List<FieldComparisonFailure> failureList = jsonCompareResult.getFieldFailures();

    assertTrue("Should not have any error", failureList.isEmpty());
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:9,代码来源:UaiJSONComparatorSuccessTest.java


示例17: isIgnoringWhenNotRequired

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Test
public void isIgnoringWhenNotRequired() {
    final JSONCompareResult jsonCompareResult = UaiJSONCompareWrapper.compareJSON("{id:1}", "{id:1, age:33}", LENIENT_COMPARATOR);

    final List<FieldComparisonFailure> failureList = jsonCompareResult.getFieldFailures();

    assertTrue("Should not have any error", failureList.isEmpty());
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:9,代码来源:UaiJSONComparatorSuccessTest.java


示例18: test

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Test
public void test() throws Exception {
    String s1 = "{ \"f1\":1, \"obj\":{ \"f2\":2}, \"arr\":[ {\"f4\":3 } ] }";
    String s2 = "{ \"f1\":2, \"obj\":{ \"f2\":3 }, \"arr\":[ {\"f4\":4 } ] }";
    JSONCompareResult result = JSONCompare.compareJSON(s1, s2,
            JSONCompareMode.STRICT);
    for (FieldComparisonFailure x : result.getFieldFailures()) {
        System.out.println(x.getField() + " " + x.getExpected() + " " + x.getActual());
    }
}
 
开发者ID:lightblue-platform,项目名称:lightblue-migrator,代码行数:11,代码来源:JsTest.java


示例19: matches

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
public boolean matches(final HttpRequest context, String matched) {
    boolean result = false;

    JSONCompareResult jsonCompareResult;
    try {
        if (Strings.isNullOrEmpty(matcher)) {
            result = true;
        } else {
            JSONCompareMode jsonCompareMode = JSONCompareMode.LENIENT;
            if (matchType == MatchType.STRICT) {
                jsonCompareMode = JSONCompareMode.STRICT;
            }
            jsonCompareResult = compareJSON(matcher, matched, jsonCompareMode);

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

            if (!result) {
                mockServerLogger.trace(context, "Failed to perform JSON match \"{}\" with \"{}\" because {}", matched, this.matcher, jsonCompareResult.getMessage());
            }
        }
    } catch (Exception e) {
        mockServerLogger.trace(context, "Failed to perform JSON match \"{}\" with \"{}\" because {}", matched, this.matcher, e.getMessage());
    }

    return not != result;
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:29,代码来源:JsonStringMatcher.java


示例20: matchesSafely

import org.skyscreamer.jsonassert.JSONCompareResult; //导入依赖的package包/类
@Override
protected boolean matchesSafely(JSONIterator actual, Description mismatchDescription)
{
    int line = 1;

    Iterator<String> itLeft = expected;
    Iterator<String> itRight = actual;

    while (true) {
        boolean hasLeft = itLeft.hasNext();
        boolean hasRight = itRight.hasNext();

        if (hasLeft && hasRight) {
            String left = itLeft.next();
            String right = itRight.next();

            try {
                JSONCompareResult r = JSONCompare.compareJSON(left, right, JSONCompareMode.STRICT);
                if (r.failed()) {
                    mismatchDescription.appendText("at line " + line + ": ");
                    mismatchDescription.appendText(r.getMessage());
                    return false;
                }
            }
            catch (JSONException e) {
                mismatchDescription.appendText("at line " + line + ": ");
                mismatchDescription.appendText(e.toString());
                throw new AssertionError(e);
            }
        }
        else if (!hasLeft && !hasRight) {
            return true;
        }
        else {
            // left or right has extra line
            mismatchDescription.appendText("at line " + line + ": ");
            if (hasLeft) {
                mismatchDescription.appendText("expected has extra lines");
            }
            else {
                mismatchDescription.appendText("actual has extra lines");
            }
            return false;
        }

        line += 1;
    }
}
 
开发者ID:CyberAgent,项目名称:embulk-input-parquet_hadoop,代码行数:49,代码来源:JSONIteratorMatcher.java



注:本文中的org.skyscreamer.jsonassert.JSONCompareResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TIOError类代码示例发布时间:2022-05-22
下一篇:
Java UndoableEditSupport类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap