Skip to content

Commit

Permalink
Merge branch 'main' into add-es-container-env-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebhs authored Jan 2, 2024
2 parents 9ece0e0 + cae06b6 commit 7fc9e19
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public void check(Network network) throws NetworkModificationException {
if (network.getShuntCompensator(modificationInfos.getEquipmentId()) != null) {
throw new NetworkModificationException(SHUNT_COMPENSATOR_ALREADY_EXISTS, modificationInfos.getEquipmentId());
}

if (modificationInfos.getMaximumSectionCount() < 1) {
throw new NetworkModificationException(CREATE_SHUNT_COMPENSATOR_ERROR, "Maximum section count should be greater or equal to 1");
}

if (modificationInfos.getSectionCount() < 1 || modificationInfos.getSectionCount() > modificationInfos.getMaximumSectionCount()) {
throw new NetworkModificationException(CREATE_SHUNT_COMPENSATOR_ERROR, String.format("Section count should be between 1 and Maximum section count (%d), actual : %d",
modificationInfos.getMaximumSectionCount(),
modificationInfos.getSectionCount()));
}
ModificationUtils.getInstance().controlConnectivity(network, modificationInfos.getVoltageLevelId(),
modificationInfos.getBusOrBusbarSectionId(), modificationInfos.getConnectionPosition());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import java.util.ArrayList;
import java.util.List;

import static org.gridsuite.modification.server.NetworkModificationException.Type.SHUNT_COMPENSATOR_NOT_FOUND;
import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_LEVEL_NOT_FOUND;
import static org.gridsuite.modification.server.NetworkModificationException.Type.*;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand All @@ -46,11 +45,28 @@ public void check(Network network) throws NetworkModificationException {
String.format("Shunt compensator %s does not exist in network", modificationInfos.getEquipmentId()));
}

int maximumSectionCount = modificationInfos.getMaximumSectionCount() != null
? modificationInfos.getMaximumSectionCount().getValue()
: shuntCompensator.getMaximumSectionCount();

int sectionCount = modificationInfos.getSectionCount() != null
? modificationInfos.getSectionCount().getValue()
: shuntCompensator.getSectionCount();

if (modificationInfos.getMaximumSectionCount() != null && modificationInfos.getMaximumSectionCount().getValue() < 1) {
throw new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR, "Maximum section count should be greater or equal to 1");
}

if (sectionCount < 1 || maximumSectionCount < 1 || sectionCount > maximumSectionCount) {
throw new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR, String.format("Section count should be between 1 and Maximum section count (%d), actual : %d", maximumSectionCount, sectionCount));
}

VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getVoltageLevelId());
if (voltageLevel == null) {
throw new NetworkModificationException(VOLTAGE_LEVEL_NOT_FOUND,
String.format("Voltage level %s does not exist in network", modificationInfos.getVoltageLevelId()));
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import java.util.Map;
import java.util.UUID;

import static org.gridsuite.modification.server.NetworkModificationException.Type.CONNECTION_POSITION_ERROR;
import static org.gridsuite.modification.server.NetworkModificationException.Type.SHUNT_COMPENSATOR_ALREADY_EXISTS;
import static org.gridsuite.modification.server.NetworkModificationException.Type.*;
import static org.gridsuite.modification.server.utils.assertions.Assertions.*;
import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -101,6 +100,31 @@ public void testCreateWithError() throws Exception {
modificationToCreate.getErrorType().name(), reportService);
}

@Test
public void testCreateWithMaximumSectionCountError() throws Exception {
ShuntCompensatorCreationInfos modificationToCreate = (ShuntCompensatorCreationInfos) buildModification();
modificationToCreate.setMaximumSectionCount(0);

String modificationToCreateJson = mapper.writeValueAsString(modificationToCreate);
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertLogMessage(new NetworkModificationException(CREATE_SHUNT_COMPENSATOR_ERROR, "Maximum section count should be greater or equal to 1").getMessage(),
modificationToCreate.getErrorType().name(), reportService);
}

