-
Notifications
You must be signed in to change notification settings - Fork 5
/
SystemParticipantValidationUtilsTest.groovy
485 lines (368 loc) · 21.5 KB
/
SystemParticipantValidationUtilsTest.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.utils.validation
import edu.ie3.datamodel.exceptions.InvalidEntityException
import edu.ie3.datamodel.exceptions.NotImplementedException
import edu.ie3.datamodel.models.input.NodeInput
import edu.ie3.datamodel.models.input.system.characteristic.WecCharacteristicInput
import edu.ie3.datamodel.models.input.system.type.*
import edu.ie3.test.common.SystemParticipantTestData
import edu.ie3.util.quantities.interfaces.Currency
import edu.ie3.util.quantities.interfaces.DimensionlessRate
import edu.ie3.util.quantities.interfaces.EnergyPrice
import spock.lang.Specification
import tech.units.indriya.ComparableQuantity
import tech.units.indriya.quantity.Quantities
import javax.measure.quantity.*
import static edu.ie3.datamodel.models.StandardUnits.*
import static tech.units.indriya.unit.Units.PERCENT
class SystemParticipantValidationUtilsTest extends Specification {
def "Instantiating a ConnectorValidationUtil leads to an exception"() {
when:
new SystemParticipantValidationUtils()
then:
def e = thrown(IllegalStateException)
e.message == "Don't try and instantiate a Utility class."
}
def "Smoke Test: Correct system participant throws no exception"() {
given:
def systemParticipant = SystemParticipantTestData.bmInput
when:
ValidationUtils.check(systemParticipant)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.check() recognizes all potential errors for a system participant"() {
when:
SystemParticipantValidationUtils.check(invalidSystemParticipant)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidSystemParticipant || expectedException
SystemParticipantTestData.bmInput.copy().qCharacteristics(null).build() || new InvalidEntityException("Reactive power characteristics of system participant is not defined", invalidSystemParticipant)
}
// Common data for all system participant types
private static final UUID uuid = UUID.fromString("92ec3bcf-1327-4d38-af67-0bf7a9fa73c7")
private static final String id = "test_id"
private static final ComparableQuantity<Currency> capex = Quantities.getQuantity(100d, CAPEX)
private static final ComparableQuantity<EnergyPrice> opex = Quantities.getQuantity(50d, ENERGY_PRICE)
private static final ComparableQuantity<Power> sRated = Quantities.getQuantity(25d, ACTIVE_POWER_IN)
private static final cosPhiRated = 0.95
// Common data for some (but not all) system participant types
private static final ComparableQuantity<Dimensionless> etaConv = Quantities.getQuantity(98d, EFFICIENCY)
// Specific data for bm type
private static final ComparableQuantity<DimensionlessRate> activePowerGradient = Quantities.getQuantity(25, ACTIVE_POWER_GRADIENT)
// Specific data for CHP type (and HP type)
private static final ComparableQuantity<Dimensionless> etaEl = Quantities.getQuantity(19, EFFICIENCY)
private static final ComparableQuantity<Dimensionless> etaThermal = Quantities.getQuantity(76, EFFICIENCY)
private static final ComparableQuantity<Power> pOwn = Quantities.getQuantity(0, ACTIVE_POWER_IN)
private static final ComparableQuantity<Power> pThermal = Quantities.getQuantity(9, ACTIVE_POWER_IN)
// Specific data for storage type
private static final ComparableQuantity<Energy> eStorage = Quantities.getQuantity(100, ENERGY_IN)
private static final ComparableQuantity<Power> pMax = Quantities.getQuantity(15, ACTIVE_POWER_IN)
private static final ComparableQuantity<Dimensionless> eta = Quantities.getQuantity(95, EFFICIENCY)
private static final ComparableQuantity<Dimensionless> dod = Quantities.getQuantity(10, EFFICIENCY)
private static final ComparableQuantity<DimensionlessRate> cpRate = Quantities.getQuantity(100, ACTIVE_POWER_GRADIENT)
private static final ComparableQuantity<Time> lifeTime = Quantities.getQuantity(175316.4, LIFE_TIME)
private static final int lifeCycle = 100
// Specific data for wec type
private static final WecCharacteristicInput wecCharacteristic = new WecCharacteristicInput("cP:{(10.00,0.05),(15.00,0.10),(20.00,0.20)}")
private static final ComparableQuantity<Area> rotorArea = Quantities.getQuantity(20, ROTOR_AREA)
private static final ComparableQuantity<Length> hubHeight = Quantities.getQuantity(200, HUB_HEIGHT)
def "SystemParticipantValidationUtils.checkType() recognizes all potential errors for a system participant type"() {
when:
SystemParticipantValidationUtils.check(invalidType)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidType || expectedException
new BmTypeInput(uuid, id, null, opex, activePowerGradient, sRated, cosPhiRated, etaConv) || new InvalidEntityException("At least one of capex, opex, or sRated is null", invalidType)
new BmTypeInput(uuid, id, Quantities.getQuantity(-100d, CAPEX), Quantities.getQuantity(-50d, ENERGY_PRICE), activePowerGradient, Quantities.getQuantity(-25d, ACTIVE_POWER_IN), cosPhiRated, etaConv) || new InvalidEntityException("The following quantities have to be zero or positive: -100 EUR, -50 EUR/MWh, -25 kVA", invalidType)
new BmTypeInput(uuid, id, capex, opex, activePowerGradient, sRated, 2, etaConv) || new InvalidEntityException("Rated power factor of BmTypeInput must be between 0 and 1", invalidType)
}
// BM
def "Smoke Test: Correct biomass power plant throws no exception"() {
given:
def bmInput = SystemParticipantTestData.bmInput
when:
ValidationUtils.check(bmInput)
then:
noExceptionThrown()
}
// No tests for "SystemParticipantValidationUtils.checkBm() recognizes all potential errors for a biomass power plant"
def "Smoke Test: Correct biomass power plant type throws no exception"() {
given:
def bmType = SystemParticipantTestData.bmTypeInput
when:
ValidationUtils.check(bmType)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkBmType() recognizes all potential errors for a biomass power plant type"() {
when:
SystemParticipantValidationUtils.check(invalidBmType)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidBmType || expectedException
new BmTypeInput(uuid, id, capex, opex, Quantities.getQuantity(-25, ACTIVE_POWER_GRADIENT), sRated, cosPhiRated, etaConv) || new InvalidEntityException("The following quantities have to be zero or positive: -25 %/h", invalidBmType)
new BmTypeInput(uuid, id, capex, opex, activePowerGradient, sRated, cosPhiRated, Quantities.getQuantity(1000d, PERCENT)) || new InvalidEntityException("Efficiency of inverter of BmTypeInput must be between 0% and 100%", invalidBmType)
}
// CHP
def "Smoke Test: Correct CHP plant throws no exception"() {
given:
def chpInput = SystemParticipantTestData.chpInput
when:
ValidationUtils.check(chpInput)
then:
noExceptionThrown()
}
// No tests for "SystemParticipantValidationUtils.checkChp() recognizes all potential errors for a CHP plant, as there is nothing to test here"
def "Smoke Test: Correct CHP type throws no exception"() {
given:
def chpType = SystemParticipantTestData.chpTypeInput
when:
ValidationUtils.check(chpType)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkChpType() recognizes all potential errors for a CHP type"() {
when:
SystemParticipantValidationUtils.check(invalidChpType)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidChpType || expectedException
new ChpTypeInput(uuid, id, capex, opex, etaEl, etaThermal, sRated, cosPhiRated, pThermal, Quantities.getQuantity(-100, ACTIVE_POWER_IN)) || new InvalidEntityException("The following quantities have to be zero or positive: -100 kW", invalidChpType)
new ChpTypeInput(uuid, id, capex, opex, etaEl, etaThermal, sRated, cosPhiRated, Quantities.getQuantity(0, ACTIVE_POWER_IN), pOwn) || new InvalidEntityException("The following quantities have to be positive: 0 kW", invalidChpType)
new ChpTypeInput(uuid, id, capex, opex, Quantities.getQuantity(110, EFFICIENCY), etaThermal, sRated, cosPhiRated, pThermal, pOwn) || new InvalidEntityException("Electrical efficiency of ChpTypeInput must be between 0% and 100%", invalidChpType)
new ChpTypeInput(uuid, id, capex, opex, etaEl, Quantities.getQuantity(110, EFFICIENCY), sRated, cosPhiRated, pThermal, pOwn) || new InvalidEntityException("Thermal efficiency of ChpTypeInput must be between 0% and 100%", invalidChpType)
}
// EV
def "Smoke Test: Correct EV throws no exception"() {
given:
def evInput = SystemParticipantTestData.evInput
when:
ValidationUtils.check(evInput)
then:
noExceptionThrown()
}
// No tests for "SystemParticipantValidationUtils.checkEv() recognizes all potential errors for an EV"
def "Smoke Test: Correct EV type throws no exception"() {
given:
def evType = SystemParticipantTestData.evTypeInput
when:
ValidationUtils.check(evType)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkEvType() recognizes all potential errors for an EV type"() {
when:
SystemParticipantValidationUtils.check(invalidEvType)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidEvType || expectedException
new EvTypeInput(uuid, id, capex, opex, Quantities.getQuantity(0, ENERGY_IN), Quantities.getQuantity(0, ENERGY_PER_DISTANCE), sRated, cosPhiRated) || new InvalidEntityException("The following quantities have to be positive: 0 kWh, 0 kWh/km", invalidEvType)
}
// Fixed Feed In
def "Smoke Test: Correct Fixed Feed-In throws no exception"() {
given:
def fixedFeedInInput = SystemParticipantTestData.fixedFeedInInput
when:
ValidationUtils.check(fixedFeedInInput)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkFixedFeedIn() recognizes all potential errors for an a Fixed Feed-In"() {
when:
SystemParticipantValidationUtils.check(invalidFixedFeedIn)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidFixedFeedIn || expectedException
SystemParticipantTestData.fixedFeedInInput.copy().sRated(Quantities.getQuantity(-100d, ACTIVE_POWER_IN)).build() || new InvalidEntityException("The following quantities have to be zero or positive: -100 kVA", invalidFixedFeedIn)
SystemParticipantTestData.fixedFeedInInput.copy().cosPhiRated(-1d).build() || new InvalidEntityException("Rated power factor of FixedFeedInInput must be between 0 and 1", invalidFixedFeedIn)
}
// HP
def "Smoke Test: Correct HP throws no exception"() {
given:
def hpInput = SystemParticipantTestData.hpInput
when:
ValidationUtils.check(hpInput)
then:
noExceptionThrown()
}
// No tests for "SystemParticipantValidationUtils.checkHp() recognizes all potential errors for an HP"
def "Smoke Test: Correct HP type throws no exception"() {
given:
def hpType = SystemParticipantTestData.hpTypeInput
when:
ValidationUtils.check(hpType)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkHpType() recognizes all potential errors for an HP type"() {
when:
SystemParticipantValidationUtils.check(invalidHpType)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidHpType || expectedException
new HpTypeInput(uuid, id, capex, opex, sRated, cosPhiRated, Quantities.getQuantity(0, ACTIVE_POWER_IN)) || new InvalidEntityException("The following quantities have to be positive: 0 kW", invalidHpType)
}
// Load
def "Smoke Test: Correct load throws no exception"() {
given:
def load = SystemParticipantTestData.loadInput
when:
ValidationUtils.check(load)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkLoad() recognizes all potential errors for a load"() {
when:
SystemParticipantValidationUtils.check(invalidLoad)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidLoad || expectedException
SystemParticipantTestData.loadInput.copy().loadprofile(null).build() || new InvalidEntityException("No standard load profile defined for load", invalidLoad)
SystemParticipantTestData.loadInput.copy().sRated(Quantities.getQuantity(-25d, ACTIVE_POWER_IN)).eConsAnnual(Quantities.getQuantity(-4000, ENERGY_IN)).build() || new InvalidEntityException("The following quantities have to be zero or positive: -25 kVA, -4000 kWh", invalidLoad)
SystemParticipantTestData.loadInput.copy().cosPhiRated(2).build() || new InvalidEntityException("Rated power factor of LoadInput must be between 0 and 1", invalidLoad)
}
// PV
def "Smoke Test: Correct PV throws no exception"() {
given:
def pvInput = SystemParticipantTestData.pvInput
when:
ValidationUtils.check(pvInput)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkPV() recognizes all potential errors for a PV"() {
when:
SystemParticipantValidationUtils.check(invalidPV)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidPV || expectedException
SystemParticipantTestData.pvInput.copy().sRated(Quantities.getQuantity(-25d, ACTIVE_POWER_IN)).build() || new InvalidEntityException("The following quantities have to be zero or positive: -25 kVA", invalidPV)
SystemParticipantTestData.pvInput.copy().albedo(2).build() || new InvalidEntityException("Albedo of the plant's surrounding of PvInput must be between 0 and 1", invalidPV)
SystemParticipantTestData.pvInput.copy().azimuth(Quantities.getQuantity(-100d, AZIMUTH)).build() || new InvalidEntityException("Azimuth angle of PvInput must be between -90° (east) and 90° (west)", invalidPV)
SystemParticipantTestData.pvInput.copy().etaConv(Quantities.getQuantity(110d, EFFICIENCY)).build() || new InvalidEntityException("Efficiency of the converter of PvInput must be between 0% and 100%", invalidPV)
SystemParticipantTestData.pvInput.copy().elevationAngle(Quantities.getQuantity(100d, SOLAR_ELEVATION_ANGLE)).build() || new InvalidEntityException("Tilted inclination from horizontal of PvInput must be between 0° and 90°", invalidPV)
SystemParticipantTestData.pvInput.copy().cosPhiRated(2).build() || new InvalidEntityException("Rated power factor of PvInput must be between 0 and 1", invalidPV)
}
// Storage
def "Smoke Test: Correct storage throws no exception"() {
given:
def storage = SystemParticipantTestData.storageInput
when:
ValidationUtils.check(storage)
then:
noExceptionThrown()
}
// No tests for "SystemParticipantValidationUtils.checkStorage() recognizes all potential errors for a storage"
def "Smoke Test: Correct storage type throws no exception"() {
given:
def storageType = SystemParticipantTestData.storageTypeInput
when:
ValidationUtils.check(storageType)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkStorageType() recognizes all potential errors for a storage type"() {
when:
SystemParticipantValidationUtils.check(invalidStorageType)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidStorageType || expectedException
new StorageTypeInput(uuid, id, capex, opex, eStorage, sRated, cosPhiRated, pMax, cpRate, eta, dod, lifeTime, -1) || new InvalidEntityException("Permissible amount of life cycles of the storage type must be zero or positive", invalidStorageType)
new StorageTypeInput(uuid, id, capex, opex, eStorage, sRated, cosPhiRated, pMax, cpRate, Quantities.getQuantity(110, EFFICIENCY), dod, lifeTime, lifeCycle) || new InvalidEntityException("Efficiency of the electrical converter of StorageTypeInput must be between 0% and 100%", invalidStorageType)
new StorageTypeInput(uuid, id, capex, opex, eStorage, sRated, cosPhiRated, pMax, cpRate, eta, Quantities.getQuantity(-10, EFFICIENCY), lifeTime, lifeCycle) || new InvalidEntityException("Maximum permissible depth of discharge of StorageTypeInput must be between 0% and 100%", invalidStorageType)
new StorageTypeInput(uuid, id, capex, opex, eStorage, sRated, cosPhiRated, Quantities.getQuantity(-15, ACTIVE_POWER_IN), Quantities.getQuantity(-100, ACTIVE_POWER_GRADIENT), eta, dod, Quantities.getQuantity(-10.5, LIFE_TIME), lifeCycle) || new InvalidEntityException("The following quantities have to be zero or positive: -15 kW, -100 %/h, -10.5 h", invalidStorageType)
new StorageTypeInput(uuid, id, capex, opex, Quantities.getQuantity(0, ENERGY_IN), sRated, cosPhiRated, pMax, cpRate, eta, dod, lifeTime, lifeCycle) || new InvalidEntityException("The following quantities have to be positive: 0 kWh", invalidStorageType)
}
// WEC
def "Smoke Test: Correct WEC throws no exception"() {
given:
def wec = SystemParticipantTestData.wecInput
when:
ValidationUtils.check(wec)
then:
noExceptionThrown()
}
// No tests for "SystemParticipantValidationUtils.checkWec() recognizes all potential errors for a WEC"
def "Smoke Test: Correct WEC type throws no exception"() {
given:
def wecType = SystemParticipantTestData.wecType
when:
ValidationUtils.check(wecType)
then:
noExceptionThrown()
}
def "SystemParticipantValidationUtils.checkWecType() recognizes all potential errors for a wec type"() {
when:
SystemParticipantValidationUtils.check(invalidWecType)
then:
Exception ex = thrown()
ex.class == expectedException.class
ex.message == expectedException.message
where:
invalidWecType || expectedException
new WecTypeInput(uuid, id, capex, opex, sRated, cosPhiRated, wecCharacteristic, Quantities.getQuantity(110d, EFFICIENCY), rotorArea, hubHeight) || new InvalidEntityException("Efficiency of the converter of WecTypeInput must be between 0% and 100%", invalidWecType)
new WecTypeInput(uuid, id, capex, opex, sRated, cosPhiRated, wecCharacteristic, etaConv, Quantities.getQuantity(-10, ROTOR_AREA), Quantities.getQuantity(-200, HUB_HEIGHT)) || new InvalidEntityException("The following quantities have to be zero or positive: -10 m², -200 m", invalidWecType)
}
def "Checking an unsupported asset leads to an exception"() {
given:
def node = Mock(NodeInput)
node.getUuid() >> UUID.randomUUID()
def invalidParticipant = new InvalidSystemParticipantInput(node)
when:
SystemParticipantValidationUtils.check(invalidParticipant)
then:
def e = thrown(NotImplementedException)
e.message == "Cannot validate object of class 'InvalidSystemParticipantInput', as no routine is implemented."
}
def "Checking an unsupported asset type leads to an exception"() {
given:
def invalidParticipantInput = new InvalidSystemParticipantTypeInput()
when:
SystemParticipantValidationUtils.check(invalidParticipantInput)
then:
def e = thrown(NotImplementedException)
e.message == "Cannot validate object of class 'InvalidSystemParticipantTypeInput', as no routine is implemented."
}
def "Checking electric vehicle charging stations leads to an exception"() {
when:
SystemParticipantValidationUtils.checkEvcs()
then:
def e = thrown(NotImplementedException)
e.message == "Validation of 'EvcsInput' is currently not supported."
}
}