Add test for #392
This commit is contained in:
parent
a3af502ee2
commit
e26e31ae02
|
@ -0,0 +1,28 @@
|
|||
package ca.uhn.fhir.parser.i391;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.model.api.IElement;
|
||||
import ca.uhn.fhir.model.api.annotation.Block;
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Observation;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.ElementUtil;
|
||||
|
||||
@Block
|
||||
public class CustomBlock extends Observation.Component {
|
||||
|
||||
@Child(name = "value", min = 0, max = 1, order = Child.REPLACE_PARENT, summary = true, type = {StringDt.class})
|
||||
public StringDt ourValue;
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return super.isBaseEmpty() && ElementUtil.isEmpty(ourValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
|
||||
return ElementUtil.allPopulatedChildElements(theType, ourValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package ca.uhn.fhir.parser.i391;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
|
||||
|
||||
@ResourceDef(name = "OperationOutcome", profile = "http://hl7.org/fhir/profiles/custom-operation-outcome", id = "custom-operation-outcome")
|
||||
public class CustomOperationOutcome extends OperationOutcome {
|
||||
|
||||
@Child(name = "someElement2", type = CustomBlock.class)
|
||||
@Extension(definedLocally = false, isModifier = false, url = "#someElement2")
|
||||
public CustomBlock element2;
|
||||
|
||||
}
|
|
@ -2,17 +2,40 @@ package ca.uhn.fhir.parser.i391;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.primitive.BoundCodeDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.parser.CustomTypeDstu2Test;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* See #391
|
||||
*/
|
||||
public class TestOutcomeTest {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomTypeDstu2Test.class);
|
||||
|
||||
@Test
|
||||
public void testCustomDataTypeBugN2_UnknownElement() {
|
||||
CustomBlock nameDt = new CustomBlock();
|
||||
nameDt.ourValue = new StringDt("testText");
|
||||
|
||||
CustomOperationOutcome outcome = new CustomOperationOutcome();
|
||||
outcome.element2 = nameDt;
|
||||
|
||||
IParser parser = FhirContext.forDstu2().newXmlParser();
|
||||
String outcomeString = parser.setPrettyPrint(true).encodeResourceToString(outcome);
|
||||
CustomOperationOutcome parsedOutcome = parser.parseResource(CustomOperationOutcome.class, outcomeString);
|
||||
ourLog.info(outcomeString);
|
||||
|
||||
// assertNotNull(parsedOutcome.element2);
|
||||
// assertNotNull(parsedOutcome.element2.ourValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBoundCodeDtJson() {
|
||||
IParser jsonParser = FhirContext.forDstu2().newJsonParser();
|
||||
|
@ -42,4 +65,10 @@ public class TestOutcomeTest {
|
|||
assertTrue(operationOutcome.getElement() instanceof BoundCodeDt);
|
||||
assertEquals(outcome.getElement(), operationOutcome.getElement());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue