diff --git a/src/main/java/org/gridsuite/modification/server/dto/VoltageInitModificationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/VoltageInitModificationInfos.java index 6a32c47d6..d17baf90e 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/VoltageInitModificationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/VoltageInitModificationInfos.java @@ -46,6 +46,9 @@ public class VoltageInitModificationInfos extends ModificationInfos { @Schema(description = "vsc converter station modifications") private List vscConverterStations; + @Schema(description = "shunt compensator modifications") + private List shuntCompensators; + @Override public ModificationEntity toEntity() { return new VoltageInitModificationEntity(this); diff --git a/src/main/java/org/gridsuite/modification/server/dto/VoltageInitShuntCompensatorModificationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/VoltageInitShuntCompensatorModificationInfos.java new file mode 100644 index 000000000..22496ca81 --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/dto/VoltageInitShuntCompensatorModificationInfos.java @@ -0,0 +1,34 @@ +/* + * 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/. + */ +package org.gridsuite.modification.server.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +/** + * @author Franck Lecuyer + */ +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@Schema(description = "Voltage init shunt compensator modification infos") +public class VoltageInitShuntCompensatorModificationInfos { + @Schema(description = "Shunt compensator id") + private String shuntCompensatorId; + + @Schema(description = "Section count") + private Integer sectionCount; + + @Schema(description = "Connexion") + private Boolean connect; +} diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageInitModificationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageInitModificationEntity.java index 47a13bda7..444c3dfce 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageInitModificationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageInitModificationEntity.java @@ -13,6 +13,7 @@ import org.gridsuite.modification.server.dto.VoltageInitGeneratorModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.VoltageInitShuntCompensatorModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitStaticVarCompensatorModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitTransformerModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitVscConverterStationModificationInfos; @@ -61,6 +62,12 @@ public class VoltageInitModificationEntity extends ModificationEntity { foreignKey = @ForeignKey(name = "VoltageInitModificationEntity_vsc_converter_stations_fk1")) private List vscConverterStations; + @ElementCollection + @CollectionTable(name = "voltageInitShuntCompensatorsModification", + indexes = {@Index(name = "VoltageInitModificationEntity_shunt_compensators_idx1", columnList = "voltage_init_modification_entity_id")}, + foreignKey = @ForeignKey(name = "VoltageInitModificationEntity_shunt_compensators_fk1")) + private List shuntCompensators; + public VoltageInitModificationEntity(VoltageInitModificationInfos voltageInitModificationInfos) { super(voltageInitModificationInfos); assignAttributes(voltageInitModificationInfos); @@ -77,6 +84,7 @@ private void assignAttributes(VoltageInitModificationInfos voltageInitModificati transformers = toEmbeddableVoltageInitTransformers(voltageInitModificationInfos.getTransformers()); staticVarCompensators = toEmbeddableVoltageInitStaticVarCompensators(voltageInitModificationInfos.getStaticVarCompensators()); vscConverterStations = toEmbeddableVoltageInitVscConverterStations(voltageInitModificationInfos.getVscConverterStations()); + shuntCompensators = toEmbeddableVoltageInitShuntCompensators(voltageInitModificationInfos.getShuntCompensators()); } public static List toEmbeddableVoltageInitGenerators(List generators) { @@ -131,6 +139,19 @@ private List toVscConverterStat .collect(Collectors.toList()) : null; } + public static List toEmbeddableVoltageInitShuntCompensators(List shuntCompensators) { + return shuntCompensators == null ? null : shuntCompensators.stream() + .map(shuntCompensator -> new VoltageInitShuntCompensatorModificationEmbeddable(shuntCompensator.getShuntCompensatorId(), shuntCompensator.getSectionCount(), shuntCompensator.getConnect())) + .collect(Collectors.toList()); + } + + private List toShuntCompensatorsModification(List shuntCompensators) { + return shuntCompensators != null ? shuntCompensators + .stream() + .map(shuntCompensator -> new VoltageInitShuntCompensatorModificationInfos(shuntCompensator.getShuntCompensatorId(), shuntCompensator.getSectionCount(), shuntCompensator.getConnect())) + .collect(Collectors.toList()) : null; + } + @Override public VoltageInitModificationInfos toModificationInfos() { return VoltageInitModificationInfos.builder() @@ -140,6 +161,7 @@ public VoltageInitModificationInfos toModificationInfos() { .transformers(toTransformersModification(transformers)) .staticVarCompensators(toStaticVarCompensatorsModification(staticVarCompensators)) .vscConverterStations(toVscConverterStationsModification(vscConverterStations)) + .shuntCompensators(toShuntCompensatorsModification(shuntCompensators)) .build(); } } diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageInitShuntCompensatorModificationEmbeddable.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageInitShuntCompensatorModificationEmbeddable.java new file mode 100644 index 000000000..64ce0dfa7 --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/modification/VoltageInitShuntCompensatorModificationEmbeddable.java @@ -0,0 +1,34 @@ +/** + * 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/. + */ + +package org.gridsuite.modification.server.entities.equipment.modification; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.Embeddable; + +/** + * @author Franck Lecuyer + */ + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Embeddable +public class VoltageInitShuntCompensatorModificationEmbeddable { + @Column + private String shuntCompensatorId; + + @Column + private Integer sectionCount; + + @Column + private Boolean connect; +} diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VoltageInitModification.java b/src/main/java/org/gridsuite/modification/server/modifications/VoltageInitModification.java index 2a6629d67..dbb2270f8 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VoltageInitModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VoltageInitModification.java @@ -13,13 +13,17 @@ import com.powsybl.commons.reporter.TypedValue; import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.ShuntCompensator; import com.powsybl.iidm.network.StaticVarCompensator; +import com.powsybl.iidm.network.Terminal; import com.powsybl.iidm.network.ThreeWindingsTransformer; import com.powsybl.iidm.network.TwoWindingsTransformer; import com.powsybl.iidm.network.VscConverterStation; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.VoltageInitModificationInfos; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_INIT_MODIFICATION_ERROR; @@ -38,6 +42,11 @@ public class VoltageInitModification extends AbstractModification { private static final String VSC_CONVERTER_STATION_MSG = "Vsc converter station "; private static final String VOLTAGE_SET_POINT = "Voltage set point"; private static final String REACTIVE_POWER_SET_POINT = "Reactive power set point"; + private static final String SHUNT_COMPENSATOR_MSG = "Shunt compensator "; + private static final String SECTION_COUNT = "Section count"; + private static final String SHUNT_SECTION_COUNT_VALUE_IGNORED_KEY = "shuntCompensatorSectionCountValueIgnored"; + private static final String SHUNT_SECTION_COUNT_VALUE_CANNOT_BE_APPLIED = "Section count value ${value} cannot be applied : it should be 0 or 1"; + private static final String VALUE = "value"; public VoltageInitModification(VoltageInitModificationInfos voltageInitModificationInfos) { this.voltageInitModificationInfos = voltageInitModificationInfos; @@ -51,14 +60,19 @@ public void check(Network network) throws NetworkModificationException { } private void report(Reporter reporter, String key, String defaultMessage, Map values, TypedValue severity) { + Report report = createReport(key, defaultMessage, values, severity, 0); + reporter.report(report); + } + + private Report createReport(String key, String defaultMessage, Map values, TypedValue severity, int indentationLevel) { ReportBuilder builder = Report.builder() .withKey(key) - .withDefaultMessage(defaultMessage) + .withDefaultMessage(" ".repeat(indentationLevel * 4) + defaultMessage) .withSeverity(severity); for (Map.Entry valueEntry : values.entrySet()) { builder.withValue(valueEntry.getKey(), valueEntry.getValue().toString()); } - reporter.report(builder.build()); + return builder.build(); } private void applyGeneratorModification(Network network, Reporter subReporter) { @@ -185,6 +199,65 @@ private void applyVscConverterStationModification(Network network, Reporter subR }); } + private void applyShuntCompensatorModification(Network network, Reporter subReporter) { + voltageInitModificationInfos.getShuntCompensators().forEach(m -> { + ShuntCompensator shuntCompensator = network.getShuntCompensator(m.getShuntCompensatorId()); + if (shuntCompensator == null) { + Reporter reporter = subReporter.createSubReporter(SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId(), SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId()); + report(reporter, "shuntCompensatorNotFound", "Shunt compensator with id=${id} not found", Map.of("id", m.getShuntCompensatorId()), TypedValue.WARN_SEVERITY); + return; + } + if (m.getSectionCount() != null || m.getConnect() != null) { + List reports = new ArrayList<>(); + + int currentSectionCount = shuntCompensator.getSectionCount(); + + Terminal shuntCompensatorTerminal = shuntCompensator.getTerminal(); + if (shuntCompensatorTerminal.isConnected()) { // shunt compensator is connected + if (m.getSectionCount() == null) { + reports.add(createReport("shuntCompensatorSectionCountUndefined", "Section count value is undefined", Map.of(), TypedValue.WARN_SEVERITY, 1)); + } else if (m.getSectionCount() > 1) { + reports.add(createReport(SHUNT_SECTION_COUNT_VALUE_IGNORED_KEY, SHUNT_SECTION_COUNT_VALUE_CANNOT_BE_APPLIED, Map.of(VALUE, m.getSectionCount()), TypedValue.WARN_SEVERITY, 1)); + } else if (currentSectionCount > 1) { + reports.add(createReport("shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of(VALUE, currentSectionCount), TypedValue.WARN_SEVERITY, 1)); + } else { + if (m.getSectionCount() == 0) { + shuntCompensatorTerminal.disconnect(); + reports.add(createReport("shuntCompensatorDisconnected", "Shunt compensator disconnected", Map.of(), TypedValue.INFO_SEVERITY, 1)); + } + if (m.getSectionCount() != currentSectionCount) { + shuntCompensator.setSectionCount(m.getSectionCount()); + reports.add(ModificationUtils.getInstance().buildModificationReportWithIndentation(currentSectionCount, m.getSectionCount(), SECTION_COUNT, 1)); + } + } + } else { // shunt compensator is disconnected + if (m.getConnect() == null) { + reports.add(createReport("shuntCompensatorConnectUndefined", "Connect value is undefined", Map.of(), TypedValue.WARN_SEVERITY, 1)); + } else if (m.getSectionCount() > 1) { + reports.add(createReport(SHUNT_SECTION_COUNT_VALUE_IGNORED_KEY, SHUNT_SECTION_COUNT_VALUE_CANNOT_BE_APPLIED, Map.of(VALUE, m.getSectionCount()), TypedValue.WARN_SEVERITY, 1)); + } else if (currentSectionCount > 1) { + reports.add(createReport("shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of(VALUE, currentSectionCount), TypedValue.WARN_SEVERITY, 1)); + } else { + if (Boolean.TRUE.equals(m.getConnect()) && m.getSectionCount() == 1) { + shuntCompensatorTerminal.connect(); + reports.add(createReport("shuntCompensatorReconnected", "Shunt compensator reconnected", Map.of(), TypedValue.INFO_SEVERITY, 1)); + } + if (m.getSectionCount() != currentSectionCount) { + shuntCompensator.setSectionCount(m.getSectionCount()); + reports.add(ModificationUtils.getInstance().buildModificationReportWithIndentation(currentSectionCount, m.getSectionCount(), SECTION_COUNT, 1)); + } + } + } + + if (!reports.isEmpty()) { + Reporter reporter = subReporter.createSubReporter(SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId(), SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId()); + report(reporter, "shuntCompensatorModification", "Shunt compensator with id=${id} modified :", Map.of("id", m.getShuntCompensatorId()), TypedValue.INFO_SEVERITY); + reports.forEach(reporter::report); + } + } + }); + } + @Override public void apply(Network network, Reporter subReporter) { // apply generators modifications @@ -198,5 +271,8 @@ public void apply(Network network, Reporter subReporter) { // apply vsc converter stations modifications applyVscConverterStationModification(network, subReporter); + + // apply shunt compensators modifications + applyShuntCompensatorModification(network, subReporter); } } diff --git a/src/main/resources/db/changelog/changesets/changelog_20230907T121742Z.xml b/src/main/resources/db/changelog/changesets/changelog_20230907T121742Z.xml new file mode 100644 index 000000000..d2d6f2874 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20230907T121742Z.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 6a453045c..c7c8a0200 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -191,4 +191,7 @@ databaseChangeLog: relativeToChangelogFile: true - include: file: changesets/changelog_20230816T150718Z.xml + relativeToChangelogFile: true + - include: + file: changesets/changelog_20230907T121742Z.xml relativeToChangelogFile: true \ No newline at end of file diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index 1e800d2c8..a6b4733ec 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -1261,6 +1261,22 @@ public void testCreateVoltageInitModification() throws Exception { .vscConverterStationId("VSC2") .voltageSetpoint(224.) .build())) + .shuntCompensators(List.of( + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v2shunt") + .sectionCount(1) + .connect(true) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v5shunt") + .sectionCount(0) + .connect(false) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v6shunt") + .sectionCount(1) + .connect(false) + .build())) .build(); MvcResult mvcResult = mockMvc.perform(post("/v1/groups/modification") diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java index 5752df598..876593409 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java @@ -16,18 +16,24 @@ import org.gridsuite.modification.server.dto.VoltageInitGeneratorModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.VoltageInitShuntCompensatorModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitStaticVarCompensatorModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitTransformerModificationInfos; import org.gridsuite.modification.server.dto.VoltageInitVscConverterStationModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; +import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.springframework.http.MediaType; import java.util.List; import java.util.UUID; import static org.gridsuite.modification.server.utils.NetworkUtil.createGenerator; import static org.gridsuite.modification.server.utils.NetworkUtil.createSwitch; +import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.junit.Assert.assertEquals; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * @author Franck Lecuyer @@ -78,6 +84,10 @@ protected Network createNetwork(UUID networkUuid) { .endStep() .add(); + network.getShuntCompensator("v2shunt").setSectionCount(1); + network.getShuntCompensator("v5shunt").setSectionCount(0); + network.getShuntCompensator("v6shunt").setSectionCount(0); + return network; } @@ -151,6 +161,27 @@ protected ModificationInfos buildModification() { .vscConverterStationId("vscNotFound") .voltageSetpoint(218.) .build())) + .shuntCompensators(List.of( + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v2shunt") + .sectionCount(1) + .connect(true) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v5shunt") + .sectionCount(0) + .connect(true) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v6shunt") + .sectionCount(1) + .connect(false) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("shuntNotFound") + .sectionCount(1) + .connect(false) + .build())) .build(); } @@ -194,19 +225,165 @@ protected ModificationInfos buildModificationUpdate() { .vscConverterStationId("v2vsc") .reactivePowerSetpoint(46.) .build())) + .shuntCompensators(List.of( + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v2shunt") + .sectionCount(0) + .connect(false) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v5shunt") + .sectionCount(1) + .connect(true) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v6shunt") + .sectionCount(0) + .connect(false) + .build())) + .build(); + } + + private void testVoltageInitShunt(String shuntCompensatorId, int currentSectionCount, Integer sectionCount, Boolean connect) throws Exception { + setNetwork(createNetwork(getNetworkId())); + getNetwork().getShuntCompensator(shuntCompensatorId).setSectionCount(currentSectionCount); + + VoltageInitModificationInfos modification = VoltageInitModificationInfos.builder() + .generators(List.of()) + .transformers(List.of()) + .staticVarCompensators(List.of()) + .vscConverterStations(List.of()) + .shuntCompensators(List.of( + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId(shuntCompensatorId) + .sectionCount(sectionCount) + .connect(connect) + .build())) .build(); + + mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(modification)).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + } + + @Test + public void testVoltageInitConnectedSectionCountNull() throws Exception { + testVoltageInitShunt("v2shunt", 0, null, false); + assertLogMessage("Section count value is undefined", "shuntCompensatorSectionCountUndefined", reportService); + } + + @Test + public void testVoltageInitConnectedCurrentSection0Section0() throws Exception { + testVoltageInitShunt("v2shunt", 0, 0, false); + assertLogMessage("Shunt compensator disconnected", "shuntCompensatorDisconnected", reportService); + } + + @Test + public void testVoltageInitConnectedCurrentSection0Section1() throws Exception { + testVoltageInitShunt("v2shunt", 0, 1, false); + assertEquals(1, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); + } + + @Test + public void testVoltageInitConnectedCurrentSection0Section2() throws Exception { + testVoltageInitShunt("v2shunt", 0, 2, false); + assertLogMessage("Section count value 2 cannot be applied : it should be 0 or 1", "shuntCompensatorSectionCountValueIgnored", reportService); + assertEquals(0, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); + } + + @Test + public void testVoltageInitConnectedCurrentSection1Section0() throws Exception { + testVoltageInitShunt("v2shunt", 1, 0, false); + assertLogMessage("Shunt compensator disconnected", "shuntCompensatorDisconnected", reportService); + assertEquals(0, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); + } + + @Test + public void testVoltageInitConnectedCurrentSection1Section1() throws Exception { + testVoltageInitShunt("v2shunt", 1, 1, false); + assertEquals(1, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); + } + + @Test + public void testVoltageInitConnectedCurrentSection1Section2() throws Exception { + testVoltageInitShunt("v2shunt", 1, 2, false); + assertLogMessage("Section count value 2 cannot be applied : it should be 0 or 1", "shuntCompensatorSectionCountValueIgnored", reportService); + assertEquals(1, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); + } + + @Test + public void testVoltageInitDisconnectedConnectNull() throws Exception { + testVoltageInitShunt("v5shunt", 0, 0, null); + assertLogMessage("Connect value is undefined", "shuntCompensatorConnectUndefined", reportService); + } + + @Test + public void testVoltageInitDisconnectedCurrentSection0Section0() throws Exception { + testVoltageInitShunt("v5shunt", 0, 0, true); + assertEquals(0, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); + } + + @Test + public void testVoltageInitDisconnectedCurrentSection0Section1() throws Exception { + testVoltageInitShunt("v5shunt", 0, 1, true); + assertLogMessage("Shunt compensator reconnected", "shuntCompensatorReconnected", reportService); + assertEquals(1, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); + } + + @Test + public void testVoltageInitDisconnectedCurrentSection0Section2() throws Exception { + testVoltageInitShunt("v5shunt", 0, 2, true); + assertLogMessage("Section count value 2 cannot be applied : it should be 0 or 1", "shuntCompensatorSectionCountValueIgnored", reportService); + assertEquals(0, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); + } + + @Test + public void testVoltageInitDisconnectedCurrentSection1Section0() throws Exception { + testVoltageInitShunt("v5shunt", 1, 0, true); + assertEquals(0, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); + } + + @Test + public void testVoltageInitDisconnectedCurrentSection1Section1() throws Exception { + testVoltageInitShunt("v5shunt", 1, 1, true); + assertLogMessage("Shunt compensator reconnected", "shuntCompensatorReconnected", reportService); + assertEquals(1, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); + } + + @Test + public void testVoltageInitDisconnectedCurrentSection1Section2() throws Exception { + testVoltageInitShunt("v5shunt", 1, 2, true); + assertLogMessage("Section count value 2 cannot be applied : it should be 0 or 1", "shuntCompensatorSectionCountValueIgnored", reportService); + assertEquals(1, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); } @Override protected void assertAfterNetworkModificationCreation() { + assertLogMessage("Shunt compensator with id=shuntNotFound not found", "shuntCompensatorNotFound", reportService); assertEquals(10., getNetwork().getGenerator("idGenerator").getTargetQ(), 0.001); assertEquals(226., getNetwork().getGenerator("newGen").getTargetV(), 0.001); - + assertEquals(2, getNetwork().getTwoWindingsTransformer("trf1").getRatioTapChanger().getTapPosition()); + assertEquals(2, getNetwork().getThreeWindingsTransformer("trf6").getLeg2().getRatioTapChanger().getTapPosition()); + assertEquals(50., getNetwork().getStaticVarCompensator("v5Compensator").getReactivePowerSetpoint(), 0.001); + assertEquals(372., getNetwork().getStaticVarCompensator("v6Compensator").getVoltageSetpoint(), 0.001); + assertEquals(23., getNetwork().getVscConverterStation("v2vsc").getReactivePowerSetpoint(), 0.001); + assertEquals(560., getNetwork().getVscConverterStation("v2vsc").getVoltageSetpoint(), 0.001); + assertEquals(1, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); + assertEquals(0, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); + assertEquals(1, getNetwork().getShuntCompensator("v6shunt").getSectionCount()); } @Override protected void assertAfterNetworkModificationDeletion() { assertEquals(1., getNetwork().getGenerator("idGenerator").getTargetQ(), 0.001); assertEquals(224., getNetwork().getGenerator("newGen").getTargetV(), 0.001); + assertEquals(1, getNetwork().getTwoWindingsTransformer("trf1").getRatioTapChanger().getTapPosition()); + assertEquals(1, getNetwork().getThreeWindingsTransformer("trf6").getLeg2().getRatioTapChanger().getTapPosition()); + assertEquals(100., getNetwork().getStaticVarCompensator("v5Compensator").getReactivePowerSetpoint(), 0.001); + assertEquals(380., getNetwork().getStaticVarCompensator("v6Compensator").getVoltageSetpoint(), 0.001); + assertEquals(40., getNetwork().getVscConverterStation("v2vsc").getReactivePowerSetpoint(), 0.001); + assertEquals(150., getNetwork().getVscConverterStation("v2vsc").getVoltageSetpoint(), 0.001); + assertEquals(1, getNetwork().getShuntCompensator("v2shunt").getSectionCount()); + assertEquals(0, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); + assertEquals(0, getNetwork().getShuntCompensator("v6shunt").getSectionCount()); } } diff --git a/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java b/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java index b25db29b4..736aa72a9 100644 --- a/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java +++ b/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java @@ -1105,10 +1105,26 @@ public void testVoltageInitModification() { .vscConverterStationId("VSC2") .voltageSetpoint(224.) .build())) + .shuntCompensators(List.of( + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v2shunt") + .sectionCount(1) + .connect(true) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v5shunt") + .sectionCount(0) + .connect(false) + .build(), + VoltageInitShuntCompensatorModificationInfos.builder() + .shuntCompensatorId("v6shunt") + .sectionCount(1) + .connect(false) + .build())) .build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(voltageInitModificationEntity)); - assertRequestsCount(1, 11, 1, 0); + assertRequestsCount(1, 14, 1, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(1, modificationInfos.size()); @@ -1120,7 +1136,7 @@ public void testVoltageInitModification() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(voltageInitModificationEntity.getId())); - assertRequestsCount(2, 0, 0, 6); + assertRequestsCount(2, 0, 0, 7); SQLStatementCountValidator.reset(); assertEquals(0, networkModificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); diff --git a/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java b/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java index 5b1d2a7b4..aa84cddb8 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java +++ b/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java @@ -139,7 +139,7 @@ public static void assertLogNthMessage(String expectedMessage, String reportKey, assertNotNull(reporterCaptor.getValue()); Optional message = getMessageFromReporter(reportKey, reporterCaptor.getValue(), rank); assertTrue(message.isPresent()); - assertEquals(expectedMessage, message.get()); + assertEquals(expectedMessage, message.get().trim()); } public static void assertLogMessage(String expectedMessage, String reportKey, ReportService reportService) {