-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #426 from com-pas/feat/add-voltage-level-service
feat: add voltage level service
- Loading branch information
Showing
5 changed files
with
108 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
sct-commons/src/main/java/org/lfenergy/compas/sct/commons/VoltageLevelService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.lfenergy.compas.scl2007b4.model.*; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
public class VoltageLevelService { | ||
|
||
public Stream<TVoltageLevel> getVoltageLevels(SCL scd) { | ||
if (!scd.isSetSubstation()) { | ||
return Stream.empty(); | ||
} | ||
return scd.getSubstation() | ||
.stream() | ||
.map(TSubstation::getVoltageLevel) | ||
.flatMap(Collection::stream); | ||
} | ||
|
||
public Optional<TVoltageLevel> findVoltageLevel(SCL scd, Predicate<TVoltageLevel> tVoltageLevelPredicate) { | ||
return getVoltageLevels(scd).filter(tVoltageLevelPredicate).findFirst(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
sct-commons/src/test/java/org/lfenergy/compas/sct/commons/VoltageLevelServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.lfenergy.compas.scl2007b4.model.SCL; | ||
import org.lfenergy.compas.scl2007b4.model.TVoltageLevel; | ||
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
class VoltageLevelServiceTest { | ||
|
||
private final VoltageLevelService voltageLevelService = new VoltageLevelService(); | ||
|
||
@Test | ||
void getVoltageLevels_should_succeed() { | ||
// Given | ||
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml"); | ||
// When | ||
List<TVoltageLevel> tVoltageLevels = voltageLevelService.getVoltageLevels(scd).toList(); | ||
// Then | ||
assertThat(tVoltageLevels).hasSize(2); | ||
} | ||
|
||
@Test | ||
void findVoltageLevel_when_voltageLevelExist_should_succeed() { | ||
// Given | ||
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml"); | ||
// When Then | ||
assertThatCode(() -> voltageLevelService.findVoltageLevel(scd, tVoltageLevel1 -> "4".equals(tVoltageLevel1.getName())).orElseThrow()) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void findVoltageLevel_when_voltageLevelNotExist_should_return_empty() { | ||
// Given | ||
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml"); | ||
// When Then | ||
assertThat(voltageLevelService.findVoltageLevel(scd, tVoltageLevel1 -> "5".equals(tVoltageLevel1.getName()))) | ||
.isEmpty(); | ||
} | ||
} |