From 84803a02ef1f2e72a98a7a576c9932cbe614b29e Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 29 Oct 2019 15:54:49 -0400 Subject: [PATCH] Preserve line numbers in XML validation (#1567) * Preserve line numbers in XML validation * Test fixes --- .../jpa/provider/dstu3/ResourceProviderDstu3Test.java | 10 ++-------- .../fhir/jpa/provider/r4/ResourceProviderR4Test.java | 4 +--- .../fhir/common/hapi/validation/ValidatorWrapper.java | 6 +++++- .../r4/validation/FhirInstanceValidatorR4Test.java | 2 ++ src/site/xdoc/download.xml.vm | 10 ++++++++++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 0439df50d23..69a03290a8a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -4080,22 +4080,16 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Patient patient = new Patient(); patient.addName().addGiven("James"); patient.setBirthDateElement(new DateType("2011-02-02")); - patient.addContact().setGender(AdministrativeGender.MALE); String inputStr = myFhirCtx.newXmlParser().encodeResourceToString(patient); HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); post.setEntity(new StringEntity(inputStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - CloseableHttpResponse response = ourHttpClient.execute(post); - try { + try (CloseableHttpResponse response = ourHttpClient.execute(post)) { String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); ourLog.info(resp); - assertEquals(412, response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); assertThat(resp, not(containsString("Resource has no id"))); - assertThat(resp, containsString("")); - } finally { - IOUtils.closeQuietly(response.getEntity().getContent()); - response.close(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index d4ce979de70..ca67457117f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -5308,7 +5308,6 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient patient = new Patient(); patient.addName().addGiven("James"); patient.setBirthDateElement(new DateType("2011-02-02")); - patient.addContact().setGender(AdministrativeGender.MALE); String inputStr = myFhirCtx.newXmlParser().encodeResourceToString(patient); HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); @@ -5317,9 +5316,8 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { try (CloseableHttpResponse response = ourHttpClient.execute(post)) { String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); ourLog.info(resp); - assertEquals(412, response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); assertThat(resp, not(containsString("Resource has no id"))); - assertThat(resp, containsString("")); } } diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java index 27ddb19b07f..61f1358ec1b 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java @@ -111,7 +111,11 @@ public class ValidatorWrapper { profileSet.getCanonical().add(new ValidationProfileSet.ProfileRegistration(nextProfile, true)); } - v.validate(null, messages, document, profileSet); + String resourceAsString = theValidationContext.getResourceAsString(); + InputStream inputStream = new ReaderInputStream(new StringReader(resourceAsString), Charsets.UTF_8); + + Manager.FhirFormat format = Manager.FhirFormat.XML; + v.validate(null, messages, inputStream, format, profileSet); } else if (encoding == EncodingEnum.JSON) { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java index 881f0e95d7d..a9f9cbdda01 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java @@ -799,6 +799,8 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("/f:Patient", output.getMessages().get(0).getLocationString()); assertEquals("Undefined element 'foo'", output.getMessages().get(0).getMessage()); + assertEquals(28, output.getMessages().get(0).getLocationCol().intValue()); + assertEquals(4, output.getMessages().get(0).getLocationLine().intValue()); } @Test diff --git a/src/site/xdoc/download.xml.vm b/src/site/xdoc/download.xml.vm index 804b0f79aad..ac699047c8f 100644 --- a/src/site/xdoc/download.xml.vm +++ b/src/site/xdoc/download.xml.vm @@ -262,6 +262,16 @@ 4.0.0 4.1.0-e0e3caf9ba + + HAPI FHIR 4.1.0 + JDK8 + + 1.0.2 + 1.4.0 + 3.0.1 + 4.0.0 + 4.1.0-1a7623d866 +