-
Notifications
You must be signed in to change notification settings - Fork 5
/
SystemParticipantTypeInputFactoryTest.groovy
296 lines (252 loc) · 12.5 KB
/
SystemParticipantTypeInputFactoryTest.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
* © 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.typeinput
import static edu.ie3.util.quantities.PowerSystemUnits.METRE_PER_SECOND
import static edu.ie3.util.quantities.PowerSystemUnits.PU
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.io.factory.EntityData
import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.datamodel.models.input.system.characteristic.CharacteristicPoint
import edu.ie3.datamodel.models.input.system.type.*
import edu.ie3.datamodel.utils.Try
import edu.ie3.test.helper.FactoryTestHelper
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities
import javax.measure.quantity.Dimensionless
import javax.measure.quantity.Speed
class SystemParticipantTypeInputFactoryTest extends Specification implements FactoryTestHelper {
def "A SystemParticipantTypeInputFactory should contain all expected classes for parsing"() {
given:
def typeInputFactory = new SystemParticipantTypeInputFactory()
def expectedClasses = [
EvTypeInput,
HpTypeInput,
BmTypeInput,
WecTypeInput,
ChpTypeInput,
StorageTypeInput
]
expect:
typeInputFactory.supportedClasses == Arrays.asList(expectedClasses.toArray())
}
def "A SystemParticipantTypeInputFactory should parse a valid EvTypeInput correctly"() {
given: "a system participant input type factory and model data"
def typeInputFactory = new SystemParticipantTypeInputFactory()
Map<String, String> parameter = [
"uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"id": "blablub",
"capex": "3",
"opex": "4",
"srated": "5",
"cosPhiRated": "6",
"estorage": "7",
"econs": "8",
"srateddc": "9",
]
def typeInputClass = EvTypeInput
when:
Try<? extends SystemParticipantTypeInput, FactoryException> typeInput = typeInputFactory.get(new EntityData(parameter, typeInputClass))
then:
typeInput.success
typeInput.data.get().getClass() == typeInputClass
((EvTypeInput) typeInput.data.get()).with {
assert uuid == UUID.fromString(parameter["uuid"])
assert id == parameter["id"]
assert capex == getQuant(parameter["capex"], StandardUnits.CAPEX)
assert opex == getQuant(parameter["opex"], StandardUnits.ENERGY_PRICE)
assert sRated == getQuant(parameter["srated"], StandardUnits.S_RATED)
assert cosPhiRated == Double.parseDouble(parameter["cosPhiRated"])
assert eStorage == getQuant(parameter["estorage"], StandardUnits.ENERGY_IN)
assert eCons == getQuant(parameter["econs"], StandardUnits.ENERGY_PER_DISTANCE)
assert sRatedDC == getQuant(parameter["srateddc"], StandardUnits.ACTIVE_POWER_IN)
}
}
def "A SystemParticipantTypeInputFactory should parse a valid HpTypeInput correctly"() {
given: "a system participant input type factory and model data"
def typeInputFactory = new SystemParticipantTypeInputFactory()
Map<String, String> parameter = [
"uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"id": "blablub",
"capex": "3",
"opex": "4",
"srated": "5",
"cosPhiRated": "6",
"pthermal": "7",
]
def typeInputClass = HpTypeInput
when:
Try<? extends SystemParticipantTypeInput, FactoryException> typeInput = typeInputFactory.get(new EntityData(parameter, typeInputClass))
then:
typeInput.success
typeInput.data.get().getClass() == typeInputClass
((HpTypeInput) typeInput.data.get()).with {
assert uuid == UUID.fromString(parameter["uuid"])
assert id == parameter["id"]
assert capex == getQuant(parameter["capex"], StandardUnits.CAPEX)
assert opex == getQuant(parameter["opex"], StandardUnits.ENERGY_PRICE)
assert sRated == getQuant(parameter["srated"], StandardUnits.S_RATED)
assert cosPhiRated == Double.parseDouble(parameter["cosPhiRated"])
assert pThermal == getQuant(parameter["pthermal"], StandardUnits.ACTIVE_POWER_IN)
}
}
def "A SystemParticipantTypeInputFactory should parse a valid BmTypeInput correctly"() {
given: "a system participant input type factory and model data"
def typeInputFactory = new SystemParticipantTypeInputFactory()
Map<String, String> parameter = [
"uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"id": "blablub",
"capex": "3",
"opex": "4",
"srated": "5",
"cosPhiRated": "6",
"activepowergradient": "7",
"etaconv": "8"
]
def typeInputClass = BmTypeInput
when:
Try<? extends SystemParticipantTypeInput, FactoryException> typeInput = typeInputFactory.get(new EntityData(parameter, typeInputClass))
then:
typeInput.success
typeInput.data.get().getClass() == typeInputClass
((BmTypeInput) typeInput.data.get()).with {
assert uuid == UUID.fromString(parameter["uuid"])
assert id == parameter["id"]
assert capex == getQuant(parameter["capex"], StandardUnits.CAPEX)
assert opex == getQuant(parameter["opex"], StandardUnits.ENERGY_PRICE)
assert sRated == getQuant(parameter["srated"], StandardUnits.S_RATED)
assert cosPhiRated == Double.parseDouble(parameter["cosPhiRated"])
assert activePowerGradient == getQuant(parameter["activepowergradient"], StandardUnits.ACTIVE_POWER_GRADIENT)
assert etaConv == getQuant(parameter["etaconv"], StandardUnits.EFFICIENCY)
}
}
def "A SystemParticipantTypeInputFactory should parse a valid WecTypeInput correctly"() {
given: "a system participant input type factory and model data"
def typeInputFactory = new SystemParticipantTypeInputFactory()
Map<String, String> parameter = [
"uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"id": "blablub",
"capex": "3",
"opex": "4",
"srated": "5",
"cosPhiRated": "6",
"cpCharacteristic": "cP:{(10.00,0.05),(15.00,0.10),(20.00,0.20)}",
"etaconv": "7",
"rotorarea": "8",
"hubheight": "9"
]
def typeInputClass = WecTypeInput
when:
Try<? extends SystemParticipantTypeInput, FactoryException> typeInput = typeInputFactory.get(new EntityData(parameter, typeInputClass))
then:
typeInput.success
typeInput.data.get().getClass() == typeInputClass
((WecTypeInput) typeInput.data.get()).with {
assert uuid == UUID.fromString(parameter["uuid"])
assert id == parameter["id"]
assert capex == getQuant(parameter["capex"], StandardUnits.CAPEX)
assert opex == getQuant(parameter["opex"], StandardUnits.ENERGY_PRICE)
assert sRated == getQuant(parameter["srated"], StandardUnits.S_RATED)
assert cosPhiRated == Double.parseDouble(parameter["cosPhiRated"])
cpCharacteristic.with {
assert uuid != null
assert points == Collections.unmodifiableSortedSet([
new CharacteristicPoint<Speed, Dimensionless>(Quantities.getQuantity(10d, METRE_PER_SECOND), Quantities.getQuantity(0.05, PU)),
new CharacteristicPoint<Speed, Dimensionless>(Quantities.getQuantity(15d, METRE_PER_SECOND), Quantities.getQuantity(0.1, PU)),
new CharacteristicPoint<Speed, Dimensionless>(Quantities.getQuantity(20d, METRE_PER_SECOND), Quantities.getQuantity(0.2, PU))
] as TreeSet)
}
assert etaConv == getQuant(parameter["etaconv"], StandardUnits.EFFICIENCY)
assert rotorArea == getQuant(parameter["rotorarea"], StandardUnits.ROTOR_AREA)
assert hubHeight == getQuant(parameter["hubheight"], StandardUnits.HUB_HEIGHT)
}
}
def "A SystemParticipantTypeInputFactory should parse a valid ChpTypeInput correctly"() {
given: "a system participant input type factory and model data"
def typeInputFactory = new SystemParticipantTypeInputFactory()
Map<String, String> parameter = [
"uuid": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"id": "blablub",
"capex": "3",
"opex": "4",
"srated": "5",
"cosPhiRated": "6",
"etael": "7",
"etathermal": "8",
"pthermal": "9",
"pown": "10"
]
def typeInputClass = ChpTypeInput
when:
Try<? extends SystemParticipantTypeInput, FactoryException> typeInput = typeInputFactory.get(new EntityData(parameter, typeInputClass))
then:
typeInput.success
typeInput.data.get().getClass() == typeInputClass
((ChpTypeInput) typeInput.data.get()).with {
assert uuid == UUID.fromString(parameter["uuid"])
assert id == parameter["id"]
assert capex == getQuant(parameter["capex"], StandardUnits.CAPEX)
assert opex == getQuant(parameter["opex"], StandardUnits.ENERGY_PRICE)
assert sRated == getQuant(parameter["srated"], StandardUnits.S_RATED)
assert cosPhiRated == Double.parseDouble(parameter["cosPhiRated"])
assert etaEl == getQuant(parameter["etael"], StandardUnits.EFFICIENCY)
assert etaThermal == getQuant(parameter["etathermal"], StandardUnits.EFFICIENCY)
assert pThermal == getQuant(parameter["pthermal"], StandardUnits.ACTIVE_POWER_IN)
assert pOwn == getQuant(parameter["pown"], StandardUnits.ACTIVE_POWER_IN)
}
}
def "A SystemParticipantTypeInputFactory should parse a valid StorageTypeInput correctly"() {
given: "a system participant input type factory and model data"
def typeInputFactory = new SystemParticipantTypeInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"id" : "blablub",
"capex" : "3",
"opex" : "4",
"srated" : "5",
"cosPhiRated" : "6",
"estorage" : "6",
"pmax" : "8",
"activepowergradient" : "1",
"eta" : "9",
"dod" : "10",
"lifetime" : "11",
"lifecycle" : "12"
]
def typeInputClass = StorageTypeInput
when:
Try<? extends SystemParticipantTypeInput, FactoryException> typeInput = typeInputFactory.get(new EntityData(parameter, typeInputClass))
then:
typeInput.success
typeInput.data.get().getClass() == typeInputClass
((StorageTypeInput) typeInput.data.get()).with {
assert uuid == UUID.fromString(parameter["uuid"])
assert id == parameter["id"]
assert capex == getQuant(parameter["capex"], StandardUnits.CAPEX)
assert opex == getQuant(parameter["opex"], StandardUnits.ENERGY_PRICE)
assert sRated == getQuant(parameter["srated"], StandardUnits.S_RATED)
assert cosPhiRated == Double.parseDouble(parameter["cosPhiRated"])
assert eStorage == getQuant(parameter["estorage"], StandardUnits.ENERGY_IN)
assert pMax == getQuant(parameter["pmax"], StandardUnits.ACTIVE_POWER_IN)
assert activePowerGradient == getQuant(parameter["activepowergradient"], StandardUnits.ACTIVE_POWER_GRADIENT)
assert eta == getQuant(parameter["eta"], StandardUnits.EFFICIENCY)
assert dod == getQuant(parameter["dod"], StandardUnits.DOD)
assert lifeTime == getQuant(parameter["lifetime"], StandardUnits.LIFE_TIME)
assert lifeCycle == Integer.parseInt(parameter["lifecycle"])
}
}
def "A SystemParticipantTypeInputFactory should throw an exception on invalid or incomplete data"() {
given: "a system participant factory and model data"
def typeInputFactory = new SystemParticipantTypeInputFactory()
def actualFields = SystemParticipantTypeInputFactory.newSet("uuid", "id", "capex", "opex", "srated", "cosPhiRated", "estorage", "pmin", "pmax", "eta", "dod", "lifetime",)
when:
def input = typeInputFactory.validate(actualFields, StorageTypeInput)
then:
input.failure
input.exception.get().message == "The provided fields [capex, cosPhiRated, dod, estorage, eta, id, lifetime, opex, pmax, pmin, srated, uuid] are invalid for instance of 'StorageTypeInput'. \n" +
"The following fields (without complex objects e.g. nodes, operators, ...) to be passed to a constructor of 'StorageTypeInput' are possible (NOT case-sensitive!):\n" +
"0: [activePowerGradient, capex, cosPhiRated, dod, eStorage, eta, id, lifeCycle, lifeTime, opex, pMax, sRated, uuid] or [active_power_gradient, capex, cos_phi_rated, dod, e_storage, eta, id, life_cycle, life_time, opex, p_max, s_rated, uuid]\n"
}
}