Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...r-structures-dstu2/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserDstu2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ca.uhn.fhir.parser.jsonlike; | ||
|
||
import java.io.StringReader; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.AfterClass; | ||
import org.junit.Test; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.parser.IJsonLikeParser; | ||
import ca.uhn.fhir.parser.json.GsonStructure; | ||
import ca.uhn.fhir.parser.json.JsonLikeStructure; | ||
import ca.uhn.fhir.util.TestUtil; | ||
|
||
public class JsonLikeParserDstu2Test { | ||
private static FhirContext ourCtx = FhirContext.forDstu2(); | ||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonLikeParserDstu2Test.class); | ||
|
||
/** | ||
* Test for #146 | ||
*/ | ||
@Test | ||
public void testJsonLikeParseAndEncodeBundleFromXmlToJson() throws Exception { | ||
String content = IOUtils.toString(JsonLikeParserDstu2Test.class.getResourceAsStream("/bundle-example2.xml")); | ||
|
||
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, content); | ||
|
||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed); | ||
ourLog.info(encoded); | ||
|
||
JsonLikeStructure jsonLikeStructure = new GsonStructure(); | ||
jsonLikeStructure.load(new StringReader(encoded)); | ||
|
||
IJsonLikeParser jsonLikeparser = (IJsonLikeParser)ourCtx.newJsonParser(); | ||
|
||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = jsonLikeparser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, jsonLikeStructure); | ||
|
||
} | ||
|
||
@AfterClass | ||
public static void afterClassClearContext() { | ||
TestUtil.clearAllStaticFieldsForUnitTest(); | ||
} | ||
} |