Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check null values for droop and P0 (2e patch) #523

Merged
merged 16 commits into from
Sep 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Map;

import static org.gridsuite.modification.server.NetworkModificationException.Type.*;
import static org.gridsuite.modification.server.modifications.VscModification.DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG;

/**
* @author Seddik Yengui <seddik.yengui at rte-france.com>
Expand All @@ -33,6 +32,7 @@ public class VscCreation extends AbstractModification {

public static final String VSC_SETPOINTS = "vscSetPoints";
public static final String VSC_CHARACTERISTICS = "vscCharacteristics";
public static final String DROOP_P0_REQUIRED_ERROR_MSG = "Droop and P0 are both required when angle droop active power control is activated";

private final VscCreationInfos modificationInfos;

Expand All @@ -59,8 +59,7 @@ private void checkDroop() {

// enable the extension => should verify whether all fields have been filled
if (modificationInfos.getDroop() == null || modificationInfos.getP0() == null) {
throw new NetworkModificationException(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL,
String.format(DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG));
throw new NetworkModificationException(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL, DROOP_P0_REQUIRED_ERROR_MSG);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class VscModification extends AbstractModification {
public static final String ANGLE_DROOP_ACTIVE_POWER_CONTROL_FIELD = "AngleDroopActivePowerControl";
public static final String DROOP_FIELD = "Droop";
public static final String P0_FIELD = "P0";
public static final String DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG = "Both Droop and P0 are required when angle droop active power control is activated";
public static final String DROOP_ACTIVE_POWER_CONTROL_P0_REQUIRED_ERROR_MSG = "P0 is required when Droop is provided";
public static final String ACTIVE_POWER_CONTROL_DROOP_P0_REQUIRED_ERROR_MSG = "Angle droop active power control, Droop and P0 must be provided together";

private final VscModificationInfos modificationInfos;

Expand Down Expand Up @@ -66,29 +65,29 @@ public void check(Network network) throws NetworkModificationException {
}

private void checkDroopModification(HvdcLine hvdcLine) {
// the extension already exists
//--- the extension already exists ---//
HvdcAngleDroopActivePowerControl hvdcAngleDroopActivePowerControl = hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class);
if (hvdcAngleDroopActivePowerControl != null) {
// if droop is set p0 should be also
if (modificationInfos.getDroop() != null && modificationInfos.getP0() == null) {
throw new NetworkModificationException(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL,
String.format(DROOP_ACTIVE_POWER_CONTROL_P0_REQUIRED_ERROR_MSG));
}
return;
}

// the extension doesn't exist yet and the modification wants to enable the extension =>
// should verify whether all fields have been filled
boolean isEnabledAngleDroopActivePowerControl = modificationInfos.getAngleDroopActivePowerControl() != null
&& Boolean.TRUE.equals(modificationInfos.getAngleDroopActivePowerControl().getValue());
if (!isEnabledAngleDroopActivePowerControl) {
//--- the extension doesn't exist yet ---//
// all fields should be filled => OK
if (modificationInfos.getAngleDroopActivePowerControl() != null &&
modificationInfos.getDroop() != null &&
modificationInfos.getP0() != null) {
return;
}

if (modificationInfos.getDroop() == null || modificationInfos.getP0() == null) {
// at least one field is filled but not for others => NOT OK
if (modificationInfos.getAngleDroopActivePowerControl() != null ||
modificationInfos.getDroop() != null ||
modificationInfos.getP0() != null) {
throw new NetworkModificationException(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL,
String.format(DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG));
ACTIVE_POWER_CONTROL_DROOP_P0_REQUIRED_ERROR_MSG);
}

// all fields are not filled => OK => do nothing
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.gridsuite.modification.server.NetworkModificationException.Type.*;
import static org.gridsuite.modification.server.modifications.VscModification.DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG;
import static org.gridsuite.modification.server.modifications.VscCreation.DROOP_P0_REQUIRED_ERROR_MSG;
import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand Down Expand Up @@ -327,7 +327,7 @@ public void testCreateWithEnablingDroopPowerControl() throws Exception {
mockMvc.perform(post(getNetworkModificationUri()).content(vscCreationInfosJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
assertLogMessage(new NetworkModificationException(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL,
String.format(DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG)).getMessage(),
String.format(DROOP_P0_REQUIRED_ERROR_MSG)).getMessage(),
vscCreationInfos.getErrorType().name(), reportService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.util.CollectionUtils;

import java.io.IOException;
Expand All @@ -30,7 +32,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.gridsuite.modification.server.NetworkModificationException.Type.WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL;
import static org.gridsuite.modification.server.modifications.VscModification.DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG;
import static org.gridsuite.modification.server.modifications.VscModification.ACTIVE_POWER_CONTROL_DROOP_P0_REQUIRED_ERROR_MSG;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
Expand All @@ -39,7 +41,7 @@
* @author jamal kheyyad <jamal.kheyyad at rte-france.com>
*/
@Tag("IntegrationTest")
public class VscModificationTest extends AbstractNetworkModificationTest {
class VscModificationTest extends AbstractNetworkModificationTest {

private static final String PROPERTY_NAME = "property-name";
private static final String PROPERTY_VALUE = "property-value";
Expand Down Expand Up @@ -244,52 +246,37 @@ public void testActivateHvdcAngleDroopActivePowerControl() throws Exception {
Assert.assertTrue(activePowerControl.isEnabled());
}

@Test
public void testActivateHvdcAngleDroopActivePowerControlWithNullValues() {
@ParameterizedTest(name = "Test lack of provided values")
@CsvSource({
"true,false,false",
"true,true,false",
"true,false,true",
"false,true,false",
"false,true,true",
"false,false,true",
})
void testHvdcAngleDroopActivePowerControlWithNullValues(boolean isNullAngleDroopActivePowerControl, boolean isNullDroop, boolean isNullP0) {
var networkuuid = UUID.randomUUID();
Network networkWithoutExt = NetworkCreation.createWithVSC(networkuuid, false);
VscModificationInfos wrongModificationInfos = (VscModificationInfos) buildModification();
wrongModificationInfos.setDroop(null);
wrongModificationInfos.setP0(null);
wrongModificationInfos.setAngleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET));
VscModification wrongVscModification = new VscModification(wrongModificationInfos);
String message = Assert.assertThrows(NetworkModificationException.class,
() -> wrongVscModification.check(networkWithoutExt))
.getMessage();
assertThat(message).isEqualTo(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL.name() + " : " +
String.format(DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG));
}

@Test
public void testActivateHvdcAngleDroopActivePowerControlWithDroopNull() {
var networkuuid = UUID.randomUUID();
Network networkWithoutExt = NetworkCreation.createWithVSC(networkuuid, false);
VscModificationInfos wrongModificationInfos = (VscModificationInfos) buildModification();
wrongModificationInfos.setDroop(null);
wrongModificationInfos.setP0(new AttributeModification<>(100f, OperationType.SET));
wrongModificationInfos.setAngleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET));
VscModification wrongVscModification = new VscModification(wrongModificationInfos);
String message = Assert.assertThrows(NetworkModificationException.class,
() -> wrongVscModification.check(networkWithoutExt))
.getMessage();
assertThat(message).isEqualTo(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL.name() + " : " +
String.format(DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG));
}
// reset null depending to test arguments
if (isNullAngleDroopActivePowerControl) {
wrongModificationInfos.setAngleDroopActivePowerControl(null);
}
if (isNullDroop) {
wrongModificationInfos.setDroop(null);
}
if (isNullP0) {
wrongModificationInfos.setP0(null);
}

