51
51
import org .springframework .test .web .servlet .request .MockHttpServletRequestBuilder ;
52
52
53
53
import java .io .IOException ;
54
- import java .util .List ;
55
- import java .util .Map ;
56
- import java .util .Objects ;
57
- import java .util .UUID ;
54
+ import java .util .*;
58
55
59
56
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
60
57
import static org .gridsuite .study .server .StudyConstants .*;
63
60
import static org .junit .Assert .assertEquals ;
64
61
import static org .junit .Assert .assertTrue ;
65
62
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
63
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
66
64
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
67
65
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
68
66
@@ -259,8 +257,8 @@ public void testGetHvdcLinesMapServer() throws Exception {
259
257
260
258
//get the hvdc lines ids of a network
261
259
String hvdcLineIdsAsString = List .of ("hvdc-line1" , "hvdc-line2" , "hvdc-line3" ).toString ();
262
- getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , "HVDC_LINE" , List .of (), hvdcLineIdsAsString );
263
- getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , "HVDC_LINE" , List .of ("S1" ), hvdcLineIdsAsString );
260
+ getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , hvdcLineIdsAsString , mapper . writeValueAsString ( createRequestBody ( "HVDC_LINE" , List .of ())) );
261
+ getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , hvdcLineIdsAsString , mapper . writeValueAsString ( createRequestBody ( "HVDC_LINE" , List .of ("S1" ))) );
264
262
}
265
263
266
264
@ Test
@@ -280,7 +278,7 @@ public void testGet2wtMapServer() throws Exception {
280
278
281
279
//get the 2wt ids of a network
282
280
String twtIdsAsString = List .of ("twt1" , "twt2" , "twt3" ).toString ();
283
- getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , "TWO_WINDINGS_TRANSFORMER" , List .of (), twtIdsAsString );
281
+ getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , twtIdsAsString , mapper . writeValueAsString ( createRequestBody ( "TWO_WINDINGS_TRANSFORMER" , List .of ())) );
284
282
assertTrue (TestUtils .getRequestsDone (3 , server ).stream ().anyMatch (r -> r .matches ("/v1/parameters/" + LOADFLOW_PARAMETERS_UUID_STRING )));
285
283
}
286
284
@@ -313,7 +311,7 @@ public void testGetSubstationMapServer() throws Exception {
313
311
314
312
//get the substation ids of a network
315
313
String substationIdsAsString = List .of ("substation1" , "substation2" , "substation3" ).toString ();
316
- getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , "SUBSTATION" , List .of (), substationIdsAsString );
314
+ getNetworkElementsIds (studyNameUserIdUuid , rootNodeUuid , substationIdsAsString , mapper . writeValueAsString ( createRequestBody ( "SUBSTATION" , List .of ())) );
317
315
assertTrue (TestUtils .getRequestsDone (1 , server ).stream ().anyMatch (r -> r .matches ("/v1/parameters/" + LOADFLOW_PARAMETERS_UUID_STRING )));
318
316
}
319
317
@@ -516,17 +514,15 @@ private RootNode getRootNode(UUID study) throws Exception {
516
514
}
517
515
518
516
@ SneakyThrows
519
- private MvcResult getNetworkElementsIds (UUID studyUuid , UUID rootNodeUuid , String elementType , List <String > substationsIds , String responseBody ) {
520
- UUID stubUuid = wireMockUtils .stubNetworkElementsIdsGet (NETWORK_UUID_STRING , elementType , responseBody );
521
- MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get ("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-map/equipments-ids" , studyUuid , rootNodeUuid )
522
- .queryParam (QUERY_PARAM_EQUIPMENT_TYPE , elementType );
523
- if (!substationsIds .isEmpty ()) {
524
- mockHttpServletRequestBuilder .queryParam (QUERY_PARAM_SUBSTATIONS_IDS , substationsIds .stream ().toArray (String []::new ));
525
- }
517
+ private MvcResult getNetworkElementsIds (UUID studyUuid , UUID rootNodeUuid , String responseBody , String requestBody ) {
518
+ UUID stubUuid = wireMockUtils .stubNetworkElementsIdsPost (NETWORK_UUID_STRING , responseBody );
519
+
520
+ MockHttpServletRequestBuilder mockHttpServletRequestBuilder = post ("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-map/equipments-ids" , studyUuid , rootNodeUuid )
521
+ .content (requestBody );
526
522
MvcResult mvcResult = mockMvc .perform (mockHttpServletRequestBuilder )
527
523
.andExpect (status ().isOk ())
528
524
.andReturn ();
529
- wireMockUtils .verifyNetworkElementsIdsGet (stubUuid , NETWORK_UUID_STRING , elementType );
525
+ wireMockUtils .verifyNetworkElementsIdsPost (stubUuid , NETWORK_UUID_STRING , requestBody );
530
526
531
527
return mvcResult ;
532
528
}
@@ -713,6 +709,13 @@ public void testGetNominalVoltagesError() throws Exception {
713
709
wireMockUtils .verifyNominalVoltagesGet (stubUuid , NETWORK_UUID_STRING );
714
710
}
715
711
712
+ private Map <String , Object > createRequestBody (String elementType , List <String > substationsIds ) {
713
+ Map <String , Object > requestBody = new HashMap <>();
714
+ requestBody .put ("elementType" , elementType );
715
+ requestBody .put ("substationsIds" , substationsIds );
716
+ return requestBody ;
717
+ }
718
+
716
719
private void cleanDB () {
717
720
studyRepository .findAll ().forEach (s -> networkModificationTreeService .doDeleteTree (s .getId ()));
718
721
studyRepository .deleteAll ();
0 commit comments