From 7a83a48d0294c0a699ffb84902fef67bc64d42cd Mon Sep 17 00:00:00 2001 From: Slimane AMAR Date: Fri, 16 Jun 2023 15:15:15 +0200 Subject: [PATCH 1/4] Migrate to PowSyBl 2023.2.1 Signed-off-by: Slimane AMAR --- pom.xml | 2 +- .../shortcircuit/server/ShortCircuitController.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9d41ad84..e9f15e1d 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ - 23 + 25 org.gridsuite.shortcircuit.server 3.11.1 diff --git a/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java b/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java index ba0ee781..dce59787 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java @@ -6,6 +6,7 @@ */ package org.gridsuite.shortcircuit.server; +import com.powsybl.commons.extensions.Extension; import com.powsybl.shortcircuit.ShortCircuitParameters; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -22,6 +23,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -43,7 +45,14 @@ public ShortCircuitController(ShortCircuitService shortCircuitService) { } private static ShortCircuitParameters getNonNullParameters(ShortCircuitParameters parameters) { - return parameters != null ? parameters : new ShortCircuitParameters(); + // Hack : remove with the future powsybl version + ShortCircuitParameters nonNullParameters = parameters != null ? parameters : new ShortCircuitParameters(); + Collection> extensions = ShortCircuitParameters.load().getExtensions(); + extensions.forEach(e -> { + e.setExtendable(null); + nonNullParameters.addExtension((Class) e.getClass(), e); + }); + return nonNullParameters; } @PostMapping(value = "/networks/{networkUuid}/run-and-save", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) From 997d86e2e2c1281d20545fa133100257eaa96c24 Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Wed, 21 Jun 2023 13:56:45 +0200 Subject: [PATCH 2/4] Add test for extension in params + change comment Signed-off-by: Etienne Homer --- .../server/ShortCircuitController.java | 3 +- .../ShortCircuitAnalysisControllerTest.java | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java b/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java index dce59787..74f6b4bc 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitController.java @@ -45,7 +45,8 @@ public ShortCircuitController(ShortCircuitService shortCircuitService) { } private static ShortCircuitParameters getNonNullParameters(ShortCircuitParameters parameters) { - // Hack : remove with the future powsybl version + //FIXME : this hack has to be removed with the future powsybl version (should be 2023.3.0) + // See the related test to be removed parametersWithExtentionTest() ShortCircuitParameters nonNullParameters = parameters != null ? parameters : new ShortCircuitParameters(); Collection> extensions = ShortCircuitParameters.load().getExtensions(); extensions.forEach(e -> { diff --git a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java index ca70b67a..3a9fbbae 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java @@ -7,6 +7,7 @@ package org.gridsuite.shortcircuit.server; import com.fasterxml.jackson.databind.ObjectMapper; +import com.powsybl.commons.extensions.AbstractExtension; import com.powsybl.commons.reporter.Reporter; import com.powsybl.computation.ComputationManager; import com.powsybl.iidm.network.Network; @@ -21,6 +22,7 @@ import lombok.SneakyThrows; import org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisStatus; import org.gridsuite.shortcircuit.server.service.ReportService; +import org.gridsuite.shortcircuit.server.service.ShortCircuitService; import org.gridsuite.shortcircuit.server.service.UuidGeneratorService; import org.junit.After; import org.junit.Before; @@ -118,6 +120,9 @@ private static final class ShortCircuitAnalysisResultMock { @MockBean private NetworkStoreService networkStoreService; + @MockBean + private ShortCircuitService shortCircuitService; + @MockBean private ReportService reportService; @@ -304,6 +309,35 @@ public void mergingViewTest() { } } + //FIXME: test to be removed when the hack in ShortCircuitParameters.getNonNullParameters() is removed + @SneakyThrows + @Test + public void parametersWithExtentionTest() { + + class ShortCircuitParametersRandomExtension extends AbstractExtension { + @Override + public String getName() { + return "RandomExtension"; + } + } + + ShortCircuitParameters parametersWithExtentions = new ShortCircuitParameters(); + parametersWithExtentions.addExtension(ShortCircuitParametersRandomExtension.class, new ShortCircuitParametersRandomExtension()); + + try (MockedStatic shortCircuitAnalysisMockedStatic = Mockito.mockStatic(ShortCircuitParameters.class)) { + shortCircuitAnalysisMockedStatic.when(() -> ShortCircuitParameters.load()) + .thenReturn(parametersWithExtentions); + + MvcResult result = mockMvc.perform(post( + "/" + VERSION + "/networks/{networkUuid}/run-and-save?receiver=me&variantId=" + VARIANT_2_ID, NETWORK_UUID) + .header(HEADER_USER_ID, "userId")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); + assertEquals("", mapper.readValue(result.getResponse().getContentAsString(), UUID.class)); + } + } + @SneakyThrows @Test public void testStatus() { From 5a446f3702741c37a8d140c2173e4f5379aba786 Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Wed, 21 Jun 2023 14:04:07 +0200 Subject: [PATCH 3/4] fix test Signed-off-by: Etienne Homer --- .../shortcircuit/server/ShortCircuitAnalysisControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java index 3a9fbbae..ed2a4a40 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java @@ -334,7 +334,7 @@ public String getName() { .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); - assertEquals("", mapper.readValue(result.getResponse().getContentAsString(), UUID.class)); + assertEquals("", result.getResponse().getContentAsString()); } } From 8c30657c54e89853b1bd7cb236d30ce3f6e09dec Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Wed, 21 Jun 2023 14:19:08 +0200 Subject: [PATCH 4/4] fix UT Signed-off-by: Etienne Homer --- .../server/ShortCircuitAnalysisControllerTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java index ed2a4a40..16949986 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java @@ -22,7 +22,6 @@ import lombok.SneakyThrows; import org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisStatus; import org.gridsuite.shortcircuit.server.service.ReportService; -import org.gridsuite.shortcircuit.server.service.ShortCircuitService; import org.gridsuite.shortcircuit.server.service.UuidGeneratorService; import org.junit.After; import org.junit.Before; @@ -120,9 +119,6 @@ private static final class ShortCircuitAnalysisResultMock { @MockBean private NetworkStoreService networkStoreService; - @MockBean - private ShortCircuitService shortCircuitService; - @MockBean private ReportService reportService; @@ -334,7 +330,7 @@ public String getName() { .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); - assertEquals("", result.getResponse().getContentAsString()); + assertEquals(RESULT_UUID, mapper.readValue(result.getResponse().getContentAsString(), UUID.class)); } }