-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynawoEventModelsSupplierTest.java
145 lines (132 loc) · 6.08 KB
/
DynawoEventModelsSupplierTest.java
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
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawo.suppliers;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.dynamicsimulation.EventModel;
import com.powsybl.dynawo.models.events.EventActivePowerVariationBuilder;
import com.powsybl.dynawo.models.events.EventDisconnectionBuilder;
import com.powsybl.dynawo.suppliers.events.DynawoEventModelsSupplier;
import com.powsybl.dynawo.suppliers.events.EventModelConfig;
import com.powsybl.dynawo.suppliers.events.EventModelConfigsJsonDeserializer;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TwoSides;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
class DynawoEventModelsSupplierTest {
@Test
void testEventSupplier() {
Network network = EurostagTutorialExample1Factory.createWithLFResults();
List<EventModelConfig> eventModelConfigList = getEventConfigs();
List<EventModel> events = new DynawoEventModelsSupplier(eventModelConfigList).get(network, ReportNode.NO_OP);
EventModel disconnection = EventDisconnectionBuilder.of(network)
.staticId("NHV1_NHV2_2")
.startTime(1)
.disconnectOnly(TwoSides.TWO)
.build();
EventModel step = EventActivePowerVariationBuilder.of(network)
.staticId("LOAD")
.startTime(1)
.deltaP(20)
.build();
assertEquals(2, events.size());
assertThat(events.get(0)).usingRecursiveComparison().isEqualTo(disconnection);
assertThat(events.get(1)).usingRecursiveComparison().isEqualTo(step);
}
@Test
void testWrongNameBuilder() {
Network network = EurostagTutorialExample1Factory.create();
List<EventModelConfig> eventModelConfigList = List.of(
new EventModelConfig("WrongName", Collections.emptyList())
);
List<EventModel> events = new DynawoEventModelsSupplier(eventModelConfigList).get(network, ReportNode.NO_OP);
assertTrue(events.isEmpty());
}
@Test
void testSupplierFromPath() throws URISyntaxException {
Network network = EurostagTutorialExample1Factory.create();
Path path = Path.of(Objects.requireNonNull(getClass().getResource("/suppliers/events.json")).toURI());
List<EventModel> models = DynawoEventModelsSupplier.load(path).get(network);
assertEquals(1, models.size());
}
@Test
void testEventModelConfigDeserializer() throws IOException {
SupplierJsonDeserializer<EventModelConfig> deserializer = new SupplierJsonDeserializer<>(new EventModelConfigsJsonDeserializer());
try (InputStream is = getClass().getResourceAsStream("/suppliers/events.json")) {
List<EventModelConfig> configs = deserializer.deserialize(is);
assertEquals(1, configs.size());
assertThat(configs.get(0)).usingRecursiveComparison().isEqualTo(getActivePowerVariationConfig());
}
}
@Test
void wrongPropertyException() {
Network network = EurostagTutorialExample1Factory.create();
EventModelConfig eventModelConfig = new EventModelConfig("Disconnect", List.of(
new PropertyBuilder()
.name("wrongName")
.value("NHV1_NHV2_2")
.type(PropertyType.STRING)
.build()
));
DynawoEventModelsSupplier supplier = new DynawoEventModelsSupplier(List.of(eventModelConfig));
Exception e = assertThrows(PowsyblException.class, () -> supplier.get(network, ReportNode.NO_OP));
assertEquals("Method wrongName not found for parameter NHV1_NHV2_2 on builder EventDisconnectionBuilder", e.getMessage());
}
private static List<EventModelConfig> getEventConfigs() {
return List.of(
new EventModelConfig("Disconnect", List.of(
new PropertyBuilder()
.name("staticId")
.value("NHV1_NHV2_2")
.type(PropertyType.STRING)
.build(),
new PropertyBuilder()
.name("startTime")
.value("1")
.type(PropertyType.DOUBLE)
.build(),
new PropertyBuilder()
.name("disconnectOnly")
.value("TWO")
.type(PropertyType.TWO_SIDES)
.build()
)),
getActivePowerVariationConfig()
);
}
private static EventModelConfig getActivePowerVariationConfig() {
return new EventModelConfig("Step", List.of(
new PropertyBuilder()
.name("staticId")
.value("LOAD")
.type(PropertyType.STRING)
.build(),
new PropertyBuilder()
.name("startTime")
.value("1")
.type(PropertyType.DOUBLE)
.build(),
new PropertyBuilder()
.name("deltaP")
.value("20")
.type(PropertyType.DOUBLE)
.build()));
}
}