当前位置: 首页>>代码示例>>Java>>正文


Java JSONCompareResult类代码示例

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


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


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