-
Notifications
You must be signed in to change notification settings - Fork 5
/
CsvGraphicSourceTest.groovy
170 lines (140 loc) · 6.68 KB
/
CsvGraphicSourceTest.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
165
166
167
168
169
170
/*
* © 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 edu.ie3.datamodel.io.factory.FactoryData
import edu.ie3.datamodel.io.factory.input.graphics.LineGraphicInputEntityData
import edu.ie3.datamodel.io.factory.input.graphics.NodeGraphicInputEntityData
import edu.ie3.datamodel.models.input.NodeInput
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.input.graphics.NodeGraphicInput
import edu.ie3.test.common.GridTestData as gtd
import org.locationtech.jts.geom.LineString
import org.locationtech.jts.geom.Point
import spock.lang.Specification
class CsvGraphicSourceTest extends Specification implements CsvTestDataMeta {
def "A CsvGraphicSource should provide an instance of GraphicElements based on valid input data correctly"() {
given:
def typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
def rawGridSource = new CsvRawGridSource(csvSep, gridDefaultFolderPath, fileNamingStrategy, typeSource)
def csvGraphicSource = new CsvGraphicSource(csvSep, graphicsFolderPath, fileNamingStrategy, typeSource, rawGridSource)
when:
def graphicElements = csvGraphicSource.graphicElements
then:
graphicElements.allEntitiesAsList().size() == 3
graphicElements.nodeGraphics.size() == 2
graphicElements.lineGraphics.size() == 1
}
def "A CsvGraphicSource should process invalid input data as expected when requested to provide an instance of GraphicElements"() {
given:
def typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
def rawGridSource =
new CsvRawGridSource(csvSep, gridDefaultFolderPath, fileNamingStrategy, typeSource) {
@Override
Set<NodeInput> getNodes() {
return Collections.emptySet()
}
@Override
Set<NodeInput> getNodes(Set<OperatorInput> operators) {
return Collections.emptySet()
}
}
def csvGraphicSource = new CsvGraphicSource(csvSep, graphicsFolderPath, fileNamingStrategy, typeSource, rawGridSource)
when:
def graphicElements = csvGraphicSource.graphicElements
then:
graphicElements.nodeGraphics.empty
graphicElements.lineGraphics.empty
}
def "A CsvGraphicSource should read and handle a valid node graphics file as expected"() {
given:
def csvGraphicSource = new CsvGraphicSource(csvSep, graphicsFolderPath, fileNamingStrategy, Mock(CsvTypeSource), Mock(CsvRawGridSource))
def expectedNodeGraphicD = new NodeGraphicInput(
gtd.nodeGraphicD.uuid,
gtd.nodeGraphicD.graphicLayer,
gtd.nodeGraphicD.path,
gtd.nodeD,
gtd.geoJsonReader.read("{ \"type\": \"Point\", \"coordinates\": [7.4116482, 51.4843281] }") as Point
)
def expectedNodeGraphicC = new NodeGraphicInput(
gtd.nodeGraphicC.uuid,
gtd.nodeGraphicC.graphicLayer,
gtd.geoJsonReader.read("{ \"type\": \"LineString\", \"coordinates\": [[7.4116482, 51.4843281], [7.4116482, 51.4843281]]}") as LineString,
gtd.nodeC,
gtd.nodeGraphicC.point
)
when:
def nodeGraphics = csvGraphicSource.getNodeGraphicInput([gtd.nodeC, gtd.nodeD] as Set)
then:
nodeGraphics.size() == 2
nodeGraphics == [
expectedNodeGraphicC,
expectedNodeGraphicD
] as Set
}
def "A CsvGraphicSource should read and handle a valid line graphics file as expected"() {
given:
def csvGraphicSource = new CsvGraphicSource(csvSep, graphicsFolderPath, fileNamingStrategy, Mock(CsvTypeSource), Mock(CsvRawGridSource))
when:
def lineGraphics = csvGraphicSource.getLineGraphicInput([gtd.lineCtoD] as Set)
then:
lineGraphics.size() == 1
lineGraphics.first() == gtd.lineGraphicCtoD
}
def "A CsvGraphicSource should build node graphic entity data from valid and invalid input data correctly"() {
given:
def csvGraphicSource = new CsvGraphicSource(csvSep, graphicsFolderPath, fileNamingStrategy, Mock(CsvTypeSource), Mock(CsvRawGridSource))
def fieldsToAttributesMap = [
"uuid" : "09aec636-791b-45aa-b981-b14edf171c4c",
"graphic_layer": "main",
"node" : "bd837a25-58f3-44ac-aa90-c6b6e3cd91b2",
"path" : "",
"point" : "{\"type\":\"Point\",\"coordinates\":[0.0,10],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}"
]
expect:
def res = csvGraphicSource.buildNodeGraphicEntityData(new FactoryData.MapWithRowIndex("-1", fieldsToAttributesMap), nodeCollection as Set)
res.present == isPresent
res.ifPresent({ value ->
assert value == new NodeGraphicInputEntityData(new FactoryData.MapWithRowIndex("-1", [
"uuid" : "09aec636-791b-45aa-b981-b14edf171c4c",
"graphic_layer": "main",
"path" : "",
"point" : "{\"type\":\"Point\",\"coordinates\":[0.0,10],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}"
]), gtd.nodeC)
assert value.node == gtd.nodeC
})
where:
nodeCollection || isPresent
[]|| false // no nodes provide
[gtd.nodeA, gtd.nodeB]|| false // node cannot be found
[gtd.nodeC]|| true // node found
}
def "A CsvGraphicSource should build line graphic entity data from valid and invalid input data correctly"() {
given:
def csvGraphicSource = new CsvGraphicSource(csvSep, graphicsFolderPath, fileNamingStrategy, Mock(CsvTypeSource), Mock(CsvRawGridSource))
def fieldsToAttributesMap = [
"uuid" : "ece86139-3238-4a35-9361-457ecb4258b0",
"graphic_layer": "main",
"line" : "92ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"path" : "{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[0.0,10]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}"
]
expect:
def res = csvGraphicSource.buildLineGraphicEntityData(new FactoryData.MapWithRowIndex("-1", fieldsToAttributesMap), nodeCollection as Set)
res.present == isPresent
res.ifPresent({ value ->
assert value == new LineGraphicInputEntityData(new FactoryData.MapWithRowIndex("-1", ["uuid" : "ece86139-3238-4a35-9361-457ecb4258b0",
"graphic_layer": "main",
"path" : "{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[0.0,10]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}"
])
, gtd.lineAtoB)
assert value.line == gtd.lineAtoB
})
where:
nodeCollection || isPresent
[]|| false // no nodes provide
[gtd.lineCtoD]|| false // line cannot be found
[gtd.lineAtoB]|| true // line found
}
}