diff --git a/pom.xml b/pom.xml index 222be8f32..6ebfe3682 100644 --- a/pom.xml +++ b/pom.xml @@ -46,11 +46,14 @@ 34 1.0.5 - 0.0.2 - 1.16.2 + 5.0.0-alpha.14 org.gridsuite.modification.server - 1.18.2 + 1.19.0 + **/migration/**/* + + 1.0.14 @@ -86,6 +89,13 @@ + + com.squareup.okhttp3 + okhttp-bom + ${mockwebserver3.version} + pom + import + com.powsybl powsybl-network-store-client @@ -116,26 +126,19 @@ - de.dentrassi.elasticsearch - log4j2-mock - ${log4j2-mock-version} - - - org.testcontainers - elasticsearch - ${testcontainers.version} - test + com.vladmihalcea + db-util + ${db-util.version} - - org.gridsuite gridsuite-filter + ${filter.version} com.powsybl @@ -210,7 +213,6 @@ org.liquibase liquibase-core - runtime org.springframework.cloud @@ -219,71 +221,46 @@ - com.powsybl powsybl-config-test test - org.springframework.boot spring-boot-starter-test test - - junit - junit - test - org.assertj assertj-guava test - - - org.junit.vintage - junit-vintage-engine - test - - com.h2database h2 test - com.vladmihalcea db-util - ${db-util.version} test - org.testcontainers - elasticsearch + junit-jupiter test - - de.dentrassi.elasticsearch - log4j2-mock - test - - - - com.squareup.okhttp3 - okhttp + org.testcontainers + elasticsearch test com.squareup.okhttp3 - mockwebserver + mockwebserver3-junit5 test - org.springframework.cloud spring-cloud-stream-test-binder diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java index b8e6bddce..8175e5f04 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java @@ -235,9 +235,11 @@ public ResponseEntity stashNetworkModifications( @Parameter(description = "Group UUID") @RequestParam("groupUuid") UUID groupUuid, @Parameter(description = "stash or unstash network modifications") @RequestParam(name = "stashed", defaultValue = "true") Boolean stashed) { if (Boolean.TRUE.equals(stashed)) { - networkModificationService.stashNetworkModifications(networkModificationUuids); + networkModificationService.stashNetworkModifications(groupUuid, networkModificationUuids); + networkModificationService.reorderNetworkModifications(groupUuid, Boolean.FALSE); } else { - networkModificationService.restoreNetworkModifications(networkModificationUuids); + networkModificationService.restoreNetworkModifications(groupUuid, networkModificationUuids); + networkModificationService.reorderNetworkModifications(groupUuid, Boolean.TRUE); } return ResponseEntity.ok().build(); } diff --git a/src/main/java/org/gridsuite/modification/server/dto/ReactiveCapabilityCurveModificationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/ReactiveCapabilityCurveModificationInfos.java index 1e534f9d0..d58e5d028 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/ReactiveCapabilityCurveModificationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/ReactiveCapabilityCurveModificationInfos.java @@ -4,14 +4,12 @@ * 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.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; import lombok.NoArgsConstructor; -import lombok.Setter; import lombok.experimental.SuperBuilder; /** @@ -21,8 +19,7 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -@Getter -@Setter +@Data @Schema(description = "Generator reactive capability curve point creation") public class ReactiveCapabilityCurveModificationInfos { @Schema(description = "Minimum reactive power ") diff --git a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java index 117db9718..f2688faca 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java @@ -16,8 +16,7 @@ import org.gridsuite.modification.server.modifications.ModificationUtils; import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_BATTERY_ERROR; -import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatteryActiveLimitsAttributes; -import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatterySetpointsAttributes; +import static org.gridsuite.modification.server.modifications.BatteryModification.*; /** * @author Seddik Yengui @@ -44,6 +43,7 @@ public static String getReferenceValue(Battery battery, String batteryField) { public static void setNewValue(Battery battery, String batteryField, @NotNull String newValue) { BatteryField field = BatteryField.valueOf(batteryField); + String errorMessage = String.format(ERROR_MESSAGE, battery.getId()); final AttributeModification attributeModification = new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET); switch (field) { case MINIMUM_ACTIVE_POWER -> @@ -53,7 +53,7 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St case ACTIVE_POWER_SET_POINT -> { ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower( attributeModification, null, null, battery.getMinP(), - battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : " + battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, errorMessage ); modifyBatterySetpointsAttributes(attributeModification, null, null, null, battery, null); } @@ -64,7 +64,8 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St ActivePowerControlAdder activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); ModificationUtils.getInstance().modifyActivePowerControlAttributes( activePowerControl, activePowerControlAdder, null, - new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null); + new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, + null, MODIFY_BATTERY_ERROR, errorMessage); } } } diff --git a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java index 028c313f4..d0bafe1f4 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java @@ -65,6 +65,7 @@ public static String getReferenceValue(Generator generator, String generatorFiel public static void setNewValue(Generator generator, String generatorField, @NotNull String newValue) { GeneratorField field = GeneratorField.valueOf(generatorField); + String errorMessage = String.format(ERROR_MESSAGE, generator.getId()); switch (field) { case MAXIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes( new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), @@ -75,7 +76,7 @@ public static void setNewValue(Generator generator, String generatorField, @NotN ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower( new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), null, null, generator.getMinP(), generator.getMaxP(), generator.getTargetP(), - MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : " + MODIFY_GENERATOR_ERROR, errorMessage ); generator.setTargetP(Double.parseDouble(newValue)); } @@ -98,7 +99,8 @@ public static void setNewValue(Generator generator, String generatorField, @NotN ActivePowerControl activePowerControl = generator.getExtension(ActivePowerControl.class); ActivePowerControlAdder activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class); ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, null, - new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null); + new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null, + MODIFY_GENERATOR_ERROR, errorMessage); } case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes( new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), diff --git a/src/main/java/org/gridsuite/modification/server/entities/ModificationGroupEntity.java b/src/main/java/org/gridsuite/modification/server/entities/ModificationGroupEntity.java index 83bd1f5b1..a7c5ec30f 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/ModificationGroupEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/ModificationGroupEntity.java @@ -31,7 +31,7 @@ public class ModificationGroupEntity extends AbstractManuallyAssignedIdentifierE mappedBy = "group", cascade = CascadeType.ALL ) - @OrderColumn + @OrderBy("modificationsOrder asc") private List modifications = new ArrayList<>(); public ModificationGroupEntity(UUID uuid) { diff --git a/src/main/java/org/gridsuite/modification/server/migration/ModificationOrderMigration.java b/src/main/java/org/gridsuite/modification/server/migration/ModificationOrderMigration.java new file mode 100644 index 000000000..73d59a3ef --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/migration/ModificationOrderMigration.java @@ -0,0 +1,104 @@ +package org.gridsuite.modification.server.migration; + +import liquibase.change.custom.CustomSqlChange; +import liquibase.database.Database; +import liquibase.database.jvm.JdbcConnection; +import liquibase.exception.CustomChangeException; +import liquibase.exception.DatabaseException; +import liquibase.exception.SetupException; +import liquibase.exception.ValidationErrors; +import liquibase.resource.ResourceAccessor; +import liquibase.statement.SqlStatement; +import liquibase.statement.core.UpdateStatement; +import org.apache.commons.lang3.tuple.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.stream.IntStream; + +/** + * @author Etienne Lesot + */ +public class ModificationOrderMigration implements CustomSqlChange { + + private static final Logger LOGGER = LoggerFactory.getLogger(ModificationOrderMigration.class); + + @Override + public SqlStatement[] generateStatements(Database database) throws CustomChangeException { + JdbcConnection connection = (JdbcConnection) database.getConnection(); + List statements = new ArrayList<>(); + try (PreparedStatement stmt = connection.prepareStatement("select distinct group_id from modification where group_id is not null")) { + ResultSet groupIds = stmt.executeQuery(); + while (groupIds.next()) { + UUID groupId = UUID.fromString(groupIds.getString(1)); + reorderNetworkModifications(groupId, true, connection, statements, database); + reorderNetworkModifications(groupId, false, connection, statements, database); + } + } catch (SQLException | DatabaseException e) { + throw new CustomChangeException(e); + } + return statements.toArray(new SqlStatement[0]); + } + + private void reorderNetworkModifications(UUID groupId, boolean stashed, JdbcConnection connection, List statements, Database database) throws CustomChangeException { + List entities = findAllByGroupId(groupId, stashed, connection); + List> entitiesToUpdate = new ArrayList<>(); + if (!entities.isEmpty()) { + if (Boolean.TRUE.equals(stashed)) { + IntStream.range(1, entities.size() + 1) + .forEach(i -> entitiesToUpdate.add(Pair.of(entities.get(i - 1), -i))); + } else { + IntStream.range(0, entities.size()) + .forEach(i -> entitiesToUpdate.add(Pair.of(entities.get(i), i))); + } + } + createMigrationRequests(entitiesToUpdate, statements, database); + } + + private List findAllByGroupId(UUID groupId, boolean stashed, JdbcConnection connection) throws CustomChangeException { + try (PreparedStatement stmt = connection.prepareStatement("SELECT id FROM modification m WHERE m.group_id = ? AND m.stashed = ? order by modifications_order")) { + stmt.setObject(1, groupId); + stmt.setBoolean(2, stashed); + ResultSet resultSet = stmt.executeQuery(); + List entities = new ArrayList<>(); + while (resultSet.next()) { + entities.add(UUID.fromString(resultSet.getString(1))); + } + return entities; + } catch (SQLException | DatabaseException e) { + throw new CustomChangeException(e); + } + } + + private void createMigrationRequests(List> entities, List statements, Database database) { + entities.forEach(pair -> statements.add(new UpdateStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "modification") + .addNewColumnValue("modifications_order", pair.getValue()) + .setWhereClause(String.format("id='%s'", pair.getKey())))); + } + + @Override + public String getConfirmationMessage() { + return "modification order was successfully updated"; + } + + @Override + public void setUp() throws SetupException { + LOGGER.info("Set up migration for modification order"); + } + + @Override + public void setFileOpener(ResourceAccessor resourceAccessor) { + LOGGER.info("Set file opener for modification order"); + } + + @Override + public ValidationErrors validate(Database database) { + return new ValidationErrors(); + } +} diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java index 10345a8e2..655949b30 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java @@ -18,6 +18,8 @@ import java.util.List; import static org.gridsuite.modification.server.NetworkModificationException.Type.BATTERY_ALREADY_EXISTS; +import static org.gridsuite.modification.server.NetworkModificationException.Type.CREATE_BATTERY_ERROR; +import static org.gridsuite.modification.server.modifications.BatteryModification.ERROR_MESSAGE; import static org.gridsuite.modification.server.modifications.ModificationUtils.*; /** @@ -49,6 +51,9 @@ public void check(Network network) throws NetworkModificationException { modificationInfos.getErrorType(), modificationInfos.getEquipmentId(), "Battery"); + + ModificationUtils.getInstance().checkActivePowerControl(modificationInfos.getParticipate(), + modificationInfos.getDroop(), CREATE_BATTERY_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId())); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java index 15d9bd3ad..1cc5e234e 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java @@ -38,6 +38,7 @@ public class BatteryModification extends AbstractModification { private static final String LIMITS = "Limits"; private static final String ACTIVE_LIMITS = "Active limits"; private static final String SETPOINTS = "Setpoints"; + public static final String ERROR_MESSAGE = "Battery '%s' : "; public BatteryModification(BatteryModificationInfos modificationInfos) { this.modificationInfos = modificationInfos; @@ -171,7 +172,8 @@ public static ReportNode modifyBatteryActivePowerControlAttributes(AttributeModi ReportNode subReportNodeSetpoints) { ActivePowerControl activePowerControl = battery.getExtension(ActivePowerControl.class); ActivePowerControlAdder activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); - return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, participate, droop, subReportNode, subReportNodeSetpoints); + return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, + participate, droop, subReportNode, subReportNodeSetpoints, MODIFY_BATTERY_ERROR, String.format(ERROR_MESSAGE, battery.getId())); } private ReportNode modifyBatteryConnectivityAttributes(BatteryModificationInfos modificationInfos, diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java b/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java new file mode 100644 index 000000000..82efbedcc --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/modifications/BusbarSectionFinderTraverser.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * 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 com.powsybl.iidm.network.IdentifiableType; +import com.powsybl.iidm.network.Switch; +import com.powsybl.iidm.network.Terminal; +import com.powsybl.math.graph.TraverseResult; + +/** + * @author Slimane Amar + */ +// FIXME : to remove when this class is available in network-store +public class BusbarSectionFinderTraverser implements Terminal.TopologyTraverser { + + private final boolean onlyConnectedBbs; + + private String firstTraversedBbsId; + + public BusbarSectionFinderTraverser(boolean onlyConnectedBbs) { + this.onlyConnectedBbs = onlyConnectedBbs; + } + + @Override + public TraverseResult traverse(Terminal terminal, boolean connected) { + if (terminal.getConnectable().getType() == IdentifiableType.BUSBAR_SECTION) { + firstTraversedBbsId = terminal.getConnectable().getId(); + return TraverseResult.TERMINATE_TRAVERSER; + } + return TraverseResult.CONTINUE; + } + + @Override + public TraverseResult traverse(Switch aSwitch) { + if (onlyConnectedBbs && aSwitch.isOpen()) { + return TraverseResult.TERMINATE_PATH; + } + return TraverseResult.CONTINUE; + } + + public String getFirstTraversedBbsId() { + return firstTraversedBbsId; + } +} + diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java index 8931f4a3d..9599abe89 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java @@ -20,7 +20,8 @@ import java.util.ArrayList; import java.util.List; -import static org.gridsuite.modification.server.NetworkModificationException.Type.GENERATOR_ALREADY_EXISTS; +import static org.gridsuite.modification.server.NetworkModificationException.Type.*; +import static org.gridsuite.modification.server.modifications.GeneratorModification.ERROR_MESSAGE; import static org.gridsuite.modification.server.modifications.ModificationUtils.*; /** @@ -58,6 +59,9 @@ public void check(Network network) throws NetworkModificationException { modificationInfos.getRegulatingTerminalId(), modificationInfos.getRegulatingTerminalType(), modificationInfos.getRegulatingTerminalVlId()); + + ModificationUtils.getInstance().checkActivePowerControl(modificationInfos.getParticipate(), + modificationInfos.getDroop(), CREATE_GENERATOR_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId())); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java index 71a4508b9..72b4c41d6 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java @@ -29,6 +29,7 @@ public class GeneratorModification extends AbstractModification { private static final String LIMITS = "Limits"; private static final String ACTIVE_LIMITS = "Active limits"; private static final String SETPOINTS = "Setpoints"; + public static final String ERROR_MESSAGE = "Generator '%s' : "; private final GeneratorModificationInfos modificationInfos; @@ -210,7 +211,10 @@ private ReportNode modifyGeneratorActivePowerControlAttributes(GeneratorModifica Generator generator, ReportNode subReportNode, ReportNode subReportNodeSetpoints) { ActivePowerControl activePowerControl = generator.getExtension(ActivePowerControl.class); ActivePowerControlAdder activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class); - return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints); + + return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, + modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints, + MODIFY_GENERATOR_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId())); } private void modifyGeneratorStartUpAttributes(GeneratorModificationInfos modificationInfos, Generator generator, diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index a2f5a4833..534d31b5b 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.modification.topology.*; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.*; +import com.powsybl.math.graph.TraversalType; import com.powsybl.network.store.iidm.impl.MinMaxReactiveLimitsImpl; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; @@ -57,6 +58,12 @@ public final class ModificationUtils { public static final String CONNECTION_POSITION_FIELD_NAME = "Connection position"; public static final String NOT_EXIST_IN_NETWORK = " does not exist in network"; + public enum FeederSide { + INJECTION_SINGLE_SIDE, + BRANCH_SIDE_ONE, + BRANCH_SIDE_TWO + } + private ModificationUtils() { } @@ -615,10 +622,7 @@ public ReportNode modifyInjectionConnectivityAttributes(ConnectablePosition c InjectionModificationInfos modificationInfos, ReportNode connectivityReports) { List reports = new ArrayList<>(); - if (isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId(), modificationInfos.getBusOrBusbarSectionId(), modificationInfos.getEquipmentId(), reports)) { - return reports.get(0); - } - processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, injection.getNetwork(), reports, false); + processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, injection.getNetwork(), reports); modifyConnection(modificationInfos.getTerminalConnected(), injection, injection.getTerminal(), reports); return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); @@ -630,136 +634,122 @@ public ReportNode modifyBranchConnectivityAttributes(ConnectablePosition conn BranchModificationInfos modificationInfos, ReportNode connectivityReports) { List reports = new ArrayList<>(); - if (isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId1(), modificationInfos.getBusOrBusbarSectionId1(), modificationInfos.getEquipmentId(), reports) || - isVoltageOrBusbarIdMissing(modificationInfos.getVoltageLevelId2(), modificationInfos.getBusOrBusbarSectionId2(), modificationInfos.getEquipmentId(), reports)) { - return reports.get(0); - } - - processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, branch.getNetwork(), reports, true); + processConnectivityPosition(connectablePosition, connectablePositionAdder, modificationInfos, branch.getNetwork(), reports); modifyConnection(modificationInfos.getTerminal1Connected(), branch, branch.getTerminal1(), reports); modifyConnection(modificationInfos.getTerminal2Connected(), branch, branch.getTerminal2(), reports); return reportModifications(connectivityReports, reports, "ConnectivityModified", CONNECTIVITY); } - private boolean isVoltageOrBusbarIdMissing(AttributeModification voltageLevelId, AttributeModification busbarSectionId, String equipmentId, List reports) { - if (voltageLevelId == null || busbarSectionId == null) { - reports.add(ReportNode.newRootReportNode() - .withMessageTemplate("VoltageLevelOrBusbarSectionNotFound", - "Voltage level id or Bus bar section id of equipment id=${id} not found") - .withUntypedValue("id", equipmentId) - .withSeverity(TypedValue.WARN_SEVERITY) - .build()); - return true; - } - return false; - } - private void processConnectivityPosition(ConnectablePosition connectablePosition, ConnectablePositionAdder connectablePositionAdder, BasicEquipmentModificationInfos modificationInfos, Network network, - List reports, - boolean isBranch) { + List reports) { if (connectablePosition != null) { - modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports, isBranch); + modifyExistingConnectivityPosition(connectablePosition, modificationInfos, reports); } else { - createNewConnectivityPosition(connectablePositionAdder, modificationInfos, network, reports, isBranch); + createNewConnectivityPosition(connectablePositionAdder, modificationInfos, network, reports); } } private void modifyExistingConnectivityPosition(ConnectablePosition connectablePosition, BasicEquipmentModificationInfos modificationInfos, - List reports, - boolean isBranch) { - if (isBranch) { - modifyConnectablePosition(connectablePosition.getFeeder1(), modificationInfos, reports, 1); - modifyConnectablePosition(connectablePosition.getFeeder2(), modificationInfos, reports, 2); - } else { - modifyConnectablePosition(connectablePosition.getFeeder(), modificationInfos, reports, 0); + List reports) { + if (modificationInfos instanceof BranchModificationInfos) { + modifyConnectablePosition(connectablePosition.getFeeder1(), modificationInfos, reports, FeederSide.BRANCH_SIDE_ONE); + modifyConnectablePosition(connectablePosition.getFeeder2(), modificationInfos, reports, FeederSide.BRANCH_SIDE_TWO); + } else if (modificationInfos instanceof InjectionModificationInfos) { + modifyConnectablePosition(connectablePosition.getFeeder(), modificationInfos, reports, FeederSide.INJECTION_SINGLE_SIDE); } } private void createNewConnectivityPosition(ConnectablePositionAdder adder, BasicEquipmentModificationInfos modificationInfos, Network network, - List reports, - boolean isBranch) { - if (isBranch) { - ConnectablePositionAdder.FeederAdder feederAdder1 = adder.newFeeder1(); - ConnectablePositionAdder.FeederAdder feederAdder2 = adder.newFeeder2(); - addConnectablePosition(adder, feederAdder1, modificationInfos, network, reports, 1); - addConnectablePosition(adder, feederAdder2, modificationInfos, network, reports, 2); - } else { - ConnectablePositionAdder.FeederAdder feederAdder = adder.newFeeder(); - addConnectablePosition(adder, feederAdder, modificationInfos, network, reports, 0); + List reports) { + if (modificationInfos instanceof BranchModificationInfos) { + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.BRANCH_SIDE_ONE); + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.BRANCH_SIDE_TWO); + } else if (modificationInfos instanceof InjectionModificationInfos) { + addConnectablePosition(adder, modificationInfos, network, reports, FeederSide.INJECTION_SINGLE_SIDE); } } private void modifyConnectablePosition(ConnectablePosition.Feeder feeder, BasicEquipmentModificationInfos modificationInfos, List reports, - int feederNumber) { - applyModifications(feeder, modificationInfos, reports, feederNumber); + FeederSide feederSide) { + applyModifications(feeder, modificationInfos, reports, feederSide); } private void applyModifications(ConnectablePosition.Feeder feeder, BasicEquipmentModificationInfos modificationInfos, List reports, - int feederNumber) { + FeederSide feederSide) { ReportNode connectionNameReport = applyElementaryModificationsAndReturnReport(feeder::setName, feeder.getName()::get, - getConnectionName(modificationInfos, feederNumber), - getConnectionNameField(feederNumber)); + getConnectionName(modificationInfos, feederSide), + getConnectionNameField(feederSide)); if (connectionNameReport != null) { reports.add(connectionNameReport); } ReportNode connectionDirectionReport = applyElementaryModificationsAndReturnReport(feeder::setDirection, feeder::getDirection, - getConnectionDirection(modificationInfos, feederNumber), - getConnectionDirectionField(feederNumber)); + getConnectionDirection(modificationInfos, feederSide), + getConnectionDirectionField(feederSide)); if (connectionDirectionReport != null) { reports.add(connectionDirectionReport); } ReportNode connectionPositionReport = applyElementaryModificationsAndReturnReport(feeder::setOrder, feeder.getOrder()::get, - getConnectionPosition(modificationInfos, feederNumber), - getConnectionPositionField(feederNumber)); + getConnectionPosition(modificationInfos, feederSide), + getConnectionPositionField(feederSide)); if (connectionPositionReport != null) { reports.add(connectionPositionReport); } } private void addConnectablePosition(ConnectablePositionAdder adder, - ConnectablePositionAdder.FeederAdder feeder, BasicEquipmentModificationInfos modificationInfos, Network network, List reports, - int feederNumber) { - AttributeModification connectionName = getConnectionName(modificationInfos, feederNumber); - AttributeModification connectionDirection = getConnectionDirection(modificationInfos, feederNumber); - AttributeModification connectionPosition = getConnectionPosition(modificationInfos, feederNumber); + FeederSide feederSide) { + AttributeModification connectionName = getConnectionName(modificationInfos, feederSide); + AttributeModification connectionDirection = getConnectionDirection(modificationInfos, feederSide); + AttributeModification connectionPosition = getConnectionPosition(modificationInfos, feederSide); + if (Objects.isNull(connectionName) && Objects.isNull(connectionDirection) && Objects.isNull(connectionPosition)) { + return; + } AttributeModification equipmentId = getEquipmentId(modificationInfos); - AttributeModification voltageLevelId = getVoltageLevelId(modificationInfos, feederNumber); - AttributeModification busOrBusbarSectionId = getBusOrBusbarSectionId(modificationInfos, feederNumber); - int position = getPosition(connectionPosition, busOrBusbarSectionId, network, voltageLevelId); - + AttributeModification voltageLevelId = getVoltageLevelId(modificationInfos, feederSide); + AttributeModification busOrBusbarSectionId = getBusOrBusbarSectionId(modificationInfos, feederSide); + int position = getPosition(connectionPosition, busOrBusbarSectionId, voltageLevelId, equipmentId, feederSide, network); + ConnectablePositionAdder.FeederAdder feeder; + switch (feederSide) { + case INJECTION_SINGLE_SIDE -> feeder = adder.newFeeder(); + case BRANCH_SIDE_ONE -> feeder = adder.newFeeder1(); + case BRANCH_SIDE_TWO -> feeder = adder.newFeeder2(); + default -> { + return; + } + } ReportNode connectionNameReport = applyConnectablePositionAttribute( feeder::withName, connectionName, equipmentId, reports, - getConnectionNameField(feederNumber), connectionDirection, connectionPosition + getConnectionNameField(feederSide), connectionDirection, connectionPosition ); ReportNode connectionDirectionReport = applyConnectablePositionAttribute( feeder::withDirection, connectionDirection, new AttributeModification<>(ConnectablePosition.Direction.UNDEFINED, OperationType.SET), - reports, getConnectionDirectionField(feederNumber), + reports, getConnectionDirectionField(feederSide), connectionName, connectionPosition ); ReportNode connectionPositionReport = applyConnectablePositionAttribute( feeder::withOrder, connectionPosition, new AttributeModification<>(position, OperationType.SET), - reports, getConnectionPositionField(feederNumber), + reports, getConnectionPositionField(feederSide), connectionName, connectionDirection ); @@ -791,35 +781,38 @@ private boolean isAnyAttributesNonNull(AttributeModification... attributes) { return Arrays.stream(attributes).anyMatch(Objects::nonNull); } - private T getConnectionDetail(BasicEquipmentModificationInfos modificationInfos, int feederNumber, + private T getConnectionDetail(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide, Function branchFunc1, Function branchFunc2, Function injectionFunc) { if (modificationInfos instanceof BranchModificationInfos branchInfo) { - return feederNumber == 1 ? branchFunc1.apply(branchInfo) : branchFunc2.apply(branchInfo); + if (Objects.requireNonNull(feederSide) == FeederSide.BRANCH_SIDE_ONE) { + return branchFunc1.apply(branchInfo); + } else if (feederSide == FeederSide.BRANCH_SIDE_TWO) { + return branchFunc2.apply(branchInfo); + } } else if (modificationInfos instanceof InjectionModificationInfos injectionInfo) { return injectionFunc.apply(injectionInfo); } return null; } - private String getConnectionFieldName(int feederNumber, String baseFieldName) { - return switch (feederNumber) { - case 0 -> baseFieldName; - case 1 -> baseFieldName + " 1"; - case 2 -> baseFieldName + " 2"; - default -> ""; + private String getConnectionFieldName(FeederSide feederSide, String baseFieldName) { + return switch (feederSide) { + case INJECTION_SINGLE_SIDE -> baseFieldName; + case BRANCH_SIDE_ONE -> baseFieldName + " 1"; + case BRANCH_SIDE_TWO -> baseFieldName + " 2"; }; } - private AttributeModification getVoltageLevelId(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getVoltageLevelId(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getVoltageLevelId1, BranchModificationInfos::getVoltageLevelId2, InjectionModificationInfos::getVoltageLevelId); } - private AttributeModification getBusOrBusbarSectionId(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getBusOrBusbarSectionId(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getBusOrBusbarSectionId1, BranchModificationInfos::getBusOrBusbarSectionId2, InjectionModificationInfos::getBusOrBusbarSectionId); } @@ -828,46 +821,77 @@ private AttributeModification getEquipmentId(BasicEquipmentModificationI return AttributeModification.toAttributeModification(modificationInfos.getEquipmentId(), OperationType.SET); } - private AttributeModification getConnectionName(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionName(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionName1, BranchModificationInfos::getConnectionName2, InjectionModificationInfos::getConnectionName); } - private String getConnectionNameField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_NAME_FIELD_NAME); + private String getConnectionNameField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_NAME_FIELD_NAME); } - private String getConnectionDirectionField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_DIRECTION_FIELD_NAME); + private String getConnectionDirectionField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_DIRECTION_FIELD_NAME); } - private String getConnectionPositionField(int feederNumber) { - return getConnectionFieldName(feederNumber, CONNECTION_POSITION_FIELD_NAME); + private String getConnectionPositionField(FeederSide feederSide) { + return getConnectionFieldName(feederSide, CONNECTION_POSITION_FIELD_NAME); } - private AttributeModification getConnectionDirection(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionDirection(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionDirection1, BranchModificationInfos::getConnectionDirection2, InjectionModificationInfos::getConnectionDirection); } - private AttributeModification getConnectionPosition(BasicEquipmentModificationInfos modificationInfos, int feederNumber) { - return getConnectionDetail(modificationInfos, feederNumber, + private AttributeModification getConnectionPosition(BasicEquipmentModificationInfos modificationInfos, FeederSide feederSide) { + return getConnectionDetail(modificationInfos, feederSide, BranchModificationInfos::getConnectionPosition1, BranchModificationInfos::getConnectionPosition2, InjectionModificationInfos::getConnectionPosition); } + private String getBusOrBusbarSection(Terminal terminal) { + String busOrBusbarSectionId; + if (terminal.getVoltageLevel().getTopologyKind().equals(TopologyKind.BUS_BREAKER)) { + if (terminal.isConnected()) { + busOrBusbarSectionId = terminal.getBusBreakerView().getBus().getId(); + } else { + busOrBusbarSectionId = terminal.getBusBreakerView().getConnectableBus().getId(); + } + } else { + busOrBusbarSectionId = getBusbarSectionId(terminal); + } + return busOrBusbarSectionId; + } + + private String getBusbarSectionId(Terminal terminal) { + BusbarSectionFinderTraverser connectedBusbarSectionFinder = new BusbarSectionFinderTraverser(terminal.isConnected()); + terminal.traverse(connectedBusbarSectionFinder, TraversalType.BREADTH_FIRST); + return connectedBusbarSectionFinder.getFirstTraversedBbsId(); + } + private int getPosition(AttributeModification connectionPosition, AttributeModification busOrBusbarSectionId, - Network network, - AttributeModification voltageLevelId) { - return getPosition( - connectionPosition == null ? null : connectionPosition.getValue(), - busOrBusbarSectionId == null ? null : busOrBusbarSectionId.getValue(), - network, - getVoltageLevel(network, voltageLevelId == null ? null : voltageLevelId.getValue()) - ); + AttributeModification voltageLevelId, + AttributeModification equipmentId, + FeederSide feederSide, + Network network) { + String equipmentValue = equipmentId.getValue(); + Terminal selectedTerminal = null; + switch (feederSide) { + case INJECTION_SINGLE_SIDE -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Injection injection ? injection.getTerminal() : null; + case BRANCH_SIDE_ONE -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Branch branch ? branch.getTerminal1() : null; + case BRANCH_SIDE_TWO -> selectedTerminal = network.getIdentifiable(equipmentValue) instanceof Branch branch ? branch.getTerminal2() : null; + } + String voltageLevel = (voltageLevelId != null && voltageLevelId.getValue() != null) + ? voltageLevelId.getValue() + : Optional.ofNullable(selectedTerminal).map(terminal -> terminal.getVoltageLevel().getId()).orElse(null); + String busOrBusbarSection = (busOrBusbarSectionId != null && busOrBusbarSectionId.getValue() != null) + ? busOrBusbarSectionId.getValue() + : Optional.ofNullable(selectedTerminal).map(this::getBusOrBusbarSection).orElse(null); + Integer connectionPositionValue = (connectionPosition != null) ? connectionPosition.getValue() : null; + return getPosition(connectionPositionValue, busOrBusbarSection, network, getVoltageLevel(network, voltageLevel)); } private void modifyConnection(AttributeModification terminalConnected, Identifiable equipment, Terminal terminal, List reports) { @@ -1160,18 +1184,27 @@ private void modifyExistingActivePowerControl(ActivePowerControl activePowerC private void createNewActivePowerControl(ActivePowerControlAdder adder, AttributeModification participateInfo, AttributeModification droopInfo, - List reports) { - boolean participate = participateInfo != null ? participateInfo.getValue() : false; - adder.withParticipate(participate); - if (participateInfo != null && reports != null) { - reports.add(buildModificationReport(null, participate, "Participate")); + List reports, + NetworkModificationException.Type exceptionType, + String errorMessage) { + Boolean participate = Optional.ofNullable(participateInfo).map(AttributeModification::getValue).orElse(null); + Float droop = Optional.ofNullable(droopInfo).map(AttributeModification::getValue).orElse(null); + checkActivePowerControl(participate, droop, exceptionType, errorMessage); + if (participate != null && droop != null) { + adder.withParticipate(participate) + .withDroop(droop) + .add(); + if (reports != null) { + reports.add(buildModificationReport(null, participate, "Participate")); + reports.add(buildModificationReport(Double.NaN, droop, "Droop")); + } } - double droop = droopInfo != null ? droopInfo.getValue() : Double.NaN; - adder.withDroop(droop); - if (droopInfo != null && reports != null) { - reports.add(buildModificationReport(Double.NaN, droop, "Droop")); + } + + public void checkActivePowerControl(Boolean participate, Float droop, NetworkModificationException.Type exceptionType, String errorMessage) { + if (Boolean.TRUE.equals(participate) && droop == null) { + throw new NetworkModificationException(exceptionType, String.format("%s Active power regulation on : missing required droop value", errorMessage)); } - adder.add(); } public ReportNode modifyActivePowerControlAttributes(ActivePowerControl activePowerControl, @@ -1179,19 +1212,21 @@ public ReportNode modifyActivePowerControlAttributes(ActivePowerControl activ AttributeModification participateInfo, AttributeModification droopInfo, ReportNode subReportNode, - ReportNode subReporterSetpoints) { + ReportNode subReporterSetpoints, + NetworkModificationException.Type exceptionType, + String errorMessage) { List reports = new ArrayList<>(); if (activePowerControl != null) { modifyExistingActivePowerControl(activePowerControl, participateInfo, droopInfo, reports); } else { - createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports); + createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports, exceptionType, errorMessage); } if (subReportNode != null) { ReportNode subReportNodeSetpoints2 = subReporterSetpoints; if (subReporterSetpoints == null && !reports.isEmpty()) { subReportNodeSetpoints2 = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add(); } - reportModifications(subReportNodeSetpoints2, reports, "activePowerRegulationModified", "Active power regulation"); + reportModifications(subReportNodeSetpoints2, reports, "activePowerControlModified", "Active power control"); return subReportNodeSetpoints2; } return null; @@ -1310,10 +1345,12 @@ public void checkReactivePowerLimitsAndSetPointsCreation(StaticVarCompensatorCre if (Objects.isNull(creationInfos.getMaxSusceptance()) && Objects.isNull(creationInfos.getMaxQAtNominalV())) { throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "maximum susceptance is not set"); } - if (Objects.nonNull(creationInfos.getMaxSusceptance()) && Objects.nonNull(creationInfos.getMinSusceptance()) && creationInfos.getMaxSusceptance() < creationInfos.getMinSusceptance() || - Objects.nonNull(creationInfos.getMaxQAtNominalV()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && creationInfos.getMaxQAtNominalV() < creationInfos.getMinQAtNominalV()) { + if (Objects.nonNull(creationInfos.getMaxSusceptance()) && Objects.nonNull(creationInfos.getMinSusceptance()) && creationInfos.getMaxSusceptance() < creationInfos.getMinSusceptance()) { throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "maximum susceptance is expected to be greater than or equal to minimum susceptance"); } + if (Objects.nonNull(creationInfos.getMaxQAtNominalV()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && creationInfos.getMaxQAtNominalV() < creationInfos.getMinQAtNominalV()) { + throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "maximum Q at nominal voltage is expected to be greater than or equal to minimum Q"); + } // check set points if (Objects.requireNonNull(creationInfos.getRegulationMode()) == StaticVarCompensator.RegulationMode.VOLTAGE && creationInfos.getVoltageSetpoint() == null) { @@ -1330,11 +1367,14 @@ public void checkStandbyAutomatonCreation(StaticVarCompensatorCreationInfos crea throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, "Standby is only supported in Voltage Regulation mode"); } if (Objects.nonNull(creationInfos.getB0()) && Objects.nonNull(creationInfos.getMinSusceptance()) && Objects.nonNull(creationInfos.getMaxSusceptance()) && - (creationInfos.getB0() < creationInfos.getMinSusceptance() || creationInfos.getB0() > creationInfos.getMaxSusceptance()) - || Objects.nonNull(creationInfos.getQ0()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && Objects.nonNull(creationInfos.getMaxQAtNominalV()) && + (creationInfos.getB0() < creationInfos.getMinSusceptance() || creationInfos.getB0() > creationInfos.getMaxSusceptance())) { + throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, + "b0 must be within the range of minimum susceptance and maximum susceptance"); + } + if (Objects.nonNull(creationInfos.getQ0()) && Objects.nonNull(creationInfos.getMinQAtNominalV()) && Objects.nonNull(creationInfos.getMaxQAtNominalV()) && (creationInfos.getQ0() < creationInfos.getMinQAtNominalV() || creationInfos.getQ0() > creationInfos.getMaxQAtNominalV())) { throw makeEquipmentException(creationInfos.getErrorType(), creationInfos.getEquipmentId(), equipmentName, - "b0 must be within the range of minimun susceptance and maximum susceptance"); + "q0 must be within the range of minimum Q and maximum Q"); } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java index bc99bbaa3..3916fd326 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreation.java @@ -13,7 +13,6 @@ import com.powsybl.iidm.network.extensions.StandbyAutomatonAdder; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.StaticVarCompensatorCreationInfos; -import org.gridsuite.modification.server.dto.VoltageRegulationType; import java.util.ArrayList; import java.util.List; @@ -60,16 +59,6 @@ public void check(Network network) throws NetworkModificationException { public void apply(Network network, ReportNode subReportNode) { // create the static var compensator in the network VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, modificationInfos.getVoltageLevelId()); - if (Objects.isNull(modificationInfos.getMaxSusceptance()) && Objects.nonNull(modificationInfos.getMaxQAtNominalV())) { - modificationInfos.setMaxSusceptance((modificationInfos.getMaxQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2)); - } - if (Objects.isNull(modificationInfos.getMinSusceptance()) && Objects.nonNull(modificationInfos.getMinQAtNominalV())) { - modificationInfos.setMinSusceptance((modificationInfos.getMinQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2)); - } - if (Boolean.TRUE.equals(modificationInfos.isStandbyAutomatonOn()) && Objects.isNull(modificationInfos.getB0()) - && Objects.nonNull(modificationInfos.getQ0())) { - modificationInfos.setB0((modificationInfos.getQ0()) / Math.pow(voltageLevel.getNominalV(), 2)); - } if (voltageLevel.getTopologyKind() == TopologyKind.NODE_BREAKER) { createStaticVarCompensatorInNodeBreaker(voltageLevel, modificationInfos, network, subReportNode); } else { @@ -99,12 +88,15 @@ private StaticVarCompensatorAdder createStaticVarCompensatorAdderInNodeBreaker(V staticVarCompensatorCreationInfos.getRegulatingTerminalId(), staticVarCompensatorCreationInfos.getRegulatingTerminalType(), staticVarCompensatorCreationInfos.getRegulatingTerminalVlId()); - + double bMax = Objects.isNull(staticVarCompensatorCreationInfos.getMaxSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMaxQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMaxQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMaxSusceptance(); + double bMin = Objects.isNull(staticVarCompensatorCreationInfos.getMinSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMinQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMinQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMinSusceptance(); StaticVarCompensatorAdder staticVarCompensatorAdder = voltageLevel.newStaticVarCompensator() .setId(staticVarCompensatorCreationInfos.getEquipmentId()) .setName(staticVarCompensatorCreationInfos.getEquipmentName()) - .setBmax(nanIfNull(staticVarCompensatorCreationInfos.getMaxSusceptance())) - .setBmin(nanIfNull(staticVarCompensatorCreationInfos.getMinSusceptance())) + .setBmax(bMax) + .setBmin(bMin) .setVoltageSetpoint(nanIfNull(staticVarCompensatorCreationInfos.getVoltageSetpoint())) .setReactivePowerSetpoint(nanIfNull(staticVarCompensatorCreationInfos.getReactivePowerSetpoint())) .setRegulationMode(staticVarCompensatorCreationInfos.getRegulationMode()); @@ -125,18 +117,20 @@ private void addExtensionsToStaticVarCompensator(StaticVarCompensatorCreationInf } reportInjectionCreationConnectivity(staticVarCompensatorCreationInfos, subReportNode); - createStaticVarCompensatorVoltageRegulation(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); - reportStaticVarCompensatorStandbyAutomaton(staticVarCompensatorCreationInfos, staticVarCompensator, subReportNode); + reportStaticVarCompensatorLimitsAndSetpoints(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); + reportStaticVarCompensatorStandbyAutomaton(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); } private void reportStaticVarCompensatorStandbyAutomaton(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, - StaticVarCompensator staticVarCompensator, ReportNode subReportNode) { + StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { if (Boolean.TRUE.equals(staticVarCompensatorCreationInfos.isStandbyAutomatonOn())) { List standbyAutomatonReports = new ArrayList<>(); + double b0 = Objects.isNull(staticVarCompensatorCreationInfos.getB0()) && Objects.nonNull(staticVarCompensatorCreationInfos.getQ0()) ? + (staticVarCompensatorCreationInfos.getQ0()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getB0(); try { staticVarCompensator.newExtension(StandbyAutomatonAdder.class) .withStandbyStatus(staticVarCompensatorCreationInfos.isStandby()) - .withB0(staticVarCompensatorCreationInfos.getB0()) + .withB0(b0) .withLowVoltageSetpoint(staticVarCompensatorCreationInfos.getLowVoltageSetpoint()) .withHighVoltageSetpoint(staticVarCompensatorCreationInfos.getHighVoltageSetpoint()) .withLowVoltageThreshold(staticVarCompensatorCreationInfos.getLowVoltageThreshold()) @@ -145,9 +139,16 @@ private void reportStaticVarCompensatorStandbyAutomaton(StaticVarCompensatorCrea standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( staticVarCompensatorCreationInfos.isStandby(), "Standby")); - standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( - staticVarCompensatorCreationInfos.getB0(), - "Fixed part of susceptance")); + if (Objects.nonNull(staticVarCompensatorCreationInfos.getB0())) { + standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( + staticVarCompensatorCreationInfos.getB0(), + "Fixed part of susceptance")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getQ0())) { + standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( + staticVarCompensatorCreationInfos.getQ0(), + "Fixed part of Q at nominal voltage")); + } standbyAutomatonReports.add(ModificationUtils.getInstance().buildCreationReport( staticVarCompensatorCreationInfos.getLowVoltageSetpoint(), "Low voltage set point")); @@ -163,12 +164,10 @@ private void reportStaticVarCompensatorStandbyAutomaton(StaticVarCompensatorCrea } catch (PowsyblException e) { standbyAutomatonReports.add(ReportNode.newRootReportNode() .withMessageTemplate("StandbyAutomatonExtensionAddError", - "Cannot add standby automaton extension on static var compensator with id=${id} : ${message}") - .withUntypedValue("id", staticVarCompensatorCreationInfos.getEquipmentId()) + "Cannot add standby automaton extension on ${message}") .withUntypedValue("message", e.getMessage()) .withSeverity(TypedValue.ERROR_SEVERITY) .build()); - } ModificationUtils.getInstance().reportModifications(subReportNode, standbyAutomatonReports, "StandbyAutomatonCreated", "Standby automaton"); @@ -179,14 +178,18 @@ private void createStaticVarCompensatorInBusBreaker(VoltageLevel voltageLevel, S ReportNode subReportNode) { Bus bus = ModificationUtils.getInstance().getBusBreakerBus(voltageLevel, staticVarCompensatorCreationInfos.getBusOrBusbarSectionId()); + double bMax = Objects.isNull(staticVarCompensatorCreationInfos.getMaxSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMaxQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMaxQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMaxSusceptance(); + double bMin = Objects.isNull(staticVarCompensatorCreationInfos.getMinSusceptance()) && Objects.nonNull(staticVarCompensatorCreationInfos.getMinQAtNominalV()) ? + (staticVarCompensatorCreationInfos.getMinQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2) : staticVarCompensatorCreationInfos.getMinSusceptance(); /* creating the static var compensator */ StaticVarCompensator staticVarCompensator = voltageLevel.newStaticVarCompensator() .setId(staticVarCompensatorCreationInfos.getEquipmentId()) .setName(staticVarCompensatorCreationInfos.getEquipmentName()) .setBus(bus.getId()) .setConnectableBus(bus.getId()) - .setBmax(staticVarCompensatorCreationInfos.getMaxSusceptance()) - .setBmin(staticVarCompensatorCreationInfos.getMinSusceptance()) + .setBmax(bMax) + .setBmin(bMin) .setVoltageSetpoint(staticVarCompensatorCreationInfos.getVoltageSetpoint()) .setReactivePowerSetpoint(staticVarCompensatorCreationInfos.getReactivePowerSetpoint()) .setRegulationMode(staticVarCompensatorCreationInfos.getRegulationMode()) @@ -195,13 +198,33 @@ private void createStaticVarCompensatorInBusBreaker(VoltageLevel voltageLevel, S addExtensionsToStaticVarCompensator(staticVarCompensatorCreationInfos, staticVarCompensator, voltageLevel, subReportNode); } - private void createStaticVarCompensatorVoltageRegulation(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, - StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { + private void reportStaticVarCompensatorLimitsAndSetpoints(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, + StaticVarCompensator staticVarCompensator, VoltageLevel voltageLevel, ReportNode subReportNode) { List voltageReports = new ArrayList<>(); - voltageReports.add(ModificationUtils.getInstance() - .createEnabledDisabledReport("VoltageRegulationOn", modificationInfos.getVoltageRegulationType() == VoltageRegulationType.DISTANT && - modificationInfos.getRegulationMode() == StaticVarCompensator.RegulationMode.VOLTAGE)); - voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMinSusceptance())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinSusceptance(), "Susceptance min")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMaxSusceptance())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxSusceptance(), "Susceptance max")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMinQAtNominalV())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMinQAtNominalV(), "Q min at nominal voltage")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getMaxQAtNominalV())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getMaxQAtNominalV(), "Q max at nominal voltage")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getRegulationMode())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getRegulationMode(), "regulation mode")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getVoltageSetpoint())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageSetpoint(), "Voltage set point")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getReactivePowerSetpoint())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getReactivePowerSetpoint(), "Reactive power set point")); + } + if (Objects.nonNull(staticVarCompensatorCreationInfos.getVoltageRegulationType())) { + voltageReports.add(ModificationUtils.getInstance().buildCreationReport(staticVarCompensatorCreationInfos.getVoltageRegulationType(), "Voltage Regulation type")); + } if (staticVarCompensatorCreationInfos.getRegulatingTerminalVlId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalId() != null && staticVarCompensatorCreationInfos.getRegulatingTerminalType() != null) { Terminal terminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(), @@ -212,7 +235,7 @@ private void createStaticVarCompensatorVoltageRegulation(StaticVarCompensatorCre updateCompensatorRegulatingTerminal(staticVarCompensatorCreationInfos, staticVarCompensator, terminal, voltageReports); } } - ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "VoltageRegulationCreated", "Voltage regulation"); + ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "LimitsAndSetpointsCreated", "Limits and Setpoints"); } private void updateCompensatorRegulatingTerminal(StaticVarCompensatorCreationInfos staticVarCompensatorCreationInfos, StaticVarCompensator staticVarCompensator, diff --git a/src/main/java/org/gridsuite/modification/server/repositories/ModificationRepository.java b/src/main/java/org/gridsuite/modification/server/repositories/ModificationRepository.java index 2ccbe0a55..1568bd632 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/ModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/ModificationRepository.java @@ -9,6 +9,7 @@ import org.gridsuite.modification.server.entities.ModificationEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -27,12 +28,21 @@ public interface ModificationRepository extends JpaRepository findAllBaseByGroupId(UUID uuid); + @Query(value = "SELECT new ModificationEntity(m.id, m.type, m.date, m.stashed, m.activated, m.messageType, m.messageValues) FROM ModificationEntity m WHERE m.group.id = ?1 order by m.modificationsOrder desc") + List findAllBaseByGroupIdReverse(UUID uuid); + + @Query(value = "SELECT m FROM ModificationEntity m WHERE m.group.id = ?1 AND m.stashed = ?2 order by m.modificationsOrder") + List findAllByGroupId(@Param("groupId") UUID groupId, @Param("stashed") Boolean stashed); + @Query(value = "SELECT new ModificationEntity(m.id, m.type) FROM ModificationEntity m WHERE m.id IN (?1)") List findMetadataIn(List uuids); @Query(value = "SELECT m FROM ModificationEntity m WHERE m.id IN (?1) ORDER BY m.modificationsOrder") List findAllByIdIn(List uuids); + @Query(value = "SELECT m FROM ModificationEntity m WHERE m.id IN (?1) ORDER BY m.modificationsOrder desc") + List findAllByIdInReverse(List uuids); + @Query(value = "SELECT cast(modifications_id AS VARCHAR) FROM tabular_modification_modifications WHERE tabular_modification_entity_id = :uuid ORDER BY modifications_order", nativeQuery = true) List findSubModificationIdsByTabularModificationIdOrderByModificationsOrder(UUID uuid); diff --git a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java index 8c156b2cb..1b56810e7 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java @@ -82,16 +82,16 @@ public UUID createNetworkCompositeModification(@NonNull List modificationU } private void saveModificationsNonTransactional(UUID groupUuid, List modifications) { + int order = modificationRepository.countByGroupIdAndStashed(groupUuid, false); var modificationGroupEntity = this.modificationGroupRepository .findById(groupUuid) .orElseGet(() -> modificationGroupRepository.save(new ModificationGroupEntity(groupUuid))); - modifications.forEach(m -> { + for (ModificationEntity m : modifications) { modificationGroupEntity.addModification(m); - // We need here to call the save() method on the modification entity cause the ids of the ModificationEntity's are used in further treatments in the same transaction. - // As we generate the id in Java with @GeneratedValue(strategy = GenerationType.AUTO), saving the entity in the JPA world is enough to generate the id (no need to flush it). - // Without the saving, the id generation would be done only at the flush() and wouldn't be available for the further treatments. - modificationRepository.save(m); - }); + m.setModificationsOrder(order); + order++; + } + modificationRepository.saveAll(modifications); } @Transactional @@ -99,8 +99,10 @@ private void saveModificationsNonTransactional(UUID groupUuid, List moveModifications(UUID destinationGroupUuid, UUID originGroupUuid, List modificationsToMoveUUID, UUID referenceModificationUuid) { // read origin group and modifications ModificationGroupEntity originModificationGroupEntity = getModificationGroup(originGroupUuid); - List originModificationEntities = originModificationGroupEntity.getModifications(); - + List originModificationEntities = originModificationGroupEntity.getModifications() + .stream() + .filter(modificationEntity -> !modificationEntity.getStashed()) + .collect(Collectors.toList()); // To remove null entities when @orderColumn is not a contiguous sequence starting from 0 (to be fixed?) // (there are several places in this file where we filter non-null modification entities) originModificationEntities.removeIf(Objects::isNull); @@ -139,6 +141,9 @@ private void insertModifications(List modificationsList, Lis .findFirst() .orElseThrow(() -> new NetworkModificationException(MOVE_MODIFICATION_ERROR)); modificationsList.addAll(insertionIndex, modificationsToAdd); + for (int order = 0; order < modificationsList.size(); order++) { + modificationsList.get(order).setModificationsOrder(order); + } } private List removeModifications(List modificationsList, List orderedIdsToRemove) { @@ -207,17 +212,19 @@ public List getModifications(UUID groupUuid, boolean onlyMeta } public List getModificationsMetadata(UUID groupUuid, boolean onlyStashed) { - Stream modificationEntityStream = modificationRepository - .findAllBaseByGroupId(getModificationGroup(groupUuid).getId()) - .stream(); if (onlyStashed) { - return modificationEntityStream.filter(m -> m.getStashed()) - .map(this::getModificationInfos) - .collect(Collectors.toList()); + return modificationRepository + .findAllBaseByGroupIdReverse(getModificationGroup(groupUuid).getId()) + .stream() + .filter(ModificationEntity::getStashed) + .map(this::getModificationInfos) + .collect(Collectors.toList()); } else { - return modificationEntityStream - .map(this::getModificationInfos) - .collect(Collectors.toList()); + return modificationRepository + .findAllBaseByGroupId(getModificationGroup(groupUuid).getId()) + .stream() + .map(this::getModificationInfos) + .collect(Collectors.toList()); } } @@ -408,25 +415,48 @@ public List getActiveModificationsInfos(@NonNull UUID groupUu } @Transactional - public void stashNetworkModifications(@NonNull List modificationUuids) { + public void stashNetworkModifications(@NonNull List modificationUuids, int stashedModificationCount) { + int stashModificationOrder = -stashedModificationCount - 1; + List modificationEntities = new ArrayList<>(); for (UUID modificationUuid : modificationUuids) { ModificationEntity modificationEntity = this.modificationRepository .findById(modificationUuid) .orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid))); modificationEntity.setStashed(true); - this.modificationRepository.save(modificationEntity); + modificationEntity.setModificationsOrder(stashModificationOrder); + modificationEntities.add(modificationEntity); + stashModificationOrder--; } + this.modificationRepository.saveAll(modificationEntities); } @Transactional - public void restoreNetworkModifications(@NonNull List modificationUuids) { - for (UUID modificationUuid : modificationUuids) { - ModificationEntity modificationEntity = this.modificationRepository - .findById(modificationUuid) - .orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid))); - modificationEntity.setStashed(false); - this.modificationRepository.save(modificationEntity); + public void reorderNetworkModifications(UUID groupId, Boolean stashed) { + List entities = this.modificationRepository.findAllByGroupId(groupId, stashed); + if (!entities.isEmpty()) { + if (Boolean.TRUE.equals(stashed)) { + IntStream.range(1, entities.size() + 1) + .forEach(i -> entities.get(i - 1).setModificationsOrder(-i)); + } else { + IntStream.range(0, entities.size()) + .forEach(i -> entities.get(i).setModificationsOrder(i)); + } + } + this.modificationRepository.saveAll(entities); + } + + @Transactional + public void restoreNetworkModifications(@NonNull List modificationUuids, int unstashedSize) { + int modificationOrder = unstashedSize; + List modifications = modificationRepository.findAllByIdInReverse(modificationUuids); + if (modifications.size() != modificationUuids.size()) { + throw new NetworkModificationException(MODIFICATION_NOT_FOUND); + } + for (ModificationEntity modification : modifications) { + modification.setStashed(false); + modification.setModificationsOrder(modificationOrder++); } + this.modificationRepository.saveAll(modifications); } @Transactional diff --git a/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java b/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java index 58f2b37c8..6ca1b03e2 100644 --- a/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java @@ -118,13 +118,19 @@ public void updateNetworkModificationActivation(@NonNull List modification } @Transactional - public void stashNetworkModifications(@NonNull List modificationUuids) { - networkModificationRepository.stashNetworkModifications(modificationUuids); + public void stashNetworkModifications(UUID groupUuid, @NonNull List modificationUuids) { + networkModificationRepository.stashNetworkModifications(modificationUuids, networkModificationRepository.getModificationsCount(groupUuid, true)); } @Transactional - public void restoreNetworkModifications(@NonNull List modificationUuids) { - networkModificationRepository.restoreNetworkModifications(modificationUuids); + public void reorderNetworkModifications(UUID groupId, Boolean stashed) { + networkModificationRepository.reorderNetworkModifications(groupId, stashed); + } + + @Transactional + public void restoreNetworkModifications(UUID groupUuid, @NonNull List modificationUuids) { + networkModificationRepository.restoreNetworkModifications(modificationUuids, + networkModificationRepository.getModificationsCount(groupUuid, false)); } // No transactional because we need to save modification in DB also in case of error diff --git a/src/main/resources/db/changelog/changesets/changelog_20241015T130742Z.xml b/src/main/resources/db/changelog/changesets/changelog_20241015T130742Z.xml new file mode 100644 index 000000000..da8d73207 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20241015T130742Z.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 4ef96dc04..32d3e8bde 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -315,3 +315,6 @@ databaseChangeLog: - include: relativeToChangelogFile: true file: changesets/changelog_20240912T130742Z.xml + - include: + relativeToChangelogFile: true + file: changesets/changelog_20241015T130742Z.xml \ No newline at end of file diff --git a/src/test/java/com/powsybl/iidm/modification/topology/HvdcTestNetwork.java b/src/test/java/com/powsybl/iidm/modification/topology/HvdcTestNetwork.java index c9d53df71..9a3746933 100644 --- a/src/test/java/com/powsybl/iidm/modification/topology/HvdcTestNetwork.java +++ b/src/test/java/com/powsybl/iidm/modification/topology/HvdcTestNetwork.java @@ -5,12 +5,13 @@ import java.time.ZonedDateTime; import java.util.Objects; -public final class HvdcTestNetwork { +final class HvdcTestNetwork { private static final String DISCONNECTOR_NAME = "Disconnector"; private static final String BREAKER_NAME = "Breaker"; private HvdcTestNetwork() { + throw new IllegalStateException("Utility class"); } private static Network createBase(NetworkFactory networkFactory) { diff --git a/src/test/java/org/gridsuite/modification/server/ContextConfigurationWithTestChannel.java b/src/test/java/org/gridsuite/modification/server/ContextConfigurationWithTestChannel.java index 81fb6f5fc..6b525b261 100644 --- a/src/test/java/org/gridsuite/modification/server/ContextConfigurationWithTestChannel.java +++ b/src/test/java/org/gridsuite/modification/server/ContextConfigurationWithTestChannel.java @@ -4,7 +4,6 @@ * 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; import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index ee2c5bafa..5f0228702 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -19,10 +19,8 @@ import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; -import lombok.SneakyThrows; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.tuple.Pair; -import org.gridsuite.modification.server.Impacts.TestImpactUtils; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.dto.LoadCreationInfos.LoadCreationInfosBuilder; import org.gridsuite.modification.server.dto.catalog.LineTypeInfos; @@ -31,6 +29,7 @@ import org.gridsuite.modification.server.elasticsearch.TombstonedEquipmentInfosRepository; import org.gridsuite.modification.server.impacts.AbstractBaseImpact; import org.gridsuite.modification.server.impacts.SimpleElementImpact; +import org.gridsuite.modification.server.impacts.TestImpactUtils; import org.gridsuite.modification.server.modifications.ModificationUtils; import org.gridsuite.modification.server.repositories.NetworkModificationRepository; import org.gridsuite.modification.server.service.NetworkModificationService; @@ -39,31 +38,28 @@ import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.NetworkWithTeePoint; import org.gridsuite.modification.server.utils.TestUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import java.util.*; import java.util.stream.Collectors; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.*; import static org.gridsuite.modification.server.ModificationType.EQUIPMENT_ATTRIBUTE_MODIFICATION; import static org.gridsuite.modification.server.NetworkModificationException.Type.*; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; @@ -75,11 +71,10 @@ * @author Franck Lecuyer * @author Slimane Amar */ -@RunWith(SpringRunner.class) @AutoConfigureMockMvc @SpringBootTest @Tag("IntegrationTest") -public class ModificationControllerTest { +class ModificationControllerTest { private static final UUID TEST_NETWORK_ID = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); private static final UUID TEST_NETWORK_ID_2 = UUID.fromString("7928181e-7977-4592-ba19-88027e4254e4"); @@ -90,7 +85,7 @@ public class ModificationControllerTest { private static final UUID TEST_GROUP2_ID = UUID.randomUUID(); private static final UUID TEST_NETWORK_BUS_BREAKER_ID = UUID.fromString("11111111-7977-4592-ba19-88027e4254e4"); private static final UUID TEST_NETWORK_MIXED_TOPOLOGY_ID = UUID.fromString("22222222-7977-4592-ba19-88027e4254e4"); - public static final String VARIANT_NOT_EXISTING_ID = "variant_not_existing"; + private static final String VARIANT_NOT_EXISTING_ID = "variant_not_existing"; private static final UUID TEST_REPORT_ID = UUID.randomUUID(); private static final String URI_NETWORK_MODIF_BASE = "/v1/network-modifications"; @@ -141,8 +136,8 @@ public class ModificationControllerTest { private Network networkWithTeePoint; private Network networkBusBreaker; - @Before - public void setUp() { + @BeforeEach + void setUp() { objectWriter = mapper.writer().withDefaultPrettyPrinter(); network = NetworkCreation.create(TEST_NETWORK_ID, true); when(networkStoreService.getNetwork(eq(TEST_NETWORK_ID), nullable(PreloadingStrategy.class))).then((Answer) invocation -> network); @@ -167,8 +162,8 @@ public void setUp() { equipmentInfosService.deleteAll(); } - @After - public void tearOff() { + @AfterEach + void tearOff() { // clean DB modificationRepository.deleteAll(); equipmentInfosService.deleteAll(); @@ -178,22 +173,21 @@ private boolean existTombstonedEquipmentInfos(String equipmentId, UUID networkUu return tombstonedEquipmentInfosRepository.findAllByNetworkUuidAndVariantId(networkUuid, variantId).stream().anyMatch(t -> t.getId().equals(equipmentId)); } - @SneakyThrows - private void assertApplicationStatusOK(MvcResult mvcResult) { + private void assertApplicationStatusOK(MvcResult mvcResult) throws Exception { Optional networkModificationResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); assertTrue(networkModificationResult.isPresent()); assertNotEquals(NetworkModificationResult.ApplicationStatus.WITH_ERRORS, networkModificationResult.get().getApplicationStatus()); } @Test - public void testModificationException() { + void testModificationException() { assertEquals(new NetworkModificationException(MODIFICATION_ERROR).getMessage(), MODIFICATION_ERROR.name()); assertEquals(new NetworkModificationException(MODIFICATION_ERROR, "Error message").getMessage(), MODIFICATION_ERROR.name() + " : Error message"); assertEquals(new NetworkModificationException(MODIFICATION_ERROR, new IllegalArgumentException("Error message")).getMessage(), MODIFICATION_ERROR.name() + " : Error message"); } @Test - public void testEquipmentIdNonNull() { + void testEquipmentIdNonNull() { String errorMessage = "equipmentId is marked non-null but is null"; LoadCreationInfosBuilder loadCreationBuilder = LoadCreationInfos.builder(); assertEquals(errorMessage, assertThrows(NullPointerException.class, loadCreationBuilder::build).getMessage()); @@ -204,7 +198,7 @@ public void testEquipmentIdNonNull() { } @Test - public void testNetworkNotFound() throws Exception { + void testNetworkNotFound() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF_BAD_NETWORK) .content(objectWriter.writeValueAsString(LoadCreationInfos.builder().equipmentId("id").build())) .contentType(MediaType.APPLICATION_JSON)) @@ -215,7 +209,7 @@ public void testNetworkNotFound() throws Exception { } @Test - public void assertThrowsUpdateModificationNotFound() { + void assertThrowsUpdateModificationNotFound() { UUID modificationUuid = UUID.randomUUID(); ModificationInfos modificationInfos = LoadCreationInfos.builder().equipmentId("id").build(); String errorMessage = assertThrows(NetworkModificationException.class, () -> networkModificationService.updateNetworkModification(modificationUuid, modificationInfos)).getMessage(); @@ -224,7 +218,7 @@ public void assertThrowsUpdateModificationNotFound() { } @Test - public void testModificationGroups() throws Exception { + void testModificationGroups() throws Exception { MvcResult mvcResult; String resultAsString; @@ -243,7 +237,7 @@ public 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( @@ -284,7 +278,7 @@ public void testModificationGroups() throws Exception { } @Test - public void testRestoreNetworkModifications() throws Exception { + void testRestoreNetworkModifications() throws Exception { MvcResult mvcResult; EquipmentAttributeModificationInfos switchStatusModificationInfos = EquipmentAttributeModificationInfos.builder() .equipmentType(IdentifiableType.SWITCH) @@ -297,7 +291,7 @@ public 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()); @@ -312,7 +306,7 @@ public void testRestoreNetworkModifications() throws Exception { } @Test - public void testStashNetworkModifications() throws Exception { + void testStashNetworkModifications() throws Exception { MvcResult mvcResult; EquipmentAttributeModificationInfos switchStatusModificationInfos = EquipmentAttributeModificationInfos.builder() .equipmentType(IdentifiableType.SWITCH) @@ -325,7 +319,7 @@ public 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()); @@ -339,7 +333,7 @@ public void testStashNetworkModifications() throws Exception { } @Test - public void testDisableNetworkModifications() throws Exception { + void testDisableNetworkModifications() throws Exception { MvcResult mvcResult; EquipmentAttributeModificationInfos switchStatusModificationInfos = EquipmentAttributeModificationInfos.builder() .equipmentType(IdentifiableType.SWITCH) @@ -353,7 +347,7 @@ public 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()); @@ -369,7 +363,7 @@ public void testDisableNetworkModifications() throws Exception { } @Test - public void testDeleteModification() throws Exception { + void testDeleteModification() throws Exception { MvcResult mvcResult; EquipmentAttributeModificationInfos switchStatusModificationInfos = EquipmentAttributeModificationInfos.builder() .equipmentType(IdentifiableType.SWITCH) @@ -381,7 +375,7 @@ public 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()); @@ -410,7 +404,7 @@ public void testDeleteModification() throws Exception { //test delete all modifications @Test - public void testDeleteAllModification() throws Exception { + void testDeleteAllModification() throws Exception { List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 3); assertEquals(3, modificationRepository.getModifications(TEST_GROUP_ID, false, true).size()); @@ -421,15 +415,15 @@ public void testDeleteAllModification() throws Exception { } @Test - public void testDeleteModificationMissingParamError() throws Exception { + void testDeleteModificationMissingParamError() throws Exception { mockMvc.perform(delete(URI_NETWORK_MODIF_BASE)) .andExpect(status().isInternalServerError()) - .andExpect(result -> assertTrue(result.getResolvedException() instanceof NetworkModificationException)) + .andExpect(result -> assertInstanceOf(NetworkModificationException.class, result.getResolvedException())) .andExpect(result -> assertEquals("MODIFICATION_DELETION_ERROR : need to specify the group or give a list of UUIDs", result.getResolvedException().getMessage())); } @Test - public void testNetworkModificationsWithErrorOnNetworkFlush() throws Exception { + void testNetworkModificationsWithErrorOnNetworkFlush() throws Exception { String uriString = URI_NETWORK_MODIF_BASE + "?networkUuid=" + TEST_NETWORK_WITH_FLUSH_ERROR_ID + URI_NETWORK_MODIF_PARAMS; GroovyScriptInfos groovyScriptInfos = GroovyScriptInfos.builder() @@ -443,7 +437,7 @@ public void testNetworkModificationsWithErrorOnNetworkFlush() throws Exception { } @Test - public void testMultipleModificationsWithError() throws Exception { + void testMultipleModificationsWithError() throws Exception { GroovyScriptInfos groovyScriptInfos = GroovyScriptInfos.builder() .script("network.getGenerator('idGenerator').targetP=10\nnetwork.getGenerator('idGenerator').targetP=20\n") .build(); @@ -505,7 +499,7 @@ private ModificationInfos createDeletionModification(UUID groupId, IdentifiableT } @Test - public void testCopyModification() throws Exception { + void testCopyModification() throws Exception { // create 3 modifications List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 3); List modificationUuidList = modificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); @@ -595,7 +589,7 @@ public void testCopyModification() throws Exception { } @Test - public void testCopyModificationWithUnexistingId() throws Exception { + void testCopyModificationWithUnexistingId() throws Exception { // create 1 modifications List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 1); List modificationUuidList = modificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); @@ -619,7 +613,7 @@ public void testCopyModificationWithUnexistingId() throws Exception { } @Test - public void createGeneratorWithStartup() throws Exception { + void createGeneratorWithStartup() throws Exception { // create and build generator without startup GeneratorCreationInfos generatorCreationInfos = ModificationCreation.getCreationGenerator("v2", "idGenerator1", "nameGenerator1", "1B", "v2load", "LOAD", "v1"); @@ -675,7 +669,7 @@ public void createGeneratorWithStartup() throws Exception { } @Test - public void testMoveModificationInSameGroup() throws Exception { + void testMoveModificationInSameGroup() throws Exception { // create 2 modifications in a single group List modificationUuidList = createSomeSwitchModifications(TEST_GROUP_ID, 2). stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); @@ -700,7 +694,7 @@ public void testMoveModificationInSameGroup() throws Exception { } @Test - public void testNetworkCompositeModification() throws Exception { + void testNetworkCompositeModification() throws Exception { // Insert a switch modification in the group List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 1); assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); @@ -738,7 +732,7 @@ public void testNetworkCompositeModification() throws Exception { } @Test - public void testMoveModificationBetweenTwoGroups() throws Exception { + void testMoveModificationBetweenTwoGroups() throws Exception { String substationS3 = network.getLoad("v5load").getTerminal().getVoltageLevel().getSubstation().get().getId(); String substationS1 = network.getLoad("v1load").getTerminal().getVoltageLevel().getSubstation().get().getId(); assertEquals("s3", substationS3); @@ -794,7 +788,7 @@ public void testMoveModificationBetweenTwoGroups() throws Exception { } @Test - public void testMoveModificationWithUnexistingId() throws Exception { + void testMoveModificationWithUnexistingId() throws Exception { // create 2 modifications List modificationUuidList = createSomeSwitchModifications(TEST_GROUP_ID, 2). stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); @@ -820,7 +814,7 @@ public void testMoveModificationWithUnexistingId() throws Exception { } @Test - public void testDuplicateModificationGroup() throws Exception { + void testDuplicateModificationGroup() throws Exception { MvcResult mvcResult; VoltageLevelCreationInfos vl1 = ModificationCreation.getCreationVoltageLevel("s1", "vl1Id", "vl1Name"); mockMvc.perform( @@ -862,7 +856,7 @@ public 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); @@ -935,7 +929,7 @@ public void testDuplicateModificationGroup() throws Exception { } @Test - public void replaceTeePointByVoltageLevelOnLineDuplicateModificationGroupTest() throws Exception { + void replaceTeePointByVoltageLevelOnLineDuplicateModificationGroupTest() throws Exception { LinesAttachToSplitLinesInfos linesAttachToSplitLinesInfos = new LinesAttachToSplitLinesInfos("l1", "l2", "l3", "v4", "bbs4", "nl1", "NewLine1", "nl2", "NewLine2"); MvcResult mvcResult = mockMvc.perform(post(URI_NETWORK_WITH_TEE_POINT_MODIF) @@ -956,7 +950,7 @@ public void replaceTeePointByVoltageLevelOnLineDuplicateModificationGroupTest() } @Test - public void testGroupDuplication() throws Exception { + void testGroupDuplication() throws Exception { // create new load in voltage level with node/breaker topology (in voltage level "v2" and busbar section "1B") LoadCreationInfos loadCreationInfos = LoadCreationInfos.builder() .equipmentId("idLoad1") @@ -985,7 +979,7 @@ public void testGroupDuplication() throws Exception { } @Test - public void testTombstonedEquipmentInfos() throws Exception { + void testTombstonedEquipmentInfos() throws Exception { MvcResult mvcResult; assertTrue(equipmentInfosRepository.findAllByNetworkUuidAndVariantId(TEST_NETWORK_ID, NetworkCreation.VARIANT_ID).isEmpty()); @@ -1255,7 +1249,7 @@ private void test3WTDeletionImpacts(String resultAsString, String w3tId, assertFalse(existTombstonedEquipmentInfos(disconnectorId3, TEST_NETWORK_ID, VariantManagerConstants.INITIAL_VARIANT_ID)); } - private void testMultipleDeletionImpacts(String networkModificationResultAsString, List expectedImpacts) throws JsonProcessingException { + private void testMultipleDeletionImpacts(String networkModificationResultAsString, List expectedImpacts) throws Exception { for (AbstractBaseImpact impact : expectedImpacts) { if (impact instanceof SimpleElementImpact simpleImpact) { // Equipment has been removed from network @@ -1285,7 +1279,7 @@ private void testNetworkModificationsCount(UUID groupUuid, int actualSize) throw } @Test - public void shouldGetPosition() { + void shouldGetPosition() { var network = networkStoreService.getNetwork(TEST_NETWORK_ID, null); var network2 = networkStoreService.getNetwork(TEST_NETWORK_MIXED_TOPOLOGY_ID, null); var vl = network.getVoltageLevel("v2"); @@ -1306,7 +1300,7 @@ public void shouldGetPosition() { } @Test - public void testGetPositionAfterAndBefore() { + void testGetPositionAfterAndBefore() { Network testNetwork = new NetworkFactoryImpl().createNetwork("testNetwork", "test"); Substation s1 = testNetwork.newSubstation().setId("s1").setName("s1").setCountry(Country.FR).add(); VoltageLevel v1 = s1.newVoltageLevel().setId("v1").setName("v1").setTopologyKind(TopologyKind.NODE_BREAKER).setNominalV(380.).add(); @@ -1326,7 +1320,7 @@ public void testGetPositionAfterAndBefore() { } @Test - public void testGetLineTypesCatalog() throws Exception { + void testGetLineTypesCatalog() throws Exception { MvcResult mvcResult; String resultAsString; @@ -1336,8 +1330,7 @@ public void testGetLineTypesCatalog() throws Exception { .andExpect(status().isOk()) .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - List emptyLineTypes = mapper.readValue(resultAsString, new TypeReference<>() { - }); + List emptyLineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); assertEquals(0, emptyLineTypes.size()); // Create the catalog with some line types @@ -1352,8 +1345,7 @@ public void testGetLineTypesCatalog() throws Exception { .andExpect(status().isOk()) .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - List lineTypes = mapper.readValue(resultAsString, new TypeReference<>() { - }); + List lineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); assertEquals(8, lineTypes.size()); // Check if catalog is completely updated @@ -1367,8 +1359,7 @@ public void testGetLineTypesCatalog() throws Exception { .andExpect(status().isOk()) .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - List lineTypes2 = mapper.readValue(resultAsString, new TypeReference<>() { - }); + List lineTypes2 = mapper.readValue(resultAsString, new TypeReference<>() { }); assertEquals(2, lineTypes2.size()); mockMvc.perform(delete(URI_LINE_CATALOG)) @@ -1380,13 +1371,12 @@ public void testGetLineTypesCatalog() throws Exception { .andExpect(status().isOk()) .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - emptyLineTypes = mapper.readValue(resultAsString, new TypeReference<>() { - }); + emptyLineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); assertEquals(0, emptyLineTypes.size()); } @Test - public void testCreateVoltageInitModification() throws Exception { + void testCreateVoltageInitModification() throws Exception { // Create the modification VoltageInitModificationInfos modificationsInfos1 = VoltageInitModificationInfos.builder() .stashed(false) @@ -1479,7 +1469,7 @@ public void testCreateVoltageInitModification() throws Exception { } @Test - public void testDeleteStashedNetworkModifications() throws Exception { + void testDeleteStashedNetworkModifications() throws Exception { MvcResult mvcResult; EquipmentAttributeModificationInfos loadModificationInfos = EquipmentAttributeModificationInfos.builder() .equipmentType(IdentifiableType.LOAD) @@ -1508,7 +1498,7 @@ public void testDeleteStashedNetworkModifications() throws Exception { } @Test - public void testGetModificationsCount() throws Exception { + void testGetModificationsCount() throws Exception { MvcResult mvcResult; createSomeSwitchModifications(TEST_GROUP_ID, 3); mvcResult = mockMvc.perform(get("/v1/groups/{groupUuid}/network-modifications-count", TEST_GROUP_ID) @@ -1528,8 +1518,7 @@ public void testGetModificationsCount() throws Exception { } @Test - @SneakyThrows - public void testDuplicate() { + void testDuplicate() throws Exception { // create 1 modification List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 1); List modificationUuidList = modificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); @@ -1573,8 +1562,7 @@ public void testDuplicate() { } @Test - @SneakyThrows - public void testMetadata() { + void testMetadata() throws Exception { // create a single switch attribute modification in a group List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 1); UUID switchModificationId = modificationList.get(0).getUuid(); @@ -1589,8 +1577,7 @@ public void testMetadata() { } @Test - @SneakyThrows - public void testStandaloneDeletionError() { + void testStandaloneDeletionError() throws Exception { // create a single switch attribute modification in a group List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 1); UUID switchModificationId = modificationList.get(0).getUuid(); @@ -1606,7 +1593,7 @@ public void testStandaloneDeletionError() { } @Test - public void testApplyModificationsFromUuids() throws Exception { + void testApplyModificationsFromUuids() throws Exception { // create a modification (opening a closed switch) in the database EquipmentAttributeModificationInfos switchStatusModificationInfos = EquipmentAttributeModificationInfos.builder() .equipmentType(IdentifiableType.SWITCH) diff --git a/src/test/java/org/gridsuite/modification/server/ModificationTypeTest.java b/src/test/java/org/gridsuite/modification/server/ModificationTypeTest.java index 8a3bb005e..5e33935d8 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationTypeTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationTypeTest.java @@ -6,16 +6,16 @@ */ package org.gridsuite.modification.server; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Antoine Bouhours */ -public class ModificationTypeTest { +class ModificationTypeTest { @Test - public void testMaxStrategyNoneVsNone() { + void testMaxStrategyNoneVsNone() { ModificationType noneStrategy1 = ModificationType.LOAD_CREATION; ModificationType noneStrategy2 = ModificationType.LOAD_MODIFICATION; assertEquals(noneStrategy1, noneStrategy1.maxStrategy(noneStrategy2)); @@ -23,7 +23,7 @@ public void testMaxStrategyNoneVsNone() { } @Test - public void testMaxStrategyNoneVsCollection() { + void testMaxStrategyNoneVsCollection() { ModificationType noneStrategy = ModificationType.LOAD_CREATION; ModificationType collectionStrategy = ModificationType.TABULAR_MODIFICATION; assertEquals(collectionStrategy, noneStrategy.maxStrategy(collectionStrategy)); @@ -31,7 +31,7 @@ public void testMaxStrategyNoneVsCollection() { } @Test - public void testMaxStrategyNoneVsAllCollectionsNeededForBusView() { + void testMaxStrategyNoneVsAllCollectionsNeededForBusView() { ModificationType noneStrategy = ModificationType.LOAD_CREATION; ModificationType allCollectionsNeededForBusViewStrategy = ModificationType.VOLTAGE_INIT_MODIFICATION; assertEquals(allCollectionsNeededForBusViewStrategy, noneStrategy.maxStrategy(allCollectionsNeededForBusViewStrategy)); @@ -39,7 +39,7 @@ public void testMaxStrategyNoneVsAllCollectionsNeededForBusView() { } @Test - public void testMaxStrategyCollectionVsCollection() { + void testMaxStrategyCollectionVsCollection() { ModificationType collectionStrategy1 = ModificationType.TABULAR_MODIFICATION; ModificationType collectionStrategy2 = ModificationType.TABULAR_CREATION; assertEquals(collectionStrategy1, collectionStrategy1.maxStrategy(collectionStrategy2)); @@ -47,7 +47,7 @@ public void testMaxStrategyCollectionVsCollection() { } @Test - public void testMaxStrategyCollectionVsAllCollectionsNeededForBusView() { + void testMaxStrategyCollectionVsAllCollectionsNeededForBusView() { ModificationType collectionStrategy = ModificationType.TABULAR_MODIFICATION; ModificationType allCollectionsNeededForBusViewStrategy = ModificationType.VOLTAGE_INIT_MODIFICATION; assertEquals(allCollectionsNeededForBusViewStrategy, collectionStrategy.maxStrategy(allCollectionsNeededForBusViewStrategy)); diff --git a/src/test/java/org/gridsuite/modification/server/Impacts/ElementImpactTest.java b/src/test/java/org/gridsuite/modification/server/impacts/ElementImpactTest.java similarity index 84% rename from src/test/java/org/gridsuite/modification/server/Impacts/ElementImpactTest.java rename to src/test/java/org/gridsuite/modification/server/impacts/ElementImpactTest.java index 553a53a74..28a0200be 100644 --- a/src/test/java/org/gridsuite/modification/server/Impacts/ElementImpactTest.java +++ b/src/test/java/org/gridsuite/modification/server/impacts/ElementImpactTest.java @@ -4,43 +4,33 @@ * 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.Impacts; - -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCollectionElementImpact; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCreationImpactType; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createDeletionImpactType; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createModificationImpactType; -import static org.junit.Assert.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +package org.gridsuite.modification.server.impacts; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.powsybl.iidm.network.IdentifiableType; import org.gridsuite.modification.server.dto.NetworkModificationResult; import org.gridsuite.modification.server.dto.NetworkModificationResult.ApplicationStatus; -import org.gridsuite.modification.server.impacts.AbstractBaseImpact; -import org.gridsuite.modification.server.impacts.CollectionElementImpact; -import org.gridsuite.modification.server.impacts.SimpleElementImpact; import org.gridsuite.modification.server.utils.TestUtils; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.powsybl.iidm.network.IdentifiableType; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; -import lombok.SneakyThrows; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Slimane Amar */ @Tag("UnitTest") -public class ElementImpactTest { - private ObjectMapper mapper = new ObjectMapper(); +class ElementImpactTest { + private final ObjectMapper mapper = new ObjectMapper(); @Test - public void testElementImpact() throws IOException { + void testElementImpact() throws Exception { SimpleElementImpact creationImpact = createCreationImpactType(IdentifiableType.LINE, "lineId", new TreeSet<>(List.of("s1", "s2"))); SimpleElementImpact modificationImpact = createModificationImpactType(IdentifiableType.LOAD, "loadId", new TreeSet<>(List.of("s3"))); SimpleElementImpact deletionImpact = createDeletionImpactType(IdentifiableType.GENERATOR, "generatorId", new TreeSet<>(List.of("s4"))); @@ -79,9 +69,7 @@ public void testElementImpact() throws IOException { } @Test - @SneakyThrows - public void testCollectionElementImpact() { - + void testCollectionElementImpact() throws Exception { CollectionElementImpact linesCollectionImpact = createCollectionElementImpact(IdentifiableType.LINE); CollectionElementImpact loadsCollectionImpact = createCollectionElementImpact(IdentifiableType.LOAD); CollectionElementImpact generatorsCollectionImpact = createCollectionElementImpact(IdentifiableType.GENERATOR); diff --git a/src/test/java/org/gridsuite/modification/server/Impacts/TestImpactUtils.java b/src/test/java/org/gridsuite/modification/server/impacts/TestImpactUtils.java similarity index 90% rename from src/test/java/org/gridsuite/modification/server/Impacts/TestImpactUtils.java rename to src/test/java/org/gridsuite/modification/server/impacts/TestImpactUtils.java index 25a14d3b7..28ee14aa2 100644 --- a/src/test/java/org/gridsuite/modification/server/Impacts/TestImpactUtils.java +++ b/src/test/java/org/gridsuite/modification/server/impacts/TestImpactUtils.java @@ -4,7 +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.Impacts; +package org.gridsuite.modification.server.impacts; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -13,26 +13,24 @@ import org.apache.commons.lang3.tuple.Pair; import org.gridsuite.modification.server.dto.NetworkModificationResult; import org.gridsuite.modification.server.dto.NetworkModificationResult.ApplicationStatus; -import org.gridsuite.modification.server.impacts.AbstractBaseImpact; -import org.gridsuite.modification.server.impacts.CollectionElementImpact; -import org.gridsuite.modification.server.impacts.SimpleElementImpact; import org.gridsuite.modification.server.impacts.SimpleElementImpact.SimpleImpactType; import java.util.*; import java.util.stream.Collectors; -import static org.gridsuite.modification.server.utils.assertions.Assertions.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Slimane Amar */ public final class TestImpactUtils { private TestImpactUtils() { + throw new IllegalCallerException("Utility class"); } - public static void testEmptyImpacts(ObjectMapper mapper, String resultAsString) throws JsonProcessingException { + public static void testEmptyImpacts(ObjectMapper mapper, String resultAsString) throws Exception { Optional networkModificationResult = mapper.readValue(resultAsString, new TypeReference<>() { }); assertTrue(networkModificationResult.isPresent()); testEmptyImpacts(networkModificationResult.get()); @@ -59,7 +57,7 @@ private static void testEmptyImpacts(ApplicationStatus globalApplicationStatusEx assertThat(networkModificationResult).recursivelyEquals(resultExpected); } - public static void testElementImpacts(ObjectMapper mapper, String resultAsString, int nbImpacts, Set elementTypes, Set substationIds) throws JsonProcessingException { + public static void testElementImpacts(ObjectMapper mapper, String resultAsString, int nbImpacts, Set elementTypes, Set substationIds) throws Exception { Optional networkModificationResult = mapper.readValue(resultAsString, new TypeReference<>() { }); assertTrue(networkModificationResult.isPresent()); @@ -69,7 +67,7 @@ public static void testElementImpacts(ObjectMapper mapper, String resultAsString assertThat(networkModificationResult.get().getNetworkImpacts()).containsAll(elementTypes.stream().map(TestImpactUtils::createCollectionElementImpact).toList()); } - public static void testElementImpacts(ObjectMapper mapper, String resultAsString, List elementImpactsExpected) throws JsonProcessingException { + public static void testElementImpacts(ObjectMapper mapper, String resultAsString, List elementImpactsExpected) throws Exception { Optional networkModificationResult = mapper.readValue(resultAsString, new TypeReference<>() { }); assertTrue(networkModificationResult.isPresent()); NetworkModificationResult resultExpected = NetworkModificationResult.builder() @@ -80,15 +78,11 @@ public static void testElementImpacts(ObjectMapper mapper, String resultAsString assertThat(networkModificationResult.get()).recursivelyEquals(resultExpected); } - public static void testElementCreationImpact(ObjectMapper mapper, String resultAsString, IdentifiableType elementType, String elementId, Set substationIds) throws JsonProcessingException { - testElementImpact(SimpleImpactType.CREATION, mapper, resultAsString, elementType, elementId, substationIds); + public static void testElementModificationImpact(ObjectMapper mapper, String resultAsString, Set substationIds) throws Exception { + testElementImpact(mapper, resultAsString, substationIds); } - public static void testElementModificationImpact(ObjectMapper mapper, String resultAsString, IdentifiableType elementType, String elementId, Set substationIds) throws JsonProcessingException { - testElementImpact(SimpleImpactType.MODIFICATION, mapper, resultAsString, elementType, elementId, substationIds); - } - - public static void testElementImpact(SimpleImpactType type, ObjectMapper mapper, String resultAsString, IdentifiableType elementType, String elementId, Set substationIds) throws JsonProcessingException { + 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() @@ -128,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 JsonProcessingException { + 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/AbstractInjectionModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/AbstractInjectionModificationTest.java index 638d320f1..d1da787ec 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/AbstractInjectionModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/AbstractInjectionModificationTest.java @@ -4,11 +4,12 @@ * 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 com.powsybl.iidm.network.Injection; -import org.gridsuite.modification.server.dto.*; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.InjectionModificationInfos; +import org.gridsuite.modification.server.dto.OperationType; import org.junit.jupiter.api.Tag; import org.springframework.http.MediaType; @@ -19,14 +20,13 @@ /** * @author David Braquart */ - @Tag("IntegrationTest") -public abstract class AbstractInjectionModificationTest extends AbstractNetworkModificationTest { - void assertChangeConnectionState(Injection existingEquipment, boolean expectedState) throws Exception { +abstract class AbstractInjectionModificationTest extends AbstractNetworkModificationTest { + protected void assertChangeConnectionState(Injection existingEquipment, boolean expectedState) throws Exception { assertChangeConnectionState(existingEquipment, (InjectionModificationInfos) buildModification(), expectedState); } - void assertChangeConnectionState(Injection existingEquipment, InjectionModificationInfos modificationInfos, boolean expectedState) throws Exception { + protected void assertChangeConnectionState(Injection existingEquipment, InjectionModificationInfos modificationInfos, boolean expectedState) throws Exception { modificationInfos.setTerminalConnected(new AttributeModification<>(expectedState, OperationType.SET)); if (expectedState) { 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 762887f07..3583232c4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/AbstractNetworkModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/AbstractNetworkModificationTest.java @@ -4,7 +4,6 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; @@ -18,18 +17,17 @@ import com.powsybl.network.store.iidm.impl.NetworkImpl; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.NetworkModificationResult; -import org.gridsuite.modification.server.impacts.AbstractBaseImpact; import org.gridsuite.modification.server.entities.ModificationEntity; +import org.gridsuite.modification.server.impacts.AbstractBaseImpact; import org.gridsuite.modification.server.repositories.NetworkModificationRepository; import org.gridsuite.modification.server.service.ReportService; import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.TestUtils; import org.gridsuite.modification.server.utils.WireMockUtils; import org.gridsuite.modification.server.utils.elasticsearch.DisableElasticsearch; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +36,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -49,21 +46,21 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -/* -Class to extend if you want to test a network modification. -Each modification should have its own class and implements the abstract methods. -It will automatically run the tests present in this class with the implemented methods. -If you want to add a test that can be applied to every modification, add it here. -If you want to add a test specific to a modification, add it in its own class. +/** + * Class to extend if you want to test a network modification.
    + *
  • Each modification should have its own class and implements the abstract methods.
  • + *
  • It will automatically run the tests present in this class with the implemented methods.
  • + *
  • If you want to add a test that can be applied to every modification, add it here.
  • + *
  • If you want to add a test specific to a modification, add it in its own class.
  • + *
*/ -@RunWith(SpringRunner.class) @SpringBootTest @DisableElasticsearch @AutoConfigureMockMvc @@ -101,7 +98,7 @@ public abstract class AbstractNetworkModificationTest { private Network network; - @Before + @BeforeEach public void setUp() { network = createNetwork(TEST_NETWORK_ID); @@ -115,7 +112,7 @@ public void setUp() { wireMockServer.start(); } - @After + @AfterEach public void tearOff() { modificationRepository.deleteAll(); @@ -194,15 +191,12 @@ public void testRead() throws Exception { assertTrue(networkModificationResult.isPresent()); assertNotEquals(NetworkModificationResult.ApplicationStatus.WITH_ERRORS, networkModificationResult.get().getApplicationStatus()); String resultAsString = mvcResult.getResponse().getContentAsString(); - ModificationInfos receivedModification = mapper.readValue(resultAsString, new TypeReference<>() { - }); - + ModificationInfos receivedModification = mapper.readValue(resultAsString, new TypeReference<>() { }); assertThat(receivedModification).recursivelyEquals(modificationToRead); } @Test public void testUpdate() throws Exception { - ModificationInfos modificationToUpdate = buildModification(); UUID modificationUuid = saveModification(modificationToUpdate); @@ -228,7 +222,6 @@ public void testUpdate() throws Exception { @Test public void testDelete() throws Exception { - ModificationInfos modificationToDelete = buildModification(); UUID modificationUuid = saveModification(modificationToDelete); @@ -246,7 +239,6 @@ public void testDelete() throws Exception { @Test public void testCopy() throws Exception { - ModificationInfos modificationToCopy = buildModification(); UUID modificationUuid = saveModification(modificationToCopy); @@ -320,11 +312,13 @@ protected String getNetworkModificationUriWithBadVariant() { protected abstract void assertAfterNetworkModificationDeletion(); - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + @SuppressWarnings("java:S1130") // Exceptions are throws by overrides + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("{}", modificationInfos.getMessageValues()); } - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + @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/BatteryCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/BatteryCreationInBusBreakerTest.java index e6c2f2759..b224e6027 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/BatteryCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/BatteryCreationInBusBreakerTest.java @@ -4,21 +4,19 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.BatteryCreationInfos; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveCreationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Arrays; @@ -28,13 +26,12 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.BUS_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class BatteryCreationInBusBreakerTest extends AbstractNetworkModificationTest { +class BatteryCreationInBusBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -108,7 +105,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithBusbarSectionErrors() throws Exception { + void testCreateWithBusbarSectionErrors() throws Exception { BatteryCreationInfos batteryCreationInfos = (BatteryCreationInfos) buildModification(); batteryCreationInfos.setBusOrBusbarSectionId("notFoundBus"); mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(batteryCreationInfos)).contentType(MediaType.APPLICATION_JSON)) @@ -118,16 +115,14 @@ public void testCreateWithBusbarSectionErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BATTERY_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idBattery2", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BATTERY_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idBattery2Edited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/BatteryCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/BatteryCreationInNodeBreakerTest.java index b6e77b11a..129a35e97 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/BatteryCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/BatteryCreationInNodeBreakerTest.java @@ -4,18 +4,16 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -23,13 +21,12 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class BatteryCreationInNodeBreakerTest extends AbstractNetworkModificationTest { +class BatteryCreationInNodeBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -104,7 +101,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // invalid Battery id BatteryCreationInfos batteryCreationInfos = (BatteryCreationInfos) buildModification(); batteryCreationInfos.setEquipmentId(""); @@ -206,16 +203,14 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BATTERY_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idBattery1", updatedValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BATTERY_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idBattery2Edited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/BatteryModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/BatteryModificationTest.java index 33efb0c29..82921aa9a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/BatteryModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/BatteryModificationTest.java @@ -4,7 +4,6 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; @@ -13,11 +12,10 @@ import com.powsybl.iidm.network.ReactiveCapabilityCurve; import com.powsybl.iidm.network.ReactiveLimitsKind; import com.powsybl.iidm.network.extensions.ActivePowerControl; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.CollectionUtils; @@ -29,11 +27,12 @@ import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class BatteryModificationTest extends AbstractInjectionModificationTest { +class BatteryModificationTest extends AbstractInjectionModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -90,7 +89,7 @@ protected void assertAfterNetworkModificationCreation() { assertEquals(0., modifiedBattery.getMinP()); assertEquals(100., modifiedBattery.getMaxP()); assertEquals(0.1f, modifiedBattery.getExtension(ActivePowerControl.class).getDroop()); - assertEquals(true, modifiedBattery.getExtension(ActivePowerControl.class).isParticipate()); + assertTrue(modifiedBattery.getExtension(ActivePowerControl.class).isParticipate()); assertEquals(ReactiveLimitsKind.CURVE, modifiedBattery.getReactiveLimits().getKind()); Collection points = modifiedBattery.getReactiveLimits(ReactiveCapabilityCurve.class).getPoints(); List batteryPoints = new ArrayList<>(points); @@ -120,7 +119,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testMinMaxReactiveLimitsAttributesModification() throws Exception { + void testMinMaxReactiveLimitsAttributesModification() throws Exception { BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos) buildModification(); //setting ReactiveCapabilityCurve to false with null min and max reactive limits @@ -202,7 +201,7 @@ public void testMinMaxReactiveLimitsAttributesModification() throws Exception { } @Test - public void testDroopUnchanged() throws Exception { + void testDroopUnchanged() throws Exception { BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos) buildModification(); batteryModificationInfos.getDroop().setValue(18f); @@ -228,14 +227,14 @@ public void testDroopUnchanged() throws Exception { } @Test - public void testImpactsAfterActivePowerControlModifications() throws Exception { + void testImpactsAfterActivePowerControlModifications() throws Exception { BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos) buildModification(); String modificationToCreateJson = mapper.writeValueAsString(batteryModificationInfos); mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); Battery battery = getNetwork().getBattery("v3Battery"); assertEquals(0.1f, battery.getExtension(ActivePowerControl.class).getDroop()); - assertEquals(true, battery.getExtension(ActivePowerControl.class).isParticipate()); + assertTrue(battery.getExtension(ActivePowerControl.class).isParticipate()); //modify only droop batteryModificationInfos.setDroop(new AttributeModification<>(0.5f, OperationType.SET)); modificationToCreateJson = mapper.writeValueAsString(batteryModificationInfos); @@ -262,7 +261,7 @@ public void testImpactsAfterActivePowerControlModifications() throws Exception { } @Test - public void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception { + void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception { BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos) buildModification(); Battery battery = getNetwork().getBattery("v3Battery"); battery.setTargetP(80.) @@ -283,7 +282,7 @@ public void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception } @Test - public void testMinQGreaterThanMaxQ() throws Exception { + void testMinQGreaterThanMaxQ() throws Exception { BatteryModificationInfos batteryModificationInfos = (BatteryModificationInfos) buildModification(); Battery battery = getNetwork().getBattery("v3Battery"); battery.newReactiveCapabilityCurve() @@ -328,28 +327,26 @@ public void testMinQGreaterThanMaxQ() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BATTERY_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v3Battery", updatedValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BATTERY_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idBatteryEdited", updatedValues.get("equipmentId")); } @Test - public void testDisconnection() throws Exception { + void testDisconnection() throws Exception { assertChangeConnectionState(getNetwork().getBattery("v3Battery"), false); } @Test - public void testConnection() throws Exception { + void testConnection() throws Exception { assertChangeConnectionState(getNetwork().getBattery("v3Battery"), true); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/CompositeModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/CompositeModificationsTest.java index d58b68582..47779458c 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/CompositeModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/CompositeModificationsTest.java @@ -4,13 +4,11 @@ * 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 com.powsybl.iidm.network.LoadType; import com.powsybl.iidm.network.Network; import com.vladmihalcea.sql.SQLStatementCountValidator; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.CompositeModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; @@ -18,9 +16,9 @@ import org.gridsuite.modification.server.dto.ReportInfos; import org.gridsuite.modification.server.utils.ModificationCreation; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; @@ -29,7 +27,7 @@ import java.util.UUID; import static com.vladmihalcea.sql.SQLStatementCountValidator.assertSelectCount; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -40,13 +38,13 @@ * @author Ghazwa Rehili */ @Tag("IntegrationTest") -public class CompositeModificationsTest extends AbstractNetworkModificationTest { +class CompositeModificationsTest extends AbstractNetworkModificationTest { @MockBean private NetworkModificationApplicator networkModificationApplicator; - @Before - public void specificSetUp() { + @BeforeEach + void specificSetUp() { // Currently we never apply composite modifications (apply mocked) NetworkModificationResult networkModificationResultMock = NetworkModificationResult.builder() .applicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK) @@ -91,19 +89,17 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertNotNull(ModificationType.COMPOSITE_MODIFICATION.name(), modificationInfos.getMessageType()); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertNotNull(ModificationType.COMPOSITE_MODIFICATION.name(), modificationInfos.getMessageType()); } @Test - public void testCheckSqlRequestsCount() throws Exception { + void testCheckSqlRequestsCount() throws Exception { UUID modificationUuid = saveModification(buildModification()); SQLStatementCountValidator.reset(); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/DeleteAttachingLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/DeleteAttachingLineTest.java index 685cf5be5..36d1fe0ea 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/DeleteAttachingLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/DeleteAttachingLineTest.java @@ -8,13 +8,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.DeleteAttachingLineInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkWithTeePoint; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -24,9 +23,7 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_ALREADY_EXISTS; import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -34,7 +31,7 @@ * @author bendaamerahm */ @Tag("IntegrationTest") -public class DeleteAttachingLineTest extends AbstractNetworkModificationTest { +class DeleteAttachingLineTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -80,7 +77,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void createWithInvalidLineIdTest() throws Exception { + void createWithInvalidLineIdTest() throws Exception { // test create with incorrect line id DeleteAttachingLineInfos deleteAttachingLineInfos = DeleteAttachingLineInfos.builder() .stashed(false) @@ -98,7 +95,7 @@ public void createWithInvalidLineIdTest() throws Exception { } @Test - public void createWithNoAttachmentPointTest() throws Exception { + void createWithNoAttachmentPointTest() throws Exception { DeleteAttachingLineInfos deleteAttachingLineInfos = DeleteAttachingLineInfos.builder() .stashed(false) .lineToAttachTo1Id("l1") @@ -115,7 +112,7 @@ public void createWithNoAttachmentPointTest() throws Exception { } @Test - public void createNewLineWithExistingIdTest() throws Exception { + void createNewLineWithExistingIdTest() throws Exception { // try to create an already existing line DeleteAttachingLineInfos deleteAttachingLineInfos = (DeleteAttachingLineInfos) buildModification(); deleteAttachingLineInfos.setReplacingLine1Id("l2"); @@ -127,8 +124,7 @@ public void createNewLineWithExistingIdTest() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("DELETE_ATTACHING_LINE", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("l3", createdValues.get("attachedLineId")); @@ -137,8 +133,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("DELETE_ATTACHING_LINE", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("l3", updatedValues.get("attachedLineId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/DeleteVoltageLevelOnLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/DeleteVoltageLevelOnLineTest.java index abf0e52e5..16aabb9f3 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/DeleteVoltageLevelOnLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/DeleteVoltageLevelOnLineTest.java @@ -8,13 +8,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.DeleteVoltageLevelOnLineInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -24,9 +23,7 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_ALREADY_EXISTS; import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -34,7 +31,7 @@ * @author bendaamerahm */ @Tag("IntegrationTest") -public class DeleteVoltageLevelOnLineTest extends AbstractNetworkModificationTest { +class DeleteVoltageLevelOnLineTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -82,7 +79,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void createWithInvalidLineIdTest() throws Exception { + void createWithInvalidLineIdTest() throws Exception { // test create with incorrect line id DeleteVoltageLevelOnLineInfos deleteVoltageLevelOnLineInfos = DeleteVoltageLevelOnLineInfos.builder() .stashed(false) @@ -99,7 +96,7 @@ public void createWithInvalidLineIdTest() throws Exception { } @Test - public void createNewLineWithExistingIdTest() throws Exception { + void createNewLineWithExistingIdTest() throws Exception { // try to create an already existing line DeleteVoltageLevelOnLineInfos deleteVoltageLevelOnLineInfos = (DeleteVoltageLevelOnLineInfos) buildModification(); deleteVoltageLevelOnLineInfos.setReplacingLine1Id("l2"); @@ -111,8 +108,7 @@ public void createNewLineWithExistingIdTest() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("DELETE_VOLTAGE_LEVEL_ON_LINE", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("l1", createdValues.get("lineToAttachTo1Id")); @@ -120,8 +116,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("DELETE_VOLTAGE_LEVEL_ON_LINE", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line00", updatedValues.get("lineToAttachTo1Id")); 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 d39010881..82d128ed2 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/EquipmentAttributeModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/EquipmentAttributeModificationTest.java @@ -9,13 +9,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.EquipmentAttributeModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -24,21 +23,20 @@ import java.util.Set; import java.util.UUID; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.testElementModificationImpact; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.testEmptyImpacts; import static org.gridsuite.modification.server.NetworkModificationException.Type.*; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.testElementModificationImpact; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.testEmptyImpacts; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class EquipmentAttributeModificationTest extends AbstractNetworkModificationTest { +class EquipmentAttributeModificationTest extends AbstractNetworkModificationTest { @Test - public void testEquipmentAttributeModificationInfos() throws Exception { + void testEquipmentAttributeModificationInfos() throws Exception { MvcResult mvcResult; UUID modificationUuid = UUID.randomUUID(); //We need to limit the precision to avoid database precision storage limit issue (postgres has a precision of 6 digits while h2 can go to 9) @@ -65,18 +63,18 @@ public 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 - public void testSwitch() throws Exception { + void testSwitch() throws Exception { // switches modifications on initial variant switchModifications("", "v1b1", "disc1Variant", "v2b1", "v3b1", Set.of("s1"), Set.of("s2"), 5); @@ -110,27 +108,27 @@ 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); } @Test - public void testWithErrors() throws Exception { + void testWithErrors() throws Exception { // bad equipment attribute name EquipmentAttributeModificationInfos switchStatusModificationInfos = EquipmentAttributeModificationInfos.builder() .stashed(false) @@ -194,8 +192,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_ATTRIBUTE_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("open", createdValues.get("equipmentAttributeName")); @@ -204,8 +201,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_ATTRIBUTE_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("open", createdValues.get("equipmentAttributeName")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/EquipmentDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/EquipmentDeletionTest.java index 9c6ec8e46..ac970492f 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/EquipmentDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/EquipmentDeletionTest.java @@ -4,7 +4,6 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; @@ -14,7 +13,6 @@ import com.powsybl.iidm.modification.topology.RemoveSubstationBuilder; import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.EquipmentDeletionInfos; import org.gridsuite.modification.server.dto.HvdcLccDeletionInfos; @@ -22,8 +20,10 @@ import org.gridsuite.modification.server.dto.NetworkModificationResult; import org.gridsuite.modification.server.entities.equipment.deletion.ShuntCompensatorSelectionEmbeddable; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -34,14 +34,12 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.EQUIPMENT_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class EquipmentDeletionTest extends AbstractNetworkModificationTest { +class EquipmentDeletionTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -77,7 +75,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testOkWhenRemovingIsolatedEquipment() throws Exception { + void testOkWhenRemovingIsolatedEquipment() throws Exception { EquipmentDeletionInfos equipmentDeletionInfos = EquipmentDeletionInfos.builder() .stashed(false) @@ -96,7 +94,7 @@ public void testOkWhenRemovingIsolatedEquipment() throws Exception { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // delete load (fail because the load is not found) EquipmentDeletionInfos equipmentDeletionInfos = (EquipmentDeletionInfos) buildModification(); equipmentDeletionInfos.setEquipmentId("notFoundLoad"); @@ -106,8 +104,7 @@ public void testCreateWithErrors() throws Exception { equipmentDeletionInfos.getErrorType().name(), reportService); } - @SneakyThrows - private void deleteHvdcLineWithShuntCompensator(String shuntNameToBeRemoved, boolean selected, int side, boolean warningCase) { + private void deleteHvdcLineWithShuntCompensator(String shuntNameToBeRemoved, boolean selected, int side, boolean warningCase) throws Exception { final String hvdcLineName = "hvdcLine"; // this line uses LCC converter stations assertNotNull(getNetwork().getHvdcLine(hvdcLineName)); assertEquals(warningCase, getNetwork().getShuntCompensator(shuntNameToBeRemoved) == null); @@ -139,34 +136,20 @@ private void deleteHvdcLineWithShuntCompensator(String shuntNameToBeRemoved, boo assertEquals(selected, getNetwork().getShuntCompensator(shuntNameToBeRemoved) == null); } - @Test - public void testDeleteHvdcWithLCCWithShuntCompensatorSelectedSide1() { - deleteHvdcLineWithShuntCompensator("v2shunt", true, 1, false); - } - - @Test - public void testDeleteHvdcWithLCCWithShuntCompensatorSelectedSide2() { - deleteHvdcLineWithShuntCompensator("v2shunt", true, 2, false); - } - - @Test - public void testDeleteHvdcWithLCCWithShuntCompensatorNotSelectedSide1() { - deleteHvdcLineWithShuntCompensator("v2shunt", false, 1, false); - } - - @Test - public void testDeleteHvdcWithLCCWithShuntCompensatorNotSelectedSide2() { - deleteHvdcLineWithShuntCompensator("v2shunt", false, 2, false); + @CsvSource({"true, 1", "true, 2", "false, 1", "false, 2"}) + @ParameterizedTest(name = ParameterizedTest.ARGUMENTS_WITH_NAMES_PLACEHOLDER) + void testDeleteHvdcWithLCCWithShuntCompensator(final boolean selected, final int side) throws Exception { + deleteHvdcLineWithShuntCompensator("v2shunt", selected, side, false); } @Test - public void testDeleteHvdcWithLCCWithAlreadyDeletedShuntCompensator() { - // we select an unexisting shunt: will produce a warning + void testDeleteHvdcWithLCCWithAlreadyDeletedShuntCompensator() throws Exception { + // we select a nonexistent shunt: will produce a warning deleteHvdcLineWithShuntCompensator("deletedOrMissingShuntId", true, 1, true); } @Test - public void testRemoveUnknownSubstation() { + void testRemoveUnknownSubstation() { Network network = Network.create("empty", "test"); RemoveSubstation removeSubstation = new RemoveSubstationBuilder().withSubstationId("unknownSubstation").build(); PowsyblException e = assertThrows(PowsyblException.class, () -> removeSubstation.apply(network, true, ReportNode.NO_OP)); @@ -174,16 +157,14 @@ public void testRemoveUnknownSubstation() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_DELETION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v1load", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_DELETION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idGenerator", createdValues.get("equipmentId")); 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 0dea377d8..187debc05 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GenerationDispatchTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GenerationDispatchTest.java @@ -4,7 +4,6 @@ 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 com.fasterxml.jackson.core.type.TypeReference; @@ -18,11 +17,10 @@ import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.service.FilterService; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -33,10 +31,7 @@ import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.gridsuite.modification.server.utils.TestUtils.assertLogNthMessage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -44,7 +39,7 @@ * @author Franck Lecuyer */ @Tag("IntegrationTest") -public class GenerationDispatchTest extends AbstractNetworkModificationTest { +class GenerationDispatchTest extends AbstractNetworkModificationTest { private static final String GH1_ID = "GH1"; private static final String GH2_ID = "GH2"; private static final String GH3_ID = "GH3"; @@ -68,21 +63,18 @@ public class GenerationDispatchTest extends AbstractNetworkModificationTest { private static final UUID FILTER_ID_4 = UUID.randomUUID(); private static final UUID FILTER_ID_5 = UUID.randomUUID(); private static final UUID FILTER_ID_6 = UUID.randomUUID(); - public static final String PATH = "/v1/filters/metadata"; - - @Autowired - ApplicationContext context; + private static final String PATH = "/v1/filters/metadata"; - @Before + @BeforeEach public void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); } - private IdentifierListFilterEquipmentAttributes getIdentifiableAttributes(String id) { + private static IdentifierListFilterEquipmentAttributes getIdentifiableAttributes(String id) { return new IdentifierListFilterEquipmentAttributes(id, null); } - private AbstractFilter getFilter(UUID filterID, List identifierListFilterEquipmentAttributes) { + private static AbstractFilter getFilter(UUID filterID, List identifierListFilterEquipmentAttributes) { return IdentifierListFilter.builder().id(filterID).modificationDate(new Date()).equipmentType(EquipmentType.GENERATOR) .filterEquipmentsAttributes(identifierListFilterEquipmentAttributes) .build(); @@ -112,7 +104,7 @@ private void assertLogReportsForDefaultNetwork(double batteryBalanceOnSc2) { } @Test - public void testGenerationDispatch() throws Exception { + void testGenerationDispatch() throws Exception { ModificationInfos modification = buildModification(); // network with 2 synchronous components, no battery, 2 hvdc lines between them and no forcedOutageRate and plannedOutageRate for the generators @@ -128,7 +120,7 @@ public void testGenerationDispatch() throws Exception { } @Test - public void testGenerationDispatchWithBattery() throws Exception { + void testGenerationDispatchWithBattery() throws Exception { ModificationInfos modification = buildModification(); // same than testGenerationDispatch, with 3 Batteries (in 2nd SC) @@ -147,7 +139,7 @@ public void testGenerationDispatchWithBattery() throws Exception { } @Test - public void testGenerationDispatchWithBatteryConnection() throws Exception { + void testGenerationDispatchWithBatteryConnection() throws Exception { ModificationInfos modification = buildModification(); // network with 3 Batteries (in 2nd SC) @@ -168,7 +160,7 @@ public void testGenerationDispatchWithBatteryConnection() throws Exception { } @Test - public void testGenerationDispatchWithMultipleEnergySource() throws Exception { + void testGenerationDispatchWithMultipleEnergySource() throws Exception { ModificationInfos modification = buildModification(); setNetwork(Network.read("testGenerationDispatchWithMultipleEnergySource.xiidm", getClass().getResourceAsStream("/testGenerationDispatchWithMultipleEnergySource.xiidm"))); @@ -188,7 +180,7 @@ public void testGenerationDispatchWithMultipleEnergySource() throws Exception { } @Test - public void testGenerationDispatchWithHigherLossCoefficient() throws Exception { + void testGenerationDispatchWithHigherLossCoefficient() throws Exception { ModificationInfos modification = buildModification(); ((GenerationDispatchInfos) modification).setLossCoefficient(90.); @@ -229,7 +221,7 @@ public void testGenerationDispatchWithHigherLossCoefficient() throws Exception { } @Test - public void testGenerationDispatchWithInternalHvdc() throws Exception { + void testGenerationDispatchWithInternalHvdc() throws Exception { ModificationInfos modification = buildModification(); // network with unique synchronous component, 2 internal hvdc lines and no forcedOutageRate and plannedOutageRate for the generators @@ -262,7 +254,7 @@ public void testGenerationDispatchWithInternalHvdc() throws Exception { } @Test - public void testGenerationDispatchWithMaxPReduction() throws Exception { + void testGenerationDispatchWithMaxPReduction() throws Exception { ModificationInfos modification = buildModification(); ((GenerationDispatchInfos) modification).setDefaultOutageRate(15.); ((GenerationDispatchInfos) modification).setGeneratorsWithoutOutage( @@ -280,7 +272,7 @@ public void testGenerationDispatchWithMaxPReduction() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + "(.+,){2}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); String modificationJson = mapper.writeValueAsString(modification); mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON)) @@ -319,7 +311,7 @@ public void testGenerationDispatchWithMaxPReduction() throws Exception { } @Test - public void testGenerationDispatchGeneratorsWithFixedSupply() throws Exception { + void testGenerationDispatchGeneratorsWithFixedSupply() throws Exception { ModificationInfos modification = buildModification(); ((GenerationDispatchInfos) modification).setDefaultOutageRate(15.); ((GenerationDispatchInfos) modification).setGeneratorsWithoutOutage( @@ -339,14 +331,14 @@ public void testGenerationDispatchGeneratorsWithFixedSupply() throws Exception { UUID stubIdForPmaxReduction = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_1 + "," + FILTER_ID_2 + "," + FILTER_ID_3) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filtersForPmaxReduction)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); List filtersForFixedSupply = List.of(getFilter(FILTER_ID_1, List.of(getIdentifiableAttributes(GTH1_ID), getIdentifiableAttributes(GROUP1_ID), getIdentifiableAttributes(GEN1_NOT_FOUND_ID))), getFilter(FILTER_ID_4, List.of(getIdentifiableAttributes(TEST1_ID), getIdentifiableAttributes(GROUP2_ID)))); UUID stubIdForFixedSupply = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_1 + "," + FILTER_ID_4) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filtersForFixedSupply)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); String modificationJson = mapper.writeValueAsString(modification); mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON)) @@ -391,13 +383,13 @@ public void testGenerationDispatchGeneratorsWithFixedSupply() throws Exception { wireMockUtils.verifyGetRequest(stubIdForFixedSupply, PATH, handleQueryParams(filtersForFixedSupply.stream().map(AbstractFilter::getId).collect(Collectors.toList())), false); } - private List getGeneratorsFiltersInfosWithFilters123() { + private static List getGeneratorsFiltersInfosWithFilters123() { return List.of(GeneratorsFilterInfos.builder().id(FILTER_ID_1).name("filter1").build(), GeneratorsFilterInfos.builder().id(FILTER_ID_2).name("filter2").build(), GeneratorsFilterInfos.builder().id(FILTER_ID_3).name("filter3").build()); } - private List getGeneratorsFrequencyReserveInfosWithFilters456() { + private static List getGeneratorsFrequencyReserveInfosWithFilters456() { return List.of(GeneratorsFrequencyReserveInfos.builder().frequencyReserve(3.) .generatorsFilters(List.of(GeneratorsFilterInfos.builder().id(FILTER_ID_4).name("filter4").build(), GeneratorsFilterInfos.builder().id(FILTER_ID_5).name("filter5").build())).build(), @@ -405,23 +397,23 @@ private List getGeneratorsFrequencyReserveInfos .generatorsFilters(List.of(GeneratorsFilterInfos.builder().id(FILTER_ID_6).name("filter6").build())).build()); } - private List getGeneratorsWithoutOutageFilters123() { + private static List getGeneratorsWithoutOutageFilters123() { return List.of(getFilter(FILTER_ID_1, List.of(getIdentifiableAttributes(GTH2_ID), getIdentifiableAttributes(GROUP1_ID))), getFilter(FILTER_ID_2, List.of(getIdentifiableAttributes(ABC_ID), getIdentifiableAttributes(GH3_ID))), getFilter(FILTER_ID_3, List.of(getIdentifiableAttributes(GEN1_NOT_FOUND_ID), getIdentifiableAttributes(GEN2_NOT_FOUND_ID)))); } - private List getGeneratorsFrequencyReserveFilters45() { + private static List getGeneratorsFrequencyReserveFilters45() { return List.of(getFilter(FILTER_ID_4, List.of(getIdentifiableAttributes(GTH1_ID))), getFilter(FILTER_ID_5, List.of(getIdentifiableAttributes(GTH2_ID), getIdentifiableAttributes(GH3_ID), getIdentifiableAttributes(GEN1_NOT_FOUND_ID)))); } - private List getGeneratorsFrequencyReserveFilter6() { + private static List getGeneratorsFrequencyReserveFilter6() { return List.of(getFilter(FILTER_ID_6, List.of(getIdentifiableAttributes(TEST1_ID)))); } @Test - public void testGenerationDispatchWithFrequencyReserve() throws Exception { + void testGenerationDispatchWithFrequencyReserve() throws Exception { ModificationInfos modification = buildModification(); ((GenerationDispatchInfos) modification).setDefaultOutageRate(15.); ((GenerationDispatchInfos) modification).setGeneratorsWithoutOutage(getGeneratorsFiltersInfosWithFilters123()); @@ -434,16 +426,16 @@ public void testGenerationDispatchWithFrequencyReserve() throws Exception { UUID stubIdForPmaxReduction = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_1 + "," + FILTER_ID_2 + "," + FILTER_ID_3) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(getGeneratorsWithoutOutageFilters123())) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); UUID stubIdForFrequencyReserve1 = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_4 + "," + FILTER_ID_5) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(getGeneratorsFrequencyReserveFilters45())) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); UUID stubIdForFrequencyReserve2 = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_6) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(getGeneratorsFrequencyReserveFilter6())) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); String modificationJson = mapper.writeValueAsString(modification); mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON)) @@ -485,7 +477,7 @@ public void testGenerationDispatchWithFrequencyReserve() throws Exception { } @Test - public void testGenerationDispatchWithSubstationsHierarchy() throws Exception { + void testGenerationDispatchWithSubstationsHierarchy() throws Exception { ModificationInfos modification = buildModification(); ((GenerationDispatchInfos) modification).setLossCoefficient(10.); ((GenerationDispatchInfos) modification).setDefaultOutageRate(20.); @@ -564,19 +556,21 @@ public void testGenerationDispatchWithSubstationsHierarchy() throws Exception { } @Test - public void testGenerationDispatchErrorCheck() { + 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("GENERATION_DISPATCH_ERROR : The loss coefficient must be between 0 and 100", NetworkModificationException.class, () -> generationDispatch1.check(getNetwork())); + 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("GENERATION_DISPATCH_ERROR : The default outage rate must be between 0 and 100", NetworkModificationException.class, () -> generationDispatch2.check(getNetwork())); + assertThrows(NetworkModificationException.class, () -> generationDispatch2.check(network), "GENERATION_DISPATCH_ERROR : The default outage rate must be between 0 and 100"); } @Test - public void testGenerationDispatchWithMaxValueLessThanMinP() throws Exception { + void testGenerationDispatchWithMaxValueLessThanMinP() throws Exception { ModificationInfos modification = GenerationDispatchInfos.builder() .lossCoefficient(20.) .defaultOutageRate(15.) @@ -593,15 +587,15 @@ public void testGenerationDispatchWithMaxValueLessThanMinP() throws Exception { UUID stubIdForPmaxReduction = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_1 + "," + FILTER_ID_2 + "," + FILTER_ID_3) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(getGeneratorsWithoutOutageFilters123())) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); UUID stubIdForFrequencyReserve1 = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_4 + "," + FILTER_ID_5) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(getGeneratorsFrequencyReserveFilters45())) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); UUID stubIdForFrequencyReserve2 = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_6) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(getGeneratorsFrequencyReserveFilter6())) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); String modificationJson = mapper.writeValueAsString(modification); MvcResult mvcResult = mockMvc.perform(post(getNetworkModificationUri()).content(modificationJson).contentType(MediaType.APPLICATION_JSON)) @@ -708,11 +702,11 @@ protected void assertAfterNetworkModificationDeletion() { assertEquals(7., getNetwork().getGenerator(NEW_GROUP2_ID).getTargetP(), 0.001); } - private Map handleQueryParams(List filterIds) { + private static Map handleQueryParams(List filterIds) { return Map.of("ids", WireMock.matching(filterIds.stream().map(uuid -> ".+").collect(Collectors.joining(",")))); } - private String getPath(boolean isRegexPhat) { + private static String getPath(boolean isRegexPhat) { if (isRegexPhat) { return "/v1/filters/metadata\\?ids="; } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInBusBreakerTest.java index 9ea44787f..e00e147be 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInBusBreakerTest.java @@ -4,22 +4,20 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.EnergySource; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.GeneratorCreationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveCreationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Arrays; @@ -30,14 +28,12 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.BUS_NOT_FOUND; import static org.gridsuite.modification.server.NetworkModificationException.Type.EQUIPMENT_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class GeneratorCreationInBusBreakerTest extends AbstractNetworkModificationTest { +class GeneratorCreationInBusBreakerTest extends AbstractNetworkModificationTest { private static String PROPERTY_NAME = "property-name"; private static String PROPERTY_VALUE = "property-value"; @@ -139,7 +135,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithBusbarSectionErrors() throws Exception { + void testCreateWithBusbarSectionErrors() throws Exception { GeneratorCreationInfos generatorCreationInfos = (GeneratorCreationInfos) buildModification(); generatorCreationInfos.setBusOrBusbarSectionId("notFoundBus"); mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(generatorCreationInfos)).contentType(MediaType.APPLICATION_JSON)) @@ -149,7 +145,7 @@ public void testCreateWithBusbarSectionErrors() throws Exception { } @Test - public void testCreateWithRegulatedTerminalError() throws Exception { + void testCreateWithRegulatedTerminalError() throws Exception { // invalid regulating terminal id <---> regulation terminal type GeneratorCreationInfos generatorCreationInfos = (GeneratorCreationInfos) buildModification(); generatorCreationInfos.setRegulatingTerminalType("LINE"); @@ -163,16 +159,14 @@ public void testCreateWithRegulatedTerminalError() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("GENERATOR_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idGenerator2", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("GENERATOR_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idGenerator2Edited", createdValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInNodeBreakerTest.java index dac2e7c5d..c5fcab3d4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorCreationInNodeBreakerTest.java @@ -4,41 +4,30 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.EnergySource; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; -import org.gridsuite.modification.server.dto.GeneratorCreationInfos; -import org.gridsuite.modification.server.dto.ModificationInfos; -import org.gridsuite.modification.server.dto.NetworkModificationResult; -import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveCreationInfos; -import org.gridsuite.modification.server.dto.FreePropertyInfos; +import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; -import java.util.Arrays; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.List; +import java.util.*; import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class GeneratorCreationInNodeBreakerTest extends AbstractNetworkModificationTest { +class GeneratorCreationInNodeBreakerTest extends AbstractNetworkModificationTest { private static String PROPERTY_NAME = "property-name"; private static String PROPERTY_VALUE = "property-value"; @@ -141,7 +130,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // invalid Generator id GeneratorCreationInfos generatorCreationInfos = (GeneratorCreationInfos) buildModification(); generatorCreationInfos.setEquipmentId(""); @@ -246,7 +235,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testCreateWithShortCircuitErrors() throws Exception { + void testCreateWithShortCircuitErrors() throws Exception { // invalid short circuit transient reactance GeneratorCreationInfos generatorCreationInfos = (GeneratorCreationInfos) buildModification(); generatorCreationInfos.setDirectTransX(Double.NaN); @@ -258,16 +247,14 @@ public void testCreateWithShortCircuitErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("GENERATOR_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idGenerator1", updatedValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("GENERATOR_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idGenerator2", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java index b9841d3f3..a8115d764 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorModificationTest.java @@ -4,19 +4,18 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ActivePowerControl; +import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.GeneratorShortCircuit; import com.powsybl.iidm.network.extensions.GeneratorStartup; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.util.CollectionUtils; @@ -24,15 +23,15 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.IntStream; +import static org.gridsuite.modification.server.utils.NetworkUtil.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class GeneratorModificationTest extends AbstractInjectionModificationTest { +class GeneratorModificationTest extends AbstractInjectionModificationTest { private static String PROPERTY_NAME = "property-name"; private static String PROPERTY_VALUE = "property-value"; @@ -50,6 +49,9 @@ protected ModificationInfos buildModification() { .equipmentName(new AttributeModification<>("newV1Generator", OperationType.SET)) .voltageLevelId(new AttributeModification<>("v2", OperationType.SET)) .busOrBusbarSectionId(new AttributeModification<>("1B", OperationType.SET)) + .connectionName(new AttributeModification<>("idGenerator", OperationType.SET)) + .connectionPosition(new AttributeModification<>(1, OperationType.SET)) + .connectionDirection(new AttributeModification<>(ConnectablePosition.Direction.TOP, OperationType.SET)) .targetP(new AttributeModification<>(80.0, OperationType.SET)) .targetQ(new AttributeModification<>(40.0, OperationType.SET)) .targetV(new AttributeModification<>(48.0, OperationType.SET)) @@ -113,7 +115,7 @@ protected void assertAfterNetworkModificationCreation() { assertEquals(80.0, modifiedGenerator.getTargetP()); assertEquals(40.0, modifiedGenerator.getTargetQ()); assertEquals(48.0, modifiedGenerator.getTargetV()); - assertEquals(false, modifiedGenerator.isVoltageRegulatorOn()); + assertFalse(modifiedGenerator.isVoltageRegulatorOn()); assertEquals(0., modifiedGenerator.getMinP()); assertEquals(100., modifiedGenerator.getMaxP()); assertEquals(220., modifiedGenerator.getRatedS()); @@ -122,7 +124,7 @@ protected void assertAfterNetworkModificationCreation() { assertEquals(0.30, modifiedGenerator.getExtension(GeneratorStartup.class).getPlannedOutageRate()); assertEquals(0.40, modifiedGenerator.getExtension(GeneratorStartup.class).getForcedOutageRate()); assertEquals(0.1f, modifiedGenerator.getExtension(ActivePowerControl.class).getDroop()); - assertEquals(true, modifiedGenerator.getExtension(ActivePowerControl.class).isParticipate()); + assertTrue(modifiedGenerator.getExtension(ActivePowerControl.class).isParticipate()); assertEquals(0.1, modifiedGenerator.getExtension(GeneratorShortCircuit.class).getDirectTransX()); assertEquals(0.1, modifiedGenerator.getExtension(GeneratorShortCircuit.class).getStepUpTransformerX()); assertEquals(ReactiveLimitsKind.CURVE, modifiedGenerator.getReactiveLimits().getKind()); @@ -137,7 +139,7 @@ protected void assertAfterNetworkModificationDeletion() { assertEquals(42.1, generator.getTargetP()); assertEquals(1.0, generator.getTargetQ()); assertEquals(Double.NaN, generator.getTargetV()); - assertEquals(false, generator.isVoltageRegulatorOn()); + assertFalse(generator.isVoltageRegulatorOn()); assertEquals(-1.1, generator.getMinP()); assertEquals(1000.0, generator.getMaxP()); assertEquals(Double.NaN, generator.getRatedS()); @@ -146,7 +148,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testMinMaxReactiveLimitsAttributesModification() throws Exception { + void testMinMaxReactiveLimitsAttributesModification() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); //setting ReactiveCapabilityCurve to false with null min and max reactive limits @@ -230,7 +232,7 @@ public void testMinMaxReactiveLimitsAttributesModification() throws Exception { } @Test - public void testGeneratorShortCircuitAttributesModification() throws Exception { + void testGeneratorShortCircuitAttributesModification() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); // setting transient reactance to null, modifying only step up transformer reactance @@ -260,7 +262,7 @@ public void testGeneratorShortCircuitAttributesModification() throws Exception { } @Test - public void testGeneratorVoltageRegulatorAttributesModification() throws Exception { + void testGeneratorVoltageRegulatorAttributesModification() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); // setting voltageRegulatorOn to true, applying qPercent and regulatingTerminal @@ -316,7 +318,7 @@ public void testGeneratorVoltageRegulatorAttributesModification() throws Excepti } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); // Unset an attribute that should not be null generatorModificationInfos.setEnergySource(new AttributeModification<>(null, OperationType.UNSET)); @@ -330,7 +332,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testDroopUnchanged() throws Exception { + void testDroopUnchanged() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); generatorModificationInfos.getDroop().setValue(18f); @@ -356,7 +358,7 @@ public void testDroopUnchanged() throws Exception { } @Test - public void testMinQGreaterThanMaxQ() throws Exception { + void testMinQGreaterThanMaxQ() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); Generator generator = getNetwork().getGenerator("idGenerator"); generator.newReactiveCapabilityCurve() @@ -401,7 +403,7 @@ public void testMinQGreaterThanMaxQ() throws Exception { } @Test - public void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception { + void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); Generator generator = getNetwork().getGenerator("idGenerator"); generator.setTargetP(80.) @@ -423,7 +425,7 @@ public void testActivePowerZeroOrBetweenMinAndMaxActivePower() throws Exception } @Test - public void testUnsetAttributes() throws Exception { + void testUnsetAttributes() throws Exception { GeneratorModificationInfos generatorModificationInfos = (GeneratorModificationInfos) buildModification(); // Unset TargetV @@ -445,29 +447,45 @@ public void testUnsetAttributes() throws Exception { } + @Test + void changeGeneratorOnBusBreakerWithoutBusBarSection() throws Exception { + VoltageLevel v1 = createVoltageLevel(getNetwork().getSubstation("s1"), "v11", "v32", TopologyKind.BUS_BREAKER, 380.0); + createBusBarSection(getNetwork().getVoltageLevel("v1"), "1.7", "1.7", 0); + createBus(v1, "bus111", "bus111"); + createGeneratorOnBus(v1, "idGenerator1", "bus111", 42.1, 1.0); + GeneratorModificationInfos generatorModificationInfos = GeneratorModificationInfos.builder() + .stashed(false) + .equipmentId("idGenerator1") + .connectionPosition(new AttributeModification<>(1, OperationType.SET)) + .build(); + String generatorModificationInfosJson = mapper.writeValueAsString(generatorModificationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(generatorModificationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + generatorModificationInfos = (GeneratorModificationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0); + assertEquals(1, generatorModificationInfos.getConnectionPosition().getValue()); + } + @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("GENERATOR_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idGenerator", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("GENERATOR_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idGeneratorEdited", createdValues.get("equipmentId")); } @Test - public void testDisconnection() throws Exception { + void testDisconnection() throws Exception { assertChangeConnectionState(getNetwork().getGenerator("idGenerator"), false); } @Test - public void testConnection() throws Exception { + void testConnection() throws Exception { assertChangeConnectionState(getNetwork().getGenerator("idGenerator"), true); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorScalingTest.java b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorScalingTest.java index 6b33c21b4..91f368883 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GeneratorScalingTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GeneratorScalingTest.java @@ -4,7 +4,6 @@ * 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 com.github.tomakehurst.wiremock.client.WireMock; @@ -12,38 +11,37 @@ import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; -import lombok.SneakyThrows; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.VariationMode; import org.gridsuite.modification.server.VariationType; -import org.gridsuite.modification.server.dto.*; +import org.gridsuite.modification.server.dto.FilterInfos; +import org.gridsuite.modification.server.dto.GeneratorScalingInfos; +import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.ScalingVariationInfos; import org.gridsuite.modification.server.impacts.AbstractBaseImpact; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import java.nio.file.Paths; import java.time.Instant; import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.createCollectionElementImpact; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCollectionElementImpact; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -51,7 +49,7 @@ * @author Seddik Yengui */ @Tag("IntegrationTest") -public class GeneratorScalingTest extends AbstractNetworkModificationTest { +class GeneratorScalingTest extends AbstractNetworkModificationTest { private static final UUID GENERATOR_SCALING_ID = UUID.randomUUID(); private static final UUID FILTER_ID_1 = UUID.randomUUID(); private static final UUID FILTER_ID_2 = UUID.randomUUID(); @@ -72,17 +70,14 @@ public class GeneratorScalingTest extends AbstractNetworkModificationTest { private static final String GENERATOR_ID_8 = "gen8"; private static final String GENERATOR_ID_9 = "gen9"; private static final String GENERATOR_ID_10 = "gen10"; - public static final String GENERATOR_WRONG_ID_1 = "wrongId1"; - public static final String PATH = "/v1/filters/metadata"; + private static final String GENERATOR_WRONG_ID_1 = "wrongId1"; + private static final String PATH = "/v1/filters/metadata"; - @Before - public void specificSetUp() { + @BeforeEach + void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); - createGenerators(); - } - - private void createGenerators() { + //createGenerators getNetwork().getVariantManager().setWorkingVariant("variant_1"); getNetwork().getGenerator(GENERATOR_ID_1).setTargetP(100).setMaxP(500); getNetwork().getGenerator(GENERATOR_ID_2).setTargetP(200).setMaxP(2000); @@ -96,7 +91,7 @@ private void createGenerators() { getNetwork().getGenerator(GENERATOR_ID_10).setTargetP(100).setMaxP(500); } - private List getTestFilters() { + private static List getTestFilters() { IdentifierListFilter filter1 = IdentifierListFilter.builder().id(FILTER_ID_1).modificationDate(new Date()).equipmentType(EquipmentType.GENERATOR) .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_1, 1.0), new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_2, 2.0))) @@ -133,7 +128,7 @@ public void testCreate() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + "(.+,){4}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); super.testCreate(); @@ -153,7 +148,7 @@ public void testCopy() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + "(.+,){4}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); super.testCopy(); @@ -161,7 +156,7 @@ public void testCopy() throws Exception { } @Test - public void testVentilationModeWithoutDistributionKey() throws Exception { + void testVentilationModeWithoutDistributionKey() throws Exception { IdentifierListFilter noDistributionKeyFilter = IdentifierListFilter.builder().id(FILTER_NO_DK).modificationDate(new Date()).equipmentType(EquipmentType.GENERATOR) .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_2, null), new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_3, null))) @@ -170,7 +165,7 @@ public void testVentilationModeWithoutDistributionKey() throws Exception { UUID subNoDk = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_NO_DK) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(noDistributionKeyFilter))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); var filter = FilterInfos.builder() .id(FILTER_NO_DK) @@ -203,7 +198,7 @@ public void testVentilationModeWithoutDistributionKey() throws Exception { } @Test - public void testFilterWithWrongIds() throws Exception { + void testFilterWithWrongIds() throws Exception { IdentifierListFilter wrongIdFilter1 = IdentifierListFilter.builder().id(FILTER_WRONG_ID_1).modificationDate(new Date()).equipmentType(EquipmentType.GENERATOR) .filterEquipmentsAttributes(List.of()) .build(); @@ -211,7 +206,7 @@ public void testFilterWithWrongIds() throws Exception { UUID subWrongId = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_WRONG_ID_1) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(wrongIdFilter1))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); var filter = FilterInfos.builder() .name("filter") @@ -236,7 +231,7 @@ public void testFilterWithWrongIds() throws Exception { } @Test - public void testScalingCreationWithWarning() throws Exception { + void testScalingCreationWithWarning() throws Exception { IdentifierListFilter filter5 = IdentifierListFilter.builder().id(FILTER_ID_5).modificationDate(new Date()).equipmentType(EquipmentType.GENERATOR) .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_9, 0.0), new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_10, 9.0))) @@ -251,7 +246,7 @@ public void testScalingCreationWithWarning() throws Exception { UUID subFilter = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + params + "," + params)) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(wrongIdFilter2, filter5))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); var filter = FilterInfos.builder() .name("filter") .id(FILTER_WRONG_ID_2) @@ -408,15 +403,15 @@ protected void assertAfterNetworkModificationDeletion() { assertEquals(100, getNetwork().getGenerator(GENERATOR_ID_10).getTargetP(), 0); } - private Map handleQueryParams(UUID filterId) { - return Map.of("ids", WireMock.equalTo(String.valueOf(filterId))); + private static Map handleQueryParams(UUID filterId) { + return Map.of("ids", WireMock.equalTo(filterId.toString())); } - private Map handleQueryParams(List filterIds) { + private static Map handleQueryParams(List filterIds) { return Map.of("ids", WireMock.matching(filterIds.stream().map(uuid -> ".+").collect(Collectors.joining(",")))); } - private String getPath(boolean isRegexPhat) { + private static String getPath(boolean isRegexPhat) { if (isRegexPhat) { return "/v1/filters/metadata\\?ids="; } @@ -424,24 +419,23 @@ private String getPath(boolean isRegexPhat) { } @Test - public void testRegularDistributionAllConnected() { + void testRegularDistributionAllConnected() throws Exception { testVariationWithSomeDisconnections(VariationMode.REGULAR_DISTRIBUTION, List.of()); } @Test - public void testRegularDistributionOnlyGTH2Connected() { + void testRegularDistributionOnlyGTH2Connected() throws Exception { testVariationWithSomeDisconnections(VariationMode.REGULAR_DISTRIBUTION, List.of("GH1", "GH2", "GH3", "GTH1", "GTH3")); } @Test - public void testAllModesGH1Disconnected() { + void testAllModesGH1Disconnected() throws Exception { for (VariationMode mode : VariationMode.values()) { testVariationWithSomeDisconnections(mode, List.of("GH1")); } } - @SneakyThrows - private void testVariationWithSomeDisconnections(VariationMode variationMode, List generatorsToDisconnect) { + private void testVariationWithSomeDisconnections(VariationMode variationMode, List generatorsToDisconnect) throws Exception { // use a dedicated network where we can easily disconnect generators setNetwork(Network.read(Paths.get(Objects.requireNonNull(this.getClass().getClassLoader().getResource("fourSubstations_testsOpenReac.xiidm")).toURI()))); @@ -463,7 +457,7 @@ private void testVariationWithSomeDisconnections(VariationMode variationMode, Li UUID subFilter = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_ALL_GEN) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(filter1))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); var filter = FilterInfos.builder() .name("filter") 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 e82f68b5b..8a97c7824 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/GroovyScriptTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/GroovyScriptTest.java @@ -4,32 +4,30 @@ * 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 com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.GroovyScriptInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; import java.util.Set; import java.util.UUID; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.testElementModificationImpact; import static org.gridsuite.modification.server.NetworkModificationException.Type.GROOVY_SCRIPT_EMPTY; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.testElementModificationImpact; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class GroovyScriptTest extends AbstractNetworkModificationTest { +class GroovyScriptTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -63,7 +61,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testGroovy() throws Exception { + void testGroovy() throws Exception { MvcResult mvcResult; GroovyScriptInfos groovyScriptInfos = GroovyScriptInfos.builder() @@ -75,48 +73,48 @@ public 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); } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { GroovyScriptInfos groovyScriptInfos = (GroovyScriptInfos) buildModification(); groovyScriptInfos.setScript(""); // apply empty groovy script diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToNewVoltageLevelTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToNewVoltageLevelTest.java index 7a020fcc3..fa5e4e316 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToNewVoltageLevelTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToNewVoltageLevelTest.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.SwitchKind; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; import org.junit.jupiter.api.Tag; @@ -18,17 +17,14 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author David Braquart */ @Tag("IntegrationTest") -public class LineAttachToNewVoltageLevelTest extends AbstractNetworkModificationTest { - - private LineCreationInfos getAttachmentLine() { +class LineAttachToNewVoltageLevelTest extends AbstractNetworkModificationTest { + private static LineCreationInfos getAttachmentLine() { return LineCreationInfos.builder() .stashed(false) .equipmentId("attachmentLine") @@ -37,7 +33,7 @@ private LineCreationInfos getAttachmentLine() { .build(); } - private VoltageLevelCreationInfos getNewVoltageLevel() { + private static VoltageLevelCreationInfos getNewVoltageLevel() { return VoltageLevelCreationInfos.builder() .stashed(false) .equipmentId("newVoltageLevel") @@ -121,16 +117,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_ATTACH_TO_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line3", createdValues.get("lineToAttachToId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_ATTACH_TO_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line3Edited", updatedValues.get("lineToAttachToId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToVoltageLevelTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToVoltageLevelTest.java index 2cf611ee7..e18fb171d 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToVoltageLevelTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineAttachToVoltageLevelTest.java @@ -9,12 +9,11 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.SwitchKind; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Arrays; @@ -23,9 +22,7 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -34,9 +31,8 @@ * @author David Braquart */ @Tag("IntegrationTest") -public class LineAttachToVoltageLevelTest extends AbstractNetworkModificationTest { - - private LineCreationInfos getAttachmentLine(String lineName) { +class LineAttachToVoltageLevelTest extends AbstractNetworkModificationTest { + private static LineCreationInfos getAttachmentLine(String lineName) { return LineCreationInfos.builder() .stashed(false) .equipmentId(lineName) @@ -45,7 +41,7 @@ private LineCreationInfos getAttachmentLine(String lineName) { .build(); } - private VoltageLevelCreationInfos getNewVoltageLevel() { + private static VoltageLevelCreationInfos getNewVoltageLevel() { return VoltageLevelCreationInfos.builder() .stashed(false) .equipmentId("newVoltageLevel") @@ -135,7 +131,7 @@ private void tryToCreateLineWithExistingId(LineAttachToVoltageLevelInfos tryWith } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { LineAttachToVoltageLevelInfos lineAttachToAbsentLine = (LineAttachToVoltageLevelInfos) buildModification(); lineAttachToAbsentLine.setLineToAttachToId("absent_line_id"); String lineAttachToAbsentLineJson = mapper.writeValueAsString(lineAttachToAbsentLine); @@ -157,7 +153,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testCreateWithExistingEquipments() throws Exception { + void testCreateWithExistingEquipments() throws Exception { // try to create an already existing line LineAttachToVoltageLevelInfos tryWithNewLine1Id = (LineAttachToVoltageLevelInfos) buildModification(); tryWithNewLine1Id.setNewLine1Id("line1"); @@ -181,16 +177,14 @@ public void testCreateWithExistingEquipments() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_ATTACH_TO_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line3", createdValues.get("lineToAttachToId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_ATTACH_TO_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line2", updatedValues.get("lineToAttachToId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java index 5624f4d8c..5cced597a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInBusBreakerTest.java @@ -4,20 +4,18 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.CurrentLimitsInfos; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.LineCreationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Collections; @@ -26,22 +24,20 @@ import java.util.UUID; import static org.gridsuite.modification.server.NetworkModificationException.Type.BUS_NOT_FOUND; -import static org.gridsuite.modification.server.utils.assertions.Assertions.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class LineCreationInBusBreakerTest extends AbstractNetworkModificationTest { +class LineCreationInBusBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { LineCreationInfos lineCreationInfos = (LineCreationInfos) buildModification(); lineCreationInfos.setBusOrBusbarSectionId2("notFoundBus"); String lineCreationInfosJson = mapper.writeValueAsString(lineCreationInfos); @@ -52,7 +48,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testCreateLineOptionalParameters() throws Exception { + void testCreateLineOptionalParameters() throws Exception { // create new line without shunt conductance or reactance LineCreationInfos lineCreationInfosNoShunt = LineCreationInfos.builder() .stashed(false) @@ -76,7 +72,7 @@ public void testCreateLineOptionalParameters() throws Exception { } @Test - public void testCreateLineOptionalParameters2() throws Exception { + void testCreateLineOptionalParameters2() throws Exception { // create new line without shunt conductance or reactance LineCreationInfos lineCreationInfosNoShunt = LineCreationInfos.builder() .stashed(false) @@ -105,7 +101,7 @@ public void testCreateLineOptionalParameters2() throws Exception { } @Test - public void testCreateLineOptionalParameters3() throws Exception { + void testCreateLineOptionalParameters3() throws Exception { LineCreationInfos lineCreationInfosPermanentLimitOK = LineCreationInfos.builder() .stashed(false) .equipmentId("idLine2") @@ -130,7 +126,7 @@ public void testCreateLineOptionalParameters3() throws Exception { } @Test - public void testCreateLineOptionalParameters4() throws Exception { + void testCreateLineOptionalParameters4() throws Exception { LineCreationInfos lineCreationInfosPermanentLimitOK = LineCreationInfos.builder() .stashed(false) .equipmentId("idLine2") @@ -157,7 +153,7 @@ public void testCreateLineOptionalParameters4() throws Exception { } @Test - public void testCreateLineOptionalParameters5() throws Exception { + void testCreateLineOptionalParameters5() throws Exception { LineCreationInfos lineCreationInfosPermanentLimitNOK = LineCreationInfos.builder() .stashed(false) .equipmentId("idLine2") @@ -177,7 +173,7 @@ public void testCreateLineOptionalParameters5() throws Exception { } @Test - public void testCreateLineOptionalParameters6() throws Exception { + void testCreateLineOptionalParameters6() throws Exception { LineCreationInfos lineCreationInfosOK = LineCreationInfos.builder() .stashed(false) .equipmentId("idLine3") @@ -257,16 +253,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLine1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLineEdited1", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInMixedTypologyTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInMixedTypologyTest.java index 6a4e2430d..376269e10 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInMixedTypologyTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInMixedTypologyTest.java @@ -4,13 +4,11 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.LineCreationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; @@ -21,12 +19,10 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; @Tag("IntegrationTest") -public class LineCreationInMixedTypologyTest extends AbstractNetworkModificationTest { +class LineCreationInMixedTypologyTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -103,16 +99,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLine1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLineEdited1", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java index 4e2b59e9c..c507f51bf 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineCreationInNodeBreakerTest.java @@ -4,18 +4,16 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -23,18 +21,17 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class LineCreationInNodeBreakerTest extends AbstractNetworkModificationTest { +class LineCreationInNodeBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @Test - public void testCreateWithBadVariant() throws Exception { + void testCreateWithBadVariant() throws Exception { // Test create line on not yet existing variant VARIANT_NOT_EXISTING_ID : // Only the modification should be added in the database but the line cannot be created LineCreationInfos modificationToCreate = (LineCreationInfos) buildModification(); @@ -51,7 +48,7 @@ public void testCreateWithBadVariant() throws Exception { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { LineCreationInfos lineCreationInfos = (LineCreationInfos) buildModification(); lineCreationInfos.setEquipmentId(""); String lineCreationInfosJson = mapper.writeValueAsString(lineCreationInfos); @@ -100,7 +97,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testCreateLineWithOnlyPermanentCurrentLimits() throws Exception { + void testCreateLineWithOnlyPermanentCurrentLimits() throws Exception { LineCreationInfos lineCreation = LineCreationInfos.builder() .equipmentId("idLineEdited") .equipmentName("nameLineEdited") @@ -138,7 +135,7 @@ public void testCreateLineWithOnlyPermanentCurrentLimits() throws Exception { } @Test - public void testCreateLineWithOnlyTemporaryCurrentLimits() throws Exception { + void testCreateLineWithOnlyTemporaryCurrentLimits() throws Exception { LineCreationInfos lineCreation = LineCreationInfos.builder() .equipmentId("idLineEdited") .equipmentName("nameLineEdited") @@ -182,7 +179,7 @@ public void testCreateLineWithOnlyTemporaryCurrentLimits() throws Exception { } @Test - public void testCreateLineWithBothCurrentLimits() throws Exception { + void testCreateLineWithBothCurrentLimits() throws Exception { LineCreationInfos lineCreation = LineCreationInfos.builder() .equipmentId("idLineEdited") .equipmentName("nameLineEdited") @@ -302,16 +299,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLine", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLineEdited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java index 109581464..3d4552d4d 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java @@ -4,7 +4,6 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; @@ -12,12 +11,11 @@ import com.powsybl.iidm.network.LoadingLimits.TemporaryLimit; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -25,10 +23,10 @@ import java.util.UUID; import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_NOT_FOUND; -import static org.gridsuite.modification.server.utils.assertions.Assertions.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNull; +import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -36,7 +34,7 @@ * @author Ayoub LABIDI */ @Tag("IntegrationTest") -public class LineModificationTest extends AbstractNetworkModificationTest { +class LineModificationTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -154,7 +152,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { LineModificationInfos lineModificationInfos = (LineModificationInfos) buildModification(); lineModificationInfos.setEquipmentId("lineNotFound"); String lineModificationInfosJson = mapper.writeValueAsString(lineModificationInfos); @@ -167,7 +165,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testPermanentLimitUnchanged() throws Exception { + void testPermanentLimitUnchanged() throws Exception { LineModificationInfos lineModificationInfos = (LineModificationInfos) buildModification(); lineModificationInfos.getCurrentLimits1().setPermanentLimit(null); @@ -183,7 +181,7 @@ public void testPermanentLimitUnchanged() throws Exception { } @Test - public void testCharacteristicsModification() throws Exception { + void testCharacteristicsModification() throws Exception { LineModificationInfos lineModificationInfos = (LineModificationInfos) buildModification(); // Modify Series Reactance @@ -289,7 +287,7 @@ public void testCharacteristicsModification() throws Exception { } @Test - public void testTemporaryLimitsModification() throws Exception { + void testTemporaryLimitsModification() throws Exception { Line line = getNetwork().getLine("line1"); line.newCurrentLimits1() .setPermanentLimit(10.0) @@ -362,28 +360,26 @@ public void testTemporaryLimitsModification() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line1", updatedValues.get("equipmentId")); } @Test - public void testDisconnection() throws Exception { + void testDisconnection() throws Exception { changeLineConnectionState(getNetwork().getLine("line1"), false); } @Test - public void testConnection() throws Exception { + void testConnection() throws Exception { changeLineConnectionState(getNetwork().getLine("line1"), true); } @@ -425,7 +421,7 @@ private void changeLineConnectionState(Line existingEquipment, boolean expectedS } @Test - public void changeLineConnectablePosition() throws Exception { + void changeLineConnectablePosition() throws Exception { LineModificationInfos lineModificationInfos = LineModificationInfos.builder() .stashed(false) .equipmentId("line3") @@ -443,6 +439,23 @@ public void changeLineConnectablePosition() throws Exception { LineModificationInfos createdModification = (LineModificationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0); assertEquals(1, createdModification.getConnectionPosition1().getValue()); assertEquals(1, createdModification.getConnectionPosition2().getValue()); + } + + @Test + void changeLineConnectablePositionWithoutBusBarSection() throws Exception { + LineModificationInfos lineModificationInfos = LineModificationInfos.builder() + .stashed(false) + .equipmentId("line3") + .equipmentName(new AttributeModification<>("LineModified", OperationType.SET)) + .connectionName1(new AttributeModification<>("line3", OperationType.SET)) + .connectionName2(new AttributeModification<>("line3", OperationType.SET)) + .build(); + String modificationInfosJson = mapper.writeValueAsString(lineModificationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(modificationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + LineModificationInfos createdModification = (LineModificationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0); + assertEquals("line3", createdModification.getConnectionName1().getValue()); + assertEquals("line3", createdModification.getConnectionName2().getValue()); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithNewVoltageLevelTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithNewVoltageLevelTest.java index c3d76b468..1138677b3 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithNewVoltageLevelTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithNewVoltageLevelTest.java @@ -9,15 +9,14 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.SwitchKind; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.CouplingDeviceInfos; import org.gridsuite.modification.server.dto.LineSplitWithVoltageLevelInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.VoltageLevelCreationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Arrays; @@ -26,17 +25,15 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class LineSplitWithNewVoltageLevelTest extends AbstractNetworkModificationTest { +class LineSplitWithNewVoltageLevelTest extends AbstractNetworkModificationTest { @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { LineSplitWithVoltageLevelInfos lineSplitAbsentLine = (LineSplitWithVoltageLevelInfos) buildModification(); lineSplitAbsentLine.setLineToSplitId("absent_line_id"); String lineSplitAbsentLineJson = mapper.writeValueAsString(lineSplitAbsentLine); @@ -117,16 +114,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_SPLIT_WITH_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line2", createdValues.get("lineToSplitId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_SPLIT_WITH_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line2Edited", updatedValues.get("lineToSplitId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithVoltageLevelTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithVoltageLevelTest.java index 079880a21..2fe99d401 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithVoltageLevelTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LineSplitWithVoltageLevelTest.java @@ -9,15 +9,14 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.SwitchKind; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.CouplingDeviceInfos; import org.gridsuite.modification.server.dto.LineSplitWithVoltageLevelInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.VoltageLevelCreationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Arrays; @@ -27,14 +26,12 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.BUSBAR_SECTION_NOT_FOUND; import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_ALREADY_EXISTS; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class LineSplitWithVoltageLevelTest extends AbstractNetworkModificationTest { +class LineSplitWithVoltageLevelTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -104,7 +101,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithExistingLines() throws Exception { + void testCreateWithExistingLines() throws Exception { // try to create an already existing line LineSplitWithVoltageLevelInfos tryWithNewLine1Id = (LineSplitWithVoltageLevelInfos) buildModification(); tryWithNewLine1Id.setNewLine1Id("line1"); @@ -125,7 +122,7 @@ public void testCreateWithExistingLines() throws Exception { } @Test - public void testCreateWithWrongBusBar() throws Exception { + void testCreateWithWrongBusBar() throws Exception { // not existing busbar LineSplitWithVoltageLevelInfos tryWithBadId = (LineSplitWithVoltageLevelInfos) buildModification(); tryWithBadId.setBbsOrBusId("999A"); @@ -146,16 +143,14 @@ public void testCreateWithWrongBusBar() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_SPLIT_WITH_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line2", createdValues.get("lineToSplitId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINE_SPLIT_WITH_VOLTAGE_LEVEL", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("line2Edited", updatedValues.get("lineToSplitId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LinesAttachToSplitLinesTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LinesAttachToSplitLinesTest.java index c82ad9546..99d5b861d 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LinesAttachToSplitLinesTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LinesAttachToSplitLinesTest.java @@ -8,13 +8,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.LinesAttachToSplitLinesInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkWithTeePoint; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Map; @@ -23,8 +22,7 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_ALREADY_EXISTS; import static org.gridsuite.modification.server.NetworkModificationException.Type.LINE_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -32,7 +30,7 @@ * @author David Braquart */ @Tag("IntegrationTest") -public class LinesAttachToSplitLinesTest extends AbstractNetworkModificationTest { +class LinesAttachToSplitLinesTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -97,7 +95,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // use an unexisting line LinesAttachToSplitLinesInfos linesAttachToSplitLinesInfos = (LinesAttachToSplitLinesInfos) buildModification(); linesAttachToSplitLinesInfos.setLineToAttachTo1Id("absent_line_id"); @@ -125,16 +123,14 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINES_ATTACH_TO_SPLIT_LINES", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("l3", createdValues.get("attachedLineId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LINES_ATTACH_TO_SPLIT_LINES", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("newline3", updatedValues.get("attachedLineId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInBusBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInBusBreakerTest.java index dde3890f9..58b9368f7 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInBusBreakerTest.java @@ -4,14 +4,12 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.LoadType; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.LoadCreationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; @@ -22,12 +20,10 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; @Tag("IntegrationTest") -public class LoadCreationInBusBreakerTest extends AbstractNetworkModificationTest { +class LoadCreationInBusBreakerTest extends AbstractNetworkModificationTest { private static String PROPERTY_NAME = "property-name"; private static String PROPERTY_VALUE = "property-value"; @@ -80,16 +76,15 @@ protected void assertAfterNetworkModificationDeletion() { assertNull(getNetwork().getLoad("idLoad1")); } - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + @Override + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LOAD_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLoad1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LOAD_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLoadEdited1", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInNodeBreakerTest.java index b31e4b790..77daf0fa6 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LoadCreationInNodeBreakerTest.java @@ -4,22 +4,20 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.LoadType; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.LoadCreationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.NetworkModificationResult; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -31,18 +29,17 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.BUSBAR_SECTION_NOT_FOUND; import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_LEVEL_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class LoadCreationInNodeBreakerTest extends AbstractNetworkModificationTest { +class LoadCreationInNodeBreakerTest extends AbstractNetworkModificationTest { private static String PROPERTY_NAME = "property-name"; private static String PROPERTY_VALUE = "property-value"; @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // Create load without connection name and UNDEFINED direction LoadCreationInfos loadCreationInfos1 = (LoadCreationInfos) buildModification(); loadCreationInfos1.setConnectionDirection(null); @@ -149,16 +146,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LOAD_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLoad1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LOAD_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idLoad1Edited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LoadModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LoadModificationTest.java index 638b7e5dc..b1937c92d 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LoadModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LoadModificationTest.java @@ -4,18 +4,16 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Load; import com.powsybl.iidm.network.LoadType; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -23,14 +21,12 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class LoadModificationTest extends AbstractInjectionModificationTest { +class LoadModificationTest extends AbstractInjectionModificationTest { private static String PROPERTY_NAME = "property-name"; private static String PROPERTY_VALUE = "property-value"; @@ -89,7 +85,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // Unset an attribute that should not be null LoadModificationInfos loadModificationInfos = LoadModificationInfos.builder() .stashed(false) @@ -102,28 +98,27 @@ public void testCreateWithErrors() throws Exception { assertLogMessage("Load 'v1load': load type is null", loadModificationInfos.getErrorType().name(), reportService); } - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + @Override + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LOAD_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v1load", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("LOAD_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v1loadEdited", updatedValues.get("equipmentId")); } @Test - public void testDisconnection() throws Exception { + void testDisconnection() throws Exception { assertChangeConnectionState(getNetwork().getLoad("v1load"), false); } @Test - public void testConnection() throws Exception { + void testConnection() throws Exception { assertChangeConnectionState(getNetwork().getLoad("v1load"), true); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/LoadScalingTest.java b/src/test/java/org/gridsuite/modification/server/modifications/LoadScalingTest.java index 28d2deef3..08dd24523 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/LoadScalingTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/LoadScalingTest.java @@ -4,7 +4,6 @@ * 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 com.github.tomakehurst.wiremock.client.WireMock; @@ -12,7 +11,6 @@ import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; -import lombok.SneakyThrows; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; @@ -20,31 +18,31 @@ import org.gridsuite.modification.server.ReactiveVariationMode; import org.gridsuite.modification.server.VariationMode; import org.gridsuite.modification.server.VariationType; -import org.gridsuite.modification.server.dto.*; +import org.gridsuite.modification.server.dto.FilterInfos; +import org.gridsuite.modification.server.dto.LoadScalingInfos; +import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.ScalingVariationInfos; import org.gridsuite.modification.server.impacts.AbstractBaseImpact; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; import org.hamcrest.core.IsNull; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import java.nio.file.Paths; import java.time.Instant; import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.createCollectionElementImpact; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCollectionElementImpact; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -53,59 +51,35 @@ * @author bendaamerahm */ @Tag("IntegrationTest") -public class LoadScalingTest extends AbstractNetworkModificationTest { +class LoadScalingTest extends AbstractNetworkModificationTest { private static final UUID LOAD_SCALING_ID = UUID.randomUUID(); - private static final UUID FILTER_ID_1 = UUID.randomUUID(); - private static final UUID FILTER_ID_2 = UUID.randomUUID(); - private static final UUID FILTER_ID_3 = UUID.randomUUID(); - private static final UUID FILTER_ID_4 = UUID.randomUUID(); - private static final UUID FILTER_ID_5 = UUID.randomUUID(); - private static final UUID FILTER_ID_ALL_LOADS = UUID.randomUUID(); - private static final UUID FILTER_NO_DK = UUID.randomUUID(); - private static final UUID FILTER_WRONG_ID_1 = UUID.randomUUID(); - private static final UUID FILTER_WRONG_ID_2 = UUID.randomUUID(); - private static final String LOAD_ID_1 = "load1"; - private static final String LOAD_ID_2 = "load2"; - private static final String LOAD_ID_3 = "load3"; - private static final String LOAD_ID_4 = "load4"; - private static final String LOAD_ID_5 = "load5"; - private static final String LOAD_ID_6 = "load6"; - private static final String LOAD_ID_7 = "load7"; - private static final String LOAD_ID_8 = "load8"; - private static final String LOAD_ID_9 = "load9"; - private static final String LOAD_ID_10 = "load10"; + private static final String LOAD_WRONG_ID_1 = "wrongId1"; + private static final String PATH = "/v1/filters/metadata"; - public static final String LOAD_WRONG_ID_1 = "wrongId1"; - - public static final String PATH = "/v1/filters/metadata"; - - @Before - public void specificSetUp() { + @BeforeEach + void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); - createLoads(); - } - - private void createLoads() { + //createLoads getNetwork().getVariantManager().setWorkingVariant("variant_1"); getNetwork().getLoad(LOAD_ID_1).setP0(100).setQ0(10); getNetwork().getLoad(LOAD_ID_2).setP0(200).setQ0(20); @@ -119,7 +93,7 @@ private void createLoads() { getNetwork().getLoad(LOAD_ID_10).setP0(100).setQ0(1.0); } - private List getTestFilters() { + private static List getTestFilters() { IdentifierListFilter filter1 = IdentifierListFilter.builder().id(FILTER_ID_1).modificationDate(new Date()).equipmentType(EquipmentType.LOAD) .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes(LOAD_ID_1, 1.0), new IdentifierListFilterEquipmentAttributes(LOAD_ID_2, 2.0))) @@ -156,7 +130,7 @@ public void testCreate() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + "(.+,){4}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); super.testCreate(); @@ -170,7 +144,7 @@ public void testCopy() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + "(.+,){4}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); super.testCopy(); @@ -178,7 +152,7 @@ public void testCopy() throws Exception { } @Test - public void testVentilationModeWithoutDistributionKey() throws Exception { + void testVentilationModeWithoutDistributionKey() throws Exception { IdentifierListFilter noDistributionKeyFilter = IdentifierListFilter.builder().id(FILTER_NO_DK).modificationDate(new Date()).equipmentType(EquipmentType.LOAD) .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes(LOAD_ID_2, null), new IdentifierListFilterEquipmentAttributes(LOAD_ID_3, null))) @@ -187,7 +161,7 @@ public void testVentilationModeWithoutDistributionKey() throws Exception { UUID stubNonDistributionKey = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_NO_DK) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(noDistributionKeyFilter))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); FilterInfos filter = FilterInfos.builder() .id(FILTER_NO_DK) .name("filter") @@ -218,7 +192,7 @@ public void testVentilationModeWithoutDistributionKey() throws Exception { } @Test - public void testFilterWithWrongIds() throws Exception { + void testFilterWithWrongIds() throws Exception { IdentifierListFilter wrongIdFilter1 = IdentifierListFilter.builder().id(FILTER_WRONG_ID_1).modificationDate(new Date()).equipmentType(EquipmentType.LOAD) .filterEquipmentsAttributes(List.of()) .build(); @@ -242,7 +216,7 @@ public void testFilterWithWrongIds() throws Exception { UUID stubWithWrongId = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_WRONG_ID_1) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(wrongIdFilter1))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); mockMvc.perform(post(getNetworkModificationUri()) .content(mapper.writeValueAsString(loadScalingInfo)) @@ -254,7 +228,7 @@ public void testFilterWithWrongIds() throws Exception { } @Test - public void testScalingCreationWithWarning() throws Exception { + void testScalingCreationWithWarning() throws Exception { String params = "(" + FILTER_ID_5 + "|" + FILTER_WRONG_ID_2 + ")"; IdentifierListFilter filter5 = IdentifierListFilter.builder().id(FILTER_ID_5).modificationDate(new Date()).equipmentType(EquipmentType.LOAD) @@ -291,7 +265,7 @@ public void testScalingCreationWithWarning() throws Exception { UUID stubMultipleWrongIds = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + params + "," + params)) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(wrongIdFilter2, filter5))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); mockMvc.perform(post(getNetworkModificationUri()) .content(mapper.writeValueAsString(loadScalingInfo)) @@ -433,15 +407,15 @@ protected void assertAfterNetworkModificationDeletion() { assertEquals(100.0, getNetwork().getLoad(LOAD_ID_10).getP0(), 0); } - private Map handleQueryParams(UUID filterId) { - return Map.of("ids", WireMock.equalTo(String.valueOf(filterId))); + private static Map handleQueryParams(UUID filterId) { + return Map.of("ids", WireMock.equalTo(filterId.toString())); } - private Map handleQueryParams(List filterIds) { + private static Map handleQueryParams(List filterIds) { return Map.of("ids", WireMock.matching(filterIds.stream().map(uuid -> ".+").collect(Collectors.joining(",")))); } - private String getPath(boolean isRegexPhat) { + private static String getPath(boolean isRegexPhat) { if (isRegexPhat) { return "/v1/filters/metadata\\?ids="; } @@ -449,23 +423,22 @@ private String getPath(boolean isRegexPhat) { } @Test - public void testProportionalAllConnected() { + void testProportionalAllConnected() throws Exception { testVariationWithSomeDisconnections(VariationMode.PROPORTIONAL, List.of()); } @Test - public void testProportionalAndVentilationLD1Disconnected() { + void testProportionalAndVentilationLD1Disconnected() throws Exception { testVariationWithSomeDisconnections(VariationMode.PROPORTIONAL, List.of("LD1")); testVariationWithSomeDisconnections(VariationMode.VENTILATION, List.of("LD1")); } @Test - public void testProportionalOnlyLD6Connected() { + void testProportionalOnlyLD6Connected() throws Exception { testVariationWithSomeDisconnections(VariationMode.PROPORTIONAL, List.of("LD1", "LD2", "LD3", "LD4", "LD5")); } - @SneakyThrows - private void testVariationWithSomeDisconnections(VariationMode variationMode, List loadsToDisconnect) { + private void testVariationWithSomeDisconnections(VariationMode variationMode, List loadsToDisconnect) throws Exception { // use a dedicated network where we can easily disconnect loads setNetwork(Network.read(Paths.get(Objects.requireNonNull(this.getClass().getClassLoader().getResource("fourSubstations_testsOpenReac.xiidm")).toURI()))); @@ -476,7 +449,8 @@ private void testVariationWithSomeDisconnections(VariationMode variationMode, Li .toList(); IdentifierListFilter filter1 = IdentifierListFilter.builder().id(FILTER_ID_ALL_LOADS).modificationDate(new Date()).equipmentType(EquipmentType.LOAD) - .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes("LD1", 0.0), + .filterEquipmentsAttributes(List.of( + new IdentifierListFilterEquipmentAttributes("LD1", 0.0), new IdentifierListFilterEquipmentAttributes("LD2", 100.0), new IdentifierListFilterEquipmentAttributes("LD3", 100.0), new IdentifierListFilterEquipmentAttributes("LD4", 100.0), @@ -487,7 +461,7 @@ private void testVariationWithSomeDisconnections(VariationMode variationMode, Li UUID subFilter = wireMockServer.stubFor(WireMock.get(getPath(false) + FILTER_ID_ALL_LOADS) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(filter1))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); FilterInfos filter = FilterInfos.builder() .name("filter") diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideOneLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideOneLineTest.java index e01a42936..8d9dbf88d 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideOneLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideOneLineTest.java @@ -9,13 +9,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Line; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; -import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Map; @@ -23,14 +22,12 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.OPERATING_STATUS_MODIFICATION_ERROR; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class OperatingStatusModificationEnergiseSideOneLineTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationEnergiseSideOneLineTest extends AbstractNetworkModificationTest { private static final String TARGET_LINE_ID = "line2"; @Override @@ -82,7 +79,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // Add a line that can't be disconnected Line line = getNetwork().newLine() .setId("cantdisconnect") @@ -104,8 +101,7 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("vl1", createdValues.get("energizedVoltageLevelId")); @@ -114,8 +110,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("vl1_bis", updatedValues.get("energizedVoltageLevelId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideTwoLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideTwoLineTest.java index 375051058..91505872a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideTwoLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationEnergiseSideTwoLineTest.java @@ -9,13 +9,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Line; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; -import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Map; @@ -23,14 +22,12 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.OPERATING_STATUS_MODIFICATION_ERROR; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class OperatingStatusModificationEnergiseSideTwoLineTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationEnergiseSideTwoLineTest extends AbstractNetworkModificationTest { private static final String TARGET_LINE_ID = "line2"; @Override @@ -81,7 +78,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // Add a line that can't be disconnected Line line = getNetwork().newLine() .setId("cantdisconnect") @@ -103,8 +100,7 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("vl2", createdValues.get("energizedVoltageLevelId")); @@ -113,8 +109,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("vl2_bis", updatedValues.get("energizedVoltageLevelId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutHvdcLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutHvdcLineTest.java index aca6c1b88..bbc021331 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutHvdcLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutHvdcLineTest.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.OperatingStatus; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; @@ -24,8 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("IntegrationTest") -public class OperatingStatusModificationLockoutHvdcLineTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationLockoutHvdcLineTest extends AbstractNetworkModificationTest { private static final String TARGET_HVDC_LINE_ID = "hvdcLine"; private static final OperatingStatus.Status TARGET_HVDC_LINE_STATUS = PLANNED_OUTAGE; @@ -69,8 +67,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", createdValues.get("energizedVoltageLevelId")); @@ -79,8 +76,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", updatedValues.get("energizedVoltageLevelId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutLineTest.java index 55f50642c..fb0bf47fa 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationLockoutLineTest.java @@ -13,14 +13,13 @@ import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.iidm.network.extensions.OperatingStatus; import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; -import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.TestUtils; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Map; @@ -31,16 +30,13 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.NetworkUtil.createSwitch; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class OperatingStatusModificationLockoutLineTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationLockoutLineTest extends AbstractNetworkModificationTest { private static final String TARGET_LINE_ID = "line2"; private static final String UPDATE_BRANCH_ID = "line1"; private static final OperatingStatus.Status TARGET_BRANCH_STATUS = PLANNED_OUTAGE; @@ -117,21 +113,21 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testLockoutLinesWithLoadBreakerSwitches() throws Exception { + void testLockoutLinesWithLoadBreakerSwitches() throws Exception { //Lockout line with switches of kind LOAD_BREAK_SWITCH createLineAndSwitches(SwitchKind.LOAD_BREAK_SWITCH, false); testLockoutLine("line1"); } @Test - public void testLockoutLinesWithDisconnectorSwitches() throws Exception { + void testLockoutLinesWithDisconnectorSwitches() throws Exception { //Lockout line with switches of kind DISCONNECTOR createLineAndSwitches(SwitchKind.DISCONNECTOR, false); testLockoutLine("line1"); } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // line not existing OperatingStatusModificationInfos modificationInfos = (OperatingStatusModificationInfos) buildModification(); modificationInfos.setEquipmentId("notFound"); @@ -173,8 +169,7 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", createdValues.get("energizedVoltageLevelId")); @@ -183,8 +178,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", updatedValues.get("energizedVoltageLevelId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationSwitchOnLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationSwitchOnLineTest.java index 830907a84..a429a6fdf 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationSwitchOnLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationSwitchOnLineTest.java @@ -10,22 +10,18 @@ import com.powsybl.iidm.network.Line; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.Terminal; -import lombok.SneakyThrows; -import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; import org.junit.jupiter.api.Tag; import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; @Tag("IntegrationTest") -public class OperatingStatusModificationSwitchOnLineTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationSwitchOnLineTest extends AbstractNetworkModificationTest { private static final String TARGET_LINE_ID = "line2"; @Override @@ -73,8 +69,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", createdValues.get("energizedVoltageLevelId")); @@ -83,8 +78,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelIdEdited", updatedValues.get("energizedVoltageLevelId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTrip2WTransformerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTrip2WTransformerTest.java index e3a1a9164..d4559ca63 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTrip2WTransformerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTrip2WTransformerTest.java @@ -9,9 +9,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.OperatingStatus; -import lombok.SneakyThrows; -import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.TestUtils; import org.junit.jupiter.api.Tag; @@ -24,8 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("IntegrationTest") -public class OperatingStatusModificationTrip2WTransformerTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationTrip2WTransformerTest extends AbstractNetworkModificationTest { private static final String TARGET_BRANCH_ID = "trf1"; private static final String UPDATE_BRANCH_ID = "trf1Edited"; private static final OperatingStatus.Status TARGET_BRANCH_STATUS = FORCED_OUTAGE; @@ -69,8 +67,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", createdValues.get("energizedVoltageLevelId")); @@ -79,8 +76,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelIdEdited", updatedValues.get("energizedVoltageLevelId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripBusBarTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripBusBarTest.java index 534ea7257..297a8d18b 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripBusBarTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripBusBarTest.java @@ -7,14 +7,13 @@ package org.gridsuite.modification.server.modifications; import com.fasterxml.jackson.core.type.TypeReference; -import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.BusbarSection; +import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.OperatingStatus; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.TestUtils; -import org.junit.Assert; import org.junit.jupiter.api.Tag; import java.util.Map; @@ -25,8 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("IntegrationTest") -public class OperatingStatusModificationTripBusBarTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationTripBusBarTest extends AbstractNetworkModificationTest { private static final String TARGET_BUSBAR_ID = "1.A"; private static final OperatingStatus.Status TARGET_BUSBAR_STATUS = FORCED_OUTAGE; private static final OperatingStatus.Status INITIAL_BUSBAR_STATUS = IN_OPERATION; @@ -69,16 +67,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("TRIP", createdValues.get("action")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("SWITCH_ON", updatedValues.get("action")); @@ -86,6 +82,6 @@ protected void testUpdateModificationMessage(ModificationInfos modificationInfos private void assertTerminalsStatusAfterNetworkModification(boolean shouldBeConnected) { BusbarSection busbarSection = getNetwork().getBusbarSection(TARGET_BUSBAR_ID); - Assert.assertEquals(busbarSection.getTerminal().isConnected(), shouldBeConnected); + assertEquals(busbarSection.getTerminal().isConnected(), shouldBeConnected); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripHvdcLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripHvdcLineTest.java index 3edbe0b78..72cbe54db 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripHvdcLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripHvdcLineTest.java @@ -10,12 +10,10 @@ import com.powsybl.iidm.network.HvdcLine; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.OperatingStatus; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.TestUtils; -import org.junit.Assert; import org.junit.jupiter.api.Tag; import java.util.Map; @@ -26,8 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("IntegrationTest") -public class OperatingStatusModificationTripHvdcLineTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationTripHvdcLineTest extends AbstractNetworkModificationTest { private static final String TARGET_HVDC_LINE_ID = "hvdcLine"; private static final OperatingStatus.Status TARGET_HVDC_LINE_STATUS = FORCED_OUTAGE; @@ -73,8 +70,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", createdValues.get("energizedVoltageLevelId")); @@ -83,8 +79,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", updatedValues.get("energizedVoltageLevelId")); @@ -94,7 +89,7 @@ protected void testUpdateModificationMessage(ModificationInfos modificationInfos private void assertTerminalsStatusAfterNetworkModification(boolean shouldBeConnected) { HvdcLine hvdcLine = getNetwork().getHvdcLine(TARGET_HVDC_LINE_ID); - Assert.assertEquals(hvdcLine.getConverterStation1().getTerminal().isConnected(), shouldBeConnected); - Assert.assertEquals(hvdcLine.getConverterStation2().getTerminal().isConnected(), shouldBeConnected); + assertEquals(hvdcLine.getConverterStation1().getTerminal().isConnected(), shouldBeConnected); + assertEquals(hvdcLine.getConverterStation2().getTerminal().isConnected(), shouldBeConnected); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripLineTest.java b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripLineTest.java index 89727ce39..ee2572c11 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripLineTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/OperatingStatusModificationTripLineTest.java @@ -9,9 +9,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.OperatingStatus; -import lombok.SneakyThrows; -import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; +import org.gridsuite.modification.server.dto.OperatingStatusModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.TestUtils; import org.junit.jupiter.api.Tag; @@ -24,8 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("IntegrationTest") -public class OperatingStatusModificationTripLineTest extends AbstractNetworkModificationTest { - +class OperatingStatusModificationTripLineTest extends AbstractNetworkModificationTest { private static final String TARGET_LINE_ID = "line2"; private static final String UPDATE_BRANCH_ID = "line1"; private static final OperatingStatus.Status TARGET_BRANCH_STATUS = FORCED_OUTAGE; @@ -69,8 +67,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelId", createdValues.get("energizedVoltageLevelId")); @@ -79,8 +76,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("OPERATING_STATUS_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("energizedVoltageLevelIdEdited", updatedValues.get("energizedVoltageLevelId")); 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 792d668b4..8354c9e0a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInBusBreakerTest.java @@ -4,20 +4,18 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.ShuntCompensatorCreationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.time.Instant; @@ -28,19 +26,17 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.BUS_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class ShuntCompensatorCreationInBusBreakerTest extends AbstractNetworkModificationTest { +class ShuntCompensatorCreationInBusBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { ShuntCompensatorCreationInfos shunt = (ShuntCompensatorCreationInfos) buildModification(); shunt.setBusOrBusbarSectionId("notFoundBus"); String shuntJson = mapper.writeValueAsString(shunt); @@ -102,16 +98,15 @@ protected void assertAfterNetworkModificationDeletion() { assertNull(getNetwork().getShuntCompensator("shuntOneId")); } - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + @Override + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SHUNT_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("shuntOneId", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SHUNT_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("shuntOneIdEdited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInNodeBreakerTest.java index 7f31b48c4..9d180cace 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInNodeBreakerTest.java @@ -4,21 +4,19 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.ShuntCompensatorCreationInfos; import org.gridsuite.modification.server.dto.ShuntCompensatorType; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.time.Instant; @@ -28,16 +26,14 @@ import java.util.UUID; import static org.gridsuite.modification.server.NetworkModificationException.Type.*; -import static org.gridsuite.modification.server.utils.assertions.Assertions.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class ShuntCompensatorCreationInNodeBreakerTest extends AbstractNetworkModificationTest { +class ShuntCompensatorCreationInNodeBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -94,7 +90,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithError() throws Exception { + void testCreateWithError() throws Exception { ShuntCompensatorCreationInfos modificationToCreate = (ShuntCompensatorCreationInfos) buildModification(); // try to create an existing equipment modificationToCreate.setEquipmentId("v5shunt"); @@ -107,7 +103,7 @@ public void testCreateWithError() throws Exception { } @Test - public void testCreateWithMaximumSectionCountError() throws Exception { + void testCreateWithMaximumSectionCountError() throws Exception { ShuntCompensatorCreationInfos modificationToCreate = (ShuntCompensatorCreationInfos) buildModification(); modificationToCreate.setMaximumSectionCount(0); @@ -119,7 +115,7 @@ public void testCreateWithMaximumSectionCountError() throws Exception { } @Test - public void testCreateWithSectionError() throws Exception { + void testCreateWithSectionError() throws Exception { ShuntCompensatorCreationInfos modificationToCreate = (ShuntCompensatorCreationInfos) buildModification(); modificationToCreate.setMaximumSectionCount(2); modificationToCreate.setSectionCount(3); @@ -132,7 +128,7 @@ public void testCreateWithSectionError() throws Exception { } @Test - public void testCreateWithExistingConnectionPosition() throws Exception { + void testCreateWithExistingConnectionPosition() throws Exception { ShuntCompensatorCreationInfos dto = (ShuntCompensatorCreationInfos) buildModification(); dto.setConnectionPosition(2); String modificationToCreateJson = mapper.writeValueAsString(dto); @@ -143,7 +139,7 @@ public void testCreateWithExistingConnectionPosition() throws Exception { } @Test - public void testCreateWithQAtNominalV() throws Exception { + void testCreateWithQAtNominalV() throws Exception { ShuntCompensatorCreationInfos dto = (ShuntCompensatorCreationInfos) buildModification(); dto.setMaxSusceptance(null); dto.setMaxQAtNominalV(80.0); @@ -166,16 +162,14 @@ public void testCreateWithQAtNominalV() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SHUNT_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("shuntOneId", updatedValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SHUNT_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("shuntOneIdEdited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModificationTest.java index af8bf16f4..546db0787 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModificationTest.java @@ -4,7 +4,6 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; @@ -12,12 +11,10 @@ import com.powsybl.iidm.network.ShuntCompensatorLinearModel; import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -28,16 +25,15 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.SHUNT_COMPENSATOR_NOT_FOUND; import static org.gridsuite.modification.server.utils.NetworkUtil.createShuntCompensator; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * @author Seddik Yengui */ - -public class ShuntCompensatorModificationTest extends AbstractInjectionModificationTest { +class ShuntCompensatorModificationTest extends AbstractInjectionModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -46,9 +42,8 @@ protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); } - @SneakyThrows @Test - public void testEquipmentWithWrongId() { + void testEquipmentWithWrongId() throws Exception { var shuntCompensator = ShuntCompensatorModificationInfos.builder() .stashed(false) .equipmentId("wrong id") @@ -61,9 +56,8 @@ public void testEquipmentWithWrongId() { shuntCompensator.getErrorType().name(), reportService); } - @SneakyThrows @Test - public void testWrongMaximumSectionCount() { + void testWrongMaximumSectionCount() throws Exception { var shuntCompensator = ShuntCompensatorModificationInfos.builder() .equipmentId("v5shunt") .sectionCount(new AttributeModification<>(3, OperationType.SET)) @@ -77,9 +71,8 @@ public void testWrongMaximumSectionCount() { shuntCompensator.getErrorType().name(), reportService); } - @SneakyThrows @Test - public void testWrongSectionCount() { + void testWrongSectionCount() throws Exception { var shuntCompensator = ShuntCompensatorModificationInfos.builder() .equipmentId("v5shunt") .sectionCount(new AttributeModification<>(3, OperationType.SET)) @@ -93,9 +86,8 @@ public void testWrongSectionCount() { shuntCompensator.getErrorType().name(), reportService); } - @SneakyThrows @Test - public void testWrongSectionCountChangeSectionCount() { + void testWrongSectionCountChangeSectionCount() throws Exception { VoltageLevel v5 = getNetwork().getVoltageLevel("v5"); createShuntCompensator(v5, "v7shunt", "v7shunt", 25, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM); @@ -115,9 +107,8 @@ public void testWrongSectionCountChangeSectionCount() { shuntCompensatorModifications.getErrorType().name(), reportService); } - @SneakyThrows @Test - public void testWrongSectionCountChangeMaximumSectionCount() { + void testWrongSectionCountChangeMaximumSectionCount() throws Exception { VoltageLevel v5 = getNetwork().getVoltageLevel("v5"); createShuntCompensator(v5, "v7shunt", "v7shunt", 25, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM); @@ -133,13 +124,12 @@ public void testWrongSectionCountChangeMaximumSectionCount() { mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(shuntCompensatorModifications)).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); assertLogMessage(new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR, - String.format("Section count should be between 0 and Maximum section count (1), actual : -1")).getMessage(), + "Section count should be between 0 and Maximum section count (1), actual : -1").getMessage(), shuntCompensatorModifications.getErrorType().name(), reportService); } - @SneakyThrows @Test - public void testNegativeQmaxAtNominalV() { + void testNegativeQmaxAtNominalV() throws Exception { var shuntCompensator = ShuntCompensatorModificationInfos.builder() .stashed(false) .equipmentId("v5shunt") @@ -153,9 +143,8 @@ public void testNegativeQmaxAtNominalV() { shuntCompensator.getErrorType().name(), reportService); } - @SneakyThrows @Test - public void testCreateModificationWithShuntCompensatorType() { + void testCreateModificationWithShuntCompensatorType() throws Exception { VoltageLevel v5 = getNetwork().getVoltageLevel("v5"); createShuntCompensator(v5, "v7shunt", "v7shunt", 25, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM); @@ -176,9 +165,8 @@ public void testCreateModificationWithShuntCompensatorType() { assertEquals(-1.0, model.getBPerSection(), 0); } - @SneakyThrows @Test - public void testCreateModificationWithSusceptancePerSection() { + void testCreateModificationWithSusceptancePerSection() throws Exception { VoltageLevel v5 = getNetwork().getVoltageLevel("v5"); createShuntCompensator(v5, "v7shunt", "v7shunt", 25, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM); @@ -199,9 +187,8 @@ public void testCreateModificationWithSusceptancePerSection() { assertEquals(3.0, model.getBPerSection(), 0); } - @SneakyThrows @Test - public void testCreateModificationWithSections() { + void testCreateModificationWithSections() throws Exception { var shuntCompensatorToModify = getNetwork().getShuntCompensator("v5shunt"); var model = shuntCompensatorToModify.getModel(ShuntCompensatorLinearModel.class); assertNotNull(model); @@ -219,9 +206,8 @@ public void testCreateModificationWithSections() { assertEquals(2, shuntCompensatorToModify.getSectionCount()); } - @SneakyThrows @Test - public void testCreateModificationWithQAtNominalV() { + void testCreateModificationWithQAtNominalV() throws Exception { VoltageLevel v5 = getNetwork().getVoltageLevel("v5"); createShuntCompensator(v5, "v7shunt", "v7shunt", 25, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM); VoltageLevel v6 = getNetwork().getVoltageLevel("v6"); @@ -290,7 +276,7 @@ protected void assertAfterNetworkModificationCreation() { var model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class); assertNotNull(model); assertEquals(2.9629E-4, model.getBPerSection(), 0.0001); - Assertions.assertEquals(PROPERTY_VALUE, getNetwork().getShuntCompensator("v7shunt").getProperty(PROPERTY_NAME)); + assertEquals(PROPERTY_VALUE, getNetwork().getShuntCompensator("v7shunt").getProperty(PROPERTY_NAME)); } @Override @@ -302,23 +288,21 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SHUNT_COMPENSATOR_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v7shunt", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { - Assertions.assertEquals("SHUNT_COMPENSATOR_MODIFICATION", modificationInfos.getMessageType()); + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { + assertEquals("SHUNT_COMPENSATOR_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v2shunt", updatedValues.get("equipmentId")); } @Test - public void testDisconnection() throws Exception { + void testDisconnection() throws Exception { ShuntCompensatorModificationInfos shuntModificationInfos = ShuntCompensatorModificationInfos.builder() .stashed(false) @@ -330,7 +314,7 @@ public void testDisconnection() throws Exception { } @Test - public void testConnection() throws Exception { + void testConnection() throws Exception { ShuntCompensatorModificationInfos shuntModificationInfos = ShuntCompensatorModificationInfos.builder() .stashed(false) 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 d1b9ee08d..2f5001f0d 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInBusBreakerTest.java @@ -10,26 +10,24 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.StaticVarCompensator; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.StaticVarCompensatorCreationInfos; import org.gridsuite.modification.server.dto.VoltageRegulationType; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; import java.util.Map; import java.util.UUID; -import static org.gridsuite.modification.server.NetworkModificationException.Type.*; +import static org.gridsuite.modification.server.NetworkModificationException.Type.BUS_NOT_FOUND; +import static org.gridsuite.modification.server.NetworkModificationException.Type.EQUIPMENT_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -37,7 +35,7 @@ * @author Ghazwa Rehili */ @Tag("IntegrationTest") -public class StaticVarCompensatorCreationInBusBreakerTest extends AbstractNetworkModificationTest { +class StaticVarCompensatorCreationInBusBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -56,8 +54,10 @@ protected ModificationInfos buildModification() { .busOrBusbarSectionId("bus1") .connectionName("top") .connectionDirection(ConnectablePosition.Direction.TOP) - .maxSusceptance(224.0) - .minSusceptance(200.0) + .maxSusceptance(null) + .minSusceptance(null) + .maxQAtNominalV(224.0) + .minQAtNominalV(200.0) .regulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) .voltageSetpoint(120.0) .reactivePowerSetpoint(300.0) @@ -105,7 +105,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)) @@ -115,7 +115,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"); @@ -130,16 +130,14 @@ public void testCreateWithRegulatedTerminalError() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("STATIC_VAR_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idStaticVarCompensator2", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("STATIC_VAR_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("idStaticVarCompensator2Edited", createdValues.get("equipmentId")); 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 eed31aafb..781002856 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/StaticVarCompensatorCreationInNodeBreakerTest.java @@ -10,12 +10,11 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.StaticVarCompensator; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -25,11 +24,10 @@ import java.util.UUID; import static com.powsybl.iidm.network.StaticVarCompensator.RegulationMode.OFF; -import static org.gridsuite.modification.server.NetworkModificationException.Type.BUSBAR_SECTION_NOT_FOUND; -import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_LEVEL_NOT_FOUND; +import static com.powsybl.iidm.network.StaticVarCompensator.RegulationMode.VOLTAGE; +import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -37,7 +35,7 @@ * @author Ghazwa Rehili */ @Tag("IntegrationTest") -public class StaticVarCompensatorCreationInNodeBreakerTest extends AbstractNetworkModificationTest { +class StaticVarCompensatorCreationInNodeBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -58,6 +56,8 @@ protected ModificationInfos buildModification() { .connectionDirection(ConnectablePosition.Direction.TOP) .maxSusceptance(224.0) .minSusceptance(200.0) + .maxQAtNominalV(null) + .minQAtNominalV(null) .regulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) .voltageSetpoint(120.0) .reactivePowerSetpoint(300.0) @@ -73,17 +73,22 @@ protected ModificationInfos buildModificationUpdate() { .stashed(false) .equipmentId("idStaticVarCompensator1Edited") .equipmentName("staticVarCompensatorNameEdited") + .maxSusceptance(null) + .minSusceptance(null) + .maxQAtNominalV(224.0) + .minQAtNominalV(200.0) .standbyAutomatonOn(true) .standby(true) - .b0(221.0) + .b0(null) + .q0(221.0) .lowVoltageSetpoint(200.0) .highVoltageSetpoint(400.0) .lowVoltageThreshold(250.0) .highVoltageThreshold(300.0) + .regulatingTerminalId("idGenerator1") + .regulatingTerminalType("GENERATOR") + .regulatingTerminalVlId("v1") .voltageRegulationType(VoltageRegulationType.DISTANT) - .regulatingTerminalId("idStaticVarCompensator1") - .regulatingTerminalType("STATIC_VAR_COMPENSATOR") - .regulatingTerminalVlId("v2") .build(); } @@ -103,7 +108,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // invalid Generator id StaticVarCompensatorCreationInfos compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); compensatorCreationInfos.setEquipmentId(""); @@ -112,6 +117,15 @@ public void testCreateWithErrors() throws Exception { .andExpect(status().isOk()); assertLogMessage("Invalid id ''", compensatorCreationInfos.getErrorType().name(), reportService); + // try to create an existing cspr + compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); + compensatorCreationInfos.setEquipmentId("v5Compensator"); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage(new NetworkModificationException(STATIC_VAR_COMPENSATOR_ALREADY_EXISTS, "v5Compensator").getMessage(), + compensatorCreationInfos.getErrorType().name(), reportService); + // not found voltage level compensatorCreationInfos.setEquipmentId("idStaticVarCompensator2"); compensatorCreationInfos.setVoltageLevelId("notFoundVoltageLevelId"); @@ -144,6 +158,7 @@ public void testCreateWithErrors() throws Exception { compensatorCreationInfos.setMinSusceptance(200.0); compensatorCreationInfos.setMaxSusceptance(null); compensatorCreationInfos.setMaxQAtNominalV(null); + compensatorCreationInfos.setMinQAtNominalV(null); compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); @@ -161,8 +176,18 @@ public void testCreateWithErrors() throws Exception { assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + "StaticVarCompensator 'idStaticVarCompensator2' : maximum susceptance is expected to be greater than or equal to minimum susceptance", compensatorCreationInfos.getErrorType().name(), reportService); - compensatorCreationInfos.setMaxSusceptance(200.0); - compensatorCreationInfos.setMinSusceptance(100.0); + compensatorCreationInfos.setMaxSusceptance(null); + compensatorCreationInfos.setMinSusceptance(null); + compensatorCreationInfos.setMaxQAtNominalV(200.0); + compensatorCreationInfos.setMinQAtNominalV(300.0); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : maximum Q at nominal voltage is expected to be greater than or equal to minimum Q", + compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setMaxQAtNominalV(200.0); + compensatorCreationInfos.setMinQAtNominalV(100.0); compensatorCreationInfos.setRegulationMode(StaticVarCompensator.RegulationMode.REACTIVE_POWER); compensatorCreationInfos.setReactivePowerSetpoint(null); compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); @@ -191,23 +216,77 @@ public void testCreateWithErrors() throws Exception { }); assertTrue(networkModificationResult.isEmpty()); assertNull(getNetwork().getStaticVarCompensator("idStaticVarCompensator3")); - testNetworkModificationsCount(getGroupId(), 9); + compensatorCreationInfos = StaticVarCompensatorCreationInfos.builder() + .stashed(false) + .equipmentId("idStaticVarCompensator3") + .equipmentName("nameStaticVarCompensator3") + .voltageLevelId("v2") + .busOrBusbarSectionId("1B") + .maxQAtNominalV(224.0) + .minQAtNominalV(200.0) + .lowVoltageSetpoint(200.0) + .highVoltageSetpoint(400.0) + .lowVoltageThreshold(250.0) + .highVoltageThreshold(300.0) + .q0(210.0) + .standbyAutomatonOn(true) + .build(); + compensatorCreationInfos.setEquipmentId("idStaticVarCompensator3"); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + testNetworkModificationsCount(getGroupId(), 12); } @Test - public void testCreateWithStandbyAutomatonErrors() throws Exception { + void testCreateWithStandbyAutomatonErrors() throws Exception { StaticVarCompensatorCreationInfos compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); compensatorCreationInfos.setStandbyAutomatonOn(true); - compensatorCreationInfos.setB0(300.0); - + compensatorCreationInfos.setMaxSusceptance(null); + compensatorCreationInfos.setMinSusceptance(null); + compensatorCreationInfos.setMinQAtNominalV(200.0); + compensatorCreationInfos.setMaxQAtNominalV(300.0); + compensatorCreationInfos.setLowVoltageSetpoint(200.0); + compensatorCreationInfos.setHighVoltageSetpoint(400.0); + compensatorCreationInfos.setLowVoltageThreshold(250.0); + compensatorCreationInfos.setHighVoltageThreshold(300.0); + compensatorCreationInfos.setQ0(Double.NaN); String compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("Cannot add standby automaton extension on Static var compensator 'idStaticVarCompensator1': b0 is invalid", + "StandbyAutomatonExtensionAddError", reportService); + compensatorCreationInfos = (StaticVarCompensatorCreationInfos) buildModification(); + compensatorCreationInfos.setEquipmentId("idStaticVarCompensator2"); + compensatorCreationInfos.setStandbyAutomatonOn(true); + compensatorCreationInfos.setMaxSusceptance(null); + compensatorCreationInfos.setMinSusceptance(null); + compensatorCreationInfos.setMinQAtNominalV(200.0); + compensatorCreationInfos.setMaxQAtNominalV(300.0); + compensatorCreationInfos.setLowVoltageSetpoint(200.0); + compensatorCreationInfos.setHighVoltageSetpoint(400.0); + compensatorCreationInfos.setLowVoltageThreshold(250.0); + compensatorCreationInfos.setHighVoltageThreshold(300.0); + compensatorCreationInfos.setQ0(400.0); + + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + - "StaticVarCompensator 'idStaticVarCompensator1' : b0 must be within the range of minimun susceptance and maximum susceptance", + "StaticVarCompensator 'idStaticVarCompensator2' : q0 must be within the range of minimum Q and maximum Q", + compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setMinQAtNominalV(null); + compensatorCreationInfos.setMaxQAtNominalV(null); + compensatorCreationInfos.setMaxSusceptance(300.0); + compensatorCreationInfos.setMinSusceptance(200.0); + compensatorCreationInfos.setB0(400.0); + compensatorCreationInfos.setQ0(null); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + + "StaticVarCompensator 'idStaticVarCompensator2' : b0 must be within the range of minimum susceptance and maximum susceptance", compensatorCreationInfos.getErrorType().name(), reportService); - - compensatorCreationInfos.setB0(200.0); compensatorCreationInfos.setRegulationMode(OFF); compensatorCreationInfos.setStandby(true); @@ -215,14 +294,23 @@ public void testCreateWithStandbyAutomatonErrors() throws Exception { mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); assertLogMessage("CREATE_STATIC_VAR_COMPENSATOR_ERROR : " + - "StaticVarCompensator 'idStaticVarCompensator1' : Standby is only supported in Voltage Regulation mode", + "StaticVarCompensator 'idStaticVarCompensator2' : Standby is only supported in Voltage Regulation mode", compensatorCreationInfos.getErrorType().name(), reportService); + compensatorCreationInfos.setRegulationMode(VOLTAGE); + compensatorCreationInfos.setB0(null); + compensatorCreationInfos.setQ0(200.0); + compensatorCreationInfos.setLowVoltageSetpoint(200.0); + compensatorCreationInfos.setHighVoltageSetpoint(400.0); + compensatorCreationInfos.setLowVoltageThreshold(250.0); + compensatorCreationInfos.setHighVoltageThreshold(300.0); + compensatorCreationInfosJson = mapper.writeValueAsString(compensatorCreationInfos); + mockMvc.perform(post(getNetworkModificationUri()).content(compensatorCreationInfosJson).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("STATIC_VAR_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); @@ -230,8 +318,7 @@ protected void testCreationModificationMessage(ModificationInfos modificationInf } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("STATIC_VAR_COMPENSATOR_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/SubstationCreationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/SubstationCreationTest.java index c9c9795f8..252d9c065 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/SubstationCreationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/SubstationCreationTest.java @@ -4,20 +4,18 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Country; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.Substation; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.FreePropertyInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.dto.SubstationCreationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -25,13 +23,12 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class SubstationCreationTest extends AbstractNetworkModificationTest { +class SubstationCreationTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -73,7 +70,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { SubstationCreationInfos substationCreationInfos = (SubstationCreationInfos) buildModification(); substationCreationInfos.setEquipmentId(""); String substationCreationInfosJson = mapper.writeValueAsString(substationCreationInfos); @@ -83,16 +80,14 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SUBSTATION_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("SubstationId", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SUBSTATION_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("SubstationIdEdited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/SubstationDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/SubstationDeletionTest.java index 5dd4f366a..e975b1289 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/SubstationDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/SubstationDeletionTest.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.EquipmentDeletionInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; @@ -17,14 +16,12 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author Etienne Homer */ -public class SubstationDeletionTest extends AbstractNetworkModificationTest { +class SubstationDeletionTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -66,16 +63,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_DELETION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("s1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_DELETION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v2", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/SubstationModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/SubstationModificationTest.java index 041c8f06b..341c7d85c 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/SubstationModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/SubstationModificationTest.java @@ -4,18 +4,16 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Country; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.Substation; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -24,8 +22,8 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -33,7 +31,7 @@ * @author David Braquart */ @Tag("IntegrationTest") -public class SubstationModificationTest extends AbstractNetworkModificationTest { +class SubstationModificationTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { @@ -91,7 +89,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { // Try to modify an unknown substation SubstationModificationInfos infos = SubstationModificationInfos.builder() .equipmentId("unknown") @@ -104,16 +102,14 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SUBSTATION_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("s3", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("SUBSTATION_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("s3Edited", updatedValues.get("equipmentId")); 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 01fe45641..16f5da3d3 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationBusBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationBusBreakerTest.java @@ -4,20 +4,17 @@ 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 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; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -26,16 +23,15 @@ import java.util.Set; import java.util.UUID; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.testBranchCreationImpacts; import static org.gridsuite.modification.server.NetworkModificationException.Type.BUS_NOT_FOUND; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.testBranchCreationImpacts; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class TwoWindingsTransformerCreationBusBreakerTest extends AbstractNetworkModificationTest { +class TwoWindingsTransformerCreationBusBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -260,7 +256,7 @@ protected ModificationInfos buildModificationUpdate() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { TwoWindingsTransformerCreationInfos twoWindingsTransformerCreationInfos = (TwoWindingsTransformerCreationInfos) buildModification(); twoWindingsTransformerCreationInfos.setEquipmentId(""); String twoWindingsTransformerCreationInfosJson = mapper.writeValueAsString(twoWindingsTransformerCreationInfos); @@ -300,7 +296,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateTwoWindingsTransformerWithRatioTapChangerInBusBreaker() throws Exception { + void testCreateTwoWindingsTransformerWithRatioTapChangerInBusBreaker() throws Exception { // create new 2wt in voltage level with Bus/breaker topology, having a RatioTapChanger RatioTapChangerCreationInfos ratioTapChangerCreationInfos = RatioTapChangerCreationInfos.builder() .lowTapPosition(0) @@ -359,7 +355,7 @@ public void testCreateTwoWindingsTransformerWithRatioTapChangerInBusBreaker() th } @Test - public void testCreateTwoWindingsTransformerWithPhaseTapChangerInBusBreaker() throws Exception { + void testCreateTwoWindingsTransformerWithPhaseTapChangerInBusBreaker() throws Exception { // create new 2wt in voltage level with Bus/breaker topology, having a PhaseTapChanger PhaseTapChangerCreationInfos phaseTapChangerCreationInfos = PhaseTapChangerCreationInfos.builder() .lowTapPosition(0) @@ -405,12 +401,12 @@ 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); } - private List getTapChangerSteps() { + private static List getTapChangerSteps() { return List.of( TapChangerStepCreationInfos.builder() .r(39.78473) @@ -437,16 +433,14 @@ private List getTapChangerSteps() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("new2wt", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("new2wtUpdate", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationMixedBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationMixedBreakerTest.java index 8a7dcfa26..26f6945e3 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationMixedBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationMixedBreakerTest.java @@ -4,19 +4,17 @@ 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 com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.PhaseTapChanger; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -24,13 +22,12 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class TwoWindingsTransformerCreationMixedBreakerTest extends AbstractNetworkModificationTest { +class TwoWindingsTransformerCreationMixedBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -276,7 +273,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { TwoWindingsTransformerCreationInfos twoWindingsTransformerCreationInfos = (TwoWindingsTransformerCreationInfos) buildModification(); twoWindingsTransformerCreationInfos.setEquipmentId(""); String twoWindingsTransformerCreationInfosJson = mapper.writeValueAsString(twoWindingsTransformerCreationInfos); @@ -293,16 +290,14 @@ public void testCreateWithErrors() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("id2wt1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("new2wtUpdate", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationNodeBreakerTest.java b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationNodeBreakerTest.java index c96fa21e2..155a7d051 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationNodeBreakerTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerCreationNodeBreakerTest.java @@ -4,7 +4,6 @@ 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 com.fasterxml.jackson.core.type.TypeReference; @@ -13,12 +12,11 @@ import com.powsybl.iidm.network.PhaseTapChanger; import com.powsybl.iidm.network.TwoWindingsTransformer; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -27,16 +25,15 @@ import java.util.Optional; import java.util.UUID; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.testBranchCreationImpacts; import static org.gridsuite.modification.server.NetworkModificationException.Type.TWO_WINDINGS_TRANSFORMER_ALREADY_EXISTS; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.testBranchCreationImpacts; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Tag("IntegrationTest") -public class TwoWindingsTransformerCreationNodeBreakerTest extends AbstractNetworkModificationTest { +class TwoWindingsTransformerCreationNodeBreakerTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -286,7 +283,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateTwoWindingsTransformerWithRatioTapChangerInNodeBreaker() throws Exception { + void testCreateTwoWindingsTransformerWithRatioTapChangerInNodeBreaker() throws Exception { // create new 2wt in voltage level with Node/breaker topology, having a RatioTapChanger RatioTapChangerCreationInfos ratioTapChangerCreationInfos = RatioTapChangerCreationInfos.builder() .lowTapPosition(0) @@ -386,7 +383,7 @@ public void testCreateTwoWindingsTransformerWithRatioTapChangerInNodeBreaker() t } @Test - public void testCreateTwoWindingsTransformerWithPhaseTapChangerInNodeBreaker() throws Exception { + void testCreateTwoWindingsTransformerWithPhaseTapChangerInNodeBreaker() throws Exception { // create new 2wt in voltage level with Node/breaker topology, having a PhaseTapChanger with Load regulating PhaseTapChangerCreationInfos phaseTapChangerLoadRegulatingCreationInfos = PhaseTapChangerCreationInfos.builder() .lowTapPosition(0) @@ -497,7 +494,7 @@ public void testCreateTwoWindingsTransformerWithPhaseTapChangerInNodeBreaker() t } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { TwoWindingsTransformerCreationInfos twoWindingsTransformerCreationInfos = (TwoWindingsTransformerCreationInfos) buildModification(); twoWindingsTransformerCreationInfos.setEquipmentId(""); String twoWindingsTransformerCreationInfosJson = mapper.writeValueAsString(twoWindingsTransformerCreationInfos); @@ -555,7 +552,7 @@ private void testCreateTwoWindingsTransformerInNodeBreaker(TwoWindingsTransforme testNetworkModificationsCount(getGroupId(), actualSize); } - private List getTapChangerSteps() { + private static List getTapChangerSteps() { return List.of( TapChangerStepCreationInfos.builder() .r(39.78473) @@ -582,16 +579,14 @@ private List getTapChangerSteps() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("new2wt", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("new2wtUpdate", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java index efd3a20a0..a4e5ff367 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java @@ -4,36 +4,24 @@ 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 com.fasterxml.jackson.core.type.TypeReference; -import com.powsybl.iidm.network.LoadingLimits; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.PhaseTapChanger; -import com.powsybl.iidm.network.Terminal; -import com.powsybl.iidm.network.TwoSides; -import com.powsybl.iidm.network.TwoWindingsTransformer; - +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import static org.gridsuite.modification.server.NetworkModificationException.Type.TWO_WINDINGS_TRANSFORMER_NOT_FOUND; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.gridsuite.modification.server.utils.assertions.Assertions.*; +import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -42,7 +30,7 @@ * @author Florent MILLOT */ @Tag("IntegrationTest") -public class TwoWindingsTransformerModificationTest extends AbstractNetworkModificationTest { +class TwoWindingsTransformerModificationTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -296,7 +284,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { TwoWindingsTransformerModificationInfos twoWindingsTransformerModificationInfos = (TwoWindingsTransformerModificationInfos) buildModification(); twoWindingsTransformerModificationInfos.setEquipmentId("2wt_not_existing"); String modificationInfosJson = mapper.writeValueAsString(twoWindingsTransformerModificationInfos); @@ -309,7 +297,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testRatioTapChangerModification() throws Exception { + void testRatioTapChangerModification() throws Exception { TwoWindingsTransformerModificationInfos twoWindingsTransformerModificationInfos = TwoWindingsTransformerModificationInfos.builder() .stashed(false) .equipmentId("trf1") @@ -431,7 +419,7 @@ public void testRatioTapChangerModification() throws Exception { } @Test - public void testPhaseTapChangerModification() throws Exception { + void testPhaseTapChangerModification() throws Exception { TwoWindingsTransformerModificationInfos twoWindingsTransformerModificationInfos = TwoWindingsTransformerModificationInfos.builder() .stashed(false) .equipmentId("trf2") @@ -577,24 +565,21 @@ public void testPhaseTapChangerModification() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("trf1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("TWO_WINDINGS_TRANSFORMER_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("trf1Edited", updatedValues.get("equipmentId")); } @Test - @SneakyThrows - public void testChangeConnectionStatus() { + void testChangeConnectionStatus() throws Exception { changeConnectionState(getNetwork().getTwoWindingsTransformer("trf1"), TwoSides.ONE, true, true, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf1"), TwoSides.ONE, true, false, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf1"), TwoSides.TWO, true, true, null); @@ -602,11 +587,10 @@ public void testChangeConnectionStatus() { changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.ONE, true, true, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.ONE, true, false, null); changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, true, null); - changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, false, "Could not disconnect equipment 'trf2' on side TWO"); + changeConnectionState(getNetwork().getTwoWindingsTransformer("trf2"), TwoSides.TWO, true, false, "Could not disconnect equipment 'trf2'"); } - @SneakyThrows - private void changeConnectionState(TwoWindingsTransformer existingEquipment, TwoSides side, boolean actualState, boolean expectedState, String errorMessage) { + private void changeConnectionState(TwoWindingsTransformer existingEquipment, TwoSides side, boolean actualState, boolean expectedState, String errorMessage) throws Exception { Terminal terminal = existingEquipment.getTerminal(side); assertThat(terminal.isConnected()).isEqualTo(actualState); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java index 50b791137..d9a9dda76 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VoltageInitModificationTest.java @@ -4,15 +4,14 @@ * 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 com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -21,7 +20,7 @@ import static org.gridsuite.modification.server.utils.NetworkUtil.createGenerator; import static org.gridsuite.modification.server.utils.NetworkUtil.createSwitch; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -29,7 +28,7 @@ * @author Franck Lecuyer */ @Tag("IntegrationTest") -public class VoltageInitModificationTest extends AbstractNetworkModificationTest { +class VoltageInitModificationTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { Network network = NetworkCreation.create(networkUuid, true); @@ -290,25 +289,25 @@ private void testVoltageInitShunt(String shuntCompensatorId, int currentSectionC } @Test - public void testVoltageInitConnectedSectionCountNull() throws Exception { + void testVoltageInitConnectedSectionCountNull() throws Exception { testVoltageInitShunt("v2shunt", 0, null, false); assertLogMessage("Section count value is undefined", "shuntCompensatorSectionCountUndefined", reportService); } @Test - public void testVoltageInitConnectedCurrentSection0Section0() throws Exception { + void testVoltageInitConnectedCurrentSection0Section0() throws Exception { testVoltageInitShunt("v2shunt", 0, 0, false); assertLogMessage("Shunt compensator disconnected", "shuntCompensatorDisconnected", reportService); } @Test - public void testVoltageInitDisconnectedConnectNull() throws Exception { + void testVoltageInitDisconnectedConnectNull() throws Exception { testVoltageInitShunt("v5shunt", 0, 0, null); assertLogMessage("Connect value is undefined", "shuntCompensatorConnectUndefined", reportService); } @Test - public void testVoltageInitDisconnectedCurrentSection0Section2() throws Exception { + void testVoltageInitDisconnectedCurrentSection0Section2() throws Exception { testVoltageInitShunt("v5shunt", 0, 2, true); assertLogMessage("Shunt compensator reconnected", "shuntCompensatorReconnected", reportService); assertLogMessage("Section count : 0 → 2", "modification-indent1", reportService); @@ -316,7 +315,7 @@ public void testVoltageInitDisconnectedCurrentSection0Section2() throws Exceptio } @Test - public void testVoltageInitDisconnectedCurrentSection1Section1() throws Exception { + void testVoltageInitDisconnectedCurrentSection1Section1() throws Exception { testVoltageInitShunt("v5shunt", 1, 1, true); assertLogMessage("Shunt compensator reconnected", "shuntCompensatorReconnected", reportService); assertEquals(1, getNetwork().getShuntCompensator("v5shunt").getSectionCount()); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java index 7e921a793..20d02664a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelCreationTest.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.SwitchKind; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.CouplingDeviceInfos; import org.gridsuite.modification.server.dto.FreePropertyInfos; @@ -17,8 +16,8 @@ import org.gridsuite.modification.server.dto.VoltageLevelCreationInfos; import org.gridsuite.modification.server.utils.ModificationCreation; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.Arrays; @@ -27,10 +26,8 @@ import java.util.UUID; import static org.gridsuite.modification.server.NetworkModificationException.Type.*; -import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -38,7 +35,7 @@ * @author walid Sahnoun */ @Tag("IntegrationTest") -public class VoltageLevelCreationTest extends AbstractNetworkModificationTest { +class VoltageLevelCreationTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -97,7 +94,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { VoltageLevelCreationInfos vli = (VoltageLevelCreationInfos) buildModification(); vli.setSubstationId("absent_station"); @@ -144,7 +141,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testCreateWithBbsNotExist() throws Exception { + void testCreateWithBbsNotExist() throws Exception { VoltageLevelCreationInfos vli = (VoltageLevelCreationInfos) buildModification(); vli.setEquipmentId("vl_1"); vli.getCouplingDevices().get(0).setBusbarSectionId1("1.1"); @@ -164,7 +161,7 @@ public void testCreateWithBbsNotExist() throws Exception { } @Test - public void testIpMinEqualsIpMax() throws Exception { + void testIpMinEqualsIpMax() throws Exception { VoltageLevelCreationInfos vli = (VoltageLevelCreationInfos) buildModification(); vli.setEquipmentId("vl_ok"); vli.setIpMin(25.0); @@ -177,7 +174,7 @@ public void testIpMinEqualsIpMax() throws Exception { } @Test - public void testCreateWithIpMinNull() throws Exception { + void testCreateWithIpMinNull() throws Exception { VoltageLevelCreationInfos vli = (VoltageLevelCreationInfos) buildModification(); vli.setEquipmentId("vl_ok"); vli.setIpMin(null); @@ -203,56 +200,29 @@ private void testIccWithError(Double ipMin, Double ipMax, String reportError) th } @Test - public void testIpMinGreaterThanIpMax() throws Exception { + void testIpMinGreaterThanIpMax() throws Exception { testIccWithError(15.1, 15.0, "IpMin cannot be greater than IpMax"); } @Test - public void testIpMinNegative() throws Exception { + void testIpMinNegative() throws Exception { testIccWithError(-25.0, 15.0, "IpMin must be positive"); } @Test - public void testIpMaxNegative() throws Exception { + void testIpMaxNegative() throws Exception { testIccWithError(25.0, -15.0, "IpMax must be positive"); } - public void testCreateWithShortCircuitExtension() throws Exception { - VoltageLevelCreationInfos vli = (VoltageLevelCreationInfos) buildModification(); - vli.setIpMin(null); - - String vliJson = mapper.writeValueAsString(vli); - mockMvc - .perform(post(getNetworkModificationUri()).content(vliJson).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andReturn(); - VoltageLevelCreationInfos createdModification = (VoltageLevelCreationInfos) modificationRepository - .getModifications(getGroupId(), false, true).get(0); - assertThat(createdModification).recursivelyEquals(vli); - - vli.setIpMin(0.0); - vli.setIpMax(null); - vli.setEquipmentId("vlId2"); - - vliJson = mapper.writeValueAsString(vli); - mockMvc - .perform(post(getNetworkModificationUri()).content(vliJson).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andReturn(); - createdModification = (VoltageLevelCreationInfos) modificationRepository - .getModifications(getGroupId(), false, true).get(1); - assertThat(createdModification).recursivelyEquals(vli); - } - @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("VOLTAGE_LEVEL_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("vlId", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("VOLTAGE_LEVEL_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("VoltageLevelIdEdited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelDeletionTest.java index b36cf1968..c49ab0eb1 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelDeletionTest.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.dto.EquipmentDeletionInfos; import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.utils.NetworkCreation; @@ -17,14 +16,12 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author Etienne Homer */ -public class VoltageLevelDeletionTest extends AbstractNetworkModificationTest { +class VoltageLevelDeletionTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -64,16 +61,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_DELETION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("EQUIPMENT_DELETION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v2", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java index e3385e182..b16e36aec 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VoltageLevelModificationTest.java @@ -4,7 +4,6 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; @@ -12,12 +11,11 @@ import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -26,8 +24,7 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_VOLTAGE_LEVEL_ERROR; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -35,7 +32,7 @@ * @author Seddik Yengui */ @Tag("IntegrationTest") -public class VoltageLevelModificationTest extends AbstractNetworkModificationTest { +class VoltageLevelModificationTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -100,7 +97,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testModifyShortCircuitExtension() throws Exception { + void testModifyShortCircuitExtension() throws Exception { VoltageLevelModificationInfos infos = (VoltageLevelModificationInfos) buildModification(); applyModification(infos); @@ -156,37 +153,37 @@ private void testIpMinIpMaxNotChanged(Double ipMin, Double ipMax, String reportE } @Test - public void testIpMinGreaterThanIpMax() throws Exception { + void testIpMinGreaterThanIpMax() throws Exception { // check only modification inputs testIpMinIpMaxNotChanged(30.0, 29.0, "IpMin cannot be greater than IpMax"); } @Test - public void testIpMinNegative() throws Exception { + void testIpMinNegative() throws Exception { // check only modification inputs testIpMinIpMaxNotChanged(-30.0, 0.0, "IpMin must be positive"); } @Test - public void testIpMaxNegative() throws Exception { + void testIpMaxNegative() throws Exception { // check only modification inputs testIpMinIpMaxNotChanged(0.0, -12.0, "IpMax must be positive"); } @Test - public void testIpMinGreaterThanEquipmentIpMax() throws Exception { + void testIpMinGreaterThanEquipmentIpMax() throws Exception { // check ipMin modification input against equipement ipMax real value (25.0) testIpMinIpMaxNotChanged(30.0, null, "IpMin cannot be greater than IpMax"); } @Test - public void testEquipmentIpMinGreaterThanIpMax() throws Exception { + void testEquipmentIpMinGreaterThanIpMax() throws Exception { // check ipMax modification input against equipement ipMin real value (15.0) testIpMinIpMaxNotChanged(null, 14.9, "IpMin cannot be greater than IpMax"); } @Test - public void testIpMinEqualsIpMax() throws Exception { + void testIpMinEqualsIpMax() throws Exception { final String vlWithBothIcc = "v3"; final double iccValue = 29.0; VoltageLevelModificationInfos vli = (VoltageLevelModificationInfos) buildModification(); @@ -205,7 +202,7 @@ public void testIpMinEqualsIpMax() throws Exception { } @Test - public void testSetIpMinOnEquipmentWithoutExtension() throws Exception { + void testSetIpMinOnEquipmentWithoutExtension() throws Exception { final String vlWithNoIcc = "v2"; VoltageLevelModificationInfos vli = VoltageLevelModificationInfos.builder() .stashed(false) @@ -221,7 +218,7 @@ public void testSetIpMinOnEquipmentWithoutExtension() throws Exception { } @Test - public void testSetIpMaxOnEquipmentWitOnlyIpMaxExtension() throws Exception { + void testSetIpMaxOnEquipmentWitOnlyIpMaxExtension() throws Exception { final String vlName = "v2"; // has no ICC getNetwork().getVoltageLevel(vlName) .newExtension(IdentifiableShortCircuitAdder.class).withIpMax(30.0).add(); @@ -250,16 +247,14 @@ private void applyModification(VoltageLevelModificationInfos infos) throws Excep } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("VOLTAGE_LEVEL_MODIFICATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("VOLTAGE_LEVEL_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("v1Edited", updatedValues.get("equipmentId")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VscCreationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VscCreationTest.java index 086e333b4..7554bdd3e 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VscCreationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VscCreationTest.java @@ -4,7 +4,6 @@ * 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 com.fasterxml.jackson.core.type.TypeReference; @@ -12,12 +11,10 @@ import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControl; import com.powsybl.iidm.network.extensions.HvdcOperatorActivePowerRange; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -28,16 +25,14 @@ import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.modifications.VscModification.ACTIVE_POWER_CONTROL_DROOP_P0_REQUIRED_ERROR_MSG; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * @author Seddik Yengui */ - -public class VscCreationTest extends AbstractNetworkModificationTest { - +class VscCreationTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -69,7 +64,7 @@ protected ModificationInfos buildModification() { .build(); } - private ConverterStationCreationInfos buildConverterStationWithMinMaxReactiveLimits() { + private static ConverterStationCreationInfos buildConverterStationWithMinMaxReactiveLimits() { return ConverterStationCreationInfos.builder() .equipmentId("stationId2") .equipmentName("station2") @@ -89,7 +84,7 @@ private ConverterStationCreationInfos buildConverterStationWithMinMaxReactiveLim .build(); } - private ConverterStationCreationInfos buildConverterStationWithReactiveCapabilityCurve() { + private static ConverterStationCreationInfos buildConverterStationWithReactiveCapabilityCurve() { var point1 = ReactiveCapabilityCurveCreationInfos.builder() .p(0.4) .maxQ(3.) @@ -191,19 +186,17 @@ protected void assertAfterNetworkModificationCreation() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("VSC_CREATION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals("vsc1", createdValues.get("equipmentId")); + assertEquals("vsc1", createdValues.get("equipmentId")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("VSC_CREATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals("vsc1Edited", updatedValues.get("equipmentId")); + assertEquals("vsc1Edited", updatedValues.get("equipmentId")); } @Override @@ -218,7 +211,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { VscCreationInfos vscCreationInfos = (VscCreationInfos) buildModification(); vscCreationInfos.setEquipmentId(""); String vscCreationInfosJson = mapper.writeValueAsString(vscCreationInfos); @@ -302,7 +295,7 @@ public void testCreateWithErrors() throws Exception { } @Test - public void testCreateAngleDroopPowerControlWithoutEnabling() throws Exception { + void testCreateAngleDroopPowerControlWithoutEnabling() throws Exception { VscCreationInfos vscCreationInfos = (VscCreationInfos) buildModification(); vscCreationInfos.setAngleDroopActivePowerControl(false); String vscCreationInfosJson = mapper.writeValueAsString(vscCreationInfos); @@ -318,7 +311,7 @@ public void testCreateAngleDroopPowerControlWithoutEnabling() throws Exception { } @Test - public void testNotCreateAngleDroopPowerControlWithoutEnabling() throws Exception { + void testNotCreateAngleDroopPowerControlWithoutEnabling() throws Exception { VscCreationInfos vscCreationInfos = (VscCreationInfos) buildModification(); vscCreationInfos.setAngleDroopActivePowerControl(false); vscCreationInfos.setDroop(null); @@ -333,7 +326,7 @@ public void testNotCreateAngleDroopPowerControlWithoutEnabling() throws Exceptio } @Test - public void testAngleDroopPowerControlWithAbsentInfos() throws Exception { + void testAngleDroopPowerControlWithAbsentInfos() throws Exception { boolean[][] droopInfosIsPresentData = { {true, false, false}, {true, true, false}, diff --git a/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java index a3010ab14..461c775e2 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/VscModificationTest.java @@ -14,33 +14,25 @@ import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControl; import com.powsybl.iidm.network.extensions.HvdcOperatorActivePowerRange; import com.powsybl.iidm.network.extensions.HvdcOperatorActivePowerRangeAdder; -import lombok.SneakyThrows; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Assert; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.util.CollectionUtils; -import java.io.IOException; import java.util.*; import java.util.stream.IntStream; import static org.assertj.core.api.Assertions.assertThat; import static org.gridsuite.modification.server.NetworkModificationException.Type.WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL; import static org.gridsuite.modification.server.modifications.VscModification.ACTIVE_POWER_CONTROL_DROOP_P0_REQUIRED_ERROR_MSG; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author jamal kheyyad */ @Tag("IntegrationTest") -public class VscModificationTest extends AbstractNetworkModificationTest { - +class VscModificationTest extends AbstractNetworkModificationTest { private static final String PROPERTY_NAME = "property-name"; private static final String PROPERTY_VALUE = "property-value"; @@ -72,7 +64,7 @@ protected ModificationInfos buildModification() { .build(); } - private ConverterStationModificationInfos buildConverterStationWithReactiveCapabilityCurve() { + private static ConverterStationModificationInfos buildConverterStationWithReactiveCapabilityCurve() { return ConverterStationModificationInfos.builder() .equipmentId("v1vsc") .stashed(false) @@ -88,14 +80,14 @@ private ConverterStationModificationInfos buildConverterStationWithReactiveCapab .build(); } - private ConverterStationModificationInfos buildEmptyConverterStation() { + private static ConverterStationModificationInfos buildEmptyConverterStation() { return ConverterStationModificationInfos.builder() .equipmentId("v1vsc") .stashed(false) .build(); } - private ConverterStationModificationInfos buildConverterStationWithMinMaxReactiveLimits() { + private static ConverterStationModificationInfos buildConverterStationWithMinMaxReactiveLimits() { return ConverterStationModificationInfos.builder() .equipmentId("v2vsc") .stashed(false) @@ -145,20 +137,20 @@ protected void assertAfterNetworkModificationCreation() { assertEquals(PROPERTY_VALUE, hvdcLine.getProperty(PROPERTY_NAME)); HvdcOperatorActivePowerRange hvdcOperatorActivePowerRange = hvdcLine.getExtension(HvdcOperatorActivePowerRange.class); - Assert.assertEquals(6, hvdcOperatorActivePowerRange.getOprFromCS1toCS2(), 0); - Assert.assertEquals(8, hvdcOperatorActivePowerRange.getOprFromCS2toCS1(), 0); + assertEquals(6, hvdcOperatorActivePowerRange.getOprFromCS1toCS2(), 0); + assertEquals(8, hvdcOperatorActivePowerRange.getOprFromCS2toCS1(), 0); HvdcAngleDroopActivePowerControl activePowerControl = hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class); - Assert.assertEquals(5, activePowerControl.getP0(), 0); - Assert.assertEquals(1, activePowerControl.getDroop(), 0); - Assert.assertTrue(activePowerControl.isEnabled()); + assertEquals(5, activePowerControl.getP0(), 0); + assertEquals(1, activePowerControl.getDroop(), 0); + assertTrue(activePowerControl.isEnabled()); - Assert.assertEquals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER, hvdcLine.getConvertersMode()); + assertEquals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER, hvdcLine.getConvertersMode()); - Assert.assertEquals(1, getNetwork().getVoltageLevel("v1").getVscConverterStationStream() + assertEquals(1, getNetwork().getVoltageLevel("v1").getVscConverterStationStream() .filter(converterStation -> converterStation.getId().equals("v1vsc")).count()); - Assert.assertEquals(1, getNetwork().getVoltageLevel("v2").getVscConverterStationStream() + assertEquals(1, getNetwork().getVoltageLevel("v2").getVscConverterStationStream() .filter(converterStation -> converterStation.getId().equals("v2vsc")).count()); VscModificationInfos vscModificationInfos = (VscModificationInfos) buildModification(); @@ -166,12 +158,12 @@ protected void assertAfterNetworkModificationCreation() { { VscConverterStation vscConverterStation1 = (VscConverterStation) hvdcLine.getConverterStation1(); assertNotNull(vscConverterStation1); - Assert.assertEquals("v1vsc-name", vscConverterStation1.getOptionalName().orElse("")); - Assert.assertEquals(0.2, vscConverterStation1.getReactivePowerSetpoint(), 0); - Assert.assertEquals(0.1F, vscConverterStation1.getLossFactor(), 0); - Assert.assertEquals(ReactiveLimitsKind.CURVE, vscConverterStation1.getReactiveLimits().getKind()); + assertEquals("v1vsc-name", vscConverterStation1.getOptionalName().orElse("")); + assertEquals(0.2, vscConverterStation1.getReactivePowerSetpoint(), 0); + assertEquals(0.1F, vscConverterStation1.getLossFactor(), 0); + assertEquals(ReactiveLimitsKind.CURVE, vscConverterStation1.getReactiveLimits().getKind()); ReactiveCapabilityCurve reactiveLimits1 = vscConverterStation1.getReactiveLimits(ReactiveCapabilityCurve.class); - Assert.assertEquals(2, reactiveLimits1.getPointCount()); + assertEquals(2, reactiveLimits1.getPointCount()); Collection points = vscConverterStation1.getReactiveLimits(ReactiveCapabilityCurve.class).getPoints(); List vscPoints = new ArrayList<>(points); List modificationPoints = vscModificationInfos.getConverterStation1().getReactiveCapabilityCurvePoints(); @@ -185,46 +177,44 @@ protected void assertAfterNetworkModificationCreation() { assertEquals(modificationPoint.getP(), point.getP()); }); } - Assert.assertEquals(0.3, vscConverterStation1.getVoltageSetpoint(), 0); - Assert.assertEquals("v1", vscConverterStation1.getTerminal().getVoltageLevel().getId()); + assertEquals(0.3, vscConverterStation1.getVoltageSetpoint(), 0); + assertEquals("v1", vscConverterStation1.getTerminal().getVoltageLevel().getId()); } { VscConverterStation vscConverterStation2 = (VscConverterStation) hvdcLine.getConverterStation2(); assertNotNull(vscConverterStation2); - Assert.assertEquals("v2vsc-name", vscConverterStation2.getOptionalName().orElse("")); - Assert.assertEquals(0.2, vscConverterStation2.getReactivePowerSetpoint(), 0); - Assert.assertEquals(0.1F, vscConverterStation2.getLossFactor(), 0); - Assert.assertEquals(ReactiveLimitsKind.MIN_MAX, vscConverterStation2.getReactiveLimits().getKind()); + assertEquals("v2vsc-name", vscConverterStation2.getOptionalName().orElse("")); + assertEquals(0.2, vscConverterStation2.getReactivePowerSetpoint(), 0); + assertEquals(0.1F, vscConverterStation2.getLossFactor(), 0); + assertEquals(ReactiveLimitsKind.MIN_MAX, vscConverterStation2.getReactiveLimits().getKind()); MinMaxReactiveLimits reactiveLimits2 = vscConverterStation2.getReactiveLimits(MinMaxReactiveLimits.class); - Assert.assertEquals(0.5, reactiveLimits2.getMaxQ(), 0); - Assert.assertEquals(0.4, reactiveLimits2.getMinQ(), 0); - Assert.assertEquals(0.3, vscConverterStation2.getVoltageSetpoint(), 0); - Assert.assertEquals("v2", vscConverterStation2.getTerminal().getVoltageLevel().getId()); + assertEquals(0.5, reactiveLimits2.getMaxQ(), 0); + assertEquals(0.4, reactiveLimits2.getMinQ(), 0); + assertEquals(0.3, vscConverterStation2.getVoltageSetpoint(), 0); + assertEquals("v2", vscConverterStation2.getTerminal().getVoltageLevel().getId()); } } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { String type = modificationInfos.getMessageType(); - Assert.assertEquals("VSC_MODIFICATION", type); - Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { - }); - Assertions.assertEquals("hvdcLine", createdValues.get("equipmentId")); //TODO : implement equipement id change and change hvdcLine to vsc1 for example + assertEquals("VSC_MODIFICATION", type); + Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); + assertEquals("hvdcLine", createdValues.get("equipmentId")); //TODO : implement equipment id change and change hvdcLine to vsc1 for example } @Override protected void assertAfterNetworkModificationDeletion() { assertNull(getNetwork().getHvdcLine("vsc1")); - Assert.assertEquals(0, getNetwork().getVoltageLevel("v1").getVscConverterStationStream() + assertEquals(0, getNetwork().getVoltageLevel("v1").getVscConverterStationStream() .filter(converterStation -> converterStation.getId().equals("stationId1")).count()); - Assert.assertEquals(0, getNetwork().getVoltageLevel("v2").getVscConverterStationStream() + assertEquals(0, getNetwork().getVoltageLevel("v2").getVscConverterStationStream() .filter(converterStation -> converterStation.getId().equals("stationId2")).count()); } @Test - public void testCreateAngleDroopActivePowerControlWithEnabling() throws Exception { + void testCreateAngleDroopActivePowerControlWithEnabling() throws Exception { var networkuuid = UUID.randomUUID(); Network networkWithoutExt = NetworkCreation.createWithVSC(networkuuid, false); VscModificationInfos modificationInfos = (VscModificationInfos) buildModification(); @@ -240,13 +230,13 @@ public void testCreateAngleDroopActivePowerControlWithEnabling() throws Exceptio HvdcAngleDroopActivePowerControl activePowerControlExt = hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class); assertThat(activePowerControlExt).isNotNull(); - Assert.assertEquals(5, activePowerControlExt.getP0(), 0); - Assert.assertEquals(1, activePowerControlExt.getDroop(), 0); + assertEquals(5, activePowerControlExt.getP0(), 0); + assertEquals(1, activePowerControlExt.getDroop(), 0); assertThat(activePowerControlExt.isEnabled()).isTrue(); } @Test - public void testAngleDroopActivePowerControlWithAbsentInfos() { + void testAngleDroopActivePowerControlWithAbsentInfos() { var networkuuid = UUID.randomUUID(); Network networkWithoutExt = NetworkCreation.createWithVSC(networkuuid, false); @@ -280,9 +270,9 @@ private VscModificationInfos buildModificationWithDroopAbsentInfos(boolean isPre return modificationInfos; } - private void checkDroopWithAbsentInfos(VscModificationInfos modificationInfos, Network networkWithoutExt) { + private static void checkDroopWithAbsentInfos(VscModificationInfos modificationInfos, Network networkWithoutExt) { VscModification vscModification = new VscModification(modificationInfos); - String message = Assert.assertThrows(NetworkModificationException.class, + String message = assertThrows(NetworkModificationException.class, () -> vscModification.check(networkWithoutExt)) .getMessage(); assertThat(message).isEqualTo(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL.name() + " : " @@ -290,7 +280,7 @@ private void checkDroopWithAbsentInfos(VscModificationInfos modificationInfos, N } @Test - public void testNotCreateAngleDroopActivePowerControl() throws Exception { + void testNotCreateAngleDroopActivePowerControl() throws Exception { var networkuuid = UUID.randomUUID(); Network networkWithExt = NetworkCreation.createWithVSC(networkuuid, false); VscModificationInfos modificationInfos = (VscModificationInfos) buildModification(); @@ -309,7 +299,7 @@ public void testNotCreateAngleDroopActivePowerControl() throws Exception { } @Test - public void testNotChangeAngleDroopActivePowerControl() throws Exception { + void testNotChangeAngleDroopActivePowerControl() throws Exception { var networkuuid = UUID.randomUUID(); Network networkWithExt = NetworkCreation.createWithVSC(networkuuid, true); VscModificationInfos modificationInfos = (VscModificationInfos) buildModification(); @@ -324,13 +314,13 @@ public void testNotChangeAngleDroopActivePowerControl() throws Exception { HvdcLine hvdcLine = networkWithExt.getHvdcLine("hvdcLine"); assertThat(hvdcLine).isNotNull(); HvdcAngleDroopActivePowerControl activePowerControlExt = hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class); - Assert.assertEquals(10, activePowerControlExt.getDroop(), 0); - Assert.assertEquals(0, activePowerControlExt.getP0(), 0); + assertEquals(10, activePowerControlExt.getDroop(), 0); + assertEquals(0, activePowerControlExt.getP0(), 0); assertThat(activePowerControlExt.isEnabled()).isTrue(); } @Test - public void testChangeAngleDroopActivePowerControl() throws Exception { + void testChangeAngleDroopActivePowerControl() throws Exception { var networkuuid = UUID.randomUUID(); Network networkWithExt = NetworkCreation.createWithVSC(networkuuid, true); VscModificationInfos modificationInfos = (VscModificationInfos) buildModification(); @@ -345,21 +335,20 @@ public void testChangeAngleDroopActivePowerControl() throws Exception { HvdcLine hvdcLine = networkWithExt.getHvdcLine("hvdcLine"); assertThat(hvdcLine).isNotNull(); HvdcAngleDroopActivePowerControl activePowerControlExt = hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class); - Assert.assertEquals(2, activePowerControlExt.getDroop(), 0); - Assert.assertEquals(6, activePowerControlExt.getP0(), 0); + assertEquals(2, activePowerControlExt.getDroop(), 0); + assertEquals(6, activePowerControlExt.getP0(), 0); assertThat(activePowerControlExt.isEnabled()).isFalse(); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("VSC_MODIFICATION", modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals("vsc1Edited", updatedValues.get("equipmentId")); } @Test - public void testDtoContainRequiredData() { + void testDtoContainRequiredData() { VscModificationInfos modificationInfos = VscModificationInfos.builder() .stashed(false) .equipmentId("hvdcLine") @@ -368,11 +357,11 @@ public void testDtoContainRequiredData() { var networkuuid = UUID.randomUUID(); Network networkWitoutExt = NetworkCreation.createWithVSC(networkuuid, true); VscModification vscModification = new VscModification(modificationInfos); - Assert.assertThrows(NetworkModificationException.class, () -> vscModification.check(networkWitoutExt)); + assertThrows(NetworkModificationException.class, () -> vscModification.check(networkWitoutExt)); } @Test - public void testModifyOperatorActiveRange() throws IOException { + void testModifyOperatorActiveRange() throws Exception { VscModificationInfos modificationInfos = VscModificationInfos.builder() .stashed(false) .equipmentId("hvdcLine") @@ -395,12 +384,12 @@ public void testModifyOperatorActiveRange() throws IOException { assertDoesNotThrow(() -> vscModification.check(networkWithExt)); vscModification.apply(networkWithExt, true, computationManager, subReporter); var hvdcOperatorActivePowerRange = hvdcLine.getExtension(HvdcOperatorActivePowerRange.class); - Assert.assertEquals(100.f, hvdcOperatorActivePowerRange.getOprFromCS1toCS2(), 0.1); - Assert.assertEquals(99.f, hvdcOperatorActivePowerRange.getOprFromCS2toCS1(), 0.1); + assertEquals(100.f, hvdcOperatorActivePowerRange.getOprFromCS1toCS2(), 0.1); + assertEquals(99.f, hvdcOperatorActivePowerRange.getOprFromCS2toCS1(), 0.1); } @Test - public void testNoChangeOnConverterStation() throws IOException { + void testNoChangeOnConverterStation() throws Exception { var networkuuid = UUID.randomUUID(); ConverterStationModificationInfos emptyConverterStation = buildEmptyConverterStation(); Network networkWithExt = NetworkCreation.createWithVSC(networkuuid, true); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java index 9bb0958e2..d33363de1 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/AbstractModificationByAssignmentTest.java @@ -4,7 +4,6 @@ * 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.byfilter.assignment; import com.fasterxml.jackson.core.type.TypeReference; @@ -27,9 +26,10 @@ import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -37,9 +37,9 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCollectionElementImpact; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.createCollectionElementImpact; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -49,7 +49,7 @@ * @author Thang PHAM */ @Tag("IntegrationTest") -public abstract class AbstractModificationByAssignmentTest extends AbstractNetworkModificationTest { +abstract class AbstractModificationByAssignmentTest extends AbstractNetworkModificationTest { protected static final UUID FILTER_ID_1 = UUID.randomUUID(); protected static final UUID FILTER_ID_2 = UUID.randomUUID(); protected static final UUID FILTER_ID_3 = UUID.randomUUID(); @@ -66,17 +66,16 @@ public abstract class AbstractModificationByAssignmentTest extends AbstractNetwo protected final FilterInfos filter6 = new FilterInfos(FILTER_ID_6, "filter6"); protected final FilterInfos filterWithOneWrongId = new FilterInfos(FILTER_WITH_ONE_WRONG_ID, "filterWithOneWrongId"); - public static final String PATH = "/v1/filters/metadata"; + protected static final String PATH = "/v1/filters/metadata"; @Override protected void assertResultImpacts(List impacts) { assertThat(impacts).containsExactly(createCollectionElementImpact(getIdentifiableType())); } - @Before + @BeforeEach public void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); - getNetwork().getVariantManager().setWorkingVariant("variant_1"); createEquipments(); } @@ -108,7 +107,7 @@ protected void checkCreateWithWarning(List> assignments, List UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching("/v1/filters/metadata\\?ids=" + FILTER_WITH_ONE_WRONG_ID)) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(filter))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); checkCreationApplicationStatus(assignments, NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); @@ -124,7 +123,7 @@ protected void checkCreateWithError(List> assignments, List handleQueryParams(List filterIds) { + protected Map handleQueryParams(List filterIds) { return Map.of("ids", WireMock.matching(filterIds.stream().map(uuid -> ".+").collect(Collectors.joining(",")))); } - String getPath(boolean isRegexPath) { + protected String getPath(boolean isRegexPath) { if (isRegexPath) { return "/v1/filters/metadata\\?ids="; } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/BatteryModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/BatteryModificationByAssignmentTest.java index ed88c74f2..635beeb4d 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/BatteryModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/BatteryModificationByAssignmentTest.java @@ -4,7 +4,6 @@ * 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.byfilter.assignment; import com.powsybl.iidm.network.IdentifiableType; @@ -17,19 +16,19 @@ import org.gridsuite.modification.server.dto.byfilter.assignment.AssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.assignment.DoubleAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.equipmentfield.BatteryField; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.List; import static org.gridsuite.modification.server.utils.NetworkUtil.createBattery; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Thang PHAM */ -public class BatteryModificationByAssignmentTest extends AbstractModificationByAssignmentTest { +class BatteryModificationByAssignmentTest extends AbstractModificationByAssignmentTest { private static final String BATTERY_ID_1 = "v3Battery"; private static final String BATTERY_ID_2 = "battery2"; private static final String BATTERY_ID_3 = "battery3"; @@ -38,7 +37,7 @@ public class BatteryModificationByAssignmentTest extends AbstractModificationByA private static final String BATTERY_ID_6 = "battery6"; @Test - public void testCreateWithWarning() throws Exception { + void testCreateWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes = getIdentifiableAttributes(BATTERY_ID_1, 1.0); IdentifierListFilterEquipmentAttributes wrongIdAttributes = getIdentifiableAttributes("wrongId", 1.0); @@ -210,5 +209,4 @@ protected IdentifiableType getIdentifiableType() { protected EquipmentType getEquipmentType() { return EquipmentType.BATTERY; } - } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/GeneratorModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/GeneratorModificationByAssignmentTest.java index f4c724173..181075785 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/GeneratorModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/GeneratorModificationByAssignmentTest.java @@ -4,7 +4,6 @@ * 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.byfilter.assignment; import com.powsybl.iidm.network.Generator; @@ -18,22 +17,22 @@ import org.gridsuite.modification.server.dto.byfilter.assignment.BooleanAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.assignment.DoubleAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.equipmentfield.GeneratorField; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.gridsuite.modification.server.utils.NetworkUtil.createGenerator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Thang PHAM */ @Tag("IntegrationTest") -public class GeneratorModificationByAssignmentTest extends AbstractModificationByAssignmentTest { +class GeneratorModificationByAssignmentTest extends AbstractModificationByAssignmentTest { private static final String GENERATOR_ID_1 = "idGenerator"; private static final String GENERATOR_ID_2 = "v5generator"; private static final String GENERATOR_ID_3 = "v6generator"; @@ -46,7 +45,7 @@ public class GeneratorModificationByAssignmentTest extends AbstractModificationB private static final String GENERATOR_ID_10 = "gen10"; @Test - public void testCreateWithWarning() throws Exception { + void testCreateWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes = getIdentifiableAttributes(GENERATOR_ID_1, 1.0); IdentifierListFilterEquipmentAttributes wrongIdAttributes = getIdentifiableAttributes("wrongId", 1.0); @@ -60,6 +59,7 @@ public void testCreateWithWarning() throws Exception { assertEquals(55, getNetwork().getGenerator(GENERATOR_ID_1).getTargetP(), 0); } + @Override protected void createEquipments() { getNetwork().getGenerator(GENERATOR_ID_1) .setTargetP(100) @@ -128,6 +128,7 @@ protected void createEquipments() { getNetwork().getGenerator(GENERATOR_ID_10).setRatedS(30.); } + @Override protected List getTestFilters() { IdentifierListFilter filter1 = IdentifierListFilter.builder().id(FILTER_ID_1).modificationDate(new Date()).equipmentType(EquipmentType.GENERATOR) .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_1, 1.0), diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/LoadModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/LoadModificationByAssignmentTest.java index e4fb3de38..f561e3acc 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/LoadModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/LoadModificationByAssignmentTest.java @@ -4,7 +4,6 @@ * 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.byfilter.assignment; import com.powsybl.iidm.network.IdentifiableType; @@ -24,14 +23,14 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createSubstationImpacts; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.createSubstationImpacts; import static org.gridsuite.modification.server.utils.NetworkUtil.createLoad; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Thang PHAM */ -public class LoadModificationByAssignmentTest extends AbstractModificationByAssignmentTest { +class LoadModificationByAssignmentTest extends AbstractModificationByAssignmentTest { private static final String LOAD_ID_1 = "load1"; private static final String LOAD_ID_2 = "load2"; private static final String LOAD_ID_3 = "load3"; @@ -130,5 +129,4 @@ protected void assertResultImpacts(List impacts) { // since the test network has only 4 loads which is less than the collectionThreshold 5 assertThat(impacts).containsAll(createSubstationImpacts(Set.of("s1", "s2"))); } - } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/ShuntCompensatorModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/ShuntCompensatorModificationByAssignmentTest.java index 727b1d4b2..9938578ca 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/ShuntCompensatorModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/ShuntCompensatorModificationByAssignmentTest.java @@ -4,7 +4,6 @@ * 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.byfilter.assignment; import com.powsybl.iidm.network.IdentifiableType; @@ -19,18 +18,18 @@ import org.gridsuite.modification.server.dto.byfilter.assignment.DoubleAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.assignment.IntegerAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.equipmentfield.ShuntCompensatorField; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.List; import static org.gridsuite.modification.server.utils.NetworkUtil.createShuntCompensator; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Thang PHAM */ -public class ShuntCompensatorModificationByAssignmentTest extends AbstractModificationByAssignmentTest { +class ShuntCompensatorModificationByAssignmentTest extends AbstractModificationByAssignmentTest { private static final String SHUNT_COMPENSATOR_ID_1 = "v1shunt"; private static final String SHUNT_COMPENSATOR_ID_2 = "v2shunt"; private static final String SHUNT_COMPENSATOR_ID_3 = "v3shunt"; @@ -38,7 +37,7 @@ public class ShuntCompensatorModificationByAssignmentTest extends AbstractModifi private static final String SHUNT_COMPENSATOR_ID_5 = "v5shunt"; @Test - public void testCreateWithWarning() throws Exception { + void testCreateWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes = getIdentifiableAttributes(SHUNT_COMPENSATOR_ID_1, 1.0); IdentifierListFilterEquipmentAttributes wrongIdAttributes = getIdentifiableAttributes("wrongId", 1.0); @@ -180,5 +179,4 @@ protected IdentifiableType getIdentifiableType() { protected EquipmentType getEquipmentType() { return EquipmentType.SHUNT_COMPENSATOR; } - } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java index 0b1cb2f14..ec5de4345 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/TwoWindingsTransformerModificationByAssignmentTest.java @@ -4,7 +4,6 @@ * 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.byfilter.assignment; import com.github.tomakehurst.wiremock.client.WireMock; @@ -19,19 +18,21 @@ import org.gridsuite.modification.server.dto.byfilter.assignment.DoubleAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.assignment.IntegerAssignmentInfos; import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import java.util.Date; import java.util.List; import java.util.UUID; import static org.gridsuite.modification.server.utils.NetworkUtil.createTwoWindingsTransformer; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Thang PHAM */ -public class TwoWindingsTransformerModificationByAssignmentTest extends AbstractModificationByAssignmentTest { +class TwoWindingsTransformerModificationByAssignmentTest extends AbstractModificationByAssignmentTest { private static final String TWT_ID_1 = "twt1"; private static final String TWT_ID_2 = "twt2"; private static final String TWT_ID_3 = "twt3"; @@ -40,7 +41,7 @@ public class TwoWindingsTransformerModificationByAssignmentTest extends Abstract private static final String TWT_ID_6 = "twt6"; @Test - public void testModifyTwtWithError() throws Exception { + void testModifyTwtWithError() throws Exception { // Test modifying ratio tab changer field when ratio tab changer is null IdentifierListFilterEquipmentAttributes identifiableAttributes1 = getIdentifiableAttributes(TWT_ID_4, 1.); IdentifierListFilterEquipmentAttributes identifiableAttributes2 = getIdentifiableAttributes(TWT_ID_6, 1.); @@ -73,7 +74,7 @@ public void testModifyTwtWithError() throws Exception { } @Test - public void testModifyTwtWithWarning() throws Exception { + void testModifyTwtWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes1 = getIdentifiableAttributes(TWT_ID_1, 1.); IdentifierListFilterEquipmentAttributes identifiableAttributes2 = getIdentifiableAttributes(TWT_ID_2, 1.); IdentifierListFilterEquipmentAttributes identifiableAttributes3 = getIdentifiableAttributes(TWT_ID_4, 1.); @@ -84,7 +85,7 @@ public void testModifyTwtWithWarning() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + ".{2,}")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(filterTwt1, filterTwt2))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); IntegerAssignmentInfos assignmentInfos = IntegerAssignmentInfos.builder() .filters(List.of(filter1, filter4)) @@ -476,7 +477,7 @@ protected void assertAfterNetworkModificationDeletion() { assertEquals(75, twt6.getG(), 0); } - private void addRatioTapChangerSteps(RatioTapChangerAdder ratioTapChangerAdder) { + private static void addRatioTapChangerSteps(RatioTapChangerAdder ratioTapChangerAdder) { ratioTapChangerAdder.beginStep() .setR(39.78473) .setX(39.784725) @@ -522,7 +523,7 @@ private void addRatioTapChangerSteps(RatioTapChangerAdder ratioTapChangerAdder) .add(); } - private void addPhaseTapChangerSteps(PhaseTapChangerAdder phaseTapChangerAdder) { + private static void addPhaseTapChangerSteps(PhaseTapChangerAdder phaseTapChangerAdder) { phaseTapChangerAdder.beginStep() .setR(39.78473) .setX(39.784725) diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/VoltageLevelModificationByAssignmentTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/VoltageLevelModificationByAssignmentTest.java index 4e105be3c..75286ee66 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/VoltageLevelModificationByAssignmentTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/assignment/VoltageLevelModificationByAssignmentTest.java @@ -4,7 +4,6 @@ * 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.byfilter.assignment; import com.powsybl.iidm.network.IdentifiableType; @@ -22,13 +21,13 @@ import java.util.Date; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Thang PHAM */ -public class VoltageLevelModificationByAssignmentTest extends AbstractModificationByAssignmentTest { +class VoltageLevelModificationByAssignmentTest extends AbstractModificationByAssignmentTest { private static final String VOLTAGE_LEVEL_ID_1 = "v1"; private static final String VOLTAGE_LEVEL_ID_2 = "v2"; private static final String VOLTAGE_LEVEL_ID_3 = "v3"; @@ -221,5 +220,4 @@ protected void assertAfterNetworkModificationDeletion() { assertEquals(100, identifiableShortCircuit6.getIpMin(), 0); assertEquals(200, identifiableShortCircuit6.getIpMax(), 0); } - } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/AbstractByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/AbstractByFormulaModificationTest.java index 355ed6f17..4deb04aa7 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/AbstractByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/AbstractByFormulaModificationTest.java @@ -4,7 +4,6 @@ * 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.byfilter.formula; import com.fasterxml.jackson.core.type.TypeReference; @@ -26,32 +25,28 @@ import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCollectionElementImpact; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.createCollectionElementImpact; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * @author Seddik Yengui */ - @Tag("IntegrationTest") -public abstract class AbstractByFormulaModificationTest extends AbstractNetworkModificationTest { +abstract class AbstractByFormulaModificationTest extends AbstractNetworkModificationTest { protected static final UUID FILTER_ID_1 = UUID.randomUUID(); protected static final UUID FILTER_ID_2 = UUID.randomUUID(); protected static final UUID FILTER_ID_3 = UUID.randomUUID(); @@ -68,17 +63,16 @@ public abstract class AbstractByFormulaModificationTest extends AbstractNetworkM protected final FilterInfos filter6 = new FilterInfos(FILTER_ID_6, "filter6"); protected final FilterInfos filterWithOneWrongId = new FilterInfos(FILTER_WITH_ONE_WRONG_ID, "filterWithOneWrongId"); - public static final String PATH = "/v1/filters/metadata"; + protected static final String PATH = "/v1/filters/metadata"; @Override protected void assertResultImpacts(List impacts) { assertThat(impacts).containsExactly(createCollectionElementImpact(getIdentifiableType())); } - @Before + @BeforeEach public void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); - getNetwork().getVariantManager().setWorkingVariant("variant_1"); createEquipments(); } @@ -115,7 +109,7 @@ protected void checkCreateWithWarning(List formulaInfos, List formulaInfos, List handleQueryParams(List filterIds) { + protected Map handleQueryParams(List filterIds) { return Map.of("ids", WireMock.matching(filterIds.stream().map(uuid -> ".+").collect(Collectors.joining(",")))); } - String getPath(boolean isRegexPath) { + protected String getPath(boolean isRegexPath) { if (isRegexPath) { return "/v1/filters/metadata\\?ids="; } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/BatteryByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/BatteryByFormulaModificationTest.java index 34eb4f325..de93e1c7a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/BatteryByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/BatteryByFormulaModificationTest.java @@ -4,7 +4,6 @@ * 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.byfilter.formula; import com.powsybl.iidm.network.IdentifiableType; @@ -14,24 +13,23 @@ import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.utils.EquipmentType; +import org.gridsuite.modification.server.dto.byfilter.equipmentfield.BatteryField; import org.gridsuite.modification.server.dto.byfilter.formula.FormulaInfos; import org.gridsuite.modification.server.dto.byfilter.formula.Operator; import org.gridsuite.modification.server.dto.byfilter.formula.ReferenceFieldOrValue; -import org.gridsuite.modification.server.dto.byfilter.equipmentfield.BatteryField; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.List; import static org.gridsuite.modification.server.utils.NetworkUtil.createBattery; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Seddik Yengui */ - -public class BatteryByFormulaModificationTest extends AbstractByFormulaModificationTest { +class BatteryByFormulaModificationTest extends AbstractByFormulaModificationTest { private static final String BATTERY_ID_1 = "v3Battery"; private static final String BATTERY_ID_2 = "battery2"; private static final String BATTERY_ID_3 = "battery3"; @@ -40,7 +38,7 @@ public class BatteryByFormulaModificationTest extends AbstractByFormulaModificat private static final String BATTERY_ID_6 = "battery6"; @Test - public void testCreateWithWarning() throws Exception { + void testCreateWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes = getIdentifiableAttributes(BATTERY_ID_1, 1.0); IdentifierListFilterEquipmentAttributes wrongIdAttributes = getIdentifiableAttributes("wrongId", 1.0); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/GeneratorByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/GeneratorByFormulaModificationTest.java index d841030bc..f946d1ff0 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/GeneratorByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/GeneratorByFormulaModificationTest.java @@ -4,45 +4,35 @@ * 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.byfilter.formula; import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.IdentifiableType; -import com.powsybl.iidm.network.extensions.ActivePowerControl; -import com.powsybl.iidm.network.extensions.ActivePowerControlAdder; -import com.powsybl.iidm.network.extensions.ConnectablePosition; -import com.powsybl.iidm.network.extensions.CoordinatedReactiveControl; -import com.powsybl.iidm.network.extensions.CoordinatedReactiveControlAdder; -import com.powsybl.iidm.network.extensions.GeneratorShortCircuit; -import com.powsybl.iidm.network.extensions.GeneratorShortCircuitAdder; -import com.powsybl.iidm.network.extensions.GeneratorStartup; -import com.powsybl.iidm.network.extensions.GeneratorStartupAdder; +import com.powsybl.iidm.network.extensions.*; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.dto.FilterInfos; +import org.gridsuite.modification.server.dto.byfilter.equipmentfield.GeneratorField; import org.gridsuite.modification.server.dto.byfilter.formula.FormulaInfos; import org.gridsuite.modification.server.dto.byfilter.formula.Operator; import org.gridsuite.modification.server.dto.byfilter.formula.ReferenceFieldOrValue; -import org.gridsuite.modification.server.dto.byfilter.equipmentfield.GeneratorField; -import org.junit.Test; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.List; import static org.gridsuite.modification.server.utils.NetworkUtil.createGenerator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Seddik Yengui */ - @Tag("IntegrationTest") -public class GeneratorByFormulaModificationTest extends AbstractByFormulaModificationTest { +class GeneratorByFormulaModificationTest extends AbstractByFormulaModificationTest { private static final String GENERATOR_ID_1 = "idGenerator"; private static final String GENERATOR_ID_2 = "v5generator"; private static final String GENERATOR_ID_3 = "v6generator"; @@ -55,7 +45,7 @@ public class GeneratorByFormulaModificationTest extends AbstractByFormulaModific private static final String GENERATOR_ID_10 = "gen10"; @Test - public void testCreateWithWarning() throws Exception { + void testCreateWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes = getIdentifiableAttributes(GENERATOR_ID_1, 1.0); IdentifierListFilterEquipmentAttributes wrongIdAttributes = getIdentifiableAttributes("wrongId", 1.0); @@ -72,7 +62,7 @@ public void testCreateWithWarning() throws Exception { } @Test - public void testWithNullReferenceFieldOrValue() throws Exception { + void testWithNullReferenceFieldOrValue() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes = getIdentifiableAttributes(GENERATOR_ID_1, 1.0); AbstractFilter filterEquipments = getFilterEquipments(FILTER_ID_1, List.of(identifiableAttributes)); @@ -151,6 +141,7 @@ protected void createEquipments() { getNetwork().getGenerator(GENERATOR_ID_10).setRatedS(30.); } + @Override protected List getTestFilters() { IdentifierListFilter filter1 = IdentifierListFilter.builder().id(FILTER_ID_1).modificationDate(new Date()).equipmentType(EquipmentType.GENERATOR) .filterEquipmentsAttributes(List.of(new IdentifierListFilterEquipmentAttributes(GENERATOR_ID_1, 1.0), diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/LoadByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/LoadByFormulaModificationTest.java index 47e333d41..1f766d4bf 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/LoadByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/LoadByFormulaModificationTest.java @@ -4,7 +4,6 @@ * 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.byfilter.formula; import com.powsybl.iidm.network.IdentifiableType; @@ -23,15 +22,14 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createSubstationImpacts; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.createSubstationImpacts; import static org.gridsuite.modification.server.utils.NetworkUtil.createLoad; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Seddik Yengui */ - -public class LoadByFormulaModificationTest extends AbstractByFormulaModificationTest { +class LoadByFormulaModificationTest extends AbstractByFormulaModificationTest { private static final String LOAD_ID_1 = "load1"; private static final String LOAD_ID_2 = "load2"; private static final String LOAD_ID_3 = "load3"; diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/ShuntCompensatorByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/ShuntCompensatorByFormulaModificationTest.java index 215c528b6..9711d71f4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/ShuntCompensatorByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/ShuntCompensatorByFormulaModificationTest.java @@ -4,7 +4,6 @@ * 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.byfilter.formula; import com.powsybl.iidm.network.IdentifiableType; @@ -15,19 +14,19 @@ import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.utils.EquipmentType; +import org.gridsuite.modification.server.dto.byfilter.equipmentfield.ShuntCompensatorField; import org.gridsuite.modification.server.dto.byfilter.formula.FormulaInfos; import org.gridsuite.modification.server.dto.byfilter.formula.Operator; import org.gridsuite.modification.server.dto.byfilter.formula.ReferenceFieldOrValue; -import org.gridsuite.modification.server.dto.byfilter.equipmentfield.ShuntCompensatorField; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.List; import static org.gridsuite.modification.server.utils.NetworkUtil.createShuntCompensator; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class ShuntCompensatorByFormulaModificationTest extends AbstractByFormulaModificationTest { +class ShuntCompensatorByFormulaModificationTest extends AbstractByFormulaModificationTest { private static final String SHUNT_COMPENSATOR_ID_1 = "v1shunt"; private static final String SHUNT_COMPENSATOR_ID_2 = "v2shunt"; private static final String SHUNT_COMPENSATOR_ID_3 = "v3shunt"; @@ -36,7 +35,7 @@ public class ShuntCompensatorByFormulaModificationTest extends AbstractByFormula private static final String SHUNT_COMPENSATOR_ID_6 = "v6shunt"; @Test - public void testCreateWithWarning() throws Exception { + void testCreateWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes = getIdentifiableAttributes(SHUNT_COMPENSATOR_ID_1, 1.0); IdentifierListFilterEquipmentAttributes wrongIdAttributes = getIdentifiableAttributes("wrongId", 1.0); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java index c6c1a84ec..bd2dd0865 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/TwoWindingsTransformerByFormulaModificationTest.java @@ -1,13 +1,7 @@ package org.gridsuite.modification.server.modifications.byfilter.formula; import com.github.tomakehurst.wiremock.client.WireMock; -import com.powsybl.iidm.network.IdentifiableType; -import com.powsybl.iidm.network.PhaseTapChanger; -import com.powsybl.iidm.network.PhaseTapChangerAdder; -import com.powsybl.iidm.network.RatioTapChanger; -import com.powsybl.iidm.network.RatioTapChangerAdder; -import com.powsybl.iidm.network.Substation; -import com.powsybl.iidm.network.TwoWindingsTransformer; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; @@ -15,22 +9,22 @@ import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.dto.ByFormulaModificationInfos; import org.gridsuite.modification.server.dto.NetworkModificationResult; +import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField; import org.gridsuite.modification.server.dto.byfilter.formula.FormulaInfos; import org.gridsuite.modification.server.dto.byfilter.formula.Operator; import org.gridsuite.modification.server.dto.byfilter.formula.ReferenceFieldOrValue; -import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import java.util.Date; import java.util.List; import java.util.UUID; import static org.gridsuite.modification.server.utils.NetworkUtil.createTwoWindingsTransformer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; -public class TwoWindingsTransformerByFormulaModificationTest extends AbstractByFormulaModificationTest { +class TwoWindingsTransformerByFormulaModificationTest extends AbstractByFormulaModificationTest { private static final String TWT_ID_1 = "twt1"; private static final String TWT_ID_2 = "twt2"; private static final String TWT_ID_3 = "twt3"; @@ -39,7 +33,7 @@ public class TwoWindingsTransformerByFormulaModificationTest extends AbstractByF private static final String TWT_ID_6 = "twt6"; @Test - public void testModifyTwtWithError() throws Exception { + void testModifyTwtWithError() throws Exception { // Test modifying ratio tab changer field when ratio tab changer is null IdentifierListFilterEquipmentAttributes identifiableAttributes1 = getIdentifiableAttributes(TWT_ID_4, 1.); IdentifierListFilterEquipmentAttributes identifiableAttributes2 = getIdentifiableAttributes(TWT_ID_6, 1.); @@ -76,7 +70,7 @@ public void testModifyTwtWithError() throws Exception { } @Test - public void testDivisionByZero() throws Exception { + void testDivisionByZero() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes1 = getIdentifiableAttributes(TWT_ID_4, 1.); IdentifierListFilterEquipmentAttributes identifiableAttributes2 = getIdentifiableAttributes(TWT_ID_6, 1.); AbstractFilter filter = getFilterEquipments(FILTER_ID_4, List.of(identifiableAttributes1, identifiableAttributes2)); @@ -84,7 +78,7 @@ public void testDivisionByZero() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching("/v1/filters/metadata\\?ids=" + FILTER_ID_4)) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(filter))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); // Test division by 0 FormulaInfos formulaInfos2 = FormulaInfos.builder() @@ -102,7 +96,7 @@ public void testDivisionByZero() throws Exception { } @Test - public void testModifyTwtWithWarning() throws Exception { + void testModifyTwtWithWarning() throws Exception { IdentifierListFilterEquipmentAttributes identifiableAttributes1 = getIdentifiableAttributes(TWT_ID_1, 1.); IdentifierListFilterEquipmentAttributes identifiableAttributes2 = getIdentifiableAttributes(TWT_ID_2, 1.); IdentifierListFilterEquipmentAttributes identifiableAttributes3 = getIdentifiableAttributes(TWT_ID_4, 1.); @@ -113,7 +107,7 @@ public void testModifyTwtWithWarning() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath(true) + ".{2,}")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(List.of(filterTwt1, filterTwt2))) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); FormulaInfos formulaInfos = FormulaInfos.builder() .filters(List.of(filter1, filter4)) @@ -504,7 +498,7 @@ protected void assertAfterNetworkModificationDeletion() { assertEquals(75, twt6.getG(), 0); } - private void addRatioTapChangerSteps(RatioTapChangerAdder ratioTapChangerAdder) { + private static void addRatioTapChangerSteps(RatioTapChangerAdder ratioTapChangerAdder) { ratioTapChangerAdder.beginStep() .setR(39.78473) .setX(39.784725) @@ -550,7 +544,7 @@ private void addRatioTapChangerSteps(RatioTapChangerAdder ratioTapChangerAdder) .add(); } - private void addPhaseTapChangerSteps(PhaseTapChangerAdder phaseTapChangerAdder) { + private static void addPhaseTapChangerSteps(PhaseTapChangerAdder phaseTapChangerAdder) { phaseTapChangerAdder.beginStep() .setR(39.78473) .setX(39.784725) diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/VoltageLevelByFormulaModificationTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/VoltageLevelByFormulaModificationTest.java index fd73c32fd..7d30794d0 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/VoltageLevelByFormulaModificationTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilter/formula/VoltageLevelByFormulaModificationTest.java @@ -4,7 +4,6 @@ * 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.byfilter.formula; import com.powsybl.iidm.network.IdentifiableType; @@ -27,13 +26,12 @@ import static org.gridsuite.modification.server.modifications.byfilter.AbstractModificationByAssignment.REPORT_KEY_BY_FILTER_MODIFICATION_SOME; import static org.gridsuite.modification.server.modifications.byfilter.ByFormulaModification.REPORT_KEY_EQUIPMENT_MODIFIED_ERROR; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessageWithoutRank; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Seddik Yengui */ - -public class VoltageLevelByFormulaModificationTest extends AbstractByFormulaModificationTest { +class VoltageLevelByFormulaModificationTest extends AbstractByFormulaModificationTest { private static final String VOLTAGE_LEVEL_ID_1 = "v1"; private static final String VOLTAGE_LEVEL_ID_2 = "v2"; private static final String VOLTAGE_LEVEL_ID_3 = "v3"; diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/AbstractByFilterDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/AbstractByFilterDeletionTest.java index 451795215..c5396ad6b 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/AbstractByFilterDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/AbstractByFilterDeletionTest.java @@ -4,14 +4,16 @@ import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.matching.StringValuePattern; import com.powsybl.iidm.network.IdentifiableType; -import lombok.SneakyThrows; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.modification.server.dto.*; +import org.gridsuite.modification.server.dto.ByFilterDeletionInfos; +import org.gridsuite.modification.server.dto.FilterInfos; +import org.gridsuite.modification.server.dto.ModificationInfos; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import java.util.Date; @@ -25,7 +27,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public abstract class AbstractByFilterDeletionTest extends AbstractNetworkModificationTest { +abstract class AbstractByFilterDeletionTest extends AbstractNetworkModificationTest { protected static final UUID FILTER_ID_1 = UUID.randomUUID(); protected static final UUID FILTER_ID_2 = UUID.randomUUID(); protected static final String EQUIPMENT_WRONG_ID_1 = "wrongId1"; @@ -38,7 +40,7 @@ public abstract class AbstractByFilterDeletionTest extends AbstractNetworkModifi protected abstract List getTestFilters(); - public static final String PATH = "/v1/filters/metadata"; + protected static final String PATH = "/v1/filters/metadata"; @Test @Override @@ -47,7 +49,7 @@ public void testCreate() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath() + "(.+,){1}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); super.testCreate(); @@ -55,7 +57,7 @@ public void testCreate() throws Exception { } @Test - public void testCreateWithErrors() throws Exception { + void testCreateWithErrors() throws Exception { var filter1 = FilterInfos.builder() .id(FILTER_ID_1) .name("filter1") @@ -75,7 +77,7 @@ public void testCreateWithErrors() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath() + "(.+){1}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(byFilterDeletionInfos)).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); @@ -92,7 +94,7 @@ public void testCopy() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath() + ".{2,}")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); super.testCopy(); @@ -100,7 +102,7 @@ public void testCopy() throws Exception { } @Test - public void testCreateAllFiltersWrong() throws Exception { + void testCreateAllFiltersWrong() throws Exception { var filter1 = FilterInfos.builder() .id(FILTER_ID_1) .name("filter1") @@ -118,7 +120,7 @@ public void testCreateAllFiltersWrong() throws Exception { UUID stubId = wireMockServer.stubFor(WireMock.get(WireMock.urlMatching(getPath() + "(.+){1}.*")) .willReturn(WireMock.ok() .withBody(mapper.writeValueAsString(filters)) - .withHeader("Content-Type", "application/json"))).getId(); + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(byFilterDeletionInfos)).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); @@ -169,16 +171,14 @@ protected ModificationInfos buildModificationUpdate() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BY_FILTER_DELETION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals(getIdentifiableType().name(), createdValues.get("equipmentType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals("BY_FILTER_DELETION", modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals(getIdentifiableType().name(), createdValues.get("equipmentType")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/EquipmentByFilterDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/EquipmentByFilterDeletionTest.java index 889bc7255..0f36d442c 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/EquipmentByFilterDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/EquipmentByFilterDeletionTest.java @@ -4,7 +4,6 @@ * 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.byfilterdeletion; import com.powsybl.iidm.network.IdentifiableType; @@ -16,28 +15,25 @@ import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import java.util.Date; import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; @Tag("IntegrationTest") -public class EquipmentByFilterDeletionTest extends AbstractByFilterDeletionTest { +class EquipmentByFilterDeletionTest extends AbstractByFilterDeletionTest { private static final String LOAD_ID_1 = "load1"; - private static final String LOAD_ID_2 = "load2"; - private static final String LOAD_ID_3 = "load3"; - private static final String LOAD_ID_4 = "load4"; - @Before - public void specificSetUp() { + @BeforeEach + void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); getNetwork().getVariantManager().setWorkingVariant("variant_1"); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/HvdcLineByFilterDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/HvdcLineByFilterDeletionTest.java index dd2736992..32cc7aa66 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/HvdcLineByFilterDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/HvdcLineByFilterDeletionTest.java @@ -14,22 +14,22 @@ import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import java.util.Date; import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; @Tag("IntegrationTest") -public class HvdcLineByFilterDeletionTest extends AbstractByFilterDeletionTest { +class HvdcLineByFilterDeletionTest extends AbstractByFilterDeletionTest { private static final String HVDC_LINE_ID_1 = "hvdcLine"; - @Before - public void specificSetUp() { + @BeforeEach + void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); getNetwork().getVariantManager().setWorkingVariant("variant_1"); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/SubstationByFilterDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/SubstationByFilterDeletionTest.java index 94389308a..9fb44b197 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/SubstationByFilterDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/SubstationByFilterDeletionTest.java @@ -14,26 +14,24 @@ import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import java.util.Date; import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; @Tag("IntegrationTest") -public class SubstationByFilterDeletionTest extends AbstractByFilterDeletionTest { +class SubstationByFilterDeletionTest extends AbstractByFilterDeletionTest { private static final String SUBSTATION_ID_1 = "s1"; - private static final String SUBSTATION_ID_2 = "s2"; - private static final String SUBSTATION_ID_3 = "s3"; - @Before - public void specificSetUp() { + @BeforeEach + void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); getNetwork().getVariantManager().setWorkingVariant("variant_1"); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/VoltageLevelByFilterDeletionTest.java b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/VoltageLevelByFilterDeletionTest.java index 3f9d85453..e3c1f1774 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/VoltageLevelByFilterDeletionTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/byfilterdeletion/VoltageLevelByFilterDeletionTest.java @@ -14,27 +14,25 @@ import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.modification.server.service.FilterService; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import java.util.Date; import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; @Tag("IntegrationTest") -public class VoltageLevelByFilterDeletionTest extends AbstractByFilterDeletionTest { +class VoltageLevelByFilterDeletionTest extends AbstractByFilterDeletionTest { private static final String VOLTAGE_LEVEL_ID_1 = "v1"; - private static final String VOLTAGE_LEVEL_ID_2 = "v2"; - private static final String VOLTAGE_LEVEL_ID_3 = "v3"; private static final String VOLTAGE_LEVEL_ID_4 = "v4"; - @Before - public void specificSetUp() { + @BeforeEach + void specificSetUp() { FilterService.setFilterServerBaseUri(wireMockServer.baseUrl()); getNetwork().getVariantManager().setWorkingVariant("variant_1"); } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularcreations/TabularGeneratorCreationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularcreations/TabularGeneratorCreationsTest.java index 3eb6548b8..0e56cca4c 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularcreations/TabularGeneratorCreationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularcreations/TabularGeneratorCreationsTest.java @@ -4,7 +4,6 @@ * 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.tabularcreations; import com.fasterxml.jackson.core.type.TypeReference; @@ -12,7 +11,6 @@ import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.ConnectablePosition; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.GeneratorCreationInfos; import org.gridsuite.modification.server.dto.ModificationInfos; @@ -20,9 +18,8 @@ import org.gridsuite.modification.server.impacts.AbstractBaseImpact; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import java.util.List; @@ -32,11 +29,9 @@ import static com.vladmihalcea.sql.SQLStatementCountValidator.assertSelectCount; import static com.vladmihalcea.sql.SQLStatementCountValidator.reset; import static org.assertj.core.api.Assertions.assertThat; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.createCollectionElementImpact; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCollectionElementImpact; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @@ -46,7 +41,7 @@ * @author Franck Lecuyer */ @Tag("IntegrationTest") -public class TabularGeneratorCreationsTest extends AbstractNetworkModificationTest { +class TabularGeneratorCreationsTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -175,7 +170,7 @@ protected void assertResultImpacts(List impacts) { } @Test - public void testCheckSqlRequestsCount() throws Exception { + void testCheckSqlRequestsCount() throws Exception { UUID modificationUuid = saveModification(buildModification()); reset(); @@ -220,7 +215,7 @@ public void testCheckSqlRequestsCount() throws Exception { } @Test - public void testAllModificationsHaveSucceeded() throws Exception { + void testAllModificationsHaveSucceeded() throws Exception { List creations = List.of( GeneratorCreationInfos.builder() .equipmentId("id1").equipmentName("name1").voltageLevelId("v1").busOrBusbarSectionId("1.1") @@ -258,7 +253,7 @@ public void testAllModificationsHaveSucceeded() throws Exception { } @Test - public void testAllModificationsHaveFailed() throws Exception { + void testAllModificationsHaveFailed() throws Exception { List creations = List.of( GeneratorCreationInfos.builder() .equipmentId("id1").equipmentName("name1").voltageLevelId("unknown_vl").busOrBusbarSectionId("1.1") @@ -307,18 +302,16 @@ public void testAllModificationsHaveFailed() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_CREATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.GENERATOR_CREATION.name(), createdValues.get("tabularCreationType")); + assertEquals(ModificationType.GENERATOR_CREATION.name(), createdValues.get("tabularCreationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_CREATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.GENERATOR_CREATION.name(), updatedValues.get("tabularCreationType")); + assertEquals(ModificationType.GENERATOR_CREATION.name(), updatedValues.get("tabularCreationType")); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularBatteryModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularBatteryModificationsTest.java index 3b4842761..28fb50411 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularBatteryModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularBatteryModificationsTest.java @@ -4,21 +4,14 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; -import org.gridsuite.modification.server.dto.AttributeModification; -import org.gridsuite.modification.server.dto.BatteryModificationInfos; -import org.gridsuite.modification.server.dto.ModificationInfos; -import org.gridsuite.modification.server.dto.OperationType; -import org.gridsuite.modification.server.dto.TabularModificationInfos; +import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import java.util.List; @@ -26,13 +19,13 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Franck Lecuyer */ @Tag("IntegrationTest") -public class TabularBatteryModificationsTest extends AbstractNetworkModificationTest { +class TabularBatteryModificationsTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -83,18 +76,16 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.BATTERY_MODIFICATION.name(), createdValues.get("tabularModificationType")); + assertEquals(ModificationType.BATTERY_MODIFICATION.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.BATTERY_MODIFICATION.name(), updatedValues.get("tabularModificationType")); + assertEquals(ModificationType.BATTERY_MODIFICATION.name(), updatedValues.get("tabularModificationType")); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java index 82a98cfce..236f4d9b0 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java @@ -4,12 +4,10 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; @@ -17,9 +15,8 @@ import org.gridsuite.modification.server.utils.ModificationCreation; import org.gridsuite.modification.server.utils.NetworkCreation; import org.gridsuite.modification.server.utils.TestUtils; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.testcontainers.shaded.org.apache.commons.lang3.tuple.Pair; @@ -35,7 +32,7 @@ import static com.vladmihalcea.sql.SQLStatementCountValidator.reset; import static org.assertj.core.api.Assertions.assertThat; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -43,7 +40,7 @@ * @author Etienne Homer */ @Tag("IntegrationTest") -public class TabularGeneratorModificationsTest extends AbstractNetworkModificationTest { +class TabularGeneratorModificationsTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -94,7 +91,7 @@ protected void assertAfterNetworkModificationDeletion() { } @Test - public void testSqlRequestsCountOnGetModification() throws Exception { + void testSqlRequestsCountOnGetModification() throws Exception { Pair tabularWith1Modification = createTabularGeneratorModification(1); reset(); ModificationInfos tabularWith1ModificationInfos = ApiUtils.getModification(mockMvc, tabularWith1Modification.getLeft()); // Getting one tabular modification with one sub-modification @@ -109,7 +106,7 @@ public void testSqlRequestsCountOnGetModification() throws Exception { } @Test - public void testSqlRequestsCountOnGetGroupModifications() throws Exception { + void testSqlRequestsCountOnGetGroupModifications() throws Exception { List> modifications = createFewTabularModifications(); reset(); @@ -150,24 +147,24 @@ public void testSqlRequestsCountOnGetGroupModifications() throws Exception { response time, it is a better optimization to start multiplying requests instead of entries in one request. */ @Test - public void testSqlRequestsCountOnPostGroups() throws Exception { + void testSqlRequestsCountOnPostGroups() throws Exception { List> modifications = createFewTabularModifications(); UUID targetGroupUuid = UUID.randomUUID(); reset(); ApiUtils.postGroups(mockMvc, getGroupId(), targetGroupUuid); - TestUtils.assertRequestsCount(9, 8, 2, 0); // (13, 8, 2, 0) before improvements + TestUtils.assertRequestsCount(10, 8, 1, 0); // (13, 8, 2, 0) before improvements assertTabularModificationsEquals(modifications, targetGroupUuid); } @Test - public void testSqlRequestsCountOnPostGroups2() throws Exception { + void testSqlRequestsCountOnPostGroups2() throws Exception { List> modifications = createMoreTabularModifications(); UUID targetGroupUuid = UUID.randomUUID(); reset(); ApiUtils.postGroups(mockMvc, getGroupId(), targetGroupUuid); - TestUtils.assertRequestsCount(15, 9, 2, 0); // (95, 9, 2, 0) before improvements, why one additional insert ? It feels batch_size is limited at 100 for insertions and is it reached for reactive_capability_curve_points + TestUtils.assertRequestsCount(16, 9, 1, 0); // (95, 9, 2, 0) before improvements, why one additional insert ? It feels batch_size is limited at 100 for insertions and is it reached for reactive_capability_curve_points assertTabularModificationsEquals(modifications, targetGroupUuid); } @@ -203,24 +200,24 @@ public void testSqlRequestsCountOnPostGroups2() throws Exception { response time, it is a better optimization to start multiplying requests instead of entries in one request. */ @Test - public void testSqlRequestsCountOnPutGroupsDuplications() throws Exception { + void testSqlRequestsCountOnPutGroupsDuplications() throws Exception { List> modifications = createFewTabularModifications(); UUID targetGroupUuid = UUID.randomUUID(); reset(); ApiUtils.putGroupsDuplications(mockMvc, getGroupId(), targetGroupUuid, getNetworkId()); - TestUtils.assertRequestsCount(9, 8, 2, 0); // (19, 8, 2, 0) before improvements + TestUtils.assertRequestsCount(10, 8, 1, 0); // (19, 8, 2, 0) before improvements assertTabularModificationsEquals(modifications, targetGroupUuid); } @Test - public void testSqlRequestsCountOnPutGroupsDuplications2() throws Exception { + void testSqlRequestsCountOnPutGroupsDuplications2() throws Exception { List> modifications = createMoreTabularModifications(); UUID targetGroupUuid = UUID.randomUUID(); reset(); ApiUtils.putGroupsDuplications(mockMvc, getGroupId(), targetGroupUuid, getNetworkId()); - TestUtils.assertRequestsCount(15, 9, 2, 0); // (107, 9, 2, 0) before improvements, why one additional insert ? It feels batch_size is limited at 100 for insertions and is it reached for reactive_capability_curve_points + TestUtils.assertRequestsCount(16, 9, 1, 0); // (107, 9, 2, 0) before improvements, why one additional insert ? It feels batch_size is limited at 100 for insertions and is it reached for reactive_capability_curve_points assertTabularModificationsEquals(modifications, targetGroupUuid); } @@ -255,24 +252,24 @@ public void testSqlRequestsCountOnPutGroupsDuplications2() throws Exception { response time, it is a better optimization to start multiplying requests instead of entries in one request. */ @Test - public void testSqlRequestsCountOnPutGroupsWithCopy() throws Exception { + void testSqlRequestsCountOnPutGroupsWithCopy() throws Exception { List> modifications = createFewTabularModifications(); UUID targetGroupUuid = UUID.randomUUID(); reset(); ApiUtils.putGroupsWithCopy(mockMvc, targetGroupUuid, modifications.stream().map(Pair::getLeft).toList(), getNetworkId()); - TestUtils.assertRequestsCount(8, 8, 2, 0); // (14, 8, 2, 0) before improvements + TestUtils.assertRequestsCount(9, 8, 1, 0); // (14, 8, 2, 0) before improvements assertTabularModificationsEquals(modifications, targetGroupUuid); } @Test - public void testSqlRequestsCountOnPutGroupsWithCopy2() throws Exception { + void testSqlRequestsCountOnPutGroupsWithCopy2() throws Exception { List> modifications = createMoreTabularModifications(); UUID targetGroupUuid = UUID.randomUUID(); reset(); ApiUtils.putGroupsWithCopy(mockMvc, targetGroupUuid, modifications.stream().map(Pair::getLeft).toList(), getNetworkId()); - TestUtils.assertRequestsCount(14, 9, 2, 0); // (26, 9, 2, 0) before improvements, why one additional insert ? It feels batch_size is limited at 100 for insertions and is it reached for reactive_capability_curve_points + TestUtils.assertRequestsCount(15, 9, 1, 0); // (26, 9, 2, 0) before improvements, why one additional insert ? It feels batch_size is limited at 100 for insertions and is it reached for reactive_capability_curve_points assertTabularModificationsEquals(modifications, targetGroupUuid); } @@ -305,7 +302,7 @@ public void testSqlRequestsCountOnPutGroupsWithCopy2() throws Exception { response time, it is a better optimization to start multiplying requests instead of entries in one request. */ @Test - public void testSqlRequestsCountOnPostNetworkModificationsDuplicate() throws Exception { + void testSqlRequestsCountOnPostNetworkModificationsDuplicate() throws Exception { List> modifications = createFewTabularModifications(); reset(); @@ -315,7 +312,7 @@ public void testSqlRequestsCountOnPostNetworkModificationsDuplicate() throws Exc } @Test - public void testSqlRequestsCountOnPostNetworkModificationsDuplicate2() throws Exception { + void testSqlRequestsCountOnPostNetworkModificationsDuplicate2() throws Exception { List> modifications = createMoreTabularModifications(); reset(); @@ -344,7 +341,7 @@ public void testSqlRequestsCountOnPostNetworkModificationsDuplicate2() throws Ex - 1 delete of the group */ @Test - public void testSqlRequestsCountOnDeleteGroup() throws Exception { + void testSqlRequestsCountOnDeleteGroup() throws Exception { createFewTabularModifications(); reset(); @@ -354,7 +351,7 @@ public void testSqlRequestsCountOnDeleteGroup() throws Exception { } @Test - public void testSqlRequestsCountOnDeleteGroup2() throws Exception { + void testSqlRequestsCountOnDeleteGroup2() throws Exception { createMoreTabularModifications(); reset(); @@ -381,7 +378,7 @@ public void testSqlRequestsCountOnDeleteGroup2() throws Exception { - delete modification for tabular modifications */ @Test - public void testSqlRequestsCountOnDeleteStashedInGroup() throws Exception { + void testSqlRequestsCountOnDeleteStashedInGroup() throws Exception { List> modifications = createFewTabularModifications(); ApiUtils.stashNetworkModifications(mockMvc, modifications.stream().map(Pair::getLeft).toList()); @@ -392,7 +389,7 @@ public void testSqlRequestsCountOnDeleteStashedInGroup() throws Exception { } @Test - public void testSqlRequestsCountOnDeleteStashedInGroup2() throws Exception { + void testSqlRequestsCountOnDeleteStashedInGroup2() throws Exception { List> modifications = createMoreTabularModifications(); ApiUtils.stashNetworkModifications(mockMvc, modifications.stream().map(Pair::getLeft).toList()); @@ -420,7 +417,7 @@ public void testSqlRequestsCountOnDeleteStashedInGroup2() throws Exception { - delete modification for tabular modifications */ @Test - public void testSqlRequestsCountOnDeleteNetworkModificationsInGroup() throws Exception { + void testSqlRequestsCountOnDeleteNetworkModificationsInGroup() throws Exception { createFewTabularModifications(); reset(); @@ -430,7 +427,7 @@ public void testSqlRequestsCountOnDeleteNetworkModificationsInGroup() throws Exc } @Test - public void testSqlRequestsCountOnDeleteNetworkModificationsInGroup2() throws Exception { + void testSqlRequestsCountOnDeleteNetworkModificationsInGroup2() throws Exception { createMoreTabularModifications(); reset(); @@ -458,23 +455,23 @@ public void testSqlRequestsCountOnDeleteNetworkModificationsInGroup2() throws Ex - delete modification for tabular modifications */ @Test - public void testSqlRequestsCountOnDeleteNetworkModificationsByIdsInGroup() throws Exception { + void testSqlRequestsCountOnDeleteNetworkModificationsByIdsInGroup() throws Exception { List> modifications = createFewTabularModifications(); reset(); ApiUtils.deleteNetworkModificationsInGroup(mockMvc, getGroupId(), List.of(modifications.get(0).getLeft())); // removing only 1 tabular modification in the group // It is actually (3, 0, 1, 7) because deletes made in the native query are not counted - TestUtils.assertRequestsCount(3, 0, 1, 0); + TestUtils.assertRequestsCount(3, 0, 0, 0); } @Test - public void testSqlRequestsCountOnDeleteNetworkModificationsByIdsInGroup2() throws Exception { + void testSqlRequestsCountOnDeleteNetworkModificationsByIdsInGroup2() throws Exception { List> modifications = createMoreTabularModifications(); reset(); ApiUtils.deleteNetworkModificationsInGroup(mockMvc, getGroupId(), modifications.subList(0, 3).stream().map(Pair::getLeft).toList()); // removing only 3 tabular modification in the group // It is actually (5, 0, 1, 21) because deletes made in the native query are not counted - TestUtils.assertRequestsCount(5, 0, 1, 0); + TestUtils.assertRequestsCount(5, 0, 0, 0); } /* @@ -495,7 +492,7 @@ public void testSqlRequestsCountOnDeleteNetworkModificationsByIdsInGroup2() thro */ @Test - public void testSqlRequestsCountOnDeleteNetworkModificationsByIds() throws Exception { + void testSqlRequestsCountOnDeleteNetworkModificationsByIds() throws Exception { List> modifications = createFewTabularModifications(); Map idsMapping = ApiUtils.postNetworkModificationsDuplicate(mockMvc, modifications.stream().map(Pair::getLeft).toList()); @@ -506,7 +503,7 @@ public void testSqlRequestsCountOnDeleteNetworkModificationsByIds() throws Excep } @Test - public void testSqlRequestsCountOnDeleteNetworkModificationsByIds2() throws Exception { + void testSqlRequestsCountOnDeleteNetworkModificationsByIds2() throws Exception { List> modifications = createMoreTabularModifications(); Map idsMapping = ApiUtils.postNetworkModificationsDuplicate(mockMvc, modifications.stream().map(Pair::getLeft).toList()); @@ -517,7 +514,7 @@ public void testSqlRequestsCountOnDeleteNetworkModificationsByIds2() throws Exce } @Test - public void testAllModificationsHaveFailed() throws Exception { + void testAllModificationsHaveFailed() throws Exception { List modifications = List.of( GeneratorModificationInfos.builder().equipmentId("idGenerator").maxP(new AttributeModification<>(-300., OperationType.SET)).build(), GeneratorModificationInfos.builder().equipmentId("v5generator").maxP(new AttributeModification<>(-300., OperationType.SET)).build(), @@ -536,19 +533,17 @@ public void testAllModificationsHaveFailed() throws Exception { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.GENERATOR_MODIFICATION.name(), createdValues.get("tabularModificationType")); + assertEquals(ModificationType.GENERATOR_MODIFICATION.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.GENERATOR_MODIFICATION.name(), updatedValues.get("tabularModificationType")); + assertEquals(ModificationType.GENERATOR_MODIFICATION.name(), updatedValues.get("tabularModificationType")); } private List> createFewTabularModifications() { @@ -577,7 +572,7 @@ private Pair createTabularGeneratorModification(int qty return Pair.of(uuid, tabularModification); } - private List createGeneratorModificationList(int qty) { + private static List createGeneratorModificationList(int qty) { return IntStream.range(0, qty) .mapToObj(i -> (ModificationInfos) GeneratorModificationInfos.builder() @@ -621,14 +616,14 @@ private void assertTabularModificationsEquals(List assertTabularModificationsEquals(sourceModifications, targetModifications); } - private void assertTabularModificationsEquals(List expectedModifications, List modificationInfos) { + private static void assertTabularModificationsEquals(List expectedModifications, List modificationInfos) { assertThat(expectedModifications) .usingRecursiveComparison() .ignoringFields("uuid", "date", "modifications.uuid", "modifications.date") .isEqualTo(modificationInfos); } - private void assertTabularModificationsEquals(ModificationInfos expectedModificationInfos, ModificationInfos modificationInfos) { + private static void assertTabularModificationsEquals(ModificationInfos expectedModificationInfos, ModificationInfos modificationInfos) { assertThat(expectedModificationInfos) .usingRecursiveComparison() .ignoringFields("uuid", "date", "modifications.uuid", "modifications.date") diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLineModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLineModificationsTest.java index 224a60fc6..736d58850 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLineModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLineModificationsTest.java @@ -4,17 +4,14 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import java.util.List; @@ -22,13 +19,13 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Anis Touri */ @Tag("IntegrationTest") -public class TabularLineModificationsTest extends AbstractNetworkModificationTest { +class TabularLineModificationsTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -83,18 +80,16 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.LINE_MODIFICATION.name(), createdValues.get("tabularModificationType")); + assertEquals(ModificationType.LINE_MODIFICATION.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.LINE_MODIFICATION.name(), updatedValues.get("tabularModificationType")); + assertEquals(ModificationType.LINE_MODIFICATION.name(), updatedValues.get("tabularModificationType")); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLoadModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLoadModificationsTest.java index 850c72cef..023c581a4 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLoadModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularLoadModificationsTest.java @@ -4,30 +4,27 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import java.util.List; import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Etienne Homer */ @Tag("IntegrationTest") -public class TabularLoadModificationsTest extends AbstractNetworkModificationTest { +class TabularLoadModificationsTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -76,18 +73,16 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.LOAD_MODIFICATION.name(), createdValues.get("tabularModificationType")); + assertEquals(ModificationType.LOAD_MODIFICATION.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.LOAD_MODIFICATION.name(), updatedValues.get("tabularModificationType")); + assertEquals(ModificationType.LOAD_MODIFICATION.name(), updatedValues.get("tabularModificationType")); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularShuntCompensatorModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularShuntCompensatorModificationsTest.java index fb331990b..6abd6fb64 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularShuntCompensatorModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularShuntCompensatorModificationsTest.java @@ -4,7 +4,6 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; @@ -14,14 +13,8 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.ShuntCompensator; import com.powsybl.iidm.network.ShuntCompensatorModelType; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; -import org.gridsuite.modification.server.dto.AttributeModification; -import org.gridsuite.modification.server.dto.ModificationInfos; -import org.gridsuite.modification.server.dto.OperationType; -import org.gridsuite.modification.server.dto.ShuntCompensatorModificationInfos; -import org.gridsuite.modification.server.dto.ShuntCompensatorType; -import org.gridsuite.modification.server.dto.TabularModificationInfos; +import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.modifications.TabularModification; import org.gridsuite.modification.server.utils.NetworkCreation; @@ -34,7 +27,7 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; /** @@ -97,16 +90,14 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals(ModificationType.SHUNT_COMPENSATOR_MODIFICATION.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); assertEquals(ModificationType.SHUNT_COMPENSATOR_MODIFICATION.name(), updatedValues.get("tabularModificationType")); diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularSubstationModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularSubstationModificationsTest.java index e7776a720..625edf7d2 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularSubstationModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularSubstationModificationsTest.java @@ -4,31 +4,28 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Country; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import java.util.List; import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author AJELLAL Ali */ @Tag("IntegrationTest") -public class TabularSubstationModificationsTest extends AbstractNetworkModificationTest { +class TabularSubstationModificationsTest extends AbstractNetworkModificationTest { public static final ModificationType MOFIFICATION_TYPE = ModificationType.SUBSTATION_MODIFICATION; @Override @@ -80,18 +77,16 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(MOFIFICATION_TYPE.name(), createdValues.get("tabularModificationType")); + assertEquals(MOFIFICATION_TYPE.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(MOFIFICATION_TYPE.name(), updatedValues.get("tabularModificationType")); + assertEquals(MOFIFICATION_TYPE.name(), updatedValues.get("tabularModificationType")); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularTwoWindingsTransformerModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularTwoWindingsTransformerModificationsTest.java index d99eecf67..31215d3bf 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularTwoWindingsTransformerModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularTwoWindingsTransformerModificationsTest.java @@ -4,17 +4,14 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import java.util.List; @@ -22,13 +19,13 @@ import java.util.UUID; import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Florent MILLOT */ @Tag("IntegrationTest") -public class TabularTwoWindingsTransformerModificationsTest extends AbstractNetworkModificationTest { +class TabularTwoWindingsTransformerModificationsTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -81,18 +78,16 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.TWO_WINDINGS_TRANSFORMER_MODIFICATION.name(), createdValues.get("tabularModificationType")); + assertEquals(ModificationType.TWO_WINDINGS_TRANSFORMER_MODIFICATION.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.TWO_WINDINGS_TRANSFORMER_MODIFICATION.name(), updatedValues.get("tabularModificationType")); + assertEquals(ModificationType.TWO_WINDINGS_TRANSFORMER_MODIFICATION.name(), updatedValues.get("tabularModificationType")); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularVoltageLevelModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularVoltageLevelModificationsTest.java index bfe1d553e..d54ef4152 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularVoltageLevelModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularVoltageLevelModificationsTest.java @@ -4,30 +4,27 @@ * 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.tabularmodifications; import com.fasterxml.jackson.core.type.TypeReference; import com.powsybl.iidm.network.Network; -import lombok.SneakyThrows; import org.gridsuite.modification.server.ModificationType; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import java.util.List; import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author AJELLAL Ali */ @Tag("IntegrationTest") -public class TabularVoltageLevelModificationsTest extends AbstractNetworkModificationTest { +class TabularVoltageLevelModificationsTest extends AbstractNetworkModificationTest { @Override protected Network createNetwork(UUID networkUuid) { return NetworkCreation.create(networkUuid, true); @@ -80,18 +77,16 @@ protected void assertAfterNetworkModificationDeletion() { } @Override - @SneakyThrows - protected void testCreationModificationMessage(ModificationInfos modificationInfos) { + protected void testCreationModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map createdValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.VOLTAGE_LEVEL_MODIFICATION.name(), createdValues.get("tabularModificationType")); + assertEquals(ModificationType.VOLTAGE_LEVEL_MODIFICATION.name(), createdValues.get("tabularModificationType")); } @Override - @SneakyThrows - protected void testUpdateModificationMessage(ModificationInfos modificationInfos) { + protected void testUpdateModificationMessage(ModificationInfos modificationInfos) throws Exception { assertEquals(ModificationType.TABULAR_MODIFICATION.name(), modificationInfos.getMessageType()); Map updatedValues = mapper.readValue(modificationInfos.getMessageValues(), new TypeReference<>() { }); - Assertions.assertEquals(ModificationType.VOLTAGE_LEVEL_MODIFICATION.name(), updatedValues.get("tabularModificationType")); + assertEquals(ModificationType.VOLTAGE_LEVEL_MODIFICATION.name(), updatedValues.get("tabularModificationType")); } } diff --git a/src/test/java/org/gridsuite/modification/server/service/BuildTest.java b/src/test/java/org/gridsuite/modification/server/service/BuildTest.java index fac2cd64f..5221a4653 100644 --- a/src/test/java/org/gridsuite/modification/server/service/BuildTest.java +++ b/src/test/java/org/gridsuite/modification/server/service/BuildTest.java @@ -14,11 +14,12 @@ import com.powsybl.iidm.network.extensions.*; import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; +import mockwebserver3.Dispatcher; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; +import mockwebserver3.junit5.internal.MockWebServerExtension; import okhttp3.HttpUrl; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; import org.apache.commons.lang3.tuple.Pair; import org.gridsuite.modification.server.ContextConfigurationWithTestChannel; import org.gridsuite.modification.server.TapChangerType; @@ -38,11 +39,11 @@ import org.gridsuite.modification.server.utils.TestUtils; import org.gridsuite.modification.server.utils.assertions.Assertions; import org.jetbrains.annotations.NotNull; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +57,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.messaging.Message; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import java.io.IOException; @@ -64,13 +64,12 @@ import java.util.concurrent.*; import static com.powsybl.iidm.network.ReactiveLimitsKind.MIN_MAX; -import static org.gridsuite.modification.server.Impacts.TestImpactUtils.*; +import static org.gridsuite.modification.server.impacts.TestImpactUtils.*; import static org.gridsuite.modification.server.service.BuildWorkerService.CANCEL_MESSAGE; import static org.gridsuite.modification.server.service.BuildWorkerService.FAIL_MESSAGE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -81,12 +80,12 @@ /** * @author Franck Lecuyer */ -@RunWith(SpringRunner.class) +@ExtendWith(MockWebServerExtension.class) @AutoConfigureMockMvc @SpringBootTest @ContextConfigurationWithTestChannel @Tag("IntegrationTest") -public class BuildTest { +class BuildTest { private static final Logger LOGGER = LoggerFactory.getLogger(BuildTest.class); @Autowired @@ -132,7 +131,7 @@ public class BuildTest { private NetworkStoreService networkStoreService; @Autowired - ModificationGroupRepository modificationGroupRepository; + private ModificationGroupRepository modificationGroupRepository; @Autowired private NetworkModificationRepository modificationRepository; @@ -161,10 +160,8 @@ public class BuildTest { private Network network; - private MockWebServer server; - - @Before - public void setUp() throws IOException { + @BeforeEach + public void setUp(final MockWebServer mockWebServer) { objectWriter = mapper.writer().withDefaultPrettyPrinter(); // create a new network for each invocation (answer) when(networkStoreService.getNetwork(eq(TEST_NETWORK_ID), any(PreloadingStrategy.class))).then((Answer) invocation -> { @@ -183,20 +180,16 @@ public void setUp() throws IOException { return network; }); - cleanDB(); - - initMockWebServer(); + initMockWebServer(mockWebServer); } - private void cleanDB() { + @AfterEach + void cleanDB() { modificationRepository.deleteAll(); equipmentInfosService.deleteVariants(TEST_NETWORK_ID, List.of(VariantManagerConstants.INITIAL_VARIANT_ID, NetworkCreation.VARIANT_ID, VARIANT_ID_2)); } - private void initMockWebServer() throws IOException { - server = new MockWebServer(); - server.start(); - + private void initMockWebServer(final MockWebServer server) { // Ask the server for its URL. You'll need this to make HTTP requests. HttpUrl baseHttpUrl = server.url(""); String baseUrl = baseHttpUrl.toString().substring(0, baseHttpUrl.toString().length() - 1); @@ -210,21 +203,20 @@ public MockResponse dispatch(RecordedRequest request) { if (path.matches("/v1/reports/.*") && Objects.equals(request.getMethod(), HttpMethod.PUT.name())) { String reportUuid = Objects.requireNonNull(request.getRequestUrl()).pathSegments().get(2); if (TEST_ERROR_REPORT_ID.toString().equals(reportUuid)) { - return new MockResponse().setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value()); + return new MockResponse(HttpStatus.INTERNAL_SERVER_ERROR.value()); } - return new MockResponse().setResponseCode(HttpStatus.OK.value()); + return new MockResponse(HttpStatus.OK.value()); } else { LOGGER.error("Unhandled method+path: " + request.getMethod() + " " + request.getPath()); - return new MockResponse().setResponseCode(HttpStatus.I_AM_A_TEAPOT.value()).setBody("Unhandled method+path: " + request.getMethod() + " " + request.getPath()); + return new MockResponse.Builder().code(HttpStatus.I_AM_A_TEAPOT.value()).body("Unhandled method+path: " + request.getMethod() + " " + request.getPath()).build(); } } }; - server.setDispatcher(dispatcher); } @Test - public void runBuildForLineSplits() throws Exception { + void runBuildForLineSplits(final MockWebServer server) throws Exception { List entities1 = List.of( LineCreationInfos.builder() .equipmentId("newLine") @@ -314,7 +306,7 @@ public void runBuildForLineSplits() throws Exception { } @Test - public void runBuildWithEmptyGroupTest() throws Exception { + void runBuildWithEmptyGroupTest(final MockWebServer server) throws Exception { Network network = NetworkCreation.create(TEST_NETWORK_ID, false); BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID, NetworkCreation.VARIANT_ID, @@ -344,7 +336,7 @@ public void runBuildWithEmptyGroupTest() throws Exception { } @Test - public void testIndexationAfterBuild() throws Exception { + void testIndexationAfterBuild(final MockWebServer server) { List equipmentsToAdd = new ArrayList<>(); // add new voltage level equipmentsToAdd.add(VoltageLevelCreationInfos.builder() @@ -494,7 +486,7 @@ public void testIndexationAfterBuild() throws Exception { } @Test - public void runBuildTest() throws Exception { + void runBuildTest(final MockWebServer server) throws Exception { // create modification entities in the database List entities1 = new ArrayList<>(); entities1.add(EquipmentAttributeModificationInfos.builder().equipmentId("v1d1").equipmentAttributeName("open").equipmentAttributeValue(true).equipmentType(IdentifiableType.SWITCH).build().toEntity()); @@ -825,7 +817,7 @@ public void runBuildTest() throws Exception { } @Test - public void runBuildWithStashedModificationsTest() throws Exception { + void runBuildWithStashedModificationsTest(final MockWebServer server) { // create modification entities in the database List entities1 = new ArrayList<>(); entities1.add(EquipmentAttributeModificationInfos.builder().equipmentId("v1d1").equipmentAttributeName("open").equipmentAttributeValue(true).equipmentType(IdentifiableType.SWITCH).build().toEntity()); @@ -849,7 +841,7 @@ public void runBuildWithStashedModificationsTest() throws Exception { } @Test - public void stopBuildTest() throws Exception { + void stopBuildTest() throws Exception { List entities = List.of( EquipmentAttributeModificationInfos.builder().equipmentId("v1d1").equipmentAttributeName("open").equipmentAttributeValue(true).equipmentType(IdentifiableType.SWITCH).build().toEntity(), EquipmentAttributeModificationInfos.builder().equipmentId("line1").equipmentAttributeName("operatingStatus").equipmentAttributeValue(OperatingStatus.Status.PLANNED_OUTAGE).equipmentType(IdentifiableType.LINE).build().toEntity() @@ -872,7 +864,7 @@ public void stopBuildTest() throws Exception { .content(buildInfosJson)) .andExpect(status().isOk()); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("mock mvc perform error", e); } }, executorService); @@ -893,7 +885,7 @@ public void stopBuildTest() throws Exception { } @Test - public void runBuildWithReportErrorTest() throws Exception { + void runBuildWithReportErrorTest(final MockWebServer server) throws Exception { modificationRepository.saveModifications(TEST_GROUP_ID, List.of(EquipmentAttributeModificationInfos.builder().equipmentId("v1d1").equipmentAttributeName("open").equipmentAttributeValue(true).equipmentType(IdentifiableType.SWITCH).build().toEntity())); // build VARIANT_ID by cloning network initial variant and applying all modifications in all groups @@ -919,7 +911,7 @@ public void runBuildWithReportErrorTest() throws Exception { } @Test - public void testApplyModificationWithErrors() { + void testApplyModificationWithErrors(final MockWebServer server) { Network network = NetworkCreation.create(TEST_NETWORK_ID, true); LoadCreationInfos loadCreationInfos = LoadCreationInfos.builder().voltageLevelId("unknownVoltageLevelId").equipmentId("loadId").build(); UUID groupUuid = UUID.randomUUID(); @@ -946,7 +938,7 @@ public void testApplyModificationWithErrors() { } @Test - public void testLastGroupModificationStatus() { + void testLastGroupModificationStatus(final MockWebServer server) { Network network = NetworkCreation.create(TEST_NETWORK_ID, true); LoadCreationInfos loadCreationInfos = LoadCreationInfos.builder().voltageLevelId("unknownVoltageLevelId").equipmentId("loadId").build(); UUID reportUuid = UUID.randomUUID(); @@ -968,8 +960,8 @@ private void testNetworkModificationsCount(UUID groupUuid, int actualSize) { assertEquals(actualSize, modificationRepository.getModifications(groupUuid, true, true).size()); } - @After - public void tearDown() { + @AfterEach + void tearDown(final MockWebServer server) { List destinations = List.of(consumeBuildDestination, cancelBuildDestination, buildResultDestination, buildStoppedDestination, buildFailedDestination); TestUtils.assertQueuesEmptyThenClear(destinations, output); try { diff --git a/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java b/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java index 9f4c51f2d..a62bbb4b1 100644 --- a/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java +++ b/src/test/java/org/gridsuite/modification/server/service/EquipmentInfosServiceTests.java @@ -20,28 +20,25 @@ import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService; import org.gridsuite.modification.server.elasticsearch.TombstonedEquipmentInfosRepository; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Tag; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import java.util.List; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Slimane Amar */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @Tag("IntegrationTest") -public class EquipmentInfosServiceTests { +class EquipmentInfosServiceTests { private static final UUID NETWORK_UUID = UUID.randomUUID(); @@ -63,7 +60,7 @@ private boolean existEquipmentInfos(String equipmentId, UUID networkUuid, String } @Test - public void testAddDeleteEquipmentInfos() { + void testAddDeleteEquipmentInfos() { EquipmentInfos equipmentInfos = EquipmentInfos.builder() .networkUuid(NETWORK_UUID) .id("id1") @@ -186,7 +183,7 @@ public void testAddDeleteEquipmentInfos() { } @Test - public void testCloneVariant() { + void testCloneVariant() { equipmentInfosService.addAllEquipmentInfos(List.of(EquipmentInfos.builder().networkUuid(NETWORK_UUID).id("id1").name("name1").type(IdentifiableType.LOAD.name()).variantId(VARIANT_NAME_1).voltageLevels(Set.of(VoltageLevelInfos.builder().id("vl1").name("vl1").build())).substations(Set.of(SubstationInfos.builder().id("s1").name("s1").build())).build())); assertEquals(1, equipmentInfosRepository.findAllByNetworkUuidAndVariantId(NETWORK_UUID, VARIANT_NAME_1).size()); @@ -199,7 +196,7 @@ public void testCloneVariant() { } @Test - public void testDeleteVariants() { + void testDeleteVariants() { equipmentInfosService.addAllEquipmentInfos(List.of(EquipmentInfos.builder().networkUuid(NETWORK_UUID).id("id1").name("name1").type(IdentifiableType.LOAD.name()).variantId(VARIANT_NAME_1).voltageLevels(Set.of(VoltageLevelInfos.builder().id("vl1").name("vl1").build())).substations(Set.of(SubstationInfos.builder().id("s1").name("s1").build())).build())); assertEquals(1, equipmentInfosRepository.findAllByNetworkUuidAndVariantId(NETWORK_UUID, VARIANT_NAME_1).size()); @@ -221,7 +218,7 @@ public void testDeleteVariants() { } @Test - public void testVoltageLevels() { + void testVoltageLevels() { Network network = NetworkCreation.create(NETWORK_UUID, true); assertEquals(Set.of(VoltageLevelInfos.builder().id("v1").name("v1").build(), VoltageLevelInfos.builder().id("v2").name("v2").build(), VoltageLevelInfos.builder().id("v4").name("v4").build()), EquipmentInfos.getVoltageLevelsInfos(network.getSubstation("s1"))); assertEquals(Set.of(VoltageLevelInfos.builder().id("v1").name("v1").build()), EquipmentInfos.getVoltageLevelsInfos(network.getVoltageLevel("v1"))); @@ -240,7 +237,7 @@ public void testVoltageLevels() { } @Test - public void testSubstations() { + void testSubstations() { Network network = NetworkCreation.create(NETWORK_UUID, true); assertEquals(Set.of(SubstationInfos.builder().id("s1").name("s1").build()), EquipmentInfos.getSubstationsInfos(network.getSubstation("s1"))); assertEquals(Set.of(SubstationInfos.builder().id("s1").name("s1").build()), EquipmentInfos.getSubstationsInfos(network.getVoltageLevel("v1"))); @@ -259,7 +256,7 @@ public void testSubstations() { } @Test - public void testBadType() { + void testBadType() { Identifiable network = new NetworkFactoryImpl().createNetwork("test", "test"); String errorMessage = assertThrows(NetworkModificationException.class, () -> EquipmentInfos.getVoltageLevelsInfos(network)).getMessage(); @@ -272,7 +269,7 @@ public void testBadType() { assertTrue(errorMessage.contains(String.format("The equipment type : %s is unknown", NetworkImpl.class.getSimpleName()))); } - @After + @AfterEach public void tearDown() { equipmentInfosService.deleteVariants(NETWORK_UUID, List.of(VARIANT_NAME_1, VARIANT_NAME_2, VARIANT_NAME_3)); } diff --git a/src/test/java/org/gridsuite/modification/server/service/ModificationElasticsearchTest.java b/src/test/java/org/gridsuite/modification/server/service/ModificationElasticsearchTest.java index 3c26963d1..1cdffbc16 100644 --- a/src/test/java/org/gridsuite/modification/server/service/ModificationElasticsearchTest.java +++ b/src/test/java/org/gridsuite/modification/server/service/ModificationElasticsearchTest.java @@ -14,34 +14,33 @@ import org.gridsuite.modification.server.repositories.ModificationRepository; import org.gridsuite.modification.server.utils.ModificationCreation; import org.gridsuite.modification.server.utils.NetworkCreation; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import java.util.List; import java.util.UUID; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringRunner.class) @AutoConfigureMockMvc @SpringBootTest @Tag("IntegrationTest") -public class ModificationElasticsearchTest { - private static UUID NETWORK_UUID = UUID.randomUUID(); +class ModificationElasticsearchTest { + private static final UUID NETWORK_UUID = UUID.randomUUID(); private static final UUID TEST_GROUP_ID = UUID.randomUUID(); private static final UUID TEST_REPORT_ID = UUID.randomUUID(); private static final String URI_NETWORK_MODIF_BASE = "/v1/network-modifications"; @@ -52,22 +51,22 @@ public class ModificationElasticsearchTest { private static final String NEW_VARIANT_2 = "NewVariant2"; @Autowired - MockMvc mockMvc; + private MockMvc mockMvc; @Autowired private ObjectMapper mapper; @Autowired - EquipmentInfosService equipmentInfosService; + private EquipmentInfosService equipmentInfosService; @Autowired - ModificationRepository modificationRepository; + private ModificationRepository modificationRepository; @MockBean - NetworkStoreService networkStoreService; + private NetworkStoreService networkStoreService; @MockBean - ReportService reportService; + private ReportService reportService; @Autowired private EquipmentInfosRepository equipmentInfosRepository; @@ -75,9 +74,9 @@ public class ModificationElasticsearchTest { @Autowired private TombstonedEquipmentInfosRepository tombstonedEquipmentInfosRepository; - Network network; + private Network network; - @Before + @BeforeEach public void setUp() { network = NetworkCreation.create(NETWORK_UUID, true); when(networkStoreService.getNetwork(eq(NETWORK_UUID), nullable(PreloadingStrategy.class))).then((Answer) invocation -> network); @@ -88,7 +87,7 @@ public void setUp() { } @Test - public void testModificationsToImpactElasticsearch() throws Exception { + void testModificationsToImpactElasticsearch() throws Exception { network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, NEW_VARIANT); network.getVariantManager().setWorkingVariant(NEW_VARIANT); @@ -107,7 +106,7 @@ public void testModificationsToImpactElasticsearch() throws Exception { } @Test - public void testModifyGenThenDeleteVl() throws Exception { + void testModifyGenThenDeleteVl() throws Exception { network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, NEW_VARIANT); network.getVariantManager().setWorkingVariant(NEW_VARIANT); @@ -131,7 +130,7 @@ public void testModifyGenThenDeleteVl() throws Exception { } @Test - public void testVLModificationsToImpactElasticsearch() throws Exception { + void testVLModificationsToImpactElasticsearch() throws Exception { network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, NEW_VARIANT); network.getVariantManager().setWorkingVariant(NEW_VARIANT); diff --git a/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java b/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java index 643898006..b490b6998 100644 --- a/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java +++ b/src/test/java/org/gridsuite/modification/server/service/ModificationRepositoryTest.java @@ -24,35 +24,30 @@ import org.gridsuite.modification.server.repositories.ModificationRepository; import org.gridsuite.modification.server.repositories.NetworkModificationRepository; import org.gridsuite.modification.server.utils.elasticsearch.DisableElasticsearch; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import java.util.*; import java.util.stream.Collectors; import static com.powsybl.iidm.network.StaticVarCompensator.RegulationMode.VOLTAGE; -import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFICATION_GROUP_NOT_FOUND; -import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFICATION_NOT_FOUND; -import static org.gridsuite.modification.server.NetworkModificationException.Type.MOVE_MODIFICATION_ERROR; +import static org.gridsuite.modification.server.NetworkModificationException.Type.*; import static org.gridsuite.modification.server.dto.VoltageRegulationType.DISTANT; import static org.gridsuite.modification.server.utils.TestUtils.assertRequestsCount; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; -import static org.junit.Assert.*; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Slimane Amar */ -@RunWith(SpringRunner.class) @SpringBootTest @DisableElasticsearch @Tag("IntegrationTest") -public class ModificationRepositoryTest { +class ModificationRepositoryTest { private static final UUID TEST_GROUP_ID = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); private static final UUID TEST_GROUP_ID_2 = UUID.fromString("5809dabf-60f8-46e5-9e58-57b03d6b1818"); private static final UUID TEST_GROUP_ID_3 = UUID.fromString("de67bab1-f47b-4199-80a7-10bd77285675"); @@ -66,14 +61,14 @@ public class ModificationRepositoryTest { @Autowired private ModificationRepository modificationRepository; - @Before - public void setUp() { + @BeforeEach + void setUp() { modificationRepository.deleteAll(); modificationGroupRepository.deleteAll(); SQLStatementCountValidator.reset(); } - public EquipmentAttributeModificationInfos getEquipmentAttributeModification(UUID modificationUuid) { + private EquipmentAttributeModificationInfos getEquipmentAttributeModification(UUID modificationUuid) { return (EquipmentAttributeModificationInfos) networkModificationRepository.getModificationInfo(modificationUuid); } @@ -97,11 +92,11 @@ private VoltageLevelCreationInfos getVoltageLevelCreationModification(UUID modif return (VoltageLevelCreationInfos) networkModificationRepository.getModificationInfo(modificationUuid); } - public GroovyScriptInfos getGroovyScript(UUID modificationUuid) { + private GroovyScriptInfos getGroovyScript(UUID modificationUuid) { return (GroovyScriptInfos) networkModificationRepository.getModificationInfo(modificationUuid); } - public ShuntCompensatorCreationInfos getShuntCompensatorCreationModification(UUID modificationUuid) { + private ShuntCompensatorCreationInfos getShuntCompensatorCreationModification(UUID modificationUuid) { return (ShuntCompensatorCreationInfos) networkModificationRepository.getModificationInfo(modificationUuid); } @@ -130,11 +125,10 @@ private VoltageInitModificationInfos getVoltageInitModification(UUID modificatio } @Test - public void test() { + void test() { assertEquals(List.of(), this.networkModificationRepository.getModificationGroupsUuids()); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); assertEquals(0, networkModificationRepository.getModifications(TEST_GROUP_ID, true, false).size()); var nullModifEntity = EquipmentAttributeModificationInfos.builder().equipmentId("id0").equipmentAttributeName("attribute").equipmentAttributeValue(null).equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); @@ -175,13 +169,12 @@ public void test() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertEquals(0, modificationRepository.findAll().size()); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testCreateModificationGroupQueryCount() { + void testCreateModificationGroupQueryCount() { modificationGroupRepository.save(new ModificationGroupEntity(TEST_GROUP_ID)); // No select @@ -189,16 +182,16 @@ public void testCreateModificationGroupQueryCount() { } @Test - public void testCreateModificationQueryCount() { + void testCreateModificationQueryCount() { var modifEntity1 = EquipmentAttributeModificationInfos.builder().equipmentId("id1").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); var modifEntity2 = EquipmentAttributeModificationInfos.builder().equipmentId("id2").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(modifEntity1, modifEntity2)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); } @Test - public void testGetModificationQueryCount() { + void testGetModificationQueryCount() { var modifEntity1 = EquipmentAttributeModificationInfos.builder().equipmentId("id1").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); var modifEntity2 = EquipmentAttributeModificationInfos.builder().equipmentId("id2").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); var modifEntity3 = EquipmentAttributeModificationInfos.builder().equipmentId("id3").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); @@ -217,39 +210,37 @@ public void testGetModificationQueryCount() { assertRequestsCount(1, 0, 0, 0); // Non-existent modification uuid - assertThrows(new NetworkModificationException(MODIFICATION_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> getEquipmentAttributeModification(TEST_GROUP_ID) - ); + assertThrows(NetworkModificationException.class, () -> getEquipmentAttributeModification(TEST_GROUP_ID), + new NetworkModificationException(MODIFICATION_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testDeleteModificationQueryCount() { + void testDeleteModificationQueryCount() { var modifEntity1 = EquipmentAttributeModificationInfos.builder().equipmentId("id2").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); var modifEntity2 = EquipmentAttributeModificationInfos.builder().equipmentId("id2").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(modifEntity1, modifEntity2)); SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(modifEntity1.getId())); - assertRequestsCount(3, 0, 1, 2); + assertRequestsCount(3, 0, 0, 2); SQLStatementCountValidator.reset(); networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(3, 0, 0, 3); // Non-existent group modification uuid - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testLoadCreation() { + void testLoadCreation() { var createLoadEntity1 = LoadCreationInfos.builder().equipmentId("idLoad1").equipmentName("nameLoad1").loadType(LoadType.AUXILIARY).voltageLevelId("vlId1").busOrBusbarSectionId("busId1").p0(100.).q0(20.).connectionName("top1").connectionDirection(ConnectablePosition.Direction.TOP).connectionPosition(11).build().toEntity(); var createLoadEntity2 = LoadCreationInfos.builder().equipmentId("idLoad2").equipmentName("nameLoad2").loadType(LoadType.FICTITIOUS).voltageLevelId("vlId2").busOrBusbarSectionId("busId2").p0(80.).q0(30.).connectionName("bottom1").connectionDirection(ConnectablePosition.Direction.BOTTOM).connectionPosition(11).build().toEntity(); var createLoadEntity3 = LoadCreationInfos.builder().equipmentId("idLoad3").equipmentName("nameLoad3").loadType(LoadType.FICTITIOUS).voltageLevelId("vlId3").busOrBusbarSectionId("busId3").p0(50.).q0(90.).connectionName("top2").connectionDirection(ConnectablePosition.Direction.TOP).connectionPosition(12).build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(createLoadEntity1, createLoadEntity2, createLoadEntity3)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(3, modificationInfos.size()); @@ -266,7 +257,7 @@ public void testLoadCreation() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(createLoadEntity2.getId(), createLoadEntity3.getId())); - assertRequestsCount(4, 0, 1, 2); + assertRequestsCount(4, 0, 0, 2); SQLStatementCountValidator.reset(); assertEquals(1, networkModificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); @@ -276,13 +267,12 @@ public void testLoadCreation() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(3, 0, 0, 3); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testGeneratorCreation() { + void testGeneratorCreation() { var createGeneratorEntity1 = GeneratorCreationInfos.builder() .equipmentId("idGenerator1").equipmentName("nameGenerator1") .energySource(EnergySource.HYDRO).voltageLevelId("vlId1") @@ -331,7 +321,7 @@ public void testGeneratorCreation() { .connectionPosition(3).build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(createGeneratorEntity1, createGeneratorEntity2, createGeneratorEntity3)); - assertRequestsCount(1, 4, 1, 0); + assertRequestsCount(2, 4, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(3, modificationInfos.size()); @@ -348,7 +338,7 @@ public void testGeneratorCreation() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(createGeneratorEntity2.getId(), createGeneratorEntity3.getId())); - assertRequestsCount(4, 0, 1, 3); + assertRequestsCount(4, 0, 0, 3); SQLStatementCountValidator.reset(); assertEquals(1, networkModificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); @@ -358,13 +348,12 @@ public void testGeneratorCreation() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(3, 0, 0, 4); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testShuntCompensatorCreation() { + void testShuntCompensatorCreation() { var shunt1 = ShuntCompensatorCreationInfos.builder() .equipmentId("shunt1").equipmentName("nameOne") .maximumSectionCount(2) @@ -384,7 +373,7 @@ public void testShuntCompensatorCreation() { var createShuntCompensatorEntity2 = shunt2.toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(createShuntCompensatorEntity1, createShuntCompensatorEntity2)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(2, modificationInfos.size()); @@ -399,7 +388,7 @@ public void testShuntCompensatorCreation() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(createShuntCompensatorEntity2.getId())); - assertRequestsCount(3, 0, 1, 2); + assertRequestsCount(3, 0, 0, 2); SQLStatementCountValidator.reset(); assertEquals(1, networkModificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); @@ -409,20 +398,19 @@ public void testShuntCompensatorCreation() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(3, 0, 0, 3); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testLineCreation() { + void testLineCreation() { var createLineEntity1 = LineCreationInfos.builder().equipmentId("idLine1").equipmentName("nameLine1").r(1.0).x(1.1).g1(10.0).b1(11.0).g2(100.0).b2(100.1).voltageLevelId1("vlId11").busOrBusbarSectionId1("busId11").voltageLevelId2("vlId12").busOrBusbarSectionId2("busId12").connectionName1("cn11").connectionDirection1(ConnectablePosition.Direction.TOP).connectionName2("cn22").connectionDirection2(ConnectablePosition.Direction.TOP).build().toEntity(); var createLineEntity2 = LineCreationInfos.builder().equipmentId("idLine2").equipmentName("nameLine2").r(2.0).x(2.2).g1(20.0).b1(22.0).g2(200.0).b2(200.2).voltageLevelId1("vlId21").busOrBusbarSectionId1("busId21").voltageLevelId2("vlId22").busOrBusbarSectionId2("busId22").connectionName1("cn33").connectionDirection1(ConnectablePosition.Direction.TOP).connectionName2("cn44").connectionDirection2(ConnectablePosition.Direction.BOTTOM).currentLimits2(CurrentLimitsInfos.builder().permanentLimit(5.0).temporaryLimits(Collections.emptyList()).build()).build().toEntity(); var createLineEntity3 = LineCreationInfos.builder().equipmentId("idLine3").equipmentName("nameLine3").r(3.0).x(3.3).g1(30.0).b1(33.0).g2(300.0).b2(300.3).voltageLevelId1("vlId31").busOrBusbarSectionId1("busId31").voltageLevelId2("vlId32").busOrBusbarSectionId2("busId32").connectionName1("cn55").connectionDirection1(ConnectablePosition.Direction.TOP).connectionName2("cn66").connectionDirection2(ConnectablePosition.Direction.TOP).currentLimits1(CurrentLimitsInfos.builder().permanentLimit(5.0).temporaryLimits(Collections.emptyList()).build()).build().toEntity(); var createLineEntity4 = LineCreationInfos.builder().equipmentId("idLine4").equipmentName("nameLine4").r(3.0).x(3.3).g1(null).b1(null).g2(null).b2(null).voltageLevelId1("vlId41").busOrBusbarSectionId1("busId41").voltageLevelId2("vlId42").busOrBusbarSectionId2("busId42").connectionName1("cn77").connectionDirection1(ConnectablePosition.Direction.TOP).connectionName2("cn88").connectionDirection2(ConnectablePosition.Direction.BOTTOM).currentLimits1(CurrentLimitsInfos.builder().permanentLimit(5.0).temporaryLimits(Collections.emptyList()).build()).currentLimits2(CurrentLimitsInfos.builder().permanentLimit(4.0).temporaryLimits(Collections.emptyList()).build()).build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(createLineEntity1, createLineEntity2, createLineEntity3, createLineEntity4)); - assertRequestsCount(1, 4, 1, 0); + assertRequestsCount(2, 4, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(4, modificationInfos.size()); @@ -441,7 +429,7 @@ public void testLineCreation() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(createLineEntity2.getId(), createLineEntity3.getId())); - assertRequestsCount(6, 0, 1, 7); + assertRequestsCount(6, 0, 0, 7); SQLStatementCountValidator.reset(); assertEquals(2, networkModificationRepository.getModifications(TEST_GROUP_ID, false, true).size()); @@ -451,13 +439,12 @@ public void testLineCreation() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(6, 0, 0, 5); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testMoveModificationInSameGroup() { + void testMoveModificationInSameGroup() { // use a group Tabular modification List groupModifications = List.of( GeneratorModificationInfos.builder().equipmentId("idGenerator").maxP(new AttributeModification<>(500., OperationType.SET)).build(), @@ -480,13 +467,13 @@ public void testMoveModificationInSameGroup() { List modificationEntities = List.of(groovyScriptEntity1, groovyScriptEntity2, groovyScriptEntity3, groovyScriptEntity4, groovyScriptEntity5, tabularModificationEntity); networkModificationRepository.saveModifications(TEST_GROUP_ID, modificationEntities); - assertRequestsCount(1, 8, 1, 0); + assertRequestsCount(2, 8, 0, 0); var modificationOriginal = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); SQLStatementCountValidator.reset(); networkModificationRepository.moveModifications(TEST_GROUP_ID, TEST_GROUP_ID, List.of(tabularModificationEntity.getId()), groovyScriptEntity2.getId()); - assertRequestsCount(2, 0, 1, 0); + assertRequestsCount(2, 0, 2, 0); var modification = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); // [0:1, 1:6, 2:2, 3:3, 4:4 ,5:5 ] @@ -497,7 +484,7 @@ public void testMoveModificationInSameGroup() { SQLStatementCountValidator.reset(); networkModificationRepository.moveModifications(TEST_GROUP_ID, TEST_GROUP_ID, List.of(groovyScriptEntity3.getId(), tabularModificationEntity.getId()), null); - assertRequestsCount(2, 0, 1, 0); + assertRequestsCount(2, 0, 2, 0); // [0:1, 1:2, 2:4, 3:5, 4:6, 5:3 ] modification = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); @@ -508,7 +495,7 @@ public void testMoveModificationInSameGroup() { } @Test - public void testMoveModificationsBetweenTwoGroups() { + void testMoveModificationsBetweenTwoGroups() { var groovyScriptEntity1 = GroovyScriptInfos.builder().script("script1").build().toEntity(); var groovyScriptEntity2 = GroovyScriptInfos.builder().script("script2").build().toEntity(); var groovyScriptEntity3 = GroovyScriptInfos.builder().script("script3").build().toEntity(); @@ -518,11 +505,11 @@ public void testMoveModificationsBetweenTwoGroups() { networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(groovyScriptEntity1, groovyScriptEntity2, groovyScriptEntity3, groovyScriptEntity4)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); SQLStatementCountValidator.reset(); networkModificationRepository.saveModifications(TEST_GROUP_ID_2, List.of(groovyScriptEntity5, groovyScriptEntity6)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); var modificationOriginal1 = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); var modificationOriginal2 = networkModificationRepository.getModifications(TEST_GROUP_ID_2, true, true); @@ -531,7 +518,7 @@ public void testMoveModificationsBetweenTwoGroups() { List uuidsToMove = List.of(groovyScriptEntity2.getId(), groovyScriptEntity3.getId()); List movedModifications = networkModificationRepository.moveModifications(TEST_GROUP_ID_2, TEST_GROUP_ID, uuidsToMove, null); assertEquals(uuidsToMove.size(), movedModifications.size()); - assertRequestsCount(4, 0, 2, 0); + assertRequestsCount(4, 0, 1, 0); var modification1 = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); var modification2 = networkModificationRepository.getModifications(TEST_GROUP_ID_2, true, true); @@ -547,7 +534,7 @@ public void testMoveModificationsBetweenTwoGroups() { uuidsToMove = List.of(expected2.get(0).getUuid(), expected2.get(1).getUuid()); movedModifications = networkModificationRepository.moveModifications(TEST_GROUP_ID_3, TEST_GROUP_ID_2, uuidsToMove, null); assertEquals(uuidsToMove.size(), movedModifications.size()); - assertRequestsCount(3, 1, 3, 0); + assertRequestsCount(3, 1, 1, 0); modification2 = networkModificationRepository.getModifications(TEST_GROUP_ID_2, true, true); var modification3 = networkModificationRepository.getModifications(TEST_GROUP_ID_3, true, true); @@ -560,7 +547,7 @@ public void testMoveModificationsBetweenTwoGroups() { } @Test - public void testMoveModificationsBetweenTwoGroupsWithReferenceNode() { + void testMoveModificationsBetweenTwoGroupsWithReferenceNode() { var groovyScriptEntity1 = GroovyScriptInfos.builder().script("script1").build().toEntity(); var groovyScriptEntity2 = GroovyScriptInfos.builder().script("script2").build().toEntity(); var groovyScriptEntity3 = GroovyScriptInfos.builder().script("script3").build().toEntity(); @@ -570,11 +557,11 @@ public void testMoveModificationsBetweenTwoGroupsWithReferenceNode() { networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(groovyScriptEntity1, groovyScriptEntity2, groovyScriptEntity3, groovyScriptEntity4)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); SQLStatementCountValidator.reset(); networkModificationRepository.saveModifications(TEST_GROUP_ID_2, List.of(groovyScriptEntity5, groovyScriptEntity6)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); var modificationOriginal1 = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); var modificationOriginal2 = networkModificationRepository.getModifications(TEST_GROUP_ID_2, true, true); @@ -583,7 +570,7 @@ public void testMoveModificationsBetweenTwoGroupsWithReferenceNode() { List uuidsToMove = List.of(groovyScriptEntity2.getId(), groovyScriptEntity3.getId()); List movedModifications = networkModificationRepository.moveModifications(TEST_GROUP_ID_2, TEST_GROUP_ID, uuidsToMove, groovyScriptEntity6.getId()); assertEquals(uuidsToMove.size(), movedModifications.size()); - assertRequestsCount(4, 0, 2, 0); + assertRequestsCount(4, 0, 1, 0); var modification1 = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); var modification2 = networkModificationRepository.getModifications(TEST_GROUP_ID_2, true, true); @@ -596,7 +583,7 @@ public void testMoveModificationsBetweenTwoGroupsWithReferenceNode() { } @Test - public void testMoveModificationsBetweenMoreThanTwoGroups() { + void testMoveModificationsBetweenMoreThanTwoGroups() { var groovyScriptEntity1 = GroovyScriptInfos.builder().script("script1").build().toEntity(); var groovyScriptEntity2 = GroovyScriptInfos.builder().script("script2").build().toEntity(); var groovyScriptEntity3 = GroovyScriptInfos.builder().script("script3").build().toEntity(); @@ -605,15 +592,15 @@ public void testMoveModificationsBetweenMoreThanTwoGroups() { var groovyScriptEntity6 = GroovyScriptInfos.builder().script("script6").build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(groovyScriptEntity1, groovyScriptEntity2)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); SQLStatementCountValidator.reset(); networkModificationRepository.saveModifications(TEST_GROUP_ID_2, List.of(groovyScriptEntity3, groovyScriptEntity4)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); SQLStatementCountValidator.reset(); networkModificationRepository.saveModifications(TEST_GROUP_ID_3, List.of(groovyScriptEntity5, groovyScriptEntity6)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); var modificationOriginal1 = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); var modificationOriginal2 = networkModificationRepository.getModifications(TEST_GROUP_ID_2, true, true); @@ -623,7 +610,7 @@ public void testMoveModificationsBetweenMoreThanTwoGroups() { SQLStatementCountValidator.reset(); List modificationsToMoveUuid = List.of(groovyScriptEntity1.getId(), UUID.randomUUID()); List movedModifications = networkModificationRepository.moveModifications(TEST_GROUP_ID_3, TEST_GROUP_ID, modificationsToMoveUuid, null); - assertRequestsCount(4, 0, 2, 0); + assertRequestsCount(4, 0, 1, 0); // only the valid modification is moved assertEquals(1, movedModifications.size()); assertEquals(groovyScriptEntity1.getId(), movedModifications.get(0).getId()); @@ -638,9 +625,8 @@ public void testMoveModificationsBetweenMoreThanTwoGroups() { SQLStatementCountValidator.reset(); List modificationsToMoveUuid2 = List.of(groovyScriptEntity2.getId()); UUID referenceNodeUuid = groovyScriptEntity2.getId(); - assertThrows(new NetworkModificationException(MOVE_MODIFICATION_ERROR).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.moveModifications(TEST_GROUP_ID_2, TEST_GROUP_ID, modificationsToMoveUuid2, referenceNodeUuid) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.moveModifications(TEST_GROUP_ID_2, TEST_GROUP_ID, modificationsToMoveUuid2, referenceNodeUuid), + new NetworkModificationException(MOVE_MODIFICATION_ERROR).getMessage()); assertRequestsCount(4, 0, 0, 0); var modification1 = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); @@ -655,18 +641,18 @@ public void testMoveModificationsBetweenMoreThanTwoGroups() { assertEquals(getIds(modification3), getIds(expected3)); } - private List getIds(List expected) { + private static List getIds(List expected) { return expected.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); } @Test - public void testGroovyScript() { + void testGroovyScript() { var groovyScriptEntity1 = GroovyScriptInfos.builder().script("script1").build().toEntity(); var groovyScriptEntity2 = GroovyScriptInfos.builder().script("script2").build().toEntity(); var groovyScriptEntity3 = GroovyScriptInfos.builder().script("script3").build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(groovyScriptEntity1, groovyScriptEntity2, groovyScriptEntity3)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, false, true); assertEquals(3, modificationInfos.size()); @@ -683,7 +669,7 @@ public void testGroovyScript() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(groovyScriptEntity2.getId(), groovyScriptEntity3.getId())); - assertRequestsCount(2, 0, 1, 2); + assertRequestsCount(2, 0, 0, 2); SQLStatementCountValidator.reset(); assertEquals(1, networkModificationRepository.getModifications(TEST_GROUP_ID, false, true).size()); @@ -693,13 +679,12 @@ public void testGroovyScript() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(2, 0, 0, 3); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testSubstationCreation() { + void testSubstationCreation() { var createSubstationEntity1 = SubstationCreationInfos.builder() .equipmentId("idSubstation1") .equipmentName("nameSubstation1") @@ -720,7 +705,7 @@ public void testSubstationCreation() { .build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(createSubstationEntity1, createSubstationEntity2, createSubstationEntity3)); - assertRequestsCount(1, 4, 2, 0); + assertRequestsCount(2, 4, 1, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, false, true); assertEquals(3, modificationInfos.size()); @@ -737,7 +722,7 @@ public void testSubstationCreation() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(createSubstationEntity2.getId(), createSubstationEntity3.getId())); - assertRequestsCount(4, 0, 1, 2); + assertRequestsCount(4, 0, 0, 2); SQLStatementCountValidator.reset(); assertEquals(1, networkModificationRepository.getModifications(TEST_GROUP_ID, false, true).size()); @@ -747,13 +732,12 @@ public void testSubstationCreation() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(3, 0, 1, 4); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testVoltageLevelCreation() { + void testVoltageLevelCreation() { VoltageLevelCreationEntity createVoltLvlEntity1 = VoltageLevelCreationInfos.builder() .equipmentId("idVL1") .equipmentName("VLName") @@ -784,14 +768,12 @@ public void testVoltageLevelCreation() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(2, 0, 0, 1); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } - private VoltageLevelCreationInfos makeAVoltageLevelInfos() { - - VoltageLevelCreationInfos createVoltLvlEntity1 = VoltageLevelCreationInfos.builder() + private static VoltageLevelCreationInfos makeAVoltageLevelInfos() { + return VoltageLevelCreationInfos.builder() .substationId("s1").nominalV(379.0).equipmentId("idVL1").equipmentName("VLName") .lowVoltageLimit(0.0) .highVoltageLimit(10.0) @@ -802,12 +784,10 @@ private VoltageLevelCreationInfos makeAVoltageLevelInfos() { .switchKinds(Arrays.asList(SwitchKind.BREAKER)) .couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("bbs.nw").busbarSectionId2("bbs.ne").build())) .build(); - - return createVoltLvlEntity1; } @Test - public void testStatusLineModification() { + void testStatusLineModification() { List entities = List.of( OperatingStatusModificationInfos.builder().equipmentId("idLine1").action(OperatingStatusModificationInfos.ActionType.LOCKOUT).build().toEntity(), OperatingStatusModificationInfos.builder().equipmentId("idLine2").action(OperatingStatusModificationInfos.ActionType.TRIP).build().toEntity(), @@ -817,7 +797,7 @@ public void testStatusLineModification() { ); networkModificationRepository.saveModifications(TEST_GROUP_ID, entities); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) .stream() @@ -843,7 +823,7 @@ public void testStatusLineModification() { } @Test - public void testLineSplitWithVoltageLevel() { + void testLineSplitWithVoltageLevel() { LineSplitWithVoltageLevelEntity lineSplitEntity1 = LineSplitWithVoltageLevelInfos.builder() .lineToSplitId("lineId0") .percent(30.0) @@ -892,13 +872,12 @@ public void testLineSplitWithVoltageLevel() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(2, 0, 0, 1); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testLineAttachToVoltageLevel() { + void testLineAttachToVoltageLevel() { LineCreationInfos attachmentLine = LineCreationInfos.builder() .equipmentId("attachmentLineId") .r(50.6) @@ -949,19 +928,18 @@ public void testLineAttachToVoltageLevel() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(lineAttachToEntity1.getId(), lineAttachToEntity2.getId())); - assertRequestsCount(5, 0, 0, 12); + assertRequestsCount(6, 0, 0, 12); SQLStatementCountValidator.reset(); networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(2, 0, 0, 1); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testLinesAttachToSplitLines() { + void testLinesAttachToSplitLines() { LinesAttachToSplitLinesEntity linesAttachToEntity1 = LinesAttachToSplitLinesInfos.builder() .lineToAttachTo1Id("lineId0") .lineToAttachTo2Id("lineId1") @@ -1006,13 +984,12 @@ public void testLinesAttachToSplitLines() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(2, 0, 0, 1); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testDeleteStashedModificationList() { + void testDeleteStashedModificationList() { //create a modification and add it to the repository var groovyScriptEntity1 = GroovyScriptInfos.builder().stashed(true).script("script1").build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(groovyScriptEntity1)); @@ -1028,7 +1005,7 @@ public void testDeleteStashedModificationList() { } @Test - public void testDeleteNonStashedModificationList() { + void testDeleteNonStashedModificationList() { //create a modification and add it to the repository var groovyScriptEntity1 = GroovyScriptInfos.builder().stashed(false).script("script1").build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(groovyScriptEntity1)); @@ -1044,7 +1021,7 @@ public void testDeleteNonStashedModificationList() { } @Test - public void testDeleteAttachingLine() { + void testDeleteAttachingLine() { DeleteAttachingLineEntity deleteAttachingLineEntity = DeleteAttachingLineInfos.builder() .lineToAttachTo1Id("lineId0") .lineToAttachTo2Id("lineId1") @@ -1075,13 +1052,12 @@ public void testDeleteAttachingLine() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(2, 0, 0, 1); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } @Test - public void testDeleteVoltageLevelOnLine() { + void testDeleteVoltageLevelOnLine() { DeleteVoltageLevelOnLineEntity deleteVoltageLevelOnLineToEntity1 = DeleteVoltageLevelOnLineInfos.builder() .lineToAttachTo1Id("lineId0") .lineToAttachTo2Id("lineId1") @@ -1118,25 +1094,24 @@ public void testDeleteVoltageLevelOnLine() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(2, 0, 0, 1); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, false, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } - private void testModificationEmbedded(IAttributeModificationEmbeddable modification, T val) { + private static void testModificationEmbedded(IAttributeModificationEmbeddable modification, T val) { assertEquals(val, modification.getValue()); assertEquals(OperationType.SET, modification.getOpType()); } @Test - public void testEmbeddedModificationTypes() { + void testEmbeddedModificationTypes() { testModificationEmbedded(new DoubleModificationEmbedded(new AttributeModification<>(10., OperationType.SET)), 10.); testModificationEmbedded(new EnumModificationEmbedded<>(new AttributeModification<>(OperationType.SET, OperationType.SET)), OperationType.SET); testModificationEmbedded(new BooleanModificationEmbedded(new AttributeModification<>(true, OperationType.SET)), true); } @Test - public void testVoltageInitModification() { + void testVoltageInitModification() { var voltageInitModificationEntity = VoltageInitModificationInfos.builder() .generators(List.of( VoltageInitGeneratorModificationInfos.builder() @@ -1210,7 +1185,7 @@ public void testVoltageInitModification() { .build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(voltageInitModificationEntity)); - assertRequestsCount(1, 9, 1, 0); + assertRequestsCount(2, 9, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(1, modificationInfos.size()); @@ -1230,7 +1205,7 @@ public void testVoltageInitModification() { } @Test - public void testVscModification() { + void testVscModification() { var vscModificationEntity = VscModificationInfos.builder() .equipmentId("VSC1") .converterStation1(ConverterStationModificationInfos.builder().equipmentId("C1").build()) @@ -1238,14 +1213,14 @@ public void testVscModification() { .build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(vscModificationEntity)); - assertRequestsCount(1, 5, 1, 0); + assertRequestsCount(2, 5, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(1, modificationInfos.size()); } @Test - public void testGetModificationCount() { + void testGetModificationCount() { var modifEntity1 = EquipmentAttributeModificationInfos.builder().equipmentId("id2").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); var modifEntity2 = EquipmentAttributeModificationInfos.builder().equipmentId("id2").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(modifEntity1, modifEntity2)); @@ -1261,7 +1236,7 @@ public void testGetModificationCount() { } @Test - public void testModificationOrder() { + void testModificationOrder() { // add 1 modification in a group var modifEntity1 = EquipmentAttributeModificationInfos.builder().equipmentId("id1").equipmentAttributeName("attribute").equipmentAttributeValue("foo").equipmentType(IdentifiableType.VOLTAGE_LEVEL).build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(modifEntity1)); @@ -1276,11 +1251,11 @@ public void testModificationOrder() { // trick: move it too, to see the order in the entity movedEntities = networkModificationRepository.moveModifications(TEST_GROUP_ID_2, TEST_GROUP_ID, List.of(modifEntity2.getId()), null); assertEquals(1, movedEntities.size()); - assertEquals(0, movedEntities.get(0).getModificationsOrder()); + assertEquals(1, movedEntities.get(0).getModificationsOrder()); } @Test - public void testStaticVarCompensatorCreation() { + void testStaticVarCompensatorCreation() { var createStaticVarCompensator1 = StaticVarCompensatorCreationInfos.builder() .equipmentId("idStaticVarCompensator1").equipmentName("nameStaticVarCompensator1") .voltageLevelId("vlId1") @@ -1316,7 +1291,7 @@ public void testStaticVarCompensatorCreation() { .build().toEntity(); networkModificationRepository.saveModifications(TEST_GROUP_ID, List.of(createStaticVarCompensator1, createStaticVarCompensator2, createStaticVarCompensator3)); - assertRequestsCount(1, 3, 1, 0); + assertRequestsCount(2, 3, 0, 0); List modificationInfos = networkModificationRepository.getModifications(TEST_GROUP_ID, true, true); assertEquals(3, modificationInfos.size()); @@ -1331,7 +1306,7 @@ public void testStaticVarCompensatorCreation() { SQLStatementCountValidator.reset(); networkModificationRepository.deleteModifications(TEST_GROUP_ID, List.of(createStaticVarCompensator2.getId(), createStaticVarCompensator3.getId())); - assertRequestsCount(4, 0, 1, 2); + assertRequestsCount(4, 0, 0, 2); SQLStatementCountValidator.reset(); assertEquals(1, networkModificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); @@ -1341,8 +1316,7 @@ public void testStaticVarCompensatorCreation() { networkModificationRepository.deleteModificationGroup(TEST_GROUP_ID, true); assertRequestsCount(3, 0, 0, 3); - assertThrows(new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage(), - NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true) - ); + assertThrows(NetworkModificationException.class, () -> networkModificationRepository.getModifications(TEST_GROUP_ID, true, true), + new NetworkModificationException(MODIFICATION_GROUP_NOT_FOUND, TEST_GROUP_ID.toString()).getMessage()); } } diff --git a/src/test/java/org/gridsuite/modification/server/service/NetworkStoreListenerTest.java b/src/test/java/org/gridsuite/modification/server/service/NetworkStoreListenerTest.java index c550f649d..5a7f71a67 100644 --- a/src/test/java/org/gridsuite/modification/server/service/NetworkStoreListenerTest.java +++ b/src/test/java/org/gridsuite/modification/server/service/NetworkStoreListenerTest.java @@ -4,10 +4,9 @@ * 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 org.gridsuite.modification.server.dto.NetworkModificationResult; +import org.gridsuite.modification.server.dto.NetworkModificationResult.ApplicationStatus; import org.junit.jupiter.api.Tag; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -15,24 +14,21 @@ import java.util.stream.Stream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("UnitTest") class NetworkStoreListenerTest { @ParameterizedTest @MethodSource("provideArgumentsForWorstStatus") - void worstStatus(NetworkModificationResult.ApplicationStatus firstStatus, NetworkModificationResult.ApplicationStatus secondStatus) { + void worstStatus(ApplicationStatus firstStatus, ApplicationStatus secondStatus) { assertEquals(secondStatus, firstStatus.max(secondStatus)); } private static Stream provideArgumentsForWorstStatus() { return Stream.of( - Arguments.of(NetworkModificationResult.ApplicationStatus.ALL_OK, - NetworkModificationResult.ApplicationStatus.WITH_WARNINGS), - Arguments.of(NetworkModificationResult.ApplicationStatus.ALL_OK, - NetworkModificationResult.ApplicationStatus.WITH_ERRORS), - Arguments.of(NetworkModificationResult.ApplicationStatus.WITH_WARNINGS, - NetworkModificationResult.ApplicationStatus.WITH_ERRORS) + Arguments.of(ApplicationStatus.ALL_OK, ApplicationStatus.WITH_WARNINGS), + Arguments.of(ApplicationStatus.ALL_OK, ApplicationStatus.WITH_ERRORS), + Arguments.of(ApplicationStatus.WITH_WARNINGS, ApplicationStatus.WITH_ERRORS) ); } } diff --git a/src/test/java/org/gridsuite/modification/server/utils/ApiUtils.java b/src/test/java/org/gridsuite/modification/server/utils/ApiUtils.java index f87e96902..06fc81614 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/ApiUtils.java +++ b/src/test/java/org/gridsuite/modification/server/utils/ApiUtils.java @@ -4,7 +4,6 @@ * 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.utils; import com.fasterxml.jackson.core.type.TypeReference; @@ -26,9 +25,8 @@ * @author Joris Mancini */ public final class ApiUtils { - private ApiUtils() { - // Should not be instantiated + throw new IllegalCallerException("Utility class"); } public static List getGroupModifications(MockMvc mockMvc, UUID groupUuid) throws Exception { diff --git a/src/test/java/org/gridsuite/modification/server/utils/DatasourceProxyBeanPostProcessor.java b/src/test/java/org/gridsuite/modification/server/utils/DatasourceProxyBeanPostProcessor.java index 1f7d83adc..e8c0558f7 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/DatasourceProxyBeanPostProcessor.java +++ b/src/test/java/org/gridsuite/modification/server/utils/DatasourceProxyBeanPostProcessor.java @@ -4,13 +4,8 @@ * 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.utils; -import javax.sql.DataSource; - -import java.lang.reflect.Method; - import net.ttddyy.dsproxy.listener.ChainListener; import net.ttddyy.dsproxy.listener.DataSourceQueryCountListener; import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel; @@ -23,6 +18,9 @@ import org.springframework.stereotype.Component; import org.springframework.util.ReflectionUtils; +import javax.sql.DataSource; +import java.lang.reflect.Method; + @Component /** * The author of db-utils describes its library in https://vladmihalcea.com/how-to-detect-the-n-plus-one-query-problem-during-testing/ diff --git a/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java b/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java index 25984d36e..c5fc0befb 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java +++ b/src/test/java/org/gridsuite/modification/server/utils/ModificationCreation.java @@ -4,7 +4,6 @@ * 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.utils; import com.powsybl.iidm.network.EnergySource; @@ -12,6 +11,7 @@ import com.powsybl.iidm.network.SwitchKind; import com.powsybl.iidm.network.extensions.ConnectablePosition; import org.gridsuite.modification.server.dto.*; + import java.util.Arrays; /** @@ -22,6 +22,7 @@ public final class ModificationCreation { private static final String PROPERTY_VALUE = "property-value"; private ModificationCreation() { + throw new IllegalStateException("Utility class"); } public static VoltageLevelCreationInfos getCreationVoltageLevel(String substationId, String voltageLevelId, String voltageLevelName) { diff --git a/src/test/java/org/gridsuite/modification/server/utils/NetworkCreation.java b/src/test/java/org/gridsuite/modification/server/utils/NetworkCreation.java index 9c90abbb3..71d099d1e 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/NetworkCreation.java +++ b/src/test/java/org/gridsuite/modification/server/utils/NetworkCreation.java @@ -4,7 +4,6 @@ * 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.utils; import com.powsybl.iidm.network.*; @@ -21,6 +20,7 @@ public final class NetworkCreation { public static final String VARIANT_ID = "variant_1"; private NetworkCreation() { + throw new IllegalCallerException("Utility class"); } public static Network create(UUID uuid, boolean createHvdcLine) { diff --git a/src/test/java/org/gridsuite/modification/server/utils/NetworkUtil.java b/src/test/java/org/gridsuite/modification/server/utils/NetworkUtil.java index bd038d7b7..4091a22c7 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/NetworkUtil.java +++ b/src/test/java/org/gridsuite/modification/server/utils/NetworkUtil.java @@ -4,7 +4,6 @@ * 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.utils; import com.powsybl.iidm.network.*; @@ -14,8 +13,8 @@ import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; public final class NetworkUtil { - private NetworkUtil() { + throw new IllegalStateException("Utility class"); } @SuppressWarnings("SameParameterValue") diff --git a/src/test/java/org/gridsuite/modification/server/utils/NetworkWithTeePoint.java b/src/test/java/org/gridsuite/modification/server/utils/NetworkWithTeePoint.java index 4cbcc91d0..384f5ff82 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/NetworkWithTeePoint.java +++ b/src/test/java/org/gridsuite/modification/server/utils/NetworkWithTeePoint.java @@ -4,7 +4,6 @@ * 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.utils; import com.powsybl.iidm.network.*; @@ -20,8 +19,8 @@ * @author Geoffroy Jamgotchian */ public final class NetworkWithTeePoint { - private NetworkWithTeePoint() { + throw new IllegalCallerException("Utility class"); } public static Network create(UUID uuid) { 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 9d43e55b3..2529c37ad 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java +++ b/src/test/java/org/gridsuite/modification/server/utils/TestUtils.java @@ -4,7 +4,6 @@ * 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.utils; import com.github.tomakehurst.wiremock.WireMockServer; @@ -16,7 +15,7 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.extensions.OperatingStatus; import com.powsybl.iidm.network.extensions.OperatingStatusAdder; -import okhttp3.mockwebserver.MockWebServer; +import mockwebserver3.MockWebServer; import org.apache.commons.text.StringSubstitutor; import org.gridsuite.modification.server.service.ReportService; import org.junit.platform.commons.util.StringUtils; @@ -32,7 +31,7 @@ import java.util.stream.IntStream; import static com.vladmihalcea.sql.SQLStatementCountValidator.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; /** @@ -43,6 +42,7 @@ public final class TestUtils { private static final long TIMEOUT = 100; private TestUtils() { + throw new IllegalCallerException("Utility class"); } public static Set getRequestsDone(int n, MockWebServer server) throws UncheckedInterruptedException { @@ -67,7 +67,7 @@ public static void purgeRequests(MockWebServer server) throws UncheckedInterrupt public static void assertQueuesEmptyThenClear(List destinations, OutputDestination output) { try { - destinations.forEach(destination -> assertNull("Should not be any messages in queue " + destination + " : ", output.receive(TIMEOUT, destination))); + destinations.forEach(destination -> assertNull(output.receive(TIMEOUT, destination), "Should not be any messages in queue " + destination)); } catch (NullPointerException e) { // Ignoring } finally { @@ -77,7 +77,6 @@ public static void assertQueuesEmptyThenClear(List destinations, OutputD public static void assertServerRequestsEmptyThenShutdown(MockWebServer server) throws UncheckedInterruptedException, IOException { Set httpRequest = null; - try { httpRequest = getRequestsDone(1, server); } catch (NullPointerException e) { @@ -85,8 +84,7 @@ public static void assertServerRequestsEmptyThenShutdown(MockWebServer server) t } finally { server.shutdown(); } - - assertNull("Should not be any http requests : ", httpRequest); + assertNull(httpRequest, "Should not be any http requests :"); } public static void assertRequestsCount(long select, long insert, long update, long delete) { diff --git a/src/test/java/org/gridsuite/modification/server/utils/WireMockUtils.java b/src/test/java/org/gridsuite/modification/server/utils/WireMockUtils.java index f57643473..f34b7adfe 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/WireMockUtils.java +++ b/src/test/java/org/gridsuite/modification/server/utils/WireMockUtils.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class WireMockUtils { diff --git a/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/DisableElasticsearch.java b/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/DisableElasticsearch.java index ce0ce3bab..a2027e5ee 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/DisableElasticsearch.java +++ b/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/DisableElasticsearch.java @@ -4,7 +4,6 @@ * 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.utils.elasticsearch; import org.gridsuite.modification.server.elasticsearch.EquipmentInfosRepository;