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 extends ModificationEntity> 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 extends Mo
public 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