Skip to content

Commit

Permalink
inject LnService
Browse files Browse the repository at this point in the history
Signed-off-by: massifben <105049157+massifben@users.noreply.github.com>
  • Loading branch information
massifben committed Jan 22, 2025
1 parent bdeb7b1 commit 56f286f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SclAutomationServiceIntegrationTest {
private SclAutomationService sclAutomationService ;
private static final SclEditor sclEditor = new SclService() ;
private static final SubstationEditor substationEditor = new SubstationService(new VoltageLevelService()) ;
private static final ControlBlockEditor controlBlockEditor = new ControlBlockEditorService(new ControlService(), new LdeviceService()) ;
private static final ControlBlockEditor controlBlockEditor = new ControlBlockEditorService(new ControlService(), new LdeviceService(new LnService()));

private HeaderDTO headerDTO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ExtRefEditorService implements ExtRefEditor {
* @param channel TChannel represent parameters
* @return the IED sources matching the LDEPF parameters
*/
private static List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBay compasBay, TChannel channel) {
private List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBay compasBay, TChannel channel) {
return sclRootAdapter.streamIEDAdapters()
.filter(iedAdapter -> (channel.getBayScope().equals(TCBScopeType.BAY_EXTERNAL)
&& iedAdapter.getPrivateCompasBay().stream().noneMatch(bay -> bay.getUUID().equals(compasBay.getUUID())))
Expand Down Expand Up @@ -143,8 +143,7 @@ private static boolean doesIcdHeaderMatchLDEPFChannel(IEDAdapter iedAdapter, TCh
* @param channel TChannel
* @return LDeviceAdapter object that matches the EPF channel
*/
private static Optional<LDeviceAdapter> getActiveSourceLDeviceByLDEPFChannel(IEDAdapter iedAdapter, TChannel channel) {
LdeviceService ldeviceService = new LdeviceService();
private Optional<LDeviceAdapter> getActiveSourceLDeviceByLDEPFChannel(IEDAdapter iedAdapter, TChannel channel) {
return ldeviceService.findLdevice(iedAdapter.getCurrentElem(), tlDevice -> tlDevice.getInst().equals(channel.getLDInst()))
.filter(tlDevice -> ldeviceService.getLdeviceStatus(tlDevice).map(ActiveStatus.ON::equals).orElse(false))
.map(tlDevice -> new LDeviceAdapter(iedAdapter, tlDevice));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.lfenergy.compas.sct.commons;

import lombok.RequiredArgsConstructor;
import org.lfenergy.compas.scl2007b4.model.TAccessPoint;
import org.lfenergy.compas.scl2007b4.model.TIED;
import org.lfenergy.compas.scl2007b4.model.TLDevice;
Expand All @@ -15,8 +16,11 @@
import java.util.function.Predicate;
import java.util.stream.Stream;

@RequiredArgsConstructor
public class LdeviceService {

private final LnService lnService;

public Stream<TLDevice> getLdevices(TIED tied) {
if (!tied.isSetAccessPoint()) {
return Stream.empty();
Expand All @@ -43,7 +47,6 @@ public Optional<TLDevice> findLdevice(TIED tied, Predicate<TLDevice> ldevicePred
}

public Optional<ActiveStatus> getLdeviceStatus(TLDevice tlDevice) {
LnService lnService = new LnService();
return lnService.getDaiModStValValue(tlDevice.getLN0());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ControlBlockEditorServiceTest {

@BeforeEach
void init() {
controlBlockEditorService = new ControlBlockEditorService(new ControlService(), new LdeviceService());
controlBlockEditorService = new ControlBlockEditorService(new ControlService(), new LdeviceService(new LnService()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ExtRefEditorServiceTest {

@BeforeEach
void init() {
extRefEditorService = new ExtRefEditorService(new IedService(), new LdeviceService(), new LnService(), new DataTypeTemplatesService());
extRefEditorService = new ExtRefEditorService(new IedService(), new LdeviceService(new LnService()), new LnService(), new DataTypeTemplatesService());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.lfenergy.compas.sct.commons;

import org.assertj.core.groups.Tuple;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TIED;
Expand All @@ -19,16 +20,20 @@

class LdeviceServiceTest {

private LdeviceService ldeviceService;

@BeforeEach
void setUp() {
ldeviceService = new LdeviceService(new LnService());
}

@Test
void getLdeviceStatus_should_return_status() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLDevice tlDevice = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0);
LdeviceService ldeviceService = new LdeviceService();

TLDevice tlDevice = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().getFirst();
//When
Optional<ActiveStatus> ldeviceStatus = ldeviceService.getLdeviceStatus(tlDevice);

//Then
assertThat(ldeviceStatus).contains(ActiveStatus.ON);
}
Expand All @@ -37,12 +42,9 @@ void getLdeviceStatus_should_return_status() {
void getLdevices_should_return_ldevices() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().get(0);
LdeviceService ldeviceService = new LdeviceService();

TIED tied = std.getIED().getFirst();
//When
List<TLDevice> tlDevices = ldeviceService.getLdevices(tied).toList();

//Then
assertThat(tlDevices)
.hasSize(2)
Expand All @@ -55,12 +57,9 @@ void getLdevices_should_return_ldevices() {
void getFilteredLdevices_should_return_ldevices() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().get(0);
LdeviceService ldeviceService = new LdeviceService();

TIED tied = std.getIED().getFirst();
//When
List<TLDevice> tlDevices = ldeviceService.getFilteredLdevices(tied, tlDevice -> "LDTM".equals(tlDevice.getInst())).toList();

//Then
assertThat(tlDevices)
.hasSize(1)
Expand All @@ -72,12 +71,9 @@ void getFilteredLdevices_should_return_ldevices() {
void findLdevice_should_return_ldevice() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().get(0);
LdeviceService ldeviceService = new LdeviceService();

TIED tied = std.getIED().getFirst();
//When
TLDevice ldevice = ldeviceService.findLdevice(tied, tlDevice -> "LDTM".equals(tlDevice.getInst())).orElseThrow();

//Then
assertThat(ldevice)
.extracting(TLDevice::getInst, TLDevice::getLdName)
Expand All @@ -88,17 +84,14 @@ void findLdevice_should_return_ldevice() {
void getActiveLdevices_should_return_ldevices() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().get(0);
LdeviceService ldeviceService = new LdeviceService();

TIED tied = std.getIED().getFirst();
//When
List<TLDevice> tlDevices = ldeviceService.getActiveLdevices(tied).toList();

//Then
assertThat(tlDevices)
.hasSize(1)
.extracting(TLDevice::getInst, TLDevice::getLdName)
.containsExactly(Tuple.tuple("LDSUIED", "VirtualSAMULDSUIED"));
}

}
}

0 comments on commit 56f286f

Please sign in to comment.