Skip to content

Commit 3e2e66d

Browse files
committed
Same every asyncStart in variable of type ResultActions and minimal diff
1 parent 155a9f8 commit 3e2e66d

28 files changed

+305
-297
lines changed

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

Lines changed: 135 additions & 136 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ protected void assertChangeConnectionState(Injection<?> existingEquipment, Injec
4747
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON))
4848
.andExpect(request().asyncStarted());
4949
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
50-
.andExpect(status().isOk()).andReturn();
50+
.andExpect(status().isOk());
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
5555
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON))
5656
.andExpect(request().asyncStarted());
5757
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
58-
.andExpect(status().isOk()).andReturn();
58+
.andExpect(status().isOk());
5959
assertThat(existingEquipment.getTerminal().isConnected()).isEqualTo(expectedState);
6060
}
6161
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public void testCreate() throws Exception {
136136
ModificationInfos modificationToCreate = buildModification();
137137
String bodyJson = getJsonBody(modificationToCreate, null);
138138

139-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(bodyJson).contentType(MediaType.APPLICATION_JSON))
140-
.andExpect(request().asyncStarted()).andReturn();
141-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
139+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(bodyJson).contentType(MediaType.APPLICATION_JSON))
140+
.andExpect(request().asyncStarted());
141+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
142142
.andExpect(status().isOk()).andReturn();
143143
networkModificationsResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
144144
assertEquals(1, extractApplicationStatus(networkModificationsResult).size());
@@ -162,9 +162,9 @@ public void testCreateDisabledModification() throws Exception {
162162
modificationToCreate.setActivated(false);
163163
String modificationToCreateJson = getJsonBody(modificationToCreate, null);
164164

165-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
166-
.andExpect(request().asyncStarted()).andReturn();
167-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
165+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
166+
.andExpect(request().asyncStarted());
167+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
168168
.andExpect(status().isOk()).andReturn();
169169
networkModificationsResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
170170
assertEquals(1, extractApplicationStatus(networkModificationsResult).size());
@@ -253,7 +253,7 @@ public void testCopy() throws Exception {
253253
.contentType(MediaType.APPLICATION_JSON))
254254
.andExpect(request().asyncStarted());
255255
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
256-
.andExpect(status().isOk()).andReturn();
256+
.andExpect(status().isOk());
257257

258258
List<ModificationInfos> modifications = networkModificationRepository
259259
.getModifications(TEST_GROUP_ID, false, true);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.http.HttpStatus;
2525
import org.springframework.http.MediaType;
2626
import org.springframework.test.web.servlet.MvcResult;
27+
import org.springframework.test.web.servlet.ResultActions;
2728
import org.springframework.web.client.HttpStatusCodeException;
2829

2930
import java.util.List;
@@ -123,9 +124,9 @@ public void testCreate() throws Exception {
123124
ModificationInfos modificationToCreate = buildModification();
124125
String bodyJson = getJsonBody(modificationToCreate, null);
125126

126-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(bodyJson).contentType(MediaType.APPLICATION_JSON))
127-
.andExpect(request().asyncStarted()).andReturn();
128-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
127+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(bodyJson).contentType(MediaType.APPLICATION_JSON))
128+
.andExpect(request().asyncStarted());
129+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
129130
.andExpect(status().isOk()).andReturn();
130131
networkModificationsResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
131132
assertEquals(1, extractApplicationStatus(networkModificationsResult).size());

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.junit.jupiter.api.Test;
1818
import org.springframework.http.MediaType;
1919
import org.springframework.test.web.servlet.MvcResult;
20+
import org.springframework.test.web.servlet.ResultActions;
2021

2122
import java.util.*;
2223

