diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java index 8f6ca7e4d..da3d81830 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java @@ -45,6 +45,8 @@ public class AllergyIntoleranceFhirResourceProviderIntegrationTest extends BaseF private static final String JSON_PATCH_ALLERGY_PATH = "org/openmrs/module/fhir2/providers/AllergyIntolerance_json_patch.json"; + private static final String XML_PATCH_ALLERGY_PATH = "org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml"; + private static final String JSON_CREATE_ALLERGY_DOCUMENT = "org/openmrs/module/fhir2/providers/AllergyIntoleranceWebTest_create.json"; private static final String XML_CREATE_ALLERGY_DOCUMENT = "org/openmrs/module/fhir2/providers/AllergyIntoleranceWebTest_create.xml"; @@ -458,6 +460,31 @@ public void shouldPatchExistingAllergyUsingJsonPatch() throws Exception { assertThat(allergyIntolerance, validResource()); } + @Test + public void shouldPatchExistingAllergyUsingXmlPatch() throws Exception { + String xmlAllergyPatch; + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_ALLERGY_PATH)) { + Objects.requireNonNull(is); + xmlAllergyPatch = inputStreamToString(is, UTF_8); + } + + MockHttpServletResponse response = patch("/AllergyIntolerance/" + ALLERGY_UUID) + .xmlPatch(xmlAllergyPatch).accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + AllergyIntolerance allergyIntolerance = readResponse(response); + + assertThat(allergyIntolerance, notNullValue()); + assertThat(allergyIntolerance.getIdElement().getIdPart(), equalTo(ALLERGY_UUID)); + + //ensure category has been patched + assertThat(allergyIntolerance.getCategory().get(0).getCode(), equalTo("food")); + assertThat(allergyIntolerance, validResource()); + } + @Test public void shouldDeleteExistingAllergyAsXML() throws Exception { MockHttpServletResponse response = delete("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go(); diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml new file mode 100644 index 000000000..f4833ba36 --- /dev/null +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml @@ -0,0 +1,14 @@ + + + + + food + +