@Test
public void testCreateWithSectionError() throws Exception {
ShuntCompensatorCreationInfos modificationToCreate = (ShuntCompensatorCreationInfos) buildModification();
modificationToCreate.setMaximumSectionCount(2);
modificationToCreate.setSectionCount(3);

String modificationToCreateJson = mapper.writeValueAsString(modificationToCreate);
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertLogMessage(new NetworkModificationException(CREATE_SHUNT_COMPENSATOR_ERROR, "Section count should be between 1 and Maximum section count (2), actual : 3").getMessage(),
modificationToCreate.getErrorType().name(), reportService);
}

@Test
public void testCreateWithExistingConnectionPosition() throws Exception {
ShuntCompensatorCreationInfos dto = (ShuntCompensatorCreationInfos) buildModification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,82 @@ public void testWrongVoltageLevelId() {
shuntCompensator.getErrorType().name(), reportService);
}

@SneakyThrows
@Test
public void testWrongMaximumSectionCount() {
var shuntCompensator = ShuntCompensatorModificationInfos.builder()
.equipmentId("v5shunt")
.sectionCount(new AttributeModification<>(3, OperationType.SET))
.maximumSectionCount(new AttributeModification<>(-1, OperationType.SET))
.build();

mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(shuntCompensator)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertLogMessage(new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR,
String.format("Maximum section count should be greater or equal to 1")).getMessage(),
shuntCompensator.getErrorType().name(), reportService);
}

@SneakyThrows
@Test
public void testWrongSectionCount() {
var shuntCompensator = ShuntCompensatorModificationInfos.builder()
.equipmentId("v5shunt")
.sectionCount(new AttributeModification<>(3, OperationType.SET))
.maximumSectionCount(new AttributeModification<>(1, OperationType.SET))
.build();

mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(shuntCompensator)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertLogMessage(new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR,
String.format("Section count should be between 1 and Maximum section count (1), actual : 3")).getMessage(),
shuntCompensator.getErrorType().name(), reportService);
}

@SneakyThrows
@Test
public void testWrongSectionCountChangeSectionCount() {
VoltageLevel v5 = getNetwork().getVoltageLevel("v5");
createShuntCompensator(v5, "v7shunt", "v7shunt", 6, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);

var shuntCompensator = getNetwork().getShuntCompensator("v7shunt");
var model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class);
assertNotNull(model);

var shuntCompensatorModifications = ShuntCompensatorModificationInfos.builder()
.equipmentId("v7shunt")
.sectionCount(new AttributeModification<>(3, OperationType.SET))
.build();

mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(shuntCompensatorModifications)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertLogMessage(new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR,
String.format("Section count should be between 1 and Maximum section count (1), actual : 3")).getMessage(),
shuntCompensatorModifications.getErrorType().name(), reportService);
}

@SneakyThrows
@Test
public void testWrongSectionCountChangeMaximumSectionCount() {
VoltageLevel v5 = getNetwork().getVoltageLevel("v5");
createShuntCompensator(v5, "v7shunt", "v7shunt", 6, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);

var shuntCompensator = getNetwork().getShuntCompensator("v7shunt");
var model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class);
assertNotNull(model);

var shuntCompensatorModifications = ShuntCompensatorModificationInfos.builder()
.equipmentId("v7shunt")
.sectionCount(new AttributeModification<>(0, OperationType.SET))
.build();

mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(shuntCompensatorModifications)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertLogMessage(new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR,
String.format("Section count should be between 1 and Maximum section count (1), actual : 0")).getMessage(),
shuntCompensatorModifications.getErrorType().name(), reportService);
}

@SneakyThrows
@Test
public void testNegativeQmaxAtNominalV() {
Expand Down Expand Up @@ -119,7 +195,7 @@ public void testCreateModificationWithShuntCompensatorType() {
@Test
public void testCreateModificationWithSusceptancePerSection() {
VoltageLevel v5 = getNetwork().getVoltageLevel("v5");
createShuntCompensator(v5, "v7shunt", "v7shunt", 6, 225., 10, true, 1, 1, 2, 0, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);
createShuntCompensator(v5, "v7shunt", "v7shunt", 6, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);

var shuntCompensator = getNetwork().getShuntCompensator("v7shunt");
var model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class);
Expand Down

0 comments on commit 7fc9e19

Please sign in to comment.