-
Notifications
You must be signed in to change notification settings - Fork 5
/
ExtractorTest.groovy
164 lines (147 loc) · 5.18 KB
/
ExtractorTest.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
/*
* © 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.extractor
import edu.ie3.datamodel.exceptions.ExtractorException
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.input.system.FixedFeedInInput
import edu.ie3.test.common.GridTestData as gtd
import edu.ie3.test.common.SystemParticipantTestData as sptd
import edu.ie3.test.common.ThermalUnitInputTestData as tutd
import spock.lang.Specification
class ExtractorTest extends Specification {
private final class InvalidNestedExtensionClass implements NestedEntity {}
def "An Extractor should be able to extract an entity with nested elements correctly"() {
expect:
println(nestedEntity)
def result = Extractor.extractElements(nestedEntity) as Set
result == expectedExtractedEntities as Set
where:
nestedEntity || expectedExtractedEntities
gtd.lineCtoD || [
gtd.lineCtoD.nodeA,
gtd.lineCtoD.nodeB,
gtd.lineCtoD.type,
gtd.lineCtoD.operator
]
gtd.transformerAtoBtoC || [
gtd.transformerAtoBtoC.nodeA,
gtd.transformerAtoBtoC.nodeB,
gtd.transformerAtoBtoC.nodeC,
gtd.transformerAtoBtoC.type,
gtd.transformerAtoBtoC.operator,
gtd.transformerAtoBtoC.nodeA.operator
]
gtd.transformerCtoG || [
gtd.transformerCtoG.nodeA,
gtd.transformerCtoG.nodeB,
gtd.transformerCtoG.type,
gtd.transformerCtoG.operator
]
gtd.switchAtoB || [
gtd.switchAtoB.nodeA,
gtd.switchAtoB.nodeB,
gtd.switchAtoB.nodeA.operator,
gtd.switchAtoB.operator
]
sptd.fixedFeedInInput || [
sptd.fixedFeedInInput.node,
sptd.fixedFeedInInput.operator,
sptd.fixedFeedInInput.node.operator
]
sptd.wecInput || [
sptd.wecInput.node,
sptd.wecInput.type,
sptd.wecInput.operator,
sptd.wecInput.node.operator
]
sptd.chpInput || [
sptd.chpInput.node,
sptd.chpInput.node.operator,
sptd.chpInput.type,
sptd.chpInput.thermalBus,
sptd.chpInput.thermalStorage,
sptd.chpInput.thermalStorage.thermalBus,
sptd.chpInput.thermalStorage.thermalBus.operator
]
sptd.bmInput || [
sptd.bmInput.node,
sptd.bmInput.type,
sptd.bmInput.operator,
sptd.bmInput.node.operator
]
sptd.evInput || [
sptd.evInput.node,
sptd.evInput.type,
sptd.evInput.operator,
sptd.evInput.node.operator
]
sptd.storageInput || [
sptd.storageInput.node,
sptd.storageInput.type,
sptd.storageInput.operator,
sptd.storageInput.node.operator
]
sptd.hpInput || [
sptd.hpInput.node,
sptd.hpInput.type,
sptd.hpInput.operator,
sptd.hpInput.thermalBus,
sptd.hpInput.thermalBus.operator,
sptd.hpInput.node.operator
]
gtd.lineGraphicCtoD || [
gtd.lineGraphicCtoD.line,
gtd.lineGraphicCtoD.line.nodeB,
gtd.lineGraphicCtoD.line.nodeA,
gtd.lineGraphicCtoD.line.type,
gtd.lineGraphicCtoD.line.operator
]
gtd.nodeGraphicC || [gtd.nodeGraphicC.node]
gtd.measurementUnitInput || [
gtd.measurementUnitInput.node,
gtd.measurementUnitInput.operator
]
tutd.thermalBus || [
tutd.thermalBus.operator
]
tutd.cylindricStorageInput || [
tutd.cylindricStorageInput.operator,
tutd.cylindricStorageInput.thermalBus,
tutd.cylindricStorageInput.thermalBus.operator
]
tutd.thermalHouseInput || [
tutd.thermalHouseInput.operator,
tutd.thermalHouseInput.thermalBus,
tutd.thermalHouseInput.thermalBus.operator
]
}
def "An Extractor should throw an ExtractorException if the provided Nested entity is unknown and or an invalid extension of the 'Nested' interface took place"() {
when:
Extractor.extractElements(new InvalidNestedExtensionClass())
then:
ExtractorException ex = thrown()
ex.message == "Unable to extract entity of class 'InvalidNestedExtensionClass'. " +
"Does this class implements NestedEntity and one of its sub-interfaces correctly?"
}
def "An Extractor should not extract an operator that is marked as not assigned"() {
given:
def sampleFixedFeedInput = new FixedFeedInInput(UUID.fromString("717af017-cc69-406f-b452-e022d7fb516a"), "test_fixedFeedInInput",
OperatorInput.NO_OPERATOR_ASSIGNED,
sptd.fixedFeedInInput.operationTime, sptd.fixedFeedInInput.node, sptd.fixedFeedInInput.qCharacteristics,
sptd.fixedFeedInInput.sRated,sptd.fixedFeedInInput.cosPhiRated)
expect:
Extractor.extractElements(sampleFixedFeedInput) as Set == [
sptd.fixedFeedInInput.node,
sptd.fixedFeedInInput.node.operator
] as Set
}
def "An Extractor should not extract an operator that is marked as not assigned and not throw an exception if the resulting list empty"() {
given:
def sampleNodeInput = gtd.nodeB
expect:
Extractor.extractElements(sampleNodeInput) == [] as Set
}
}