Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gb-cic committed Dec 18, 2023
1 parent b6bc901 commit e5a7bc7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,9 @@ public class ConfigSRV implements IConfigSRV {

@Autowired
private IConfigClient client;

@Autowired
private ProfileUtility profiles;

private final Map<String, Pair<Long, String>> props;

Expand All @@ -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<ConfigDataItemDTO> 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
Expand Down Expand Up @@ -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<ConfigDataItemDTO> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +68,8 @@ class ExecutorTest {
private IExecutorRepo repository;
@Autowired
private EDSSchemaDB db;
@MockBean
private ConfigSRV config;

@BeforeAll
public void init() { resetDB(); }
Expand All @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit e5a7bc7

Please sign in to comment.