Add elastic test (#2348)

* Add elastic test

* Rework

* Add test
This commit is contained in:
James Agnew 2021-02-04 11:04:27 -05:00 committed by GitHub
parent ba41daf4bf
commit 92669b29da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Observation;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -93,6 +94,11 @@ public class LastNElasticsearchSvcMultipleObservationsIT {
} }
} }
@AfterEach
public void after() throws IOException {
elasticsearchSvc.close();
}
@Test @Test
public void testLastNAllPatientsQuery() { public void testLastNAllPatientsQuery() {

View File

@ -1,7 +1,9 @@
package ca.uhn.fhir.parser; package ca.uhn.fhir.parser;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
@ -20,6 +22,7 @@ import org.hl7.fhir.r4.model.Composition;
import org.hl7.fhir.r4.model.DateTimeType; import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.Device; import org.hl7.fhir.r4.model.Device;
import org.hl7.fhir.r4.model.DocumentReference; import org.hl7.fhir.r4.model.DocumentReference;
import org.hl7.fhir.r4.model.Dosage;
import org.hl7.fhir.r4.model.Encounter; import org.hl7.fhir.r4.model.Encounter;
import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Medication; import org.hl7.fhir.r4.model.Medication;
@ -30,10 +33,12 @@ import org.hl7.fhir.r4.model.Narrative;
import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.PrimitiveType;
import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.QuestionnaireResponse; import org.hl7.fhir.r4.model.QuestionnaireResponse;
import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.Type;
import org.hl7.fhir.r4.model.UuidType; import org.hl7.fhir.r4.model.UuidType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
@ -80,6 +85,20 @@ public class JsonParserR4Test extends BaseTest {
ourLog.info(narrative); ourLog.info(narrative);
} }
@Test
public void testEncodeExtensionWithUnknownType() throws IOException {
Patient p = new Patient();
p.addExtension("http://foo", new MyUnknownPrimitiveType());
try {
ourCtx.newJsonParser().encodeResourceToString(p);
fail();
} catch (ConfigurationException e) {
assertEquals("Unable to encode extension, unrecognized child element type: ca.uhn.fhir.parser.JsonParserR4Test.MyUnknownPrimitiveType", e.getMessage());
}
}
@Test @Test
public void testNamespacePrefixTrimmedFromNarrative() { public void testNamespacePrefixTrimmedFromNarrative() {
String input = "<Patient xmlns=\"http://hl7.org/fhir\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">" + String input = "<Patient xmlns=\"http://hl7.org/fhir\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">" +
@ -910,6 +929,42 @@ public class JsonParserR4Test extends BaseTest {
} }
@DatatypeDef(
name = "UnknownPrimitiveType"
)
private static class MyUnknownPrimitiveType extends PrimitiveType<Object> {
@Override
public Object getValue() {
return "AAA";
}
@Override
public String getValueAsString() {
return "AAA";
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public Type copy() {
return this;
}
@Override
protected String encode(Object theO) {
return "AAA";
}
@Override
protected Object parse(String theS) {
return new Object();
}
}
@AfterAll @AfterAll
public static void afterClassClearContext() { public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest(); TestUtil.clearAllStaticFieldsForUnitTest();