|
| 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 | + |
| 8 | +package org.gridsuite.modification.server.modifications.tabularmodifications; |
| 9 | + |
| 10 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 11 | +import com.powsybl.iidm.network.Country; |
| 12 | +import com.powsybl.iidm.network.Network; |
| 13 | +import lombok.SneakyThrows; |
| 14 | +import org.gridsuite.modification.server.dto.*; |
| 15 | +import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; |
| 16 | +import org.gridsuite.modification.server.utils.NetworkCreation; |
| 17 | +import org.junit.jupiter.api.Assertions; |
| 18 | +import org.junit.jupiter.api.Tag; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | +import java.util.UUID; |
| 23 | + |
| 24 | +import static org.junit.Assert.assertEquals; |
| 25 | + |
| 26 | +/** |
| 27 | + * @author AJELLAL Ali <[email protected]> |
| 28 | + */ |
| 29 | +@Tag("IntegrationTest") |
| 30 | +public class TabularSubstationModificationsTest extends AbstractNetworkModificationTest { |
| 31 | + public static final String MODIFICATION_TYPE = "SUBSTATION_MODIFICATION"; |
| 32 | + |
| 33 | + @Override |
| 34 | + protected Network createNetwork(UUID networkUuid) { |
| 35 | + return NetworkCreation.create(networkUuid, true); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + protected ModificationInfos buildModification() { |
| 40 | + |
| 41 | + List<ModificationInfos> modifications = List.of( |
| 42 | + SubstationModificationInfos.builder().equipmentId("s1").equipmentName(new AttributeModification<>("s1", OperationType.SET)).substationCountry(new AttributeModification<>(Country.BE, OperationType.SET)).build(), |
| 43 | + SubstationModificationInfos.builder().equipmentId("s2").equipmentName(new AttributeModification<>("s2", OperationType.SET)).substationCountry(new AttributeModification<>(Country.BE, OperationType.SET)).build() |
| 44 | + ); |
| 45 | + return TabularModificationInfos.builder() |
| 46 | + .modificationType(MODIFICATION_TYPE) |
| 47 | + .modifications(modifications) |
| 48 | + .stashed(false) |
| 49 | + .build(); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + protected ModificationInfos buildModificationUpdate() { |
| 54 | + List<ModificationInfos> modifications = List.of( |
| 55 | + SubstationModificationInfos.builder().equipmentId("s1").equipmentName(new AttributeModification<>("s1", OperationType.SET)).substationCountry(new AttributeModification<>(Country.JP, OperationType.SET)).build(), |
| 56 | + SubstationModificationInfos.builder().equipmentId("s2").equipmentName(new AttributeModification<>("s2", OperationType.SET)).substationCountry(new AttributeModification<>(Country.JP, OperationType.SET)).build() |
| 57 | + ); |
| 58 | + return TabularModificationInfos.builder() |
| 59 | + .modificationType(MODIFICATION_TYPE) |
| 60 | + .modifications(modifications) |
| 61 | + .stashed(false) |
| 62 | + .build(); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + protected void assertAfterNetworkModificationCreation() { |
| 67 | + assertEquals(Country.BE, getNetwork().getSubstation("s1").getCountry().orElse(Country.AF)); |
| 68 | + assertEquals("s1", getNetwork().getSubstation("s1").getOptionalName().orElse("s2")); |
| 69 | + assertEquals(Country.BE, getNetwork().getSubstation("s2").getCountry().orElse(Country.AF)); |
| 70 | + assertEquals("s2", getNetwork().getSubstation("s2").getOptionalName().orElse("s1")); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + protected void assertAfterNetworkModificationDeletion() { |
| 75 | + assertEquals(Country.FR, getNetwork().getSubstation("s1").getCountry().orElse(Country.BE)); |
| 76 | + assertEquals("s1", getNetwork().getSubstation("s1").getOptionalName().orElse("s2")); |
| 77 | + assertEquals(Country.FR, getNetwork().getSubstation("s2").getCountry().orElse(Country.BE)); |
| 78 | + assertEquals("s2", getNetwork().getSubstation("s2").getOptionalName().orElse("s1")); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + @SneakyThrows |
| 83 | + protected void testCreationModificationMessage(ModificationInfos modificationInfos) { |
| 84 | + assertEquals("TABULAR_MODIFICATION", modificationInfos.getMessageType()); |
| 85 | + Map<String, String> createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); |
| 86 | + Assertions.assertEquals(MODIFICATION_TYPE, createdValues.get("tabularModificationType")); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + @SneakyThrows |
| 91 | + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { |
| 92 | + assertEquals("TABULAR_MODIFICATION", modificationInfos.getMessageType()); |
| 93 | + Map<String, String> updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); |
| 94 | + Assertions.assertEquals(MODIFICATION_TYPE, updatedValues.get("tabularModificationType")); |
| 95 | + } |
| 96 | +} |
0 commit comments