@Test
public void testActivateHvdcAngleDroopActivePowerControlWithP0Null() {
var networkuuid = UUID.randomUUID();
Network networkWithoutExt = NetworkCreation.createWithVSC(networkuuid, false);
VscModificationInfos wrongModificationInfos = (VscModificationInfos) buildModification();
wrongModificationInfos.setDroop(new AttributeModification<>(20f, OperationType.SET));
wrongModificationInfos.setP0(null);
wrongModificationInfos.setAngleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET));
VscModification wrongVscModification = new VscModification(wrongModificationInfos);
String message = Assert.assertThrows(NetworkModificationException.class,
() -> wrongVscModification.check(networkWithoutExt))
.getMessage();
assertThat(message).isEqualTo(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL.name() + " : "
+ String.format(DROOP_ACTIVE_POWER_CONTROL_P0_DROOP_REQUIRED_ERROR_MSG));
+ ACTIVE_POWER_CONTROL_DROOP_P0_REQUIRED_ERROR_MSG);
}

@Test
Expand All @@ -313,27 +300,6 @@ public void testUnchangedHvdcAngleDroopActivePowerControl() throws Exception {
Assert.assertTrue(activePowerControl.isEnabled());
}

@Test
public void testHvdcAngleDroopActivePowerControlWithoutP0() {
var networkuuid = UUID.randomUUID();
Network networkWithExt = NetworkCreation.createWithVSC(networkuuid, true);
VscModificationInfos modificationInfos = (VscModificationInfos) buildModification();
modificationInfos.setAngleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET));
{ //Test : p0 should be required if drop is changed
modificationInfos.setDroop(new AttributeModification<>(10F, OperationType.SET));
modificationInfos.setP0(null);
VscModification vscModification = new VscModification(modificationInfos);
Assert.assertThrows(NetworkModificationException.class, () -> vscModification.check(networkWithExt));
}
{ //Test : p0 should not be required if drop unchanged
modificationInfos.setDroop(null);
modificationInfos.setP0(null);
VscModification vscModification = new VscModification(modificationInfos);
assertDoesNotThrow(() -> vscModification.check(networkWithExt));

}
}

@Override
@SneakyThrows
protected void testUpdateModificationMessage(ModificationInfos modificationInfos) {
Expand Down
Loading