/** * Thanks to Alexander Kley! */ @Test public void testParseContainedBinaryResource() { byte[] bin = new byte[] { 0, 1, 2, 3, 4 }; final Binary binary = new Binary("PatientConsent", bin); // binary.setId(UUID.randomUUID().toString()); DocumentManifest manifest = new DocumentManifest(); // manifest.setId(UUID.randomUUID().toString()); manifest.setType(new CodeableConceptDt("mySystem", "PatientDocument")); manifest.setMasterIdentifier("mySystem", UUID.randomUUID().toString()); manifest.addContent().setResource(binary); manifest.setStatus(DocumentReferenceStatusEnum.CURRENT); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(manifest); ourLog.info(encoded); assertThat(encoded, StringContainsInOrder.stringContainsInOrder(Arrays.asList("contained>", "<Binary", "</contained>"))); DocumentManifest actual = ourCtx.newXmlParser().parseResource(DocumentManifest.class, encoded); assertEquals(1, actual.getContained().getContainedResources().size()); assertEquals(1, actual.getContent().size()); assertNotNull(actual.getContent().get(0).getResource()); }
@Test public void testEncodeBundle() throws InterruptedException { Bundle b = new Bundle(); b.getCategories().addTag("http://hl7.org/fhir/tag", "http://hl7.org/fhir/tag/message", "Message"); InstantDt pub = InstantDt.withCurrentTime(); Thread.sleep(2); Patient p1 = new Patient(); p1.addName().addFamily("Family1"); p1.getId().setValue("1"); BundleEntry entry = b.addEntry(); entry.setResource(p1); entry.getSummary().setValueAsString("this is the summary"); Patient p2 = new Patient(); p2.addName().addFamily("Family2"); p2.getId().setValue("2"); entry = b.addEntry(); entry.setLinkAlternate(new StringDt("http://foo/bar")); entry.setLinkSearch(new StringDt("http://foo/bar/search")); entry.setResource(p2); BundleEntry deletedEntry = b.addEntry(); deletedEntry.setDeletedResourceId(new IdDt("Patient/3")); deletedEntry.setDeleted(InstantDt.withCurrentTime()); String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b); ourLog.info(bundleString); List<String> strings = new ArrayList<String>(); strings.add("<category term=\"http://hl7.org/fhir/tag/message\" label=\"Message\" scheme=\"http://hl7.org/fhir/tag\"/>"); strings.addAll(Arrays.asList("<entry>", "<id>1</id>", "</Patient>", "<summary type=\"xhtml\">", "<div", "</entry>")); strings.addAll(Arrays.asList("<entry>", "<id>2</id>", "<link rel=\"alternate\" href=\"http://foo/bar\"/>", "<link rel=\"search\" href=\"http://foo/bar/search\"/>", "</entry>")); strings.addAll(Arrays.asList("<at:deleted-entry", "ref=\"Patient/3", "/>")); assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings)); assertThat(bundleString, not(containsString("at:by"))); }
@SuppressWarnings("deprecation") @Test public void testEncodeBundleOldIdForm() throws InterruptedException { Bundle b = new Bundle(); b.getCategories().addTag("http://hl7.org/fhir/tag", "http://hl7.org/fhir/tag/message", "Message"); 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.setLinkSearch(new StringDt("http://foo/bar/search")); entry.setResource(p2); BundleEntry deletedEntry = b.addEntry(); deletedEntry.setId(new IdDt("Patient/3")); deletedEntry.setDeleted(InstantDt.withCurrentTime()); String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b); ourLog.info(bundleString); List<String> strings = new ArrayList<String>(); strings.add("<category term=\"http://hl7.org/fhir/tag/message\" label=\"Message\" scheme=\"http://hl7.org/fhir/tag\"/>"); strings.addAll(Arrays.asList("<entry>", "<id>1</id>", "</Patient>", "<summary type=\"xhtml\">", "<div", "</entry>")); strings.addAll(Arrays.asList("<entry>", "<id>2</id>", "<link rel=\"alternate\" href=\"http://foo/bar\"/>", "<link rel=\"search\" href=\"http://foo/bar/search\"/>", "</entry>")); strings.addAll(Arrays.asList("<at:deleted-entry", "ref=\"Patient/3", "/>")); assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings)); assertThat(bundleString, not(containsString("at:by"))); }
/** * Thanks to Alexander Kley! */ @Test public void testParseContainedBinaryResource() { byte[] bin = new byte[] {0,1,2,3,4}; final Binary binary = new Binary(); binary.setContentType("PatientConsent").setContent( bin); // binary.setId(UUID.randomUUID().toString()); DocumentManifest manifest = new DocumentManifest(); // manifest.setId(UUID.randomUUID().toString()); CodeableConcept cc = new CodeableConcept(); cc.addCoding().setSystem("mySystem").setCode( "PatientDocument"); manifest.setType(cc); manifest.setMasterIdentifier(new Identifier().setSystem("mySystem").setValue( UUID.randomUUID().toString())); manifest.addContent().setResource(binary); manifest.setStatus(DocumentReferenceStatus.CURRENT); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(manifest); ourLog.info(encoded); assertThat(encoded, StringContainsInOrder.stringContainsInOrder(Arrays.asList("contained>","<Binary", "</contained>"))); DocumentManifest actual = ourCtx.newXmlParser().parseResource(DocumentManifest.class, encoded); assertEquals(1, actual.getContained().size()); assertEquals(1, actual.getContent().size()); assertNotNull(actual.getContent().get(0).getResource()); }
@Test public void testEncodeBundle() throws InterruptedException { Bundle b = new Bundle(); b.getMeta().addTag().setSystem("http://hl7.org/fhir/tag").setCode( "http://hl7.org/fhir/tag/message").setDisplay("Message"); InstantType pub = InstantType.withCurrentTime(); b.getMeta().setLastUpdatedElement(pub); Patient p1 = new Patient(); p1.addName().addFamily("Family1"); BundleEntryComponent entry = b.addEntry(); p1.getIdElement().setValue("1"); entry.setResource(p1); Patient p2 = new Patient(); p2.addName().addFamily("Family2"); entry = b.addEntry(); p2.getIdElement().setValue("2"); entry.setResource(p2); String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b); ourLog.info(bundleString); List<String> strings = new ArrayList<String>(); strings.addAll(Arrays.asList("<published>", pub.getValueAsString(), "</published>")); strings.add("<category term=\"http://hl7.org/fhir/tag/message\" label=\"Message\" scheme=\"http://hl7.org/fhir/tag\"/>"); strings.addAll(Arrays.asList("<entry>", "<id>1</id>", "</Patient>", "<summary type=\"xhtml\">", "<div", "</entry>")); strings.addAll(Arrays.asList("<entry>", "<id>2</id>", "<link rel=\"alternate\" href=\"http://foo/bar\"/>", "<link rel=\"search\" href=\"http://foo/bar/search\"/>", "</entry>")); assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings)); assertThat(bundleString, not(containsString("at:by"))); }
/** * Thanks to Alexander Kley! */ @Test public void testParseContainedBinaryResource() { byte[] bin = new byte[]{0, 1, 2, 3, 4}; final Binary binary = new Binary(); binary.setContentType("PatientConsent").setContent(bin); DocumentManifest manifest = new DocumentManifest(); CodeableConcept cc = new CodeableConcept(); cc.addCoding().setSystem("mySystem").setCode("PatientDocument"); manifest.setType(cc); manifest.setMasterIdentifier(new Identifier().setSystem("mySystem").setValue(UUID.randomUUID().toString())); manifest.addContent().setP(new Reference(binary)); manifest.setStatus(DocumentReferenceStatus.CURRENT); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(manifest); ourLog.info(encoded); assertThat(encoded, StringContainsInOrder.stringContainsInOrder(Arrays.asList("contained>", "<Binary", "</contained>"))); DocumentManifest actual = ourCtx.newXmlParser().parseResource(DocumentManifest.class, encoded); assertEquals(1, actual.getContained().size()); assertEquals(1, actual.getContent().size()); /* * If this fails, it's possibe the DocumentManifest structure is wrong: It should be * * @Child(name = "p", type = {Attachment.class, ValueSet.class}, order=1, min=1, max=1, modifier=false, summary=true) */ assertNotNull(((Reference) actual.getContent().get(0).getP()).getResource()); }
/** * Thanks to Alexander Kley! */ @Test public void testParseContainedBinaryResource() { byte[] bin = new byte[] { 0, 1, 2, 3, 4 }; final Binary binary = new Binary(); binary.setContentType("PatientConsent").setContent(bin); DocumentManifest manifest = new DocumentManifest(); CodeableConcept cc = new CodeableConcept(); cc.addCoding().setSystem("mySystem").setCode("PatientDocument"); manifest.setType(cc); manifest.setMasterIdentifier(new Identifier().setSystem("mySystem").setValue(UUID.randomUUID().toString())); manifest.addContent().setP(new Reference(binary)); manifest.setStatus(DocumentReferenceStatus.CURRENT); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(manifest); ourLog.info(encoded); assertThat(encoded, StringContainsInOrder.stringContainsInOrder(Arrays.asList("contained>", "<Binary", "</contained>"))); DocumentManifest actual = ourCtx.newXmlParser().parseResource(DocumentManifest.class, encoded); assertEquals(1, actual.getContained().size()); assertEquals(1, actual.getContent().size()); /* * If this fails, it's possibe the DocumentManifest structure is wrong: It should be * * @Child(name = "p", type = {Attachment.class, ValueSet.class}, order=1, min=1, max=1, modifier=false, summary=true) */ assertNotNull(((Reference) actual.getContent().get(0).getP()).getResource()); }
/** * Thanks to Alexander Kley! */ @Test public void testParseContainedBinaryResource() { byte[] bin = new byte[] { 0, 1, 2, 3, 4 }; final Binary binary = new Binary(); binary.setContentType("PatientConsent").setContent(bin); // binary.setId(UUID.randomUUID().toString()); ca.uhn.fhir.model.dstu2.resource.DocumentManifest manifest = new ca.uhn.fhir.model.dstu2.resource.DocumentManifest(); // manifest.setId(UUID.randomUUID().toString()); CodeableConceptDt cc = new CodeableConceptDt(); cc.addCoding().setSystem("mySystem").setCode("PatientDocument"); manifest.setType(cc); manifest.setMasterIdentifier(new IdentifierDt().setSystem("mySystem").setValue(UUID.randomUUID().toString())); manifest.addContent().setP(new ResourceReferenceDt(binary)); manifest.setStatus(DocumentReferenceStatusEnum.CURRENT); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(manifest); ourLog.info(encoded); assertThat(encoded, StringContainsInOrder.stringContainsInOrder(Arrays.asList("contained>", "<Binary", "</contained>"))); ca.uhn.fhir.model.dstu2.resource.DocumentManifest actual = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.DocumentManifest.class, encoded); assertEquals(1, actual.getContained().getContainedResources().size()); assertEquals(1, actual.getContent().size()); assertNotNull(((ResourceReferenceDt) actual.getContent().get(0).getP()).getResource()); }
@Test public void testEncodeBundle() throws InterruptedException { Bundle b = new Bundle(); b.getMeta().addTag().setSystem("http://hl7.org/fhir/tag").setCode("http://hl7.org/fhir/tag/message") .setDisplay("Message"); InstantType pub = InstantType.withCurrentTime(); b.getMeta().setLastUpdatedElement(pub); Patient p1 = new Patient(); p1.addName().addFamily("Family1"); BundleEntryComponent entry = b.addEntry(); p1.getIdElement().setValue("1"); entry.setResource(p1); Patient p2 = new Patient(); p2.addName().addFamily("Family2"); entry = b.addEntry(); p2.getIdElement().setValue("2"); entry.setResource(p2); String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b); ourLog.info(bundleString); // @formatter:on String[] strings = { "<Bundle xmlns=\"http://hl7.org/fhir\">", "<lastUpdated value=\"" + pub.getValueAsString() + "\"/>", "<Patient xmlns=\"http://hl7.org/fhir\">", "<id value=\"1\"/>", "<Patient xmlns=\"http://hl7.org/fhir\">", "<id value=\"2\"/>" }; // @formatter:off assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings)); }
/** * Thanks to Alexander Kley! */ @Test public void testParseContainedBinaryResource() throws Exception { byte[] bin = new byte[] { 0, 1, 2, 3, 4 }; final Binary binary = new Binary(); binary.setContentType("PatientConsent").setContent(bin); // binary.setId(UUID.randomUUID().toString()); DocumentManifest manifest = new DocumentManifest(); // manifest.setId(UUID.randomUUID().toString()); CodeableConcept cc = new CodeableConcept(); cc.addCoding().setSystem("mySystem").setCode("PatientDocument"); manifest.setType(cc); manifest.setMasterIdentifier(new Identifier().setSystem("mySystem").setValue(UUID.randomUUID().toString())); manifest.addContent().setP(new Reference(binary)); manifest.setStatus(org.hl7.fhir.instance.model.Enumerations.DocumentReferenceStatus.CURRENT); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(manifest); ourLog.info(encoded); assertThat(encoded, StringContainsInOrder.stringContainsInOrder(Arrays.asList("contained>", "<Binary", "</contained>"))); DocumentManifest actual = ourCtx.newXmlParser().parseResource(DocumentManifest.class, encoded); assertEquals(1, actual.getContained().size()); assertEquals(1, actual.getContent().size()); /* * If this fails, the child named "p" in DocumentManifest is missing the * type IBaseResource in its definition... This isn't being auto added right * now, need to figure out why * * @Child(name = "p", type = {Attachment.class, IBaseResource.class}, * order=1, min=1, max=1, modifier=false, summary=true) */ assertNotNull(actual.getContent().get(0).getPReference().getResource()); }
private static Matcher<String> stringContainsInOrder(String... substrings) { return new StringContainsInOrder(Arrays.asList(substrings)); }
@Test public void testParseEncodeNarrative() { String input = "<Patient xmlns=\"http://hl7.org/fhir\"><text><status value=\"generated\"/><div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\"> Donald null <b>DUCK </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>7000135</td></tr><tr><td>Address</td><td><span>10 Duxon Street </span><br/><span>VICTORIA </span><span>BC </span><span>Can </span></td></tr><tr><td>Date of birth</td><td><span>01 June 1980</span></td></tr></tbody></table></div></text><identifier><use value=\"official\"/><label value=\"University Health Network MRN 7000135\"/><system value=\"urn:oid:2.16.840.1.113883.3.239.18.148\"/><value value=\"7000135\"/><assigner><reference value=\"Organization/1.3.6.1.4.1.12201\"/></assigner></identifier><name><family value=\"Duck\"/><given value=\"Donald\"/></name><telecom><system value=\"phone\"/><use value=\"home\"/></telecom><telecom><system value=\"phone\"/><use value=\"work\"/></telecom><telecom><system value=\"phone\"/><use value=\"mobile\"/></telecom><telecom><system value=\"email\"/><use value=\"home\"/></telecom><gender><coding><system value=\"http://hl7.org/fhir/v3/AdministrativeGender\"/><code value=\"M\"/></coding></gender><birthDate value=\"1980-06-01T00:00:00\"/><address><use value=\"home\"/><line value=\"10 Duxon Street\"/><city value=\"VICTORIA\"/><state value=\"BC\"/><zip value=\"V8N 1Y4\"/><country value=\"Can\"/></address><managingOrganization><reference value=\"Organization/1.3.6.1.4.1.12201\"/></managingOrganization></Patient>"; IResource res = ourCtx.newXmlParser().parseResource(input); String output = ourCtx.newXmlParser().encodeResourceToString(res); // Should occur exactly twice (once for the resource, once for the DIV assertThat(output, (StringContainsInOrder.stringContainsInOrder(Arrays.asList("Patient xmlns", "div xmlns")))); assertThat(output, not(StringContainsInOrder.stringContainsInOrder(Arrays.asList("b xmlns")))); output = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(res); // Should occur exactly twice (once for the resource, once for the DIV assertThat(output, (StringContainsInOrder.stringContainsInOrder(Arrays.asList("Patient xmlns", "div xmlns")))); assertThat(output, not(StringContainsInOrder.stringContainsInOrder(Arrays.asList("b xmlns")))); }
@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"))); }
@Test public void testParseEncodeNarrative() { String input = "<Patient xmlns=\"http://hl7.org/fhir\"><text><status value=\"generated\"/><div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\"> Donald null <b>DUCK </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>7000135</td></tr><tr><td>Address</td><td><span>10 Duxon Street </span><br/><span>VICTORIA </span><span>BC </span><span>Can </span></td></tr><tr><td>Date of birth</td><td><span>01 June 1980</span></td></tr></tbody></table></div></text><identifier><use value=\"official\"/><label value=\"University Health Network MRN 7000135\"/><system value=\"urn:oid:2.16.840.1.113883.3.239.18.148\"/><value value=\"7000135\"/><assigner><reference value=\"Organization/1.3.6.1.4.1.12201\"/></assigner></identifier><name><family value=\"Duck\"/><given value=\"Donald\"/></name><telecom><system value=\"phone\"/><use value=\"home\"/></telecom><telecom><system value=\"phone\"/><use value=\"work\"/></telecom><telecom><system value=\"phone\"/><use value=\"mobile\"/></telecom><telecom><system value=\"email\"/><use value=\"home\"/></telecom><gender><coding><system value=\"http://hl7.org/fhir/v3/AdministrativeGender\"/><code value=\"M\"/></coding></gender><birthDate value=\"1980-06-01T00:00:00\"/><address><use value=\"home\"/><line value=\"10 Duxon Street\"/><city value=\"VICTORIA\"/><state value=\"BC\"/><zip value=\"V8N 1Y4\"/><country value=\"Can\"/></address><managingOrganization><reference value=\"Organization/1.3.6.1.4.1.12201\"/></managingOrganization></Patient>"; IBaseResource res = ourCtx.newXmlParser().parseResource(input); String output = ourCtx.newXmlParser().encodeResourceToString(res); // Should occur exactly twice (once for the resource, once for the DIV assertThat(output, (StringContainsInOrder.stringContainsInOrder(Arrays.asList("Patient xmlns", "div xmlns")))); assertThat(output, not(StringContainsInOrder.stringContainsInOrder(Arrays.asList("b xmlns")))); output = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(res); // Should occur exactly twice (once for the resource, once for the DIV assertThat(output, (StringContainsInOrder.stringContainsInOrder(Arrays.asList("Patient xmlns", "div xmlns")))); assertThat(output, not(StringContainsInOrder.stringContainsInOrder(Arrays.asList("b xmlns")))); }
@Test public void testEncodeBundle() throws InterruptedException { Bundle b = new Bundle(); InstantType pub = InstantType.now(); b.getMeta().setLastUpdatedElement(pub); Thread.sleep(2); Patient p1 = new Patient(); p1.addName().addFamily("Family1"); BundleEntryComponent entry = b.addEntry(); entry.getIdElement().setValue("1"); entry.setResource(p1); Patient p2 = new Patient(); p2.addName().addFamily("Family2"); entry = b.addEntry(); entry.getIdElement().setValue("2"); entry.setResource(p2); BundleEntryComponent deletedEntry = b.addEntry(); Patient dp = new Patient(); deletedEntry.setResource(dp); dp.setId(("3")); InstantType nowDt = InstantType.withCurrentTime(); dp.getMeta().setDeleted(true); dp.getMeta().setLastUpdatedElement(nowDt); String bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); ourLog.info(bundleString); List<String> strings = new ArrayList<String>(); strings.addAll(Arrays.asList("\"published\":\"" + pub.getValueAsString() + "\"")); strings.addAll(Arrays.asList("\"id\":\"1\"")); 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.getEntry().remove(2); bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); assertThat(bundleString, not(containsString("deleted"))); }
@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"))); }
@Test public void testEncodeBundle() throws InterruptedException { Bundle b = new Bundle(); InstantType pub = InstantType.now(); b.getMeta().setLastUpdatedElement(pub); Thread.sleep(2); Patient p1 = new Patient(); p1.addName().addFamily("Family1"); p1.setId("1"); BundleEntryComponent entry = b.addEntry(); entry.setResource(p1); Patient p2 = new Patient(); p2.setId("Patient/2"); p2.addName().addFamily("Family2"); entry = b.addEntry(); entry.setResource(p2); BundleEntryComponent deletedEntry = b.addEntry(); Patient dp = new Patient(); deletedEntry.setResource(dp); dp.setId(("3")); InstantType nowDt = InstantType.withCurrentTime(); dp.getMeta().setLastUpdatedElement(nowDt); String bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); ourLog.info(bundleString); // List<String> strings = new ArrayList<String>(); // strings.addAll(Arrays.asList("\"published\":\"" + pub.getValueAsString() + "\"")); // strings.addAll(Arrays.asList("\"id\":\"1\"")); // strings.addAll(Arrays.asList("\"id\":\"2\"", "\"rel\":\"alternate\"", "\"href\":\"http://foo/bar\"")); // strings.addAll(Arrays.asList("\"deleted\":\"" + nowDt.getValueAsString() + "\"", "\"id\":\"Patient/3\"")); //@formatter:off String[] strings = new String[] { "\"resourceType\": \"Bundle\",", "\"lastUpdated\": \"" + pub.getValueAsString() + "\"", "\"entry\": [", "\"resource\": {", "\"id\": \"1\"", "\"resource\": {", "\"id\": \"2\"", "\"resource\": {", "\"id\": \"3\"", "\"meta\": {", "\"lastUpdated\": \"" + nowDt.getValueAsString() + "\"" }; //@formatter:off assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings)); b.getEntry().remove(2); bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); assertThat(bundleString, not(containsString("deleted"))); }
private Matcher<? super String> containsInOrder(String... strings) { return new StringContainsInOrder(asList(strings)); }