1919import org .junit .jupiter .api .Test ;
2020import org .springframework .http .MediaType ;
2121import org .springframework .test .web .servlet .MvcResult ;
22+ import org .springframework .test .web .servlet .ResultActions ;
2223import org .springframework .util .CollectionUtils ;
2324
2425import java .util .*;
@@ -146,10 +147,10 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
146147 .add ();
147148 String modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
148149
149- MvcResult mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
150- .andExpect (request ().asyncStarted ()). andReturn () ;
151- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
152- .andExpect (status ().isOk ()). andReturn () ;
150+ ResultActions mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
151+ .andExpect (request ().asyncStarted ());
152+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
153+ .andExpect (status ().isOk ());
153154
154155 BatteryModificationInfos createdModification = (BatteryModificationInfos ) networkModificationRepository .getModifications (getGroupId (), false , true ).get (0 );
155156
@@ -160,10 +161,10 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
160161 batteryModificationInfos .setMinQ (new AttributeModification <>(-200. , OperationType .SET ));
161162 modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
162163
163- mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
164- .andExpect (request ().asyncStarted ()). andReturn () ;
165- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
166- .andExpect (status ().isOk ()). andReturn () ;
164+ mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
165+ .andExpect (request ().asyncStarted ());
166+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
167+ .andExpect (status ().isOk ());
167168
168169 createdModification = (BatteryModificationInfos ) networkModificationRepository .getModifications (getGroupId (), false , true ).get (1 );
169170
@@ -175,10 +176,10 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
175176 batteryModificationInfos .setMaxQ (new AttributeModification <>(200. , OperationType .SET ));
176177 modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
177178
178- mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
179- .andExpect (request ().asyncStarted ()). andReturn () ;
180- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
181- .andExpect (status ().isOk ()). andReturn () ;
179+ mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
180+ .andExpect (request ().asyncStarted ());
181+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
182+ .andExpect (status ().isOk ());
182183
183184 createdModification = (BatteryModificationInfos ) networkModificationRepository .getModifications (getGroupId (), false , true ).get (2 );
184185
@@ -189,10 +190,10 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
189190 batteryModificationInfos .setMinQ (new AttributeModification <>(-1.1 , OperationType .SET ));
190191 modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
191192
192- mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
193- .andExpect (request ().asyncStarted ()). andReturn () ;
194- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
195- .andExpect (status ().isOk ()). andReturn () ;
193+ mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
194+ .andExpect (request ().asyncStarted ());
195+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
196+ .andExpect (status ().isOk ());
196197
197198 createdModification = (BatteryModificationInfos ) networkModificationRepository .getModifications (getGroupId (), false , true ).get (3 );
198199
@@ -205,10 +206,10 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
205206 batteryModificationInfos .setMinP (null );
206207 batteryModificationInfos .setMaxP (null );
207208 modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
208- mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
209- .andExpect (request ().asyncStarted ()). andReturn () ;
210- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
211- .andExpect (status ().isOk ()). andReturn () ;
209+ mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
210+ .andExpect (request ().asyncStarted ());
211+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
212+ .andExpect (status ().isOk ());
212213 createdModification = (BatteryModificationInfos ) networkModificationRepository .getModifications (getGroupId (), false , true ).get (4 );
213214 assertThat (createdModification ).recursivelyEquals (batteryModificationInfos );
214215 testNetworkModificationsCount (getGroupId (), 5 );
@@ -221,10 +222,10 @@ void testDroopUnchanged() throws Exception {
221222 batteryModificationInfos .getDroop ().setValue (18f );
222223 String modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
223224
224- MvcResult mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
225- .andExpect (request ().asyncStarted ()). andReturn () ;
226- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
227- .andExpect (status ().isOk ()). andReturn () ;
225+ ResultActions mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
226+ .andExpect (request ().asyncStarted ());
227+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
228+ .andExpect (status ().isOk ());
228229
229230 BatteryModificationInfos createdModification = (BatteryModificationInfos ) networkModificationRepository .getModifications (getGroupId (), false , true ).get (0 );
230231
@@ -234,10 +235,10 @@ void testDroopUnchanged() throws Exception {
234235 batteryModificationInfos .setDroop (null );
235236 modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
236237
237- mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
238- .andExpect (request ().asyncStarted ()). andReturn () ;
239- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
240- .andExpect (status ().isOk ()). andReturn () ;
238+ mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
239+ .andExpect (request ().asyncStarted ());
240+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
241+ .andExpect (status ().isOk ());
241242
242243 createdModification = (BatteryModificationInfos ) networkModificationRepository .getModifications (getGroupId (), false , true ).get (0 );
243244
@@ -249,19 +250,19 @@ void testImpactsAfterActivePowerControlModifications() throws Exception {
249250 BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos ) buildModification ();
250251 String modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
251252
252- MvcResult mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
253- .andExpect (request ().asyncStarted ()). andReturn () ;
254- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
255- .andExpect (status ().isOk ()). andReturn () ;
253+ ResultActions mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
254+ .andExpect (request ().asyncStarted ());
255+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
256+ .andExpect (status ().isOk ());
256257 Battery battery = getNetwork ().getBattery ("v3Battery" );
257258 assertEquals (0.1f , battery .getExtension (ActivePowerControl .class ).getDroop ());
258259 assertTrue (battery .getExtension (ActivePowerControl .class ).isParticipate ());
259260 //modify only droop
260261 batteryModificationInfos .setDroop (new AttributeModification <>(0.5f , OperationType .SET ));
261262 modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
262- mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
263- .andExpect (request ().asyncStarted ()). andReturn () ;
264- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
263+ mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
264+ .andExpect (request ().asyncStarted ());
265+ MvcResult mvcResult = mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
265266 .andExpect (status ().isOk ()).andReturn ();
266267 //check impacts
267268 String resultAsString = mvcResult .getResponse ().getContentAsString ();
@@ -299,10 +300,10 @@ void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception {
299300 Double activePower = batteryModificationInfos .getTargetP () != null ? batteryModificationInfos .getTargetP ().getValue () : battery .getTargetP ();
300301
301302 String modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
302- MvcResult mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
303- .andExpect (request ().asyncStarted ()). andReturn () ;
304- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
305- .andExpect (status ().isOk ()). andReturn () ;
303+ ResultActions mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
304+ .andExpect (request ().asyncStarted ());
305+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
306+ .andExpect (status ().isOk ());
306307 assertLogMessage ("MODIFY_BATTERY_ERROR : Battery '" + "v3Battery" + "' : Active power " + activePower + " is expected to be equal to 0 or within the range of minimum active power and maximum active power: [" + minActivePower + ", " + maxActivePower + "]" ,
307308 ERROR_MESSAGE_KEY , reportService );
308309
@@ -346,9 +347,9 @@ void testMinQGreaterThanMaxQ() throws Exception {
346347 });
347348 }
348349 String modificationToCreateJson = getJsonBody (batteryModificationInfos , null );
349- MvcResult mvcResult = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
350- .andExpect (request ().asyncStarted ()). andReturn () ;
351- mvcResult = mockMvc .perform (asyncDispatch (mvcResult ))
350+ ResultActions mockMvcResultActions = mockMvc .perform (post (getNetworkModificationUri ()).content (modificationToCreateJson ).contentType (MediaType .APPLICATION_JSON ))
351+ .andExpect (request ().asyncStarted ());
352+ mockMvc .perform (asyncDispatch (mockMvcResultActions . andReturn () ))
352353 .andExpect (status ().isOk ()).andReturn ();
353354 assertLogMessage ("MODIFY_BATTERY_ERROR : Battery '" + "v3Battery" + "' : maximum reactive power " + maxQ .get () + " is expected to be greater than or equal to minimum reactive power " + minQ .get (),
354355 ERROR_MESSAGE_KEY , reportService );
0 commit comments