Skip to content

Commit 155a9f8

Browse files
committed
no unused variable
1 parent fb438ca commit 155a9f8

25 files changed

+447
-438
lines changed

src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.springframework.mock.web.MockMultipartFile;
5858
import org.springframework.test.web.servlet.MockMvc;
5959
import org.springframework.test.web.servlet.MvcResult;
60+
import org.springframework.test.web.servlet.ResultActions;
6061
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
6162

6263
import java.io.IOException;
@@ -218,11 +219,11 @@ void testEquipmentIdNonNull() {
218219
@Test
219220
void testNetworkNotFound() throws Exception {
220221
String body = getJsonBody(LoadCreationInfos.builder().equipmentId("id").build(), NOT_FOUND_NETWORK_ID, NetworkCreation.VARIANT_ID);
221-
MvcResult mvcResult = mockMvc.perform(post(NETWORK_MODIFICATION_URI)
222+
ResultActions mockMvcResultActions = mockMvc.perform(post(NETWORK_MODIFICATION_URI)
222223
.content(body)
223224
.contentType(MediaType.APPLICATION_JSON))
224-
.andExpect(request().asyncStarted()).andReturn();
225-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
225+
.andExpect(request().asyncStarted());
226+
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
226227
.andExpectAll(
227228
status().isNotFound(),
228229
content().string(new NetworkModificationException(NETWORK_NOT_FOUND, NOT_FOUND_NETWORK_ID.toString()).getMessage())
@@ -256,9 +257,9 @@ void testModificationGroups() throws Exception {
256257
resultAsString = mvcResult.getResponse().getContentAsString();
257258
List<UUID> bsicListResult = mapper.readValue(resultAsString, new TypeReference<>() { });
258259
assertEquals(bsicListResult, List.of());
259-
mvcResult = mockMvc.perform(post(NETWORK_MODIFICATION_URI).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
260-
.andExpect(request().asyncStarted()).andReturn();
261-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
260+
ResultActions mockMvcResultActions = mockMvc.perform(post(NETWORK_MODIFICATION_URI).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
261+
.andExpect(request().asyncStarted());
262+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
262263
.andExpect(status().isOk()).andReturn();
263264
assertApplicationStatusOK(mvcResult);
264265
testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1"));
@@ -461,9 +462,9 @@ void testNetworkModificationsWithErrorOnNetworkFlush() throws Exception {
461462
.build();
462463
String groovyScriptInfosJson = getJsonBody(groovyScriptInfos, TEST_NETWORK_WITH_FLUSH_ERROR_ID, NetworkCreation.VARIANT_ID);
463464

464-
MvcResult mvcResult = mockMvc.perform(post(NETWORK_MODIFICATION_URI).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON))
465-
.andExpect(request().asyncStarted()).andReturn();
466-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().is5xxServerError()).andReturn();
465+
ResultActions mockMvcResultActions = mockMvc.perform(post(NETWORK_MODIFICATION_URI).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON))
466+
.andExpect(request().asyncStarted());
467+
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn())).andExpect(status().is5xxServerError()).andReturn();
467468

468469
assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, true, false).size());
469470
}
@@ -1034,12 +1035,12 @@ void testDuplicateModificationGroup() throws Exception {
10341035
MvcResult mvcResult;
10351036
VoltageLevelCreationInfos vl1 = ModificationCreation.getCreationVoltageLevel("s1", "vl1Id", "vl1Name");
10361037
String bodyJson = getJsonBody(vl1, TEST_NETWORK_BUS_BREAKER_ID, null);
1037-
mvcResult = mockMvc.perform(
1038+
ResultActions mockMvcResultActions = mockMvc.perform(
10381039
post(NETWORK_MODIFICATION_URI)
10391040
.content(bodyJson)
10401041
.contentType(MediaType.APPLICATION_JSON))
1041-
.andExpect(request().asyncStarted()).andReturn();
1042-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
1042+
.andExpect(request().asyncStarted());
1043+
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
10431044
.andExpect(status().isOk())
10441045
.andReturn();
10451046

src/test/java/org/gridsuite/modification/server/modifications/AbstractInjectionModificationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.gridsuite.modification.dto.OperationType;
1313
import org.junit.jupiter.api.Tag;
1414
import org.springframework.http.MediaType;
15-
import org.springframework.test.web.servlet.MvcResult;
15+
import org.springframework.test.web.servlet.ResultActions;
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch;
@@ -44,17 +44,17 @@ protected void assertChangeConnectionState(Injection<?> existingEquipment, Injec
4444
assertThat(existingEquipment.getTerminal().isConnected()).isNotEqualTo(expectedState);
4545

4646
String modificationInfosJson = getJsonBody(modificationInfos, null);
47-
MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON))
48-
.andExpect(request().asyncStarted()).andReturn();
49-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
47+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON))
48+
.andExpect(request().asyncStarted());
49+
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
5050
.andExpect(status().isOk()).andReturn();
5151
// connection state has changed as expected
5252
assertThat(existingEquipment.getTerminal().isConnected()).isEqualTo(expectedState);
5353

5454
// try to modify again => no change on connection state
55-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON))
56-
.andExpect(request().asyncStarted()).andReturn();
57-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
55+
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON))
56+
.andExpect(request().asyncStarted());
57+
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
5858
.andExpect(status().isOk()).andReturn();
5959
assertThat(existingEquipment.getTerminal().isConnected()).isEqualTo(expectedState);
6060
}

src/test/java/org/gridsuite/modification/server/modifications/AbstractNetworkModificationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.http.MediaType;
4040
import org.springframework.test.web.servlet.MockMvc;
4141
import org.springframework.test.web.servlet.MvcResult;
42+
import org.springframework.test.web.servlet.ResultActions;
4243

4344
import java.io.IOException;
4445
import java.util.*;
@@ -247,11 +248,11 @@ public void testCopy() throws Exception {
247248

248249
UUID modificationUuid = saveModification(modificationToCopy);
249250
String body = TestUtils.getJsonBody(List.of(modificationUuid), AbstractNetworkModificationTest.TEST_NETWORK_ID, null);
250-
MvcResult mvcResult = mockMvc.perform(put(URI_NETWORK_MODIF_COPY)
251+
ResultActions mockMvcResultActions = mockMvc.perform(put(URI_NETWORK_MODIF_COPY)
251252
.content(body)
252253
.contentType(MediaType.APPLICATION_JSON))
253-
.andExpect(request().asyncStarted()).andReturn();
254-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
254+
.andExpect(request().asyncStarted());
255+
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
255256
.andExpect(status().isOk()).andReturn();
256257

257258
List<ModificationInfos> modifications = networkModificationRepository

src/test/java/org/gridsuite/modification/server/modifications/BatteryModificationTest.java

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.jupiter.api.Test;
2020
import org.springframework.http.MediaType;
2121
import org.springframework.test.web.servlet.MvcResult;
22+
import org.springframework.test.web.servlet.ResultActions;
2223
import org.springframework.util.CollectionUtils;
2324

2425
import 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

Comments
 (0)