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 7926c2d commit f44710d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.finanze.sanita.fse2.ms.edsclient.dto.ConfigItemDTO;
import it.finanze.sanita.fse2.ms.edsclient.enums.ConfigItemTypeEnum;
import it.finanze.sanita.fse2.ms.edsclient.service.IConfigSRV;
import it.finanze.sanita.fse2.ms.edsclient.utility.ProfileUtility;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,6 +29,9 @@ public class ConfigSRV implements IConfigSRV {
@Autowired
private IConfigClient client;

@Autowired
private ProfileUtility profiles;

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

public ConfigSRV() {
Expand All @@ -36,19 +40,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<ConfigItemDTO.ConfigDataItemDTO> 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");
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() {
}
}

private void init() {
for(ConfigItemTypeEnum en : ConfigItemTypeEnum.priority()) {
log.info("[GTW-CFG] Retrieving {} properties ...", en.name());
ConfigItemDTO items = client.getConfigurationItems(en);
List<ConfigItemDTO.ConfigDataItemDTO> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.*;

import java.util.UUID;

import it.finanze.sanita.fse2.ms.edsclient.service.impl.ConfigSRV;
import org.junit.jupiter.api.BeforeEach;
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.context.annotation.ComponentScan;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand Down Expand Up @@ -58,6 +59,9 @@ class EdsClientTest extends AbstractTest {
@SpyBean
private RestTemplate restTemplate;

@MockBean
private ConfigSRV config;

private static final String TEST_WORKFLOW_INSTANCE_ID = UUID.randomUUID().toString();
IniEdsInvocationETY invocation;

Expand All @@ -72,6 +76,7 @@ void publishSuccessTest() {
assertNotNull(invocation, "Invocation must exist to test the client call");
mockEdsClient(ProcessorOperationEnum.PUBLISH, HttpStatus.OK);

when(config.isRemoveMetadataEnable()).thenReturn(false);
final ResponseEntity<EdsResponseDTO> response = callPublishEdsClient(TEST_WORKFLOW_INSTANCE_ID);

assertNotNull(response, "A response should be returned");
Expand Down Expand Up @@ -159,6 +164,8 @@ void replaceSuccessTest() {
JsonUtility.jsonToObject(req, PublicationMetadataReqDTO.class);
mockEdsClient(ProcessorOperationEnum.REPLACE, HttpStatus.OK);

when(config.isRemoveMetadataEnable()).thenReturn(false);

final ResponseEntity<EdsResponseDTO> response = callReplaceEdsClient(docId, TEST_WORKFLOW_INSTANCE_ID);

assertNotNull(response, "A response should be returned");
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data.mongodb.schema-name=FSE_GTW
# Client Config
#######################################
eds-ingestion.url.host=http://localhost:9087
gtw-config.url.host=http://localhost:8018

####### LOGGING OUTPUT FORMAT ############
# Must be one of console, json
Expand Down

0 comments on commit f44710d

Please sign in to comment.