Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 922efaa0 authored by pm's avatar pm
Browse files

end of feature, sonar then ready for qualif

parent b3fae468
No related branches found
No related tags found
2 merge requests!5Release/2.0.0,!4Pixm
......@@ -18,9 +18,15 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;
import net.ihe.gazelle.adapter.connector.BusinessToFhirConverter;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PatientSearchCriterionKey;
import net.ihe.gazelle.app.patientregistryapi.business.PersonName;
......@@ -34,13 +40,15 @@ import net.ihe.gazelle.lib.searchmodelapi.business.searchcriterion.SearchCriteri
import net.ihe.gazelle.lib.searchmodelapi.business.searchcriterion.StringSearchCriterion;
//TODO allure description
//test name for exception
@Feature("PatientSearchClientTest")
@RunWith(MockitoJUnitRunner.class)
public class PatientRegistrySearchClientTest {
static private BusinessToFhirConverter businessToFhirConverter;
private static final String TEST_UUID = "123e4567-e89b-12d3-a456-426614174000";
private static final String MALFORMED_UUID = "123e4567-e89b-12d3-a456-42661417400";
@Mock
static private PatientSearchClient patientSearchClientMock;
@Mock
......@@ -54,7 +62,10 @@ public class PatientRegistrySearchClientTest {
operationalPreferencesService = Mockito.mock(OperationalPreferencesService.class);
}
//@Test
@Test
@Description("Test on initialization, when a namespace exception is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializeNameSpaceException() throws PreferenceException, NamespaceException {
Mockito.doThrow(NamespaceException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -63,14 +74,17 @@ public class PatientRegistrySearchClientTest {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
assertThrows(SearchException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
@Test
@Description("Test on initialization, when a preference exception is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializePreferenceException() throws PreferenceException, NamespaceException {
Mockito.doThrow(PreferenceException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -79,14 +93,17 @@ public class PatientRegistrySearchClientTest {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
assertThrows(SearchException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
@Test
@Description("Test on initialization, when the url of the server is malformed")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializeMalformedURLException() throws PreferenceException, NamespaceException {
Mockito.doThrow(MalformedURLException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -95,14 +112,17 @@ public class PatientRegistrySearchClientTest {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
assertThrows(SearchException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
@Test
@Description("Test on initialization, when a web service exception is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializeWebServiceException() throws PreferenceException, NamespaceException {
Mockito.doThrow(WebServiceException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -111,88 +131,103 @@ public class PatientRegistrySearchClientTest {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
assertThrows(SearchException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
void TestSearchException() throws SearchException {
@Test
@Description("Test on read, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestSearchExceptionMapping() throws SearchException {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
SearchException exception = new SearchException("Exception while Mapping with GITB elements !");
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
Mockito.doThrow(exception).when(patientSearchClientMock).search(searchCriteria);
assertThrows(InternalError.class,
Mockito.doThrow(exception).when(patientSearchClientMock).search(anyObject());
assertThrows(InternalErrorException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
void TestSearchException2() throws SearchException {
@Test
@Description("Test on read, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestSearchExceptionInvalidResponse() throws SearchException {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
SearchException exception = new SearchException("Invalid Response from distant PatientFeedProcessingService !");
Mockito.doThrow(exception).when(patientSearchClientMock).search(searchCriteria);
Mockito.doThrow(exception).when(patientSearchClientMock).search(anyObject());
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
assertThrows(ResourceNotFoundException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
void TestSearchException3() throws SearchException {
@Test
@Description("Test on read, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestSearchExceptionInvalidOperation() throws SearchException {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
SearchException exception = new SearchException("Invalid operation used on distant PatientFeedProcessingService !");
Mockito.doThrow(exception).when(patientSearchClientMock).search(searchCriteria);
Mockito.doThrow(exception).when(patientSearchClientMock).search(anyObject());
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
assertThrows(InvalidRequestException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
void TestSearchException4() throws SearchException {
@Test
@Description("Test on read, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestSearchExceptionInvalidRquest() throws SearchException {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
SearchException exception = new SearchException("Invalid Request sent to distant PatientFeedProcessingService !");
Mockito.doThrow(exception).when(patientSearchClientMock).search(searchCriteria);
Mockito.doThrow(exception).when(patientSearchClientMock).search(anyObject());
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
assertThrows(InvalidRequestException.class,
() -> patientRegistrySearchClient.searchPatient(searchCriterion.getValue()));
}
//@Test
@Test
@Description("Test on read, when no patient is returned")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestNoPatientReturned() throws SearchException {
List <Patient> resources = new ArrayList<>();
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
Mockito.doReturn(resources).when(patientSearchClientMock).search(searchCriteria);
doAnswer(invocation -> resources).when(patientSearchClientMock).search(anyObject());
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
......@@ -202,7 +237,10 @@ public class PatientRegistrySearchClientTest {
}
//@Test
@Test
@Description("Test on read, when exactly one patient is returned")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestOnePatientReturned() throws SearchException {
org.hl7.fhir.r4.model.Patient arthur = new org.hl7.fhir.r4.model.Patient();
......@@ -217,10 +255,10 @@ public class PatientRegistrySearchClientTest {
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriterion.setValue(TEST_UUID);
searchCriteria.addSearchCriterion(searchCriterion);
Mockito.doReturn(resources).when(patientSearchClientMock).search(searchCriteria);
doAnswer(invocation -> resources).when(patientSearchClientMock).search(anyObject());
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
......@@ -229,23 +267,73 @@ public class PatientRegistrySearchClientTest {
}
@Test
@Description("Test on read, when more than one patient is returned")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestManyPatientsReturned() throws SearchException {
List <Patient> resources = new ArrayList<>();
resources.add(new Patient());
resources.add(new Patient());
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion<String> searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue("123e4567-e89b-12d3-a456-426614174000");
searchCriteria.addSearchCriterion(searchCriterion);
doAnswer(invocation -> resources).when(patientSearchClientMock).search(anyObject());
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
assertThrows(ResourceNotFoundException.class,
() -> patientRegistrySearchClient.searchPatient("123e4567-e89b-12d3-a456-426614174000"));
() -> patientRegistrySearchClient.searchPatient(TEST_UUID));
}
//@Test
@Description("Test on read, when a conversion exception happens")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestConversionException() throws SearchException {
List <Patient> resources = new ArrayList<>();
resources.add(new Patient());
resources.add(new Patient());
// ConversionException exception = new ConversionException("Invalid Response from distant PatientFeedProcessingService !");
//Mockito.doThrow(exception).when(businessToFhirConverter).patientToFhirPatient(anyObject());
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
assertThrows(ResourceNotFoundException.class,
() -> patientRegistrySearchClient.searchPatient(TEST_UUID));
}
@Test
@Description("Test on read, when more than one patient is returned")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestMalformedUuid() throws SearchException {
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
assertThrows(InvalidRequestException.class,
() -> patientRegistrySearchClient.searchPatient(MALFORMED_UUID));
}
@Test
@Description("Test on read, when parameter is null")
@Severity(SeverityLevel.CRITICAL)
@Story("read")
void TestNoEntry() throws SearchException {
patientRegistrySearchClient = new PatientRegistrySearchClient();
patientRegistrySearchClient.setClient(patientSearchClientMock);
assertThrows(InvalidRequestException.class,
() -> patientRegistrySearchClient.searchPatient(null));
}
......
......@@ -4,6 +4,10 @@ import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import io.qameta.allure.Description;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
......@@ -46,6 +50,9 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
@Description("Test on initialization, when a namespace exception is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializeNameSpaceException() throws PreferenceException, NamespaceException {
Mockito.doThrow(NamespaceException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -61,6 +68,9 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
@Description("Test on initialization, when a preference exception is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializePreferenceException() throws PreferenceException, NamespaceException {
Mockito.doThrow(PreferenceException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -76,6 +86,9 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
@Description("Test on initialization, when a malformed url exception is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializeMalformedURLException() throws PreferenceException, NamespaceException {
Mockito.doThrow(MalformedURLException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -91,6 +104,9 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
@Description("Test on initialization, when a web service exception is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("initialization")
void TestInitializeWebServiceException() throws PreferenceException, NamespaceException {
Mockito.doThrow(WebServiceException.class).when(operationalPreferencesService).getStringValue("java:/app/gazelle/pixm-connector" +
"/operational" +
......@@ -107,7 +123,10 @@ class PatientRegistryXRefSearchClientTest {
@Test
void TestSearchCrossException() throws SearchCrossReferenceException {
@Description("Test on ihe_pix, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
void TestSearchCrossExceptionInvalidRequest() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("Test1");
sourceIdentifier.setValue("1");
......@@ -121,7 +140,10 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
void TestSearchCrossException2() throws SearchCrossReferenceException {
@Description("Test on ihe_pix, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
void TestSearchCrossExceptionResourceNotFound() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("Test1");
sourceIdentifier.setValue("1");
......@@ -135,7 +157,10 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
void TestSearchCrossException3() throws SearchCrossReferenceException {
@Description("Test on ihe_pix, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
void TestSearchCrossExceptionForbiddenOperation() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("Test1");
sourceIdentifier.setValue("1");
......@@ -149,7 +174,10 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
void TestSearchCrossException4() throws SearchCrossReferenceException {
@Description("Test on ihe_pix, a specific excpetion is thrown")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
void TestSearchCrossExceptionInternalError() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("Test1");
sourceIdentifier.setValue("1");
......@@ -163,6 +191,9 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
@Description("Test on ihe_pix, when no Patient is returned")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
void TestSearchCrossNoMember() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("Test1");
......@@ -178,6 +209,9 @@ class PatientRegistryXRefSearchClientTest {
@Test
@Description("Test on ihe_pix, when one Patient is returned")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
void TestSearchCross1Member() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("Test1");
......@@ -203,6 +237,9 @@ class PatientRegistryXRefSearchClientTest {
}
@Test
@Description("Test on ihe_pix, when one target domain was given as parameter")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
void TestSearchNotargetDomain() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("Test1");
......@@ -227,6 +264,9 @@ class PatientRegistryXRefSearchClientTest {
Assert.assertEquals(1, parameters.getParameter().size());
}
@Description("Test on ihe_pix, when two target domain was given as parameter")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix")
@Test
void TestSearchfullTargetDomain() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
......
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.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.BeforeAll;
import org.junit.jupiter.api.Test;
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.ForbiddenOperationException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import io.qameta.allure.*;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;
import net.ihe.gazelle.application.PatientRegistrySearchClient;
import net.ihe.gazelle.application.PatientRegistryXRefSearchClient;
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.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Feature("ChaPatientProvider")
class ChPatientResourceProviderTest {
private static PatientRegistryXRefSearchClient xRefSearchClientMock = new PatientRegistryXRefSearchClientMock();
private static final ChPatientResourceProvider provider = new ChPatientResourceProvider(xRefSearchClientMock);
@BeforeAll
static void initialized() {
xRefSearchClientMock = new PatientRegistryXRefSearchClientMock();
}
@Test
void testOkPatient() {
TokenParam sourceId = new TokenParam("urn:oid:1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("urn:oid:2"));
targetDomains.addAnd(stringParam);
Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
ParametersParameterComponent singleResponse = response.getParameter().get(0);
Identifier r4 = (Identifier) singleResponse.getValue();
assertEquals(PatientRegistryXRefSearchClientMock.URN_OK, r4.getValue());
assertEquals(PatientRegistryXRefSearchClientMock.URN_OK, r4.getSystem());
}
@Test
void testOkPatientHttp() {
TokenParam sourceId = new TokenParam("http://1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
ParametersParameterComponent singleResponse = response.getParameter().get(0);
Identifier r4 = (Identifier) singleResponse.getValue();
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getValue());
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getSystem());
}
@Test
void testOkPatientTwoTargetSystem() {
TokenParam sourceId = new TokenParam("http://1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
stringParam.add(new StringParam("http://3"));
targetDomains.addAnd(stringParam);
Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
ParametersParameterComponent singleResponse = response.getParameter().get(0);
Identifier r4 = (Identifier) singleResponse.getValue();
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getValue());
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getSystem());
}
@Test
void testSourceIdentifierNull() {
TokenParam sourceId = new TokenParam();
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ResourceNotFoundException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
}
}
@Test
void testSourceIdentifierSystemNull() {
TokenParam sourceId = new TokenParam();
sourceId.setValue("69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ResourceNotFoundException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
}
}
@Test
void testSourceIdentifierValueNull() {
TokenParam sourceId = new TokenParam();
sourceId.setSystem("http://1");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (InvalidRequestException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
}
}
@Test
void testSourceIdentifierSystemBlank() {
TokenParam sourceId = new TokenParam("", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (InvalidRequestException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
}
}
@Test
void testMalformedSystemIdentifier() {
TokenParam sourceId = new TokenParam("1:2:3", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ResourceNotFoundException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
}
}
@Test
void testTargetIdentifierBlank() {
TokenParam sourceId = new TokenParam("http::/1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam(""));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ForbiddenOperationException e) {
assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
}
}
@Test
void testTargetIdentifierNull() {
TokenParam sourceId = new TokenParam("http::/1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ForbiddenOperationException e) {
assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
}
}
@Test
void testTargetIdentifierMoreThanTwo() {
TokenParam sourceId = new TokenParam("http::/1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
stringParam.add(new StringParam("http://3"));
stringParam.add(new StringParam("http://4"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ForbiddenOperationException e) {
assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on read method, good arguments")
@Severity(SeverityLevel.CRITICAL)
@Story("ReadMethod")
void testReadFine() {
Assert.assertFalse(false);
}
private static PatientRegistryXRefSearchClient xRefSearchClientMock = new PatientRegistryXRefSearchClientMock();
private static PatientRegistrySearchClient searchClientMock = new PatientRegistrySearchClientMock();
private static final ChPatientResourceProvider provider = new ChPatientResourceProvider(xRefSearchClientMock);
private static final ChPatientResourceProvider read_provider = new ChPatientResourceProvider(searchClientMock);
@BeforeAll
static void initialized() {
xRefSearchClientMock = new PatientRegistryXRefSearchClientMock();
}
@Test
@Description("Test on ihe_pix operation, when aiming for a patient on 1 target System, with unr:oid: type system identifiers")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testOkPatient() {
TokenParam sourceId = new TokenParam("urn:oid:1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("urn:oid:2"));
targetDomains.addAnd(stringParam);
Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
ParametersParameterComponent singleResponse = response.getParameter().get(0);
Identifier r4 = (Identifier) singleResponse.getValue();
assertEquals(PatientRegistryXRefSearchClientMock.URN_OK, r4.getValue());
assertEquals(PatientRegistryXRefSearchClientMock.URN_OK, r4.getSystem());
}
@Test
@Description("Test on ihe_pix operation, when aiming for a patient on 1 target System, with http system identifiers")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testOkPatientHttp() {
TokenParam sourceId = new TokenParam("http://1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
ParametersParameterComponent singleResponse = response.getParameter().get(0);
Identifier r4 = (Identifier) singleResponse.getValue();
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getValue());
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getSystem());
}
@Test
@Description("Test on ihe_pix operation, when aiming for a patient on 2 target System")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testOkPatientTwoTargetSystem() {
TokenParam sourceId = new TokenParam("http://1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
stringParam.add(new StringParam("http://3"));
targetDomains.addAnd(stringParam);
Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
ParametersParameterComponent singleResponse = response.getParameter().get(0);
Identifier r4 = (Identifier) singleResponse.getValue();
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getValue());
assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getSystem());
}
@Test
@Description("Test on ihe_pix operation, when the patient source identifiers is null")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierNull() {
TokenParam sourceId = new TokenParam();
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ResourceNotFoundException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on ihe_pix operation, when the patient system identifiers is null")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierSystemNull() {
TokenParam sourceId = new TokenParam();
sourceId.setValue("69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ResourceNotFoundException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on ihe_pix operation, when the patient source identifiers is null")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierValueNull() {
TokenParam sourceId = new TokenParam();
sourceId.setSystem("http://1");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (InvalidRequestException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on ihe_pix operation, when the patient system identifiers is blank")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierSystemBlank() {
TokenParam sourceId = new TokenParam("", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (InvalidRequestException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on ihe_pix operation, when the patient system identifier hasn't been recognized")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testMalformedSystemIdentifier() {
TokenParam sourceId = new TokenParam("1:2:3", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ResourceNotFoundException e) {
assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on ihe_pix operation, when target identifiers is blank")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testTargetIdentifierBlank() {
TokenParam sourceId = new TokenParam("http::/1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam(""));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ForbiddenOperationException e) {
assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on ihe_pix operation, when no target identifiers is given")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testTargetIdentifierNull() {
TokenParam sourceId = new TokenParam("http::/1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ForbiddenOperationException e) {
assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on ihe_pix operation, when target identifiers don't have valid cardinality")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testTargetIdentifierMoreThanTwo() {
TokenParam sourceId = new TokenParam("http::/1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
StringOrListParam stringParam = new StringOrListParam();
stringParam.add(new StringParam("http://2"));
stringParam.add(new StringParam("http://3"));
stringParam.add(new StringParam("http://4"));
targetDomains.addAnd(stringParam);
try {
provider.findPatientsByIdentifier(sourceId, targetDomains);
} catch (ForbiddenOperationException e) {
assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
}
}
@Test
@Description("Test on read method, but resource is not found")
@Severity(SeverityLevel.CRITICAL)
@Story("ReadMethod")
void testReadResourceNotFound() {
IdType id = new IdType();
id.setValue("1");
assertThrows(InternalErrorException.class,
() -> read_provider.read(id));
}
@Test
@Description("Test on read method, but no parametr is given")
@Severity(SeverityLevel.CRITICAL)
@Story("ReadMethod")
void testReadNoIdGiven() {
IdType id = new IdType();
id.setValue("2");
try {
read_provider.read(id);
} catch (InvalidRequestException e) {
Assert.assertEquals(ChPatientResourceProvider.NO_ID_PROVIDED, e.getMessage());
}
}
@Test
@Description("Test on read method, returns ok")
@Severity(SeverityLevel.CRITICAL)
@Story("ReadMethod")
void testReadFine() {
IdType id = new IdType();
id.setValue("3");
assertEquals("[Arthur]", read_provider.read(id).getName().get(0).getGiven().toString());
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import io.qameta.allure.Description;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;
......@@ -19,7 +20,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Story("Test")
@Story("IHE Patient Provider")
class IhePatientResourceProviderTest {
private static PatientRegistryXRefSearchClient xRefSearchClientMock = new PatientRegistryXRefSearchClientMock();
private static final IhePatientResourceProvider provider = new IhePatientResourceProvider(xRefSearchClientMock);
......@@ -30,7 +31,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Severity(SeverityLevel.MINOR)
@Description("Test on ihe_pix operation, when aiming for a patient on 1 target System, with urn:oid: type system identifiers")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testOkPatient() {
TokenParam sourceId = new TokenParam("urn:oid:1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
......@@ -47,6 +50,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Description("Test on ihe_pix operation, when aiming for a patient on 1 target System, with http system identifiers")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testOkPatientHttp() {
TokenParam sourceId = new TokenParam("http://1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
......@@ -63,6 +69,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Description("Test on ihe_pix operation, when the whole patient source identifier is null")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierNull() {
TokenParam sourceId = new TokenParam();
StringAndListParam targetDomains = new StringAndListParam();
......@@ -79,6 +88,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Description("Test on ihe_pix operation, when the patient system identifiers is null")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierSystemNull() {
TokenParam sourceId = new TokenParam();
sourceId.setValue("69420");
......@@ -96,6 +108,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Description("Test on ihe_pix operation, when the patient source identifiers is null")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierValueNull() {
TokenParam sourceId = new TokenParam();
sourceId.setSystem("http://1");
......@@ -113,6 +128,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Description("Test on ihe_pix operation, when the patient system identifiers is blank")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testSourceIdentifierSystemBlank() {
TokenParam sourceId = new TokenParam("", "69420");
StringAndListParam targetDomains = new StringAndListParam();
......@@ -129,6 +147,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Description("Test on ihe_pix operation, when the target system is malformed and not recognized")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testMalformedSystemIdentifier() {
TokenParam sourceId = new TokenParam("1:2:3", "69420");
StringAndListParam targetDomains = new StringAndListParam();
......@@ -145,6 +166,9 @@ class IhePatientResourceProviderTest {
}
@Test
@Description("Test on ihe_pix operation, when the target system is blank")
@Severity(SeverityLevel.CRITICAL)
@Story("ihe_pix operation")
void testTargetIdentifierBlank() {
TokenParam sourceId = new TokenParam("http::/1", "69420");
StringAndListParam targetDomains = new StringAndListParam();
......
package net.ihe.gazelle.business.provider;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.r4.model.Patient;
import net.ihe.gazelle.app.patientregistrysearchclient.adapter.PatientSearchClient;
import net.ihe.gazelle.application.PatientRegistrySearchClient;
import net.ihe.gazelle.framework.preferencesmodelapi.application.OperationalPreferencesService;
import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
public class PatientRegistrySearchClientMock extends PatientRegistrySearchClient {
public static final String HTTP_OK = "HTTP_OK";
public static final String URN_OK = "URN_OK";
private static final String CROSS_REFERENCE = "Cross Reference";
public PatientRegistrySearchClientMock() {
}
public PatientRegistrySearchClientMock(OperationalPreferencesService operationalPreferencesService) {
super(operationalPreferencesService);
}
public PatientRegistrySearchClientMock(PatientSearchClient searchClient) {
setClient(searchClient);
}
@Override
public Patient searchPatient(String uuid) throws SearchException {
Patient arthur = new Patient();
arthur.addName().addGiven("Arthur");
switch (uuid){
case "1":
throw new SearchException("test exception");
case "3":
return arthur;
default:
return null;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment