-
Notifications
You must be signed in to change notification settings - Fork 5
/
SystemParticipantResultFactoryTest.groovy
162 lines (142 loc) · 5.97 KB
/
SystemParticipantResultFactoryTest.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
/*
* © 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.result
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.io.factory.SimpleEntityData
import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.datamodel.models.result.system.*
import edu.ie3.datamodel.utils.Try
import edu.ie3.test.helper.FactoryTestHelper
import spock.lang.Specification
import tech.units.indriya.unit.Units
class SystemParticipantResultFactoryTest extends Specification implements FactoryTestHelper {
def "A SystemParticipantResultFactory should contain all expected classes for parsing"() {
given:
def resultFactory = new SystemParticipantResultFactory()
def expectedClasses = [
LoadResult,
FixedFeedInResult,
BmResult,
PvResult,
ChpResult,
WecResult,
StorageResult,
EvcsResult,
EvResult,
HpResult,
EmResult
]
expect:
resultFactory.supportedClasses == Arrays.asList(expectedClasses.toArray())
}
def "A SystemParticipantResultFactory should parse a valid result model correctly"() {
given: "a system participant factory and model data"
def resultFactory = new SystemParticipantResultFactory()
Map<String, String> parameter = [
"time" : "2020-01-30 17:26:44",
"inputModel": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"p" : "2",
"q" : "2"
]
if (modelClass == EvResult || modelClass == StorageResult) {
parameter["soc"] = "10"
}
if (modelClass == HpResult || modelClass == ChpResult) {
parameter["qDot"] = "1"
}
when:
Try<? extends SystemParticipantResult, FactoryException> result = resultFactory.get(new SimpleEntityData(parameter, modelClass))
then:
result.success
result.data.get().getClass() == resultingModelClass
((SystemParticipantResult) result.data.get()).with {
assert p == getQuant(parameter["p"], StandardUnits.ACTIVE_POWER_RESULT)
assert q == getQuant(parameter["q"], StandardUnits.REACTIVE_POWER_RESULT)
assert time == TIME_UTIL.toZonedDateTime(parameter["time"])
assert inputModel == UUID.fromString(parameter["inputModel"])
}
if (modelClass == EvResult) {
assert (((EvResult) result.data.get()).soc == getQuant(parameter["soc"], Units.PERCENT))
}
if (modelClass == StorageResult) {
assert (((StorageResult) result.data.get()).soc == getQuant(parameter["soc"], Units.PERCENT))
}
if (modelClass == HpResult) {
assert(((HpResult) result.data.get()).getqDot() == getQuant(parameter["qDot"], StandardUnits.Q_DOT_RESULT))
}
if (modelClass == ChpResult) {
assert(((ChpResult) result.data.get()).getqDot() == getQuant(parameter["qDot"], StandardUnits.Q_DOT_RESULT))
}
where:
modelClass || resultingModelClass
LoadResult || LoadResult
FixedFeedInResult || FixedFeedInResult
BmResult || BmResult
EvResult || EvResult
PvResult || PvResult
EvcsResult || EvcsResult
ChpResult || ChpResult
WecResult || WecResult
HpResult || HpResult
StorageResult || StorageResult
EmResult || EmResult
}
def "A SystemParticipantResultFactory should parse a StorageResult correctly"() {
given: "a system participant factory and model data"
def resultFactory = new SystemParticipantResultFactory()
Map<String, String> parameter = [
"time" : "2020-01-30 17:26:44",
"inputModel": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"soc" : "20",
"p" : "2",
"q" : "2"
]
when:
Try<? extends SystemParticipantResult, FactoryException> result = resultFactory.get(new SimpleEntityData(parameter, StorageResult))
then:
result.success
result.data.get().getClass() == StorageResult
((StorageResult) result.data.get()).with {
assert p == getQuant(parameter["p"], StandardUnits.ACTIVE_POWER_RESULT)
assert q == getQuant(parameter["q"], StandardUnits.REACTIVE_POWER_RESULT)
assert soc == getQuant(parameter["soc"], Units.PERCENT)
assert time == TIME_UTIL.toZonedDateTime(parameter["time"])
assert inputModel == UUID.fromString(parameter["inputModel"])
}
}
def "A SystemParticipantResultFactory should throw an exception on invalid or incomplete data"() {
given: "a system participant factory and model data"
def resultFactory = new SystemParticipantResultFactory()
def foundFields = resultFactory.newSet("time", "input_model", "q")
when:
Try<SystemParticipantResult, FactoryException> result = Try.ofVoid(() -> resultFactory.validate(foundFields, WecResult), FactoryException)
then:
result.failure
result.exception.get().message == "The provided fields [input_model, q, time] are invalid for instance of 'WecResult'. \n" +
"The following fields (without complex objects e.g. nodes, operators, ...) to be passed to a constructor of 'WecResult' are possible (NOT case-sensitive!):\n" +
"0: [inputModel, p, q, time] or [input_model, p, q, time]\n" +
"1: [inputModel, p, q, time, uuid] or [input_model, p, q, time, uuid]\n"
}
def "A SystemParticipantResultFactory should be performant"() {
given: "a factory and dummy model data"
def resultFactory = new SystemParticipantResultFactory()
Map<String, String> parameter = [
"time" : "2020-01-30 17:26:44",
"inputModel": "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"soc" : "20",
"p" : "2",
"q" : "2",
]
expect: "that the factory should not need more than 3 seconds for processing 10.000 entities"
Long startTime = System.currentTimeMillis()
10000.times {
resultFactory.get(new SimpleEntityData(parameter, StorageResult))
}
BigDecimal elapsedTime = (System
.currentTimeMillis() - startTime) / 1000.0
elapsedTime < 3
}
}