-
Notifications
You must be signed in to change notification settings - Fork 5
/
NodeInputFactoryTest.groovy
69 lines (62 loc) · 2.74 KB
/
NodeInputFactoryTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.io.factory.input
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.datamodel.models.input.NodeInput
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils
import edu.ie3.datamodel.utils.Try
import edu.ie3.test.helper.FactoryTestHelper
import spock.lang.Specification
import tech.units.indriya.ComparableQuantity
import javax.measure.quantity.ElectricPotential
import java.time.ZonedDateTime
class NodeInputFactoryTest extends Specification implements FactoryTestHelper {
def "A NodeInputFactory should contain exactly the expected class for parsing"() {
given:
def inputFactory = new NodeInputFactory()
def expectedClasses = [NodeInput]
expect:
inputFactory.supportedClasses == Arrays.asList(expectedClasses.toArray())
}
def "A NodeInputFactory should parse a valid NodeInput correctly"() {
given: "a system participant input type factory and model data"
def inputFactory = new NodeInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"operatesfrom" : "2019-01-01T00:00:00+01:00[Europe/Berlin]",
"operatesuntil": "",
"id" : "TestID",
"vtarget" : "2",
"vrated" : "3",
"slack" : "true",
"geoposition" : "{ \"type\": \"Point\", \"coordinates\": [7.411111, 51.492528] }",
"voltlvl" : "lv",
"subnet" : "7"
]
def inputClass = NodeInput
def operatorInput = Mock(OperatorInput)
when:
Try<NodeInput, FactoryException> input = inputFactory.get(new AssetInputEntityData(parameter, inputClass, operatorInput))
then:
input.success
input.data().getClass() == inputClass
((NodeInput) input.data()).with {
assert uuid == UUID.fromString(parameter["uuid"])
assert operationTime.startDate.present
assert operationTime.startDate.get() == ZonedDateTime.parse(parameter["operatesfrom"])
assert !operationTime.endDate.present
assert operator == operatorInput
assert id == parameter["id"]
assert vTarget == getQuant(parameter["vtarget"], StandardUnits.TARGET_VOLTAGE_MAGNITUDE)
assert slack
assert geoPosition == getGeometry(parameter["geoposition"])
assert voltLvl == GermanVoltageLevelUtils.parse(parameter["voltlvl"], getQuant(parameter["vrated"], StandardUnits.RATED_VOLTAGE_MAGNITUDE) as ComparableQuantity<ElectricPotential>)
assert subnet == Integer.parseInt(parameter["subnet"])
}
}
}