Test cleanup
This commit is contained in:
parent
a4cbde8269
commit
059265a041
|
@ -1,5 +1,25 @@
|
||||||
package ca.uhn.fhir.util;
|
package ca.uhn.fhir.util;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* HAPI FHIR - Core Library
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2014 - 2017 University Health Network
|
||||||
|
* %%
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
||||||
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ca.uhn.fhir.parser;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.hl7.fhir.r4.model.Bundle;
|
import org.hl7.fhir.r4.model.Bundle;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
@ -20,6 +21,19 @@ public class XmlParserR4Test {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(XmlParserR4Test.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(XmlParserR4Test.class);
|
||||||
private static FhirContext ourCtx = FhirContext.forR4();
|
private static FhirContext ourCtx = FhirContext.forR4();
|
||||||
|
|
||||||
|
private Bundle createBundleWithPatient() {
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.setId("BUNDLEID");
|
||||||
|
b.getMeta().addProfile("http://FOO");
|
||||||
|
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.setId("PATIENTID");
|
||||||
|
p.getMeta().addProfile("http://BAR");
|
||||||
|
p.addName().addGiven("GIVEN");
|
||||||
|
b.addEntry().setResource(p);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExcludeNothing() {
|
public void testExcludeNothing() {
|
||||||
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||||
|
@ -45,6 +59,32 @@ public class XmlParserR4Test {
|
||||||
assertEquals("GIVEN", ((Patient) b.getEntry().get(0).getResource()).getNameFirstRep().getGivenAsSingleString());
|
assertEquals("GIVEN", ((Patient) b.getEntry().get(0).getResource()).getNameFirstRep().getGivenAsSingleString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExcludeRootStuff() {
|
||||||
|
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||||
|
Set<String> excludes = new HashSet<>();
|
||||||
|
excludes.add("id");
|
||||||
|
excludes.add("meta");
|
||||||
|
parser.setDontEncodeElements(excludes);
|
||||||
|
|
||||||
|
Bundle b = createBundleWithPatient();
|
||||||
|
|
||||||
|
String encoded = parser.encodeResourceToString(b);
|
||||||
|
ourLog.info(encoded);
|
||||||
|
|
||||||
|
assertThat(encoded, not(containsString("BUNDLEID")));
|
||||||
|
assertThat(encoded, not(containsString("http://FOO")));
|
||||||
|
assertThat(encoded, (containsString("PATIENTID")));
|
||||||
|
assertThat(encoded, (containsString("http://BAR")));
|
||||||
|
assertThat(encoded, containsString("GIVEN"));
|
||||||
|
|
||||||
|
b = parser.parseResource(Bundle.class, encoded);
|
||||||
|
|
||||||
|
assertNotEquals("BUNDLEID", b.getIdElement().getIdPart());
|
||||||
|
assertEquals("Patient/PATIENTID", ((Patient) b.getEntry().get(0).getResource()).getId());
|
||||||
|
assertEquals("GIVEN", ((Patient) b.getEntry().get(0).getResource()).getNameFirstRep().getGivenAsSingleString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExcludeStarDotStuff() {
|
public void testExcludeStarDotStuff() {
|
||||||
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||||
|
@ -71,45 +111,6 @@ public class XmlParserR4Test {
|
||||||
assertEquals("GIVEN", ((Patient) b.getEntry().get(0).getResource()).getNameFirstRep().getGivenAsSingleString());
|
assertEquals("GIVEN", ((Patient) b.getEntry().get(0).getResource()).getNameFirstRep().getGivenAsSingleString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testExcludeRootStuff() {
|
|
||||||
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
||||||
Set<String> excludes = new HashSet<>();
|
|
||||||
excludes.add("id");
|
|
||||||
excludes.add("meta");
|
|
||||||
parser.setDontEncodeElements(excludes);
|
|
||||||
|
|
||||||
Bundle b = createBundleWithPatient();
|
|
||||||
|
|
||||||
String encoded = parser.encodeResourceToString(b);
|
|
||||||
ourLog.info(encoded);
|
|
||||||
|
|
||||||
assertThat(encoded, not(containsString("BUNDLEID")));
|
|
||||||
assertThat(encoded, not(containsString("http://FOO")));
|
|
||||||
assertThat(encoded, (containsString("PATIENTID")));
|
|
||||||
assertThat(encoded, (containsString("http://BAR")));
|
|
||||||
assertThat(encoded, containsString("GIVEN"));
|
|
||||||
|
|
||||||
b = parser.parseResource(Bundle.class, encoded);
|
|
||||||
|
|
||||||
assertNotEquals("BUNDLEID", b.getIdElement().getIdPart());
|
|
||||||
assertEquals("Patient/PATIENTID", ((Patient) b.getEntry().get(0).getResource()).getId());
|
|
||||||
assertEquals("GIVEN", ((Patient) b.getEntry().get(0).getResource()).getNameFirstRep().getGivenAsSingleString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Bundle createBundleWithPatient() {
|
|
||||||
Bundle b = new Bundle();
|
|
||||||
b.setId("BUNDLEID");
|
|
||||||
b.getMeta().addProfile("http://FOO");
|
|
||||||
|
|
||||||
Patient p = new Patient();
|
|
||||||
p.setId("PATIENTID");
|
|
||||||
p.getMeta().addProfile("http://BAR");
|
|
||||||
p.addName().addGiven("GIVEN");
|
|
||||||
b.addEntry().setResource(p);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseAndEncodeExtensionWithValueWithExtension() {
|
public void testParseAndEncodeExtensionWithValueWithExtension() {
|
||||||
String input = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
|
String input = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
|
||||||
|
@ -131,11 +132,16 @@ public class XmlParserR4Test {
|
||||||
" <gender value=\"female\"/>\n" +
|
" <gender value=\"female\"/>\n" +
|
||||||
"</Patient>";
|
"</Patient>";
|
||||||
|
|
||||||
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, input);
|
IParser xmlParser = ourCtx.newXmlParser();
|
||||||
|
IParser jsonParser = ourCtx.newJsonParser();
|
||||||
|
jsonParser.setDontEncodeElements(Sets.newHashSet("id", "meta"));
|
||||||
|
xmlParser.setDontEncodeElements(Sets.newHashSet("id", "meta"));
|
||||||
|
|
||||||
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed));
|
Patient parsed = xmlParser.parseResource(Patient.class, input);
|
||||||
assertThat(ourCtx.newXmlParser().encodeResourceToString(parsed), containsString("Underweight"));
|
|
||||||
assertThat(ourCtx.newJsonParser().encodeResourceToString(parsed), containsString("Underweight"));
|
ourLog.info(jsonParser.setPrettyPrint(true).encodeResourceToString(parsed));
|
||||||
|
assertThat(xmlParser.encodeResourceToString(parsed), containsString("Underweight"));
|
||||||
|
assertThat(jsonParser.encodeResourceToString(parsed), containsString("Underweight"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue