From 373d8e258b6d7aa212bdf44b1a76f2a5b720121f Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Tue, 5 Dec 2023 17:23:16 +0100 Subject: [PATCH 1/7] add coverage Signed-off-by: Nicolas Rol --- iidm/iidm-impl/pom.xml | 15 ++- .../impl/extensions/StandbyAutomatonImpl.java | 58 ++++++--- .../tck/extensions/StandbyAutomatonTest.java | 110 ++++++++++++++++++ .../AbstractStandbyAutomatonTest.java | 1 - 4 files changed, 165 insertions(+), 19 deletions(-) diff --git a/iidm/iidm-impl/pom.xml b/iidm/iidm-impl/pom.xml index 6e168b3702a..c7645db176c 100644 --- a/iidm/iidm-impl/pom.xml +++ b/iidm/iidm-impl/pom.xml @@ -77,6 +77,16 @@ + + ch.qos.logback + logback-core + test + + + ch.qos.logback + logback-classic + test + com.google.jimfs jimfs @@ -97,11 +107,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/StandbyAutomatonImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/StandbyAutomatonImpl.java index 1660fb910b8..440e1ce1239 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,55 @@ 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 element %s of %s", + lowVoltageSetpoint, + staticVarCompensator.getId(), + staticVarCompensator.getClass())); } if (Double.isNaN(highVoltageSetpoint)) { - throw new IllegalArgumentException("highVoltageSetpoint is invalid"); + throw new IllegalArgumentException( + String.format("highVoltageSetpoint (%s) is invalid for element %s of %s", + highVoltageSetpoint, + staticVarCompensator.getId(), + staticVarCompensator.getClass())); } if (Double.isNaN(lowVoltageThreshold)) { - throw new IllegalArgumentException("lowVoltageThreshold is invalid"); + throw new IllegalArgumentException( + String.format("lowVoltageThreshold (%s) is invalid for element %s of %s", + lowVoltageThreshold, + staticVarCompensator.getId(), + staticVarCompensator.getClass())); } if (Double.isNaN(highVoltageThreshold)) { - throw new IllegalArgumentException("highVoltageThreshold is invalid"); + throw new IllegalArgumentException( + String.format("highVoltageThreshold (%s) is invalid for element %s of %s", + highVoltageThreshold, + staticVarCompensator.getId(), + staticVarCompensator.getClass())); } 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 element %s of %s", + lowVoltageThreshold, + highVoltageThreshold, + staticVarCompensator.getId(), + staticVarCompensator.getClass())); } if (lowVoltageSetpoint < lowVoltageThreshold) { - LOGGER.warn("Invalid low voltage setpoint {} < threshold {}", lowVoltageSetpoint, lowVoltageThreshold); + LOGGER.warn("Invalid low voltage setpoint {} < threshold {} for element {} of {}", + lowVoltageSetpoint, lowVoltageThreshold, + staticVarCompensator.getId(), + staticVarCompensator.getClass()); } if (highVoltageSetpoint > highVoltageThreshold) { - LOGGER.warn("Invalid high voltage setpoint {} > threshold {}", highVoltageSetpoint, highVoltageThreshold); + LOGGER.warn("Invalid high voltage setpoint {} > threshold {} for element {} of {}", + highVoltageSetpoint, highVoltageThreshold, + staticVarCompensator.getId(), + staticVarCompensator.getClass()); } } @@ -64,7 +92,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 +138,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 +152,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 +166,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 +180,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/StandbyAutomatonTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/StandbyAutomatonTest.java index 50943c1bff8..d2d0a3f9380 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 + public 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 element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + 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 element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + 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 element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + 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 element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + 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 element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + 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 element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + logsList.get(0).getFormattedMessage()); + assertEquals("Invalid high voltage setpoint 410.0 > threshold 405.0 for element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + logsList.get(1).getFormattedMessage()); + } } 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()); } } - } From 42a552a4a00ce1bee22ebc776ee8320a5a3c1abf Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 6 Dec 2023 10:02:37 +0100 Subject: [PATCH 2/7] change error messages to add more precise information + change relevant tests Signed-off-by: Nicolas Rol --- .../extensions/BusbarSectionPositionImpl.java | 15 ++++---- .../CoordinatedReactiveControlImpl.java | 3 +- .../GeneratorEntsoeCategoryImpl.java | 10 +++--- .../HvdcAngleDroopActivePowerControlImpl.java | 20 ++++++----- .../impl/extensions/LoadDetailImpl.java | 21 +++++------ .../extensions/ReferencePriorityImpl.java | 3 +- .../impl/extensions/StandbyAutomatonImpl.java | 35 ++++++++----------- .../tck/extensions/StandbyAutomatonTest.java | 14 ++++---- ...bstractCoordinatedReactiveControlTest.java | 2 +- ...AbstractHvdcAngleDroopActivePowerTest.java | 4 +-- .../AbstractReferencePrioritiesTest.java | 2 +- 11 files changed, 67 insertions(+), 62 deletions(-) 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..6b92ec26dcf 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..9a072151480 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 @@ -34,10 +34,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 +47,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 +59,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 +71,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 +83,15 @@ 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(errorMessage + " (%s) for load %s", + power, load.getId())); } return power; } 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..310e3c07574 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 should be zero or positive for ReferencePriority extension", + priority)); } 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 440e1ce1239..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 @@ -40,51 +40,44 @@ private static void checkVoltageConfig(double lowVoltageSetpoint, double highVol StaticVarCompensator staticVarCompensator) { if (Double.isNaN(lowVoltageSetpoint)) { throw new IllegalArgumentException( - String.format("lowVoltageSetpoint (%s) is invalid for element %s of %s", + String.format("lowVoltageSetpoint (%s) is invalid for StaticVarCompensator %s", lowVoltageSetpoint, - staticVarCompensator.getId(), - staticVarCompensator.getClass())); + staticVarCompensator.getId())); } if (Double.isNaN(highVoltageSetpoint)) { throw new IllegalArgumentException( - String.format("highVoltageSetpoint (%s) is invalid for element %s of %s", + String.format("highVoltageSetpoint (%s) is invalid for StaticVarCompensator %s", highVoltageSetpoint, - staticVarCompensator.getId(), - staticVarCompensator.getClass())); + staticVarCompensator.getId())); } if (Double.isNaN(lowVoltageThreshold)) { throw new IllegalArgumentException( - String.format("lowVoltageThreshold (%s) is invalid for element %s of %s", + String.format("lowVoltageThreshold (%s) is invalid for StaticVarCompensator %s", lowVoltageThreshold, - staticVarCompensator.getId(), - staticVarCompensator.getClass())); + staticVarCompensator.getId())); } if (Double.isNaN(highVoltageThreshold)) { throw new IllegalArgumentException( - String.format("highVoltageThreshold (%s) is invalid for element %s of %s", + String.format("highVoltageThreshold (%s) is invalid for StaticVarCompensator %s", highVoltageThreshold, - staticVarCompensator.getId(), - staticVarCompensator.getClass())); + staticVarCompensator.getId())); } if (lowVoltageThreshold >= highVoltageThreshold) { throw new IllegalArgumentException( - String.format("Inconsistent low (%s) and high (%s) voltage thresholds for element %s of %s", + String.format("Inconsistent low (%s) and high (%s) voltage thresholds for StaticVarCompensator %s", lowVoltageThreshold, highVoltageThreshold, - staticVarCompensator.getId(), - staticVarCompensator.getClass())); + staticVarCompensator.getId())); } if (lowVoltageSetpoint < lowVoltageThreshold) { - LOGGER.warn("Invalid low voltage setpoint {} < threshold {} for element {} of {}", + LOGGER.warn("Invalid low voltage setpoint {} < threshold {} for StaticVarCompensator {}", lowVoltageSetpoint, lowVoltageThreshold, - staticVarCompensator.getId(), - staticVarCompensator.getClass()); + staticVarCompensator.getId()); } if (highVoltageSetpoint > highVoltageThreshold) { - LOGGER.warn("Invalid high voltage setpoint {} > threshold {} for element {} of {}", + LOGGER.warn("Invalid high voltage setpoint {} > threshold {} for StaticVarCompensator {}", highVoltageSetpoint, highVoltageThreshold, - staticVarCompensator.getId(), - staticVarCompensator.getClass()); + staticVarCompensator.getId()); } } 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 d2d0a3f9380..fce61e47a40 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 @@ -44,7 +44,7 @@ public void checkVoltageConfigTest() { .withLowVoltageThreshold(385f) .withHighVoltageThreshold(350f); IllegalArgumentException e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); - assertEquals("Inconsistent low (385.0) and high (350.0) voltage thresholds for element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + assertEquals("Inconsistent low (385.0) and high (350.0) voltage thresholds for StaticVarCompensator SVC2", e0.getMessage()); // lowVoltageSetpoint invalid @@ -53,7 +53,7 @@ public void checkVoltageConfigTest() { .withLowVoltageThreshold(385f) .withHighVoltageThreshold(405f); e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); - assertEquals("lowVoltageSetpoint (NaN) is invalid for element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + assertEquals("lowVoltageSetpoint (NaN) is invalid for StaticVarCompensator SVC2", e0.getMessage()); // highVoltageSetpoint invalid @@ -62,7 +62,7 @@ public void checkVoltageConfigTest() { .withLowVoltageThreshold(385f) .withHighVoltageThreshold(405f); e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); - assertEquals("highVoltageSetpoint (NaN) is invalid for element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + assertEquals("highVoltageSetpoint (NaN) is invalid for StaticVarCompensator SVC2", e0.getMessage()); // lowVoltageSetpoint invalid @@ -71,7 +71,7 @@ public void checkVoltageConfigTest() { .withLowVoltageThreshold(Double.NaN) .withHighVoltageThreshold(405f); e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); - assertEquals("lowVoltageThreshold (NaN) is invalid for element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + assertEquals("lowVoltageThreshold (NaN) is invalid for StaticVarCompensator SVC2", e0.getMessage()); // highVoltageSetpoint invalid @@ -80,7 +80,7 @@ public void checkVoltageConfigTest() { .withLowVoltageThreshold(385f) .withHighVoltageThreshold(Double.NaN); e0 = assertThrows(IllegalArgumentException.class, standbyAutomatonAdder::add); - assertEquals("highVoltageThreshold (NaN) is invalid for element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + assertEquals("highVoltageThreshold (NaN) is invalid for StaticVarCompensator SVC2", e0.getMessage()); } @@ -117,9 +117,9 @@ void logsTests() { // Checks List logsList = logWatcher.list; assertEquals(2, logsList.size()); - assertEquals("Invalid low voltage setpoint 380.0 < threshold 385.0 for element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + 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 element SVC2 of class com.powsybl.iidm.network.impl.StaticVarCompensatorImpl", + 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..6e567cd0dc0 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 should be zero or positive for ReferencePriority extension", thrown.getMessage()); } @Test From b886c5c03ba567269fd4c65c0acfc1e465205d2b Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 6 Dec 2023 16:09:44 +0100 Subject: [PATCH 3/7] improve coverage Signed-off-by: Nicolas Rol --- .../GeneratorEntsoeCategoryImpl.java | 2 +- .../impl/extensions/LoadDetailImpl.java | 7 ++- .../BusbarSectionPositionImplTest.java | 58 +++++++++++++++++ .../GeneratorEntsoeCategoryTest.java | 63 +++++++++++++++++++ .../impl/tck/extensions/LoadDetailTest.java | 51 +++++++++++++++ .../tck/extensions/StandbyAutomatonTest.java | 2 +- 6 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/BusbarSectionPositionImplTest.java create mode 100644 iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/GeneratorEntsoeCategoryTest.java 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 6b92ec26dcf..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 @@ -19,7 +19,7 @@ public class GeneratorEntsoeCategoryImpl extends AbstractExtension im private static int checkCode(int code, Generator generator) { if (code < 1) { - throw new IllegalArgumentException(String.format("Bad generator ENTSO-E code %s for generator %s ", + throw new IllegalArgumentException(String.format("Bad generator ENTSO-E code %s for generator %s", code, generator.getId())); } 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 9a072151480..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; /** @@ -90,8 +89,10 @@ public LoadDetail setVariableReactivePower(double variableReactivePower) { private static double checkPower(double power, String errorMessage, Load load) { if (Double.isNaN(power)) { - throw new IllegalArgumentException(String.format(errorMessage + " (%s) for load %s", - power, load.getId())); + throw new IllegalArgumentException(String.format("%s (%s) for load %s", + errorMessage, + power, + load.getId())); } return power; } 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..00b9ab4665d --- /dev/null +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/extensions/BusbarSectionPositionImplTest.java @@ -0,0 +1,58 @@ +/* + * 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); + assertEquals(10, busbarSectionPosition.getBusbarIndex()); + } +} 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 fce61e47a40..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 @@ -28,7 +28,7 @@ class StandbyAutomatonTest extends AbstractStandbyAutomatonTest { @Test - public void checkVoltageConfigTest() { + void checkVoltageConfigTest() { Network network = SvcTestCaseFactory.create(); StaticVarCompensator svc = network.getStaticVarCompensator("SVC2"); assertNotNull(svc); From 877cf87f659f5e1086668fde2438e8a31beac760 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Wed, 6 Dec 2023 16:22:27 +0100 Subject: [PATCH 4/7] improved coverage Signed-off-by: Nicolas Rol --- .../impl/tck/extensions/BusbarSectionPositionImplTest.java | 2 ++ 1 file changed, 2 insertions(+) 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 index 00b9ab4665d..6cc0125a0ae 100644 --- 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 @@ -53,6 +53,8 @@ void testExtension() { // RIght busbar index busbarSectionPosition.setBusbarIndex(10); + busbarSectionPosition.setSectionIndex(5); assertEquals(10, busbarSectionPosition.getBusbarIndex()); + assertEquals(5, busbarSectionPosition.getSectionIndex()); } } From 3f208e9ffb55aaa1bde705f66332ee049710da4d Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Thu, 7 Dec 2023 14:26:28 +0100 Subject: [PATCH 5/7] delete redundant dependency call Signed-off-by: Nicolas Rol --- iidm/iidm-impl/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/iidm/iidm-impl/pom.xml b/iidm/iidm-impl/pom.xml index ece80a210a5..d1d32afea21 100644 --- a/iidm/iidm-impl/pom.xml +++ b/iidm/iidm-impl/pom.xml @@ -77,11 +77,6 @@ - - ch.qos.logback - logback-core - test - ch.qos.logback logback-classic From 8e3492756da5a74f43a23df15e216f14ac6c19b2 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Mon, 11 Dec 2023 11:35:58 +0100 Subject: [PATCH 6/7] improved error message for ReferencePriorities Signed-off-by: Nicolas Rol --- .../iidm/network/impl/extensions/ReferencePriorityImpl.java | 4 ++-- .../tck/extensions/AbstractReferencePrioritiesTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 310e3c07574..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,8 +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(String.format("Priority (%s) of terminal should be zero or positive for ReferencePriority extension", - priority)); + 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-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 6e567cd0dc0..afe8f901418 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 (-2) of terminal 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 From 70f23bd7ff3e4aef7ab124d39bb7bcd60d410ec2 Mon Sep 17 00:00:00 2001 From: Nicolas Rol Date: Tue, 12 Dec 2023 09:11:28 +0100 Subject: [PATCH 7/7] add connectable information in error message Signed-off-by: Nicolas Rol --- .../iidm/network/impl/extensions/ReferencePrioritiesImpl.java | 3 ++- .../tck/extensions/AbstractReferencePrioritiesTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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-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 afe8f901418..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 @@ -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()); } }