Skip to content

Commit

Permalink
Fix with comments, add section value to message, add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lilian Houdelet <[email protected]>
  • Loading branch information
lilian-houdelet committed Dec 29, 2023
1 parent f52fdca commit 580a774
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public void check(Network network) throws NetworkModificationException {
}

if (modificationInfos.getSectionCount() < 1 || modificationInfos.getSectionCount() > modificationInfos.getMaximumSectionCount()) {
throw new NetworkModificationException(CREATE_SHUNT_COMPENSATOR_ERROR, "Section count should be between 1 and Maximum section count");
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 @@ -58,7 +58,7 @@ public void check(Network network) throws NetworkModificationException {
}

if (sectionCount < 1 || maximumSectionCount < 1 || sectionCount > maximumSectionCount) {
throw new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR, "Section count should be between 1 and Maximum section count");
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testCreateWithSectionError() throws Exception {
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").getMessage(),
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,54 @@ public void testWrongSectionCount() {
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")).getMessage(),
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

0 comments on commit 580a774

Please sign in to comment.