10
10
import com .fasterxml .jackson .databind .DeserializationFeature ;
11
11
import com .fasterxml .jackson .databind .ObjectMapper ;
12
12
import com .powsybl .commons .reporter .Report ;
13
+ import com .powsybl .commons .reporter .Reporter ;
13
14
import com .powsybl .commons .reporter .ReporterModel ;
14
15
import com .powsybl .commons .reporter .TypedValue ;
15
16
import com .powsybl .iidm .network .IdentifiableType ;
38
39
import org .gridsuite .voltageinit .server .service .parameters .FilterService ;
39
40
import org .gridsuite .voltageinit .server .service .parameters .VoltageInitParametersService ;
40
41
import org .gridsuite .voltageinit .server .util .VoltageLimitParameterType ;
42
+ import org .gridsuite .voltageinit .utils .TestUtils ;
41
43
import org .junit .jupiter .api .BeforeEach ;
42
44
import org .junit .jupiter .api .DynamicTest ;
43
45
import org .junit .jupiter .api .Test ;
44
46
import org .junit .jupiter .api .TestFactory ;
47
+ import org .skyscreamer .jsonassert .JSONAssert ;
45
48
import org .springframework .beans .factory .annotation .Autowired ;
46
49
import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
47
50
import org .springframework .boot .test .context .SpringBootTest ;
52
55
import org .springframework .test .web .servlet .MockMvc ;
53
56
import org .springframework .test .web .servlet .MvcResult ;
54
57
import org .springframework .transaction .annotation .Transactional ;
58
+ import org .springframework .util .function .ThrowingBiFunction ;
55
59
56
- import java .util .*;
60
+ import java .util .List ;
61
+ import java .util .Map ;
62
+ import java .util .Objects ;
63
+ import java .util .UUID ;
57
64
import java .util .function .Consumer ;
58
- import java .util .function .Function ;
59
65
import java .util .stream .Collectors ;
60
66
import java .util .stream .Stream ;
61
67
@@ -281,14 +287,17 @@ private static Consumer<VoltageLimitOverride> assertVoltageLimitOverride(final S
281
287
282
288
@ TestFactory
283
289
List <DynamicTest > dynamicTestsBuildSpecificVoltageLimits () {
284
- final Function <List <VoltageLimitEntity >, ListAssert <VoltageLimitOverride >> initTestEnv = (voltageLimits ) -> {
290
+ final ThrowingBiFunction <List <VoltageLimitEntity >, String , ListAssert <VoltageLimitOverride >> initTestEnv = (voltageLimits , reportFilename ) -> {
285
291
final VoltageInitParametersEntity voltageInitParameters = parametersRepository .save (
286
292
new VoltageInitParametersEntity (UUID .randomUUID (), null , "" , voltageLimits , null , null , null )
287
293
);
288
294
final VoltageInitRunContext context = new VoltageInitRunContext (NETWORK_UUID , VARIANT_ID_1 , null , REPORT_UUID , null , "" , "" , voltageInitParameters .getId ());
289
295
final OpenReacParameters openReacParameters = voltageInitParametersService .buildOpenReacParameters (context , network );
290
296
/*TODO*/ System .out .println (parametersRepository .findAll ().stream ().map (ToStringBuilder ::reflectionToString ).collect (Collectors .joining ()));
291
- /*TODO*/ //System.out.println(mapper.writeValueAsString(context.getRootReporter()));
297
+ ReporterModel reporter = new ReporterModel ("test" , "test" );
298
+ VoltageInitWorkerService .addRestrictedVoltageLevelReport (context .getVoltageLevelsIdsRestricted (), reporter );
299
+ /*TODO*/ System .out .println (mapper .writeValueAsString (reporter ));
300
+ JSONAssert .assertEquals ("build parameters logs" , TestUtils .resourceToString (reportFilename ), mapper .writeValueAsString (reporter ), false );
292
301
return assertThat (openReacParameters .getSpecificVoltageLimits ()).as ("SpecificVoltageLimits" );
293
302
};
294
303
final VoltageLimitEntity voltageLimit = new VoltageLimitEntity (UUID .randomUUID (), 5. , 10. , 0 , VoltageLimitParameterType .DEFAULT , List .of (new FilterEquipmentsEmbeddable (FILTER_UUID_1 , FILTER_1 )));
@@ -297,7 +306,7 @@ List<DynamicTest> dynamicTestsBuildSpecificVoltageLimits() {
297
306
final VoltageLimitEntity voltageLimit4 = new VoltageLimitEntity (UUID .randomUUID (), -20.0 , 10.0 , 0 , VoltageLimitParameterType .MODIFICATION , List .of (new FilterEquipmentsEmbeddable (FILTER_UUID_1 , FILTER_1 )));
298
307
final VoltageLimitEntity voltageLimit5 = new VoltageLimitEntity (UUID .randomUUID (), 10.0 , 10.0 , 0 , VoltageLimitParameterType .DEFAULT , List .of (new FilterEquipmentsEmbeddable (FILTER_UUID_1 , FILTER_1 )));
299
308
return List .of (
300
- DynamicTest .dynamicTest ("No voltage limit modification" , () -> initTestEnv .apply (List .of (voltageLimit , voltageLimit2 ))
309
+ DynamicTest .dynamicTest ("No voltage limit modification" , () -> initTestEnv .apply (List .of (voltageLimit , voltageLimit2 ), "report_empty.json" )
301
310
.hasSize (4 )
302
311
//No override should be relative since there is no voltage limit modification
303
312
.noneMatch (VoltageLimitOverride ::isRelative )
@@ -310,7 +319,7 @@ List<DynamicTest> dynamicTestsBuildSpecificVoltageLimits() {
310
319
assertVoltageLimitOverride ("VLLOAD" , VoltageLimitType .HIGH_VOLTAGE_LIMIT , 88. )
311
320
)),
312
321
//We now add limit modifications in additions to defaults settings
313
- DynamicTest .dynamicTest ("With voltage limit modifications" , () -> initTestEnv .apply (List .of (voltageLimit , voltageLimit2 , voltageLimit3 ))
322
+ DynamicTest .dynamicTest ("With voltage limit modifications" , () -> initTestEnv .apply (List .of (voltageLimit , voltageLimit2 , voltageLimit3 ), "report_empty.json" )
314
323
//Limits that weren't impacted by default settings are now impacted by modification settings
315
324
.hasSize (8 )
316
325
//There should (not?) be relative overrides since voltage limit modification are applied
@@ -323,13 +332,13 @@ List<DynamicTest> dynamicTestsBuildSpecificVoltageLimits() {
323
332
.satisfiesOnlyOnce (assertVoltageLimitOverride ("VLLOAD" , VoltageLimitType .HIGH_VOLTAGE_LIMIT , 86. ))),
324
333
//note: VoltageLimitOverride implement equals() correctly, so we can use it
325
334
// We need to check for the case of relative = true with the modification less than 0 => the new low voltage limit = low voltage limit * -1
326
- DynamicTest .dynamicTest ("Case relative true overrides" , () -> initTestEnv .apply (List .of (voltageLimit4 ))
335
+ DynamicTest .dynamicTest ("Case relative true overrides" , () -> initTestEnv .apply (List .of (voltageLimit4 ), "report_case_relative_true.json" )
327
336
.hasSize (4 )
328
337
// isRelative: There should have relative true overrides since voltage limit modification are applied for VLGEN
329
338
// getLimit: The low voltage limit must be impacted by the modification of the value
330
339
.containsOnlyOnce (new VoltageLimitOverride ("VLGEN" , VoltageLimitType .LOW_VOLTAGE_LIMIT , true , -10.0 ))),
331
340
// We need to check for the case of relative = false with the modification less than 0 => the new low voltage limit = 0
332
- DynamicTest .dynamicTest ("Case relative false overrides" , () -> initTestEnv .apply (List .of (voltageLimit4 , voltageLimit5 ))
341
+ DynamicTest .dynamicTest ("Case relative false overrides" , () -> initTestEnv .apply (List .of (voltageLimit4 , voltageLimit5 ), "report_case_relative_false.json" )
333
342
.hasSize (8 )
334
343
// isRelative: There should have relative false overrides since voltage limit modification are applied for VLHV1
335
344
// getLimit: The low voltage limit must be impacted by the modification of the value
@@ -342,18 +351,10 @@ void testAddRestrictedVoltageLevelReport() {
342
351
Map <String , Double > restrictedVoltageLevel = Map .of ("vl" , 10.0 );
343
352
ReporterModel reporter = new ReporterModel ("test" , "test" );
344
353
VoltageInitWorkerService .addRestrictedVoltageLevelReport (restrictedVoltageLevel , reporter );
345
- assertThat (reporter .getReports ()).first ()
346
- .returns ("restrictedVoltageLevels" , Report ::getReportKey )
347
- .returns ("The modifications to the low limits for certain voltage levels have been restricted to avoid negative voltage limits: vl=10.0" , Report ::getDefaultMessage );
348
-
349
- Optional <Map .Entry <String , TypedValue >> typedValues = reporter .getReports ()
350
- .stream ()
351
- .map (Report ::getValues ) //Stream<Map<String, TypedValue>>
352
- .findFirst () //Optional<Map<String, TypedValue>>
353
- .flatMap (values -> values .entrySet ().stream ().findFirst ());
354
- assertThat (typedValues .map (Map .Entry ::getKey )).contains ("reportSeverity" );
355
- assertThat (typedValues .map (value -> value .getValue ().getValue ())).contains ("WARN" );
356
-
357
- //TODO replace by json resource
354
+ Reporter expected = new ReporterModel ("test" , "test" );
355
+ expected .report ("restrictedVoltageLevels" ,
356
+ "The modifications to the low limits for certain voltage levels have been restricted to avoid negative voltage limits: vl=10.0" ,
357
+ Map .of (Report .REPORT_SEVERITY_KEY , TypedValue .WARN_SEVERITY ));
358
+ assertThat (reporter ).usingRecursiveComparison ().isEqualTo (expected );
358
359
}
359
360
}
0 commit comments