99
1010import static org .junit .jupiter .api .Assertions .assertFalse ;
1111import static org .junit .jupiter .api .Assertions .assertTrue ;
12+ import static org .mockito .Mockito .when ;
1213
1314import java .io .IOException ;
1415import java .util .stream .Stream ;
@@ -55,35 +56,35 @@ void setUp() throws IOException {
5556 super .setUp ();
5657
5758 Bus svcBus = Mockito .mock (Bus .class );
58- Mockito . when (svcBus .getV ()).thenReturn (v );
59- Mockito . when (svcBus .isInMainConnectedComponent ()).thenReturn (mainComponent );
59+ when (svcBus .getV ()).thenReturn (v );
60+ when (svcBus .isInMainConnectedComponent ()).thenReturn (mainComponent );
6061
6162 svcBusView = Mockito .mock (BusView .class );
62- Mockito . when (svcBusView .getBus ()).thenReturn (svcBus );
63- Mockito . when (svcBusView .getConnectableBus ()).thenReturn (svcBus );
63+ when (svcBusView .getBus ()).thenReturn (svcBus );
64+ when (svcBusView .getConnectableBus ()).thenReturn (svcBus );
6465
6566 VoltageLevel voltageLevel = Mockito .mock (VoltageLevel .class );
66- Mockito . when (voltageLevel .getNominalV ()).thenReturn (nominalV );
67+ when (voltageLevel .getNominalV ()).thenReturn (nominalV );
6768
6869 svcTerminal = Mockito .mock (Terminal .class );
69- Mockito . when (svcTerminal .getP ()).thenReturn (p );
70- Mockito . when (svcTerminal .getQ ()).thenReturn (q );
71- Mockito . when (svcTerminal .getBusView ()).thenReturn (svcBusView );
72- Mockito . when (svcTerminal .getVoltageLevel ()).thenReturn (voltageLevel );
70+ when (svcTerminal .getP ()).thenReturn (p );
71+ when (svcTerminal .getQ ()).thenReturn (q );
72+ when (svcTerminal .getBusView ()).thenReturn (svcBusView );
73+ when (svcTerminal .getVoltageLevel ()).thenReturn (voltageLevel );
7374
7475 svc = Mockito .mock (StaticVarCompensator .class );
75- Mockito . when (svc .getId ()).thenReturn ("svc" );
76- Mockito . when (svc .getTerminal ()).thenReturn (svcTerminal );
77- Mockito . when (svc .getReactivePowerSetpoint ()).thenReturn (reactivePowerSetpoint );
78- Mockito . when (svc .getVoltageSetpoint ()).thenReturn (voltageSetpoint );
79- Mockito . when (svc .getRegulationMode ()).thenReturn (regulationMode );
80- Mockito . when (svc .isRegulating ()).thenReturn (regulating );
81- Mockito . when (svc .getBmin ()).thenReturn (bMin );
82- Mockito . when (svc .getBmax ()).thenReturn (bMax );
76+ when (svc .getId ()).thenReturn ("svc" );
77+ when (svc .getTerminal ()).thenReturn (svcTerminal );
78+ when (svc .getReactivePowerSetpoint ()).thenReturn (reactivePowerSetpoint );
79+ when (svc .getVoltageSetpoint ()).thenReturn (voltageSetpoint );
80+ when (svc .getRegulationMode ()).thenReturn (regulationMode );
81+ when (svc .isRegulating ()).thenReturn (regulating );
82+ when (svc .getBmin ()).thenReturn (bMin );
83+ when (svc .getBmax ()).thenReturn (bMax );
8384 }
8485
8586 @ Test
86- void checkSvcsValues () {
87+ void checkSvcsValuess () {
8788 // active power should be equal to 0
8889 assertTrue (StaticVarCompensatorsValidation .INSTANCE .checkSVCs ("test" , p , q , v , v , nominalV , reactivePowerSetpoint , voltageSetpoint , regulationMode , regulating , bMin , bMax , connected , mainComponent , strictConfig , NullWriter .INSTANCE ));
8990 p = -39.8 ;
@@ -168,19 +169,19 @@ void checkSvcsValues() {
168169 void checkSvcs () {
169170 // active power should be equal to 0
170171 assertTrue (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (svc , strictConfig , NullWriter .INSTANCE ));
171- Mockito . when (svcTerminal .getP ()).thenReturn (-39.8 );
172+ when (svcTerminal .getP ()).thenReturn (-39.8 );
172173 assertFalse (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (svc , strictConfig , NullWriter .INSTANCE ));
173174
174175 // the unit is disconnected
175- Mockito . when (svcBusView .getBus ()).thenReturn (null );
176+ when (svcBusView .getBus ()).thenReturn (null );
176177 assertTrue (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (svc , strictConfig , NullWriter .INSTANCE ));
177178 }
178179
179180 @ Test
180181 void checkNetworkSvcs () throws IOException {
181182 Network network = Mockito .mock (Network .class );
182- Mockito . when (network .getId ()).thenReturn ("network" );
183- Mockito . when (network .getStaticVarCompensatorStream ()).thenAnswer (dummy -> Stream .of (svc ));
183+ when (network .getId ()).thenReturn ("network" );
184+ when (network .getStaticVarCompensatorStream ()).thenAnswer (dummy -> Stream .of (svc ));
184185
185186 assertTrue (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (network , looseConfig , data ));
186187
@@ -189,4 +190,31 @@ void checkNetworkSvcs() throws IOException {
189190 ValidationWriter validationWriter = ValidationUtils .createValidationWriter (network .getId (), looseConfig , NullWriter .INSTANCE , ValidationType .SVCS );
190191 assertTrue (ValidationType .SVCS .check (network , looseConfig , validationWriter ));
191192 }
193+
194+ // Rule1: active power should be equal to 0
195+ @ Test
196+ void checkSVCActivePowerShouldBeZeroWithinThreshold () {
197+ // Given (p = 0)
198+ when (svcTerminal .getP ()).thenReturn (0.0 );
199+ //When Then
200+ assertTrue (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (svc , strictConfig , NullWriter .INSTANCE ));
201+ //Given (p > 0.01)
202+ when (svcTerminal .getP ()).thenReturn (0.02 );
203+ //When Then
204+ assertFalse (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (svc , strictConfig , NullWriter .INSTANCE ));
205+ }
206+
207+ // Rule2: **reactivePowerSetpoint** must be 0 if p or q is missing (NaN)
208+ @ Test
209+ void checkSVCReactivePowerSetpointWhenPOrQMissing () {
210+ // non-zero setpoint with missing p/q => KO
211+ when (svcTerminal .getP ()).thenReturn (Double .NaN );
212+ when (svcTerminal .getQ ()).thenReturn (Double .NaN );
213+ when (svc .getReactivePowerSetpoint ()).thenReturn (5.0 );
214+ assertFalse (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (svc , strictConfig , NullWriter .INSTANCE ));
215+ // zero setpoint with missing p/q => OK
216+ when (svc .getReactivePowerSetpoint ()).thenReturn (0.0 );
217+ assertTrue (StaticVarCompensatorsValidation .INSTANCE .checkSVCs (svc , strictConfig , NullWriter .INSTANCE ));
218+ }
219+
192220}
0 commit comments