Fix to Bulk Export Enabled Disrupts Custom Resource Addition (#5255)
* Required change to fix bug editing test case currently * Solution and unit test * Adding changelogs * adding coverage for registerCustomTypes * Fixing test cases, using same context for two tests messed it up
This commit is contained in:
parent
fb3e141c4d
commit
293f02ad7c
|
@ -1001,9 +1001,9 @@ public class FhirContext {
|
|||
*/
|
||||
public void registerCustomType(final Class<? extends IBase> theType) {
|
||||
Validate.notNull(theType, "theType must not be null");
|
||||
|
||||
ensureCustomTypeList();
|
||||
myCustomTypes.add(theType);
|
||||
myResourceNames = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1025,6 +1025,7 @@ public class FhirContext {
|
|||
ensureCustomTypeList();
|
||||
|
||||
myCustomTypes.addAll(theTypes);
|
||||
myResourceNames = null;
|
||||
}
|
||||
|
||||
private BaseRuntimeElementDefinition<?> scanDatatype(final Class<? extends IElement> theResourceType) {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 5254
|
||||
title: "Previously, when bulk export is enabled the resource list would be generated and would
|
||||
not be able to add a custom resource to that list. Now once a custom resource is added the list is
|
||||
rebuilt.
|
||||
"
|
|
@ -10,6 +10,7 @@ import ca.uhn.fhir.model.primitive.DateTimeDt;
|
|||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.parser.CustomResource364R4.CustomResource364CustomDate;
|
||||
import ca.uhn.fhir.util.ElementUtil;
|
||||
import ca.uhn.fhir.util.SearchParameterUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.DateTimeType;
|
||||
|
@ -23,10 +24,17 @@ import org.hl7.fhir.r4.model.Type;
|
|||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static ca.uhn.fhir.context.FhirVersionEnum.R4;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
@ -37,6 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
public class CustomTypeR4Test {
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forR4();
|
||||
private AnnotationConfigApplicationContext myAppCtx;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomTypeR4Test.class);
|
||||
|
||||
@BeforeEach
|
||||
|
@ -387,6 +396,28 @@ public class CustomTypeR4Test {
|
|||
assertEquals(MyMedication.class, mo.getContained().get(0).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomResource_whenResourceListIsAlreadyGenerated() {
|
||||
FhirContext newContext = new FhirContext(R4);
|
||||
Set<String> resourceSet = newContext.getResourceTypes();
|
||||
assertEquals(false,resourceSet.contains("CustomResource"));
|
||||
newContext.registerCustomType(CustomResource364R4.class);
|
||||
newContext.getElementDefinition(CustomResource364R4.class);
|
||||
resourceSet = newContext.getResourceTypes();
|
||||
assertEquals(true,resourceSet.contains("CustomResource"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCustomTypes_whenResourceListIsAlreadyGenerated(){
|
||||
FhirContext newContext = new FhirContext(R4);
|
||||
Set<String> resourceSet = newContext.getResourceTypes();
|
||||
assertEquals(false,resourceSet.contains("CustomResource"));
|
||||
newContext.registerCustomTypes(Collections.singleton(CustomResource364R4.class));
|
||||
newContext.getElementDefinition(CustomResource364R4.class);
|
||||
resourceSet = newContext.getResourceTypes();
|
||||
assertEquals(true,resourceSet.contains("CustomResource"));
|
||||
}
|
||||
|
||||
public static String createBundle(String... theResources) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("<Bundle xmlns=\"http://hl7.org/fhir\">\n");
|
||||
|
|
Loading…
Reference in New Issue