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