diff --git a/iidm/iidm-impl/pom.xml b/iidm/iidm-impl/pom.xml index eea52fe7974..d1d32afea21 100644 --- a/iidm/iidm-impl/pom.xml +++ b/iidm/iidm-impl/pom.xml @@ -77,6 +77,11 @@ + + ch.qos.logback + logback-classic + test + com.google.jimfs jimfs @@ -97,11 +102,6 @@ log4j-over-slf4j test - - org.slf4j - slf4j-simple - test - ${project.groupId} powsybl-commons-test diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/BusbarSectionPositionImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/BusbarSectionPositionImpl.java index 2a851defda3..24f16224425 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/BusbarSectionPositionImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/BusbarSectionPositionImpl.java @@ -19,17 +19,20 @@ public class BusbarSectionPositionImpl extends AbstractExtension private int sectionIndex; - private static int checkIndex(int index) { + private static int checkIndex(int index, BusbarSection busbarSection) { if (index < 0) { - throw new IllegalArgumentException("Busbar index has to be greater or equals to zero"); + throw new IllegalArgumentException( + String.format("Busbar index (%s) has to be greater or equals to zero for busbar section %s", + index, + busbarSection.getId())); } return index; } public BusbarSectionPositionImpl(BusbarSection busbarSection, int busbarIndex, int sectionIndex) { super(busbarSection); - this.busbarIndex = checkIndex(busbarIndex); - this.sectionIndex = checkIndex(sectionIndex); + this.busbarIndex = checkIndex(busbarIndex, busbarSection); + this.sectionIndex = checkIndex(sectionIndex, busbarSection); } public int getBusbarIndex() { @@ -37,7 +40,7 @@ public int getBusbarIndex() { } public BusbarSectionPositionImpl setBusbarIndex(int busbarIndex) { - this.busbarIndex = checkIndex(busbarIndex); + this.busbarIndex = checkIndex(busbarIndex, this.getExtendable()); return this; } @@ -46,7 +49,7 @@ public int getSectionIndex() { } public BusbarSectionPositionImpl setSectionIndex(int sectionIndex) { - this.sectionIndex = checkIndex(sectionIndex); + this.sectionIndex = checkIndex(sectionIndex, this.getExtendable()); return this; } } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/CoordinatedReactiveControlImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/CoordinatedReactiveControlImpl.java index 1dcc1e36c49..e3dcf9b1a1f 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/CoordinatedReactiveControlImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/CoordinatedReactiveControlImpl.java @@ -43,7 +43,8 @@ public void setQPercent(double qPercent) { private static double checkQPercent(Generator generator, double qPercent) { if (Double.isNaN(qPercent)) { - throw new PowsyblException("Undefined value for qPercent"); + throw new PowsyblException(String.format("Undefined value (%s) for qPercent for generator %s", + qPercent, generator.getId())); } if (qPercent < 0 || qPercent > 100) { LOGGER.debug("qPercent value of generator {} does not seem to be a valid percent: {}", generator.getId(), qPercent); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/GeneratorEntsoeCategoryImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/GeneratorEntsoeCategoryImpl.java index 064ad5c0691..9f81e834509 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/GeneratorEntsoeCategoryImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/GeneratorEntsoeCategoryImpl.java @@ -17,16 +17,18 @@ public class GeneratorEntsoeCategoryImpl extends AbstractExtension im private int code; - private static int checkCode(int code) { + private static int checkCode(int code, Generator generator) { if (code < 1) { - throw new IllegalArgumentException("Bad generator ENTSO-E code " + code); + throw new IllegalArgumentException(String.format("Bad generator ENTSO-E code %s for generator %s", + code, + generator.getId())); } return code; } public GeneratorEntsoeCategoryImpl(Generator generator, int code) { super(generator); - this.code = checkCode(code); + this.code = checkCode(code, generator); } @Override @@ -36,7 +38,7 @@ public int getCode() { @Override public GeneratorEntsoeCategoryImpl setCode(int code) { - this.code = checkCode(code); + this.code = checkCode(code, this.getExtendable()); return this; } } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/HvdcAngleDroopActivePowerControlImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/HvdcAngleDroopActivePowerControlImpl.java index 31823514527..65370edf9b5 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/HvdcAngleDroopActivePowerControlImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/HvdcAngleDroopActivePowerControlImpl.java @@ -48,8 +48,8 @@ public HvdcAngleDroopActivePowerControlImpl(HvdcLine hvdcLine, float p0, float d this.droop = new TFloatArrayList(variantArraySize); this.enabled = new TBooleanArrayList(variantArraySize); for (int i = 0; i < variantArraySize; i++) { - this.p0.add(checkP0(p0)); - this.droop.add(checkDroop(droop)); + this.p0.add(checkP0(p0, hvdcLine)); + this.droop.add(checkDroop(droop, hvdcLine)); this.enabled.add(enabled); } } @@ -71,13 +71,13 @@ public boolean isEnabled() { @Override public HvdcAngleDroopActivePowerControl setP0(float p0) { - this.p0.set(getVariantIndex(), checkP0(p0)); + this.p0.set(getVariantIndex(), checkP0(p0, this.getExtendable())); return this; } @Override public HvdcAngleDroopActivePowerControl setDroop(float droop) { - this.droop.set(getVariantIndex(), checkDroop(droop)); + this.droop.set(getVariantIndex(), checkDroop(droop, this.getExtendable())); return this; } @@ -87,17 +87,21 @@ public HvdcAngleDroopActivePowerControl setEnabled(boolean enabled) { return this; } - private float checkP0(float p0) { + private float checkP0(float p0, HvdcLine hvdcLine) { if (Float.isNaN(p0)) { - throw new IllegalArgumentException("p0 is not set"); + throw new IllegalArgumentException(String.format("p0 value (%s) is invalid for HVDC line %s", + p0, + hvdcLine.getId())); } return p0; } - private float checkDroop(float droop) { + private float checkDroop(float droop, HvdcLine hvdcLine) { if (Float.isNaN(droop)) { - throw new IllegalArgumentException("droop is not set"); + throw new IllegalArgumentException(String.format("droop value (%s) is invalid for HVDC line %s", + droop, + hvdcLine.getId())); } return droop; diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/LoadDetailImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/LoadDetailImpl.java index fd4915a4433..8b9a74db4d0 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/LoadDetailImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/LoadDetailImpl.java @@ -9,7 +9,6 @@ import com.powsybl.iidm.network.Load; import com.powsybl.iidm.network.extensions.LoadDetail; import com.powsybl.iidm.network.impl.AbstractMultiVariantIdentifiableExtension; - import gnu.trove.list.array.TDoubleArrayList; /** @@ -34,10 +33,10 @@ public LoadDetailImpl(Load load, double fixedActivePower, double fixedReactivePo this.variableActivePower = new TDoubleArrayList(variantArraySize); this.variableReactivePower = new TDoubleArrayList(variantArraySize); for (int i = 0; i < variantArraySize; i++) { - this.fixedActivePower.add(checkPower(fixedActivePower, "Invalid fixedActivePower")); - this.fixedReactivePower.add(checkPower(fixedReactivePower, "Invalid fixedReactivePower")); - this.variableActivePower.add(checkPower(variableActivePower, "Invalid variableActivePower")); - this.variableReactivePower.add(checkPower(variableReactivePower, "Invalid variableReactivePower")); + this.fixedActivePower.add(checkPower(fixedActivePower, "Invalid fixedActivePower", load)); + this.fixedReactivePower.add(checkPower(fixedReactivePower, "Invalid fixedReactivePower", load)); + this.variableActivePower.add(checkPower(variableActivePower, "Invalid variableActivePower", load)); + this.variableReactivePower.add(checkPower(variableReactivePower, "Invalid variableReactivePower", load)); } } @@ -47,7 +46,7 @@ public double getFixedActivePower() { @Override public LoadDetail setFixedActivePower(double fixedActivePower) { - checkPower(fixedActivePower, "Invalid fixedActivePower"); + checkPower(fixedActivePower, "Invalid fixedActivePower", this.getExtendable()); this.fixedActivePower.set(getVariantIndex(), fixedActivePower); return this; } @@ -59,7 +58,7 @@ public double getFixedReactivePower() { @Override public LoadDetail setFixedReactivePower(double fixedReactivePower) { - checkPower(fixedReactivePower, "Invalid fixedReactivePower"); + checkPower(fixedReactivePower, "Invalid fixedReactivePower", this.getExtendable()); this.fixedReactivePower.set(getVariantIndex(), fixedReactivePower); return this; } @@ -71,7 +70,7 @@ public double getVariableActivePower() { @Override public LoadDetail setVariableActivePower(double variableActivePower) { - checkPower(variableActivePower, "Invalid variableActivePower"); + checkPower(variableActivePower, "Invalid variableActivePower", this.getExtendable()); this.variableActivePower.set(getVariantIndex(), variableActivePower); return this; } @@ -83,14 +82,17 @@ public double getVariableReactivePower() { @Override public LoadDetail setVariableReactivePower(double variableReactivePower) { - checkPower(variableReactivePower, "Invalid variableReactivePower"); + checkPower(variableReactivePower, "Invalid variableReactivePower", this.getExtendable()); this.variableReactivePower.set(getVariantIndex(), variableReactivePower); return this; } - private static double checkPower(double power, String errorMessage) { + private static double checkPower(double power, String errorMessage, Load load) { if (Double.isNaN(power)) { - throw new IllegalArgumentException(errorMessage); + throw new IllegalArgumentException(String.format("%s (%s) for load %s", + errorMessage, + power, + load.getId())); } return power; } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePrioritiesImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePrioritiesImpl.java index a91707ed030..1dcd61700b5 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePrioritiesImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePrioritiesImpl.java @@ -31,7 +31,8 @@ public ReferencePrioritiesImpl(C extendable) { ReferencePrioritiesImpl add(ReferencePriority referencePriority) { if (!getExtendable().getTerminals().contains(referencePriority.getTerminal())) { - throw new PowsyblException("The provided terminal does not belong to this connectable"); + throw new PowsyblException(String.format("The provided terminal does not belong to the connectable %s", + getExtendable().getId())); } referencePrioritiesPerVariant.get(getVariantIndex()).put(referencePriority.getTerminal(), referencePriority); return this; diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePriorityImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePriorityImpl.java index 332437d54c0..79d4aa876ac 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePriorityImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/ReferencePriorityImpl.java @@ -23,7 +23,8 @@ class ReferencePriorityImpl implements ReferencePriority { ReferencePriorityImpl(Terminal terminal, int priority) { this.terminal = Objects.requireNonNull(terminal, "Terminal needs to be set for ReferencePriority extension"); if (priority < 0) { - throw new PowsyblException("Priority should be zero or positive for ReferencePriority extension"); + throw new PowsyblException(String.format("Priority (%s) of terminal (equipment %s) should be zero or positive for ReferencePriority extension", + priority, terminal.getConnectable().getId())); } this.priority = priority; } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java index 1660fb910b8..a2314845cad 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java @@ -36,27 +36,48 @@ private static double checkB0(double b0) { } private static void checkVoltageConfig(double lowVoltageSetpoint, double highVoltageSetpoint, - double lowVoltageThreshold, double highVoltageThreshold) { + double lowVoltageThreshold, double highVoltageThreshold, + StaticVarCompensator staticVarCompensator) { if (Double.isNaN(lowVoltageSetpoint)) { - throw new IllegalArgumentException("lowVoltageSetpoint is invalid"); + throw new IllegalArgumentException( + String.format("lowVoltageSetpoint (%s) is invalid for StaticVarCompensator %s", + lowVoltageSetpoint, + staticVarCompensator.getId())); } if (Double.isNaN(highVoltageSetpoint)) { - throw new IllegalArgumentException("highVoltageSetpoint is invalid"); + throw new IllegalArgumentException( + String.format("highVoltageSetpoint (%s) is invalid for StaticVarCompensator %s", + highVoltageSetpoint, + staticVarCompensator.getId())); } if (Double.isNaN(lowVoltageThreshold)) { - throw new IllegalArgumentException("lowVoltageThreshold is invalid"); + throw new IllegalArgumentException( + String.format("lowVoltageThreshold (%s) is invalid for StaticVarCompensator %s", + lowVoltageThreshold, + staticVarCompensator.getId())); } if (Double.isNaN(highVoltageThreshold)) { - throw new IllegalArgumentException("highVoltageThreshold is invalid"); + throw new IllegalArgumentException( + String.format("highVoltageThreshold (%s) is invalid for StaticVarCompensator %s", + highVoltageThreshold, + staticVarCompensator.getId())); } if (lowVoltageThreshold >= highVoltageThreshold) { - throw new IllegalArgumentException("Inconsistent low (" + lowVoltageThreshold + ") and high (" + highVoltageThreshold + ") voltage thresholds"); + throw new IllegalArgumentException( + String.format("Inconsistent low (%s) and high (%s) voltage thresholds for StaticVarCompensator %s", + lowVoltageThreshold, + highVoltageThreshold, + staticVarCompensator.getId())); } if (lowVoltageSetpoint < lowVoltageThreshold) { - LOGGER.warn("Invalid low voltage setpoint {} < threshold {}", lowVoltageSetpoint, lowVoltageThreshold); + LOGGER.warn("Invalid low voltage setpoint {} < threshold {} for StaticVarCompensator {}", + lowVoltageSetpoint, lowVoltageThreshold, + staticVarCompensator.getId()); } if (highVoltageSetpoint > highVoltageThreshold) { - LOGGER.warn("Invalid high voltage setpoint {} > threshold {}", highVoltageSetpoint, highVoltageThreshold); + LOGGER.warn("Invalid high voltage setpoint {} > threshold {} for StaticVarCompensator {}", + highVoltageSetpoint, highVoltageThreshold, + staticVarCompensator.getId()); } } @@ -64,7 +85,7 @@ public StandbyAutomatonImpl(StaticVarCompensator svc, double b0, boolean standby double lowVoltageThreshold, double highVoltageThreshold) { super(svc); int variantArraySize = getVariantManagerHolder().getVariantManager().getVariantArraySize(); - checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold); + checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold, svc); this.b0 = checkB0(b0); this.standby = new TBooleanArrayList(variantArraySize); this.lowVoltageSetpoint = new TDoubleArrayList(variantArraySize); @@ -110,7 +131,8 @@ public double getHighVoltageSetpoint() { @Override public StandbyAutomatonImpl setHighVoltageSetpoint(double highVoltageSetpoint) { checkVoltageConfig(lowVoltageSetpoint.get(getVariantIndex()), highVoltageSetpoint, - lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold.get(getVariantIndex())); + lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold.get(getVariantIndex()), + this.getExtendable()); this.highVoltageSetpoint.set(getVariantIndex(), highVoltageSetpoint); return this; } @@ -123,7 +145,8 @@ public double getHighVoltageThreshold() { @Override public StandbyAutomatonImpl setHighVoltageThreshold(double highVoltageThreshold) { checkVoltageConfig(lowVoltageSetpoint.get(getVariantIndex()), highVoltageSetpoint.get(getVariantIndex()), - lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold); + lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold, + this.getExtendable()); this.highVoltageThreshold.set(getVariantIndex(), highVoltageThreshold); return this; } @@ -136,7 +159,8 @@ public double getLowVoltageSetpoint() { @Override public StandbyAutomatonImpl setLowVoltageSetpoint(double lowVoltageSetpoint) { checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint.get(getVariantIndex()), - lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold.get(getVariantIndex())); + lowVoltageThreshold.get(getVariantIndex()), highVoltageThreshold.get(getVariantIndex()), + this.getExtendable()); this.lowVoltageSetpoint.set(getVariantIndex(), lowVoltageSetpoint); return this; } @@ -149,7 +173,8 @@ public double getLowVoltageThreshold() { @Override public StandbyAutomatonImpl setLowVoltageThreshold(double lowVoltageThreshold) { checkVoltageConfig(lowVoltageSetpoint.get(getVariantIndex()), highVoltageSetpoint.get(getVariantIndex()), - lowVoltageThreshold, highVoltageThreshold.get(getVariantIndex())); + lowVoltageThreshold, highVoltageThreshold.get(getVariantIndex()), + this.getExtendable()); this.lowVoltageThreshold.set(getVariantIndex(), lowVoltageThreshold); return this; } diff --git a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/BusbarSectionPositionImplTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/BusbarSectionPositionImplTest.java new file mode 100644 index 00000000000..6cc0125a0ae --- /dev/null +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/BusbarSectionPositionImplTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.iidm.network.impl.tck.extensions; + +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.BusbarSectionPosition; +import com.powsybl.iidm.network.extensions.BusbarSectionPositionAdder; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author Nicolas Rol {@literal } + */ +class BusbarSectionPositionImplTest { + + @Test + void testExtension() { + IllegalArgumentException e0; + Network network = Network.create("test", "test"); + Substation s = network.newSubstation() + .setId("S") + .setCountry(Country.FR) + .add(); + VoltageLevel vl = s.newVoltageLevel() + .setId("VL") + .setNominalV(400.0) + .setTopologyKind(TopologyKind.NODE_BREAKER) + .add(); + BusbarSection bbs = vl.getNodeBreakerView().newBusbarSection() + .setId("BBS") + .setNode(0) + .add(); + + BusbarSectionPosition busbarSectionPosition = bbs.newExtension(BusbarSectionPositionAdder.class) + .withBusbarIndex(1) + .withSectionIndex(2) + .add(); + assertEquals(1, busbarSectionPosition.getBusbarIndex()); + assertEquals(2, busbarSectionPosition.getSectionIndex()); + + // Wrong Busbar index + e0 = assertThrows(IllegalArgumentException.class, () -> busbarSectionPosition.setBusbarIndex(-1)); + assertEquals("Busbar index (-1) has to be greater or equals to zero for busbar section BBS", + e0.getMessage()); + + // RIght busbar index + busbarSectionPosition.setBusbarIndex(10); + busbarSectionPosition.setSectionIndex(5); + assertEquals(10, busbarSectionPosition.getBusbarIndex()); + assertEquals(5, busbarSectionPosition.getSectionIndex()); + } +} diff --git a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/GeneratorEntsoeCategoryTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/GeneratorEntsoeCategoryTest.java new file mode 100644 index 00000000000..498bc4c2589 --- /dev/null +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/GeneratorEntsoeCategoryTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.iidm.network.impl.tck.extensions; + +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.GeneratorEntsoeCategory; +import com.powsybl.iidm.network.extensions.GeneratorEntsoeCategoryAdder; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author Nicolas Rol {@literal } + */ +class GeneratorEntsoeCategoryTest { + + @Test + void testExtension() { + Network network = Network.create("test", "test"); + Substation s = network.newSubstation() + .setId("S") + .setCountry(Country.FR) + .add(); + VoltageLevel vl = s.newVoltageLevel() + .setId("VL") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl.getBusBreakerView().newBus() + .setId("B") + .add(); + Generator generator = vl.newGenerator() + .setId("G1") + .setBus("B") + .setMaxP(100) + .setMinP(50) + .setTargetP(100) + .setTargetV(400) + .setVoltageRegulatorOn(true) + .add(); + + GeneratorEntsoeCategory generatorEntsoeCategory = generator.newExtension(GeneratorEntsoeCategoryAdder.class) + .withCode(10) + .add(); + assertEquals(10, generatorEntsoeCategory.getCode()); + + // Wrong code + IllegalArgumentException e0 = assertThrows(IllegalArgumentException.class, () -> generatorEntsoeCategory.setCode(-1)); + assertEquals("Bad generator ENTSO-E code -1 for generator G1", + e0.getMessage()); + + // Right code + generatorEntsoeCategory.setCode(5); + assertEquals(5, generatorEntsoeCategory.getCode()); + } +} diff --git a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/LoadDetailTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/LoadDetailTest.java index 420c32ba49c..d8206f8faf9 100644 --- a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/LoadDetailTest.java +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/LoadDetailTest.java @@ -7,10 +7,61 @@ package com.powsybl.iidm.network.impl.tck.extensions; +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.LoadDetailAdder; import com.powsybl.iidm.network.tck.extensions.AbstractLoadDetailTest; +import org.junit.jupiter.api.Test; + +import java.time.ZonedDateTime; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Mathieu Bague {@literal } */ class LoadDetailTest extends AbstractLoadDetailTest { + + private static Network createNetwork() { + Network network = Network.create("test", "test"); + network.setCaseDate(ZonedDateTime.parse("2016-06-27T12:27:58.535+02:00")); + Substation s = network.newSubstation() + .setId("S") + .setCountry(Country.FR) + .add(); + VoltageLevel vl = s.newVoltageLevel() + .setId("VL") + .setNominalV(400) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl.getBusBreakerView().newBus() + .setId("B") + .add(); + vl.newLoad() + .setId("L") + .setBus("B") + .setConnectableBus("B") + .setP0(100) + .setQ0(50) + .add(); + return network; + } + + @Test + void checkVoltageConfigTest() { + Network network = createNetwork(); + Load load = network.getLoad("L"); + assertNotNull(load); + + // Builder + LoadDetailAdder loadDetailAdder = load.newExtension(LoadDetailAdder.class) + .withFixedActivePower(40f) + .withFixedReactivePower(20f) + .withVariableActivePower(60f) + .withVariableReactivePower(Double.NaN); + + // VariableReactivePower invalid + IllegalArgumentException e0 = assertThrows(IllegalArgumentException.class, loadDetailAdder::add); + assertEquals("Invalid variableReactivePower (NaN) for load L", + e0.getMessage()); + } } diff --git a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/StandbyAutomatonTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/StandbyAutomatonTest.java index 50943c1bff8..d071bb0f876 100644 --- a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/StandbyAutomatonTest.java +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/StandbyAutomatonTest.java @@ -6,10 +6,120 @@ */ package com.powsybl.iidm.network.impl.tck.extensions; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.StaticVarCompensator; +import com.powsybl.iidm.network.extensions.StandbyAutomatonAdder; +import com.powsybl.iidm.network.impl.extensions.StandbyAutomatonImpl; import com.powsybl.iidm.network.tck.extensions.AbstractStandbyAutomatonTest; +import com.powsybl.iidm.network.test.SvcTestCaseFactory; +import org.junit.jupiter.api.Test; +import org.slf4j.LoggerFactory; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Anne Tilloy {@literal } */ class StandbyAutomatonTest extends AbstractStandbyAutomatonTest { + + @Test + void checkVoltageConfigTest() { + Network network = SvcTestCaseFactory.create(); + StaticVarCompensator svc = network.getStaticVarCompensator("SVC2"); + assertNotNull(svc); + + // Builder + StandbyAutomatonAdder standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class) + .withB0(0.0001f) + .withStandbyStatus(true); + + // LowVoltageThreshold > HighVoltageThreshold + standbyAutomatonAdder.withLowVoltageSetpoint(390f) + .withHighVoltageSetpoint(345f) + .withLowVoltageThreshold(385f) + .withHighVoltageThreshold(350f); + IllegalArgumentException e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); + assertEquals("Inconsistent low (385.0) and high (350.0) voltage thresholds for StaticVarCompensator SVC2", + e0.getMessage()); + + // lowVoltageSetpoint invalid + standbyAutomatonAdder.withLowVoltageSetpoint(Double.NaN) + .withHighVoltageSetpoint(400f) + .withLowVoltageThreshold(385f) + .withHighVoltageThreshold(405f); + e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); + assertEquals("lowVoltageSetpoint (NaN) is invalid for StaticVarCompensator SVC2", + e0.getMessage()); + + // highVoltageSetpoint invalid + standbyAutomatonAdder.withLowVoltageSetpoint(390f) + .withHighVoltageSetpoint(Double.NaN) + .withLowVoltageThreshold(385f) + .withHighVoltageThreshold(405f); + e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); + assertEquals("highVoltageSetpoint (NaN) is invalid for StaticVarCompensator SVC2", + e0.getMessage()); + + // lowVoltageSetpoint invalid + standbyAutomatonAdder.withLowVoltageSetpoint(390f) + .withHighVoltageSetpoint(400f) + .withLowVoltageThreshold(Double.NaN) + .withHighVoltageThreshold(405f); + e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); + assertEquals("lowVoltageThreshold (NaN) is invalid for StaticVarCompensator SVC2", + e0.getMessage()); + + // highVoltageSetpoint invalid + standbyAutomatonAdder.withLowVoltageSetpoint(390f) + .withHighVoltageSetpoint(400f) + .withLowVoltageThreshold(385f) + .withHighVoltageThreshold(Double.NaN); + e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); + assertEquals("highVoltageThreshold (NaN) is invalid for StaticVarCompensator SVC2", + e0.getMessage()); + } + + @Test + void logsTests() { + ListAppender logWatcher = new ListAppender<>(); + logWatcher.start(); + ((Logger) LoggerFactory.getLogger(StandbyAutomatonImpl.class)).addAppender(logWatcher); + + // Prepare the test + Network network = SvcTestCaseFactory.create(); + StaticVarCompensator svc = network.getStaticVarCompensator("SVC2"); + assertNotNull(svc); + + // Builder + StandbyAutomatonAdder standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class) + .withB0(0.0001f) + .withStandbyStatus(true); + + // lowVoltageSetpoint < lowVoltageThreshold + standbyAutomatonAdder.withLowVoltageSetpoint(380f) + .withHighVoltageSetpoint(400f) + .withLowVoltageThreshold(385f) + .withHighVoltageThreshold(405f) + .add(); + + // highVoltageSetpoint > highVoltageThreshold + standbyAutomatonAdder.withLowVoltageSetpoint(390f) + .withHighVoltageSetpoint(410f) + .withLowVoltageThreshold(385f) + .withHighVoltageThreshold(405f) + .add(); + + // Checks + List logsList = logWatcher.list; + assertEquals(2, logsList.size()); + assertEquals("Invalid low voltage setpoint 380.0 < threshold 385.0 for StaticVarCompensator SVC2", + logsList.get(0).getFormattedMessage()); + assertEquals("Invalid high voltage setpoint 410.0 > threshold 405.0 for StaticVarCompensator SVC2", + logsList.get(1).getFormattedMessage()); + } } diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractCoordinatedReactiveControlTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractCoordinatedReactiveControlTest.java index ae141a8af3a..f673c746ef5 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractCoordinatedReactiveControlTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractCoordinatedReactiveControlTest.java @@ -51,7 +51,7 @@ public void testUndefined() { PowsyblException e = assertThrows(PowsyblException.class, () -> generator.newExtension(CoordinatedReactiveControlAdder.class) .withQPercent(Double.NaN) .add()); - assertTrue(e.getMessage().contains("Undefined value for qPercent")); + assertTrue(e.getMessage().contains("Undefined value (NaN) for qPercent for generator GEN")); } @Test diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractHvdcAngleDroopActivePowerTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractHvdcAngleDroopActivePowerTest.java index ff6b7d0043e..5c58b4c2544 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractHvdcAngleDroopActivePowerTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractHvdcAngleDroopActivePowerTest.java @@ -123,13 +123,13 @@ public void variantsCloneTest() { hadpc.setP0(Float.NaN); fail(); } catch (IllegalArgumentException e) { - assertEquals("p0 is not set", e.getMessage()); + assertEquals("p0 value (NaN) is invalid for HVDC line L", e.getMessage()); } try { hadpc.setDroop(Float.NaN); fail(); } catch (IllegalArgumentException e) { - assertEquals("droop is not set", e.getMessage()); + assertEquals("droop value (NaN) is invalid for HVDC line L", e.getMessage()); } } } diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractReferencePrioritiesTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractReferencePrioritiesTest.java index 0d9bc94f4aa..46719ff0d7a 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractReferencePrioritiesTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractReferencePrioritiesTest.java @@ -198,7 +198,7 @@ void testBadPriority() { .setTerminal(lineS3S4.getTerminal1()) .setPriority(-2) .add()); - assertEquals("Priority should be zero or positive for ReferencePriority extension", thrown.getMessage()); + assertEquals("Priority (-2) of terminal (equipment LINE_S3S4) should be zero or positive for ReferencePriority extension", thrown.getMessage()); } @Test @@ -209,7 +209,7 @@ void testTerminalNotInConnectable() { .setTerminal(gh1.getTerminal()) .setPriority(5) .add()); - assertEquals("The provided terminal does not belong to this connectable", thrown.getMessage()); + assertEquals("The provided terminal does not belong to the connectable LINE_S3S4", thrown.getMessage()); } } diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java index b8b1a42329d..d24e80dccd3 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/extensions/AbstractStandbyAutomatonTest.java @@ -152,5 +152,4 @@ public void variantsCloneTest() { assertEquals("Variant index not set", e.getMessage()); } } - }