Merge pull request #1792 from jamesagnew/json_should_not_preserve_invalid_value

add two additional test to check the JSON and XML parsers
This commit is contained in:
James Agnew 2020-04-09 14:37:21 -04:00 committed by GitHub
commit f0bc70f39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -58,6 +58,24 @@ public class JsonParserDstu3Test {
ourCtx.setNarrativeGenerator(null);
}
@Test
public void testEncodedResourceWithIncorrectRepresentationOfDecimalTypeToJson() {
DecimalType decimalType = new DecimalType();
decimalType.setValueAsString(".5");
MedicationRequest mr = new MedicationRequest();
Dosage dosage = new Dosage();
dosage.setDose(new SimpleQuantity()
.setValue(decimalType.getValue())
.setUnit("{tablet}")
.setSystem("http://unitsofmeasure.org")
.setCode("{tablet}"));
mr.addDosageInstruction(dosage);
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(mr);
ourLog.info(encoded);
mr = ourCtx.newJsonParser().parseResource(MedicationRequest.class, encoded);
assertEquals(BigDecimal.valueOf(0.5), mr.getDosageInstructionFirstRep().getDoseSimpleQuantity().getValue());
assertTrue(encoded.contains("0.5"));
}
/**
* See #563

View File

@ -45,6 +45,7 @@ import org.xmlunit.diff.ElementSelectors;
import java.io.IOException;
import java.io.StringReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
@ -70,6 +71,25 @@ public class XmlParserDstu3Test {
ourCtx.setNarrativeGenerator(null);
}
@Test
public void testEncodedResourceWithIncorrectRepresentationOfDecimalTypeToXml() {
DecimalType decimalType = new DecimalType();
decimalType.setValueAsString(".5");
MedicationRequest mr = new MedicationRequest();
Dosage dosage = new Dosage();
dosage.setDose(new SimpleQuantity()
.setValue(decimalType.getValue())
.setUnit("{tablet}")
.setSystem("http://unitsofmeasure.org")
.setCode("{tablet}"));
mr.addDosageInstruction(dosage);
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(mr);
ourLog.info(encoded);
mr = ourCtx.newXmlParser().parseResource(MedicationRequest.class, encoded);
assertEquals(BigDecimal.valueOf(0.5), mr.getDosageInstructionFirstRep().getDoseSimpleQuantity().getValue());
assertTrue(encoded.contains("0.5"));
}
/**
* We specifically include extensions on CapabilityStatment even in
* summary mode, since this is behaviour that people depend on