Skip to content

Commit a7a12c6

Browse files
authored
Use Voltage Level Deletion modification from powsybl (#209)
Signed-off-by: Etienne Homer <[email protected]>
1 parent e11dac4 commit a7a12c6

File tree

5 files changed

+71
-23
lines changed

5 files changed

+71
-23
lines changed

src/main/java/org/gridsuite/modification/server/modifications/EquipmentDeletion.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.powsybl.commons.reporter.Reporter;
1111
import com.powsybl.commons.reporter.TypedValue;
1212
import com.powsybl.iidm.modification.topology.RemoveFeederBay;
13+
import com.powsybl.iidm.modification.topology.RemoveVoltageLevel;
1314
import com.powsybl.iidm.network.*;
1415
import org.gridsuite.modification.server.NetworkModificationException;
1516
import org.gridsuite.modification.server.dto.EquipmentDeletionInfos;
@@ -38,7 +39,7 @@ public void apply(Network network, Reporter subReporter) {
3839
} else if (identifiable instanceof HvdcLine) {
3940
((HvdcLine) identifiable).remove();
4041
} else if (identifiable instanceof VoltageLevel) {
41-
((VoltageLevel) identifiable).remove();
42+
new RemoveVoltageLevel(modificationInfos.getEquipmentId()).apply(network, true, subReporter);
4243
} else if (identifiable instanceof Substation) {
4344
((Substation) identifiable).remove();
4445
}

src/test/java/org/gridsuite/modification/server/Impacts/TestImpactUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.gridsuite.modification.server.impacts.SimpleElementImpact.SimpleImpactType;
1818
import org.gridsuite.modification.server.utils.MatcherJson;
1919
import org.hamcrest.MatcherAssert;
20+
import org.skyscreamer.jsonassert.JSONAssert;
21+
import org.skyscreamer.jsonassert.JSONCompareMode;
2022

2123
import java.util.*;
2224
import java.util.stream.Collectors;
@@ -78,7 +80,7 @@ public static void testElementImpacts(ObjectMapper mapper, String resultAsString
7880
.applicationStatus(ApplicationStatus.ALL_OK)
7981
.networkImpacts(elementImpactsExpected)
8082
.build();
81-
assertThat(networkModificationResult.get(), new MatcherJson<>(mapper, resultExpected));
83+
JSONAssert.assertEquals(mapper.writeValueAsString(resultExpected), resultAsString, JSONCompareMode.NON_EXTENSIBLE);
8284
}
8385

8486
public static void testElementCreationImpact(ObjectMapper mapper, String resultAsString, IdentifiableType elementType, String elementId, Set<String> substationIds) {

src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -866,16 +866,8 @@ public void testTombstonedEquipmentInfos() {
866866
Pair.of(IdentifiableType.SHUNT_COMPENSATOR, "v5shunt"), Pair.of(IdentifiableType.STATIC_VAR_COMPENSATOR, "v5Compensator")),
867867
"s3"
868868
);
869-
testNetworkModificationsCount(TEST_GROUP_ID, 14);
870869

871-
// try to delete voltage level (Internal error because the vl is still connected)
872-
equipmentDeletionInfos.setEquipmentType(IdentifiableType.VOLTAGE_LEVEL.name());
873-
equipmentDeletionInfos.setEquipmentId("v4");
874-
mockMvc.perform(post(URI_NETWORK_MODIF).content(objectWriter.writeValueAsString(equipmentDeletionInfos)).contentType(MediaType.APPLICATION_JSON))
875-
.andExpect(status().isOk());
876-
assertNotNull(network.getVoltageLevel("v4"));
877-
assertLogMessage(new PowsyblException(new AssertionError("The voltage level 'v4' cannot be removed because of a remaining LINE")).getMessage(),
878-
equipmentDeletionInfos.getErrorType().name(), reportService);
870+
testNetworkModificationsCount(TEST_GROUP_ID, 14);
879871

880872
// delete substation
881873
equipmentDeletionInfos.setEquipmentType(IdentifiableType.SUBSTATION.name());
@@ -888,7 +880,7 @@ public void testTombstonedEquipmentInfos() {
888880
Pair.of(IdentifiableType.SHUNT_COMPENSATOR, "v6shunt"), Pair.of(IdentifiableType.STATIC_VAR_COMPENSATOR, "v6Compensator")),
889881
"s3");
890882
testSubstationDeletionImpacts(mvcResult.getResponse().getContentAsString(), "s3", vlDeletionImpacts);
891-
testNetworkModificationsCount(TEST_GROUP_ID, 16);
883+
testNetworkModificationsCount(TEST_GROUP_ID, 15);
892884

