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

Java JSONCompare类代码示例

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

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



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

示例1: logInconsistencyUsingJSONCompare

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的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


示例2: isDifferenceInDefinition

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的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


示例3: compare

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的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


示例4: compareJSON

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的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


示例5: equals

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
    try {
        if ((obj instanceof JSONWrapper) && JSONCompare.compareJSON(value.toString(), ((JSONWrapper) obj).value.toString(), mode).passed()) {
            return true;
        }
    } catch (JSONException e) {
        return false;
    }
    return false;
}
 
开发者ID:lightblue-platform,项目名称:lightblue-esb-hook,代码行数:12,代码来源:JSONWrapper.java


示例6: should

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的package包/类
@Then("^the json response's body should (contain|be):$")
public void then_response_json_body_should_satisfy(String comparator, String expectedText) throws JSONException {
    HttpResponse response = httpWorld.lastResponse();
    String actual = response.bodyAsText();

    JSONCompareMode mode = JSONCompareMode.LENIENT;
    if (comparator.equals("be"))
        mode = JSONCompareMode.NON_EXTENSIBLE;

    JSONCompare.compareJSON(expectedText, actual, mode);
}
 
开发者ID:Arnauld,项目名称:bidij,代码行数:12,代码来源:RawHttpStepdefs.java


示例7: test

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的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


示例8: testJSONComparePerformance

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的package包/类
/**
 * On my machine: JSONCompare consistency check took 370ms.
 *
 * @throws IOException
 * @throws JSONException
 */
@Test
public void testJSONComparePerformance() throws IOException, JSONException {

    String jsonStr = new ObjectMapper().writeValueAsString(fooList);

    log.info("Json str size: " + jsonStr.length() / 1024 + "kB");

    Timer t = new Timer("JSONCompare.compareJSON");
    Assert.assertTrue(JSONCompare.compareJSON(jsonStr, jsonStr, JSONCompareMode.LENIENT).passed());
    long tookMs = t.complete();
    log.info("JSONCompare consistency check took " + tookMs + "ms");
}
 
开发者ID:lightblue-platform,项目名称:lightblue-migrator,代码行数:19,代码来源:ConsistencyCheckPerforformanceTest.java


示例9: matchesSafely

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的package包/类
/**
 * Compares the item (which represents the actual result) against the expected value to see if they are the same JSON.  These two
 * values
 * may not be equal as Strings, but the JSON comparison should ignore unnecessary whitespace and the differences between " and '.
 *
 * @param item a String containing valid JSON to compare against the expected value
 * @return true if the expected and actual values are equivalent JSON values
 */
@Override
public boolean matchesSafely(final String item) {
    try {
        return JSONCompare.compareJSON(expectedJson, item, JSONCompareMode.STRICT).passed();
    } catch (final JSONException e) {
        Assert.fail(String.format("JSON compare threw exception when trying to compare %n %s %n with %n %s%n Exception was: %n%s ",
                                  expectedJson, item, e));
        return false;
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:19,代码来源:JSONMatcher.java


示例10: matchesSafely

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的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


示例11: processHook

import org.skyscreamer.jsonassert.JSONCompare; //导入依赖的package包/类
@Override
public void processHook(EntityMetadata entityMetadata, HookConfiguration hookConfiguration, List<HookDoc> docs) {
    if (!(hookConfiguration instanceof PublishHookConfiguration)) {
        throw new IllegalArgumentException("Only instances of PublishHookConfiguration are supported.");
    }

    PublishHookConfiguration publishHookConfiguration = (PublishHookConfiguration) hookConfiguration;

    for (HookDoc doc : docs) {

        for (EventConfiguration eventConfiguration : publishHookConfiguration.getEventConfigurations()) {

            try {
                LOGGER.debug("eventConfiguration.getIdentityProjection: {}", eventConfiguration.getIdentityProjection());
                Projection integratedFieldsProjection = Projection
                        .add(eventConfiguration.getIdentityProjection(), eventConfiguration.getIntegratedFieldsProjection());
                Projector identityProjector = Projector.getInstance(eventConfiguration.getIdentityProjection(), entityMetadata);
                Projector integratedFieldsProjector = Projector.getInstance(integratedFieldsProjection, entityMetadata);

                String integrationProjectedPreDoc = null, integrationProjectedPostDoc, identityProjectedPostDoc;
                if (doc.getPreDoc() != null) {
                    integrationProjectedPreDoc = integratedFieldsProjector.project(doc.getPreDoc(), factory).toString();
                }
                // no point in creating events if post doc is not available
                if (doc.getPostDoc() != null) {
                    LOGGER.debug("postDoc: {}", doc.getPostDoc());
                    integrationProjectedPostDoc = integratedFieldsProjector.project(doc.getPostDoc(), factory).toString();
                    identityProjectedPostDoc = identityProjector.project(doc.getPostDoc(), factory).toString();

                    if (doc.getPreDoc() == null
                            || JSONCompare.compareJSON(integrationProjectedPreDoc, integrationProjectedPostDoc, JSONCompareMode.LENIENT).failed()) {
                        LOGGER.debug("integrationProjectedPreDoc: {}", integrationProjectedPreDoc);
                        LOGGER.debug("integrationProjectedPostDoc: {}", integrationProjectedPostDoc);
                        LOGGER.debug("identityProjectedPostDoc: {}", identityProjectedPostDoc);
                        Set<Event> extractedEvents = EventExctractionUtil.compareAndExtractEvents(
                                integrationProjectedPreDoc,
                                integrationProjectedPostDoc,
                                identityProjectedPostDoc);
                        for (Event event : extractedEvents) {
                            event.setEntityName(doc.getEntityMetadata().getName());
                            event.setVersion(doc.getEntityMetadata().getVersion().getValue());

                            event.setEsbRootEntityName(eventConfiguration.getEsbRootEntityName());
                            event.setEsbEventEntityName(eventConfiguration.getEsbEventEntityName());
                            event.setEndSystem(eventConfiguration.getEndSystem());
                            event.setCreatedBy(HOOK_NAME);
                            event.setCreationDate(doc.getWhen());
                            event.addHeaders(eventConfiguration.getHeaders());
                            event.setLastUpdatedBy(HOOK_NAME);
                            event.setLastUpdateDate(doc.getWhen());
                            event.setStatus(Event.Status.UNPROCESSED);

                            if (!StringUtils.isEmpty(doc.getWho())) {
                                event.setEventSource(doc.getWho());
                            } else {
                                event.setEventSource("Unknown");
                            }

                            if (eventConfiguration.getRootIdentityFields() != null && eventConfiguration.getRootIdentityFields().size() > 0) {
                                event.addRootIdentities(getRootIdentities(event.getIdentity(), eventConfiguration.getRootIdentityFields()));
                            }

                            insert(ENTITY_NAME, event);
                        }
                    }
                }
            } catch (IllegalArgumentException | JSONException e) {
                LOGGER.error("Unexpected exception while preparing events for insertion.", e);
            }
        }
    }
}
 
开发者ID:lightblue-platform,项目名称:lightblue-esb-hook,代码行数:73,代码来源:PublishHook.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java BERTags类代码示例发布时间:2022-05-22
下一篇:
Java ResourceAccessException类代码示例发布时间: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