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

Do not allow switches with the same node or bus at both ends. #1991

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public Switch add() {
if (busId2 == null) {
throw new ValidationException(this, "second connection bus is not set");
}
if (busId1.equals(busId2)) {
throw new ValidationException(this, "same bus at both ends");
}

SwitchImpl aSwitch = new SwitchImpl(BusBreakerVoltageLevel.this, id, getName(), isFictitious(), SwitchKind.BREAKER, open, true);
addSwitch(aSwitch, busId1, busId2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public Switch add() {
if (node2 == null) {
throw new ValidationException(this, "second connection node is not set");
}
if (node1.equals(node2)) {
throw new ValidationException(this, "same node at both ends");
}
if (kind == null) {
throw new ValidationException(this, "kind is not set");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2022, 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 com.powsybl.iidm.network.impl.tck;

import com.powsybl.iidm.network.tck.AbstractSwitchBusBreakerTest;

public class SwitchBusBreakerTest extends AbstractSwitchBusBreakerTest { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2022, 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 com.powsybl.iidm.network.impl.tck;

import com.powsybl.iidm.network.tck.AbstractSwitchNodeBreakerTest;

public class SwitchNodeBreakerTest extends AbstractSwitchNodeBreakerTest { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2022, 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 com.powsybl.iidm.network.tck;

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.BatteryNetworkFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public abstract class AbstractSwitchBusBreakerTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

private Network network;
private VoltageLevel voltageLevel;

@Before
public void initNetwork() {
network = BatteryNetworkFactory.create();
voltageLevel = network.getVoltageLevel("VLGEN");
}

@Test
public void addSwitchWithSameBusAtBothEnds() {
thrown.expect(ValidationException.class);
thrown.expectMessage("Switch 'Sw1': same bus at both ends");
Bus bus = voltageLevel.getBusBreakerView().getBus("NGEN");
voltageLevel.getBusBreakerView().newSwitch()
.setId("Sw1")
.setBus1(bus.getId())
.setBus2(bus.getId())
.add();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2022, 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 com.powsybl.iidm.network.tck;

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.FictitiousSwitchFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public abstract class AbstractSwitchNodeBreakerTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

private Network network;
private VoltageLevel voltageLevel;

@Before
public void initNetwork() {
network = FictitiousSwitchFactory.create();
voltageLevel = network.getVoltageLevel("C");
}

@Test
public void addSwitchWithSameNodeAtBothEnds() {
thrown.expect(ValidationException.class);
thrown.expectMessage("Switch 'Sw1': same node at both ends");
int newNode = voltageLevel.getNodeBreakerView().getMaximumNodeIndex() + 1;
voltageLevel.getNodeBreakerView().newSwitch()
.setId("Sw1")
.setNode1(newNode)
.setNode2(newNode)
.setKind(SwitchKind.BREAKER)
.add();
}

@Test
public void addSwitchWithNullKind() {
thrown.expect(ValidationException.class);
thrown.expectMessage("Switch 'Sw1': kind is not set");
int newNode1 = voltageLevel.getNodeBreakerView().getMaximumNodeIndex() + 1;
int newNode2 = newNode1 + 1;
voltageLevel.getNodeBreakerView().newSwitch()
.setId("Sw1")
.setNode1(newNode1)
.setNode2(newNode2)
.add();
}
}