From b5ff6e93e76d6c66b9ca5d4fc2d662ea292a996e Mon Sep 17 00:00:00 2001 From: Alexandre P <apo@kereval.com> Date: Tue, 24 Aug 2021 16:54:07 +0200 Subject: [PATCH] PATREG-188 : Adding Test and Mock for Create Method in pixm-connector --- pom.xml | 8 +- .../BundleToPatientRegistryConverter.java | 21 +-- .../business/provider/CHBundleProvider.java | 57 ++++++-- .../provider/ChPatientResourceProvider.java | 20 ++- .../ResourcesToTestPurpose/post_request.json | 127 ++++++++++++++++++ .../post_request_1_entry.json | 37 +++++ .../post_request_NO_PATIENT.json | 48 +++++++ .../ResourcesToTestPurpose/post_response.json | 36 +++++ .../provider/CHBundleProviderMock.java | 40 ++++++ .../provider/CHBundleProviderTest.java | 75 +++++++++++ .../provider/CHPatientProviderMock.java | 41 ++++++ .../ChPatientResourceProviderTest.java | 18 ++- .../PatientRegistryFeedClientMock.java | 13 +- 13 files changed, 492 insertions(+), 49 deletions(-) create mode 100644 src/test/ResourcesToTestPurpose/post_request.json create mode 100644 src/test/ResourcesToTestPurpose/post_request_1_entry.json create mode 100644 src/test/ResourcesToTestPurpose/post_request_NO_PATIENT.json create mode 100644 src/test/ResourcesToTestPurpose/post_response.json create mode 100644 src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderMock.java create mode 100644 src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java create mode 100644 src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java diff --git a/pom.xml b/pom.xml index 1215fea..b753c02 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ <hapifhir_version>5.4.0</hapifhir_version> <maven.release.plugin.version>2.5.3</maven.release.plugin.version> <nexus.staging.maven.plugin.version>1.6.8</nexus.staging.maven.plugin.version> - <sonar.maven.plugin>3.5.0.1254</sonar.maven.plugin> + <sonar.maven.plugin>3.9.0.2155</sonar.maven.plugin> </properties> <scm> @@ -421,5 +421,11 @@ <artifactId>allure-junit5</artifactId> <version>2.14.0</version> </dependency> + <dependency> + <groupId>com.googlecode.json-simple</groupId> + <artifactId>json-simple</artifactId> + <version>1.1.1</version> + </dependency> + </dependencies> </project> diff --git a/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java b/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java index 6b150f2..1395419 100644 --- a/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java +++ b/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java @@ -27,26 +27,9 @@ public class BundleToPatientRegistryConverter { private BundleToPatientRegistryConverter() { } - public static net.ihe.gazelle.app.patientregistryapi.business.Patient iti93BundleToPatient(Bundle pixmFeed) throws ConversionException { - List<BundleEntryComponent> listOfEntries = pixmFeed.getEntry(); - if (listOfEntries.size() != 2) { - throw new InvalidRequestException("PixM Feed should have 2 entries."); - } - for (BundleEntryComponent entry : listOfEntries) { - if (entry.getResource().getResourceType() == ResourceType.Bundle) { - Bundle historyBundle = (Bundle) entry.getResource(); - for (BundleEntryComponent resource : historyBundle.getEntry()) { - if (resource.getResource().getResourceType() == ResourceType.Patient) { - Patient patientToFeed = (Patient) resource.getResource(); - return hl7PatientToPatientRegistry(patientToFeed); - } - } - } - } - throw new InvalidRequestException("Missing Patient in Bundle"); - } - private static net.ihe.gazelle.app.patientregistryapi.business.Patient hl7PatientToPatientRegistry(Patient patient) throws ConversionException { + + public static net.ihe.gazelle.app.patientregistryapi.business.Patient hl7PatientToPatientRegistry(Patient patient) throws ConversionException { net.ihe.gazelle.app.patientregistryapi.business.Patient convertedPatient = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); if (patient.hasActive()) { convertedPatient.setActive(patient.getActive()); diff --git a/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java b/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java index 95178df..20983cc 100644 --- a/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java +++ b/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java @@ -5,26 +5,43 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import net.ihe.gazelle.adapter.connector.BundleToPatientRegistryConverter; import net.ihe.gazelle.adapter.connector.ConversionException; import net.ihe.gazelle.application.PatientRegistryFeedClient; +import net.ihe.gazelle.lib.annotations.Package; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.ResourceType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Named; +import java.util.List; @Named("chBundleProvider") public class CHBundleProvider implements IResourceProvider { + private static final Logger patientLogger = LoggerFactory.getLogger(CHBundleProvider.class); - @Inject + + private CHBundleProvider(){} + + @Package + public CHBundleProvider(ChPatientResourceProvider chPatientResourceProvider){ + this.chPatientResourceProvider=chPatientResourceProvider; + } + + @Inject private ChPatientResourceProvider chPatientResourceProvider; @Inject private PatientRegistryFeedClient patientRegistryFeedClient; + @Package + public CHBundleProvider(PatientRegistryFeedClient client) { + this.patientRegistryFeedClient = client; + } + @Override public Class<? extends IBaseResource> getResourceType() { return Bundle.class; @@ -36,25 +53,37 @@ public class CHBundleProvider implements IResourceProvider { * @param iti93Bundle * @return */ + @Create public MethodOutcome create(@ResourceParam Bundle iti93Bundle) { + if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { - patientLogger.error("test"); - throw new InvalidRequestException("test"); + throw new InvalidRequestException("Bundle is null or Empty"); } try { - net.ihe.gazelle.app.patientregistryapi.business.Patient patient = BundleToPatientRegistryConverter.iti93BundleToPatient(iti93Bundle); - MethodOutcome methodOutcome = new MethodOutcome(); -// chPatientResourceProvider.create(patient); -// methodOutcome.setResource(patientRegistryFeedClient.createPatient(patient)); - return methodOutcome; - + Patient patientBundle = iti93BundleToPatient(iti93Bundle); + return chPatientResourceProvider.create(patientBundle); } catch (ConversionException e) { throw new InvalidRequestException("Bundle Could not be converted to HL7 Patient"); } -// } catch (PatientFeedException e) { -// throw new InternalErrorException("Patient Feed client is not set"); -// } + } -} + private Patient iti93BundleToPatient(Bundle pixmFeed) throws ConversionException { + List<Bundle.BundleEntryComponent> listOfEntries = pixmFeed.getEntry(); + if (listOfEntries.size() != 2) { + throw new InvalidRequestException("PixM Feed should have 2 entries."); + } + for (Bundle.BundleEntryComponent entry : listOfEntries) { + if (entry.getResource().getResourceType() == ResourceType.Bundle) { + Bundle historyBundle = (Bundle) entry.getResource(); + for (Bundle.BundleEntryComponent resource : historyBundle.getEntry()) { + if (resource.getResource().getResourceType() == ResourceType.Patient) { + return (Patient) resource.getResource(); + } + } + } + } + throw new InvalidRequestException("Missing Patient in Bundle"); + } +} \ No newline at end of file diff --git a/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java b/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java index 9071ab3..3505063 100644 --- a/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java +++ b/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java @@ -80,6 +80,7 @@ public class ChPatientResourceProvider implements IResourceProvider { } + /** * The getResourceType method comes from IResourceProvider, and must be overridden to indicate what type of resource this provider supplies. */ @@ -121,15 +122,20 @@ public class ChPatientResourceProvider implements IResourceProvider { */ @Create public MethodOutcome create(@ResourceParam Patient iti93Bundle) { -// if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { -// patientLogger.error(NO_BUNDLE_PROVIDED); -// throw new InvalidRequestException(NO_BUNDLE_PROVIDED); -// } + if (iti93Bundle == null || iti93Bundle.isEmpty()) { + patientLogger.error(NO_BUNDLE_PROVIDED); + throw new InvalidRequestException(NO_BUNDLE_PROVIDED); + } try { - net.ihe.gazelle.app.patientregistryapi.business.Patient patient = BundleToPatientRegistryConverter.iti93BundleToPatient(null); + net.ihe.gazelle.app.patientregistryapi.business.Patient patient = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(iti93Bundle); MethodOutcome methodOutcome = new MethodOutcome(); methodOutcome.setResource(patientRegistryFeedClient.createPatient(patient)); - return methodOutcome; + if (methodOutcome != null){ + return methodOutcome; + } + else { + throw new NullPointerException("MethodOutcome was not created"); + } } catch (ConversionException e) { throw new InvalidRequestException("Bundle Could not be converted to HL7 Patient"); @@ -156,7 +162,7 @@ public class ChPatientResourceProvider implements IResourceProvider { } try { net.ihe.gazelle.app.patientregistryapi.business.Patient patientToUpdate = - BundleToPatientRegistryConverter.iti93BundleToPatient(null); + BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(null); MethodOutcome methodOutcome = new MethodOutcome(); methodOutcome.setResource(patientRegistryFeedClient.updatePatient(patientToUpdate, uuid)); return methodOutcome; diff --git a/src/test/ResourcesToTestPurpose/post_request.json b/src/test/ResourcesToTestPurpose/post_request.json new file mode 100644 index 0000000..a2f3449 --- /dev/null +++ b/src/test/ResourcesToTestPurpose/post_request.json @@ -0,0 +1,127 @@ +{ + "resourceType" : "Bundle", + "id" : "BundlePIXmFeed", + "meta" : { + "profile" : [ + "http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-pixm-bundle" + ] + }, + "type" : "message", + "entry" : [ + { + "fullUrl" : "http://example.com/fhir/MessageHeader/1", + "resource" : { + "resourceType" : "MessageHeader", + "id" : "1", + "text" : { + "status" : "generated", + "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative</b></p><p><b>event</b>: <code>urn:ihe:iti:pmir:2019:patient-feed</code></p><h3>Destinations</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientEndpoint\">http://example.com/patientEndpoint</a></td></tr></table><h3>Sources</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientSource\">http://example.com/patientSource</a></td></tr></table><p><b>focus</b>: <a href=\"#Bundle_abc\">See above (Bundle/abc)</a></p></div>" + }, + "eventUri" : "urn:ihe:iti:pmir:2019:patient-feed", + "destination" : [ + { + "endpoint" : "http://example.com/patientEndpoint" + } + ], + "source" : { + "endpoint" : "http://example.com/patientSource" + }, + "focus" : [ + { + "reference" : "Bundle/abc" + } + ] + } + }, + { + "fullUrl" : "http://example.com/fhir/Bundle/abc", + "resource" : { + "resourceType" : "Bundle", + "id" : "abc", + "type" : "history", + "entry" : [ + { + "fullUrl" : "http://example.com/fhir/Patient/PatientPIXmFeed", + "resource" : { + "resourceType" : "Patient", + "id" : "PatientPIXmFeed", + "text" : { + "status" : "generated", + "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative</b></p><p><b>id</b>: PatientPIXmFeed</p><p><b>meta</b>: </p><p><b>identifier</b>: Medical record number = 8734</p><p><b>name</b>: Franz Muster , Muster </p><p><b>gender</b>: male</p><p><b>birthDate</b>: 1995-01-27</p></div>" + }, + "contained" : [ + { + "resourceType" : "Organization", + "id" : "org1", + "identifier" : [ + { + "system" : "urn:oid:2.51.1.3", + "value" : "7601000201041" + } + ], + "address" : [ + { + "use" : "work", + "line" : [ + "Doktorgasse", + "2" + ], + "city" : "Musterhausen", + "postalCode" : "8888", + "country" : "CH" + } + ] + } + ], + "identifier" : [ + { + "type" : { + "coding" : [ + { + "system" : "http://terminology.hl7.org/CodeSystem/v2-0203", + "code" : "MR" + } + ] + }, + "system" : "urn:oid:2.16.756.888888.3.1", + "value" : "8734" + } + ], + "name" : [ + { + "family" : "Muster", + "given" : [ + "Franz" + ] + }, + { + "family" : "Muster", + "_family" : { + "extension" : [ + { + "url" : "http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier", + "valueCode" : "BR" + } + ] + } + } + ], + "gender" : "male", + "birthDate" : "1995-01-27", + "managingOrganization" : { + "reference" : "#org1" + } + }, + "request" : { + "method" : "POST", + "url" : "Patient" + }, + "response" : { + "status" : "200" + } + } + ] + } + } + ] +} diff --git a/src/test/ResourcesToTestPurpose/post_request_1_entry.json b/src/test/ResourcesToTestPurpose/post_request_1_entry.json new file mode 100644 index 0000000..2272eb1 --- /dev/null +++ b/src/test/ResourcesToTestPurpose/post_request_1_entry.json @@ -0,0 +1,37 @@ +{ + "resourceType" : "Bundle", + "id" : "BundlePIXmFeed", + "meta" : { + "profile" : [ + "http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-pixm-bundle" + ] + }, + "type" : "message", + "entry" : [ + { + "fullUrl" : "http://example.com/fhir/MessageHeader/1", + "resource" : { + "resourceType" : "MessageHeader", + "id" : "1", + "text" : { + "status" : "generated", + "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative</b></p><p><b>event</b>: <code>urn:ihe:iti:pmir:2019:patient-feed</code></p><h3>Destinations</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientEndpoint\">http://example.com/patientEndpoint</a></td></tr></table><h3>Sources</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientSource\">http://example.com/patientSource</a></td></tr></table><p><b>focus</b>: <a href=\"#Bundle_abc\">See above (Bundle/abc)</a></p></div>" + }, + "eventUri" : "urn:ihe:iti:pmir:2019:patient-feed", + "destination" : [ + { + "endpoint" : "http://example.com/patientEndpoint" + } + ], + "source" : { + "endpoint" : "http://example.com/patientSource" + }, + "focus" : [ + { + "reference" : "Bundle/abc" + } + ] + } + } + ] +} diff --git a/src/test/ResourcesToTestPurpose/post_request_NO_PATIENT.json b/src/test/ResourcesToTestPurpose/post_request_NO_PATIENT.json new file mode 100644 index 0000000..cf37919 --- /dev/null +++ b/src/test/ResourcesToTestPurpose/post_request_NO_PATIENT.json @@ -0,0 +1,48 @@ +{ + "resourceType" : "Bundle", + "id" : "BundlePIXmFeed", + "meta" : { + "profile" : [ + "http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-pixm-bundle" + ] + }, + "type" : "message", + "entry" : [ + { + "fullUrl" : "http://example.com/fhir/MessageHeader/1", + "resource" : { + "resourceType" : "MessageHeader", + "id" : "1", + "text" : { + "status" : "generated", + "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative</b></p><p><b>event</b>: <code>urn:ihe:iti:pmir:2019:patient-feed</code></p><h3>Destinations</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientEndpoint\">http://example.com/patientEndpoint</a></td></tr></table><h3>Sources</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientSource\">http://example.com/patientSource</a></td></tr></table><p><b>focus</b>: <a href=\"#Bundle_abc\">See above (Bundle/abc)</a></p></div>" + }, + "eventUri" : "urn:ihe:iti:pmir:2019:patient-feed", + "destination" : [ + { + "endpoint" : "http://example.com/patientEndpoint" + } + ], + "source" : { + "endpoint" : "http://example.com/patientSource" + }, + "focus" : [ + { + "reference" : "Bundle/abc" + } + ] + } + }, + { + "fullUrl" : "http://example.com/fhir/Bundle/abc", + "resource" : { + "resourceType" : "Bundle", + "id" : "abc", + "type" : "history", + "entry" : [ + + ] + } + } + ] +} diff --git a/src/test/ResourcesToTestPurpose/post_response.json b/src/test/ResourcesToTestPurpose/post_response.json new file mode 100644 index 0000000..213578d --- /dev/null +++ b/src/test/ResourcesToTestPurpose/post_response.json @@ -0,0 +1,36 @@ +{ + "resourceType" : "Bundle", + "id" : "BundlePIXmResponse", + "meta" : { + "profile" : [ + "http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-pixm-bundle-response" + ] + }, + "type" : "message", + "entry" : [ + { + "fullUrl" : "http://example.com/fhir/MessageHeader/1", + "resource" : { + "resourceType" : "MessageHeader", + "id" : "1", + "text" : { + "status" : "generated", + "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative</b></p><p><b>event</b>: <code>urn:ihe:iti:pmir:2019:patient-feed</code></p><h3>Destinations</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientEndpoint\">http://example.com/patientEndpoint</a></td></tr></table><h3>Sources</h3><table class=\"grid\"><tr><td>-</td><td><b>Endpoint</b></td></tr><tr><td>*</td><td><a href=\"http://example.com/patientSource\">http://example.com/patientSource</a></td></tr></table><h3>Responses</h3><table class=\"grid\"><tr><td>-</td><td><b>Identifier</b></td><td><b>Code</b></td></tr><tr><td>*</td><td>1</td><td>ok</td></tr></table></div>" + }, + "eventUri" : "urn:ihe:iti:pmir:2019:patient-feed", + "destination" : [ + { + "endpoint" : "http://example.com/patientEndpoint" + } + ], + "source" : { + "endpoint" : "http://example.com/patientSource" + }, + "response" : { + "identifier" : "1", + "code" : "ok" + } + } + } + ] +} \ No newline at end of file diff --git a/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderMock.java b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderMock.java new file mode 100644 index 0000000..fdebe3b --- /dev/null +++ b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderMock.java @@ -0,0 +1,40 @@ +package net.ihe.gazelle.business.provider; + + +import ca.uhn.fhir.context.FhirContext; +import org.hl7.fhir.r4.model.Bundle; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class CHBundleProviderMock { + + public final static String ID_TO_RETURN= "OK"; + public final static String PATH_TO_RESOURCE="src/test/ResourcesToTestPurpose/"; + + + + protected Bundle returnBundleFromResource(String nameOfFile){ + try{ + + if ("null.json".equals(nameOfFile)){ + return null; + } + Bundle bundleResquest = (Bundle) FhirContext.forR4().newJsonParser().parseResource(new FileReader(PATH_TO_RESOURCE+nameOfFile)); + return bundleResquest; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + +}// end class \ No newline at end of file diff --git a/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java new file mode 100644 index 0000000..e08dd3d --- /dev/null +++ b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java @@ -0,0 +1,75 @@ +package net.ihe.gazelle.business.provider; + +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.param.StringAndListParam; +import ca.uhn.fhir.rest.param.StringOrListParam; +import ca.uhn.fhir.rest.param.StringParam; +import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import io.qameta.allure.Description; +import io.qameta.allure.Severity; +import io.qameta.allure.SeverityLevel; +import io.qameta.allure.Story; +import net.ihe.gazelle.application.PatientRegistryFeedClient; +import net.ihe.gazelle.application.PatientRegistrySearchClient; +import net.ihe.gazelle.application.PatientRegistryXRefSearchClient; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.InvalidClassException; + +import static org.junit.jupiter.api.Assertions.*; + +class CHBundleProviderTest { + + @BeforeAll + static void initialized() { + xRefSearchClientMock = new PatientRegistryXRefSearchClientMock(); + } + + + private static PatientRegistryXRefSearchClient xRefSearchClientMock = new PatientRegistryXRefSearchClientMock(); + private static PatientRegistrySearchClient searchClientMock = new PatientRegistrySearchClientMock(); + private static PatientRegistryFeedClient feedClientMock = new PatientRegistryFeedClientMock(); + + private static final ChPatientResourceProvider provider = new ChPatientResourceProvider(xRefSearchClientMock); + private static final ChPatientResourceProvider read_provider = new ChPatientResourceProvider(searchClientMock); + private static final ChPatientResourceProvider feed_provider = new ChPatientResourceProvider(feedClientMock); + + private static final CHBundleProvider bundle_feed_provider = new CHBundleProvider(new CHPatientProviderMock(feedClientMock)); + + CHBundleProviderMock cbpm = new CHBundleProviderMock(); + + + @Test + @Description("Test on the Create Method for pixm-connector") + void testCreatePatient() { + String fileName = "post_request.json"; + MethodOutcome mo = bundle_feed_provider.create(cbpm.returnBundleFromResource(fileName)); + assertEquals(cbpm.ID_TO_RETURN,mo.getId().getValue()); + } + + @Test + @Description("Test on the Create Method for pixm-connector with a null Bundle") + void testCreateNullBundle() { + String fileName = "null.json"; + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.create(cbpm.returnBundleFromResource(fileName)),"Bundle is null or Empty"); + } + + @Test + @Description("Test on the Create Method with a Bundle with No Patient inside") + void testCreateNoPatientInBundle() { + String fileName = "post_request_NO_PATIENT.json"; + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.create(cbpm.returnBundleFromResource(fileName)),"Missing Patient in Bundle"); + } + + @Test + @Description("Test on the Create Method with a Bundle with 3 entries") + void testCreatePatientBundleWith3Entries() { + String fileName = "post_request_1_entry.json"; + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.create(cbpm.returnBundleFromResource(fileName))); + } + + + +} \ No newline at end of file diff --git a/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java b/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java new file mode 100644 index 0000000..10f9b4b --- /dev/null +++ b/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java @@ -0,0 +1,41 @@ +package net.ihe.gazelle.business.provider; + +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.api.MethodOutcome; +import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException; +import net.ihe.gazelle.application.PatientRegistryFeedClient; +import net.ihe.gazelle.application.PatientRegistryXRefSearchClient; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Patient; + +public class CHPatientProviderMock extends ChPatientResourceProvider{ + + + public CHPatientProviderMock(PatientRegistryFeedClient patientRegistryFeedClient) { + super(patientRegistryFeedClient); + + } + + @Override + public MethodOutcome create(@ResourceParam Patient iti93Bundle) { + MethodOutcome mo = new MethodOutcome(); + IIdType iIdType = new IdType(); + + //Case OK + if (iti93Bundle.getId().equals("Patient/PatientPIXmFeed")){ + return mo.setId(iIdType.setValue("OK")); + } + //Case NULL + if (iti93Bundle==null){ + return null; + } + return null; + + + //ttt spécifique de mon mock : tel cas d'entrée c'est tel sortie etc + // cas ok ko cas null + + + } +} diff --git a/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java index ca724be..e9ced36 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java +++ b/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java @@ -3,11 +3,13 @@ package net.ihe.gazelle.business.provider; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -275,7 +277,7 @@ class ChPatientResourceProviderTest { try { read_provider.read(id); } catch (InvalidRequestException e) { - Assert.assertEquals(ChPatientResourceProvider.NO_ID_PROVIDED, e.getMessage()); + assertEquals(ChPatientResourceProvider.NO_ID_PROVIDED, e.getMessage()); } } @@ -290,14 +292,16 @@ class ChPatientResourceProviderTest { } //TODO not implemented UTs on provider yet. - /*@Test - @Description("Test on create method, returns ok") + @Test + @Description("Test on Update method, returns ok") @Severity(SeverityLevel.CRITICAL) - @Story("CreateMethod") - void testCreateFine() { + @Story("UpdateMethod") + void testUpdateFine() { IdType id = new IdType(); + Bundle iti93Bundle = new Bundle(); + iti93Bundle.addEntry().getRequest(); id.setValue("3"); - assertEquals("[Arthur]", feed_provider.create(iti93Bundle)); - }*/ + //assertEquals("[Arthur]", feed_provider.update(id,iti93Bundle)); + } } \ No newline at end of file diff --git a/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java b/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java index a383e3a..64e5064 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java +++ b/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java @@ -1,9 +1,11 @@ package net.ihe.gazelle.business.provider; import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException; +import net.ihe.gazelle.app.patientregistryapi.business.Patient; import net.ihe.gazelle.app.patientregistryfeedclient.adapter.PatientFeedClient; import net.ihe.gazelle.application.PatientRegistryFeedClient; import net.ihe.gazelle.framework.preferencesmodelapi.application.OperationalPreferencesService; +import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException; import org.hl7.fhir.r4.model.Bundle; public class PatientRegistryFeedClientMock extends PatientRegistryFeedClient { @@ -26,6 +28,15 @@ public class PatientRegistryFeedClientMock extends PatientRegistryFeedClient { @Override public Bundle createPatient(net.ihe.gazelle.app.patientregistryapi.business.Patient patient) throws PatientFeedException { - return null; + String uuid = patient.getUuid(); + Bundle bundle = new Bundle(); + bundle.setId("1"); + + switch (uuid){ + case "PatientPixMFeed": + return bundle; + default: + return null; + } } } -- GitLab