Commit 1adcc866 authored by Bergamote Orange's avatar Bergamote Orange
Browse files

MR review comments

parent 543a0ef9
......@@ -26,9 +26,9 @@ public class StepExecutionContextReader implements ItemReader<Map.Entry<String,
@Override
public Map.Entry<String, List<String>> read() {
if (!prefixes.isEmpty() && index < prefixes.size()) {
AbstractMap.SimpleEntry<String, List<String>> singleMap = new AbstractMap.SimpleEntry<>(prefixes.get(index), ltids.get(index));
AbstractMap.SimpleEntry<String, List<String>> mapEntry = new AbstractMap.SimpleEntry<>(prefixes.get(index), ltids.get(index));
index++;
return singleMap;
return mapEntry;
} else {
return null;
}
......
......@@ -5,11 +5,13 @@ import fr.gouv.clea.dto.SinglePlaceCluster;
import fr.gouv.clea.dto.SinglePlaceClusterPeriod;
import fr.gouv.clea.mapper.ClusterPeriodModelsMapper;
import fr.gouv.clea.mapper.ClusterPeriodModelsMapperImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import java.util.List;
import java.util.UUID;
......@@ -36,11 +38,12 @@ class ClusterToPeriodsProcessorTest {
final int lastTimeSlot = 1001;
final int riskLevel = 4;
final long periodStart = 1L;
final ClusterPeriod clusterPeriod = buildPeriod(clusterStart, clusterDurationInSeconds, firstTimeSlot, lastTimeSlot, riskLevel, periodStart);
final SinglePlaceCluster cluster = buildCluster(ltid, venueType, venueCat1, venueCat2, clusterPeriod);
final ClusterPeriod clusterPeriod = new ClusterPeriod(periodStart, firstTimeSlot, lastTimeSlot, clusterStart, clusterDurationInSeconds, riskLevel);
final SinglePlaceCluster cluster = new SinglePlaceCluster(ltid, venueType, venueCat1, venueCat2, List.of(clusterPeriod));
final List<SinglePlaceClusterPeriod> singlePlaceClusterPeriods = processor.process(cluster);
assertThat(singlePlaceClusterPeriods).isNotNull();
assertThat(singlePlaceClusterPeriods.size()).isEqualTo(1);
assertThat(singlePlaceClusterPeriods.get(0).getClusterStart()).isEqualTo(clusterStart);
assertThat(singlePlaceClusterPeriods.get(0).getClusterDurationInSeconds()).isEqualTo(clusterDurationInSeconds);
......@@ -54,25 +57,4 @@ class ClusterToPeriodsProcessorTest {
assertThat(singlePlaceClusterPeriods.get(0).getRiskLevel()).isEqualTo(riskLevel);
}
private SinglePlaceCluster buildCluster(final UUID ltid, final int venueType, final int venueCat1, final int venueCat2, final ClusterPeriod p1) {
final SinglePlaceCluster cluster = new SinglePlaceCluster();
cluster.setVenueType(venueType);
cluster.setVenueCategory1(venueCat1);
cluster.setVenueCategory2(venueCat2);
cluster.setLocationTemporaryPublicId(ltid);
cluster.setPeriods(List.of(p1));
return cluster;
}
private ClusterPeriod buildPeriod(final int clusterStart, final int clusterDurationInSeconds, final int firstTimeSlot, final int lastTimeSlot, final int riskLevel, final long periodStart) {
final ClusterPeriod clusterPeriod = new ClusterPeriod();
clusterPeriod.setClusterStart(clusterStart);
clusterPeriod.setClusterDurationInSeconds(clusterDurationInSeconds);
clusterPeriod.setFirstTimeSlot(firstTimeSlot);
clusterPeriod.setLastTimeSlot(lastTimeSlot);
clusterPeriod.setRiskLevel(riskLevel);
clusterPeriod.setPeriodStart(periodStart);
return clusterPeriod;
}
}
package fr.gouv.clea.identification.writer;
import fr.gouv.clea.dto.SinglePlaceClusterPeriod;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@Slf4j
@ExtendWith(MockitoExtension.class)
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class SinglePlaceClusterPeriodListWriterTest {
@Captor
private ArgumentCaptor<SqlParameterSource[]> sqlParameterSourcesCaptor;
@Mock
private NamedParameterJdbcTemplate jdbcTemplate;
@InjectMocks
SinglePlaceClusterPeriodListWriter writer;
@Test
void write_calls_template_with_parameters_from_provided_list() {
final UUID ltid1 = UUID.randomUUID();
final int venueType1 = 0;
final int venueCat1_1 = 1;
final int venueCat2_1 = 2;
final long periodStart1 = 0L;
final int firstTS1 = 3;
final int lastTS1 = 4;
final long clusterStart1 = 1L;
final int clusterDuration1 = 5;
final float riskLv1 = 1;
final UUID ltid2 = UUID.randomUUID();
final int venueType2 = 6;
final int venueCat1_2 = 7;
final int venueCat2_2 = 8;
final long periodStart2 = 0L;
final int firstTS2 = 9;
final int lastTS2 = 10;
final long clusterStart2 = 1L;
final int clusterDuration2 = 11;
final float riskLv2 = 1;
final SinglePlaceClusterPeriod period1 = buildClusterPeriod(ltid1, venueType1, venueCat1_1, venueCat2_1, periodStart1, firstTS1, lastTS1, clusterStart1, clusterDuration1, riskLv1);
final SinglePlaceClusterPeriod period2 = buildClusterPeriod(ltid2, venueType2, venueCat1_2, venueCat2_2, periodStart2, firstTS2, lastTS2, clusterStart2, clusterDuration2, riskLv2);
when(jdbcTemplate.batchUpdate(anyString(), sqlParameterSourcesCaptor.capture())).thenReturn(new int[2]);
// two lists of two singlePlaceClusterPeriods as input, one per ltid
writer.write(List.of(List.of(period1), List.of(period2)));
sqlParameterSourcesCaptor.getAllValues().forEach(sqlParameterSources -> log.info("sqlParameterSource: {}", Arrays.toString(sqlParameterSources)));
}
private SinglePlaceClusterPeriod buildClusterPeriod(final UUID ltid,
final int venueType,
final int venueCat1,
final int venueCat2,
final long periodStart,
final int firstTS,
final int lastTS,
final long clusterStart,
final int clusterDuration,
final float riskLv) {
return SinglePlaceClusterPeriod.builder()
.locationTemporaryPublicId(ltid)
.venueType(venueType)
.venueCategory1(venueCat1)
.venueCategory2(venueCat2)
.periodStart(periodStart)
.firstTimeSlot(firstTS)
.lastTimeSlot(lastTS)
.clusterStart(clusterStart)
.clusterDurationInSeconds(clusterDuration)
.riskLevel(riskLv)
.build();
}
}
package fr.gouv.clea.indexation.reader;
import org.assertj.core.data.MapEntry;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;
@ExtendWith(MockitoExtension.class)
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
......@@ -18,34 +20,27 @@ class StepExecutionContextReaderTest {
@Test
void indexation_reader_returns_map_entries_corresponding_to_its_prefixes_and_ltidsLists_inputs() {
final List<String> ltidsList2 = List.of("c7f878e0-25de-4bdc-9f62-a283b5133b3a",
"c7f878e0-25de-4bdc-9f62-a283b5133b3b",
"c7f878e0-25de-4bdc-9f62-a283b5133b3c");
final List<String> ltidsList1 = List.of("52f3fe14-2f58-4e26-b321-b73a51d411a1",
"52f3fe14-2f58-4e26-b321-b73a51d411a2",
"52f3fe14-2f58-4e26-b321-b73a51d411a3");
final List<String> ltidsList2 = List.of("c7f878e0-25de-4bdc-9f62-a283b5133b3a",
"c7f878e0-25de-4bdc-9f62-a283b5133b3b",
"c7f878e0-25de-4bdc-9f62-a283b5133b3c");
final List<List<String>> ltidsLists = List.of(ltidsList1, ltidsList2);
final String prefix1 = "52";
final String prefix2 = "c7";
final List<String> prefixes = List.of(prefix1, prefix2);
StepExecutionContextReader reader = new StepExecutionContextReader(prefixes, ltidsLists);
final StepExecutionContextReader reader = new StepExecutionContextReader(prefixes, ltidsLists);
int index = 0;
assertThat(reader.getIndex()).isEqualTo(index);
final Map<Integer, Map.Entry<String, List<String>>> resultMap = new HashMap<>();
Map.Entry<String, List<String>> entry;
final Map<String, List<String>> resultMap = new HashMap<>();
Map.Entry<String, List<String>> actualEntry;
// simulate spring batch behaviour, looping on read() method until it returns null
while ((entry = reader.read()) != null) {
resultMap.put(index, entry);
index++;
assertThat(reader.getIndex()).isEqualTo(index);
while ((actualEntry = reader.read()) != null) {
resultMap.put(actualEntry.getKey(), actualEntry.getValue());
}
for (int resultMapIndex=0; resultMapIndex< resultMap.size(); resultMapIndex++) {
assertThat(resultMap.get(resultMapIndex).getKey()).isEqualTo(prefixes.get(resultMapIndex));
assertThat(resultMap.get(resultMapIndex).getValue()).isEqualTo(ltidsLists.get(resultMapIndex));
}
assertThat(resultMap).containsExactlyInAnyOrderEntriesOf(Map.of(prefix1, ltidsList1, prefix2, ltidsList2));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment