-
Notifications
You must be signed in to change notification settings - Fork 5
/
CsvThermalSourceTest.groovy
181 lines (156 loc) · 10.1 KB
/
CsvThermalSourceTest.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
/*
* © 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 edu.ie3.datamodel.io.factory.FactoryData
import edu.ie3.datamodel.io.naming.FileNamingStrategy
import edu.ie3.datamodel.io.factory.input.AssetInputEntityData
import edu.ie3.datamodel.io.factory.input.ThermalUnitInputEntityData
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput
import edu.ie3.datamodel.models.input.thermal.ThermalUnitInput
import edu.ie3.test.common.SystemParticipantTestData as sptd
import edu.ie3.test.common.ThermalUnitInputTestData
import spock.lang.Specification
import java.util.stream.Collectors
class CsvThermalSourceTest extends Specification implements CsvTestDataMeta {
def "A CsvThermalSource should return ThermalBuses from valid and invalid input data as expected"() {
given:
def csvTypeSource = new CsvTypeSource(",", typeFolderPath, new FileNamingStrategy())
def csvThermalSource = new CsvThermalSource(csvSep, thermalFolderPath, fileNamingStrategy, csvTypeSource)
def operators = csvTypeSource.operators
//test method when no operators are provided as constructor parameters
when:
def resultingThermalBusesWoOperator = csvThermalSource.getThermalBuses()
then:
resultingThermalBusesWoOperator.size() == 1
resultingThermalBusesWoOperator.first().uuid == sptd.thermalBus.uuid
resultingThermalBusesWoOperator.first().id == sptd.thermalBus.id
resultingThermalBusesWoOperator.first().operator == sptd.thermalBus.operator
resultingThermalBusesWoOperator.first().operationTime == sptd.thermalBus.operationTime
//test method when operators are provided as constructor parameters
when:
def resultingThermalBuses = csvThermalSource.getThermalBuses(operators)
then:
resultingThermalBuses.size() == 1
resultingThermalBuses.first().uuid == sptd.thermalBus.uuid
resultingThermalBuses.first().id == sptd.thermalBus.id
resultingThermalBuses.first().operator == sptd.thermalBus.operator
resultingThermalBuses.first().operationTime == sptd.thermalBus.operationTime
}
def "A CsvThermalSource should return a CylindricalStorageInput from valid and invalid input data as expected"() {
given:
def csvTypeSource = new CsvTypeSource(",", typeFolderPath, new FileNamingStrategy())
def csvThermalSource = new CsvThermalSource(csvSep, thermalFolderPath, fileNamingStrategy, csvTypeSource)
def operators = csvTypeSource.operators
def thermalBuses = csvThermalSource.thermalBuses
//test method when operators and thermal buses are not provided as constructor parameters
when:
def resultingCylindricalStorageWoOperator = csvThermalSource.getCylindricStorages()
then:
resultingCylindricalStorageWoOperator.size() == 1
resultingCylindricalStorageWoOperator.first().uuid == sptd.thermalStorage.uuid
resultingCylindricalStorageWoOperator.first().id == sptd.thermalStorage.id
resultingCylindricalStorageWoOperator.first().operator == sptd.thermalStorage.operator
resultingCylindricalStorageWoOperator.first().operationTime == sptd.thermalStorage.operationTime
resultingCylindricalStorageWoOperator.first().thermalBus == sptd.thermalStorage.thermalBus
resultingCylindricalStorageWoOperator.first().storageVolumeLvl == sptd.storageVolumeLvl
resultingCylindricalStorageWoOperator.first().storageVolumeLvlMin == sptd.storageVolumeLvlMin
resultingCylindricalStorageWoOperator.first().inletTemp == sptd.inletTemp
resultingCylindricalStorageWoOperator.first().returnTemp == sptd.returnTemp
resultingCylindricalStorageWoOperator.first().c == sptd.c
//test method when operators and thermal buses are provided as constructor parameters
when:
def resultingCylindricalStorage = csvThermalSource.getCylindricStorages(operators, thermalBuses)
then:
resultingCylindricalStorage.size() == 1
resultingCylindricalStorage.first().uuid == sptd.thermalStorage.uuid
resultingCylindricalStorage.first().id == sptd.thermalStorage.id
resultingCylindricalStorage.first().operator == sptd.thermalStorage.operator
resultingCylindricalStorage.first().operationTime == sptd.thermalStorage.operationTime
resultingCylindricalStorage.first().thermalBus == sptd.thermalStorage.thermalBus
resultingCylindricalStorage.first().storageVolumeLvl == sptd.storageVolumeLvl
resultingCylindricalStorage.first().storageVolumeLvlMin == sptd.storageVolumeLvlMin
resultingCylindricalStorage.first().inletTemp == sptd.inletTemp
resultingCylindricalStorage.first().returnTemp == sptd.returnTemp
resultingCylindricalStorage.first().c == sptd.c
}
def "A CsvThermalSource should build thermal unit input entity from valid and invalid input data as expected"() {
given:
def csvTypeSource = new CsvTypeSource(",", typeFolderPath, new FileNamingStrategy())
def csvThermalSource = new CsvThermalSource(csvSep, thermalFolderPath, fileNamingStrategy, csvTypeSource)
def operator = new OperatorInput(UUID.fromString("8f9682df-0744-4b58-a122-f0dc730f6510"), "testOperator")
def validFieldsToAttributes = [
"uuid" : "717af017-cc69-406f-b452-e022d7fb516a",
"id" : "test_thermal_unit",
"operator" : "8f9682df-0744-4b58-a122-f0dc730f6510",
"operatesFrom" : "2020-03-24 15:11:31",
"operatesUntil" : "2020-03-25 15:11:31",
"thermalBus" : "0d95d7f2-49fb-4d49-8636-383a5220384e"
]
def assetInputEntityData = new AssetInputEntityData(new FactoryData.MapWithRowIndex("-1", validFieldsToAttributes), ThermalUnitInput, operator)
when:
def resultingDataOpt = csvThermalSource.buildThermalUnitInputEntityData(assetInputEntityData, thermalBuses).collect(Collectors.toList())
then:
resultingDataOpt.size() == 1
resultingDataOpt.first().present == resultIsPresent
resultingDataOpt.first().ifPresent({ resultingData ->
assert (resultingData == expectedThermalUnitInputEntityData)
})
where:
thermalBuses || resultIsPresent || expectedThermalUnitInputEntityData
[]|| false || null // thermal buses are not present -> method should return an empty optional -> do not check for thermal unit entity data
[
new ThermalBusInput(UUID.fromString("0d95d7f2-49fb-4d49-8636-383a5220384e"), "test_thermal_bus")
]|| true ||
new ThermalUnitInputEntityData(new FactoryData.MapWithRowIndex("-1", ["uuid": "717af017-cc69-406f-b452-e022d7fb516a",
"id": "test_thermal_unit",
"operator": "8f9682df-0744-4b58-a122-f0dc730f6510",
"operatesFrom": "2020-03-24 15:11:31",
"operatesUntil": "2020-03-25 15:11:31"]),
ThermalUnitInput,
new OperatorInput(UUID.fromString("8f9682df-0744-4b58-a122-f0dc730f6510"), "testOperator"),
new ThermalBusInput(UUID.fromString("0d95d7f2-49fb-4d49-8636-383a5220384e"), "test_thermal_bus"))
}
def "A CsvThermalSource should return a ThermalHouseInput from valid and invalid input data as expected"() {
given:
def csvTypeSource = new CsvTypeSource(",", typeFolderPath, new FileNamingStrategy())
def csvThermalSource = new CsvThermalSource(csvSep, thermalFolderPath, fileNamingStrategy, csvTypeSource)
def operators = csvTypeSource.operators
def thermalBuses = csvThermalSource.thermalBuses
//test method when operators and thermal buses are not provided as constructor parameters
when:
def resultingThermalHouseWoOperator = csvThermalSource.getThermalHouses()
then:
resultingThermalHouseWoOperator.size() == 1
resultingThermalHouseWoOperator.first().uuid == ThermalUnitInputTestData.thermalHouseInput.uuid
resultingThermalHouseWoOperator.first().id == ThermalUnitInputTestData.thermalHouseInput.id
resultingThermalHouseWoOperator.first().operator == ThermalUnitInputTestData.thermalHouseInput.operator
resultingThermalHouseWoOperator.first().operationTime.isLimited()
resultingThermalHouseWoOperator.first().operationTime == ThermalUnitInputTestData.thermalHouseInput.operationTime
resultingThermalHouseWoOperator.first().thermalBus == ThermalUnitInputTestData.thermalHouseInput.thermalBus
resultingThermalHouseWoOperator.first().ethLosses == ThermalUnitInputTestData.thermalHouseInput.ethLosses
resultingThermalHouseWoOperator.first().ethCapa == ThermalUnitInputTestData.thermalHouseInput.ethCapa
resultingThermalHouseWoOperator.first().targetTemperature == ThermalUnitInputTestData.thermalHouseInput.targetTemperature
resultingThermalHouseWoOperator.first().upperTemperatureLimit == ThermalUnitInputTestData.thermalHouseInput.upperTemperatureLimit
resultingThermalHouseWoOperator.first().lowerTemperatureLimit == ThermalUnitInputTestData.thermalHouseInput.lowerTemperatureLimit
//test method when operators and thermal buses are provided as constructor parameters
when:
def resultingThermalHouse = csvThermalSource.getThermalHouses(operators, thermalBuses)
then:
resultingThermalHouse.size() == 1
resultingThermalHouse.first().uuid == ThermalUnitInputTestData.thermalHouseInput.uuid
resultingThermalHouse.first().id == ThermalUnitInputTestData.thermalHouseInput.id
resultingThermalHouse.first().operator == ThermalUnitInputTestData.thermalHouseInput.operator
resultingThermalHouse.first().operationTime.isLimited()
resultingThermalHouse.first().operationTime == ThermalUnitInputTestData.thermalHouseInput.operationTime
resultingThermalHouseWoOperator.first().thermalBus == ThermalUnitInputTestData.thermalHouseInput.thermalBus
resultingThermalHouse.first().ethLosses == ThermalUnitInputTestData.thermalHouseInput.ethLosses
resultingThermalHouse.first().ethCapa == ThermalUnitInputTestData.thermalHouseInput.ethCapa
resultingThermalHouse.first().targetTemperature == ThermalUnitInputTestData.thermalHouseInput.targetTemperature
resultingThermalHouse.first().upperTemperatureLimit == ThermalUnitInputTestData.thermalHouseInput.upperTemperatureLimit
resultingThermalHouse.first().lowerTemperatureLimit == ThermalUnitInputTestData.thermalHouseInput.lowerTemperatureLimit
}
}