-
Notifications
You must be signed in to change notification settings - Fork 5
/
EvcsInputFactoryTest.groovy
144 lines (131 loc) · 5.8 KB
/
EvcsInputFactoryTest.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
/*
* © 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.input.participant
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.io.factory.input.NodeAssetInputEntityData
import edu.ie3.datamodel.models.input.NodeInput
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.input.system.EvcsInput
import edu.ie3.datamodel.models.input.system.characteristic.CharacteristicPoint
import edu.ie3.datamodel.models.input.system.type.chargingpoint.ChargingPointTypeUtils
import edu.ie3.datamodel.models.input.system.type.evcslocation.EvcsLocationType
import edu.ie3.datamodel.utils.Try
import edu.ie3.test.helper.FactoryTestHelper
import edu.ie3.util.quantities.PowerSystemUnits
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities
import javax.measure.quantity.Dimensionless
import java.time.ZonedDateTime
/**
* Testing EvcsInputFactory
*
* @version 0.1* @since 26.07.20
*/
class EvcsInputFactoryTest extends Specification implements FactoryTestHelper {
def "A EvcsInputFactory should contain exactly the expected class for parsing"() {
given:
def inputFactory = new EvcsInputFactory()
def expectedClasses = [EvcsInput]
expect:
inputFactory.supportedClasses == Arrays.asList(expectedClasses.toArray())
}
def "A EvcsInputFactory should parse a valid EvcsInput correctly"() {
given: "a system participant input type factory and model data"
def inputFactory = new EvcsInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"operatesfrom" : "2019-01-01T00:00:00+01:00[Europe/Berlin]",
"operatesuntil" : "2019-12-31T23:59:00+01:00[Europe/Berlin]",
"id" : "TestID",
"qcharacteristics": "cosPhiFixed:{(0.0,1.0)}",
"type" : "Household",
"chargingpoints" : "4",
"cosphirated" : "0.95",
"locationtype" : "CHARGING_HUB_TOWN",
"v2gsupport" : "false"
]
def inputClass = EvcsInput
def nodeInput = Mock(NodeInput)
def operatorInput = Mock(OperatorInput)
when:
Try<EvcsInput, FactoryException> input = inputFactory.get(
new NodeAssetInputEntityData(parameter, inputClass, operatorInput, nodeInput))
then:
input.success
input.data.get().getClass() == inputClass
input.data.get().with {
assert uuid == UUID.fromString(parameter["uuid"])
assert operationTime.startDate.present
assert operationTime.startDate.get() == ZonedDateTime.parse(parameter["operatesfrom"])
assert operationTime.endDate.present
assert operationTime.endDate.get() == ZonedDateTime.parse(parameter["operatesuntil"])
assert operator == operatorInput
assert id == parameter["id"]
assert node == nodeInput
assert qCharacteristics.with {
assert uuid != null
assert points == Collections.unmodifiableSortedSet([
new CharacteristicPoint<Dimensionless, Dimensionless>(Quantities.getQuantity(0d, PowerSystemUnits.PU), Quantities.getQuantity(1d, PowerSystemUnits.PU))
] as TreeSet)
}
assert type == ChargingPointTypeUtils.HouseholdSocket
assert chargingPoints == Integer.parseInt(parameter["chargingpoints"])
assert cosPhiRated == Double.parseDouble(parameter["cosphirated"])
assert locationType == EvcsLocationType.CHARGING_HUB_TOWN
assert !v2gSupport
}
}
def "A EvcsInputFactory should fail when passing an invalid ChargingPointType"() {
given: "a system participant input type factory and model data"
def inputFactory = new EvcsInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"operatesfrom" : "2019-01-01T00:00:00+01:00[Europe/Berlin]",
"operatesuntil" : "2019-12-31T23:59:00+01:00[Europe/Berlin]",
"id" : "TestID",
"qcharacteristics": "cosPhiFixed:{(0.0,1.0)}",
"type" : "-- invalid --",
"chargingpoints" : "4",
"cosphirated" : "0.95",
"locationtype" : "CHARGING_HUB_TOWN",
"v2gsupport" : "false"
]
def inputClass = EvcsInput
def nodeInput = Mock(NodeInput)
def operatorInput = Mock(OperatorInput)
when:
Try<EvcsInput, FactoryException> input = inputFactory.get(
new NodeAssetInputEntityData(parameter, inputClass, operatorInput, nodeInput))
then:
input.failure
input.exception.get().cause.message == "Exception while trying to parse field \"type\" with supposed int value \"-- invalid --\""
}
def "A EvcsInputFactory should fail when passing an invalid EvcsLocationType"() {
given: "a system participant input type factory and model data"
def inputFactory = new EvcsInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"operatesfrom" : "2019-01-01T00:00:00+01:00[Europe/Berlin]",
"operatesuntil" : "2019-12-31T23:59:00+01:00[Europe/Berlin]",
"id" : "TestID",
"qcharacteristics": "cosPhiFixed:{(0.0,1.0)}",
"type" : "Household",
"chargingpoints" : "4",
"cosphirated" : "0.95",
"locationType" : "-- invalid --",
"v2gsupport" : "false"
]
def inputClass = EvcsInput
def nodeInput = Mock(NodeInput)
def operatorInput = Mock(OperatorInput)
when:
Try<EvcsInput, FactoryException> input = inputFactory.get(
new NodeAssetInputEntityData(parameter, inputClass, operatorInput, nodeInput))
then:
input.failure
input.exception.get().cause.message == "Exception while trying to parse field \"locationtype\" with supposed int value \"-- invalid --\""
}
}