-
Notifications
You must be signed in to change notification settings - Fork 5
/
CsvTimeSeriesSourceIT.groovy
86 lines (67 loc) · 2.88 KB
/
CsvTimeSeriesSourceIT.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
/*
* © 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 static edu.ie3.test.common.TimeSeriesSourceTestData.*
import edu.ie3.datamodel.exceptions.SourceException
import edu.ie3.datamodel.io.naming.FileNamingStrategy
import edu.ie3.datamodel.io.factory.timeseries.TimeBasedSimpleValueFactory
import edu.ie3.datamodel.models.value.HeatAndPValue
import edu.ie3.util.interval.ClosedInterval
import spock.lang.Shared
import spock.lang.Specification
class CsvTimeSeriesSourceIT extends Specification implements CsvTestDataMeta {
@Shared
CsvTimeSeriesSource source
@Shared
TimeBasedSimpleValueFactory<HeatAndPValue> factory
def setup() {
factory = new TimeBasedSimpleValueFactory<>(HeatAndPValue)
source = new CsvTimeSeriesSource(";", timeSeriesFolderPath, new FileNamingStrategy(), UUID.fromString("76c9d846-797c-4f07-b7ec-2245f679f5c7"), "its_ph_76c9d846-797c-4f07-b7ec-2245f679f5c7", HeatAndPValue, factory)
}
def "A csv time series source throw an Exception, if the file cannot be found"() {
given:
def filePath = "file/not/found.csv"
when:
source.buildIndividualTimeSeries(UUID.fromString("fbc59b5b-9307-4fb4-a406-c1f08f26fee5"), filePath, { null })
then:
def ex = thrown(SourceException)
ex.message == "Unable to find a file with path '" + filePath + "'."
ex.cause.class == FileNotFoundException
}
def "A csv time series source is able to read in a proper file correctly"() {
given:
def filePath = "its_ph_76c9d846-797c-4f07-b7ec-2245f679f5c7"
def tsUuid = UUID.fromString("76c9d846-797c-4f07-b7ec-2245f679f5c7")
when:
def actual = source.buildIndividualTimeSeries(tsUuid, filePath, { source.createTimeBasedValue(it) })
then:
noExceptionThrown()
actual.entries.size() == 2
}
def "Construction a csv time series source with malicious parameters, leads to IllegalArgumentException"() {
when:
new CsvTimeSeriesSource(";", timeSeriesFolderPath, new FileNamingStrategy(), UUID.fromString("fbc59b5b-9307-4fb4-a406-c1f08f26fee5"), "file/not/found", HeatAndPValue, factory)
then:
def e = thrown(IllegalArgumentException)
e.message == "Unable to obtain time series with UUID 'fbc59b5b-9307-4fb4-a406-c1f08f26fee5'. Please check arguments!"
e.cause.class == SourceException
}
def "A csv time series source is able to return a time series for a period of interest"() {
given:
def interval = new ClosedInterval(TIME_15MIN, TIME_15MIN)
when:
def actual = source.getTimeSeries(interval)
then:
actual.entries.size() == 1
}
def "A csv time series source is able to return a single value, if it is covered"() {
when:
def actual = source.getValue(TIME_15MIN)
then:
actual.present
actual.get() == PH_VALUE_15MIN
}
}