Skip to content

Commit 48839ae

Browse files
Merge pull request #1470 from ie3-institute/df/#1469-cosmoFactoryTest-fail
Fix CosmoTimeBasedWeatherValueFactoryTest
2 parents 3377483 + 7a7bb21 commit 48839ae

File tree

4 files changed

+69
-16
lines changed

4 files changed

+69
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Updated Controlling_em for all the loads in readthedocs[#1447](https://github.com/ie3-institute/PowerSystemDataModel/issues/1447)
2222
- Included a doFirst clause into `checkJavaVersion.gradle` [#1462](https://github.com/ie3-institute/PowerSystemDataModel/issues/1462)
2323
- Fixed `EnergyPriceValue.equals()` [#1479](https://github.com/ie3-institute/PowerSystemDataModel/issues/1479)
24+
- Fixed tests of `TimeBasedValue` [#1469](https://github.com/ie3-institute/PowerSystemDataModel/issues/1469)
2425

2526
### Changed
2627
- Updated CI-Pipeline to run task `Deploy` and `Staging` only for `Main` [#1403](https://github.com/ie3-institute/PowerSystemDataModel/issues/1403)

src/main/java/edu/ie3/datamodel/models/timeseries/individual/TimeBasedValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public boolean equals(Object o) {
3434
if (o == null || getClass() != o.getClass()) return false;
3535
if (!super.equals(o)) return false;
3636
TimeBasedValue<?> that = (TimeBasedValue<?>) o;
37-
return time.equals(that.time);
37+
return Objects.equals(time, that.time);
3838
}
3939

4040
@Override

src/test/groovy/edu/ie3/datamodel/io/factory/timeseries/CosmoTimeBasedWeatherValueFactoryTest.groovy

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package edu.ie3.datamodel.io.factory.timeseries
77

8+
import edu.ie3.datamodel.exceptions.FactoryException
89
import edu.ie3.datamodel.models.StandardUnits
910
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
1011
import edu.ie3.datamodel.models.value.WeatherValue
@@ -22,7 +23,6 @@ class CosmoTimeBasedWeatherValueFactoryTest extends Specification {
2223
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01T00:00:00Z")
2324

2425
Map<String, String> parameter = [
25-
"uuid" : "980f7714-8def-479f-baae-4deed6c8d6d1",
2626
"time" : TimeUtil.withDefaults.toString(time),
2727
"diffuseIrradiance": "282.671997070312",
2828
"directIrradiance" : "286.872985839844",
@@ -45,7 +45,7 @@ class CosmoTimeBasedWeatherValueFactoryTest extends Specification {
4545
def model = factory.buildModel(data)
4646

4747
then:
48-
model == expectedResults
48+
Objects.equals(model,expectedResults)
4949
}
5050

5151
def "A PsdmTimeBasedWeatherValueFactory should be able to create time series values"() {
@@ -56,7 +56,6 @@ class CosmoTimeBasedWeatherValueFactoryTest extends Specification {
5656

5757
Map<String, String> parameter = [
5858
"time" : TimeUtil.withDefaults.toString(time),
59-
"uuid" : "980f7714-8def-479f-baae-4deed6c8d6d1",
6059
"diffuseIrradiance": "282.671997070312",
6160
"directIrradiance" : "286.872985839844",
6261
"temperature" : "278.019012451172",
@@ -78,6 +77,62 @@ class CosmoTimeBasedWeatherValueFactoryTest extends Specification {
7877
def model = factory.buildModel(data)
7978

8079
then:
81-
model == expectedResults
80+
Objects.equals(model,expectedResults)
81+
}
82+
83+
def "A PsdmTimeBasedWeatherValueFactory should throw FactoryException if required field is missing"() {
84+
given:
85+
def factory = new CosmoTimeBasedWeatherValueFactory()
86+
def coordinate = CosmoWeatherTestData.COORDINATE_193186
87+
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01T00:00:00Z")
88+
89+
// Missing 'directIrradiance' field
90+
Map<String, String> parameter = [
91+
"time" : TimeUtil.withDefaults.toString(time),
92+
"diffuseIrradiance": "182.671997070312",
93+
"temperature" : "278.019012451172",
94+
"windDirection" : "50",
95+
"windVelocity" : "1.66103506088257"
96+
]
97+
98+
def data = new TimeBasedWeatherValueData(parameter, coordinate)
99+
100+
when:
101+
factory.buildModel(data)
102+
103+
then:
104+
thrown(FactoryException)
105+
}
106+
107+
def "Smoke Test: This PsdmTimeBasedWeatherValueFactory should fail since expected results doesn't match input"() {
108+
given:
109+
def factory = new CosmoTimeBasedWeatherValueFactory()
110+
def coordinate = CosmoWeatherTestData.COORDINATE_193186
111+
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01T00:00:00Z")
112+
113+
Map<String, String> parameter = [
114+
"time" : TimeUtil.withDefaults.toString(time),
115+
"diffuseIrradiance": "1.0",
116+
"directIrradiance" : "2.0",
117+
"temperature" : "3.0",
118+
"windDirection" : "4",
119+
"windVelocity" : "5.0"
120+
]
121+
122+
def data = new TimeBasedWeatherValueData(parameter, coordinate)
123+
124+
def expectedResults = new TimeBasedValue(
125+
time, new WeatherValue(coordinate,
126+
Quantities.getQuantity(5.0, StandardUnits.SOLAR_IRRADIANCE),
127+
Quantities.getQuantity(4.0, StandardUnits.SOLAR_IRRADIANCE),
128+
Quantities.getQuantity(3.0, StandardUnits.TEMPERATURE),
129+
Quantities.getQuantity(2d, StandardUnits.WIND_DIRECTION),
130+
Quantities.getQuantity(1.0, StandardUnits.WIND_VELOCITY)))
131+
132+
when:
133+
def model = factory.buildModel(data)
134+
135+
then:
136+
!Objects.equals(model,expectedResults)
82137
}
83138
}

src/test/groovy/edu/ie3/datamodel/io/factory/timeseries/TimeBasedSimpleValueFactoryTest.groovy

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class TimeBasedSimpleValueFactoryTest extends Specification {
9898
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
9999
def time = zonedDateTime
100100
def data = new SimpleTimeBasedValueData([
101-
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
102101
"time": defaultTimeUtil.toString(time),
103102
"price": "52.4"
104103
], EnergyPriceValue)
@@ -128,15 +127,14 @@ class TimeBasedSimpleValueFactoryTest extends Specification {
128127
)
129128

130129
expect:
131-
factory.buildModel(data) == expected
130+
Objects.equals(factory.buildModel(data), expected)
132131
}
133132

134133
def "The simple time based value factory builds correct heat and active power value"() {
135134
given:
136135
def factory = new TimeBasedSimpleValueFactory(HeatAndPValue)
137136
def time = zonedDateTime
138137
def data = new SimpleTimeBasedValueData([
139-
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
140138
"time": defaultTimeUtil.toString(time),
141139
"p": "500.0",
142140
"heatDemand": "8.0"
@@ -147,15 +145,14 @@ class TimeBasedSimpleValueFactoryTest extends Specification {
147145
)
148146

149147
expect:
150-
factory.buildModel(data) == expected
148+
Objects.equals(factory.buildModel(data), expected)
151149
}
152150

153151
def "The simple time based value factory builds correct heat demand value"() {
154152
given:
155153
def factory = new TimeBasedSimpleValueFactory(HeatDemandValue)
156154
def time = zonedDateTime
157155
def data = new SimpleTimeBasedValueData([
158-
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
159156
"time": defaultTimeUtil.toString(time),
160157
"heatDemand": "8.0"
161158
], HeatDemandValue)
@@ -165,15 +162,14 @@ class TimeBasedSimpleValueFactoryTest extends Specification {
165162
)
166163

167164
expect:
168-
factory.buildModel(data) == expected
165+
Objects.equals(factory.buildModel(data), expected)
169166
}
170167

171168
def "The simple time based value factory builds correct apparent power value"() {
172169
given:
173170
def factory = new TimeBasedSimpleValueFactory(SValue)
174171
def time = zonedDateTime
175172
def data = new SimpleTimeBasedValueData([
176-
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
177173
"time": defaultTimeUtil.toString(time),
178174
"p": "500.0",
179175
"q": "165.0"
@@ -184,15 +180,14 @@ class TimeBasedSimpleValueFactoryTest extends Specification {
184180
)
185181

186182
expect:
187-
factory.buildModel(data) == expected
183+
Objects.equals(factory.buildModel(data), expected)
188184
}
189185

190186
def "The simple time based value factory builds correct active power value"() {
191187
given:
192188
def factory = new TimeBasedSimpleValueFactory(PValue)
193189
def time = zonedDateTime
194190
def data = new SimpleTimeBasedValueData([
195-
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
196191
"time": defaultTimeUtil.toString(time),
197192
"p": "500.0"
198193
], PValue)
@@ -201,16 +196,18 @@ class TimeBasedSimpleValueFactoryTest extends Specification {
201196
new PValue(Quantities.getQuantity(500.0, StandardUnits.ACTIVE_POWER_IN))
202197
)
203198

199+
200+
def obj = factory.buildModel(data)
201+
204202
expect:
205-
factory.buildModel(data) == expected
203+
Objects.equals(obj, expected)
206204
}
207205

208206
def "The simple time based value factory throws a FactoryException upon build request, if a class is not supported"() {
209207
given:
210208
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
211209
def time = zonedDateTime
212210
def data = new SimpleTimeBasedValueData([
213-
"uuid": "78ca078a-e6e9-4972-a58d-b2cadbc2df2c",
214211
"time": defaultTimeUtil.toString(time)
215212
], NodeInput)
216213

0 commit comments

Comments
 (0)