Skip to content

Commit

Permalink
FM2-594: Add support for XML patching operations - Person Resource (#497
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mherman22 authored Jul 7, 2023
1 parent 4be0eb8 commit 2d7ef66
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public class PersonFhirResourceProviderIntegrationTest extends BaseFhirR4Integra

private static final String XML_CREATE_PERSON = "org/openmrs/module/fhir2/providers/PersonWebTest_create.xml";

private static final String JSON_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_json_merge_patch.json";
private static final String JSON_MERGE_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_json_merge_patch.json";

private static final String JSON_PATCH_PERSON_FILE = "org/openmrs/module/fhir2/providers/Person_json_patch.json";
private static final String JSON_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_json_patch.json";

private static final String XML_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_xmlpatch.xml";

private static final String PERSON_UUID = "5c521595-4e12-46b0-8248-b8f2d3697766";

Expand Down Expand Up @@ -340,7 +342,7 @@ public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsXML() thro
@Test
public void shouldPatchPersonResourceUsingJsonMergePatch() throws Exception {
String jsonPersonPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_PERSON_PATH)) {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_MERGE_PATCH_PERSON_PATH)) {
Objects.requireNonNull(is);
jsonPersonPatch = inputStreamToString(is, UTF_8);
}
Expand All @@ -364,7 +366,7 @@ public void shouldPatchPersonResourceUsingJsonMergePatch() throws Exception {
@Test
public void shouldPatchPersonResourceUsingJsonPatch() throws Exception {
String jsonPersonPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_PERSON_FILE)) {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_PERSON_PATH)) {
Objects.requireNonNull(is);
jsonPersonPatch = inputStreamToString(is, UTF_8);
}
Expand All @@ -385,6 +387,30 @@ public void shouldPatchPersonResourceUsingJsonPatch() throws Exception {
assertThat(person.getGender(), equalTo(Enumerations.AdministrativeGender.FEMALE));
}

@Test
public void shouldPatchPersonResourceUsingXmlPatch() throws Exception {
String xmlPersonPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_PERSON_PATH)) {
Objects.requireNonNull(is);
xmlPersonPatch = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = patch("/Person/" + PERSON_UUID).xmlPatch(xmlPersonPatch)
.accept(FhirMediaTypes.XML).go();

assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());

Person person = readResponse(response);

assertThat(person, notNullValue());
assertThat(person.getIdElement().getIdPart(), equalTo(PERSON_UUID));
assertThat(person, validResource());

assertThat(person.getGender(), equalTo(Enumerations.AdministrativeGender.FEMALE));
}

@Test
public void shouldDeleteExistingPerson() throws Exception {
MockHttpServletResponse response = delete("/Person/" + PERSON_UUID).accept(FhirMediaTypes.JSON).go();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->
<diff xmlns:fhir="http://hl7.org/fhir">
<replace sel="/fhir:Person/fhir:gender/@value">
female
</replace>
</diff>

0 comments on commit 2d7ef66

Please sign in to comment.