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 23ef28a commit 14eaf20
Showing 1 changed file with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import it.finanze.sanita.fse2.ms.gtw.statusmanager.dto.ConfigItemDTO;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.enums.ConfigItemTypeEnum;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.service.IConfigSRV;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.utility.ProfileUtility;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -40,27 +42,22 @@ public class ConfigSRV implements IConfigSRV {
@Autowired
private IConfigClient client;

@Autowired
private ProfileUtility profiles;

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

public ConfigSRV() {
this.props = new HashMap<>();
}

@EventListener(ApplicationStartedEvent.class)
void initialize() {
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");

@PostConstruct
public void postConstruct() {
if(!profiles.isTestProfile()) {
init();
} else {
log.info("Skipping gtw-config initialization due to test profile");
}
integrity();
}

@Override
Expand Down Expand Up @@ -125,4 +122,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();
}
}

0 comments on commit 14eaf20

Please sign in to comment.