Add test
This commit is contained in:
parent
e27ceead55
commit
e6cb973f5f
|
@ -46,6 +46,7 @@ import org.hl7.fhir.dstu3.model.CapabilityStatement.UnknownContentCode;
|
|||
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
|
||||
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
|
||||
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||
import org.junit.After;
|
||||
|
@ -56,8 +57,10 @@ import org.junit.Test;
|
|||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||
import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation;
|
||||
|
@ -99,7 +102,6 @@ public class JsonParserDstu3Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #563
|
||||
*/
|
||||
|
@ -170,7 +172,7 @@ public class JsonParserDstu3Test {
|
|||
newPatient = jsonParser.parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient));
|
||||
assertEquals("myName", newPatient.getPetName().getValue());
|
||||
|
||||
//Check no NPE if base server not configure
|
||||
// Check no NPE if base server not configure
|
||||
newPatient = ourCtx.newJsonParser().parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient));
|
||||
assertNull("myName", newPatient.getPetName().getValue());
|
||||
assertEquals("myName", ((StringType) newPatient.getExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
|
||||
|
@ -237,7 +239,6 @@ public class JsonParserDstu3Test {
|
|||
assertEquals(3, countMatches(encoded, "resourceType"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseExtensions() throws Exception {
|
||||
|
||||
|
@ -402,7 +403,6 @@ public class JsonParserDstu3Test {
|
|||
assertEquals("sec_label2", tagList.get(1).getDisplay());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #336
|
||||
*/
|
||||
|
@ -1305,6 +1305,22 @@ public class JsonParserDstu3Test {
|
|||
assertEquals("{\"resourceType\":\"Observation\",\"valueQuantity\":{\"value\":0.0000000000000001}}", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* See #658
|
||||
*/
|
||||
@Test
|
||||
public void testExtraElement() throws Exception {
|
||||
IParser p = ourCtx.newJsonParser();
|
||||
p.setParserErrorHandler(new StrictErrorHandler());
|
||||
try {
|
||||
p.parseResource(IOUtils.toString(JsonParserDstu3Test.class.getResourceAsStream("/Patient.json.txt"), Charsets.UTF_8));
|
||||
fail();
|
||||
} catch (DataFormatException e) {
|
||||
assertEquals("Found incorrect type for element assigner - Expected OBJECT and found SCALAR (STRING)", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncorrectJsonTypesIdAndArray() {
|
||||
|
||||
|
@ -2298,10 +2314,14 @@ public class JsonParserDstu3Test {
|
|||
ArgumentCaptor<ValueType> actual = ArgumentCaptor.forClass(ValueType.class);
|
||||
ArgumentCaptor<ScalarType> expectedScalar = ArgumentCaptor.forClass(ScalarType.class);
|
||||
ArgumentCaptor<ScalarType> actualScalar = ArgumentCaptor.forClass(ScalarType.class);
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), elementName.capture(), expected.capture(), expectedScalar.capture(), actual.capture(), actualScalar.capture());
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), Mockito.eq("_id"), Mockito.eq(ValueType.OBJECT), expectedScalar.capture(), Mockito.eq(ValueType.SCALAR), actualScalar.capture());
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), Mockito.eq("__v"), Mockito.eq(ValueType.OBJECT), expectedScalar.capture(), Mockito.eq(ValueType.SCALAR), actualScalar.capture());
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), Mockito.eq("_status"), Mockito.eq(ValueType.OBJECT), expectedScalar.capture(), Mockito.eq(ValueType.SCALAR), actualScalar.capture());
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), elementName.capture(), expected.capture(), expectedScalar.capture(), actual.capture(),
|
||||
actualScalar.capture());
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), Mockito.eq("_id"), Mockito.eq(ValueType.OBJECT), expectedScalar.capture(), Mockito.eq(ValueType.SCALAR),
|
||||
actualScalar.capture());
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), Mockito.eq("__v"), Mockito.eq(ValueType.OBJECT), expectedScalar.capture(), Mockito.eq(ValueType.SCALAR),
|
||||
actualScalar.capture());
|
||||
verify(errorHandler, atLeastOnce()).incorrectJsonType(Mockito.any(IParseLocation.class), Mockito.eq("_status"), Mockito.eq(ValueType.OBJECT), expectedScalar.capture(),
|
||||
Mockito.eq(ValueType.SCALAR), actualScalar.capture());
|
||||
|
||||
assertEquals("_id", elementName.getAllValues().get(0));
|
||||
assertEquals(ValueType.OBJECT, expected.getAllValues().get(0));
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
{
|
||||
"resourceType": "Patient",
|
||||
"id": "patient1",
|
||||
"contained": [{
|
||||
"resourceType": "Practitioner",
|
||||
"id": "p1",
|
||||
"identifier": [{
|
||||
"system": "urn:oid:2.16.840.1.113883.3.566",
|
||||
"value": "145148",
|
||||
"assigner": "UHC"
|
||||
}],
|
||||
"name": [{
|
||||
"text": " Richard J Y Ha MD",
|
||||
"given": ["Richard",
|
||||
"J Y"],
|
||||
"family": "Ha",
|
||||
"suffix": ["MD"]
|
||||
}]
|
||||
}],
|
||||
"identifier": [{
|
||||
"use": "official",
|
||||
"type": {
|
||||
"coding": [{
|
||||
"system": "http://hl7.org/fhir/identifier-type",
|
||||
"code": "MR",
|
||||
"display": "Medical Record Number",
|
||||
"userSelected": true
|
||||
}]
|
||||
},
|
||||
"system": "urn:oid:2.16.840.1.113883.3.566",
|
||||
"value": "220457511",
|
||||
"assigner": "MU"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"coding": [{
|
||||
"system": "http://hl7.org/fhir/identifier-type",
|
||||
"code": "MR",
|
||||
"display": "UHC ID",
|
||||
"userSelected": true
|
||||
}]
|
||||
},
|
||||
"system": "urn:oid:2.16.840.1.113883.3.566",
|
||||
"value": "15246931",
|
||||
"assigner": "UHC"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"coding": [{
|
||||
"system": "http://hl7.org/fhir/identifier-type",
|
||||
"code": "MR",
|
||||
"display": "ACCT NUM",
|
||||
"userSelected": true
|
||||
}]
|
||||
},
|
||||
"system": "urn:oid:2.16.840.1.113883.3.566",
|
||||
"value": "226274321",
|
||||
"assigner": "MU"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"coding": [{
|
||||
"system": "http://hl7.org/fhir/identifier-type",
|
||||
"code": "MR",
|
||||
"display": "HNAMPERSON_ID",
|
||||
"userSelected": true
|
||||
}]
|
||||
},
|
||||
"system": "urn:oid:2.16.840.1.113883.3.566",
|
||||
"value": "25296343"
|
||||
}],
|
||||
"active": true,
|
||||
"name": [{
|
||||
"use": "official",
|
||||
"text": " MOM TWO CERNER",
|
||||
"given": ["MOM",
|
||||
"TWO"],
|
||||
"family": "CERNER"
|
||||
}],
|
||||
"gender": "female",
|
||||
"birthDate": "1990-10-18",
|
||||
"address": [{
|
||||
"use": "home",
|
||||
"text": "2401 LEMONE INDUSTRIAL BLVD, COLUMBIA, MO 65201 ",
|
||||
"line": "2401 LEMONE INDUSTRIAL BLVD",
|
||||
"city": "COLUMBIA",
|
||||
"state": "MO",
|
||||
"postalCode": "65201"
|
||||
}],
|
||||
"maritalStatus": {
|
||||
"coding": [{
|
||||
"system": "urn:oid:2.16.840.1.113883.3.566",
|
||||
"code": "M",
|
||||
"display": "Married",
|
||||
"userSelected": true
|
||||
}]
|
||||
},
|
||||
"contact": [{
|
||||
"name": {
|
||||
"text": "BABY TWO CERNER",
|
||||
"given": ["BABY",
|
||||
"TWO"],
|
||||
"family": "CERNER"
|
||||
},
|
||||
"address": {
|
||||
"text": "2401 LEMONE INDUSTRIAL BLVD, COLUMBIA MO 65201 ",
|
||||
"line": "2401 LEMONE INDUSTRIAL BLVD",
|
||||
"city": "COLUMBIA",
|
||||
"state": "MO",
|
||||
"postalCode": "65201"
|
||||
}
|
||||
}],
|
||||
"communication": [{
|
||||
"language": {
|
||||
"coding": [{
|
||||
"system": "urn:oid:2.16.840.1.113883.3.566",
|
||||
"code": "ENG",
|
||||
"userSelected": true
|
||||
}]
|
||||
}
|
||||
}],
|
||||
"generalPractitioner": [{
|
||||
"reference": "#p1"
|
||||
}],
|
||||
"managingOrganization": {
|
||||
"display": "Organization/UHC"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue