|
77 | 77 | import static com.powsybl.network.store.model.NetworkStoreApi.VERSION;
|
78 | 78 | import static org.gridsuite.voltageinit.server.service.NotificationService.CANCEL_MESSAGE;
|
79 | 79 | import static org.gridsuite.voltageinit.server.service.NotificationService.HEADER_USER_ID;
|
80 |
| -import static org.junit.Assert.assertEquals; |
81 |
| -import static org.junit.Assert.assertNotNull; |
| 80 | +import static org.junit.Assert.*; |
82 | 81 | import static org.mockito.ArgumentMatchers.any;
|
83 | 82 | import static org.mockito.ArgumentMatchers.eq;
|
84 | 83 | import static org.mockito.BDDMockito.given;
|
@@ -173,6 +172,12 @@ private OpenReacResult buildOpenReacResult() {
|
173 | 172 | return openReacResult;
|
174 | 173 | }
|
175 | 174 |
|
| 175 | + private OpenReacResult buildNokOpenReacResult() { |
| 176 | + OpenReacAmplIOFiles openReacAmplIOFiles = new OpenReacAmplIOFiles(openReacParameters, network, false); |
| 177 | + openReacResult = new OpenReacResult(OpenReacStatus.NOT_OK, openReacAmplIOFiles, INDICATORS); |
| 178 | + return openReacResult; |
| 179 | + } |
| 180 | + |
176 | 181 | private VoltageInitParametersEntity buildVoltageInitParametersEntity() {
|
177 | 182 | return VoltageInitParametersInfos.builder()
|
178 | 183 | .voltageLimitsModification(List.of(VoltageLimitInfos.builder()
|
@@ -359,6 +364,37 @@ public void runTest() throws Exception {
|
359 | 364 |
|
360 | 365 | }
|
361 | 366 |
|
| 367 | + @Test |
| 368 | + public void testReturnsResultAndDoesNotGenerateModificationIfResultNotOk() throws Exception { |
| 369 | + try (MockedStatic<OpenReacRunner> openReacRunnerMockedStatic = Mockito.mockStatic(OpenReacRunner.class)) { |
| 370 | + openReacRunnerMockedStatic.when(() -> OpenReacRunner.runAsync(eq(network), eq(VARIANT_2_ID), any(OpenReacParameters.class), any(OpenReacConfig.class), any(ComputationManager.class))) |
| 371 | + .thenReturn(CompletableFutureTask.runAsync(this::buildNokOpenReacResult, ForkJoinPool.commonPool())); |
| 372 | + |
| 373 | + MvcResult result = mockMvc.perform(post( |
| 374 | + "/" + VERSION + "/networks/{networkUuid}/run-and-save?receiver=me&variantId=" + VARIANT_2_ID, NETWORK_UUID) |
| 375 | + .header(HEADER_USER_ID, "userId")) |
| 376 | + .andExpect(status().isOk()) |
| 377 | + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
| 378 | + .andReturn(); |
| 379 | + assertEquals(RESULT_UUID, mapper.readValue(result.getResponse().getContentAsString(), UUID.class)); |
| 380 | + |
| 381 | + Message<byte[]> resultMessage = output.receive(TIMEOUT, "voltageinit.result"); |
| 382 | + assertEquals(RESULT_UUID.toString(), resultMessage.getHeaders().get("resultUuid")); |
| 383 | + assertEquals("me", resultMessage.getHeaders().get("receiver")); |
| 384 | + |
| 385 | + result = mockMvc.perform(get( |
| 386 | + "/" + VERSION + "/results/{resultUuid}", RESULT_UUID)) |
| 387 | + .andExpect(status().isOk()) |
| 388 | + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
| 389 | + .andReturn(); |
| 390 | + |
| 391 | + VoltageInitResult resultDto = mapper.readValue(result.getResponse().getContentAsString(), VoltageInitResult.class); |
| 392 | + assertEquals(RESULT_UUID, resultDto.getResultUuid()); |
| 393 | + assertEquals(INDICATORS, resultDto.getIndicators()); |
| 394 | + assertNull(resultDto.getModificationsGroupUuid()); |
| 395 | + } |
| 396 | + } |
| 397 | + |
362 | 398 | @Test
|
363 | 399 | public void runWrongNetworkTest() throws Exception {
|
364 | 400 | MvcResult result = mockMvc.perform(post(
|
|
0 commit comments