Commit 39ab6ca1 authored by Alexandre Pocinho's avatar Alexandre Pocinho
Browse files

Work on PATREG-202 adding Tests Methods for MERGE method for PatientFeedClient

parent f90a85f5
Pipeline #275168 failed with stages
in 1 minute
......@@ -544,5 +544,191 @@ public class PatientFeedClientTest {
assertEquals("Invalid operation used on distant PatientFeedProcessingService !", exception.getMessage());
}
/*------------------------------------MERGE METHOD TESTS---------------------------------------------------*/
/**
* Test Merge client getting successful response
* @throws PatientFeedException
*/
@Test
public void merge_With_Success() throws PatientFeedException {
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
String uuid = patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid());
assertEquals(TestProcessingService.UUID, uuid);
}
/**
* Test Merge client getting a response with no report
*/
@Test
public void merge_With_Success_missing_report() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.MERGE_MISSING_REPORT);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Response from the distant PatientFeedProcessingService shall contain a report with " +
"the success status of the operation !", exception.getCause().getMessage());
}
/**
* Test Merge client getting a response with failed report
*/
@Test
public void merge_With_Success_failed_report() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.DELETE_FAILED_REPORT);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("MyError", exception.getMessage());
}
/**
* Test Merge client getting a response with multiple outputs
*/
@Test
public void merge_With_Success_multiple_output() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.MERGE_MULTIPLE_OUTPUT);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Response from the distant PatientFeedProcessingService shall contain a single " +
"output for fed Patient UUID !", exception.getCause().getMessage());
}
/**
* Test Merge client getting a response with invalid output (not a String)
*/
@Test
public void merge_With_Success_invalid_output() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.INVALID_OUTPUT);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Error while mapping processing output from distant PatientFeedProcessingService " +
"to String !", exception.getCause().getMessage());
}
/**
* Test Merge client getting a null response
*/
@Test
public void merge_null_response() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.NULL_RESPONSE);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Empty Response from the distant PatientFeedProcessingService !", exception.getCause().getMessage());
}
/**
* Test Merge client getting a response with an unexpected status
*/
@Test
public void merge_unexpected_processing_status() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.MERGE_UNEXPECTED_STATUS);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Processing response with unexpected type WARNING ! Expected type is " +
"either SUCCESS or FAILURE.", exception.getCause().getMessage());
}
/**
* Test Merge client getting a response with no error report in report
*/
@Test
public void merge_no_reports_in_report() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.MERGE_NO_REPORTS_IN_REPORT);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("The report from the ProcessResponse shall not be null and shall contain a single error.", exception.getCause().getMessage());
}
/**
* Test Merge client getting a response with no error in a failure report
*/
@Test
public void merge_no_error_in_failure_report() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.MERGE_NO_ERROR_IN_FAILURE_REPORT);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("The report from the ProcessResponse shall not be null and shall contain a single error.", exception.getCause().getMessage());
}
/**
* Test Feed client getting a response with an error with no description
*/
@Test
@Covers(requirements = "PATREG-27")
public void merge_no_error_description() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.MERGE_NO_ERROR_DESCRIPTION);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Error from ProcessResponse report must have a valid description !", exception.getCause().getMessage());
}
/**
* Test Merge client getting an IllegalArgumentException
*/
@Test
public void merge_illegalArgumentException() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.ILLEGAL_ARGUMENT_EXCEPTION);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Invalid Request sent to distant PatientFeedProcessingService !", exception.getMessage());
}
/**
* Test Feed client getting an UnsupportedOperationException
*/
@Test
@Covers(requirements = "PATREG-117")
public void merge_unsupportedOperationException() {
testProcessingService.setResponseToReturn(TestProcessingService.ResponseTypes.UNSUPPORTED_OPERATION_EXCEPTION);
Patient patientOriginal = new Patient();
patientOriginal.setUuid("TEST-uuid1");
Patient patientDuplicated = new Patient();
patientDuplicated.setUuid("TEST-uuid2");
PatientFeedException exception = assertThrows(PatientFeedException.class, () -> patientFeedClient.mergePatient(patientOriginal.getUuid(),patientDuplicated.getUuid()));
assertEquals("Invalid operation used on distant PatientFeedProcessingService !", exception.getMessage());
}
}
......@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.fail;
public class TestProcessingService implements ProcessingService {
public static final String UUID = "TEST-uuid1";
public static final String UUID_dupli="TEST-uuid2";
public static final Patient PATIENT = new Patient();
......@@ -119,6 +120,24 @@ public class TestProcessingService implements ProcessingService {
return getUpdateResponseWithoutErrorInFailureReport();
case UPDATE_NO_ERROR_DESCRIPTION:
return getUpdateResponseWithFailedReport(null);
/*---------------------MERGE METHODS CASES------------------------------*/
case MERGE_CORRECT:
return getMergeCorrectProcessResponse();
case MERGE_MISSING_REPORT:
return getMergeResponseMissingReport();
case MERGE_FAILED_REPORT:
return getMergeResponseWithFailedReport("MyError");
case MERGE_MULTIPLE_OUTPUT:
return getMergeResponseWithMultipleOutputs();
case MERGE_UNEXPECTED_STATUS:
return getMergeResponseWithUnexpectedReportStatus();
case MERGE_NO_REPORTS_IN_REPORT:
return getMergeResponseWithoutReports();
case MERGE_NO_ERROR_IN_FAILURE_REPORT:
return getMergeResponseWithoutErrorInFailureReport();
case MERGE_NO_ERROR_DESCRIPTION:
return getMergeResponseWithFailedReport(null);
default:
return null;
......@@ -605,6 +624,155 @@ public class TestProcessingService implements ProcessingService {
return processResponse;
}
/*-----------------------------------getMerge methods-------------------------------------*/
/**
* Return a correct {@link ProcessResponse} to a feed Process Request
* @return a correct {@link ProcessResponse}
*/
private ProcessResponse getMergeCorrectProcessResponse(){
ProcessResponse processResponse = new ProcessResponse();
TAR report = new TAR();
report.setResult(TestResultType.SUCCESS);
processResponse.setReport(report);
try {
processResponse.getOutput().add(new MapperObjectToAnyContent().getAnyContent(UUID_OUTPUT_NAME, UUID));
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);
}
return processResponse;
}
/**
* Return a {@link ProcessResponse} with no Report
* @return a {@link ProcessResponse} with no report
*/
private ProcessResponse getMergeResponseMissingReport(){
ProcessResponse processResponse = new ProcessResponse();
try {
processResponse.getOutput().add(new MapperObjectToAnyContent().getAnyContent(UUID_OUTPUT_NAME, UUID));
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);
}
return processResponse;
}
/**
* Return a valid {@link ProcessResponse} for a failed feed request.
* @param errorDescription Value of the Error's description for the report
* @return the failed {@link ProcessResponse}
*/
private ProcessResponse getMergeResponseWithFailedReport(String errorDescription){
com.gitb.tr.ObjectFactory objectFactory = new ObjectFactory();
ProcessResponse processResponse = new ProcessResponse();
TAR report = new TAR();
report.setResult(TestResultType.FAILURE);
report.setReports(new TestAssertionGroupReportsType());
BAR itemContent = new BAR();
itemContent.setDescription(errorDescription);
report.getReports().getInfoOrWarningOrError().add(objectFactory.createTestAssertionGroupReportsTypeError(itemContent));
report.setCounters(new ValidationCounters());
report.getCounters().setNrOfAssertions(BigInteger.valueOf(0));
report.getCounters().setNrOfWarnings(BigInteger.valueOf(0));
report.getCounters().setNrOfErrors(BigInteger.valueOf(1));
report.setContext(new AnyContent());
report.getContext().getItem().add(new AnyContent());
processResponse.setReport(report);
try {
processResponse.getOutput().add(new MapperObjectToAnyContent().getAnyContent(UUID_OUTPUT_NAME, UUID));
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);
}
return processResponse;
}
/**
* Returns a {@link ProcessResponse} with multiple outputs
* @return a {@link ProcessResponse} with multiple outputs
*/
private ProcessResponse getMergeResponseWithMultipleOutputs(){
ProcessResponse processResponse = new ProcessResponse();
TAR report = new TAR();
report.setResult(TestResultType.SUCCESS);
processResponse.setReport(report);
try {
AnyContent anyContent = new MapperObjectToAnyContent().getAnyContent(UUID_OUTPUT_NAME, UUID);
processResponse.getOutput().add(anyContent);
processResponse.getOutput().add(anyContent);
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);
}
return processResponse;
}
/**
* Returns a {@link ProcessResponse} with unexpected Report Status, id not SUCCESS or FAILURE.
* @return a {@link ProcessResponse} with unexpected Report Status
*/
private ProcessResponse getMergeResponseWithUnexpectedReportStatus(){
ProcessResponse processResponse = new ProcessResponse();
TAR report = new TAR();
report.setResult(TestResultType.WARNING);
processResponse.setReport(report);
try {
processResponse.getOutput().add(new MapperObjectToAnyContent().getAnyContent(UUID_OUTPUT_NAME, UUID));
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);
}
return processResponse;
}
/**
* Returns a {@link ProcessResponse} without Error reports in the TAR report.
* @return a {@link ProcessResponse} without Error Reports
*/
private ProcessResponse getMergeResponseWithoutReports(){
ProcessResponse processResponse = new ProcessResponse();
TAR report = new TAR();
report.setResult(TestResultType.FAILURE);
report.setContext(new AnyContent());
report.getContext().getItem().add(new AnyContent());
processResponse.setReport(report);
try {
processResponse.getOutput().add(new MapperObjectToAnyContent().getAnyContent(UUID_OUTPUT_NAME, UUID));
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);
}
return processResponse;
}
/**
* Returns a {@link ProcessResponse} without any Error thought with status FAILURE.
* @return
*/
private ProcessResponse getMergeResponseWithoutErrorInFailureReport(){
ProcessResponse processResponse = new ProcessResponse();
TAR report = new TAR();
report.setResult(TestResultType.FAILURE);
report.setReports(new TestAssertionGroupReportsType());
report.setCounters(new ValidationCounters());
report.getCounters().setNrOfAssertions(BigInteger.valueOf(0));
report.getCounters().setNrOfWarnings(BigInteger.valueOf(0));
report.getCounters().setNrOfErrors(BigInteger.valueOf(0));
report.setContext(new AnyContent());
report.getContext().getItem().add(new AnyContent());
processResponse.setReport(report);
try {
processResponse.getOutput().add(new MapperObjectToAnyContent().getAnyContent(UUID_OUTPUT_NAME, UUID));
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);
}
return processResponse;
}
/**
* {@inheritDoc}
*/
......@@ -653,7 +821,15 @@ public class TestProcessingService implements ProcessingService {
UPDATE_UNEXPECTED_STATUS,
UPDATE_NO_REPORTS_IN_REPORT,
UPDATE_NO_ERROR_IN_FAILURE_REPORT,
UPDATE_NO_ERROR_DESCRIPTION
UPDATE_NO_ERROR_DESCRIPTION,
MERGE_CORRECT,
MERGE_MISSING_REPORT,
MERGE_FAILED_REPORT,
MERGE_MULTIPLE_OUTPUT,
MERGE_UNEXPECTED_STATUS,
MERGE_NO_REPORTS_IN_REPORT,
MERGE_NO_ERROR_IN_FAILURE_REPORT,
MERGE_NO_ERROR_DESCRIPTION;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment