Skip to content

Commit 9249e32

Browse files
committed
Add tests
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent bd0b80f commit 9249e32

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
package com.powsybl.nad.svg.iidm;
9+
10+
import com.powsybl.diagram.test.Networks;
11+
import com.powsybl.iidm.network.Network;
12+
import com.powsybl.nad.model.BranchEdge;
13+
import org.junit.jupiter.api.Test;
14+
15+
import java.util.List;
16+
import java.util.Map;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
20+
class TopologicalStyleProviderTest {
21+
22+
@Test
23+
void customLimitViolationStyleOverridesDefaultBranchStyle() {
24+
Network network = Networks.createNetworkWithLine();
25+
TopologicalStyleProvider provider = new TopologicalStyleProvider(network, Map.of("Line", "custom-style"));
26+
BranchEdge branchEdge = new BranchEdge("diagram", "Line", "Line", BranchEdge.LINE_EDGE);
27+
28+
List<String> styles = provider.getBranchEdgeStyleClasses(branchEdge);
29+
30+
assertEquals(List.of("custom-style"), styles);
31+
}
32+
33+
@Test
34+
void missingCustomStyleFallsBackToDefaultBranchStyle() {
35+
Network network = Networks.createNetworkWithLine();
36+
BranchEdge branchEdge = new BranchEdge("diagram", "Line", "Line", BranchEdge.LINE_EDGE);
37+
38+
TopologicalStyleProvider defaultProvider = new TopologicalStyleProvider(network);
39+
List<String> defaultStyles = defaultProvider.getBranchEdgeStyleClasses(branchEdge);
40+
41+
TopologicalStyleProvider providerWithCustomMap = new TopologicalStyleProvider(network, Map.of("OtherLine", "custom-style"));
42+
List<String> styles = providerWithCustomMap.getBranchEdgeStyleClasses(branchEdge);
43+
44+
assertEquals(defaultStyles, styles);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
package com.powsybl.sld.svg.styles.iidm;
9+
10+
import com.powsybl.diagram.test.Networks;
11+
import com.powsybl.iidm.network.Network;
12+
import com.powsybl.sld.model.graphs.VoltageLevelInfos;
13+
import com.powsybl.sld.model.nodes.BusNode;
14+
import com.powsybl.sld.model.nodes.Edge;
15+
import com.powsybl.sld.model.nodes.FeederNode;
16+
import com.powsybl.sld.model.nodes.FeederType;
17+
import com.powsybl.sld.model.nodes.NodeSide;
18+
import com.powsybl.sld.model.nodes.feeders.FeederWithSides;
19+
import org.junit.jupiter.api.Test;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
26+
class LimitHighlightStyleProviderTest {
27+
28+
private static Edge buildEdge(String equipmentId) {
29+
FeederWithSides feeder = new FeederWithSides(
30+
FeederType.BRANCH,
31+
NodeSide.ONE,
32+
new VoltageLevelInfos("VL1", "VoltageLevel1", 225.0),
33+
new VoltageLevelInfos("VL2", "VoltageLevel2", 225.0)
34+
);
35+
FeederNode feederNode = new FeederNode("feederNode", "Feeder", equipmentId, "component", false, feeder, null);
36+
BusNode busNode = new BusNode("busNode", "Bus", false);
37+
return new Edge(feederNode, busNode);
38+
}
39+
40+
@Test
41+
void customLimitViolationStyleOverridesDefaultEdgeStyles() {
42+
Network network = Networks.createNetworkWithLine();
43+
LimitHighlightStyleProvider provider = new LimitHighlightStyleProvider(network, Map.of("Line", "custom-style"));
44+
Edge edge = buildEdge("Line");
45+
46+
List<String> styles = provider.getEdgeStyles(null, edge);
47+
48+
assertEquals(List.of("custom-style"), styles);
49+
}
50+
51+
@Test
52+
void missingCustomStyleFallsBackToDefaultEdgeStyles() {
53+
Network network = Networks.createNetworkWithLine();
54+
Edge edge = buildEdge("Line");
55+
56+
LimitHighlightStyleProvider defaultProvider = new LimitHighlightStyleProvider(network);
57+
List<String> defaultStyles = defaultProvider.getEdgeStyles(null, edge);
58+
59+
LimitHighlightStyleProvider providerWithCustomMap = new LimitHighlightStyleProvider(network, Map.of("OtherLine", "custom-style"));
60+
List<String> styles = providerWithCustomMap.getEdgeStyles(null, edge);
61+
62+
assertEquals(defaultStyles, styles);
63+
}
64+
}

0 commit comments

Comments
 (0)