@@ -198,9 +199,9 @@ void testCreateWithErrors() throws Exception {
198199
batteryCreationInfos.setVoltageLevelId("v2");
199200
batteryCreationInfos.setBusOrBusbarSectionId("1B");
200201
batteryCreationInfosJson = getJsonBody(batteryCreationInfos, "variant_not_existing");
201-
MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(batteryCreationInfosJson).contentType(MediaType.APPLICATION_JSON))
202-
.andExpect(request().asyncStarted()).andReturn();
203-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
202+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(batteryCreationInfosJson).contentType(MediaType.APPLICATION_JSON))
203+
.andExpect(request().asyncStarted());
204+
MvcResult mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
204205
.andExpect(status().isOk()).andReturn();
205206
NetworkModificationsResult networkModificationsResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
206207
assertNotNull(networkModificationsResult);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
150150
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
151151
.andExpect(request().asyncStarted());
152152
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
153-
.andExpect(status().isOk());
153+
.andExpect(status().isOk()).andReturn();
154154

155155
BatteryModificationInfos createdModification = (BatteryModificationInfos) networkModificationRepository.getModifications(getGroupId(), false, true).get(0);
156156

@@ -164,7 +164,7 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
164164
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
165165
.andExpect(request().asyncStarted());
166166
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
167-
.andExpect(status().isOk());
167+
.andExpect(status().isOk()).andReturn();
168168

169169
createdModification = (BatteryModificationInfos) networkModificationRepository.getModifications(getGroupId(), false, true).get(1);
170170

@@ -179,7 +179,7 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
179179
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
180180
.andExpect(request().asyncStarted());
181181
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
182-
.andExpect(status().isOk());
182+
.andExpect(status().isOk()).andReturn();
183183

184184
createdModification = (BatteryModificationInfos) networkModificationRepository.getModifications(getGroupId(), false, true).get(2);
185185

@@ -193,7 +193,7 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
193193
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
194194
.andExpect(request().asyncStarted());
195195
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
196-
.andExpect(status().isOk());
196+
.andExpect(status().isOk()).andReturn();
197197

198198
createdModification = (BatteryModificationInfos) networkModificationRepository.getModifications(getGroupId(), false, true).get(3);
199199

@@ -209,7 +209,7 @@ void testMinMaxReactiveLimitsAttributesModification() throws Exception {
209209
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
210210
.andExpect(request().asyncStarted());
211211
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
212-
.andExpect(status().isOk());
212+
.andExpect(status().isOk()).andReturn();
213213
createdModification = (BatteryModificationInfos) networkModificationRepository.getModifications(getGroupId(), false, true).get(4);
214214
assertThat(createdModification).recursivelyEquals(batteryModificationInfos);
215215
testNetworkModificationsCount(getGroupId(), 5);
@@ -273,9 +273,9 @@ void testImpactsAfterActivePowerControlModifications() throws Exception {
273273
//modify only participate
274274
batteryModificationInfos.setParticipate(new AttributeModification<>(false, OperationType.SET));
275275
modificationToCreateJson = getJsonBody(batteryModificationInfos, null);
276-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
277-
.andExpect(request().asyncStarted()).andReturn();
278-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
276+
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
277+
.andExpect(request().asyncStarted());
278+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
279279
.andExpect(status().isOk()).andReturn();
280280
//check impacts
281281
resultAsString = mvcResult.getResponse().getContentAsString();
@@ -303,7 +303,7 @@ void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception {
303303
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
304304
.andExpect(request().asyncStarted());
305305
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
306-
.andExpect(status().isOk());
306+
.andExpect(status().isOk()).andReturn();
307307
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 + "]",
308308
ERROR_MESSAGE_KEY, reportService);
309309

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ void testEquipmentAttributeModificationInfos() throws Exception {
6565
String switchStatusModificationInfosJson = getJsonBody(switchStatusModificationInfos, null);
6666

6767
// switch opening
68-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
69-
.andExpect(request().asyncStarted()).andReturn();
70-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
68+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
69+
.andExpect(request().asyncStarted());
70+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
7171
.andExpect(status().isOk()).andReturn();
7272
testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1"));
7373

7474
// switch in variant VARIANT_ID opening
7575
switchStatusModificationInfos.setEquipmentId("break1Variant");
7676
switchStatusModificationInfosJson = getJsonBody(switchStatusModificationInfos, NetworkCreation.VARIANT_ID);
77-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
78-
.andExpect(request().asyncStarted()).andReturn();
79-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
77+
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
78+
.andExpect(request().asyncStarted());
79+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
8080
.andExpect(status().isOk()).andReturn();
8181
testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1Variant"));
8282
}
@@ -119,28 +119,27 @@ private void switchModifications(String extraParams, String switchId1, String sw
119119
// switch opening
120120
switchStatusModificationInfos.setEquipmentAttributeValue(true);
121121
switchStatusModificationInfosJson = getJsonBody(switchStatusModificationInfos, extraParams);
122-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
123-
.andExpect(request().asyncStarted()).andReturn();
124-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andReturn();
122+
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
123+
.andExpect(request().asyncStarted());
124+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn())).andExpect(status().isOk()).andReturn();
125125
testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), substationsIds);
126126

