diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index 23782d754..c7ce19493 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -122,7 +122,7 @@ HvdcLine getHvdcLine(Network network, String hvdcLineId) { StaticVarCompensator staticVarCompensator(Network network, String staticVarCompensatorId) { StaticVarCompensator staticVarCompensator = network.getStaticVarCompensator(staticVarCompensatorId); if (staticVarCompensator == null) { - throw new NetworkModificationException(GENERATOR_NOT_FOUND, "Static var compensator " + staticVarCompensatorId + " does not exist in network"); + throw new NetworkModificationException(STATIC_VAR_COMPENSATOR_NOT_FOUND, "Static var compensator " + staticVarCompensatorId + " does not exist in network"); } return staticVarCompensator; } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java index c74aaba4f..2051f68db 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java @@ -30,7 +30,6 @@ public class StaticVarCompensatorCreation extends AbstractModification { private final StaticVarCompensatorCreationInfos modificationInfos; - private static final String REACTIVE_LIMITS = "Reactive limits"; private static final String CONNECTIVITY = "Connectivity"; public StaticVarCompensatorCreation(StaticVarCompensatorCreationInfos modificationInfos) { diff --git a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java index 3c2bd54e6..574e27104 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java @@ -25,8 +25,7 @@ import java.util.Map; import java.util.UUID; -import static org.gridsuite.modification.server.NetworkModificationException.Type.BUS_NOT_FOUND; -import static org.gridsuite.modification.server.NetworkModificationException.Type.EQUIPMENT_NOT_FOUND; +import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -63,7 +62,13 @@ protected ModificationInfos buildModification() { .voltageSetpoint(120.0) .reactivePowerSetpoint(300.0) .voltageRegulationType(VoltageRegulationType.LOCAL) - .standByAutomateOn(false) + .standByAutomateOn(true) + .standby(true) + .b0(221.0) + .lowVoltageSetpoint(200.0) + .highVoltageSetpoint(400.0) + .lowVoltageThreshold(250.0) + .highVoltageThreshold(300.0) .properties(List.of(FreePropertyInfos.builder().name(PROPERTY_NAME).value(PROPERTY_VALUE).build())) .build(); } @@ -74,13 +79,7 @@ protected ModificationInfos buildModificationUpdate() { .stashed(false) .equipmentId("idStaticVarCompensator2Edited") .equipmentName("staticVarCompensatorNameEdited") - .standByAutomateOn(true) - .standby(true) - .b0(221.0) - .lowVoltageSetpoint(200.0) - .highVoltageSetpoint(400.0) - .lowVoltageThreshold(250.0) - .highVoltageThreshold(300.0) + .voltageRegulationType(VoltageRegulationType.LOCAL) .regulatingTerminalId("idStaticVarCompensator1") .regulatingTerminalType("STATIC_VAR_COMPENSATOR") .regulatingTerminalVlId("v1") diff --git a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java index 6301d9617..995b4e573 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2022, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. @@ -24,6 +24,7 @@ import java.util.Optional; import java.util.UUID; +import static com.powsybl.iidm.network.StaticVarCompensator.RegulationMode.OFF; import static org.gridsuite.modification.server.NetworkModificationException.Type.BUSBAR_SECTION_NOT_FOUND; import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_LEVEL_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; @@ -79,6 +80,7 @@ protected ModificationInfos buildModificationUpdate() { .highVoltageSetpoint(400.0) .lowVoltageThreshold(250.0) .highVoltageThreshold(300.0) + .voltageRegulationType(VoltageRegulationType.DISTANT) .regulatingTerminalId("idStaticVarCompensator1") .regulatingTerminalType("STATIC_VAR_COMPENSATOR") .regulatingTerminalVlId("v2") @@ -130,17 +132,54 @@ public void testCreateWithErrors() throws Exception { // invalid min susceptance compensatorCreationInfos.setVoltageLevelId("v2"); - compensatorCreationInfos.setBusOrBusbarSectionId("1B"); - compensatorCreationInfos.setMinSusceptance(Double.NaN); + compensatorCreationInfos.setMinSusceptance(null); + compensatorCreationInfos.setMinQAtNominalV(null); + + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : StaticVarCompensator 'idStaticVarCompensator2' : minimum susceptance is not set", + compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setMinSusceptance(200.0); + compensatorCreationInfos.setMaxSusceptance(null); + compensatorCreationInfos.setMaxQAtNominalV(null); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : maximum susceptance is not set", + compensatorCreationInfos.getErrorType().name(), reportService); + + compensatorCreationInfos.setMaxSusceptance(100.0); + compensatorCreationInfos.setMinSusceptance(200.0); + compensatorCreationInfos.setRegulationMode(StaticVarCompensator.RegulationMode.REACTIVE_POWER); + compensatorCreationInfos.setReactivePowerSetpoint(null); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : maximum susceptance is expected to be greater than or equal to minimum susceptance", + compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setMaxSusceptance(200.0); + compensatorCreationInfos.setMinSusceptance(100.0); + compensatorCreationInfos.setRegulationMode(StaticVarCompensator.RegulationMode.REACTIVE_POWER); + compensatorCreationInfos.setReactivePowerSetpoint(null); compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); - assertLogMessage("Static var compensator 'idStaticVarCompensator2': bmin is invalid", + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : Reactive power setpoint is not set", compensatorCreationInfos.getErrorType().name(), reportService); - // Test create generator on not yet existing variant VARIANT_NOT_EXISTING_ID : - // Only the modification should be added in the database but the generator cannot be created + compensatorCreationInfos.setRegulationMode(StaticVarCompensator.RegulationMode.VOLTAGE); + compensatorCreationInfos.setVoltageSetpoint(null); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : Voltage setpoint is not set", + compensatorCreationInfos.getErrorType().name(), reportService); compensatorCreationInfos.setEquipmentId("idStaticVarCompensator3"); compensatorCreationInfos.setEquipmentName("nameStaticVarCompensator3"); compensatorCreationInfos.setVoltageLevelId("v2"); @@ -150,9 +189,9 @@ public void testCreateWithErrors() throws Exception { .andExpect(status().isOk()).andReturn(); Optional networkModificationResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); - assertTrue(networkModificationResult.isEmpty()); // no modifications returned - assertNull(getNetwork().getStaticVarCompensator("idStaticVarCompensator3")); // generator was not created - testNetworkModificationsCount(getGroupId(), 5); // new modification stored in the database + assertTrue(networkModificationResult.isEmpty()); + assertNull(getNetwork().getStaticVarCompensator("idStaticVarCompensator3")); + testNetworkModificationsCount(getGroupId(), 9); } @Test @@ -164,8 +203,21 @@ public void testCreateWithStandByAutomateErrors() throws Exception { String compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); - assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : StaticVarCompensator 'idStaticVarCompensator1' : b0 is expected to be within the range of minimun susceptance and maximum susceptance", + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator1' : b0 is expected to be within the range of minimun susceptance and maximum susceptance", compensatorCreationInfos.getErrorType().name(), reportService); + + compensatorCreationInfos.setB0(200.0); + compensatorCreationInfos.setRegulationMode(OFF); + compensatorCreationInfos.setStandby(true); + + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator1' : Regulation mode is expected to be voltage", + compensatorCreationInfos.getErrorType().name(), reportService); + } @Override