-
Notifications
You must be signed in to change notification settings - Fork 5
/
CsvSystemParticipantSourceTest.groovy
357 lines (296 loc) · 18.2 KB
/
CsvSystemParticipantSourceTest.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
/*
* © 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.source.csv
import static edu.ie3.test.helper.EntityMap.map
import edu.ie3.datamodel.exceptions.SourceException
import edu.ie3.datamodel.exceptions.SystemParticipantsException
import edu.ie3.datamodel.io.source.*
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.input.system.*
import edu.ie3.datamodel.utils.Try
import edu.ie3.test.common.SystemParticipantTestData as sptd
import spock.lang.Specification
class CsvSystemParticipantSourceTest extends Specification implements CsvTestDataMeta {
def "A SystemParticipantSource with csv input should provide an instance of SystemParticipants based on valid input data correctly"() {
given:
def typeSource = new TypeSource(new CsvDataSource(csvSep, typeFolderPath, fileNamingStrategy))
def thermalSource = new ThermalSource(typeSource, new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def rawGridSource = new RawGridSource(typeSource, new CsvDataSource(csvSep, gridDefaultFolderPath, fileNamingStrategy))
def csvSystemParticipantSource = new SystemParticipantSource(
typeSource,
thermalSource,
rawGridSource,
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
when:
def systemParticipants = csvSystemParticipantSource.systemParticipants
then:
systemParticipants.allEntitiesAsList().size() == 10
systemParticipants.pvPlants.first().uuid == sptd.pvInput.uuid
systemParticipants.bmPlants.first().uuid == sptd.bmInput.uuid
systemParticipants.chpPlants.first().uuid == sptd.chpInput.uuid
systemParticipants.evs.first().uuid == sptd.evInput.uuid
systemParticipants.fixedFeedIns.first().uuid == sptd.fixedFeedInInput.uuid
systemParticipants.heatPumps.first().uuid == sptd.hpInput.uuid
systemParticipants.loads.first().uuid == sptd.loadInput.uuid
systemParticipants.wecPlants.first().uuid == sptd.wecInput.uuid
systemParticipants.storages.first().uuid == sptd.storageInput.uuid
systemParticipants.evcs.first().uuid == sptd.evcsInput.uuid
}
def "A SystemParticipantSource with csv input should process invalid input data as expected when requested to provide an instance of SystemParticipants"() {
given:
def typeSource = new TypeSource(new CsvDataSource(csvSep, typeFolderPath, fileNamingStrategy))
def thermalSource = new ThermalSource(typeSource, new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def rawGridSource = Spy(RawGridSource, constructorArgs: [
typeSource,
new CsvDataSource(csvSep, gridDefaultFolderPath, fileNamingStrategy)
]) {
// partly fake the return method of the csv raw grid source to always return empty node sets
// -> elements to build NodeGraphicInputs are missing
getNodes() >> [:]
getNodes(_) >> [:]
} as RawGridSource
def csvSystemParticipantSource = new SystemParticipantSource(
typeSource,
thermalSource,
rawGridSource,
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
when:
def systemParticipants = Try.of(() -> csvSystemParticipantSource.systemParticipants, SystemParticipantsException)
then:
systemParticipants.failure
systemParticipants.data == Optional.empty()
Exception ex = systemParticipants.exception.get()
ex.class == SystemParticipantsException
ex.message.startsWith("10 error(s) occurred while initializing system participants. " +
"edu.ie3.datamodel.exceptions.FailureException: 1 exception(s) occurred within \"FixedFeedInInput\" data, one is: " +
"edu.ie3.datamodel.exceptions.FactoryException: edu.ie3.datamodel.exceptions.SourceException: " +
"Linked node with UUID 4ca90220-74c2-4369-9afa-a18bf068840d was not found for entity AssetInputEntityData")
}
def "A SystemParticipantSource with csv input should return data from valid input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def nodeMap = map([sptd.participantNode])
def operatorMap = map([sptd.operator])
def thermalBusMap = map([sptd.thermalBus])
def thermalStorageMap = map([sptd.thermalStorage])
expect:
def heatPumps = Try.of(() -> csvSystemParticipantSource.getHeatPumps(operatorMap, nodeMap, map([sptd.hpTypeInput]), thermalBusMap), SourceException)
heatPumps.success
heatPumps.data.get() == [sptd.hpInput] as Set
def chpUnits = Try.of(() -> csvSystemParticipantSource.getChpPlants(operatorMap, nodeMap, map([sptd.chpTypeInput]), thermalBusMap, thermalStorageMap), SourceException)
chpUnits.success
chpUnits.data.get() == [sptd.chpInput] as Set
def evs = Try.of(() -> csvSystemParticipantSource.getEvs(operatorMap, nodeMap, map([sptd.evTypeInput])), SourceException)
evs.success
evs.data.get() == [sptd.evInput] as Set
def wecs = Try.of(() -> csvSystemParticipantSource.getWecPlants(operatorMap, nodeMap, map([sptd.wecType])), SourceException)
wecs.success
wecs.data.get() == [sptd.wecInput] as Set
def storages = Try.of(() -> csvSystemParticipantSource.getStorages(operatorMap, nodeMap, map([sptd.storageTypeInput])), SourceException)
storages.success
storages.data.get() == [sptd.storageInput] as Set
def bms = Try.of(() -> csvSystemParticipantSource.getBmPlants(operatorMap, nodeMap, map([sptd.bmTypeInput])), SourceException)
bms.success
bms.data.get() == [sptd.bmInput] as Set
def evcs = Try.of(() -> csvSystemParticipantSource.getEvcs(operatorMap, nodeMap), SourceException)
evcs.success
evcs.data.get() == [sptd.evcsInput] as Set
def loads = Try.of(() -> csvSystemParticipantSource.getLoads(operatorMap, nodeMap), SourceException)
loads.success
loads.data.get() == [sptd.loadInput] as Set
def pvs = Try.of(() -> csvSystemParticipantSource.getPvPlants(operatorMap, nodeMap), SourceException)
pvs.success
pvs.data.get() == [sptd.pvInput] as Set
def fixedFeedIns = Try.of(() -> csvSystemParticipantSource.getFixedFeedIns(operatorMap, nodeMap), SourceException)
fixedFeedIns.success
fixedFeedIns.data.get() == [sptd.fixedFeedInInput] as Set
}
def "A SystemParticipantSource with csv input should throw an exception from an invalid heat pump input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def nodeMap = map([sptd.participantNode])
expect:
def heatPumps = Try.of(() -> csvSystemParticipantSource.getHeatPumps(map(operators), nodeMap, map(types), map(thermalBuses)), SourceException)
heatPumps.failure
heatPumps.exception.get().class == SourceException
where:
operators | types | thermalBuses || resultingSize | resultingSet
[] | [sptd.hpInput.type] | [sptd.hpInput.thermalBus] || 1 | [new HpInput(sptd.hpInput.uuid, sptd.hpInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.hpInput.operationTime, sptd.hpInput.node, sptd.hpInput.thermalBus, sptd.hpInput.qCharacteristics, sptd.hpInput.type)]
[] | [] | [] || 0 | []
[] | [] | [] || 0 | []
[sptd.hpInput.operator] | [] | [] || 0 | []
[sptd.hpInput.operator] | [sptd.hpInput.type] | [] || 0 | []
}
def "A SystemParticipantSource with csv input should throw an exception from a invalid chp input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def nodeMap = map([sptd.participantNode])
expect:
def chpUnits = Try.of(() -> csvSystemParticipantSource.getChpPlants(map(operators), nodeMap, map(types), map(thermalBuses), map(thermalStorages)), SourceException)
chpUnits.failure
chpUnits.exception.get().class == SourceException
where:
operators | types | thermalBuses | thermalStorages || resultingSet
[] | [sptd.chpInput.type] | [sptd.chpInput.thermalBus] | [sptd.chpInput.thermalStorage] || [new ChpInput(sptd.chpInput.uuid, sptd.chpInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.chpInput.operationTime, sptd.chpInput.node, sptd.chpInput.thermalBus, sptd.chpInput.qCharacteristics, sptd.chpInput.type, sptd.chpInput.thermalStorage, sptd.chpInput.marketReaction)]
[] | [] | [] | [] as List || []
[] | [] | [] | [] as List || []
[sptd.chpInput.operator] | [] | [] | [] as List || []
[sptd.chpInput.operator] | [sptd.chpInput.type] | [] | [] as List || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid ev input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def nodeMap = map([sptd.participantNode])
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getEvs(map(operators), nodeMap, map(types)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
operators | types || resultingSet
[] | [sptd.evInput.type] || [new EvInput(sptd.evInput.uuid, sptd.evInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.evInput.operationTime, sptd.evInput.node, sptd.evInput.qCharacteristics, sptd.evInput.type)]
[sptd.evInput.operator] | [] || []
[] | [] || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid wec input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def nodeMap = map([sptd.participantNode])
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getWecPlants(map(operators), nodeMap, map(types)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
operators | types || resultingSet
[] | [sptd.wecInput.type] || [new WecInput(sptd.wecInput.uuid, sptd.wecInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.wecInput.operationTime, sptd.wecInput.node, sptd.wecInput.qCharacteristics, sptd.wecInput.type, sptd.wecInput.marketReaction)]
[sptd.wecInput.operator] | [] || []
[] | [] || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid storage input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def nodeMap = map([sptd.participantNode])
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getStorages(map(operators), nodeMap, map(types)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
operators | types || resultingSet
[] | [sptd.storageInput.type] || [new StorageInput(sptd.storageInput.uuid, sptd.storageInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.storageInput.operationTime, sptd.storageInput.node, sptd.storageInput.qCharacteristics, sptd.storageInput.type)]
[sptd.storageInput.operator] | [] || []
[] | [] || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid bm input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
def nodeMap = map([sptd.participantNode])
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getBmPlants(map(operators), nodeMap, map(types)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
operators | types || resultingSet
[] | [sptd.bmInput.type] || [new BmInput(sptd.bmInput.uuid, sptd.bmInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.bmInput.operationTime, sptd.bmInput.node, sptd.bmInput.qCharacteristics, sptd.bmInput.type, sptd.bmInput.marketReaction, sptd.bmInput.costControlled, sptd.bmInput.feedInTariff)]
[sptd.bmInput.operator] | [] || []
[] | [] || []
[] | [] || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid ev charging station input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getEvcs(map(operators), map(nodes)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
nodes | operators || resultingSet
[sptd.evcsInput.node] | [] || [new EvcsInput(sptd.evcsInput.uuid, sptd.evcsInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.evcsInput.operationTime, sptd.evcsInput.node, sptd.evcsInput.qCharacteristics, sptd.evcsInput.type, sptd.evcsInput.chargingPoints, sptd.evcsInput.cosPhiRated, sptd.evcsInput.locationType, sptd.evcsInput.v2gSupport)]
[] | [sptd.evcsInput.operator] || []
[] | [] || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid load input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getLoads(map(operators), map(nodes)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
nodes | operators || resultingSet
[sptd.loadInput.node] | [] || [new LoadInput(sptd.loadInput.uuid, sptd.loadInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.loadInput.operationTime, sptd.loadInput.node, sptd.loadInput.qCharacteristics, sptd.loadInput.loadProfile, sptd.loadInput.dsm, sptd.loadInput.eConsAnnual, sptd.loadInput.sRated, sptd.loadInput.cosPhiRated)]
[] | [sptd.loadInput.operator] || []
[] | [] || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid pv input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getPvPlants(map(operators), map(nodes)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
nodes | operators || resultingSet
[sptd.pvInput.node] | [] || [new PvInput(sptd.pvInput.uuid, sptd.pvInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.pvInput.operationTime, sptd.pvInput.node, sptd.pvInput.qCharacteristics, sptd.pvInput.albedo, sptd.pvInput.azimuth, sptd.pvInput.etaConv, sptd.pvInput.elevationAngle, sptd.pvInput.kG, sptd.pvInput.kT, sptd.pvInput.marketReaction, sptd.pvInput.sRated, sptd.pvInput.cosPhiRated)]
[] | [sptd.pvInput.operator] || []
[] | [] || []
}
def "A SystemParticipantSource with csv input should throw an exception from invalid fixedFeedIn input file as expected"() {
given:
def csvSystemParticipantSource = new SystemParticipantSource(
Mock(TypeSource),
Mock(ThermalSource),
Mock(RawGridSource),
new CsvDataSource(csvSep, participantsFolderPath, fileNamingStrategy))
expect:
def sysParts = Try.of(() -> csvSystemParticipantSource.getFixedFeedIns(map(operators), map(nodes)), SourceException)
sysParts.failure
sysParts.exception.get().class == SourceException
where:
nodes | operators || resultingSet
[sptd.fixedFeedInInput.node] | [] as List || [new FixedFeedInInput(sptd.fixedFeedInInput.uuid, sptd.fixedFeedInInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.fixedFeedInInput.operationTime, sptd.fixedFeedInInput.node, sptd.fixedFeedInInput.qCharacteristics, sptd.fixedFeedInInput.sRated, sptd.fixedFeedInInput.cosPhiRated)]
[] | [sptd.fixedFeedInInput.operator] as List || []
[] | [] as List || []
}
}