-
Notifications
You must be signed in to change notification settings - Fork 5
/
SqlWeatherSourceIconIT.groovy
111 lines (97 loc) · 5.12 KB
/
SqlWeatherSourceIconIT.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
/*
* © 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.sql
import edu.ie3.datamodel.io.connectors.SqlConnector
import edu.ie3.datamodel.io.factory.timeseries.IconTimeBasedWeatherValueFactory
import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
import edu.ie3.datamodel.models.value.WeatherValue
import edu.ie3.test.common.IconWeatherTestData
import edu.ie3.test.helper.TestContainerHelper
import edu.ie3.test.helper.WeatherSourceTestHelper
import edu.ie3.util.TimeUtil
import edu.ie3.util.interval.ClosedInterval
import org.locationtech.jts.geom.Point
import org.testcontainers.containers.Container
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.spock.Testcontainers
import org.testcontainers.utility.MountableFile
import spock.lang.Shared
import spock.lang.Specification
@Testcontainers
class SqlWeatherSourceIconIT extends Specification implements TestContainerHelper, WeatherSourceTestHelper {
@Shared
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:14.2")
@Shared
SqlWeatherSource source
static String schemaName = "public"
static String weatherTableName = "weather"
def setupSpec() {
// Copy sql import script into docker
MountableFile sqlImportFile = getMountableFile("_weather/icon/weather.sql")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/weather_icon.sql")
// Execute import script
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather_icon.sql")
assert res.stderr.empty
def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
def weatherFactory = new IconTimeBasedWeatherValueFactory(TimeUtil.withDefaults)
source = new SqlWeatherSource(connector, IconWeatherTestData.coordinateSource, schemaName, weatherTableName, weatherFactory)
}
def "A NativeSqlWeatherSource can read and correctly parse a single value for a specific date and coordinate"() {
given:
def expectedTimeBasedValue = new TimeBasedValue(IconWeatherTestData.TIME_15H, IconWeatherTestData.WEATHER_VALUE_67775_15H)
when:
def optTimeBasedValue = source.getWeather(IconWeatherTestData.TIME_15H, IconWeatherTestData.COORDINATE_67775)
then:
optTimeBasedValue.present
equalsIgnoreUUID(optTimeBasedValue.get(), expectedTimeBasedValue )
}
def "A NativeSqlWeatherSource can read multiple timeseries values for multiple coordinates"() {
given:
def coordinates = [
IconWeatherTestData.COORDINATE_67775,
IconWeatherTestData.COORDINATE_67776
]
def timeInterval = new ClosedInterval(IconWeatherTestData.TIME_16H, IconWeatherTestData.TIME_17H)
def timeSeries67775 = new IndividualTimeSeries(null,
[
new TimeBasedValue(IconWeatherTestData.TIME_16H, IconWeatherTestData.WEATHER_VALUE_67775_16H),
new TimeBasedValue(IconWeatherTestData.TIME_17H, IconWeatherTestData.WEATHER_VALUE_67775_17H)
]
as Set<TimeBasedValue>)
def timeSeries67776 = new IndividualTimeSeries(null,
[
new TimeBasedValue(IconWeatherTestData.TIME_16H, IconWeatherTestData.WEATHER_VALUE_67776_16H)
] as Set<TimeBasedValue>)
when:
Map<Point, IndividualTimeSeries<WeatherValue>> coordinateToTimeSeries = source.getWeather(timeInterval, coordinates)
then:
coordinateToTimeSeries.keySet().size() == 2
equalsIgnoreUUID(coordinateToTimeSeries.get(IconWeatherTestData.COORDINATE_67775), timeSeries67775)
equalsIgnoreUUID(coordinateToTimeSeries.get(IconWeatherTestData.COORDINATE_67776), timeSeries67776)
}
def "A NativeSqlWeatherSource can read all weather data in a given time interval"() {
given:
def timeInterval = new ClosedInterval(IconWeatherTestData.TIME_15H, IconWeatherTestData.TIME_17H)
def timeSeries67775 = new IndividualTimeSeries(null,
[
new TimeBasedValue(IconWeatherTestData.TIME_15H, IconWeatherTestData.WEATHER_VALUE_67775_15H),
new TimeBasedValue(IconWeatherTestData.TIME_16H, IconWeatherTestData.WEATHER_VALUE_67775_16H),
new TimeBasedValue(IconWeatherTestData.TIME_17H, IconWeatherTestData.WEATHER_VALUE_67775_17H)
] as Set<TimeBasedValue>)
def timeSeries67776 = new IndividualTimeSeries(null,
[
new TimeBasedValue(IconWeatherTestData.TIME_15H, IconWeatherTestData.WEATHER_VALUE_67776_15H),
new TimeBasedValue(IconWeatherTestData.TIME_16H, IconWeatherTestData.WEATHER_VALUE_67776_16H)
] as Set<TimeBasedValue>)
when:
Map<Point, IndividualTimeSeries<WeatherValue>> coordinateToTimeSeries = source.getWeather(timeInterval)
then:
coordinateToTimeSeries.keySet().size() == 2
equalsIgnoreUUID(coordinateToTimeSeries.get(IconWeatherTestData.COORDINATE_67775).entries, timeSeries67775.entries)
equalsIgnoreUUID(coordinateToTimeSeries.get(IconWeatherTestData.COORDINATE_67776).entries, timeSeries67776.entries)
}
}