From b167672d5a04ec857f00689a30d521a5d7dd7ed6 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Thu, 17 Aug 2023 17:09:25 +0200 Subject: [PATCH 1/3] CIM CRAC permissive imports --- .../cim/crac_creator/CimCracUtils.java | 2 +- .../cnec/MonitoredSeriesCreator.java | 12 +- .../contingency/CimContingencyCreator.java | 10 +- .../HvdcRangeActionCreator.java | 2 +- .../RemedialActionSeriesCreator.java | 4 +- .../cim/crac_creator/CimCracCreatorTest.java | 63 ++++- .../src/test/resources/cracs/CIM_21_1_1.xml | 6 + .../src/test/resources/cracs/CIM_21_2_1.xml | 4 +- .../test/resources/cracs/CIM_21_2_1_ARA.xml | 4 +- .../test/resources/cracs/CIM_21_2_1_mrid.xml | 2 +- .../src/test/resources/cracs/CIM_21_5_1.xml | 2 +- .../resources/cracs/CIM_21_5_1_permissive.xml | 249 ++++++++++++++++++ .../src/test/resources/cracs/CIM_21_5_3.xml | 4 +- .../src/test/resources/cracs/CIM_21_6_1.xml | 42 +-- .../src/test/resources/cracs/CIM_21_7_1.xml | 2 +- .../JsonSerializationConstants.java | 42 ++- .../serializers/UsageRulesSerializer.java | 4 +- .../src/test/resources/CIM_CRAC.xml | 38 ++- 18 files changed, 436 insertions(+), 56 deletions(-) create mode 100644 data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1_permissive.xml diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracUtils.java b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracUtils.java index 7a512f2706..be2cc0f70a 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracUtils.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracUtils.java @@ -26,7 +26,7 @@ private CimCracUtils() { } public static Contingency getContingencyFromCrac(ContingencySeries cimContingency, CimCracCreationContext cracCreationContext) { CimContingencyCreationContext ccc = cracCreationContext.getContingencyCreationContextById(cimContingency.getMRID()); - if (ccc == null || ccc.getCreatedContingencyId() == null) { + if (ccc == null || !ccc.isImported()) { return null; } return cracCreationContext.getCrac().getContingency(ccc.getCreatedContingencyId()); diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/cnec/MonitoredSeriesCreator.java b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/cnec/MonitoredSeriesCreator.java index 52ca584d35..d85fca6c41 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/cnec/MonitoredSeriesCreator.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/cnec/MonitoredSeriesCreator.java @@ -85,7 +85,7 @@ private Set getCnecSeries() { } private boolean describesCnecsToImport(Series series) { - return series.getBusinessType().equals(CNECS_SERIES_BUSINESS_TYPE); + return series.getBusinessType().equals(CNECS_SERIES_BUSINESS_TYPE) || series.getBusinessType().equals(REMEDIAL_ACTIONS_SERIES_BUSINESS_TYPE); } private void readAndAddCnec(MonitoredSeries monitoredSeries, List contingencies, String optimizationStatus, List invalidContingencies) { @@ -132,7 +132,7 @@ private void readAndAddCnec(MonitoredSeries monitoredSeries, List c } else { String contingencyList = StringUtils.join(invalidContingencies, ", "); monitoredSeriesCreationContext = MonitoredSeriesCreationContext.imported(nativeId, nativeName, resourceId, resourceName, - true, String.format("Contingencies %s not defined in B55s", contingencyList)); + true, String.format("Contingencies %s were not imported", contingencyList)); } // Read measurements @@ -180,13 +180,7 @@ private void saveMonitoredSeriesCreationContexts(String nativeId, MonitoredSerie } private boolean isMnec(String optimizationStatus) { - if (Objects.nonNull(optimizationStatus) && optimizationStatus.equals(CNECS_MNEC_MARKET_OBJECT_STATUS)) { - return true; - } else if (Objects.isNull(optimizationStatus) || optimizationStatus.equals(CNECS_OPTIMIZED_MARKET_OBJECT_STATUS)) { - return false; - } else { - throw new FaraoException(String.format("Unrecognized optimization_MarketObjectStatus.status: %s", optimizationStatus)); - } + return Objects.nonNull(optimizationStatus) && optimizationStatus.equals(CNECS_MNEC_MARKET_OBJECT_STATUS); } private MeasurementCreationContext createCnecFromMeasurement(Analog measurement, String cnecId, boolean isMnec, CgmesBranchHelper branchHelper, List contingencies) { diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java index aadd1bee3a..f2293c4605 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java @@ -24,7 +24,7 @@ import java.util.Set; import java.util.stream.Collectors; -import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.CONTINGENCY_SERIES_BUSINESS_TYPE; +import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.*; /** * @author Godelaine de Montmorillon {@literal } @@ -65,6 +65,10 @@ public void createAndAddContingencies() { } private void addContingency(ContingencySeries cimContingency) { + if (cimContingencyCreationContexts.stream().anyMatch(ccc -> ccc.getNativeId().equals(cimContingency.getMRID()))) { + return; + } + String createdContingencyId = cimContingency.getMRID(); ContingencyAdder contingencyAdder = crac.newContingency() .withId(createdContingencyId) @@ -125,6 +129,8 @@ private String getNetworkElementIdInNetwork(String networkElementIdInCrac) { } private boolean describesContingencyToImport(Series series) { - return series.getBusinessType().equals(CONTINGENCY_SERIES_BUSINESS_TYPE); + return series.getBusinessType().equals(CONTINGENCY_SERIES_BUSINESS_TYPE) + || series.getBusinessType().equals(CNECS_SERIES_BUSINESS_TYPE) + || series.getBusinessType().equals(REMEDIAL_ACTIONS_SERIES_BUSINESS_TYPE); } } diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/HvdcRangeActionCreator.java b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/HvdcRangeActionCreator.java index 031710ddea..39e2d07fce 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/HvdcRangeActionCreator.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/HvdcRangeActionCreator.java @@ -161,7 +161,7 @@ public Set add() { return raSeriesIds.stream().map(id -> RemedialActionSeriesCreationContext.importedHvdcRa(id, createdRaIds, false, isDirectionInverted.get(id), "")).collect(Collectors.toSet()); } else { String contingencyList = StringUtils.join(invalidContingencies, ", "); - return raSeriesIds.stream().map(id -> RemedialActionSeriesCreationContext.importedHvdcRa(id, createdRaIds, true, isDirectionInverted.get(id), String.format("Contingencies %s not defined in B55s", contingencyList))).collect(Collectors.toSet()); + return raSeriesIds.stream().map(id -> RemedialActionSeriesCreationContext.importedHvdcRa(id, createdRaIds, true, isDirectionInverted.get(id), String.format("Contingencies %s were not imported", contingencyList))).collect(Collectors.toSet()); } } diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/RemedialActionSeriesCreator.java b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/RemedialActionSeriesCreator.java index 8ee584f4ab..e646fd3eff 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/RemedialActionSeriesCreator.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/remedial_action/RemedialActionSeriesCreator.java @@ -343,7 +343,7 @@ public static RemedialActionSeriesCreationContext importWithContingencies(String return RemedialActionSeriesCreationContext.imported(createdRemedialActionId, false, ""); } else { String contingencyList = StringUtils.join(invalidContingencies, ", "); - return RemedialActionSeriesCreationContext.imported(createdRemedialActionId, true, String.format("Contingencies %s not defined in B55s", contingencyList)); + return RemedialActionSeriesCreationContext.imported(createdRemedialActionId, true, String.format("Contingencies %s were not imported", contingencyList)); } } @@ -352,7 +352,7 @@ public static RemedialActionSeriesCreationContext importPstRaWithContingencies(S return PstRangeActionSeriesCreationContext.imported(createdRemedialActionId, networkElementNativeMrid, networkElementNativeName, false, ""); } else { String contingencyList = StringUtils.join(invalidContingencies, ", "); - return PstRangeActionSeriesCreationContext.imported(createdRemedialActionId, networkElementNativeMrid, networkElementNativeName, true, String.format("Contingencies %s not defined in B55s", contingencyList)); + return PstRangeActionSeriesCreationContext.imported(createdRemedialActionId, networkElementNativeMrid, networkElementNativeName, true, String.format("Contingencies %s were not imported", contingencyList)); } } diff --git a/data/crac-creation/crac-creator-cim/src/test/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracCreatorTest.java b/data/crac-creation/crac-creator-cim/src/test/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracCreatorTest.java index 29829876ba..6167d2d59a 100644 --- a/data/crac-creation/crac-creator-cim/src/test/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracCreatorTest.java +++ b/data/crac-creation/crac-creator-cim/src/test/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/CimCracCreatorTest.java @@ -33,8 +33,9 @@ import com.farao_community.farao.data.crac_creation.creator.cim.parameters.*; import com.google.common.base.Suppliers; import com.powsybl.computation.local.LocalComputationManager; +import com.powsybl.iidm.network.Country; import com.powsybl.iidm.network.ImportConfig; -import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.Network; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -53,6 +54,8 @@ * @author Godelaine de Montmorillon {@literal } */ class CimCracCreatorTest { + private static final double DOUBLE_TOLERANCE = 1e-6; + private Crac importedCrac; private CimCracCreationContext cracCreationContext; private static Network baseNetwork; @@ -279,9 +282,9 @@ private void assertHasOneThreshold(String cnecId, Side side, Unit unit, double m assertEquals(side, threshold.getSide()); assertEquals(unit, threshold.getUnit()); assertTrue(threshold.limitsByMin()); - assertEquals(min, threshold.min().get(), 0.0); + assertEquals(min, threshold.min().get(), DOUBLE_TOLERANCE); assertTrue(threshold.limitsByMax()); - assertEquals(max, threshold.max().get(), 0.0); + assertEquals(max, threshold.max().get(), DOUBLE_TOLERANCE); } private void assertHasTwoThresholds(String cnecId, Unit unit, double min, double max) { @@ -292,9 +295,9 @@ private void assertHasTwoThresholds(String cnecId, Unit unit, double min, double cnec.getThresholds().forEach(threshold -> { assertEquals(unit, threshold.getUnit()); assertTrue(threshold.limitsByMin()); - assertEquals(min, threshold.min().get(), 0.0); + assertEquals(min, threshold.min().get(), DOUBLE_TOLERANCE); assertTrue(threshold.limitsByMax()); - assertEquals(max, threshold.max().get(), 0.0); + assertEquals(max, threshold.max().get(), DOUBLE_TOLERANCE); }); } @@ -929,4 +932,54 @@ void importAndDuplicateAutoCnecs() { assertCnecHasOutageDuplicate("CNEC-4 - Co-1 - auto"); assertCnecHasOutageDuplicate("CNEC-4 - Co-2 - auto"); } + + @Test + void testPermissiveImports() { + // Test that we can import contingencies from B56 & B57, and CNECs from B56 + setUpWithSpeed("/cracs/CIM_21_5_1_permissive.xml", baseNetwork, OffsetDateTime.parse("2021-04-01T23:00Z"), Set.of(new RangeActionSpeed("AUTO_1", 1))); + + // Contingencies + assertEquals(3, importedCrac.getContingencies().size()); + assertContingencyImported("Co-one-1", "OIUYTR-QSCV-1 400 kV", Set.of("_ffbabc27-1ccd-4fdc-b037-e341706c8d29"), false); + assertContingencyImported("Co-one-2", "OIUYTR-LKJHGOI-1 400 kV", Set.of("_b58bf21a-096a-4dae-9a01-3f03b60c24c7"), false); + assertContingencyImported("Co-one-3", "AZERTY-LKJHG-1 400 kV", Set.of("_df16b3dd-c905-4a6f-84ee-f067be86f5da"), false); + + // FlowCNECs + assertEquals(14, importedCrac.getFlowCnecs().size()); + + assertCnecImported("TUU_MR_31", Set.of( + "GHIOL_QSDFGH_1_220 - Co-one-1 - auto", "GHIOL_QSDFGH_1_220 - preventive", "GHIOL_QSDFGH_1_220 - Co-one-1 - outage", + "GHIOL_QSDFGH_1_220 - Co-one-3 - outage", "GHIOL_QSDFGH_1_220 - Co-one-3 - curative", "GHIOL_QSDFGH_1_220 - Co-one-2 - curative", + "GHIOL_QSDFGH_1_220 - Co-one-3 - auto", "GHIOL_QSDFGH_1_220 - Co-one-1 - curative", "GHIOL_QSDFGH_1_220 - Co-one-2 - auto", + "GHIOL_QSDFGH_1_220 - Co-one-2 - outage" + )); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -1, 1); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -1.15, 1.15); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-2 - auto", Side.LEFT, Unit.PERCENT_IMAX, -1.1, 1.1); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-3 - curative", Side.LEFT, Unit.PERCENT_IMAX, -1.05, 1.05); + + assertCnecImported("TUU_MR_56", Set.of( + "GHIOL_QSRBJH_1_400 - Co-one-1 - auto", "GHIOL_QSRBJH_1_400 - preventive", "GHIOL_QSRBJH_1_400 - Co-one-1 - outage", + "GHIOL_QSRBJH_1_400 - Co-one-1 - curative" + )); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -1, 1); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -1.5, 1.5); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - auto", Side.LEFT, Unit.PERCENT_IMAX, -1.3, 1.3); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - curative", Side.LEFT, Unit.PERCENT_IMAX, -1.05, 1.05); + + // PRA_1 + assertPstRangeActionImported("PRA_1", "_a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", false); + PstRangeAction pra1 = importedCrac.getPstRangeAction("PRA_1"); + assertEquals(7, pra1.getUsageRules().size()); + + // PRA_CRA_1 + assertPstRangeActionImported("PRA_CRA_1", "_e8a7eaec-51d6-4571-b3d9-c36d52073c33", true); + PstRangeAction praCra1 = importedCrac.getPstRangeAction("PRA_CRA_1"); + assertEquals(6, praCra1.getUsageRules().size()); + + // AUTO_1 + assertPstRangeActionImported("AUTO_1", "_e8a7eaec-51d6-4571-b3d9-c36d52073c33", true); + PstRangeAction auto1 = importedCrac.getPstRangeAction("AUTO_1"); + assertEquals(2, auto1.getUsageRules().size()); + } } diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_1_1.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_1_1.xml index 42231a7099..7cece368e2 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_1_1.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_1_1.xml @@ -117,6 +117,12 @@ 1------0 1------0 + + _df16b3dd-c905-4a6f-84ee-f067be86f5da + Co2NetworkElementName + 1------0 + 1------0 + diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1.xml index d6c5026b3b..c4a3d64c13 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1.xml @@ -134,7 +134,7 @@ Co-1 Co-1-name - _ffbabc27-1ccd-4fdc-b037-e341706c8d29 + _b18cd1aa-7808-49b9-a7cf-605eaf07b006 + _e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc Co1NetworkElementName 1------0 1------0 @@ -144,7 +144,7 @@ Fake-Co Fake-Co-name - _df16b3dd-c905-4a6f-84ee-f067be86f5da + _df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist FakeCoElement 1------0 1------0 diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_ARA.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_ARA.xml index 74c1b3be36..191bbda5b4 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_ARA.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_ARA.xml @@ -134,7 +134,7 @@ Co-1 Co-1-name - _ffbabc27-1ccd-4fdc-b037-e341706c8d29 + _b18cd1aa-7808-49b9-a7cf-605eaf07b006 + _e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc Co1NetworkElementName 1------0 1------0 @@ -144,7 +144,7 @@ Fake-Co Fake-Co-name - _df16b3dd-c905-4a6f-84ee-f067be86f5da + _df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist FakeCoElement 1------0 1------0 diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_mrid.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_mrid.xml index 9257361a15..cd47cf0020 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_mrid.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_2_1_mrid.xml @@ -134,7 +134,7 @@ Co-1 Co-1-name - _ffbabc27-1ccd-4fdc-b037-e341706c8d29 + _b18cd1aa-7808-49b9-a7cf-605eaf07b006 + _e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc Co1NetworkElementName 1------0 1------0 diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1.xml index e086419aff..7ccfee3ad9 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1.xml @@ -190,7 +190,7 @@ Co-one-9 AZERTY-LKJHG-1 400 kV_TO_IGNORE - _df16b3dd-c905-4a6f-84ee-f067be86f5da + _df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist AZERTY_LKJHG_1_400 10YES-REE------0 10YES-REE------0 diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1_permissive.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1_permissive.xml new file mode 100644 index 0000000000..ddb0c994a6 --- /dev/null +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_1_permissive.xml @@ -0,0 +1,249 @@ + + + CORESO-20210402-SWECCD2-F011 + 1 + B15 + A48 + 22XCORESO------S + A36 + 10XES-REE------E + A04 + 2021-03-31T15:02:00Z + + A42 + + + 2021-04-01T22:00Z + 2021-04-02T22:00Z + + 10YCB-FR-ES-PT-S + + REE-TimeSeries-ESFR + B54 + A03 + 10YES-REE------0 + 10YFR-RTE------C + + + 2021-04-01T22:00Z + 2021-04-02T22:00Z + + PT60M + + 2 + + A-MRList-1_ESFR + B57 + Monitored_Resources_1 + A52 + + Co-one-1 + OIUYTR-QSCV-1 400 kV + + _ffbabc27-1ccd-4fdc-b037-e341706c8d29 + IUYTR_DFG_1_400 + 10YES-REE------0 + 10YES-REE------0 + + + + TUU_MR_56 + TUU_MR_56_GHIOL_QSRBJH_1_400 + + _dad02278-bd25-476f-8f58-dbe44be72586 + _ed0c5d75-4a54-43c8-b782-b20d7431630b + GHIOL_QSRBJH_1_400 + 10YES-REE------0 + 10YES-REE------0 + + A02 + P1 + 100.0 + + + A07 + P1 + 150.0 + + + A12 + P1 + 130.0 + + + A13 + P1 + 105.0 + + + + + + RA-Series-1 + B56 + RA_SERIES_1 + Z01 + + TUU_MR_31 + TUU_MR_31_GHIOL_QSDFGH_1_220 + + _dad02278-bd25-476f-8f58-dbe44be72586 + _ed0c5d75-4a54-43c8-b782-b20d7431630b + GHIOL_QSDFGH_1_220 + 10YES-REE------0 + 10YES-REE------0 + + A02 + P1 + 100.0 + + + A07 + P1 + 115.0 + + + A12 + P1 + 110.0 + + + A13 + P1 + 105.0 + + + + + TUU_MR_33 + TUU_MR_TO_IGNORE + + + PRA_1 + PRA PST FARAO + B59 + A18 + A39 + + _a708c3bc-465d-4fe7-b6ef-6fa6408a62b0 + FARAO_1_220_220 + A06 + 10YES-REE------0 + 10YES-REE------0 + A26 + 33.0 + 1.0 + C62 + + + + + RA-Series-2 + B56 + RA_SERIES_2 + Z01 + + Co-one-2 + OIUYTR-LKJHGOI-1 400 kV + + _b58bf21a-096a-4dae-9a01-3f03b60c24c7 + IUYTR_LKJHGOI_1_400 + 10YES-REE------0 + 10YES-REE------0 + + + + Co-one-3 + AZERTY-LKJHG-1 400 kV + + _df16b3dd-c905-4a6f-84ee-f067be86f5da + AZERTY_LKJHG_1_400 + 10YES-REE------0 + 10YES-REE------0 + + + + Co-one-9 + AZERTY-LKJHG-1 400 kV_TO_IGNORE + + _df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist + AZERTY_LKJHG_1_400 + 10YES-REE------0 + 10YES-REE------0 + + + + TUU_MR_31 + TUU_MR_31_GHIOL_QSDFGH_1_220 + + _dad02278-bd25-476f-8f58-dbe44be72586 + _ed0c5d75-4a54-43c8-b782-b20d7431630b + GHIOL_QSDFGH_1_220 + 10YES-REE------0 + 10YES-REE------0 + + A02 + P1 + 100.0 + + + A07 + P1 + 115.0 + + + A12 + P1 + 110.0 + + + A13 + P1 + 105.0 + + + + + PRA_CRA_1 + PRA_CRA_PST_FALFALES + B59 + A27 + A39 + + _e8a7eaec-51d6-4571-b3d9-c36d52073c33 + PST FALFALES + A06 + 10YFR-RTE------C + 10YFR-RTE------C + A25 + 10 + -10 + C62 + + + 10YPT-REN------W + + + + AUTO_1 + AUTO_PST_FALFALES + B59 + A20 + A39 + + _e8a7eaec-51d6-4571-b3d9-c36d52073c33 + PST FALFALES + A06 + 10YFR-RTE------C + 10YFR-RTE------C + A25 + 10 + -10 + C62 + + + 10YPT-REN------W + + + + + + + \ No newline at end of file diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_3.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_3.xml index 4caabcd2d0..3b29cb18b4 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_3.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_5_3.xml @@ -122,7 +122,7 @@ Co-one-9 AZERTY-LKJHG-1 400 kV_TO_IGNORE - _df16b3dd-c905-4a6f-84ee-f067be86f5da + _df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist AZERTY_LKJHG_1_400 10YES-REE------0 10YES-REE------0 @@ -194,7 +194,7 @@ Co-one-9 AZERTY-LKJHG-1 400 kV_TO_IGNORE - _df16b3dd-c905-4a6f-84ee-f067be86f5da + _df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist AZERTY_LKJHG_1_400 10YES-REE------0 10YES-REE------0 diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_6_1.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_6_1.xml index 5fa0b478a0..2bd083d286 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_6_1.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_6_1.xml @@ -58,8 +58,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -176,8 +176,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -345,8 +345,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -471,8 +471,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -589,8 +589,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -707,8 +707,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -825,8 +825,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -941,10 +941,10 @@ Co-1 Contingency name - ELEMENT NOT IN NETWORK + FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -1061,8 +1061,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C @@ -1179,8 +1179,8 @@ FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C diff --git a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_7_1.xml b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_7_1.xml index 6d85470182..a1b7053a9d 100644 --- a/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_7_1.xml +++ b/data/crac-creation/crac-creator-cim/src/test/resources/cracs/CIM_21_7_1.xml @@ -368,7 +368,7 @@ InvalidCo InvalidCo-name - _ffbabc27-1ccd-4fdc-b037-e341706c8d29 + _ffbabc27-1ccd-4fdc-b037-e341706c8d29_doesnt_exist Co1NetworkElementName 1------0 1------0 diff --git a/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java b/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java index 0d386c8d07..2e778bbe34 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java +++ b/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java @@ -13,8 +13,9 @@ import com.farao_community.farao.data.crac_api.cnec.Side; import com.farao_community.farao.data.crac_api.network_action.ActionType; import com.farao_community.farao.data.crac_api.range.RangeType; +import com.farao_community.farao.data.crac_api.threshold.BranchThreshold; import com.farao_community.farao.data.crac_api.threshold.Threshold; -import com.farao_community.farao.data.crac_api.usage_rule.UsageMethod; +import com.farao_community.farao.data.crac_api.usage_rule.*; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; @@ -393,6 +394,11 @@ public int compare(Threshold o1, Threshold o2) { String unit1 = serializeUnit(o1.getUnit()); String unit2 = serializeUnit(o2.getUnit()); if (unit1.equals(unit2)) { + if (o1 instanceof BranchThreshold && o2 instanceof BranchThreshold) { + if (!((BranchThreshold) o1).getSide().equals(((BranchThreshold) o2).getSide())) { + return serializeSide(((BranchThreshold) o1).getSide()).compareTo(serializeSide(((BranchThreshold) o2).getSide())); + } + } if (o1.min().isPresent()) { return -1; } @@ -402,4 +408,38 @@ public int compare(Threshold o1, Threshold o2) { } } } + + public static class UsageRuleComparator implements Comparator { + @Override + public int compare(UsageRule o1, UsageRule o2) { + if (!o1.getClass().equals(o2.getClass())) { + return o1.getClass().toString().compareTo(o2.getClass().toString()); + } + if (!o1.getInstant().equals(o2.getInstant())) { + return o1.getInstant().comesBefore(o2.getInstant()) ? -1 : 1; + } + if (!o1.getUsageMethod().equals(o2.getUsageMethod())) { + return serializeUsageMethod(o1.getUsageMethod()).compareTo(serializeUsageMethod(o2.getUsageMethod())); + } + if (o1 instanceof OnInstant) { + return 0; + } + if (o1 instanceof OnContingencyState) { + return ((OnContingencyState) o1).getState().toString().compareTo(((OnContingencyState) o2).getState().toString()); + } + if (o1 instanceof OnFlowConstraint) { + return ((OnFlowConstraint) o1).getFlowCnec().getId().compareTo(((OnFlowConstraint) o2).getFlowCnec().getId()); + } + if (o1 instanceof OnFlowConstraintInCountry) { + return ((OnFlowConstraintInCountry) o1).getCountry().toString().compareTo(((OnFlowConstraintInCountry) o2).getCountry().toString()); + } + if (o1 instanceof OnAngleConstraint) { + return ((OnAngleConstraint) o1).getAngleCnec().getId().compareTo(((OnAngleConstraint) o2).getAngleCnec().getId()); + } + if (o1 instanceof OnVoltageConstraint) { + return ((OnVoltageConstraint) o1).getVoltageCnec().getId().compareTo(((OnVoltageConstraint) o2).getVoltageCnec().getId()); + } + throw new FaraoException(String.format("Unknown usage rule type: %s", o1.getClass())); + } + } } diff --git a/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/serializers/UsageRulesSerializer.java b/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/serializers/UsageRulesSerializer.java index 782cfb8a9b..2535a5882e 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/serializers/UsageRulesSerializer.java +++ b/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/serializers/UsageRulesSerializer.java @@ -35,7 +35,9 @@ public static void serializeUsageRules(RemedialAction remedialAction, JsonGen private static void serializeUsageRules(RemedialAction remedialAction, Class usageRuleType, String arrayName, JsonGenerator gen) throws IOException { List usageRules = remedialAction.getUsageRules().stream() - .filter(usageRule -> usageRuleType.isAssignableFrom(usageRule.getClass())).collect(Collectors.toList()); + .filter(usageRule -> usageRuleType.isAssignableFrom(usageRule.getClass())) + .sorted(new UsageRuleComparator()) + .collect(Collectors.toList()); if (!usageRules.isEmpty()) { gen.writeArrayFieldStart(arrayName); for (UsageRule ea : usageRules) { diff --git a/data/result-exporter/swe-cne-exporter/src/test/resources/CIM_CRAC.xml b/data/result-exporter/swe-cne-exporter/src/test/resources/CIM_CRAC.xml index 958cf23a71..4c2c526349 100644 --- a/data/result-exporter/swe-cne-exporter/src/test/resources/CIM_CRAC.xml +++ b/data/result-exporter/swe-cne-exporter/src/test/resources/CIM_CRAC.xml @@ -64,19 +64,19 @@ A52 Co-1 - Contingency name + Contingency 1 name FFR1AA11 FFR3AA11 1 FFR1AA11 FFR3AA11 1 - 1------C - 1------C + 10YFR-RTE------C + 10YFR-RTE------C Co-2 Contingency 2 name - BBE1AA11 BBE3AA1 1 + BBE1AA11 BBE3AA11 1 BBE1AA11 BBE3AA11 1 10YFR-RTE------C 10YFR-RTE------C @@ -232,6 +232,36 @@ CNEC-2 CNEC-2-name + + FFR1AA11 FFR2AA11 1 + CNEC-2 + 1---W + 1--W + + A02 + P1 + A01 + 2.0 + + + A07 + AMP + A02 + 7.0 + + + A12 + AMP + A02 + 12.0 + + + A13 + AMP + A02 + 13.0 + + PRA_1 From 22e1001dc86febf43aeb41b0d2454900b4cbd4a5 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Thu, 24 Aug 2023 14:39:33 +0200 Subject: [PATCH 2/3] add unit tests --- data/crac-io/crac-io-json/pom.xml | 5 + .../JsonSerializationConstants.java | 9 +- .../JsonSerializationConstantsTest.java | 144 +++++++++++++++++- 3 files changed, 149 insertions(+), 9 deletions(-) diff --git a/data/crac-io/crac-io-json/pom.xml b/data/crac-io/crac-io-json/pom.xml index 7c40a772be..02e39399b0 100644 --- a/data/crac-io/crac-io-json/pom.xml +++ b/data/crac-io/crac-io-json/pom.xml @@ -60,6 +60,11 @@ junit-jupiter test + + org.mockito + mockito-inline + test + com.powsybl powsybl-config-test diff --git a/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java b/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java index 2e778bbe34..b2f48704fb 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java +++ b/data/crac-io/crac-io-json/src/main/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstants.java @@ -394,10 +394,9 @@ public int compare(Threshold o1, Threshold o2) { String unit1 = serializeUnit(o1.getUnit()); String unit2 = serializeUnit(o2.getUnit()); if (unit1.equals(unit2)) { - if (o1 instanceof BranchThreshold && o2 instanceof BranchThreshold) { - if (!((BranchThreshold) o1).getSide().equals(((BranchThreshold) o2).getSide())) { - return serializeSide(((BranchThreshold) o1).getSide()).compareTo(serializeSide(((BranchThreshold) o2).getSide())); - } + if ((o1 instanceof BranchThreshold && o2 instanceof BranchThreshold) && + !((BranchThreshold) o1).getSide().equals(((BranchThreshold) o2).getSide())) { + return serializeSide(((BranchThreshold) o1).getSide()).compareTo(serializeSide(((BranchThreshold) o2).getSide())); } if (o1.min().isPresent()) { return -1; @@ -425,7 +424,7 @@ public int compare(UsageRule o1, UsageRule o2) { return 0; } if (o1 instanceof OnContingencyState) { - return ((OnContingencyState) o1).getState().toString().compareTo(((OnContingencyState) o2).getState().toString()); + return ((OnContingencyState) o1).getState().getId().compareTo(((OnContingencyState) o2).getState().getId()); } if (o1 instanceof OnFlowConstraint) { return ((OnFlowConstraint) o1).getFlowCnec().getId().compareTo(((OnFlowConstraint) o2).getFlowCnec().getId()); diff --git a/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java b/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java index 5dd7536eff..3715a5a135 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java +++ b/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java @@ -7,12 +7,24 @@ package com.farao_community.farao.data.crac_io_json; import com.farao_community.farao.commons.FaraoException; +import com.farao_community.farao.commons.Unit; +import com.farao_community.farao.data.crac_api.Instant; +import com.farao_community.farao.data.crac_api.State; +import com.farao_community.farao.data.crac_api.cnec.AngleCnec; +import com.farao_community.farao.data.crac_api.cnec.FlowCnec; +import com.farao_community.farao.data.crac_api.cnec.Side; +import com.farao_community.farao.data.crac_api.cnec.VoltageCnec; +import com.farao_community.farao.data.crac_api.threshold.BranchThreshold; +import com.farao_community.farao.data.crac_api.usage_rule.*; +import com.powsybl.iidm.network.Country; import org.junit.jupiter.api.Test; -import static com.farao_community.farao.data.crac_io_json.JsonSerializationConstants.getPrimaryVersionNumber; -import static com.farao_community.farao.data.crac_io_json.JsonSerializationConstants.getSubVersionNumber; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.Optional; + +import static com.farao_community.farao.data.crac_io_json.JsonSerializationConstants.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @author Baptiste Seguinot {@literal } @@ -41,4 +53,128 @@ void versionNumberNok2Test() { void versionNumberNok3Test() { assertThrows(FaraoException.class, () -> getPrimaryVersionNumber("1.2b")); } + + private BranchThreshold mockBranchThreshold(Unit unit, Side side, Double min) { + BranchThreshold branchThreshold = mock(BranchThreshold.class); + when(branchThreshold.getUnit()).thenReturn(unit); + when(branchThreshold.getSide()).thenReturn(side); + when(branchThreshold.min()).thenReturn(Optional.ofNullable(min)); + return branchThreshold; + } + + @Test + void testThresholdComparator() { + ThresholdComparator comparator = new ThresholdComparator(); + BranchThreshold bt1 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, -10.); + BranchThreshold bt2 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); + + assertTrue(comparator.compare(bt1, bt2) < 0); + + bt1 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); + bt2 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); + assertTrue(comparator.compare(bt1, bt2) > 0); + + bt1 = mockBranchThreshold(Unit.AMPERE, Side.RIGHT, -10.); + bt2 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); + assertTrue(comparator.compare(bt1, bt2) > 0); + + bt1 = mockBranchThreshold(Unit.AMPERE, Side.RIGHT, -10.); + bt2 = mockBranchThreshold(Unit.MEGAWATT, Side.LEFT, null); + assertTrue(comparator.compare(bt1, bt2) < 0); + } + + private UsageRule mockUsageRule(Instant instant, UsageMethod usageMethod, String stateId, String flowCnecId, Country country, String angleCnecId, String voltageCnecId) { + UsageRule usageRule = null; + if (stateId != null) { + OnContingencyState ur = mock(OnContingencyState.class); + State state = mock(State.class); + when(state.getId()).thenReturn(stateId); + when(ur.getState()).thenReturn(state); + usageRule = ur; + } else if (flowCnecId != null) { + OnFlowConstraint ur = mock(OnFlowConstraint.class); + FlowCnec flowCnec = mock(FlowCnec.class); + when(flowCnec.getId()).thenReturn(flowCnecId); + when(ur.getFlowCnec()).thenReturn(flowCnec); + usageRule = ur; + } else if (angleCnecId != null) { + OnAngleConstraint ur = mock(OnAngleConstraint.class); + AngleCnec angleCnec = mock(AngleCnec.class); + when(angleCnec.getId()).thenReturn(angleCnecId); + when(ur.getAngleCnec()).thenReturn(angleCnec); + usageRule = ur; + } else if (voltageCnecId != null) { + OnVoltageConstraint ur = mock(OnVoltageConstraint.class); + VoltageCnec voltageCnec = mock(VoltageCnec.class); + when(voltageCnec.getId()).thenReturn(voltageCnecId); + when(ur.getVoltageCnec()).thenReturn(voltageCnec); + usageRule = ur; + } else if (country != null) { + OnFlowConstraintInCountry ur = mock(OnFlowConstraintInCountry.class); + when(ur.getCountry()).thenReturn(country); + usageRule = ur; + } else { + usageRule = mock(OnInstant.class); + } + when(usageRule.getInstant()).thenReturn(instant); + when(usageRule.getUsageMethod()).thenReturn(usageMethod); + return usageRule; + } + + @Test + void testUsageRuleComparatorOnInstant() { + UsageRuleComparator comparator = new UsageRuleComparator(); + + UsageRule onInstant1 =mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, null, null, null, null); + UsageRule onInstant2 =mockUsageRule(Instant.PREVENTIVE, UsageMethod.FORCED, null, null, null, null, null); + UsageRule onInstant3 =mockUsageRule(Instant.CURATIVE, UsageMethod.AVAILABLE, null, null, null, null, null); + + assertEquals(comparator.compare(onInstant1, onInstant1) , 0); + assertEquals(comparator.compare(onInstant2, onInstant2) , 0); + assertEquals(comparator.compare(onInstant3, onInstant3) , 0); + assertTrue(comparator.compare(onInstant1, onInstant2) < 0); + assertTrue(comparator.compare(onInstant2, onInstant3) < 0); + assertTrue(comparator.compare(onInstant1, onInstant3) < 0); + assertTrue(comparator.compare(onInstant2, onInstant1) > 0); + assertTrue(comparator.compare(onInstant3, onInstant2) > 0); + assertTrue(comparator.compare(onInstant3, onInstant1) > 0); + } + + @Test + void testUsageRuleComparatorMix() { + UsageRuleComparator comparator = new UsageRuleComparator(); + + UsageRule oi1 = mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, null, null, null, null); + + UsageRule ocs1 = mockUsageRule(Instant.CURATIVE, UsageMethod.AVAILABLE, "state1", null, null, null, null); + UsageRule ocs2 = mockUsageRule(Instant.CURATIVE, UsageMethod.AVAILABLE, "state2", null, null, null, null); + assertTrue(comparator.compare(ocs1, ocs2) < 0); + assertTrue(comparator.compare(ocs2, ocs1) > 0); + + UsageRule ofc1 = mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, "fc1", null, null, null); + UsageRule ofc2 = mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, "fc2", null, null, null); + assertTrue(comparator.compare(ofc1, ofc2) < 0); + assertTrue(comparator.compare(ofc2, ofc1) > 0); + + UsageRule ofcc1 = mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, null, Country.FR, null, null); + UsageRule ofcc2 = mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, null, Country.ES, null, null); + assertTrue(comparator.compare(ofcc1, ofcc2) > 0); + assertTrue(comparator.compare(ofcc2, ofcc1) < 0); + + UsageRule oac1 = mockUsageRule(Instant.AUTO, UsageMethod.AVAILABLE, null, null, null, "BBB", null); + UsageRule oac2 = mockUsageRule(Instant.AUTO, UsageMethod.AVAILABLE, null, null, null, "AAA", null); + assertTrue(comparator.compare(oac1, oac2) > 0); + assertTrue(comparator.compare(oac2, oac1) < 0); + + UsageRule ovc1 = mockUsageRule(Instant.CURATIVE, UsageMethod.FORCED, null, null, null, null, "z"); + UsageRule ovc2 = mockUsageRule(Instant.CURATIVE, UsageMethod.FORCED, null, null, null, null, "x"); + assertTrue(comparator.compare(ovc1, ovc2) > 0); + assertTrue(comparator.compare(ovc2, ovc1) < 0); + + assertTrue(comparator.compare(oi1, ocs1) > 0); + assertTrue(comparator.compare(ocs1, ofc1) < 0); + assertTrue(comparator.compare(ofc2, ofcc1) < 0); + assertTrue(comparator.compare(oac1, ocs2) < 0); + assertTrue(comparator.compare(oac1, ovc2) < 0); + } } From f30c8597df7142f6cb799bc6c41a0355723ac74b Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Thu, 24 Aug 2023 14:42:01 +0200 Subject: [PATCH 3/3] checkstyle --- .../crac_io_json/JsonSerializationConstantsTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java b/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java index 3715a5a135..2c09fa046b 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java +++ b/data/crac-io/crac-io-json/src/test/java/com/farao_community/farao/data/crac_io_json/JsonSerializationConstantsTest.java @@ -125,13 +125,13 @@ private UsageRule mockUsageRule(Instant instant, UsageMethod usageMethod, String void testUsageRuleComparatorOnInstant() { UsageRuleComparator comparator = new UsageRuleComparator(); - UsageRule onInstant1 =mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, null, null, null, null); - UsageRule onInstant2 =mockUsageRule(Instant.PREVENTIVE, UsageMethod.FORCED, null, null, null, null, null); - UsageRule onInstant3 =mockUsageRule(Instant.CURATIVE, UsageMethod.AVAILABLE, null, null, null, null, null); + UsageRule onInstant1 = mockUsageRule(Instant.PREVENTIVE, UsageMethod.AVAILABLE, null, null, null, null, null); + UsageRule onInstant2 = mockUsageRule(Instant.PREVENTIVE, UsageMethod.FORCED, null, null, null, null, null); + UsageRule onInstant3 = mockUsageRule(Instant.CURATIVE, UsageMethod.AVAILABLE, null, null, null, null, null); - assertEquals(comparator.compare(onInstant1, onInstant1) , 0); - assertEquals(comparator.compare(onInstant2, onInstant2) , 0); - assertEquals(comparator.compare(onInstant3, onInstant3) , 0); + assertEquals(comparator.compare(onInstant1, onInstant1), 0); + assertEquals(comparator.compare(onInstant2, onInstant2), 0); + assertEquals(comparator.compare(onInstant3, onInstant3), 0); assertTrue(comparator.compare(onInstant1, onInstant2) < 0); assertTrue(comparator.compare(onInstant2, onInstant3) < 0); assertTrue(comparator.compare(onInstant1, onInstant3) < 0);