127127
// switch closing
128128
switchStatusModificationInfos.setEquipmentId(switchId2);
129129
switchStatusModificationInfos.setEquipmentAttributeValue(false);
130130
switchStatusModificationInfosJson = getJsonBody(switchStatusModificationInfos, extraParams);
131-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
132-
.andExpect(request().asyncStarted()).andReturn();
133-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
134-
.andExpect(status().isOk()).andReturn();
131+
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
132+
.andExpect(request().asyncStarted());
133+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn())).andExpect(status().isOk()).andReturn();
135134
testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), substationsIds);
136135

137136
// switch opening on another substation
138137
switchStatusModificationInfos.setEquipmentId(switchId3);
139138
switchStatusModificationInfos.setEquipmentAttributeValue(true);
140139
switchStatusModificationInfosJson = getJsonBody(switchStatusModificationInfos, extraParams);
141-
mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
142-
.andExpect(request().asyncStarted()).andReturn();
143-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andReturn();
140+
mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON))
141+
.andExpect(request().asyncStarted());
142+
mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn())).andExpect(status().isOk()).andReturn();
144143
testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), otherSubstationsIds);
145144

146145
testNetworkModificationsCount(getGroupId(), modificationsCount);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ void testOkWhenRemovingIsolatedEquipment() throws Exception {
9393
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(equipmentDeletionInfosJson).contentType(MediaType.APPLICATION_JSON))
9494
.andExpect(request().asyncStarted());
9595
mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
96-
.andExpect(status().isOk());
96+
.andExpect(status().isOk())
97+
.andReturn();
9798

9899
var v5 = getNetwork().getVoltageLevel("v5");
99100
assertNull(v5.getNodeBreakerView().getTerminal(2));
@@ -133,9 +134,9 @@ private void deleteHvdcLineWithShuntCompensator(String shuntNameToBeRemoved, boo
133134
.build();
134135
String equipmentDeletionInfosJson = getJsonBody(equipmentDeletionInfos, null);
135136

136-
MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(equipmentDeletionInfosJson).contentType(MediaType.APPLICATION_JSON))
137-
.andExpect(request().asyncStarted()).andReturn();
138-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
137+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(equipmentDeletionInfosJson).contentType(MediaType.APPLICATION_JSON))
138+
.andExpect(request().asyncStarted());
139+
MvcResult mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
139140
.andExpect(status().isOk())
140141
.andReturn();
141142
NetworkModificationsResult networkModificationsResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,9 @@ void testGenerationDispatchWithMaxValueLessThanMinP() throws Exception {
606606
.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId();
607607

608608
String modificationJson = getJsonBody(modification, null);
609-
MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON))
610-
.andExpect(request().asyncStarted()).andReturn();
611-
mvcResult = mockMvc.perform(asyncDispatch(mvcResult))
609+
ResultActions mockMvcResultActions = mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON))
610+
.andExpect(request().asyncStarted());
611+
MvcResult mvcResult = mockMvc.perform(asyncDispatch(mockMvcResultActions.andReturn()))
612612
.andExpect(status().isOk()).andReturn();
613613
NetworkModificationsResult networkModificationsResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { });
614614
assertEquals(1, extractApplicationStatus(networkModificationsResult).size());

0 commit comments

Comments
 (0)