From 51dee987cbccd83eb89ce7c823c40e16de3eabd8 Mon Sep 17 00:00:00 2001 From: Alexandre P <apo@kereval.com> Date: Tue, 30 Jan 2024 17:45:37 +0100 Subject: [PATCH] Correct http code for DELETE --- .../provider/IhePatientResourceProvider.java | 2 +- .../IhePatientResourceProviderTest.java | 93 +++++++++---------- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/pixm-connector-service/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java b/pixm-connector-service/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java index 510a8d1..4fb1f5f 100644 --- a/pixm-connector-service/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java +++ b/pixm-connector-service/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java @@ -168,7 +168,7 @@ public class IhePatientResourceProvider implements IResourceProvider { EntityIdentifier deleted = patientRegistryFeedClient.delete(identifier); MethodOutcome methodOutcome = new MethodOutcome(); int responseStatusCode = deleted == null || deleted.getValue() == null || deleted.getValue().isBlank() - ? 404 + ? 204 : 200; methodOutcome.setResponseStatusCode(responseStatusCode); return methodOutcome; diff --git a/pixm-connector-service/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java b/pixm-connector-service/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java index f7f63c9..43f7bc1 100644 --- a/pixm-connector-service/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java +++ b/pixm-connector-service/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java @@ -39,7 +39,7 @@ class IhePatientResourceProviderTest { private static ConfigurationAdapter configuration; private static IhePatientResourceProvider provider; private static final HttpServletRequest iti104Request = createHttpServletRequest("src/test/resources/http_request_iti104.http"); - static final String patientString = convertReaderIntoString(iti104Request); + static final String patientString = convertReaderIntoString(iti104Request); private static final HttpServletRequest iti83GetRequest = createHttpServletRequest("src/test/resources/http_request_get_iti83.http"); @@ -157,54 +157,54 @@ class IhePatientResourceProviderTest { assertEquals("PatientIsUpdated", patientReturned.getId()); } - @Test - void testUpdatePatientWithPatientFeedException() { - //Given - Patient patient = provider.createFhirResourceFromString(Patient.class, patientString); - String theConditional = "Patient?identifier=system%7C00001"; + @Test + void testUpdatePatientWithPatientFeedException() { + //Given + Patient patient = provider.createFhirResourceFromString(Patient.class, patientString); + String theConditional = "Patient?identifier=system%7C00001"; + //When + try { + //When + provider.update(null, theConditional, patient, iti104Request); + } catch (UnprocessableEntityException e) { + //Then + assertEquals(IhePatientResourceProvider.PATIENT_FEED_CLIENT_IS_NOT_SET, e.getMessage()); + } catch (Exception e) { + fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN); + } + } + + @Test + void testUpdatePatientWithConversionException() { + //Given + Patient patient = provider.createFhirResourceFromString(Patient.class, patientString); + String theConditional = "Patient?identifier=system%7CConversionException"; + try { //When - try { - //When - provider.update(null, theConditional, patient, iti104Request); - } catch (UnprocessableEntityException e) { - //Then - assertEquals(IhePatientResourceProvider.PATIENT_FEED_CLIENT_IS_NOT_SET, e.getMessage()); - } catch (Exception e) { - fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN); - } + provider.update(null, theConditional, patient, iti104Request); + } catch (UnprocessableEntityException e) { + //Then + assertEquals(IhePatientResourceProvider.FHIR_PATIENT_COULD_NOT_BE_CONVERTED_TO_REGISTRY_PATIENT, e.getMessage()); + } catch (Exception e) { + fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN); } + } - @Test - void testUpdatePatientWithConversionException() { - //Given - Patient patient = provider.createFhirResourceFromString(Patient.class, patientString); - String theConditional = "Patient?identifier=system%7CConversionException"; - try { - //When - provider.update(null, theConditional, patient, iti104Request); - } catch (UnprocessableEntityException e) { - //Then - assertEquals(IhePatientResourceProvider.FHIR_PATIENT_COULD_NOT_BE_CONVERTED_TO_REGISTRY_PATIENT, e.getMessage()); - } catch (Exception e) { - fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN); - } - } - - @Test - void testUpdatePatientWithNullConditional() { - //Given - Patient patient = provider.createFhirResourceFromString(Patient.class, patientString); - try { - //When - provider.update(null, null, patient, iti104Request); - } catch (UnprocessableEntityException e) { - //Then - assertEquals(NO_IDENTIFIER_PROVIDED, e.getMessage()); - } catch (Exception e) { - fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN); - } - } + @Test + void testUpdatePatientWithNullConditional() { + //Given + Patient patient = provider.createFhirResourceFromString(Patient.class, patientString); + try { + //When + provider.update(null, null, patient, iti104Request); + } catch (UnprocessableEntityException e) { + //Then + assertEquals(NO_IDENTIFIER_PROVIDED, e.getMessage()); + } catch (Exception e) { + fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN); + } + } @Test void testReadOk() { @@ -306,7 +306,7 @@ class IhePatientResourceProviderTest { //When MethodOutcome mo = provider.delete(id, theConditional, iti104Request); //Then - assertEquals(404, mo.getResponseStatusCode()); + assertEquals(204, mo.getResponseStatusCode()); } @Test @@ -439,7 +439,6 @@ class IhePatientResourceProviderTest { } - //////////////////////////////////////////////////////////////// // Methods used privately in the exclusive usage of Test Class // //////////////////////////////////////////////////////////////// -- GitLab