893885
// try to delete substation (Internal error because the substation is still connected)
894886
equipmentDeletionInfos.setEquipmentType(IdentifiableType.SUBSTATION.name());

src/test/java/org/gridsuite/modification/server/modifications/EquipmentDeletionTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package org.gridsuite.modification.server.modifications;
99

10-
import com.powsybl.commons.PowsyblException;
1110
import com.powsybl.iidm.network.Network;
1211
import lombok.SneakyThrows;
1312
import org.gridsuite.modification.server.NetworkModificationException;
@@ -95,16 +94,6 @@ public void testCreateWithErrors() {
9594
assertLogMessage(new NetworkModificationException(EQUIPMENT_NOT_FOUND, "Equipment with id=notFoundLoad not found or of bad type").getMessage(),
9695
equipmentDeletionInfos.getErrorType().name(), reportService);
9796

98-
// try to delete voltage level (Internal error because the vl is still connected)
99-
equipmentDeletionInfos.setEquipmentType("VOLTAGE_LEVEL");
100-
equipmentDeletionInfos.setEquipmentId("v4");
101-
mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(equipmentDeletionInfos)).contentType(MediaType.APPLICATION_JSON))
102-
.andExpect(status().isOk());
103-
assertLogMessage(new PowsyblException(new AssertionError("The voltage level 'v4' cannot be removed because of a remaining THREE_WINDINGS_TRANSFORMER")).getMessage(),
104-
equipmentDeletionInfos.getErrorType().name(), reportService);
105-
equipmentDeletionInfos.setEquipmentId("v4");
106-
assertNotNull(getNetwork().getVoltageLevel("v4"));
107-
10897
// try to delete substation (Internal error because the substation is still connected)
10998
equipmentDeletionInfos.setEquipmentType("SUBSTATION");
11099
equipmentDeletionInfos.setEquipmentId("s2");
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright (c) 2023, 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.Network;
10+
import org.gridsuite.modification.server.dto.EquipmentDeletionInfos;
11+
import org.gridsuite.modification.server.dto.ModificationInfos;
12+
import org.gridsuite.modification.server.utils.MatcherEquipmentDeletionInfos;
13+
import org.gridsuite.modification.server.utils.NetworkCreation;
14+
15+
import java.util.UUID;
16+
17+
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.Assert.assertNull;
19+
20+
/**
21+
* @author Etienne Homer <etienne.homer at rte-france.com>
22+
*/
23+
public class VoltageLevelDeletionTest extends AbstractNetworkModificationTest {
24+
@Override
25+
protected Network createNetwork(UUID networkUuid) {
26+
return NetworkCreation.create(networkUuid, true);
27+
}
28+
29+
@Override
30+
protected ModificationInfos buildModification() {
31+
return EquipmentDeletionInfos.builder()
32+
.equipmentType("VOLTAGE_LEVEL")
33+
.equipmentId("v1")
34+
.build();
35+
}
36+
37+
@Override
38+
protected ModificationInfos buildModificationUpdate() {
39+
return EquipmentDeletionInfos.builder()
40+
.equipmentType("LINE")
41+
.equipmentId("v2")
42+
.build();
43+
}
44+
45+
@Override
46+
protected MatcherEquipmentDeletionInfos createMatcher(ModificationInfos modificationInfos) {
47+
return MatcherEquipmentDeletionInfos.createMatcherEquipmentDeletionInfos((EquipmentDeletionInfos) modificationInfos);
48+
}
49+
50+
@Override
51+
protected void assertNetworkAfterCreation() {
52+
assertNull(getNetwork().getVoltageLevel("v1"));
53+
assertNull(getNetwork().getLoad("v1load"));
54+
assertNull(getNetwork().getLccConverterStation("v1lcc"));
55+
assertNull(getNetwork().getSwitch("v1d1"));
56+
assertNull(getNetwork().getLine("line2"));
57+
assertNull(getNetwork().getHvdcLine("hvdcLine"));
58+
}
59+
60+
@Override
61+
protected void assertNetworkAfterDeletion() {
62+
assertNotNull(getNetwork().getVoltageLevel("v1"));
63+
}
64+
}

0 commit comments

Comments
 (0)