14
14
import com .powsybl .computation .ComputationManager ;
15
15
import com .powsybl .iidm .network .Network ;
16
16
import com .powsybl .iidm .network .VariantManagerConstants ;
17
- import com .powsybl .iidm .network .VoltageLevel ;
18
17
import com .powsybl .iidm .network .extensions .IdentifiableShortCircuitAdder ;
19
18
import com .powsybl .iidm .network .test .EurostagTutorialExample1Factory ;
20
19
import com .powsybl .iidm .network .test .FourSubstationsNodeBreakerFactory ;
60
59
61
60
import static com .powsybl .network .store .model .NetworkStoreApi .VERSION ;
62
61
import static org .gridsuite .shortcircuit .server .service .NotificationService .*;
63
- import static org .junit .Assert .assertEquals ;
64
- import static org .junit .Assert .assertNotNull ;
62
+ import static org .junit .Assert .*;
65
63
import static org .mockito .ArgumentMatchers .*;
66
64
import static org .mockito .BDDMockito .given ;
67
65
import static org .mockito .Mockito .doAnswer ;
79
77
public class ShortCircuitAnalysisControllerTest {
80
78
81
79
private static final UUID NETWORK_UUID = UUID .fromString ("7928181c-7977-4592-ba19-88027e4254e4" );
80
+ private static final UUID NETWORK1_UUID = UUID .fromString ("faa0f351-f664-4771-951b-fa3b565c4d37" );
82
81
private static final UUID NODE_BREAKER_NETWORK_UUID = UUID .fromString ("060d9225-1b88-4e52-885f-0f6297f5fa35" );
83
82
private static final UUID RESULT_UUID = UUID .fromString ("0c8de370-3e6c-4d72-b292-d355a97e0d5d" );
84
83
private static final UUID OTHER_RESULT_UUID = UUID .fromString ("0c8de370-3e6c-4d72-b292-d355a97e0d5a" );
@@ -90,7 +89,7 @@ public class ShortCircuitAnalysisControllerTest {
90
89
private static final String VARIANT_1_ID = "variant_1" ;
91
90
private static final String VARIANT_2_ID = "variant_2" ;
92
91
private static final String VARIANT_3_ID = "variant_3" ;
93
-
92
+ private static final String VARIANT_4_ID = "variant_4" ;
94
93
private static final String NODE_BREAKER_NETWORK_VARIANT_ID = "node_breaker_network_variant_id" ;
95
94
96
95
private static final int TIMEOUT = 1000 ;
@@ -237,29 +236,21 @@ public void setUp() throws Exception {
237
236
238
237
// network store service mocking
239
238
network = EurostagTutorialExample1Factory .createWithMoreGenerators (new NetworkFactoryImpl ());
240
- network .getVoltageLevels ().forEach (voltageLevel -> {
241
- IdentifiableShortCircuitAdder <VoltageLevel > identifiableShortCircuitAdder = voltageLevel .newExtension (IdentifiableShortCircuitAdder .class );
242
- identifiableShortCircuitAdder .withIpMin (10.5 );
243
- identifiableShortCircuitAdder .withIpMax (200.0 );
244
- identifiableShortCircuitAdder .add ();
245
- });
239
+ network .getVoltageLevels ().forEach (voltageLevel -> voltageLevel .newExtension (IdentifiableShortCircuitAdder .class ).withIpMin (10.5 ).withIpMax (200.0 ).add ());
246
240
network .getVariantManager ().cloneVariant (VariantManagerConstants .INITIAL_VARIANT_ID , VARIANT_1_ID );
247
241
network .getVariantManager ().cloneVariant (VariantManagerConstants .INITIAL_VARIANT_ID , VARIANT_2_ID );
248
242
network .getVariantManager ().cloneVariant (VariantManagerConstants .INITIAL_VARIANT_ID , VARIANT_3_ID );
249
243
250
244
given (networkStoreService .getNetwork (NETWORK_UUID , PreloadingStrategy .ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW )).willReturn (network );
251
245
252
246
network1 = EurostagTutorialExample1Factory .createWithMoreGenerators (new NetworkFactoryImpl ());
253
- network1 .getVariantManager ().cloneVariant (VariantManagerConstants .INITIAL_VARIANT_ID , VARIANT_2_ID );
247
+ network1 .getVoltageLevelStream ().findFirst ().get ().newExtension (IdentifiableShortCircuitAdder .class ).withIpMin (5.0 ).withIpMax (100.5 ).add ();
248
+ network1 .getVariantManager ().cloneVariant (VariantManagerConstants .INITIAL_VARIANT_ID , VARIANT_4_ID );
249
+ given (networkStoreService .getNetwork (NETWORK1_UUID , PreloadingStrategy .ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW )).willReturn (network1 );
254
250
255
251
// Network for nodeBreakerView tests
256
252
nodeBreakerNetwork = FourSubstationsNodeBreakerFactory .create (new NetworkFactoryImpl ());
257
- nodeBreakerNetwork .getVoltageLevels ().forEach (voltageLevel -> {
258
- IdentifiableShortCircuitAdder <VoltageLevel > identifiableShortCircuitAdder = voltageLevel .newExtension (IdentifiableShortCircuitAdder .class );
259
- identifiableShortCircuitAdder .withIpMin (25.5 );
260
- identifiableShortCircuitAdder .withIpMax (100.0 );
261
- identifiableShortCircuitAdder .add ();
262
- });
253
+ nodeBreakerNetwork .getVoltageLevels ().forEach (voltageLevel -> voltageLevel .newExtension (IdentifiableShortCircuitAdder .class ).withIpMin (10.5 ).withIpMax (200.0 ).add ());
263
254
nodeBreakerNetwork .getVariantManager ().cloneVariant (VariantManagerConstants .INITIAL_VARIANT_ID , NODE_BREAKER_NETWORK_VARIANT_ID );
264
255
265
256
given (networkStoreService .getNetwork (NODE_BREAKER_NETWORK_UUID , PreloadingStrategy .ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW )).willReturn (nodeBreakerNetwork );
@@ -632,4 +623,63 @@ public void runWithNoShortcircuitDataTest() {
632
623
assertEquals ("me" , resultMessage .getHeaders ().get ("receiver" ));
633
624
}
634
625
}
626
+
627
+ @ Test
628
+ public void checkShortCircuitLimitsTest () throws Exception {
629
+ try (MockedStatic <ShortCircuitAnalysis > shortCircuitAnalysisMockedStatic = Mockito .mockStatic (ShortCircuitAnalysis .class )) {
630
+ shortCircuitAnalysisMockedStatic .when (() -> ShortCircuitAnalysis .runAsync (eq (network ), anyList (), any (ShortCircuitParameters .class ), any (ComputationManager .class ), anyList (), any (Reporter .class )))
631
+ .thenReturn (CompletableFuture .completedFuture (ShortCircuitAnalysisResultMock .RESULT_MAGNITUDE_FULL ));
632
+ shortCircuitAnalysisMockedStatic .when (() -> ShortCircuitAnalysis .runAsync (eq (network1 ), anyList (), any (ShortCircuitParameters .class ), any (ComputationManager .class ), anyList (), any (Reporter .class )))
633
+ .thenReturn (CompletableFuture .completedFuture (ShortCircuitAnalysisResultMock .RESULT_MAGNITUDE_FULL ));
634
+
635
+ ShortCircuitParameters shortCircuitParameters = new ShortCircuitParameters ().setWithFortescueResult (false );
636
+ String parametersJson = mapper .writeValueAsString (shortCircuitParameters );
637
+ mockMvc .perform (post (
638
+ "/" + VERSION + "/networks/{networkUuid}/run-and-save?receiver=me&variantId=" + VARIANT_2_ID , NETWORK_UUID )
639
+ .header (HEADER_USER_ID , "userId" )
640
+ .contentType (MediaType .APPLICATION_JSON )
641
+ .content (parametersJson ))
642
+ .andExpect (status ().isOk ())
643
+ .andExpect (content ().contentType (MediaType .APPLICATION_JSON ))
644
+ .andReturn ();
645
+ output .receive (TIMEOUT , shortCircuitAnalysisResultDestination );
646
+ output .receive (TIMEOUT , shortCircuitAnalysisRunDestination );
647
+
648
+ MvcResult result = mockMvc .perform (get (
649
+ "/" + VERSION + "/results/{resultUuid}" , RESULT_UUID ))
650
+ .andExpect (status ().isOk ())
651
+ .andExpect (content ().contentType (MediaType .APPLICATION_JSON ))
652
+ .andReturn ();
653
+ org .gridsuite .shortcircuit .server .dto .ShortCircuitAnalysisResult resultDto = mapper .readValue (result .getResponse ().getContentAsString (), org .gridsuite .shortcircuit .server .dto .ShortCircuitAnalysisResult .class );
654
+ assertEquals (10.5 , resultDto .getFaults ().get (0 ).getShortCircuitLimits ().getIpMin (), 0.1 );
655
+ assertEquals (200.0 , resultDto .getFaults ().get (0 ).getShortCircuitLimits ().getIpMax (), 0.1 );
656
+ assertEquals (10.5 , resultDto .getFaults ().get (1 ).getShortCircuitLimits ().getIpMin (), 0.1 );
657
+ assertEquals (200.0 , resultDto .getFaults ().get (1 ).getShortCircuitLimits ().getIpMax (), 0.1 );
658
+ mockMvc .perform (delete ("/" + VERSION + "/results/{resultUuid}" , RESULT_UUID ))
659
+ .andExpect (status ().isOk ());
660
+
661
+ mockMvc .perform (post (
662
+ "/" + VERSION + "/networks/{networkUuid}/run-and-save?receiver=me&variantId=" + VARIANT_4_ID , NETWORK1_UUID )
663
+ .header (HEADER_USER_ID , "userId" )
664
+ .contentType (MediaType .APPLICATION_JSON )
665
+ .content (parametersJson ))
666
+ .andExpect (status ().isOk ())
667
+ .andExpect (content ().contentType (MediaType .APPLICATION_JSON ))
668
+ .andReturn ();
669
+
670
+ output .receive (TIMEOUT , shortCircuitAnalysisResultDestination );
671
+ output .receive (TIMEOUT , shortCircuitAnalysisRunDestination );
672
+
673
+ result = mockMvc .perform (get (
674
+ "/" + VERSION + "/results/{resultUuid}" , RESULT_UUID ))
675
+ .andExpect (status ().isOk ())
676
+ .andExpect (content ().contentType (MediaType .APPLICATION_JSON ))
677
+ .andReturn ();
678
+ resultDto = mapper .readValue (result .getResponse ().getContentAsString (), org .gridsuite .shortcircuit .server .dto .ShortCircuitAnalysisResult .class );
679
+ assertEquals (Double .NaN , resultDto .getFaults ().get (0 ).getShortCircuitLimits ().getIpMin (), 0.1 );
680
+ assertEquals (Double .NaN , resultDto .getFaults ().get (0 ).getShortCircuitLimits ().getIpMax (), 0.1 );
681
+ assertEquals (5.0 , resultDto .getFaults ().get (1 ).getShortCircuitLimits ().getIpMin (), 0.1 );
682
+ assertEquals (100.5 , resultDto .getFaults ().get (1 ).getShortCircuitLimits ().getIpMax (), 0.1 );
683
+ }
684
+ }
635
685
}
0 commit comments