diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/DockerSetup.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/DockerSetup.java index c8ccf3a..e6d4a37 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/DockerSetup.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/DockerSetup.java @@ -1,19 +1,18 @@ package it.finanze.sanita.fse2.ms.gtw.rulesmanager.config; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.event.ApplicationStartedEvent; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.context.event.EventListener; - import it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.eds.changeset.impl.EngineCFG; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.eds.changeset.impl.FhirStructuresCFG; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.exceptions.eds.EdsDbException; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.repository.IExecutorRepo; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.scheduler.executors.impl.EnginesExecutor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.context.event.EventListener; -@Profile(value = Constants.Profile.DOCKER) +@Profile(value = Constants.Profile.DEV) @Configuration @Slf4j public class DockerSetup { diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.java index 46e9bae..2a652e3 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.java @@ -5,6 +5,7 @@ import it.finanze.sanita.fse2.ms.gtw.rulesmanager.dto.ConfigItemDTO.ConfigDataItemDTO; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.enums.ConfigItemTypeEnum; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.service.IConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.rulesmanager.utility.ProfileUtility; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +28,9 @@ public class ConfigSRV implements IConfigSRV { @Autowired private IConfigClient client; + + @Autowired + private ProfileUtility profiles; private final Map> props; @@ -37,19 +41,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 @@ -82,4 +78,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(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/rulesmanager/eds/executors/ExecutorTest.java b/src/test/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/eds/executors/ExecutorTest.java index c5065f6..359fa04 100644 --- a/src/test/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/eds/executors/ExecutorTest.java +++ b/src/test/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/eds/executors/ExecutorTest.java @@ -21,6 +21,7 @@ import it.finanze.sanita.fse2.ms.gtw.rulesmanager.exceptions.eds.EdsClientException; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.mock.MockSchemaExecutor; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.repository.IExecutorRepo; +import it.finanze.sanita.fse2.ms.gtw.rulesmanager.service.impl.ConfigSRV; import lombok.extern.slf4j.Slf4j; import org.bson.types.ObjectId; import org.junit.jupiter.api.AfterEach; @@ -67,6 +68,8 @@ class ExecutorTest { private IExecutorRepo repository; @Autowired private EDSSchemaDB db; + @MockBean + private ConfigSRV config; @BeforeAll public void init() { resetDB(); } @@ -81,6 +84,7 @@ public void reset() { void execute() { // Mock an executor that simply reset doReturn(FAKE_STEPS).when(executor).getSteps(); + when(config.isControlLogPersistenceEnable()).thenReturn(true); assertEquals(OK, executor.execute()); // Mock a runtime error then call real method after test doThrow(new RuntimeException("Test error")).doCallRealMethod().when(executor).startup(any(String[].class)); @@ -94,6 +98,7 @@ void execute() { void recovery() { // Mock an executor that simply reset doReturn(FAKE_STEPS).when(executor).getRecoverySteps(); + when(config.isControlLogPersistenceEnable()).thenReturn(true); assertEquals(OK, executor.recovery()); // Mock a runtime error then call real method after test doThrow(new RuntimeException("Test error")).doCallRealMethod().when(executor).startup(any(String[].class));