Skip to content

Commit 1024473

Browse files
Merge pull request #1090 from ie3-institute/ms/#1077-gridValidation-should-check-number-of-parallelDevices
`ConnectorValidationUtils` checks if parallel devices is > 0
2 parents 91ca1eb + 1b26b12 commit 1024473

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- Enhancing `VoltageLevel` with `equals` method [#1063](https://github.com/ie3-institute/PowerSystemDataModel/issues/1063)
11+
- `ConnectorValidationUtils` checks if parallel devices is > 0 [#1077](https://github.com/ie3-institute/PowerSystemDataModel/issues/1077)
1112

1213
### Fixed
1314
- Fixed `MappingEntryies` not getting processed by adding `Getter` methods for record fields [#1084](https://github.com/ie3-institute/PowerSystemDataModel/issues/1084)

src/main/java/edu/ie3/datamodel/utils/validation/ConnectorValidationUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ protected static List<Try<Void, InvalidEntityException>> check(ConnectorInput co
6565

6666
List<Try<Void, InvalidEntityException>> exceptions = new ArrayList<>();
6767
exceptions.add(connectsDifferentNodes(connector));
68+
exceptions.add(lessThanOneParallelDevice(connector));
6869

6970
// Further checks for subclasses
7071
if (LineInput.class.isAssignableFrom(connector.getClass())) {
@@ -443,6 +444,23 @@ private static Try<Void, InvalidEntityException> connectsDifferentNodes(
443444
connectorInput));
444445
}
445446

447+
/**
448+
* Check that the given connector has at least one parallel device.
449+
*
450+
* @param connectorInput to check
451+
* @return a try
452+
*/
453+
private static Try<Void, InvalidEntityException> lessThanOneParallelDevice(
454+
ConnectorInput connectorInput) {
455+
return Try.ofVoid(
456+
connectorInput.getParallelDevices() < 1,
457+
() ->
458+
new InvalidEntityException(
459+
connectorInput.getClass().getSimpleName()
460+
+ " needs to have at least one parallel device",
461+
connectorInput));
462+
}
463+
446464
/**
447465
* Check if subnets of connector's nodes are correct depending on if they should be equal or not
448466
*

src/test/groovy/edu/ie3/datamodel/utils/validation/ConnectorValidationUtilsTest.groovy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ class ConnectorValidationUtilsTest extends Specification {
6262
OlmCharacteristicInput.CONSTANT_CHARACTERISTIC
6363
)
6464

65+
def "A ConnectorInput needs at least one parallel device"() {
66+
when:
67+
def actual = ConnectorValidationUtils.lessThanOneParallelDevice(invalidConnector)
68+
69+
then:
70+
actual.failure
71+
actual.exception.get().class == InvalidEntityException
72+
actual.exception.get().message.contains(expectedMessage)
73+
74+
where:
75+
invalidConnector || expectedMessage
76+
GridTestData.lineFtoG.copy().parallelDevices(0).build() || "LineInput needs to have at least one parallel device"
77+
GridTestData.lineCtoD.copy().parallelDevices(-1).build() || "LineInput needs to have at least one parallel device"
78+
GridTestData.transformerBtoE.copy().parallelDevices(0).build() || "Transformer2WInput needs to have at least one parallel device"
79+
GridTestData.transformerAtoBtoC.copy().parallelDevices(0).build() || "Transformer3WInput needs to have at least one parallel device"
80+
}
81+
6582
def "ConnectorValidationUtils.checkLine() recognizes all potential errors for a line"() {
6683
when:
6784
List<Try<Void, InvalidEntityException>> exceptions = ConnectorValidationUtils.check(invalidLine).stream().filter { it -> it.failure }.toList()

0 commit comments

Comments
 (0)