Skip to content

Commit e023639

Browse files
author
Slimane AMAR
committed
Fix tests
1 parent 8ff803b commit e023639

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

src/main/java/org/gridsuite/study/server/service/StudyServerExecutionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public CompletableFuture<Void> runAsyncAndComplete(Runnable runnable) {
4343
}
4444

4545
private void logAsyncError(Throwable e) {
46-
if (e != null) {
46+
if (LOGGER.isErrorEnabled() && e != null) {
4747
LOGGER.error(e.toString(), e);
4848
}
4949
}

src/test/java/org/gridsuite/study/server/LoadFLowUnitTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import org.gridsuite.study.server.repository.StudyRepository;
1717
import org.gridsuite.study.server.service.*;
1818
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
19+
import org.junit.jupiter.api.BeforeEach;
1920
import org.junit.jupiter.api.Test;
2021
import org.mockito.ArgumentCaptor;
22+
import org.mockito.stubbing.Answer;
2123
import org.springframework.beans.factory.annotation.Autowired;
2224
import org.springframework.boot.test.context.SpringBootTest;
2325
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -26,6 +28,7 @@
2628
import java.util.List;
2729
import java.util.Optional;
2830
import java.util.UUID;
31+
import java.util.concurrent.CompletableFuture;
2932

3033
import static org.assertj.core.api.Assertions.assertThat;
3134
import static org.gridsuite.study.server.dto.ComputationType.LOAD_FLOW;
@@ -71,6 +74,18 @@ class LoadFLowUnitTest {
7174
@MockBean
7275
StudyRepository studyRepository;
7376

77+
@SpyBean
78+
private StudyServerExecutionService studyServerExecutionService;
79+
80+
@BeforeEach
81+
void setup() {
82+
// Synchronize for tests
83+
doAnswer((Answer<CompletableFuture>) invocation -> {
84+
((Runnable) invocation.getArguments()[0]).run();
85+
return CompletableFuture.completedFuture(null);
86+
}).when(studyServerExecutionService).runAsyncAndComplete(any(Runnable.class));
87+
}
88+
7489
@Test
7590
void testRunLoadFlow() {
7691
when(rootNetworkNodeInfoService.getComputationResultUuid(nodeUuid, rootNetworkUuid, LOAD_FLOW)).thenReturn(null);

src/test/java/org/gridsuite/study/server/NetworkModificationTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.gridsuite.study.server.service.*;
4747
import org.gridsuite.study.server.service.client.dynamicsecurityanalysis.DynamicSecurityAnalysisClient;
4848
import org.gridsuite.study.server.service.client.dynamicsimulation.DynamicSimulationClient;
49-
import org.gridsuite.study.server.service.LoadFlowService;
5049
import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService;
5150
import org.gridsuite.study.server.utils.*;
5251
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
@@ -58,6 +57,7 @@
5857
import org.junit.jupiter.api.extension.ExtendWith;
5958
import org.junit.jupiter.params.ParameterizedTest;
6059
import org.junit.jupiter.params.provider.EnumSource;
60+
import org.mockito.stubbing.Answer;
6161
import org.slf4j.Logger;
6262
import org.slf4j.LoggerFactory;
6363
import org.springframework.beans.factory.annotation.Autowired;
@@ -76,6 +76,7 @@
7676
import org.springframework.test.web.servlet.MvcResult;
7777

7878
import java.util.*;
79+
import java.util.concurrent.CompletableFuture;
7980

8081
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
8182
import static org.gridsuite.study.server.StudyConstants.HEADER_ERROR_MESSAGE;
@@ -86,8 +87,8 @@
8687
import static org.gridsuite.study.server.utils.SendInput.POST_ACTION_SEND_INPUT;
8788
import static org.hamcrest.MatcherAssert.assertThat;
8889
import static org.junit.jupiter.api.Assertions.*;
89-
import static org.mockito.Mockito.doReturn;
90-
import static org.mockito.Mockito.when;
90+
import static org.mockito.ArgumentMatchers.any;
91+
import static org.mockito.Mockito.*;
9192
import static org.springframework.http.MediaType.APPLICATION_JSON;
9293
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
9394
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@@ -234,6 +235,9 @@ class NetworkModificationTest {
234235
@Autowired
235236
private TestUtils studyTestUtils;
236237

238+
@SpyBean
239+
private StudyServerExecutionService studyServerExecutionService;
240+
237241
@Autowired
238242
private ObjectMapper objectMapper;
239243

@@ -261,6 +265,12 @@ void setup(final MockWebServer server) {
261265

262266
when(networkStoreService.getNetwork(NETWORK_UUID)).thenReturn(network);
263267

268+
// Synchronize for tests
269+
doAnswer((Answer<CompletableFuture>) invocation -> {
270+
((Runnable) invocation.getArguments()[0]).run();
271+
return CompletableFuture.completedFuture(null);
272+
}).when(studyServerExecutionService).runAsyncAndComplete(any(Runnable.class));
273+
264274
wireMockServer = new WireMockServer(wireMockConfig().dynamicPort().extensions(new SendInput(input)));
265275
wireMockUtils = new WireMockUtils(wireMockServer);
266276

src/test/java/org/gridsuite/study/server/StudyTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import java.net.URLDecoder;
8888
import java.nio.charset.StandardCharsets;
8989
import java.util.*;
90+
import java.util.concurrent.CompletableFuture;
9091
import java.util.concurrent.CountDownLatch;
9192
import java.util.concurrent.TimeUnit;
9293
import java.util.regex.Matcher;
@@ -341,6 +342,9 @@ class StudyTest {
341342
@Autowired
342343
private TestUtils studyTestUtils;
343344

345+
@SpyBean
346+
private StudyServerExecutionService studyServerExecutionService;
347+
344348
private static EquipmentInfos toEquipmentInfos(Line line) {
345349
return EquipmentInfos.builder()
346350
.networkUuid(NETWORK_UUID)
@@ -380,6 +384,12 @@ private void initMockBeans(Network network) {
380384
.thenReturn(List.of(new VariantInfos(VariantManagerConstants.INITIAL_VARIANT_ID, 0)));
381385

382386
doNothing().when(networkStoreService).deleteNetwork(NETWORK_UUID);
387+
388+
// Synchronize for tests
389+
doAnswer((Answer<CompletableFuture>) invocation -> {
390+
((Runnable) invocation.getArguments()[0]).run();
391+
return CompletableFuture.completedFuture(null);
392+
}).when(studyServerExecutionService).runAsyncAndComplete(any(Runnable.class));
383393
}
384394

385395
private void initMockBeansNetworkNotExisting() {

0 commit comments

Comments
 (0)