Commit 4d708457 authored by Franck Desaize's avatar Franck Desaize
Browse files

PATREG-162/125

parent 80db0b07
Pipeline #261772 failed with stages
in 20 minutes and 37 seconds
......@@ -76,7 +76,7 @@ public class PatientFeedClient implements PatientFeedService {
* Extract the UUID from the ProcessResponse received from the remote ProcessingService.
* @param processResponse : response received.
* @return literal value of the UUID assigned to the fed patient by the remote Repository.
* @throws PatientFeedProcessResponseException : if the ProcesssResponse is not valid for a PatientFeed request.
* @throws PatientFeedProcessResponseException : if the ProcessResponse is not valid for a PatientFeed request.
* @throws PatientFeedException : if the Patient Feed raised an exception in the remote Repository.
*/
private String extractUUIDFromProcessResponse(ProcessResponse processResponse) throws PatientFeedProcessResponseException, PatientFeedException{
......@@ -103,7 +103,7 @@ public class PatientFeedClient implements PatientFeedService {
* Extract the UUID from the ProcessResponse.output received from the remote ProcessingService.
* @param outputs : list of received outputs.
* @return literal value of the UUID assigned to the fed patient by the remote Repository.
* @throws PatientFeedProcessResponseException : if the ProcesssResponse.output is not valid for a PatientFeed request.
* @throws PatientFeedProcessResponseException : if the ProcessResponse.output is not valid for a PatientFeed request.
*/
private String extractUUIDFromOutputs(List<AnyContent> outputs) throws PatientFeedProcessResponseException{
if (outputs.size() == 1){
......
......@@ -2,7 +2,6 @@ package net.ihe.gazelle.app.patientregistryapi.application;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
/**
......@@ -14,8 +13,8 @@ public interface PatientCrossReferenceSearch {
* retrieve the patient alias corresponding to the requested
*
* @param sourceIdentifier identifier of the reference patient
* @return the list of patient aliases matching
* @throws SearchException if an error happens during the search processing.
* @return a patient aliases that match the patient with sourceIdentifier
* @throws SearchCrossReferenceException if an error happens during the search processing.
*/
PatientAliases search(EntityIdentifier sourceIdentifier) throws SearchException;
PatientAliases search(EntityIdentifier sourceIdentifier) throws SearchCrossReferenceException;
}
package net.ihe.gazelle.app.patientregistryapi.application;
/**
* Exception to be thrown if a X-ref cannot be searched.
*/
public class SearchCrossReferenceException extends Exception {
/**
* Constructs a new exception with {@code null} as its detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*/
public SearchCrossReferenceException() {
super();
}
/**
* Constructs a new exception with the specified detail message. The
* cause is not initialized, and may subsequently be initialized by
* a call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public SearchCrossReferenceException(String message) {
super(message);
}
/**
* Constructs a new exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public SearchCrossReferenceException(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs a new exception with the specified cause and a detail
* message of {@code (cause==null ? null : cause.toString())} (which
* typically contains the class and detail message of {@code cause}).
* This constructor is useful for exceptions that are little more than
* wrappers for other throwables (for example, {@link
* java.security.PrivilegedActionException}).
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public SearchCrossReferenceException(Throwable cause) {
super(cause);
}
/**
* Constructs a new exception with the specified detail message,
* cause, suppression enabled or disabled, and writable stack
* trace enabled or disabled.
*
* @param message the detail message.
* @param cause the cause. (A {@code null} value is permitted,
* and indicates that the cause is nonexistent or unknown.)
* @param enableSuppression whether or not suppression is enabled
* or disabled
* @param writableStackTrace whether or not the stack trace should
* be writable
* @since 1.7
*/
public SearchCrossReferenceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
package net.ihe.gazelle.app.patientregistryapi.application;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
class SearchCrossReferenceExceptionTest {
/**
* Dummy Test for coverage
*
* @throws SearchCrossReferenceException testException
*/
@Test
void generateException() {
assertThrows(SearchCrossReferenceException.class, () -> {
throw new SearchCrossReferenceException("Test");
});
}
/**
* Dummy Test for coverage
*
* @throws SearchCrossReferenceException testException
*/
@Test
void generateException1() {
assertThrows(SearchCrossReferenceException.class, () -> {
throw new SearchCrossReferenceException("Test", new IllegalArgumentException("test"));
});
}
/**
* Dummy Test for coverage
*
* @throws SearchCrossReferenceException testException
*/
@Test
void generateException2() {
assertThrows(SearchCrossReferenceException.class, () -> {
throw new SearchCrossReferenceException(new IllegalArgumentException("test"));
});
}
/**
* Dummy Test for coverage
*
* @throws SearchCrossReferenceException testException
*/
@Test
void generateException4() {
assertThrows(SearchCrossReferenceException.class, () -> {
throw new SearchCrossReferenceException("Test", new IllegalArgumentException("test"), false, true);
});
}
/**
* Dummy Test for coverage
*
* @throws SearchCrossReferenceException testException
*/
@Test
void generateException3() {
assertThrows(SearchCrossReferenceException.class, () -> {
throw new SearchCrossReferenceException();
});
}
}
\ No newline at end of file
......@@ -7,13 +7,13 @@ import com.gitb.tr.TAR;
import com.gitb.tr.TestResultType;
import net.ihe.gazelle.app.patientregistryapi.adapter.ws.CrossReferenceProcessingWebServiceConstants;
import net.ihe.gazelle.app.patientregistryapi.application.PatientCrossReferenceSearch;
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.lib.gitbutils.adapter.GITBAnyContentType;
import net.ihe.gazelle.lib.gitbutils.adapter.MapperAnyContentToObject;
import net.ihe.gazelle.lib.gitbutils.adapter.MapperObjectToAnyContent;
import net.ihe.gazelle.lib.gitbutils.adapter.MappingException;
import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
import javax.inject.Inject;
import java.util.List;
......@@ -59,7 +59,7 @@ public class CrossReferenceSearchProcessingService {
return createPatientSearchProcessResponse(patient);
} catch (MappingException e) {
throw new IllegalArgumentException("Cannot decode Request inputs as SourceIdentifier !", e);
} catch (SearchException e) {
} catch (SearchCrossReferenceException e) {
return ProcessResponseWithReportCreator.createFailedProcessResponse(e, searchParameter.get(0));
}
}
......@@ -73,7 +73,7 @@ public class CrossReferenceSearchProcessingService {
* @param xRefPatient : List of {@link PatientAliases} returned by the search service.
* @return the process response to return to the WebService
*/
private ProcessResponse createPatientSearchProcessResponse(PatientAliases xRefPatient) throws SearchException {
private ProcessResponse createPatientSearchProcessResponse(PatientAliases xRefPatient) throws SearchCrossReferenceException {
AnyContent patientAliasesAnyContent;
ProcessResponse processResponse = new ProcessResponse();
if (xRefPatient == null) {
......@@ -89,7 +89,7 @@ public class CrossReferenceSearchProcessingService {
patientAliasesAnyContent.setType(GITBAnyContentType.OBJECT.getGitbType());
}
} catch (MappingException e) {
throw new SearchException("Search request response cannot be mapped to GITB AnyContent !", e);
throw new SearchCrossReferenceException("Search request response cannot be mapped to GITB AnyContent !", e);
}
processResponse.getOutput().add(patientAliasesAnyContent);
processResponse.setReport(ProcessResponseWithReportCreator.createReport(TestResultType.SUCCESS));
......
......@@ -6,12 +6,9 @@ import net.ihe.gazelle.app.patientregistryapi.adapter.ws.CrossReferenceProcessin
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.lib.gitbutils.adapter.MapperObjectToAnyContent;
import net.ihe.gazelle.lib.gitbutils.adapter.MappingException;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.validation.constraints.AssertTrue;
import static org.junit.jupiter.api.Assertions.*;
/**
......@@ -35,7 +32,7 @@ class CrossReferenceProcessingServiceTest {
* Test Unsupported Operation getModuleDefinition
*/
@Test
public void getModuleDefinition() {
void getModuleDefinition() {
assertThrows(UnsupportedOperationException.class, () -> crossReferenceProcessingService.getModuleDefinition(new Void()));
}
......@@ -43,7 +40,7 @@ class CrossReferenceProcessingServiceTest {
* Test Unsupported Operation beginTransaction
*/
@Test
public void beginTransaction() {
void beginTransaction() {
assertThrows(UnsupportedOperationException.class, () -> crossReferenceProcessingService.beginTransaction(new BeginTransactionRequest()));
}
......@@ -51,7 +48,7 @@ class CrossReferenceProcessingServiceTest {
* Test Unsupported Operation endTransaction
*/
@Test
public void endTransaction() {
void endTransaction() {
assertThrows(UnsupportedOperationException.class, () -> crossReferenceProcessingService.endTransaction(new BasicRequest()));
}
......@@ -60,7 +57,7 @@ class CrossReferenceProcessingServiceTest {
* Test Processing a patient operation, error case using null ProcessRequest
*/
@Test
public void process_no_ProcessingRequest() {
void process_no_ProcessingRequest() {
assertThrows(IllegalArgumentException.class, () -> crossReferenceProcessingService.process(null));
}
......@@ -68,7 +65,7 @@ class CrossReferenceProcessingServiceTest {
* Test Processing a patient operation, error case using wrong operation in ProcessRequest.
*/
@Test
public void process_Wrong_Operation() {
void process_Wrong_Operation() {
ProcessRequest processRequest = new ProcessRequest();
processRequest.setOperation("Wrong Operation");
......@@ -79,7 +76,7 @@ class CrossReferenceProcessingServiceTest {
* Test Processing a x-Ref Search with mock
*/
@Test
public void process_Patient_Search() {
void process_Patient_Search() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("identifierSystem");
sourceIdentifier.setValue("identifierValue");
......@@ -99,7 +96,7 @@ class CrossReferenceProcessingServiceTest {
* Test on Constructor for coverage
*/
@Test
public void create_a_CrossRefProcessingService() {
void create_a_CrossRefProcessingService() {
CrossReferenceProcessingService crossReferenceProcessingService = new CrossReferenceProcessingService();
if (crossReferenceProcessingService != null) {
......
......@@ -6,17 +6,13 @@ import com.gitb.ps.ProcessResponse;
import com.gitb.tr.BAR;
import com.gitb.tr.TestResultType;
import net.ihe.gazelle.app.patientregistryapi.adapter.ws.CrossReferenceProcessingWebServiceConstants;
import net.ihe.gazelle.app.patientregistryapi.adapter.ws.PatientProcessingWebserviceConstants;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.lib.annotations.Covers;
import net.ihe.gazelle.lib.gitbutils.adapter.MapperObjectToAnyContent;
import net.ihe.gazelle.lib.gitbutils.adapter.MappingException;
import net.ihe.gazelle.lib.searchmodelapi.business.SearchCriteria;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class CrossReferenceSearchProcessingServiceTest {
......@@ -28,13 +24,12 @@ class CrossReferenceSearchProcessingServiceTest {
* Initialize implementations to be tested before each test.
*/
@BeforeEach
public void setUp(){
public void setUp() {
this.patientCrossReferenceSearchMock = new PatientCrossReferenceSearchMock();
this.crossReferenceSearchProcessingService = new CrossReferenceSearchProcessingService(patientCrossReferenceSearchMock);
}
/**
* Test Processing a X-ref search, error case using no input in ProcessRequest
*/
......@@ -44,6 +39,7 @@ class CrossReferenceSearchProcessingServiceTest {
processRequest.setOperation(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_SEARCH_OPERATION);
assertThrows(IllegalArgumentException.class, () -> crossReferenceSearchProcessingService.processPatientCrossReferenceSearch(processRequest));
}
/**
* Test Processing a X-ref search, error case using too much input in ProcessRequest
*/
......@@ -157,7 +153,8 @@ class CrossReferenceSearchProcessingServiceTest {
assertEquals(1, processResponse.getOutput().size(), "Response shall contain a unique output which is the value of the" +
" UUID assigned to the fed patient.");
assertEquals("object", processResponse.getOutput().get(0).getType(), "Returned UUID shall be stored in a string GITB AnyContent");
assertEquals(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_OUTPUT_NAME, processResponse.getOutput().get(0).getName(), "Name of returned GITB AnyContent shall be 'XRefPatient'");
assertEquals(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_OUTPUT_NAME, processResponse.getOutput().get(0).getName(),
"Name of returned GITB AnyContent shall be 'XRefPatient'");
assertEquals(ValueEmbeddingEnumeration.BASE_64, processResponse.getOutput().get(0).getEmbeddingMethod(), "Embedding method of returned " +
"GITB AnyContent shall be 'STRING'");
assertNotNull(processResponse.getReport(), "ProcessResponse.report shall not be null !");
......@@ -165,5 +162,4 @@ class CrossReferenceSearchProcessingServiceTest {
}
}
\ No newline at end of file
package net.ihe.gazelle.app.patientregistryservice.adapter.ws;
import net.ihe.gazelle.app.patientregistryapi.application.PatientCrossReferenceSearch;
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
......@@ -9,7 +10,7 @@ import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
public class PatientCrossReferenceSearchMock implements PatientCrossReferenceSearch {
@Override
public PatientAliases search(EntityIdentifier sourceIdentifier) throws SearchException {
public PatientAliases search(EntityIdentifier sourceIdentifier) throws SearchCrossReferenceException {
if (sourceIdentifier.getSystemIdentifier().equals("identifierSystem")) {
PatientAliases patientAliases = new PatientAliases();
patientAliases.setUuid("123456789");
......@@ -22,7 +23,7 @@ public class PatientCrossReferenceSearchMock implements PatientCrossReferenceSea
} else if (sourceIdentifier.getSystemIdentifier().equals("nullResult")) {
return null;
} else {
throw new SearchException("Test exception");
throw new SearchCrossReferenceException("Test exception");
}
}
......
......@@ -52,6 +52,13 @@
<artifactId>lib.unit-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.28.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -9,6 +9,7 @@ import com.gitb.tr.TAR;
import com.gitb.tr.TestResultType;
import net.ihe.gazelle.app.patientregistryapi.adapter.ws.CrossReferenceProcessingWebServiceConstants;
import net.ihe.gazelle.app.patientregistryapi.application.PatientCrossReferenceSearch;
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.lib.gitbprocessingclient.adapter.GITBClientProcessImpl;
......@@ -45,7 +46,7 @@ public class XRefSearchClient implements PatientCrossReferenceSearch {
}
@Override
public PatientAliases search(EntityIdentifier sourceIdentifier) throws SearchException {
public PatientAliases search(EntityIdentifier sourceIdentifier) throws SearchCrossReferenceException {
ProcessRequest processRequest = new ProcessRequest();
processRequest.setOperation(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_SEARCH_OPERATION);
AnyContent patientToFeedAnyContent = null;
......@@ -57,13 +58,15 @@ public class XRefSearchClient implements PatientCrossReferenceSearch {
ProcessResponse processResponse = processingClient.process(processRequest);
return extractPatientAliasesFromProcessResponse(processResponse);
} catch (MappingException e) {
throw new SearchException("Exception while Mapping with GITB elements !", e);
throw new SearchCrossReferenceException("Exception while Mapping with GITB elements !", e);
} catch (XRefSearchProcessResponseException e) {
throw new SearchException("Invalid Response from distant PatientFeedProcessingService !", e);
throw new SearchCrossReferenceException("Invalid Response from distant CrossReferenceSearchProcessingService !", e);
} catch (UnsupportedOperationException e) {
throw new SearchException("Invalid operation used on distant PatientFeedProcessingService !", e);
throw new SearchCrossReferenceException("Invalid operation used on distant CrossReferenceSearchProcessingService !", e);
} catch (IllegalArgumentException e) {
throw new SearchException("Invalid Request sent to distant PatientFeedProcessingService !", e);
throw new SearchCrossReferenceException("Invalid Request sent to distant CrossReferenceSearchProcessingService !", e);
} catch (SearchException e) {
throw new SearchCrossReferenceException("Invalid Request sent to distant CrossReferenceSearchProcessingService !", e);
}
}
......
package net.ihe.gazelle.app.patientregistryxrefsearchclient.adapter;
import com.gitb.core.AnyContent;
import com.gitb.ps.Void;
import com.gitb.ps.*;
import com.gitb.tr.*;
import com.gitb.tr.ObjectFactory;
import net.ihe.gazelle.app.patientregistryapi.adapter.ws.CrossReferenceProcessingWebServiceConstants;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.app.patientregistryapi.business.PersonName;
import net.ihe.gazelle.lib.gitbutils.adapter.MapperObjectToAnyContent;
import net.ihe.gazelle.lib.gitbutils.adapter.MappingException;
import java.math.BigInteger;
import static net.ihe.gazelle.app.patientregistryapi.adapter.ws.PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME;
import static net.ihe.gazelle.app.patientregistryapi.adapter.ws.PatientProcessingWebserviceConstants.UUID_OUTPUT_NAME;
import static org.junit.jupiter.api.Assertions.fail;
public class ProcessingServiceMock implements ProcessingService {
private ResponseTypes responseToReturn;
/**
* Default constructor for the class. By default, the service returns a valid success answer.
*/
public ProcessingServiceMock() {
responseToReturn = ResponseTypes.CORRECT;
}
/**
* Setter to the responseToReturn property
*
* @param responseToReturn
*/
public void setResponseToReturn(ResponseTypes responseToReturn) {
this.responseToReturn = responseToReturn;
}
@Override
public GetModuleDefinitionResponse getModuleDefinition(Void parameters) {
return null;
}
@Override
public ProcessResponse process(ProcessRequest parameters) {
switch (responseToReturn) {
case CORRECT:
return getCorrectProcessResponse();
case MISSING_REPORT:
return getResponseMissingReport();
case FAILED_REPORT:
return getResponseWithFailedReport("MyError");
case MULTIPLE_OUTPUT:
return getResponseWithMultipleOutputs();
case INVALID_OUTPUT:
return getResponseWithInvalidOutput();
case NULL_RESPONSE:
return null;
case UNEXPECTED_STATUS:
return getResponseWithUnexpectedReportStatus();
case NO_REPORTS_IN_REPORT:
return getResponseWithoutReports();
case NO_ERROR_IN_FAILURE_REPORT:
return getResponseWithoutErrorInFailureReport();
case NO_ERROR_DESCRIPTION:
return getResponseWithFailedReport(null);
case ILLEGAL_ARGUMENT_EXCEPTION:
throw new IllegalArgumentException();
case UNSUPPORTED_OPERATION_EXCEPTION:
throw new UnsupportedOperationException();
default:
return null;
}
}
/**
* Return a correct {@link ProcessResponse} to a X-ref search Request
*
* @return a correct {@link ProcessResponse}
*/
private ProcessResponse getResponseWithoutErrorInFailureReport() {
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(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_OUTPUT_NAME, createPatientAliases()));
} catch (MappingException e){
fail("Unexpected Mapping exception !", e);