From 43c67bacdf36b52c46dd9aae22a252cd85de4e96 Mon Sep 17 00:00:00 2001 From: Godelaine de Montmorillon Date: Tue, 17 Dec 2024 11:02:05 +0100 Subject: [PATCH] add UT Signed-off-by: Godelaine de Montmorillon --- .../sensitivityanalysis/SystematicSensitivityResult.java | 1 + .../openrao/sensitivityanalysis/MockSensiProvider.java | 7 +++++++ .../SystematicSensitivityAdapterTest.java | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java index 55b9d3d29e..6e6a940537 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java @@ -111,6 +111,7 @@ public SystematicSensitivityResult completeDataWithFailingPerimeter(int instantO this.status = SensitivityComputationStatus.PARTIAL_FAILURE; StateResult contingencyStateResult = new StateResult(); contingencyStateResult.status = SensitivityComputationStatus.FAILURE; + postContingencyResults.putIfAbsent(instantOrder, new HashMap<>()); postContingencyResults.get(instantOrder).put(contingencyId, contingencyStateResult); return this; } diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/MockSensiProvider.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/MockSensiProvider.java index d374a1aeaf..15a87cabda 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/MockSensiProvider.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/MockSensiProvider.java @@ -25,6 +25,7 @@ */ @AutoService(SensitivityAnalysisProvider.class) public final class MockSensiProvider implements SensitivityAnalysisProvider { + int counter = 0; @Override public CompletableFuture run(Network network, String s, SensitivityFactorReader sensitivityFactorReader, SensitivityResultWriter sensitivityResultWriter, List contingencies, List glsks, SensitivityAnalysisParameters sensitivityAnalysisParameters, ComputationManager computationManager, ReportNode reportNode) { @@ -32,6 +33,12 @@ public CompletableFuture run(Network network, String s, SensitivityFactorR if (network.getNameOrId().equals("Mock_Exception")) { throw new OpenRaoException("Mocked exception"); } + if (network.getNameOrId().equals("Second_Run_Exception")) { + counter++; + if (counter == 2) { + throw new OpenRaoException("Mocked exception on second round"); + } + } TwoWindingsTransformer pst = network.getTwoWindingsTransformer("BBE2AA1 BBE3AA1 1"); if (pst == null || pst.getPhaseTapChanger().getTapPosition() == 0) { // used for most of the tests diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java index 8dbc061d96..5b44a0034f 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java @@ -177,7 +177,7 @@ void testCatchInRunSensitivity() { @Test void testCatchInRunSensitivityWithAppliedRa() { Network network = NetworkImportsUtil.import12NodesNetwork(); - network.setName("Mock_Exception"); + network.setName("Second_Run_Exception"); Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(ONE, TWO)); Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); crac.newFlowCnec() @@ -199,6 +199,6 @@ void testCatchInRunSensitivityWithAppliedRa() { appliedRemedialActions.addAppliedRangeAction(crac.getState("Contingency FR1 FR3", curativeInstant), crac.getPstRangeAction("pst"), -3.1); SystematicSensitivityResult result = SystematicSensitivityAdapter.runSensitivity(network, factorProvider, appliedRemedialActions, new SensitivityAnalysisParameters(), "MockSensi", crac.getOutageInstant()); - assertEquals(SystematicSensitivityResult.SensitivityComputationStatus.FAILURE, result.getStatus()); + assertEquals(SystematicSensitivityResult.SensitivityComputationStatus.PARTIAL_FAILURE, result.getStatus()); } }