-
Notifications
You must be signed in to change notification settings - Fork 5
/
CosmoIdCoordinateFactoryTest.groovy
82 lines (69 loc) · 2.34 KB
/
CosmoIdCoordinateFactoryTest.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
/*
* © 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.timeseries
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.io.factory.SimpleFactoryData
import edu.ie3.datamodel.utils.Try
import edu.ie3.util.geo.GeoUtils
import org.apache.commons.lang3.tuple.Pair
import org.locationtech.jts.geom.Point
import spock.lang.Shared
import spock.lang.Specification
class CosmoIdCoordinateFactoryTest extends Specification {
@Shared
CosmoIdCoordinateFactory factory
def setupSpec() {
factory = new CosmoIdCoordinateFactory()
}
def "A COSMO id to coordinate factory returns correct fields"() {
given:
def expectedFields = [
"tid",
"id",
"latRot",
"longRot",
"latGeo",
"longGeo"
] as Set
when:
def actual = factory.getFields(Pair)
then:
actual.size() == 1
actual.head() == expectedFields
}
def "A COSMO id to coordinate factory refuses to build from invalid data"() {
given:
def foundFields = factory.newSet("tid", "id", "latrot", "longrot")
when:
def actual = factory.validate(foundFields, Pair)
then:
actual.failure
actual.exception.get().message == "The provided fields [id, latrot, longrot, tid] are invalid for instance of 'Pair'. \n" +
"The following fields (without complex objects e.g. nodes, operators, ...) to be passed to a constructor of 'Pair' are possible (NOT case-sensitive!):\n" +
"0: [id, latGeo, latRot, longGeo, longRot, tid] or [id, lat_geo, lat_rot, long_geo, long_rot, tid]\n"
}
def "A COSMO id to coordinate factory builds model from valid data"() {
given:
Map<String, String> parameter = [
"tid": "1",
"id": "106580",
"latGeo": "39.602772",
"longGeo": "1.279336",
"latRot": "-10",
"longRot": "-6.8125"
]
def validSimpleFactoryData = new SimpleFactoryData(parameter, Pair)
Pair<Integer, Point> expectedPair = Pair.of(106580, GeoUtils.buildPoint(39.602772, 1.279336))
when:
def actual = factory.get(validSimpleFactoryData)
then:
actual.success
actual.data.get().with {
assert it.key == expectedPair.key
assert it.value.equalsExact(expectedPair.value, 1E-6)
}
}
}