diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index 884423c4b..5f0228702 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -237,7 +237,7 @@ void testModificationGroups() throws Exception { assertEquals(bsicListResult, List.of()); mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); assertApplicationStatusOK(mvcResult); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, "v1b1", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); // switch opening to create the default group mvcResult = mockMvc.perform(get("/v1/groups")).andExpectAll( @@ -291,7 +291,7 @@ void testRestoreNetworkModifications() throws Exception { mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); assertApplicationStatusOK(mvcResult); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, "v1b1", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); List modifications = modificationRepository.getModifications(TEST_GROUP_ID, true, true, false); assertEquals(1, modifications.size()); @@ -319,7 +319,7 @@ void testStashNetworkModifications() throws Exception { mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); assertApplicationStatusOK(mvcResult); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, "v1b1", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); List modifications = modificationRepository.getModifications(TEST_GROUP_ID, false, true); assertEquals(1, modifications.size()); @@ -347,7 +347,7 @@ void testDisableNetworkModifications() throws Exception { mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); assertApplicationStatusOK(mvcResult); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, "v1b1", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); List modifications = modificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(1, modifications.size()); @@ -375,7 +375,7 @@ void testDeleteModification() throws Exception { mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); assertApplicationStatusOK(mvcResult); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, "v1b1", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); List modifications = modificationRepository.getModifications(TEST_GROUP_ID, false, true); assertEquals(1, modifications.size()); @@ -856,7 +856,7 @@ void testDuplicateModificationGroup() throws Exception { .andReturn(); assertApplicationStatusOK(mvcResult); String resultAsString = mvcResult.getResponse().getContentAsString(); - testBranchCreationImpacts(mapper, resultAsString, IdentifiableType.LINE, "idLine1", Set.of("s1", "s2")); + testBranchCreationImpacts(mapper, resultAsString, Set.of("s1", "s2")); testNetworkModificationsCount(TEST_GROUP_ID, 2); diff --git a/src/test/java/org/gridsuite/modification/server/impacts/TestImpactUtils.java b/src/test/java/org/gridsuite/modification/server/impacts/TestImpactUtils.java index eb714d05c..28ee14aa2 100644 --- a/src/test/java/org/gridsuite/modification/server/impacts/TestImpactUtils.java +++ b/src/test/java/org/gridsuite/modification/server/impacts/TestImpactUtils.java @@ -78,11 +78,11 @@ public static void testElementImpacts(ObjectMapper mapper, String resultAsString assertThat(networkModificationResult.get()).recursivelyEquals(resultExpected); } - public static void testElementModificationImpact(ObjectMapper mapper, String resultAsString, IdentifiableType elementType, String elementId, Set substationIds) throws Exception { - testElementImpact(SimpleImpactType.MODIFICATION, mapper, resultAsString, elementType, elementId, substationIds); + public static void testElementModificationImpact(ObjectMapper mapper, String resultAsString, Set substationIds) throws Exception { + testElementImpact(mapper, resultAsString, substationIds); } - public static void testElementImpact(SimpleImpactType type, ObjectMapper mapper, String resultAsString, IdentifiableType elementType, String elementId, Set substationIds) throws Exception { + public static void testElementImpact(ObjectMapper mapper, String resultAsString, Set substationIds) throws Exception { Optional networkModificationResult = mapper.readValue(resultAsString, new TypeReference<>() { }); assertTrue(networkModificationResult.isPresent()); NetworkModificationResult resultExpected = NetworkModificationResult.builder() @@ -122,7 +122,7 @@ public static void testBranchCreationImpacts(ObjectMapper mapper, String resultA testBranchImpacts(mapper, SimpleImpactType.CREATION, resultAsString, branchType, branchId, breakerId1, disconnectorId1, substationId1, breakerId2, disconnectorId2, substationId2); } - public static void testBranchCreationImpacts(ObjectMapper mapper, String resultAsString, IdentifiableType elementType, String elementId, Set substationIds) throws Exception { + public static void testBranchCreationImpacts(ObjectMapper mapper, String resultAsString, Set substationIds) throws Exception { List substationsImpacts = createSubstationImpacts(substationIds); testElementImpacts(mapper, resultAsString, substationsImpacts); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/AbstractNetworkModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/AbstractNetworkModificationTest.java index ecbc094b4..3583232c4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/AbstractNetworkModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/AbstractNetworkModificationTest.java @@ -312,10 +312,12 @@ protected String getNetworkModificationUriWithBadVariant() { protected abstract void assertAfterNetworkModificationDeletion(); + @SuppressWarnings("java:S1130") // Exceptions are throws by overrides protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("{}", modificationInfos.getMessageValues()); } + @SuppressWarnings("java:S1130") // Exceptions are throws by overrides protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("{}", modificationInfos.getMessageValues()); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/EquipmentAttributeModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/EquipmentAttributeModificationTest.java index 4369c4a1d..82d128ed2 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/EquipmentAttributeModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/EquipmentAttributeModificationTest.java @@ -63,14 +63,14 @@ void testEquipmentAttributeModificationInfos() throws Exception { // switch opening mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, "v1b1", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); // switch in variant VARIANT_ID opening switchStatusModificationInfos.setEquipmentId("break1Variant"); switchStatusModificationInfosJson = mapper.writeValueAsString(switchStatusModificationInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri() + "&variantId=" + NetworkCreation.VARIANT_ID).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, "break1Variant", Set.of("s1Variant")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1Variant")); } @Test @@ -108,21 +108,21 @@ private void switchModifications(String extraParams, String switchId1, String sw switchStatusModificationInfos.setEquipmentAttributeValue(true); switchStatusModificationInfosJson = mapper.writeValueAsString(switchStatusModificationInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri() + extraParams).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, switchId1, substationsIds); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), substationsIds); // switch closing switchStatusModificationInfos.setEquipmentId(switchId2); switchStatusModificationInfos.setEquipmentAttributeValue(false); switchStatusModificationInfosJson = mapper.writeValueAsString(switchStatusModificationInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri() + extraParams).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, switchId2, substationsIds); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), substationsIds); // switch opening on another substation switchStatusModificationInfos.setEquipmentId(switchId3); switchStatusModificationInfos.setEquipmentAttributeValue(true); switchStatusModificationInfosJson = mapper.writeValueAsString(switchStatusModificationInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri() + extraParams).content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.SWITCH, switchId3, otherSubstationsIds); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), otherSubstationsIds); testNetworkModificationsCount(getGroupId(), modificationsCount); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GenerationDispatchTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GenerationDispatchTest.java index 6ca6bec90..187debc05 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GenerationDispatchTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GenerationDispatchTest.java @@ -557,14 +557,16 @@ void testGenerationDispatchWithSubstationsHierarchy() throws Exception { @Test void testGenerationDispatchErrorCheck() { + final Network network = Network.read("testGenerationDispatch.xiidm", getClass().getResourceAsStream("/testGenerationDispatch.xiidm")); + setNetwork(network); + GenerationDispatchInfos modification = GenerationDispatchInfos.builder().lossCoefficient(150.).defaultOutageRate(0.).build(); - setNetwork(Network.read("testGenerationDispatch.xiidm", getClass().getResourceAsStream("/testGenerationDispatch.xiidm"))); final GenerationDispatch generationDispatch1 = new GenerationDispatch(modification); - assertThrows(NetworkModificationException.class, () -> generationDispatch1.check(getNetwork()), "GENERATION_DISPATCH_ERROR : The loss coefficient must be between 0 and 100"); + assertThrows(NetworkModificationException.class, () -> generationDispatch1.check(network), "GENERATION_DISPATCH_ERROR : The loss coefficient must be between 0 and 100"); modification = GenerationDispatchInfos.builder().lossCoefficient(20.).defaultOutageRate(140.).build(); final GenerationDispatch generationDispatch2 = new GenerationDispatch(modification); - assertThrows(NetworkModificationException.class, () -> generationDispatch2.check(getNetwork()), "GENERATION_DISPATCH_ERROR : The default outage rate must be between 0 and 100"); + assertThrows(NetworkModificationException.class, () -> generationDispatch2.check(network), "GENERATION_DISPATCH_ERROR : The default outage rate must be between 0 and 100"); } @Test diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GroovyScriptTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GroovyScriptTest.java index 71491dc96..8a97c7824 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GroovyScriptTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GroovyScriptTest.java @@ -6,7 +6,6 @@ */ package org.gridsuite.modification.server.modifications; -import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.GroovyScriptInfos; @@ -74,42 +73,42 @@ void testGroovy() throws Exception { // apply groovy script with generator target P modification mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.GENERATOR, "idGenerator", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); // apply groovy script with load type modification groovyScriptInfos.setScript("network.getLoad('v1load').loadType=com.powsybl.iidm.network.LoadType.FICTITIOUS\n"); groovyScriptInfosJson = mapper.writeValueAsString(groovyScriptInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.LOAD, "v1load", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); // apply groovy script with lcc converter station power factor modification groovyScriptInfos.setScript("network.getLccConverterStation('v1lcc').powerFactor=1\n"); groovyScriptInfosJson = mapper.writeValueAsString(groovyScriptInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.HVDC_CONVERTER_STATION, "v1lcc", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); // apply groovy script with line R modification groovyScriptInfos.setScript("network.getLine('line1').r=2\n"); groovyScriptInfosJson = mapper.writeValueAsString(groovyScriptInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.LINE, "line1", Set.of("s1", "s2")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1", "s2")); // apply groovy script with two windings transformer ratio tap modification groovyScriptInfos.setScript("network.getTwoWindingsTransformer('trf1').getRatioTapChanger().tapPosition=2\n"); groovyScriptInfosJson = mapper.writeValueAsString(groovyScriptInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.TWO_WINDINGS_TRANSFORMER, "trf1", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); // apply groovy script with three windings transformer phase tap modification groovyScriptInfos.setScript("network.getThreeWindingsTransformer('trf6').getLeg1().getPhaseTapChanger().tapPosition=0\n"); groovyScriptInfosJson = mapper.writeValueAsString(groovyScriptInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(groovyScriptInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andReturn(); - testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.THREE_WINDINGS_TRANSFORMER, "trf6", Set.of("s1")); + testElementModificationImpact(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); testNetworkModificationsCount(getGroupId(), 6); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/ModificationUtilsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/ModificationUtilsTest.java index 2117bad56..1aacc1b81 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/ModificationUtilsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/ModificationUtilsTest.java @@ -4,57 +4,73 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.gridsuite.modification.server.modifications; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveModificationInfos; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.api.Test; import java.util.Collections; -import java.util.List; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchRuntimeException; import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_GENERATOR_ERROR; /** * @author David SARTORI */ + class ModificationUtilsTest { - private static final ModificationUtils INSTANCE = ModificationUtils.getInstance(); - @DisplayName("checkMaxQGreaterThanMinQ() success") - @ParameterizedTest(name = "{1}") - @MethodSource("successCases") - void testCheckMaxQGreaterThanMinQSuccess(final ReactiveCapabilityCurveModificationInfos point, final String errorMessage) { - INSTANCE.checkMaxQGreaterThanMinQ(Collections.singletonList(point), MODIFY_GENERATOR_ERROR, errorMessage); - } + @Test + void testCheckMaxQGreaterThanMinQ() { + var point1 = ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(2.0).oldMaxQ(1.0).minQ(10.0).maxQ(20.0).build(); + ModificationUtils.getInstance().checkMaxQGreaterThanMinQ( + Collections.singletonList(point1), + MODIFY_GENERATOR_ERROR, + "old KO, new OK: No exception should be thrown"); - private static List successCases() { - return List.of( - Arguments.of(ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(2.0).oldMaxQ(1.0).minQ(10.0).maxQ(20.0).build(), "old KO, new OK: No exception should be thrown"), - Arguments.of(ReactiveCapabilityCurveModificationInfos.builder().minQ(10.0).maxQ(20.0).build(), "old null, new OK: No exception should be thrown"), - Arguments.of(ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(10.0).oldMaxQ(20.0).build(), "old OK, new null: No exception should be thrown") + var point2 = ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(1.0).oldMaxQ(2.0).minQ(20.0).maxQ(10.0).build(); + var exception = (NetworkModificationException) catchRuntimeException(() -> ModificationUtils.getInstance().checkMaxQGreaterThanMinQ( + Collections.singletonList(point2), + MODIFY_GENERATOR_ERROR, + "old OK, new KO: ") ); - } + assertThat(exception.getType()).isEqualTo(MODIFY_GENERATOR_ERROR); + assertThat(exception) + .hasMessageEndingWith("old OK, new KO: maximum reactive power 10.0 is expected to be greater than or equal to minimum reactive power 20.0"); - @DisplayName("checkMaxQGreaterThanMinQ() fail") - @ParameterizedTest(name = "{1}") - @MethodSource("failureCases") - void testCheckMaxQGreaterThanMinQFailure(final ReactiveCapabilityCurveModificationInfos point, final String errorMessage) { - assertThatExceptionOfType(NetworkModificationException.class) - .isThrownBy(() -> INSTANCE.checkMaxQGreaterThanMinQ(Collections.singletonList(point), MODIFY_GENERATOR_ERROR, errorMessage)) - .withMessage(MODIFY_GENERATOR_ERROR.name() + " : " + errorMessage + "maximum reactive power 10.0 is expected to be greater than or equal to minimum reactive power 20.0") - .extracting(NetworkModificationException::getType).isEqualTo(MODIFY_GENERATOR_ERROR); - } + var point3 = ReactiveCapabilityCurveModificationInfos.builder().minQ(20.0).maxQ(10.0).build(); + exception = (NetworkModificationException) catchRuntimeException(() -> ModificationUtils.getInstance().checkMaxQGreaterThanMinQ( + Collections.singletonList(point3), + MODIFY_GENERATOR_ERROR, + "old null, new KO: ") + ); + assertThat(exception.getType()).isEqualTo(MODIFY_GENERATOR_ERROR); + assertThat(exception) + .hasMessageEndingWith("old null, new KO: maximum reactive power 10.0 is expected to be greater than or equal to minimum reactive power 20.0"); + + var point4 = ReactiveCapabilityCurveModificationInfos.builder().minQ(10.0).maxQ(20.0).build(); + ModificationUtils.getInstance().checkMaxQGreaterThanMinQ( + Collections.singletonList(point4), + MODIFY_GENERATOR_ERROR, + "old null, new OK: No exception should be thrown"); + + var point5 = ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(10.0).oldMaxQ(20.0).build(); + ModificationUtils.getInstance().checkMaxQGreaterThanMinQ( + Collections.singletonList(point5), + MODIFY_GENERATOR_ERROR, + "old OK, new null: No exception should be thrown"); - private static List failureCases() { - return List.of( - Arguments.of(ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(1.0).oldMaxQ(2.0).minQ(20.0).maxQ(10.0).build(), "old OK, new KO: "), - Arguments.of(ReactiveCapabilityCurveModificationInfos.builder().minQ(20.0).maxQ(10.0).build(), "old null, new KO: "), - Arguments.of(ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(20.0).oldMaxQ(10.0).build(), "old KO, new null: ") + var point6 = ReactiveCapabilityCurveModificationInfos.builder().oldMinQ(20.0).oldMaxQ(10.0).build(); + exception = (NetworkModificationException) catchRuntimeException(() -> ModificationUtils.getInstance().checkMaxQGreaterThanMinQ( + Collections.singletonList(point6), + MODIFY_GENERATOR_ERROR, + "old KO, new null: ") ); + assertThat(exception.getType()).isEqualTo(MODIFY_GENERATOR_ERROR); + assertThat(exception) + .hasMessageEndingWith("old KO, new null: maximum reactive power 10.0 is expected to be greater than or equal to minimum reactive power 20.0"); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInBusBreakerTest.java index a4492fec2..8354c9e0a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInBusBreakerTest.java @@ -98,6 +98,7 @@ protected void assertAfterNetworkModificationDeletion() { assertNull(getNetwork().getShuntCompensator("shuntOneId")); } + @Override protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SHUNT_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java index 2c555caad..03765c6d4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java @@ -103,7 +103,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithBusBarSectionErrors() throws Exception { + void testCreateWithBusBarSectionErrors() throws Exception { StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); staticVarCompensatorCreationInfos.setBusOrBusbarSectionId("notFoundBus"); mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(staticVarCompensatorCreationInfos)).contentType(MediaType.APPLICATION_JSON)) @@ -113,7 +113,7 @@ public void testCreateWithBusBarSectionErrors() throws Exception { } @Test - public void testCreateWithRegulatedTerminalError() throws Exception { + void testCreateWithRegulatedTerminalError() throws Exception { StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); staticVarCompensatorCreationInfos.setVoltageRegulationType(VoltageRegulationType.DISTANT); staticVarCompensatorCreationInfos.setRegulatingTerminalVlId("v1"); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java index 8897abc43..dacde794f 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java @@ -101,7 +101,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // invalid Generator id StaticVarCompensatorCreationInfos compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); compensatorCreationInfos.setEquipmentId(""); @@ -193,7 +193,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testCreateWithStandbyAutomatonErrors() throws Exception { + void testCreateWithStandbyAutomatonErrors() throws Exception { StaticVarCompensatorCreationInfos compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); compensatorCreationInfos.setStandbyAutomatonOn(true); compensatorCreationInfos.setB0(300.0); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationBusBreakerTest.java index 4f27b2ebb..16f5da3d3 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationBusBreakerTest.java @@ -7,7 +7,6 @@ package org.gridsuite.modification.server.modifications; import com.fasterxml.jackson.core.type.TypeReference; -import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.PhaseTapChanger; import com.powsybl.iidm.network.extensions.ConnectablePosition; @@ -402,7 +401,7 @@ private void testCreateTwoWindingsTransformerInBusBreaker(TwoWindingsTransformer String twoWindingsTransformerCreationInfosJson = mapper.writeValueAsString(twoWindingsTransformerCreationInfos); mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(twoWindingsTransformerCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); - testBranchCreationImpacts(mapper, mvcResult.getResponse().getContentAsString(), IdentifiableType.TWO_WINDINGS_TRANSFORMER, twoWindingsTransformerCreationInfos.getEquipmentId(), Set.of("s1")); + testBranchCreationImpacts(mapper, mvcResult.getResponse().getContentAsString(), Set.of("s1")); assertNotNull(getNetwork().getTwoWindingsTransformer(transformerId)); // transformer was created testNetworkModificationsCount(getGroupId(), actualSize); } diff --git a/src/test/java/org/gridsuite/modification/server/service/NetworkModificationApplicatorTest.java b/src/test/java/org/gridsuite/modification/server/service/NetworkModificationApplicatorTest.java index f19b0f28d..42708b1e3 100644 --- a/src/test/java/org/gridsuite/modification/server/service/NetworkModificationApplicatorTest.java +++ b/src/test/java/org/gridsuite/modification/server/service/NetworkModificationApplicatorTest.java @@ -4,6 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.gridsuite.modification.server.service; import com.powsybl.commons.report.ReportConstants; @@ -76,34 +77,100 @@ void shouldThrowExceptionOnBadSeverity() { assertThrows(IllegalArgumentException.class, () -> NetworkModificationApplicator.getApplicationStatus(rootReportNode)); } - @SuppressWarnings("checkstyle:SingleSpaceSeparator") private static Stream provideArgumentsForComputeHigherSeverity() { - final ReportNode infoReport = ReportNode.newRootReportNode() - .withMessageTemplate("info", "Info severity message") - .withSeverity(TypedValue.INFO_SEVERITY) - .build(); - final ReportNode warningReport = ReportNode.newRootReportNode() - .withMessageTemplate("warning", "Warning severity message") - .withSeverity(TypedValue.WARN_SEVERITY) - .build(); - final ReportNode errorReport = ReportNode.newRootReportNode() - .withMessageTemplate("error", "Error severity message") - .withSeverity(TypedValue.ERROR_SEVERITY) - .build(); - final ReportNode notSeverityReport = ReportNode.newRootReportNode() - .withMessageTemplate("notSeverity", "Not a severity message") - .withUntypedValue("rand", "random value") - .build(); return Stream.of( - Arguments.of(List.of(infoReport, infoReport, infoReport, infoReport, warningReport, errorReport), ApplicationStatus.WITH_ERRORS), - Arguments.of(List.of(infoReport, infoReport, infoReport, infoReport, warningReport, infoReport), ApplicationStatus.WITH_WARNINGS), - Arguments.of(List.of(infoReport, infoReport, infoReport, infoReport, infoReport, infoReport), ApplicationStatus.ALL_OK), - Arguments.of(List.of(errorReport, warningReport, infoReport, infoReport, infoReport, infoReport), ApplicationStatus.WITH_ERRORS), - Arguments.of(List.of(infoReport, errorReport, warningReport, infoReport, infoReport, infoReport), ApplicationStatus.WITH_ERRORS), - Arguments.of(List.of(infoReport, infoReport, errorReport, warningReport, infoReport, infoReport), ApplicationStatus.WITH_ERRORS), - Arguments.of(List.of(infoReport, infoReport, infoReport, errorReport, warningReport, infoReport), ApplicationStatus.WITH_ERRORS), - Arguments.of(List.of(notSeverityReport, notSeverityReport, notSeverityReport, warningReport, notSeverityReport, notSeverityReport), ApplicationStatus.WITH_WARNINGS), - Arguments.of(List.of(notSeverityReport, notSeverityReport, notSeverityReport, notSeverityReport, notSeverityReport, notSeverityReport), ApplicationStatus.ALL_OK) + Arguments.of(List.of( + infoReport, + infoReport, + infoReport, + infoReport, + warningReport, + errorReport), + ApplicationStatus.WITH_ERRORS), + Arguments.of(List.of( + infoReport, + infoReport, + infoReport, + infoReport, + warningReport, + infoReport), + ApplicationStatus.WITH_WARNINGS), + Arguments.of(List.of( + infoReport, + infoReport, + infoReport, + infoReport, + infoReport, + infoReport), + ApplicationStatus.ALL_OK), + Arguments.of(List.of( + errorReport, + warningReport, + infoReport, + infoReport, + infoReport, + infoReport), + ApplicationStatus.WITH_ERRORS), + Arguments.of(List.of( + infoReport, + errorReport, + warningReport, + infoReport, + infoReport, + infoReport), + ApplicationStatus.WITH_ERRORS), + Arguments.of(List.of( + infoReport, + infoReport, + errorReport, + warningReport, + infoReport, + infoReport), + ApplicationStatus.WITH_ERRORS), + Arguments.of(List.of( + infoReport, + infoReport, + infoReport, + errorReport, + warningReport, + infoReport), + ApplicationStatus.WITH_ERRORS), + Arguments.of(List.of( + notSeverityReport, + notSeverityReport, + notSeverityReport, + warningReport, + notSeverityReport, + notSeverityReport), + ApplicationStatus.WITH_WARNINGS), + Arguments.of(List.of( + notSeverityReport, + notSeverityReport, + notSeverityReport, + notSeverityReport, + notSeverityReport, + notSeverityReport), + ApplicationStatus.ALL_OK) ); } + + private static ReportNode infoReport = ReportNode.newRootReportNode() + .withMessageTemplate("info", "Info severity message") + .withSeverity(TypedValue.INFO_SEVERITY) + .build(); + + private static ReportNode warningReport = ReportNode.newRootReportNode() + .withMessageTemplate("warning", "Warning severity message") + .withSeverity(TypedValue.WARN_SEVERITY) + .build(); + + private static ReportNode errorReport = ReportNode.newRootReportNode() + .withMessageTemplate("error", "Error severity message") + .withSeverity(TypedValue.ERROR_SEVERITY) + .build(); + + private static ReportNode notSeverityReport = ReportNode.newRootReportNode() + .withMessageTemplate("notSeverity", "Not a severity message") + .withUntypedValue("rand", "random value") + .build(); } diff --git a/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java b/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java index 4c19d23da..2529c37ad 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java +++ b/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java @@ -18,6 +18,7 @@ import mockwebserver3.MockWebServer; import org.apache.commons.text.StringSubstitutor; import org.gridsuite.modification.server.service.ReportService; +import org.junit.platform.commons.util.StringUtils; import org.mockito.ArgumentCaptor; import org.springframework.cloud.stream.binder.test.OutputDestination; @@ -66,13 +67,9 @@ public static void purgeRequests(MockWebServer server) throws UncheckedInterrupt public static void assertQueuesEmptyThenClear(List destinations, OutputDestination output) { try { - for (String destination : destinations) { - try { - assertNull(output.receive(TIMEOUT, destination), "Should not be any messages in queue " + destination + " :"); - } catch (NullPointerException e) { - // Ignoring - } - } + destinations.forEach(destination -> assertNull(output.receive(TIMEOUT, destination), "Should not be any messages in queue " + destination)); + } catch (NullPointerException e) { + // Ignoring } finally { output.clear(); // purge in order to not fail the other tests } @@ -117,7 +114,7 @@ public static void setOperatingStatus(Network network, String identifiableName, public static String resourceToString(String resource) throws IOException { InputStream inputStream = Objects.requireNonNull(TestUtils.class.getResourceAsStream(resource)); String content = new String(ByteStreams.toByteArray(inputStream), StandardCharsets.UTF_8); - return content.replaceAll("\\s", ""); + return StringUtils.replaceWhitespaceCharacters(content, ""); } public static void assertLogNthMessage(String expectedMessage, String reportKey, ReportService reportService, int rank) {