1
1
package org .gridsuite .network .map .utils ;
2
2
3
3
import com .powsybl .iidm .network .OperationalLimitsGroup ;
4
+ import org .assertj .core .api .SoftAssertions ;
4
5
import org .assertj .core .api .WithAssertions ;
5
6
import org .assertj .core .api .junit .jupiter .SoftAssertionsExtension ;
6
7
import org .gridsuite .network .map .dto .common .CurrentLimitsData ;
8
+ import org .gridsuite .network .map .dto .common .CurrentLimitsData .Applicability ;
7
9
import org .gridsuite .network .map .dto .common .TemporaryLimitData ;
8
10
import org .gridsuite .network .map .dto .utils .ElementUtils ;
9
11
import org .junit .jupiter .api .AfterEach ;
10
12
import org .junit .jupiter .api .DisplayName ;
11
13
import org .junit .jupiter .api .Nested ;
12
14
import org .junit .jupiter .api .Test ;
13
15
import org .junit .jupiter .api .extension .ExtendWith ;
16
+ import org .junit .jupiter .params .ParameterizedTest ;
17
+ import org .junit .jupiter .params .provider .Arguments ;
18
+ import org .junit .jupiter .params .provider .MethodSource ;
14
19
import org .mockito .Mockito ;
15
20
import org .mockito .junit .jupiter .MockitoExtension ;
16
21
17
22
import java .util .ArrayList ;
18
23
import java .util .Collection ;
19
24
import java .util .List ;
25
+ import java .util .concurrent .atomic .AtomicReference ;
26
+ import java .util .function .Consumer ;
27
+ import java .util .stream .Stream ;
20
28
21
29
@ ExtendWith ({ SoftAssertionsExtension .class , MockitoExtension .class })
22
30
class ElementUtilsTest implements WithAssertions {
@@ -93,8 +101,8 @@ void nanPermLimitAndNonEmptyTempLimit() {
93
101
final var olgMock = MockUtils .mockOperationalLimitsGroup ("my id" , clMock );
94
102
mocks .add (olgMock );
95
103
assertThat (ElementUtils .operationalLimitsGroupToMapDataCurrentLimits (olgMock )).isEqualTo (CurrentLimitsData .builder ()
96
- .id ("my id" ).applicability (null ).permanentLimit (null ).temporaryLimits (List .of (TemporaryLimitData .builder ()
97
- .acceptableDuration (123 ).name ("testLimit" ).value (456.789 ).build ())).build ());
104
+ .id ("my id" ).applicability (null ).permanentLimit (null ).temporaryLimits (List .of (TemporaryLimitData .builder ()
105
+ .acceptableDuration (123 ).name ("testLimit" ).value (456.789 ).build ())).build ());
98
106
Mockito .verify (olgMock , Mockito .times (2 )).getCurrentLimits ();
99
107
Mockito .verify (olgMock ).getId ();
100
108
Mockito .verify (clMock ).getPermanentLimit ();
@@ -111,7 +119,7 @@ void nonNanPermLimitAndNullTempLimit() {
111
119
final var olgMock = MockUtils .mockOperationalLimitsGroup ("my id" , clMock );
112
120
mocks .add (olgMock );
113
121
assertThat (ElementUtils .operationalLimitsGroupToMapDataCurrentLimits (olgMock )).isEqualTo (CurrentLimitsData .builder ()
114
- .id ("my id" ).applicability (null ).permanentLimit (0.123 ).temporaryLimits (null ).build ());
122
+ .id ("my id" ).applicability (null ).permanentLimit (0.123 ).temporaryLimits (null ).build ());
115
123
Mockito .verify (olgMock , Mockito .times (2 )).getCurrentLimits ();
116
124
Mockito .verify (olgMock ).getId ();
117
125
Mockito .verify (clMock , Mockito .times (2 )).getPermanentLimit ();
@@ -125,7 +133,7 @@ void nonNanPermLimitAndEmptyTempLimit() {
125
133
final var olgMock = MockUtils .mockOperationalLimitsGroup ("my id" , clMock );
126
134
mocks .add (olgMock );
127
135
assertThat (ElementUtils .operationalLimitsGroupToMapDataCurrentLimits (olgMock )).isEqualTo (CurrentLimitsData .builder ()
128
- .id ("my id" ).applicability (null ).permanentLimit (0.123 ).temporaryLimits (null ).build ());
136
+ .id ("my id" ).applicability (null ).permanentLimit (0.123 ).temporaryLimits (null ).build ());
129
137
Mockito .verify (olgMock , Mockito .times (2 )).getCurrentLimits ();
130
138
Mockito .verify (olgMock ).getId ();
131
139
Mockito .verify (clMock , Mockito .times (2 )).getPermanentLimit ();
@@ -141,8 +149,8 @@ void nonNanPermLimitAndNonEmptyTempLimit() {
141
149
final var olgMock = MockUtils .mockOperationalLimitsGroup ("my id" , clMock );
142
150
mocks .add (olgMock );
143
151
assertThat (ElementUtils .operationalLimitsGroupToMapDataCurrentLimits (olgMock )).isEqualTo (CurrentLimitsData .builder ()
144
- .id ("my id" ).applicability (null ).permanentLimit (0.0 ).temporaryLimits (List .of (TemporaryLimitData .builder ()
145
- .acceptableDuration (123 ).name ("testLimit" ).value (456.789 ).build ())).build ());
152
+ .id ("my id" ).applicability (null ).permanentLimit (0.0 ).temporaryLimits (List .of (TemporaryLimitData .builder ()
153
+ .acceptableDuration (123 ).name ("testLimit" ).value (456.789 ).build ())).build ());
146
154
Mockito .verify (olgMock , Mockito .times (2 )).getCurrentLimits ();
147
155
Mockito .verify (olgMock ).getId ();
148
156
Mockito .verify (clMock , Mockito .times (2 )).getPermanentLimit ();
@@ -152,4 +160,125 @@ void nonNanPermLimitAndNonEmptyTempLimit() {
152
160
Mockito .verify (tlMock , Mockito .times (2 )).getValue ();
153
161
}
154
162
}
163
+
164
+ /** Tests for {@link ElementUtils#mergeCurrentLimits(Collection, Collection, Consumer)} */
165
+ @ Nested
166
+ @ DisplayName ("fn mergeCurrentLimits(…, …, …)" )
167
+ class MergeCurrentLimitsTest {
168
+ @ ParameterizedTest (name = ParameterizedTest .INDEX_PLACEHOLDER )
169
+ @ MethodSource ("mergeCurrentLimitsTestData" )
170
+ void shouldNotThrow (
171
+ final Collection <OperationalLimitsGroup > olg1 ,
172
+ final Collection <OperationalLimitsGroup > olg2 ,
173
+ final List <CurrentLimitsData > expected ) {
174
+ AtomicReference <List <CurrentLimitsData >> results = new AtomicReference <>();
175
+ ElementUtils .mergeCurrentLimits (olg1 , olg2 , results ::set );
176
+ assertThat (results .get ()).as ("Result" ).isEqualTo (expected );
177
+ }
178
+
179
+ private static Stream <Arguments > mergeCurrentLimitsTestData () {
180
+ return Stream .of (
181
+ Arguments .of (List .of (
182
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
183
+ ), List .of (
184
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
185
+ ), List .of (
186
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
187
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
188
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
189
+ )).applicability (Applicability .EQUIPMENT ).build ()
190
+ )),
191
+ Arguments .of (List .of (), List .of (
192
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
193
+ ), List .of (
194
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
195
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
196
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
197
+ )).applicability (Applicability .SIDE2 ).build ()
198
+ )),
199
+ Arguments .of (List .of (
200
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
201
+ ), List .of (), List .of (
202
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
203
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
204
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
205
+ )).applicability (Applicability .SIDE1 ).build ()
206
+ )),
207
+ // TODO get two dto but because hasLimit() condition always false
208
+ Arguments .of (List .of (
209
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of ())
210
+ ), List .of (
211
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
212
+ ), List .of (
213
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
214
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
215
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
216
+ )).applicability (Applicability .SIDE2 ).build ()
217
+ )),
218
+ // TODO java.lang.NullPointerException: Cannot invoke "org.gridsuite.network.map.dto.common.CurrentLimitsData.getId()" because "limitsData" is null
219
+ Arguments .of (List .of (
220
+ MockUtils .mockOperationalLimitsGroup ("group1" , Double .NaN , List .of ())
221
+ ), List .of (
222
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
223
+ ), List .of (
224
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
225
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
226
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
227
+ )).applicability (Applicability .SIDE2 ).build ()
228
+ )),
229
+ // TODO java.lang.NullPointerException: Cannot invoke "java.lang.Double.doubleValue()" because "this.permanentLimit" is null
230
+ Arguments .of (List .of (
231
+ MockUtils .mockOperationalLimitsGroup ("group1" , Double .NaN , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
232
+ ), List .of (
233
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
234
+ ), List .of (
235
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
236
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
237
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
238
+ )).applicability (Applicability .SIDE2 ).build ()
239
+ )),
240
+ Arguments .of (List .of (
241
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
242
+ ), List .of (
243
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of ())
244
+ ), List .of (
245
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
246
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
247
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
248
+ )).applicability (Applicability .SIDE1 ).build ()
249
+ )),
250
+ Arguments .of (List .of (
251
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
252
+ ), List .of (
253
+ MockUtils .mockOperationalLimitsGroup ("group1" , Double .NaN , List .of ())
254
+ ), List .of (
255
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
256
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
257
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
258
+ )).applicability (Applicability .SIDE1 ).build ()
259
+ )),
260
+ Arguments .of (List .of (
261
+ MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
262
+ ), List .of (
263
+ MockUtils .mockOperationalLimitsGroup ("group1" , Double .NaN , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 )))
264
+ ), List .of (
265
+ CurrentLimitsData .builder ().id ("group1" ).permanentLimit (220.0 ).temporaryLimits (List .of (
266
+ TemporaryLimitData .builder ().acceptableDuration (100 ).name ("temporary1" ).value (50.0 ).build (),
267
+ TemporaryLimitData .builder ().acceptableDuration (150 ).name ("temporary2" ).value (70.0 ).build ()
268
+ )).applicability (Applicability .SIDE1 ).build ()
269
+ ))
270
+ );
271
+ }
272
+
273
+ @ Test
274
+ void shouldThrowOnNanLimit (final SoftAssertions softly ) {
275
+ final var l1 = List .of (MockUtils .mockOperationalLimitsGroup ("group1" , Double .NaN , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 ))));
276
+ final var l2 = List .of (MockUtils .mockOperationalLimitsGroup ("group1" , 220.0 , List .of (MockUtils .mockTemporaryLimits (100 , "temporary1" , 50.0 ), MockUtils .mockTemporaryLimits (150 , "temporary2" , 70.0 ))));
277
+ AtomicReference <List <CurrentLimitsData >> results = new AtomicReference <>();
278
+ softly .assertThatNullPointerException ().isThrownBy (() -> ElementUtils .mergeCurrentLimits (l1 , l2 , results ::set ));
279
+ softly .assertThatNullPointerException ().isThrownBy (() -> ElementUtils .mergeCurrentLimits (l2 , l1 , results ::set ));
280
+ }
281
+
282
+ // TODO what to do when one side has duplicate ID?
283
+ }
155
284
}
0 commit comments