Skip to content

Commit 3796635

Browse files
authored
Merge pull request #383 from ie3-institute/to/#380-null-handling-operation-time
to/#380 null handling operation time
2 parents b2f3b95 + 1724e02 commit 3796635

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

docs/readthedocs/models/models.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ Equality Checks
8080
If you think you would benefit from such a method, please consider handing in an issue
8181
`here <https://github.com/ie3-institute/PowerSystemUtils/issues>`_.
8282

83+
Conditional Parameters
84+
Some of the models have conditional parameters. When reading model data from a data source, their respective factories for building these
85+
models can handle nulls and empty Strings (as well as any combination of those) safely. E.g.: When given parameters for a line's
86+
:code:`operationTime` where :code:`operationStartTime` and :code:`operationEndTime` are both :code:`null` or :code:`""`, the
87+
factory will build an always-on line model.
88+
8389
*****
8490
Input
8591
*****

src/test/groovy/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactoryTest.groovy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,39 @@ class AssetInputEntityFactoryTest extends Specification implements FactoryTestHe
5353
}
5454
}
5555
56+
def "An AssetInputFactory should parse a valid operated AssetInput correctly (with nulls and empty strings)"() {
57+
given: "a system participant input type factory and model data"
58+
def inputFactory = new TestAssetInputFactory()
59+
Map<String, String> parameter = [
60+
"uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
61+
"operatesfrom" : operatesfrom,
62+
"operatesuntil": operatesuntil,
63+
"id" : "TestID"
64+
]
65+
def inputClass = TestAssetInput
66+
def operatorInput = Mock(OperatorInput)
67+
68+
when:
69+
Optional<TestAssetInput> input = inputFactory.get(new AssetInputEntityData(parameter, inputClass, operatorInput))
70+
71+
then:
72+
input.present
73+
input.get().getClass() == inputClass
74+
((TestAssetInput) input.get()).with {
75+
assert uuid == UUID.fromString(parameter["uuid"])
76+
assert operationTime == OperationTime.notLimited()
77+
assert operator == operatorInput
78+
assert id == parameter["id"]
79+
}
80+
81+
where:
82+
operatesfrom | operatesuntil
83+
null | null
84+
"" | null
85+
null | ""
86+
"" | ""
87+
}
88+
5689
def "An AssetInputFactory should parse a valid operated AssetInput correctly (operation start time provided)"() {
5790
given: "a system participant input type factory and model data"
5891
def inputFactory = new TestAssetInputFactory()

0 commit comments

Comments
 (0)