Commit 763448e4 authored by Figue Orange's avatar Figue Orange Committed by calocedre TAC
Browse files

add exception when no scoring rule is found (default validator prevent this...

add exception when no scoring rule is found (default validator prevent this case, but it avoid to return null in this case)

parent 63bc8776
......@@ -10,7 +10,7 @@ import java.util.Optional;
/**
*
* Mock implementation that return same value for any venue type/categories
*
*
*/
@Component
public class RiskConfigurationService {
......@@ -18,8 +18,8 @@ public class RiskConfigurationService {
@Autowired
private RiskConfiguration riskConfiguration;
static final RiskLevelConfig DEFAULT=new RiskLevelConfig(3, 1, 3.0f, 2.0f);
static final RiskLevelConfig DEFAULT = new RiskLevelConfig(3, 1, 3.0f, 2.0f);
public Optional<RiskRule> evaluate(int venueType, int venueCategory1, int venueCategory2) {
return Optional.of(riskConfiguration.getConfigurationFor(venueType, venueCategory1, venueCategory2));
}
......
......@@ -67,7 +67,7 @@ class SinglePlaceExposedVisitsProcessorTest {
SinglePlaceCluster res = new SinglePlaceExposedVisitsProcessor(properties, riskConfigurationServiceMock).process(spe);
assertThat(res).isNull();
}
}
@Test
void oneClusterPeriod() {
......@@ -98,7 +98,7 @@ class SinglePlaceExposedVisitsProcessorTest {
assertThat(p.getClusterDurationInSeconds()).as("clusterDuration").isEqualTo(2 * properties.durationUnitInSeconds);
}
@Test
void manyClusterPeriodSlots() {
......@@ -132,9 +132,7 @@ class SinglePlaceExposedVisitsProcessorTest {
assertThat(p.getClusterDurationInSeconds()).as("clusterDuration").isEqualTo(1* properties.durationUnitInSeconds);
}
@Test
void forwardRiskLevel() {
......
package fr.gouv.clea.clea.scoring.configuration;
import fr.gouv.clea.clea.scoring.configuration.exceptions.NoScoringConfigurationFoundException;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class ScoringConfiguration {
......@@ -19,8 +20,15 @@ public abstract class ScoringConfiguration {
log.debug("Found matching rulefor venueType : {}, venueCategory1 : {}, venuCategory2: {}", matchingRule.get(), venueType, venueCategory1, venueCategory2);
return matchingRule.get();
} else {
log.error("No scoring matching found for venueType : {}, venueCategory1 : {}, venuCategory2: {}", venueType, venueCategory1, venueCategory2);
return null;
StringBuilder errorMessageBuilder = new StringBuilder()
.append("No scoring matching found for venueType : ")
.append(venueType)
.append(", venueCategory1 : ")
.append(venueCategory1)
.append(", venuCategory2: ")
.append(venueCategory2);
log.error(errorMessageBuilder.toString());
throw new NoScoringConfigurationFoundException(errorMessageBuilder.toString());
}
}
......
package fr.gouv.clea.clea.scoring.configuration.exceptions;
import lombok.Getter;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@Getter
public class NoScoringConfigurationFoundException extends RuntimeException {
public NoScoringConfigurationFoundException(String message) {
super(message);
}
}
package fr.gouv.clea.clea.scoring.configuration;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.stream.Collectors;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfiguration;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfigurationConverter;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskRule;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfiguration;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfigurationConverter;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskRule;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class ScoringRuleSelectionTest {
......
......@@ -7,11 +7,7 @@ import fr.gouv.clea.consumer.model.Visit;
import fr.gouv.clea.consumer.repository.IExposedVisitRepository;
import fr.gouv.clea.consumer.service.IVisitExpositionAggregatorService;
import org.apache.commons.lang3.RandomUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
......
Markdown is supported
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