From 5eb5697de4058f2e492d1c1f3d6b5da224b4f9af Mon Sep 17 00:00:00 2001 From: Giuseppe Baittiner Date: Tue, 19 Dec 2023 09:07:12 +0100 Subject: [PATCH] fix: tests --- .../audit/filters/RequestBodyFilter.java | 4 +- .../dispatcher/service/impl/ConfigSRV.java | 36 ++++--- .../fse2/ms/gtw/dispatcher/DeleteTest.java | 46 ++++---- .../ms/gtw/dispatcher/PublicationTest.java | 101 +++++++----------- .../fse2/ms/gtw/dispatcher/ReplaceTest.java | 87 +++++++-------- .../dispatcher/TransactionInspectTest.java | 34 ++++-- .../fse2/ms/gtw/dispatcher/UpdateTest.java | 60 ++++++----- .../ms/gtw/dispatcher/ValidationTest.java | 71 ++++++------ 8 files changed, 219 insertions(+), 220 deletions(-) diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/config/audit/filters/RequestBodyFilter.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/config/audit/filters/RequestBodyFilter.java index 6340083c..bc7646ca 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/config/audit/filters/RequestBodyFilter.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/config/audit/filters/RequestBodyFilter.java @@ -13,7 +13,7 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.audit.AuditFilter; import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.AuditETY; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.impl.ConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -25,7 +25,7 @@ public class RequestBodyFilter implements AuditFilter { @Autowired - private ConfigSRV config; + private IConfigSRV config; @Override public boolean match(HttpServletRequest req) { diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java index 0b5f2aed..d4050dad 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java @@ -4,6 +4,7 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ConfigItemDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ConfigItemTypeEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.ProfileUtility; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +17,6 @@ import java.util.Map; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.*; -import static it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ConfigItemDTO.ConfigDataItemDTO; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ConfigItemTypeEnum.DISPATCHER; @Slf4j @@ -27,6 +27,8 @@ public class ConfigSRV implements IConfigSRV { @Autowired private IConfigClient client; + @Autowired + private ProfileUtility profiles; private final Map> props; @@ -37,19 +39,11 @@ public ConfigSRV() { @PostConstruct public void postConstruct() { - for(ConfigItemTypeEnum en : ConfigItemTypeEnum.priority()) { - log.info("[GTW-CFG] Retrieving {} properties ...", en.name()); - ConfigItemDTO items = client.getConfigurationItems(en); - List opts = items.getConfigurationItems(); - for(ConfigDataItemDTO opt : opts) { - opt.getItems().forEach((key, value) -> { - log.info("[GTW-CFG] Property {} is set as {}", key, value); - props.put(key, Pair.of(new Date().getTime(), value)); - }); - } - if(opts.isEmpty()) log.info("[GTW-CFG] No props were found"); + if(!profiles.isTestProfile()) { + init(); + } else { + log.info("Skipping gtw-config initialization due to test profile"); } - integrity(); } @Override @@ -130,4 +124,20 @@ private void integrity() { if(!props.containsKey(prop)) throw new IllegalStateException(err.replace("{}", prop)); } } + + private void init() { + for(ConfigItemTypeEnum en : ConfigItemTypeEnum.priority()) { + log.info("[GTW-CFG] Retrieving {} properties ...", en.name()); + ConfigItemDTO items = client.getConfigurationItems(en); + List opts = items.getConfigurationItems(); + for(ConfigItemDTO.ConfigDataItemDTO opt : opts) { + opt.getItems().forEach((key, value) -> { + log.info("[GTW-CFG] Property {} is set as {}", key, value); + props.put(key, Pair.of(new Date().getTime(), value)); + }); + } + if(opts.isEmpty()) log.info("[GTW-CFG] No props were found"); + } + integrity(); + } } diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/DeleteTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/DeleteTest.java index dff0597f..3cd322e7 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/DeleteTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/DeleteTest.java @@ -11,44 +11,42 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; - +import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.EdsResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniReferenceResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniTraceResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import org.springframework.test.context.ActiveProfiles; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.EdsResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniReferenceResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniTraceResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; -import lombok.extern.slf4j.Slf4j; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; @Slf4j @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles(Constants.Profile.TEST) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class DeleteTest extends AbstractTest { @Autowired @@ -57,6 +55,14 @@ class DeleteTest extends AbstractTest { @SpyBean RestTemplate restTemplate; + @MockBean + IConfigSRV config; + + @BeforeAll + void init() { + when(config.isAuditEnable()).thenReturn(true); + } + @Test @DisplayName("Delete of a document") void givenAnIdentifier_shouldExecuteDeletion() { diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/PublicationTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/PublicationTest.java index 5b2bf141..74205c77 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/PublicationTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/PublicationTest.java @@ -11,82 +11,56 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeFalse; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Date; -import java.util.UUID; - -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.bson.Document; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; - import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IValidatorClient; import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.MicroservicesURLCFG; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.JWTPayloadDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.JWTTokenDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ResourceDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ValidationDataDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ValidationInfoDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.*; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.PublicationCreationReqDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.ValidationCDAReqDTO; 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.dto.response.client.TransformResDTO; -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.EventCodeEnum; -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.RawValidationEnum; -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.enums.*; import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.ValidatedDocumentsETY; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.facade.ICdaFacadeSRV; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.FileUtility; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.bson.Document; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.http.*; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +import java.io.File; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Date; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; @Slf4j @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles(Constants.Profile.TEST) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class PublicationTest extends AbstractTest { @SpyBean @@ -105,9 +79,16 @@ class PublicationTest extends AbstractTest { private MicroservicesURLCFG msCfg; @Autowired - private MongoTemplate mongo; + private MongoTemplate mongo; + + @MockBean + private IConfigSRV config; + + @BeforeAll + void init() { + when(config.isAuditEnable()).thenReturn(true); + } - @BeforeEach void createCollection(){ mongo.dropCollection(ValidatedDocumentsETY.class); diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java index 8bbce5ba..4ae52e3f 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ReplaceTest.java @@ -11,23 +11,30 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; - -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - +import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IIniClient; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IValidatorClient; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ValidationInfoDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.PublicationCreationReqDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.PublicationUpdateReqDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniReferenceResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniTraceResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.PublicationResDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.client.TransformResDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.client.ValidationResDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.*; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.IniEdsInvocationETY; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.ValidatedDocumentsETY; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.impl.ConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.FileUtility; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; +import lombok.extern.slf4j.Slf4j; import org.bson.Document; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentMatchers; @@ -41,49 +48,27 @@ import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import org.springframework.test.context.ActiveProfiles; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IIniClient; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IValidatorClient; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ValidationInfoDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.PublicationCreationReqDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.PublicationUpdateReqDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniReferenceResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniTraceResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.PublicationResDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.client.TransformResDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.client.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.EventCodeEnum; -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.RawValidationEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.TipoDocAltoLivEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.IniEdsInvocationETY; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.ValidatedDocumentsETY; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.FileUtility; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; -import lombok.extern.slf4j.Slf4j; +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.when; @Slf4j @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles(Constants.Profile.TEST) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class ReplaceTest extends AbstractTest { @Autowired @@ -101,6 +86,14 @@ class ReplaceTest extends AbstractTest { @SpyBean private IIniClient iniClient; + @MockBean + private ConfigSRV config; + + @BeforeAll + void init() { + when(config.isAuditEnable()).thenReturn(true); + } + @BeforeEach void setup() { mongoTemplate.dropCollection(IniEdsInvocationETY.class); diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/TransactionInspectTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/TransactionInspectTest.java index f67efa07..1cbd6f6e 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/TransactionInspectTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/TransactionInspectTest.java @@ -11,14 +11,15 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - +import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IStatusCheckClient; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.TransactionInspectResDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.ITransactionInspectSRV; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -30,15 +31,17 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IStatusCheckClient; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.TransactionInspectResDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.ITransactionInspectSRV; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @AutoConfigureMockMvc @ActiveProfiles(Constants.Profile.TEST) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TransactionInspectTest { @Autowired @@ -52,7 +55,16 @@ public class TransactionInspectTest { @MockBean private ITransactionInspectSRV transactionInspectSRV; - + + @MockBean + private IConfigSRV config; + + + @BeforeAll + void init() { + when(config.isAuditEnable()).thenReturn(true); + } + @Test @DisplayName("Call Search Event By wid Test") void callSearchEventByWorkflowIdTest() throws Exception { 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 741d0a2f..8cf01f68 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 @@ -11,30 +11,32 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; - -import java.util.Collections; -import java.util.Date; - +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.PublicationMetadataReqDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.EdsResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.GetMergedMetadatiDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniTraceResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.impl.ConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; @@ -44,24 +46,19 @@ import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.Gson; +import java.util.Collections; +import java.util.Date; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.PublicationMetadataReqDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.EdsResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.GetMergedMetadatiDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.IniTraceResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ResponseDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; -import lombok.extern.slf4j.Slf4j; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; @Slf4j @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc @ActiveProfiles(Constants.Profile.TEST) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class UpdateTest extends AbstractTest { @Autowired @@ -75,6 +72,15 @@ class UpdateTest extends AbstractTest { private static final String TEST_REQUEST_BODY = "{\"tipologiaStruttura\":\"Ospedale\",\"attiCliniciRegoleAccesso\":[\"P99\"],\"tipoDocumentoLivAlto\":\"WOR\",\"assettoOrganizzativo\":\"AD_PSC001\",\"dataInizioPrestazione\":\"string\",\"dataFinePrestazione\":\"string\",\"conservazioneANorma\":\"string\",\"tipoAttivitaClinica\":\"PHR\",\"identificativoSottomissione\":\"string\"}"; + @MockBean + private ConfigSRV config; + + + @BeforeAll + void init() { + when(config.isAuditEnable()).thenReturn(true); + } + @Test @DisplayName("Update of a document") void givenAnInvalidValueShouldThrowValidationException() throws Exception { diff --git a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ValidationTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ValidationTest.java index bc42f960..173cf11b 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ValidationTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/ValidationTest.java @@ -11,32 +11,24 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Map; - +import com.fasterxml.jackson.core.JsonProcessingException; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IValidatorClient; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ValidationInfoDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.ValidationCDAReqDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ValidationResDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.*; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.repository.entity.ValidatedDocumentsETY; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.ICdaSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.FileUtility; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; +import lombok.extern.slf4j.Slf4j; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.parser.Parser; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.*; import org.junit.jupiter.api.TestInstance.Lifecycle; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -46,25 +38,15 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.web.client.HttpClientErrorException; -import com.fasterxml.jackson.core.JsonProcessingException; +import java.io.File; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IValidatorClient; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ValidationInfoDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.ValidationCDAReqDTO; -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.EventTypeEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.HealthDataFormatEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.InjectionModeEnum; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RawValidationEnum; -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.repository.entity.ValidatedDocumentsETY; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.ICdaSRV; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.FileUtility; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; -import lombok.extern.slf4j.Slf4j; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; @Slf4j @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -106,9 +88,18 @@ class ValidationTest extends AbstractTest { @MockBean IValidatorClient validatorClient; + @Autowired public MongoTemplate mongo; + @MockBean + private IConfigSRV config; + + @BeforeAll + void init() { + when(config.isAuditEnable()).thenReturn(true); + } + @BeforeEach void createCollection(){ mongo.dropCollection(ValidatedDocumentsETY.class);