diff --git a/src/test/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverterTest.java b/src/test/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverterTest.java index c0500d518e1b197d3e54a346b09cf47bd31f2d4d..04d57165d7b4738e6a5b5328b28b5855d1cc5de9 100644 --- a/src/test/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverterTest.java +++ b/src/test/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverterTest.java @@ -1,5 +1,6 @@ package net.ihe.gazelle.adapter.connector; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import io.qameta.allure.*; import net.ihe.gazelle.app.patientregistryapi.business.*; import net.ihe.gazelle.app.patientregistryapi.business.Person; @@ -20,7 +21,7 @@ public class BundleToPatientRegistryConverterTest { @Description("Test on unitary conversion") @Severity(SeverityLevel.CRITICAL) @Story("Name conversion") - void TestPatientNameConverion(){ + void TestPatientNameConversion(){ Patient pat = new Patient(); HumanName name = new HumanName(); name.addGiven("Patrick"); @@ -48,7 +49,7 @@ public class BundleToPatientRegistryConverterTest { @Description("Test on unitary conversion") @Severity(SeverityLevel.CRITICAL) @Story("Gender conversion") - void TestPatientGenderConverion(){ + void TestPatientGenderConversion(){ Patient pat1 = new Patient(); pat1.setGender(Enumerations.AdministrativeGender.FEMALE); @@ -85,7 +86,7 @@ public class BundleToPatientRegistryConverterTest { @Description("Test on unitary conversion") @Severity(SeverityLevel.CRITICAL) @Story("Contact conversion") - void TestPatientContactConverion(){ + void TestPatientContactConversion(){ Patient pat = new Patient(); Patient.ContactComponent comp = new Patient.ContactComponent(); @@ -113,7 +114,7 @@ public class BundleToPatientRegistryConverterTest { @Description("Test on unitary conversion") @Severity(SeverityLevel.CRITICAL) @Story("Address conversion") - void TestPatientAddressConverion(){ + void TestPatientAddressConversion(){ Patient pat = new Patient(); Address address = new Address(); @@ -178,7 +179,7 @@ public class BundleToPatientRegistryConverterTest { @Description("Test on unitary conversion") @Severity(SeverityLevel.CRITICAL) @Story("Single parameters conversion") - void TestPatientParametersConverion(){ + void TestPatientParametersConversion(){ LocalDate dateValue = LocalDate.now(); @@ -199,4 +200,36 @@ public class BundleToPatientRegistryConverterTest { } + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Single parameters conversion") + void TestPatientIdentifiersConversion(){ + + Patient pat = new Patient(); + Identifier id = new Identifier(); + id.setSystem("urn:oid:Hello_Vincent"); + id.setValue("69420"); + pat.addIdentifier(id); + + Patient pat1 = new Patient(); + Identifier id1 = new Identifier(); + pat.addIdentifier(id1); + + + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat); + assertEquals("Hello_Vincent", response.getIdentifiers().get(0).getSystemIdentifier()); + assertEquals("69420", response.getIdentifiers().get(0).getValue()); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat1); + + } catch (InvalidRequestException e) { + assertEquals("Cannot create Patient without any Identifier", e.getMessage()); + } catch (ConversionException e) { + fail(); + } + + } + } diff --git a/src/test/java/net/ihe/gazelle/adapter/connector/BusinessToFhirConverterTest.java b/src/test/java/net/ihe/gazelle/adapter/connector/BusinessToFhirConverterTest.java index 6a24c13c1c027be3e8559aa6d6670bb80a3dbe6b..3261b7b0996ff414e7ea56b52ab9f4f61f00af1b 100644 --- a/src/test/java/net/ihe/gazelle/adapter/connector/BusinessToFhirConverterTest.java +++ b/src/test/java/net/ihe/gazelle/adapter/connector/BusinessToFhirConverterTest.java @@ -176,31 +176,6 @@ public class BusinessToFhirConverterTest { cp6.setUse(ContactPointUse.PRIMARY_HOME); pat6.addContactPoint(cp6); - /*case HOME: - case PRIMARY_HOME: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.HOME; - case MOBILE: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.MOBILE; - case WORK: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.WORK; - case TEMPORARY: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.TEMP; - - case BEEPER: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.PAGER; - case PHONE: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.PHONE; - case FAX: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.FAX; - case URL: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.URL; - case EMAIL: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.EMAIL; - case SMS: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.SMS; - case OTHER: - return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.OTHER;*/ - try { Patient response = BusinessToFhirConverter.patientToFhirPatient(pat); assertEquals("Hello", response.getTelecom().get(0).getValue()); @@ -237,4 +212,28 @@ public class BusinessToFhirConverterTest { } + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("CrossReference conversion") + void TestPatientCrossReferenceConversion(){ + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + + EntityIdentifier id = new EntityIdentifier(); + id.setSystemIdentifier("Hello_Vincent"); + id.setValue("69420"); + pat.addIdentifier(id); + + try { + Patient response = BusinessToFhirConverter.patientToFhirPatient(pat); + assertEquals("urn:oid:Hello_Vincent", response.getIdentifier().get(0).getSystem()); + assertEquals("69420", response.getIdentifier().get(0).getValue()); + + } catch (ConversionException e) { + fail("could not convert Patient with just a gender"); + } + + } + } diff --git a/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java b/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java index 7c1e010ad3809aa8b0e6fde3a7fc4fe853104d58..5ffedcf4f3b6a67e57224bfdf300406fd2f1ea7d 100644 --- a/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java +++ b/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java @@ -359,6 +359,44 @@ public class PatientFeedClientTest { } } + @Test + @Description("Test on create, for particular exceptions returned from PatientFeedApplication") + @Severity(SeverityLevel.CRITICAL) + @Story("create") + void TestFeedBlankNameOnCreation() throws PreferenceException, NamespaceException, PatientFeedException { + + Patient patient = createPatient("","name",LocalDate.of(1990, 06, 19), GenderCode.MALE); + + patientRegistryFeedClient = new PatientRegistryFeedClient(); + patientRegistryFeedClient.setClient(patientFeedClientMock); + + assertThrows(InvalidRequestException.class, () -> patientRegistryFeedClient.createPatient(patient)); + try { + patientRegistryFeedClient.createPatient(patient); + } catch (InvalidRequestException e) { + assertEquals("Mandatory fields are missing", e.getMessage()); + } + } + + @Test + @Description("Test on create, for particular exceptions returned from PatientFeedApplication") + @Severity(SeverityLevel.CRITICAL) + @Story("create") + void TestFeedBlankGenderOnCreation() throws PreferenceException, NamespaceException, PatientFeedException { + + Patient patient = createPatient("name","name",LocalDate.of(1990, 06, 19), null); + + patientRegistryFeedClient = new PatientRegistryFeedClient(); + patientRegistryFeedClient.setClient(patientFeedClientMock); + + assertThrows(InvalidRequestException.class, () -> patientRegistryFeedClient.createPatient(patient)); + try { + patientRegistryFeedClient.createPatient(patient); + } catch (InvalidRequestException e) { + assertEquals("Mandatory fields are missing", e.getMessage()); + } + } + @Test @Description("Test on update, when feeding basic request") @@ -392,6 +430,131 @@ public class PatientFeedClientTest { } + @Test + @Description("Test on update, exception thrown from PatReg") + @Severity(SeverityLevel.CRITICAL) + @Story("update") + void TestFeedUpdatePatientFeedThrown() throws PreferenceException, NamespaceException, PatientFeedException { + + String uuid = TEST_UUID; + Patient patient = createPatient("","",LocalDate.of(1990, 06, 19), GenderCode.MALE); + + PatientFeedException embedException = new PatientFeedException("Invalid Request sent to distant PatientFeedProcessingService !"); + + patientRegistryFeedClient = new PatientRegistryFeedClient(); + patientRegistryFeedClient.setClient(patientFeedClientMock); + + Mockito.doThrow(embedException).when(patientFeedClientMock).updatePatient(anyObject()); + + assertThrows(InvalidRequestException.class, () -> patientRegistryFeedClient.updatePatient(patient, uuid)); + try { + patientRegistryFeedClient.updatePatient(patient, uuid); + } + catch (InvalidRequestException e) { + assertEquals("Invalid Request sent to distant PatientFeedProcessingService !", e.getMessage()); + } + } + + @Test + @Description("Test on update, exception thrown from PatReg") + @Severity(SeverityLevel.CRITICAL) + @Story("update") + void TestFeedUpdatePatientFeedResourceThrown() throws PreferenceException, NamespaceException, PatientFeedException { + + String uuid = TEST_UUID; + Patient patient = createPatient("","",LocalDate.of(1990, 06, 19), GenderCode.MALE); + + PatientFeedException embedException = new PatientFeedException("Invalid operation used on distant PatientFeedProcessingService !"); + + patientRegistryFeedClient = new PatientRegistryFeedClient(); + patientRegistryFeedClient.setClient(patientFeedClientMock); + + Mockito.doThrow(embedException).when(patientFeedClientMock).updatePatient(anyObject()); + + assertThrows(ResourceNotFoundException.class, () -> patientRegistryFeedClient.updatePatient(patient, uuid)); + try { + patientRegistryFeedClient.updatePatient(patient, uuid); + } + catch (ResourceNotFoundException e) { + assertEquals("Invalid operation used on distant PatientFeedProcessingService !", e.getMessage()); + } + } + + @Test + @Description("Test on update, exception thrown from PatReg") + @Severity(SeverityLevel.CRITICAL) + @Story("update") + void TestFeedUpdatePatientFeedInvalidThrown() throws PreferenceException, NamespaceException, PatientFeedException { + + String uuid = TEST_UUID; + Patient patient = createPatient("","",LocalDate.of(1990, 06, 19), GenderCode.MALE); + + PatientFeedException embedException = new PatientFeedException("Invalid Response from distant PatientFeedProcessingService !"); + + patientRegistryFeedClient = new PatientRegistryFeedClient(); + patientRegistryFeedClient.setClient(patientFeedClientMock); + + Mockito.doThrow(embedException).when(patientFeedClientMock).updatePatient(anyObject()); + + assertThrows(InternalErrorException.class, () -> patientRegistryFeedClient.updatePatient(patient, uuid)); + try { + patientRegistryFeedClient.updatePatient(patient, uuid); + } + catch (InternalErrorException e) { + assertEquals("Invalid Response from distant PatientFeedProcessingService !", e.getMessage()); + } + } + + @Test + @Description("Test on update, exception thrown from PatReg") + @Severity(SeverityLevel.CRITICAL) + @Story("update") + void TestFeedUpdatePatientFeedGitbThrown() throws PreferenceException, NamespaceException, PatientFeedException { + + String uuid = TEST_UUID; + Patient patient = createPatient("","",LocalDate.of(1990, 06, 19), GenderCode.MALE); + + PatientFeedException embedException = new PatientFeedException("Exception while Mapping with GITB elements !"); + + patientRegistryFeedClient = new PatientRegistryFeedClient(); + patientRegistryFeedClient.setClient(patientFeedClientMock); + + Mockito.doThrow(embedException).when(patientFeedClientMock).updatePatient(anyObject()); + + assertThrows(InternalErrorException.class, () -> patientRegistryFeedClient.updatePatient(patient, uuid)); + try { + patientRegistryFeedClient.updatePatient(patient, uuid); + } + catch (InternalErrorException e) { + assertEquals("Exception while Mapping with GITB elements !", e.getMessage()); + } + } + + @Test + @Description("Test on update, exception thrown from PatReg") + @Severity(SeverityLevel.CRITICAL) + @Story("update") + void TestFeedUpdatePatientFeedUnhandled() throws PreferenceException, NamespaceException, PatientFeedException { + + String uuid = TEST_UUID; + Patient patient = createPatient("","",LocalDate.of(1990, 06, 19), GenderCode.MALE); + + PatientFeedException embedException = new PatientFeedException("This is supposed to be an unhandled error occuring"); + + patientRegistryFeedClient = new PatientRegistryFeedClient(); + patientRegistryFeedClient.setClient(patientFeedClientMock); + + Mockito.doThrow(embedException).when(patientFeedClientMock).updatePatient(anyObject()); + + assertThrows(InternalErrorException.class, () -> patientRegistryFeedClient.updatePatient(patient, uuid)); + try { + patientRegistryFeedClient.updatePatient(patient, uuid); + } + catch (InternalErrorException e) { + assertEquals("An unhandled error occured", e.getMessage()); + } + } + @Test @Description("Test on update, exception thrown when no Uuid is given") @Severity(SeverityLevel.CRITICAL) diff --git a/src/test/java/net/ihe/gazelle/application/PatientRegistrySearchClientTest.java b/src/test/java/net/ihe/gazelle/application/PatientRegistrySearchClientTest.java index 2bd17021e93a4f82b35ca9494c4d1a278a385862..a384a382c151994c3969ee967bc39ae0a08c4aa0 100644 --- a/src/test/java/net/ihe/gazelle/application/PatientRegistrySearchClientTest.java +++ b/src/test/java/net/ihe/gazelle/application/PatientRegistrySearchClientTest.java @@ -11,6 +11,8 @@ import java.util.List; import javax.xml.ws.WebServiceException; +import net.ihe.gazelle.adapter.connector.BusinessToFhirConverter; +import net.ihe.gazelle.adapter.connector.ConversionException; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java index dec9923be16352845bd9093713623d429f5ea300..a1cb969388cd7228d007ec1f279ebcc0d45372a3 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java +++ b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java @@ -89,6 +89,16 @@ class CHBundleProviderTest { assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.delete(id, cbpm.returnBundleFromResource(fileName)),"Bundle Could not be converted to HL7 Patient"); } + @Test + @Description("Test on the delete operation, deleting a Patient but with a null bundle") + @Severity(SeverityLevel.CRITICAL) + @Story("delete operation") + void testDeleteBlankId() { + String fileName = "post_request.json"; + IdType id = new IdType(""); + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.delete(id, cbpm.returnBundleFromResource(fileName)),"Bundle is null or Empty"); + } + @Test @Description("Test on the update operation, clean update without issue") @Severity(SeverityLevel.CRITICAL)