Skip to content

Commit

Permalink
fix: sonar code smells (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
jobulcke authored Apr 24, 2024
1 parent 0bf0155 commit 6c53d73
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ldes.client.treenodesupplier.repository.sql;

import ldes.client.treenodesupplier.domain.entities.TreeNodeRecord;
import ldes.client.treenodesupplier.domain.services.TreeNodeRecordComparator;
import ldes.client.treenodesupplier.domain.valueobject.TreeNodeStatus;
import ldes.client.treenodesupplier.repository.TreeNodeRecordRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Service
public class ConfigPipelineInitializer implements PipelineInitializer {
private static final String name = "LDI Orchestrator Spring Config Initializer";
private static final String NAME = "LDI Orchestrator Spring Config Initializer";
private final Logger log = LoggerFactory.getLogger(ConfigPipelineInitializer.class);
private final OrchestratorConfig orchestratorConfig;
private final PipelineService pipelineService;
Expand All @@ -26,15 +26,15 @@ public ConfigPipelineInitializer(OrchestratorConfig orchestratorConfig, Pipeline

@Override
public String name() {
return name;
return NAME;
}

@Override
public List<PipelineConfig> initPipelines() {
if (orchestratorConfig.getPipelines() == null) {
return List.of();
}
log.warn("{} DEPRECATED. Any configs with the same name will be ignored", name);
log.warn("{} DEPRECATED. Any configs with the same name will be ignored", NAME);
return orchestratorConfig.getPipelines()
.stream()
.map(pipeline -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import be.vlaanderen.informatievlaanderen.ldes.ldio.valueobjects.ComponentDefinition;
import be.vlaanderen.informatievlaanderen.ldes.ldio.valueobjects.InputComponentDefinition;
import be.vlaanderen.informatievlaanderen.ldes.ldio.valueobjects.PipelineConfigTO;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -20,12 +23,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import static be.vlaanderen.informatievlaanderen.ldes.ldio.repositories.PipelineFileRepository.EXTENSION_YAML;
import static be.vlaanderen.informatievlaanderen.ldes.ldio.repositories.PipelineFileRepository.EXTENSION_YML;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.*;

public class PipelineFileRepositoryTest {
Expand All @@ -41,7 +42,7 @@ public static Map<File, PipelineConfigTO> getInitialFiles(File testDirectory) {
return files
.filter(path -> !Files.isDirectory(path))
.filter(path -> path.toFile().getName().endsWith(EXTENSION_YML)
|| path.toFile().getName().endsWith(EXTENSION_YAML))
|| path.toFile().getName().endsWith(EXTENSION_YAML))
.map(path -> {
try {
return Map.of(path.toFile(), readConfigFile(path));
Expand Down Expand Up @@ -72,10 +73,14 @@ void findAll() {
var activePipelines = repository.getActivePipelines();
var storedPipelines = repository.getInactivePipelines();

assertEquals(0, activePipelines.size());
assertEquals(1, storedPipelines.size());
assertEquals(existingPipelineFile, storedPipelines.keySet().stream().toList().get(0).getName());
assertEquals(existingPipeline, storedPipelines.values().stream().toList().get(0).name());
assertThat(activePipelines).isEmpty();
assertThat(storedPipelines)
.hasSize(1);
assertThat(storedPipelines.entrySet())
.filteredOn(entry -> entry.getKey().getName().equals(existingPipelineFile))
.extracting(Map.Entry::getValue)
.extracting(PipelineConfigTO::name)
.containsExactly(existingPipeline);
}

@BeforeEach
Expand All @@ -98,7 +103,10 @@ void saveExistingFile() {

// Init pipeline
repository.activateExistingPipeline(storedPipeline.getValue().toPipelineConfig(), storedPipeline.getKey());
assertThrows(PipelineAlreadyExistsException.class, () -> repository.activateNewPipeline(storedPipeline.getValue().toPipelineConfig()));

final PipelineConfig pipelineConfig = storedPipeline.getValue().toPipelineConfig();
assertThatThrownBy(() -> repository.activateNewPipeline(pipelineConfig))
.isInstanceOf(PipelineAlreadyExistsException.class);
}

@Test
Expand Down Expand Up @@ -140,7 +148,7 @@ void repostitoryFlow() {

assertEquals(1, activePipelines.size());
assertEquals(0, inactivePipelines.size());
assertEquals(existingPipeline, activePipelines.get(0).name());
assertEquals(existingPipeline, activePipelines.getFirst().name());

var config = new PipelineConfig();
String pipelineName = "valid";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package be.vlaanderen.informatievlaanderen.ldes.ldio.config;

import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.RequestExecutor;
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.services.RequestExecutorFactory;
import be.vlaanderen.informatievlaanderen.ldes.ldi.services.ComponentExecutor;
import be.vlaanderen.informatievlaanderen.ldes.ldi.types.LdiAdapter;
Expand Down

0 comments on commit 6c53d73

Please sign in to comment.