@@ -257,6 +257,13 @@ public MockResponse dispatch(RecordedRequest request) {
257
257
server .setDispatcher (dispatcher );
258
258
}
259
259
260
+ private Map <String , Object > createRequestBody (String elementType , List <String > substationsIds ) {
261
+ Map <String , Object > requestBody = new HashMap <>();
262
+ requestBody .put ("elementType" , elementType );
263
+ requestBody .put ("substationsIds" , substationsIds );
264
+ return requestBody ;
265
+ }
266
+
260
267
@ Test
261
268
public void testDiagramsAndGraphics () throws Exception {
262
269
MvcResult mvcResult ;
@@ -379,7 +386,7 @@ public void testDiagramsAndGraphics() throws Exception {
379
386
.andExpect (status ().isNotFound ());
380
387
381
388
//get voltage levels
382
- mvcResult = getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "VOLTAGE_LEVEL " , "MAP " , List .of (), TestUtils .resourceToString ("/network-voltage-levels-infos.json" ));
389
+ mvcResult = getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "VOLTAGE_LEVEL " , List .of ()) ), TestUtils .resourceToString ("/network-voltage-levels-infos.json" ));
383
390
List <VoltageLevelInfos > vliListResponse = mapper .readValue (mvcResult .getResponse ().getContentAsString (), new TypeReference <List <VoltageLevelInfos >>() {
384
391
});
385
392
assertThat (vliListResponse , new MatcherJson <>(mapper , List .of (
@@ -421,50 +428,50 @@ public void testDiagramsAndGraphics() throws Exception {
421
428
assertTrue (TestUtils .getRequestsDone (1 , server ).contains (String .format ("/v1/substations?networkUuid=%s&variantId=%s&substationId=BBE1AA&substationId=BBE2AA" , NETWORK_UUID_STRING , VARIANT_ID )));
422
429
423
430
//get the lines map data of a network
424
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "LINE " , "MAP " , List .of (), "[]" );
425
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "LINE " , "MAP " , List .of ("BBE1AA" ), "[]" );
431
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "LINE " , List .of ()) ), "[]" );
432
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "LINE " , List .of ("BBE1AA" )) ), "[]" );
426
433
427
434
//get the substation map data of a network
428
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "SUBSTATION " , "MAP " , List .of (), "[]" );
435
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "SUBSTATION " , List .of ()) ), "[]" );
429
436
430
437
//get the 2 windings transformers map data of a network
431
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "TWO_WINDINGS_TRANSFORMER " , "MAP " , List .of (), "[]" );
438
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "TWO_WINDINGS_TRANSFORMER " , List .of ()) ), "[]" );
432
439
433
440
//get the 3 windings transformers map data of a network
434
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "THREE_WINDINGS_TRANSFORMER " , "MAP " , List .of (), "[]" );
441
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "THREE_WINDINGS_TRANSFORMER " , List .of ()) ), "[]" );
435
442
436
443
//get the generators map data of a network
437
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "GENERATOR " , "MAP " , List .of (), "[]" );
444
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "GENERATOR " , List .of ()) ), "[]" );
438
445
439
446
//get the batteries map data of a network
440
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "BATTERY " , "MAP " , List .of (), "[]" );
447
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "BATTERY " , List .of ()) ), "[]" );
441
448
442
449
//get the dangling lines map data of a network
443
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "DANGLING_LINE " , "MAP " , List .of (), "[]" );
450
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "DANGLING_LINE " , List .of ()) ), "[]" );
444
451
445
452
//get the hvdc lines map data of a network
446
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "HVDC_LINE " , "MAP " , List .of (), "[]" );
453
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "HVDC_LINE " , List .of ()) ), "[]" );
447
454
448
455
//get the lcc converter stations map data of a network
449
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "LCC_CONVERTER_STATION " , "MAP " , List .of (), "[]" );
456
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "LCC_CONVERTER_STATION " , List .of ()) ), "[]" );
450
457
451
458
//get the vsc converter stations map data of a network
452
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "VSC_CONVERTER_STATION " , "MAP " , List .of (), "[]" );
459
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "VSC_CONVERTER_STATION " , List .of ()) ), "[]" );
453
460
454
461
//get the loads map data of a network
455
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "LOAD " , "MAP " , List .of (), "[]" );
462
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "LOAD " , List .of ()) ), "[]" );
456
463
457
464
//get the shunt compensators map data of a network
458
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "SHUNT_COMPENSATOR " , "MAP " , List .of (), "[]" );
465
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "SHUNT_COMPENSATOR " , List .of ()) ), "[]" );
459
466
460
467
//get the static var compensators map data of a network
461
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "STATIC_VAR_COMPENSATOR " , "MAP " , List .of (), "[]" );
468
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "STATIC_VAR_COMPENSATOR " , List .of ()) ), "[]" );
462
469
463
470
//get the voltage levels map data of a network
464
- getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "VOLTAGE_LEVEL " , "MAP " , List .of (), "[]" );
471
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP " , mapper . writeValueAsString ( createRequestBody ( "VOLTAGE_LEVEL " , List .of ()) ), "[]" );
465
472
466
473
//get all map data of a network
467
- getNetworkEquipmentsInfos (studyNameUserIdUuid , rootNodeUuid , "all" , List .of (), "[]" );
474
+ getNetworkElementsInfos (studyNameUserIdUuid , rootNodeUuid , "MAP" , mapper . writeValueAsString ( createRequestBody ( " all" , List .of ()) ), "[]" );
468
475
469
476
// get the svg component libraries
470
477
mockMvc .perform (get ("/v1/svg-component-libraries" )).andExpectAll (
@@ -586,19 +593,18 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU
586
593
}
587
594
588
595
@ SneakyThrows
589
- private MvcResult getNetworkElementsInfos (UUID studyUuid , UUID rootNodeUuid , String elementType , String infoType , List < String > substationsIds , String responseBody ) {
590
- UUID stubUuid = wireMockUtils .stubNetworkElementsInfosGet (NETWORK_UUID_STRING , elementType , infoType , responseBody );
591
- MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get ( "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/elements" , studyUuid , rootNodeUuid )
592
- . queryParam ( QUERY_PARAM_ELEMENT_TYPE , elementType )
596
+ private MvcResult getNetworkElementsInfos (UUID studyUuid , UUID rootNodeUuid , String infoType , String requestBody , String responseBody ) {
597
+ UUID stubUuid = wireMockUtils .stubNetworkElementsInfosPost (NETWORK_UUID_STRING , infoType , responseBody );
598
+
599
+ MockHttpServletRequestBuilder mockHttpServletRequestBuilder = post ( "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/elements" , studyUuid , rootNodeUuid )
593
600
.queryParam (QUERY_PARAM_INFO_TYPE , infoType )
594
- .queryParam (String .format (QUERY_FORMAT_OPTIONAL_PARAMS , QUERY_PARAM_DC_POWERFACTOR ), Double .toString (LoadFlowParameters .DEFAULT_DC_POWER_FACTOR ));
595
- if (!substationsIds .isEmpty ()) {
596
- mockHttpServletRequestBuilder .queryParam (QUERY_PARAM_SUBSTATIONS_IDS , substationsIds .stream ().toArray (String []::new ));
597
- }
601
+ .queryParam (String .format (QUERY_FORMAT_OPTIONAL_PARAMS , QUERY_PARAM_DC_POWERFACTOR ), Double .toString (LoadFlowParameters .DEFAULT_DC_POWER_FACTOR ))
602
+ .content (requestBody );
603
+
598
604
MvcResult mvcResult = mockMvc .perform (mockHttpServletRequestBuilder )
599
605
.andExpect (status ().isOk ())
600
606
.andReturn ();
601
- wireMockUtils .verifyNetworkElementsInfosGet (stubUuid , NETWORK_UUID_STRING , elementType , infoType );
607
+ wireMockUtils .verifyNetworkElementsInfosPost (stubUuid , NETWORK_UUID_STRING , infoType , requestBody );
602
608
603
609
return mvcResult ;
604
610
}
0 commit comments