diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/AbstractTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/AbstractTest.java index 6d355e63..b15c792f 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/AbstractTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/AbstractTest.java @@ -12,6 +12,7 @@ package it.finanze.sanita.fse2.ms.gtw.dispatcher; +import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum.*; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; @@ -19,6 +20,7 @@ import java.util.HashMap; import java.util.Map; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.*; import org.jsoup.Jsoup; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; @@ -43,15 +45,6 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ErrorResponseDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.PublicationResDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ValidationResDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ActivityEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.AttivitaClinicaEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.HealthDataFormatEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.HealthcareFacilityEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.InjectionModeEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.PracticeSettingCodeEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RestExecutionResultEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.TipoDocAltoLivEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.CfUtility; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.FileUtility; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.JsonUtility; @@ -110,7 +103,7 @@ public String getFilename(){ if (fromGovway) { headers.set(Constants.Headers.JWT_GOVWAY_HEADER, generateJwtGovwayPayload(fileByte)); } else { - headers.set(Constants.Headers.JWT_HEADER, generateJwt(fileByte, isValidMultipart, EventTypeEnum.VALIDATION)); + headers.set(Constants.Headers.JWT_HEADER, generateJwt(fileByte, isValidMultipart, VALIDATION)); } } String urlValidation = getBaseUrl() + "/v1/documents/validation"; @@ -207,14 +200,21 @@ private String getPersonIdFromCda(final String cda) { } protected String generateJwtPayload(final String documentHash, final String personId, final String subject, final String docType, EventTypeEnum eventType) { - String action = "CREATE"; - String purposeOfUse = "TREATMENT"; - if (EventTypeEnum.UPDATE.equals(eventType)) { - action = "UPDATE"; - purposeOfUse = "UPDATE"; - } else if (EventTypeEnum.DELETE.equals(eventType)) { - action = "DELETE"; - purposeOfUse = "UPDATE"; + String action = ActionEnum.CREATE.name(); + String purposeOfUse = PurposeOfUseEnum.TREATMENT.name(); + if (UPDATE.equals(eventType)) { + action = ActionEnum.UPDATE.name(); + purposeOfUse = PurposeOfUseEnum.UPDATE.name(); + } else if (DELETE.equals(eventType)) { + action = ActionEnum.DELETE.name(); + purposeOfUse = PurposeOfUseEnum.UPDATE.name(); + } + else if (REPLACE.equals(eventType)){ + action = ActionEnum.UPDATE.name(); + purposeOfUse = PurposeOfUseEnum.UPDATE.name(); + } + else if(VALIDATION.equals(eventType)){ + } String applicationId = "ApplicationId"; diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/UpdateTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/UpdateTest.java index 8cf01f68..243fa72a 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/UpdateTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/UpdateTest.java @@ -31,6 +31,7 @@ import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -67,6 +68,10 @@ class UpdateTest extends AbstractTest { @Autowired MockMvc mvc; + @SpyBean + @Qualifier("restTemplateIni") + RestTemplate restTemplateIni; + @SpyBean RestTemplate restTemplate; @@ -147,18 +152,18 @@ void mockIniClient(final HttpStatus status, boolean esito) { if (status.is2xxSuccessful() && esito) { response.setMarshallResponse("response"); response.setErrorMessage(null); - Mockito.doReturn(new ResponseEntity<>(response, status)).when(restTemplate).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); + Mockito.doReturn(new ResponseEntity<>(response, status)).when(restTemplateIni).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); } else if (status.equals(HttpStatus.NOT_FOUND) && !esito) { response.setMarshallResponse(null); response.setErrorMessage("Record not found"); - Mockito.doReturn(new ResponseEntity<>(response, HttpStatus.OK)).when(restTemplate).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); + Mockito.doReturn(new ResponseEntity<>(response, HttpStatus.OK)).when(restTemplateIni).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); } else if (status.equals(HttpStatus.BAD_REQUEST) && !esito) { response.setErrorMessage("Generic error from INI"); - Mockito.doReturn(new ResponseEntity<>(response, HttpStatus.OK)).when(restTemplate).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); + Mockito.doReturn(new ResponseEntity<>(response, HttpStatus.OK)).when(restTemplateIni).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); } else if (status.is4xxClientError()) { - Mockito.doThrow(new RestClientException("")).when(restTemplate).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); + Mockito.doThrow(new RestClientException("")).when(restTemplateIni).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(GetMergedMetadatiDTO.class)); } else { - Mockito.doThrow(new BusinessException("")).when(restTemplate).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(IniTraceResponseDTO.class)); + Mockito.doThrow(new BusinessException("")).when(restTemplateIni).exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), ArgumentMatchers.eq(IniTraceResponseDTO.class)); } } diff --git a/src/test/resources/Files/attachment/CDA_ATTACHMENT.pdf b/src/test/resources/Files/attachment/CDA_ATTACHMENT.pdf index 4c6255f9..59893088 100644 Binary files a/src/test/resources/Files/attachment/CDA_ATTACHMENT.pdf and b/src/test/resources/Files/attachment/CDA_ATTACHMENT.pdf differ diff --git a/src/test/resources/Files/attachment/pdf_msg_SATLED_LED_Lettera_di_Dimissione.pdf b/src/test/resources/Files/attachment/pdf_msg_SATLED_LED_Lettera_di_Dimissione.pdf index 4c6255f9..6d870caf 100644 Binary files a/src/test/resources/Files/attachment/pdf_msg_SATLED_LED_Lettera_di_Dimissione.pdf and b/src/test/resources/Files/attachment/pdf_msg_SATLED_LED_Lettera_di_Dimissione.pdf differ