Skip to content

Commit

Permalink
Replace exception with log warn
Browse files Browse the repository at this point in the history
Signed-off-by: Sophie Frasnedo <[email protected]>
  • Loading branch information
So-Fras committed Dec 7, 2023
1 parent 3d96d05 commit 1168c00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import com.powsybl.nad.utils.iidm.IidmUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.function.Predicate;
Expand All @@ -19,6 +21,8 @@
*/
public class VoltageLevelFilter implements Predicate<VoltageLevel> {

protected static final Logger LOGGER = LoggerFactory.getLogger(VoltageLevelFilter.class);

public static final Predicate<VoltageLevel> NO_FILTER = voltageLevel -> true;

private final Set<VoltageLevel> voltageLevels;
Expand Down Expand Up @@ -138,10 +142,11 @@ public static VoltageLevelFilter createNominalVoltageFilter(Network network, Lis
throw new PowsyblException(UNKNOWN_VOLTAGE_LEVEL + voltageLevelId + "'");
}
if (vl.getNominalV() < lowNominalVoltageBound || vl.getNominalV() > highNominalVoltageBound) {
throw new PowsyblException("vl '" + voltageLevelId +
LOGGER.warn("vl '" + voltageLevelId +
"' has his nominal voltage out of the indicated thresholds");
} else {
startingSet.add(vl);
}
startingSet.add(vl);
}

Set<VoltageLevel> voltageLevels = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
*/
package com.powsybl.nad;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.PowsyblException;
import com.powsybl.diagram.test.Networks;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.*;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.nad.build.iidm.VoltageLevelFilter;
import com.powsybl.nad.layout.LayoutParameters;
import com.powsybl.nad.svg.LabelProvider;
Expand All @@ -23,10 +25,12 @@
import com.powsybl.nad.svg.iidm.NominalVoltageStyleProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.*;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -104,10 +108,15 @@ void testVoltageFilteredDiagramHighBound() {

@Test
void testVoltageFilteredDiagramOutOfBound() {
ListAppender<ILoggingEvent> logWatcher = new ListAppender<>();
logWatcher.start();
((Logger) LoggerFactory.getLogger(VoltageLevelFilter.class)).addAppender(logWatcher);
Network network = IeeeCdfNetworkFactory.create14();
List<String> voltageLevelList = List.of("VL4");
PowsyblException e = assertThrows(PowsyblException.class, () -> VoltageLevelFilter.createNominalVoltageHigherBoundFilter(network, voltageLevelList, 90, 2));
assertTrue(e.getMessage().contains("vl 'VL4' has his nominal voltage out of the indicated thresholds"));
VoltageLevelFilter.createNominalVoltageHigherBoundFilter(network, voltageLevelList, 90, 2);
List<ILoggingEvent> logsList = logWatcher.list;
assertEquals(1, logsList.size());
assertEquals("vl 'VL4' has his nominal voltage out of the indicated thresholds", logsList.get(0).getFormattedMessage());
}

@Test
Expand Down

0 comments on commit 1168c00

Please sign in to comment.