-
Notifications
You must be signed in to change notification settings - Fork 5
/
EmInputFactoryTest.groovy
114 lines (100 loc) · 4.07 KB
/
EmInputFactoryTest.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* © 2022. 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.participant
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.io.factory.input.EmAssetInputEntityData
import edu.ie3.datamodel.models.input.EmInput
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.utils.Try
import spock.lang.Specification
import java.time.ZonedDateTime
class EmInputFactoryTest extends Specification {
def "A EmInputFactory should contain exactly the expected class for parsing"() {
given:
def inputFactory = new EmInputFactory()
def expectedClasses = [EmInput] as List
expect:
inputFactory.supportedClasses == expectedClasses
}
def "A EmInputFactory should parse a valid EmInput with parent EM correctly"() {
given:
def inputFactory = new EmInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"operatesfrom" : "2019-01-01T00:00:00+01:00[Europe/Berlin]",
"operatesuntil" : "2019-12-31T23:59:00+01:00[Europe/Berlin]",
"id" : "TestID",
"controlstrategy" : "no_control"
]
def inputClass = EmInput
def operatorInput = Mock(OperatorInput)
def parentEmUnit = Mock(EmInput)
when:
Try<EmInput, FactoryException> input = inputFactory.get(
new EmAssetInputEntityData(parameter, inputClass, operatorInput, parentEmUnit))
then:
input.success
input.data.get().getClass() == inputClass
input.data.get().with {
assert uuid == UUID.fromString(parameter["uuid"])
assert operationTime.startDate.present
assert operationTime.startDate.get() == ZonedDateTime.parse(parameter["operatesfrom"])
assert operationTime.endDate.present
assert operationTime.endDate.get() == ZonedDateTime.parse(parameter["operatesuntil"])
assert operator == operatorInput
assert id == parameter["id"]
assert controlStrategy == parameter["controlstrategy"]
assert parentEm == parentEmUnit
}
}
def "A EmInputFactory should parse a valid EmInput without parent EM correctly"() {
given:
def inputFactory = new EmInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"operatesfrom" : "2019-01-01T00:00:00+01:00[Europe/Berlin]",
"operatesuntil" : "2019-12-31T23:59:00+01:00[Europe/Berlin]",
"id" : "TestID",
"controlstrategy" : "no_control"
]
def inputClass = EmInput
def operatorInput = Mock(OperatorInput)
when:
Try<EmInput, FactoryException> input = inputFactory.get(
new EmAssetInputEntityData(parameter, inputClass, operatorInput, null))
then:
input.success
input.data.get().getClass() == inputClass
input.data.get().with {
assert uuid == UUID.fromString(parameter["uuid"])
assert operationTime.startDate.present
assert operationTime.startDate.get() == ZonedDateTime.parse(parameter["operatesfrom"])
assert operationTime.endDate.present
assert operationTime.endDate.get() == ZonedDateTime.parse(parameter["operatesuntil"])
assert operator == operatorInput
assert id == parameter["id"]
assert controlStrategy == parameter["controlstrategy"]
assert parentEm == null
}
}
def "A EmInputFactory should fail when passing an invalid UUID"() {
given:
def inputFactory = new EmInputFactory()
Map<String, String> parameter = [
"uuid" : "- broken -",
"id" : "TestID",
"controlstrategy" : "no_control"
]
def inputClass = EmInput
def operatorInput = Mock(OperatorInput)
when:
Try<EmInput, FactoryException> input = inputFactory.get(
new EmAssetInputEntityData(parameter, inputClass, operatorInput, null))
then:
input.failure
input.exception.get().cause.message == "Exception while trying to parse UUID of field \"uuid\" with value \"- broken -\""
}
}