-
Notifications
You must be signed in to change notification settings - Fork 5
/
TimeBasedSimpleValueFactoryTest.groovy
237 lines (211 loc) · 7.58 KB
/
TimeBasedSimpleValueFactoryTest.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
* © 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.timeseries
import static edu.ie3.datamodel.io.factory.timeseries.TimeBasedSimpleValueFactory.*
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.datamodel.models.input.NodeInput
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
import edu.ie3.datamodel.models.value.*
import edu.ie3.util.TimeUtil
import spock.lang.Shared
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities
import java.time.ZoneId
class TimeBasedSimpleValueFactoryTest extends Specification {
@Shared
TimeUtil defaultTimeUtil
def setupSpec() {
defaultTimeUtil = new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'")
}
def "The simple time based value factory provides correct fields"() {
given:
def factory = new TimeBasedSimpleValueFactory(valueClass)
def data = Mock(SimpleTimeBasedValueData)
data.targetClass >> valueClass
expect:
factory.getFields(data.targetClass) == expectedFields
where:
valueClass || expectedFields
EnergyPriceValue || [
[
TimeBasedSimpleValueFactory.UUID,
TIME,
PRICE
] as Set
]
SValue || [
[
TimeBasedSimpleValueFactory.UUID,
TIME,
ACTIVE_POWER,
REACTIVE_POWER
] as Set
]
PValue || [
[
TimeBasedSimpleValueFactory.UUID,
TIME,
ACTIVE_POWER
] as Set
]
HeatAndSValue || [
[
TimeBasedSimpleValueFactory.UUID,
TIME,
ACTIVE_POWER,
REACTIVE_POWER,
HEAT_DEMAND
] as Set
]
HeatAndPValue || [
[
TimeBasedSimpleValueFactory.UUID,
TIME,
ACTIVE_POWER,
HEAT_DEMAND
] as Set
]
HeatDemandValue || [
[
TimeBasedSimpleValueFactory.UUID,
TIME,
HEAT_DEMAND
] as Set
]
}
def "The simple time based value factory throws a FactoryException upon request of fields, if a class is not supported"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def data = Mock(SimpleTimeBasedValueData)
data.targetClass >> NodeInput
when:
factory.getFields(data.targetClass)
then:
def e = thrown(FactoryException)
e.message == "The given factory cannot handle target class '" + NodeInput + "'."
}
def "The simple time based value factory builds correct energy price value"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")
def data = new SimpleTimeBasedValueData([
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
"time": defaultTimeUtil.toString(time),
"price": "52.4"
], EnergyPriceValue)
def expected = new TimeBasedValue(
UUID.fromString("78ca078a-e6e9-4972-a58d-b2cadbc2df2c"),
time,
new EnergyPriceValue(Quantities.getQuantity(52.4, StandardUnits.ENERGY_PRICE))
)
expect:
factory.buildModel(data) == expected
}
def "The simple time based value factory builds correct heat and apparent power value"() {
given:
def factory = new TimeBasedSimpleValueFactory(HeatAndSValue)
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")
def data = new SimpleTimeBasedValueData([
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
"time": defaultTimeUtil.toString(time),
"p": "500.0",
"q": "165.0",
"heatDemand": "8.0"
], HeatAndSValue)
def expected = new TimeBasedValue(
UUID.fromString("78ca078a-e6e9-4972-a58d-b2cadbc2df2c"),
time,
new HeatAndSValue(Quantities.getQuantity(500.0, StandardUnits.ACTIVE_POWER_IN), Quantities.getQuantity(165.0, StandardUnits.REACTIVE_POWER_IN), Quantities.getQuantity(8.0, StandardUnits.HEAT_DEMAND))
)
expect:
factory.buildModel(data) == expected
}
def "The simple time based value factory builds correct heat and active power value"() {
given:
def factory = new TimeBasedSimpleValueFactory(HeatAndPValue)
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")
def data = new SimpleTimeBasedValueData([
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
"time": defaultTimeUtil.toString(time),
"p": "500.0",
"heatDemand": "8.0"
], HeatAndPValue)
def expected = new TimeBasedValue(
UUID.fromString("78ca078a-e6e9-4972-a58d-b2cadbc2df2c"),
time,
new HeatAndPValue(Quantities.getQuantity(500.0, StandardUnits.ACTIVE_POWER_IN), Quantities.getQuantity(8.0, StandardUnits.HEAT_DEMAND))
)
expect:
factory.buildModel(data) == expected
}
def "The simple time based value factory builds correct heat demand value"() {
given:
def factory = new TimeBasedSimpleValueFactory(HeatDemandValue)
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")
def data = new SimpleTimeBasedValueData([
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
"time": defaultTimeUtil.toString(time),
"heatDemand": "8.0"
], HeatDemandValue)
def expected = new TimeBasedValue(
UUID.fromString("78ca078a-e6e9-4972-a58d-b2cadbc2df2c"),
time,
new HeatDemandValue(Quantities.getQuantity(8.0, StandardUnits.HEAT_DEMAND))
)
expect:
factory.buildModel(data) == expected
}
def "The simple time based value factory builds correct apparent power value"() {
given:
def factory = new TimeBasedSimpleValueFactory(SValue)
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")
def data = new SimpleTimeBasedValueData([
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
"time": defaultTimeUtil.toString(time),
"p": "500.0",
"q": "165.0"
], SValue)
def expected = new TimeBasedValue(
UUID.fromString("78ca078a-e6e9-4972-a58d-b2cadbc2df2c"),
time,
new SValue(Quantities.getQuantity(500.0, StandardUnits.ACTIVE_POWER_IN), Quantities.getQuantity(165.0, StandardUnits.REACTIVE_POWER_IN))
)
expect:
factory.buildModel(data) == expected
}
def "The simple time based value factory builds correct active power value"() {
given:
def factory = new TimeBasedSimpleValueFactory(PValue)
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")
def data = new SimpleTimeBasedValueData([
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
"time": defaultTimeUtil.toString(time),
"p": "500.0"
], PValue)
def expected = new TimeBasedValue(
UUID.fromString("78ca078a-e6e9-4972-a58d-b2cadbc2df2c"),
time,
new PValue(Quantities.getQuantity(500.0, StandardUnits.ACTIVE_POWER_IN))
)
expect:
factory.buildModel(data) == expected
}
def "The simple time based value factory throws a FactoryException upon build request, if a class is not supported"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")
def data = new SimpleTimeBasedValueData([
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
"time": defaultTimeUtil.toString(time)
], NodeInput)
when:
factory.buildModel(data)
then:
def e = thrown(FactoryException)
e.message == "The given factory cannot handle target class '" + NodeInput + "'."
}
}