-
Notifications
You must be signed in to change notification settings - Fork 5
/
EntitySourceTest.groovy
111 lines (90 loc) · 4.65 KB
/
EntitySourceTest.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
/*
* © 2023. 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
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.exceptions.ValidationException
import edu.ie3.datamodel.io.factory.input.ThermalBusInputFactory
import edu.ie3.datamodel.io.naming.FileNamingStrategy
import edu.ie3.datamodel.io.source.csv.CsvDataSource
import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput
import edu.ie3.test.common.GridTestData as gtd
import edu.ie3.test.common.SystemParticipantTestData as sptd
import spock.lang.Shared
import spock.lang.Specification
import java.nio.file.Path
class EntitySourceTest extends Specification {
private final class DummyEntitySource extends EntitySource {
DummyEntitySource(CsvDataSource dataSource) {
this.dataSource = dataSource
}
@Override
void validate() throws ValidationException {
}
}
@Shared
String csvSep = ","
@Shared
Path testBaseFolderPath = Path.of("testBaseFolderPath") // does not have to exist for this test
@Shared
FileNamingStrategy fileNamingStrategy = new FileNamingStrategy()
CsvDataSource csvDataSource = new CsvDataSource(csvSep, testBaseFolderPath, fileNamingStrategy)
DummyEntitySource dummyEntitySource = new DummyEntitySource(csvDataSource)
def "A csv data source is able to find the correct first entity by uuid"() {
given:
def uuid = UUID.randomUUID()
def queriedOperator = new OperatorInput(uuid, "b")
def entities = Arrays.asList(
new OperatorInput(UUID.randomUUID(), "a"),
queriedOperator,
new OperatorInput(UUID.randomUUID(), "c")
)
when:
def actual = dummyEntitySource.findFirstEntityByUuid(uuid, entities)
then:
actual.present
actual.get() == queriedOperator
}
def "A CsvDataSource should always return an operator. Either the found one (if any) or OperatorInput.NO_OPERATOR_ASSIGNED"() {
expect:
dummyEntitySource.getFirstOrDefaultOperator(operators, Optional.of(UUID.fromString(operatorUuid)), entityClassName, requestEntityUuid) == expectedOperator
where:
operatorUuid | operators | entityClassName | requestEntityUuid || expectedOperator
"8f9682df-0744-4b58-a122-f0dc730f6510" | [sptd.hpInput.operator] | "TestEntityClass" | "8f9682df-0744-4b58-a122-f0dc730f6511" || sptd.hpInput.operator
"8f9682df-0744-4b58-a122-f0dc730f6520" | [sptd.hpInput.operator] | "TestEntityClass" | "8f9682df-0744-4b58-a122-f0dc730f6511" || OperatorInput.NO_OPERATOR_ASSIGNED
"8f9682df-0744-4b58-a122-f0dc730f6510" | [] | "TestEntityClass" | "8f9682df-0744-4b58-a122-f0dc730f6511" || OperatorInput.NO_OPERATOR_ASSIGNED
}
def "A CsvDataSource should be able to handle the extraction process of an asset type correctly"() {
when:
def assetTypeOpt = dummyEntitySource.getAssetType(types, fieldsToAttributes, "TestClassName")
then:
assetTypeOpt.data.present == resultIsPresent
assetTypeOpt.data.ifPresent({ assetType ->
assert (assetType == resultData)
})
where:
types | fieldsToAttributes || resultIsPresent || resultData
[] | ["type": "202069a7-bcf8-422c-837c-273575220c8a"] || false || null
[] | ["bla": "foo"] || false || null
[gtd.transformerTypeBtoD] | ["type": "202069a7-bcf8-422c-837c-273575220c8a"] || true || gtd.transformerTypeBtoD
[sptd.chpTypeInput] | ["type": "5ebd8f7e-dedb-4017-bb86-6373c4b68eb8"] || true || sptd.chpTypeInput
}
def "A CsvDataSource should not throw an exception but assume NO_OPERATOR_ASSIGNED if the operator field is missing in the headline"() {
given:
def thermalBusInputFieldsToAttributesMap = [
"uuid" : "0d95d7f2-49fb-4d49-8636-383a5220384e",
"id" : "test_thermalBusInput",
"operatesuntil": "2020-03-25T15:11:31Z[UTC]",
"operatesfrom" : "2020-03-24T15:11:31Z[UTC]"
]
when:
def thermalBusInputEntity = new ThermalBusInputFactory().get(dummyEntitySource.assetInputEntityDataStream(ThermalBusInput, thermalBusInputFieldsToAttributesMap, Collections.emptyList()))
then:
noExceptionThrown() // no NPE should be thrown
thermalBusInputEntity.success
thermalBusInputEntity.data.get().operator.id == OperatorInput.NO_OPERATOR_ASSIGNED.id // operator id should be set accordingly
}
}