JsonParserTest.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:hapi-fhir 作者:
@Test
public void testEncodeBundle() throws InterruptedException {
    Bundle b = new Bundle();

    InstantDt pub = InstantDt.withCurrentTime();
    Thread.sleep(2);

    Patient p1 = new Patient();
    p1.addName().addFamily("Family1");
    BundleEntry entry = b.addEntry();
    entry.getId().setValue("1");
    entry.setResource(p1);
    entry.getSummary().setValueAsString("this is the summary");

    Patient p2 = new Patient();
    p2.addName().addFamily("Family2");
    entry = b.addEntry();
    entry.getId().setValue("2");
    entry.setLinkAlternate(new StringDt("http://foo/bar"));
    entry.setResource(p2);

    BundleEntry deletedEntry = b.addEntry();
    deletedEntry.setId(new IdDt("Patient/3"));
    InstantDt nowDt = InstantDt.withCurrentTime();
    deletedEntry.setDeleted(nowDt);

    String bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
    ourLog.info(bundleString);

    List<String> strings = new ArrayList<String>();
    strings.addAll(Arrays.asList("\"id\": \"1\""));
    strings.addAll(Arrays.asList("this is the summary"));
    strings.addAll(Arrays.asList("\"id\": \"2\"", "\"rel\": \"alternate\"", "\"href\": \"http://foo/bar\""));
    strings.addAll(Arrays.asList("\"deleted\": \"" + nowDt.getValueAsString() + "\"", "\"id\": \"Patient/3\""));
    assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));

    b.getEntries().remove(2);
    bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
    assertThat(bundleString, not(containsString("deleted")));

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号