|
| 1 | +/** |
| 2 | + * Copyright (c) 2025, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | +package org.gridsuite.modification.server.modifications; |
| 8 | + |
| 9 | +import com.powsybl.iidm.network.BusbarSection; |
| 10 | +import com.powsybl.iidm.network.Network; |
| 11 | +import com.powsybl.iidm.network.extensions.BusbarSectionPosition; |
| 12 | +import com.powsybl.iidm.network.extensions.BusbarSectionPositionAdder; |
| 13 | +import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; |
| 14 | +import org.gridsuite.modification.dto.CreateVoltageLevelSectionInfos; |
| 15 | +import org.gridsuite.modification.dto.ModificationInfos; |
| 16 | +import org.gridsuite.modification.server.utils.NetworkCreation; |
| 17 | + |
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.List; |
| 20 | +import java.util.UUID; |
| 21 | + |
| 22 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 24 | + |
| 25 | +/** |
| 26 | + * @author Rehili Ghazwa <ghazwa.rehili at rte-france.com> |
| 27 | + */ |
| 28 | +class CreateVoltageLevelSectionTest extends AbstractNetworkModificationTest { |
| 29 | + |
| 30 | + @Override |
| 31 | + protected Network createNetwork(UUID networkUuid) { |
| 32 | + Network network = NetworkCreation.createSwitchNetwork(networkUuid, new NetworkFactoryImpl()); |
| 33 | + network.getVoltageLevel("vl1").getNodeBreakerView().getBusbarSectionStream().forEach(busbarSection -> { |
| 34 | + if (busbarSection.getExtension(BusbarSectionPosition.class) == null) { |
| 35 | + busbarSection.newExtension(BusbarSectionPositionAdder.class) |
| 36 | + .withBusbarIndex(1) |
| 37 | + .withSectionIndex(1) |
| 38 | + .add(); |
| 39 | + } |
| 40 | + }); |
| 41 | + BusbarSection b3 = network.getVoltageLevel("vl1") |
| 42 | + .getNodeBreakerView() |
| 43 | + .newBusbarSection() |
| 44 | + .setId("b3") |
| 45 | + .setName("b3") |
| 46 | + .setNode(15) |
| 47 | + .add(); |
| 48 | + b3.newExtension(BusbarSectionPositionAdder.class) |
| 49 | + .withBusbarIndex(1) |
| 50 | + .withSectionIndex(1) |
| 51 | + .add(); |
| 52 | + |
| 53 | + BusbarSection b9 = network.getVoltageLevel("vl1") |
| 54 | + .getNodeBreakerView() |
| 55 | + .newBusbarSection() |
| 56 | + .setId("b9") |
| 57 | + .setName("b9") |
| 58 | + .setNode(20) |
| 59 | + .add(); |
| 60 | + b9.newExtension(BusbarSectionPositionAdder.class) |
| 61 | + .withBusbarIndex(1) |
| 62 | + .withSectionIndex(1) |
| 63 | + .add(); |
| 64 | + |
| 65 | + return network; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + protected ModificationInfos buildModification() { |
| 70 | + return CreateVoltageLevelSectionInfos.builder() |
| 71 | + .stashed(false) |
| 72 | + .voltageLevelId("vl1") |
| 73 | + .busbarSectionId("b3") |
| 74 | + .busbarIndex(1) |
| 75 | + .isAfterBusbarSectionId(true) |
| 76 | + .leftSwitchKind("BREAKER") |
| 77 | + .rightSwitchKind("DISCONNECTOR") |
| 78 | + .isAllBusbars(false) |
| 79 | + .isSwitchOpen(false) |
| 80 | + .build(); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + protected ModificationInfos buildModificationUpdate() { |
| 85 | + return CreateVoltageLevelSectionInfos.builder() |
| 86 | + .voltageLevelId("vl1") |
| 87 | + .busbarSectionId("b3") |
| 88 | + .busbarIndex(1) |
| 89 | + .isAfterBusbarSectionId(true) |
| 90 | + .leftSwitchKind("DISCONNECTOR") |
| 91 | + .rightSwitchKind("DISCONNECTOR") |
| 92 | + .isAllBusbars(false) |
| 93 | + .isSwitchOpen(false) |
| 94 | + .build(); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + protected void assertAfterNetworkModificationCreation() { |
| 99 | + List<String> busBarIds = new ArrayList<>(); |
| 100 | + getNetwork().getBusbarSections().forEach(busbarSection -> busBarIds.add(busbarSection.getId())); |
| 101 | + assertTrue(busBarIds.size() > 4); |
| 102 | + assertTrue(busBarIds.containsAll(List.of("b1", "b2", "b3", "b9", "vl1_1_2"))); |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + protected void assertAfterNetworkModificationDeletion() { |
| 107 | + List<String> busBarIds = new ArrayList<>(); |
| 108 | + getNetwork().getBusbarSections().forEach(busbarSection -> busBarIds.add(busbarSection.getId())); |
| 109 | + assertEquals(4, busBarIds.size()); |
| 110 | + assertTrue(busBarIds.containsAll(List.of("b1", "b2", "b3", "b9"))); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + protected void testCreationModificationMessage(ModificationInfos modificationInfos) { |
| 115 | + assertEquals("{\"voltageLevelId\":\"vl1\"}", modificationInfos.getMessageValues()); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { |
| 120 | + assertEquals("{\"voltageLevelId\":\"vl1\"}", modificationInfos.getMessageValues()); |
| 121 | + } |
| 122 | +} |
0 commit comments