From 8af820d72503f9d7eb784ccf8a58acc824ea7872 Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 5 Nov 2024 15:55:16 +0100 Subject: [PATCH 1/3] Add unit test Signed-off-by: Florian Dupuy --- .../sld/iidm/TestCaseBusDisconnected.java | 77 +++++ .../TestCaseBusBreakerBusConnected.svg | 262 ++++++++++++++++++ .../TestCaseNodeBreakerBbsConnected.svg | 236 ++++++++++++++++ 3 files changed, 575 insertions(+) create mode 100644 single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java create mode 100644 single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg create mode 100644 single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseNodeBreakerBbsConnected.svg diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java new file mode 100644 index 000000000..eebcab524 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java @@ -0,0 +1,77 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.sld.iidm; + +import com.powsybl.diagram.test.Networks; +import com.powsybl.iidm.network.*; +import com.powsybl.sld.builders.NetworkGraphBuilder; +import com.powsybl.sld.library.ConvergenceComponentLibrary; +import com.powsybl.sld.library.FlatDesignLibrary; +import com.powsybl.sld.model.graphs.VoltageLevelGraph; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author Florian Dupuy {@literal } + */ +class TestCaseBusDisconnected extends AbstractTestCaseIidm { + + + @BeforeEach + @Override + public void setUp() throws IOException { + network = Network.create("testCaseBusNodeDisconnected", "testCaseBusNodeDisconnected"); + graphBuilder = new NetworkGraphBuilder(network); + substation = Networks.createSubstation(network, "s", "s", Country.FR); + + // bus breaker topology + VoltageLevel vlBb = Networks.createVoltageLevel(substation, "vlBb", "vlBb", TopologyKind.BUS_BREAKER, 225); + Bus b1 = vlBb.getBusBreakerView().newBus().setId("b1").add(); + Bus b2 = vlBb.getBusBreakerView().newBus().setId("b2").add(); + Bus b3 = vlBb.getBusBreakerView().newBus().setId("b3").add(); + vlBb.getBusBreakerView().newSwitch().setId("s12").setBus1(b1.getId()).setBus2(b2.getId()).add(); + vlBb.getBusBreakerView().newSwitch().setId("s23").setOpen(true).setBus1(b2.getId()).setBus2(b3.getId()).add(); + + // node breaker topology + VoltageLevel vlNb = Networks.createVoltageLevel(substation, "vlNb", "vlNb", TopologyKind.NODE_BREAKER, 225); + vlNb.getNodeBreakerView().newBusbarSection().setId("bbs1").setNode(0).add(); + vlNb.getNodeBreakerView().newBusbarSection().setId("bbs2").setNode(1).add(); + vlNb.getNodeBreakerView().newSwitch().setId("sLine").setKind(SwitchKind.DISCONNECTOR).setNode1(0).setNode2(2).add(); + vlNb.getNodeBreakerView().newSwitch().setId("sLoad").setOpen(true).setKind(SwitchKind.DISCONNECTOR).setNode1(1).setNode2(3).add(); + vlNb.newLoad().setNode(3).setId("load").setP0(10).setQ0(10).add(); + + network.newLine().setId("line") + .setG1(0).setB1(0).setVoltageLevel1(vlBb.getId()).setBus1(b2.getId()) + .setG2(0).setB2(0).setVoltageLevel2(vlNb.getId()).setNode2(2) + .setR(1).setX(1) + .add(); + } + + @ParameterizedTest(name = "{1}") + @MethodSource("provideTestData") + void test(String testName, String vlId, String svgResourceName) { + VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vlId); + voltageLevelGraphLayout(g); + assertEquals(toString(svgResourceName), toSVG(g, svgResourceName)); + } + + private static List provideTestData() { + return List.of( + Arguments.of("Test bus connected/disconnected in bus breaker topology", "vlBb", "/TestCaseBusBreakerBusConnected.svg"), + Arguments.of("Test bus connected/disconnected in node breaker topology", "vlNb", "/TestCaseNodeBreakerBbsConnected.svg") + ); + } +} diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg new file mode 100644 index 000000000..f689063d2 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg @@ -0,0 +1,262 @@ + + + + + + + + b1 + + + + b2 + + + + b3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + line + + + + diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseNodeBreakerBbsConnected.svg b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseNodeBreakerBbsConnected.svg new file mode 100644 index 000000000..6450d7108 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseNodeBreakerBbsConnected.svg @@ -0,0 +1,236 @@ + + + + + + + + bbs1 + + + + bbs2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + line + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + load + + + + From 3d84c1ee72481237aa1c445d501215228f23ae84 Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 5 Nov 2024 16:30:02 +0100 Subject: [PATCH 2/3] Fix the bus breaker connection check Signed-off-by: Florian Dupuy --- .../svg/styles/iidm/HighlightLineStateStyleProvider.java | 2 +- .../java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java | 6 +++--- .../src/test/resources/TestCaseBusBreakerBusConnected.svg | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/iidm/HighlightLineStateStyleProvider.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/iidm/HighlightLineStateStyleProvider.java index b4f1af68f..0c8cdc489 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/iidm/HighlightLineStateStyleProvider.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/iidm/HighlightLineStateStyleProvider.java @@ -57,7 +57,7 @@ private boolean isBusOrBbsConnected(BusNode busNode) { } else { Bus bus = network.getBusBreakerView().getBus(equipmentId); if (bus != null) { - return bus.getConnectedTerminalStream().anyMatch(Terminal::isConnected); + return bus.getVoltageLevel().getBusView().getMergedBus(bus.getId()) != null; } return true; // should not happen } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java index eebcab524..d1da3e03d 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java @@ -60,7 +60,7 @@ public void setUp() throws IOException { .add(); } - @ParameterizedTest(name = "{1}") + @ParameterizedTest(name = "{0}") @MethodSource("provideTestData") void test(String testName, String vlId, String svgResourceName) { VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vlId); @@ -70,8 +70,8 @@ void test(String testName, String vlId, String svgResourceName) { private static List provideTestData() { return List.of( - Arguments.of("Test bus connected/disconnected in bus breaker topology", "vlBb", "/TestCaseBusBreakerBusConnected.svg"), - Arguments.of("Test bus connected/disconnected in node breaker topology", "vlNb", "/TestCaseNodeBreakerBbsConnected.svg") + Arguments.of("Test bus connected/disconnected", "vlBb", "/TestCaseBusBreakerBusConnected.svg"), + Arguments.of("Test busbarSection connected/disconnected", "vlNb", "/TestCaseNodeBreakerBbsConnected.svg") ); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg index f689063d2..d6abdaa57 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCaseBusBreakerBusConnected.svg @@ -153,7 +153,7 @@ ]]> - + b1 From ae343ea11d4968929dc277a340e8be82f3b0558f Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 5 Nov 2024 16:46:48 +0100 Subject: [PATCH 3/3] Fix checkstyle Signed-off-by: Florian Dupuy --- .../java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java index d1da3e03d..0e490e11c 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseBusDisconnected.java @@ -10,11 +10,8 @@ import com.powsybl.diagram.test.Networks; import com.powsybl.iidm.network.*; import com.powsybl.sld.builders.NetworkGraphBuilder; -import com.powsybl.sld.library.ConvergenceComponentLibrary; -import com.powsybl.sld.library.FlatDesignLibrary; import com.powsybl.sld.model.graphs.VoltageLevelGraph; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -29,7 +26,6 @@ */ class TestCaseBusDisconnected extends AbstractTestCaseIidm { - @BeforeEach @Override public void setUp() throws IOException {