Skip to content

Commit

Permalink
feat(#405): Remove LDname limitation
Browse files Browse the repository at this point in the history
Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com>
  • Loading branch information
gleizesDor committed Jul 11, 2024
1 parent 7161d87 commit 64214cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class LDeviceAdapter extends SclElementAdapter<IEDAdapter, TLDevice> {
private static final long INTG_PD_VALUE_FOR_FC_MX = 2000L;

private static final String DA_SETSRCREF = "setSrcRef";
private static final int MAXIMUM_LENGHT_LD_NAME_BY_XSD = 64;

/**
* Constructor
Expand Down Expand Up @@ -164,15 +165,10 @@ public String getXPath() {

/**
* Updates LDevice name by combining IED name and LDevice ldInst value
*
* @throws ScdException throws when renaming LDevice and new name has more than 33 caracteres
*/
public void updateLDName() throws ScdException {
public void updateLDName() {
String newLdName = parentAdapter.getCurrentElem().getName() + currentElem.getInst();
if (newLdName.length() > 33) {
throw new ScdException(newLdName + "(IED.name + LDevice.inst) has more than 33 characters");
}
// renaming ldName
// renaming ldName; Carefull because the maximum ldevice name length is 64 based on xsd
currentElem.setLdName(newLdName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,36 @@

class LDeviceAdapterTest {

private IEDAdapter iAdapter;
private IEDAdapter iedAdapter;

@BeforeEach
public void init() {
SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml");
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME"));
iedAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME"));
}

@Test
void updateLDName_when_ldName_pass_33_characters_should_throw_exception() {
void updateLDName_when_ldName_should_update() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get());
lDeviceAdapter.updateLDName();
assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED_NAMELD_INS1");
assertThat(lDeviceAdapter.getInst()).isEqualTo("LD_INS1");
String iedName = new Random().ints(97, 122)
.limit(27)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
iAdapter.setIEDName(iedName);
// When Then
assertThatThrownBy(lDeviceAdapter::updateLDName)
.isInstanceOf(ScdException.class)
.hasMessageContaining("has more than 33 characters");
}
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().getFirst();
TLDevice tlDevice = tied.getAccessPoint().getFirst().getServer().getLDevice().getFirst();
LDeviceAdapter lDeviceAdapter = new LDeviceAdapter(new IEDAdapter(new SclRootAdapter(std), tied), tlDevice);

@Test
void updateLDName_when_ldName_less_than_33_characters_should_not_throw_exception() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get());
//When
lDeviceAdapter.updateLDName();
assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED_NAMELD_INS1");
assertThat(lDeviceAdapter.getInst()).isEqualTo("LD_INS1");
String iedName = new Random().ints(97, 122)
.limit(26)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
iAdapter.setIEDName(iedName);
// When Then
assertThatCode(lDeviceAdapter::updateLDName).doesNotThrowAnyException();
assertThat(lDeviceAdapter.getLdName()).isEqualTo(iedName+"LD_INS1");

//When
assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED4d4fe1a8cda64cf88a5ee4176a1a0eefLDSUIED");
assertThat(lDeviceAdapter.getInst()).isEqualTo("LDSUIED");
}

@Test
@Tag("issue-321")
void testGetLNAdapters() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
assertThat(lDeviceAdapter.getLNAdapters()).hasSize(1);
// When Then
assertDoesNotThrow(() -> lDeviceAdapter.getLNAdapter("ANCR","1",null));
Expand All @@ -99,7 +80,7 @@ void testGetLNAdapters() {
@Test
void findLnAdapter_shouldReturnAdapter(){
// Given
LDeviceAdapter lDeviceAdapter = iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get();
LDeviceAdapter lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get();
// When
Optional<LNAdapter> lnAdapter = lDeviceAdapter.findLnAdapter("ANCR", "1", null);
// Then
Expand All @@ -110,7 +91,7 @@ void findLnAdapter_shouldReturnAdapter(){
@Test
void getExtRefBinders_whenExist_shouldReturnExtRefBindingInfo() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo();
signalInfo.setPDO("Do.sdo1");
signalInfo.setPDA("da.bda1.bda2.bda3");
Expand All @@ -122,7 +103,7 @@ void getExtRefBinders_whenExist_shouldReturnExtRefBindingInfo() {
@Test
void getExtRefBinders_when_PLN_NotMatch_shouldReturnEmptyList() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
ExtRefSignalInfo signalInfo = new ExtRefSignalInfo();
signalInfo.setPLN("CSWI");
//When Then
Expand All @@ -133,7 +114,7 @@ void getExtRefBinders_when_PLN_NotMatch_shouldReturnEmptyList() {
@Test
void getExtRefBinders_when_PLN_NotSet_shouldReturnEmptyList() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
ExtRefSignalInfo signalInfo = new ExtRefSignalInfo();
//When Then
assertDoesNotThrow(()-> lDeviceAdapter.getExtRefBinders(signalInfo));
Expand All @@ -144,7 +125,7 @@ void getExtRefBinders_when_PLN_NotSet_shouldReturnEmptyList() {
@Tag("issue-321")
void getExtRefInfo_should_return_expected_list_of_ExtRefInfo() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
// When
List<ExtRefInfo> extRefInfoList = assertDoesNotThrow(lDeviceAdapter::getExtRefInfo);
// Then
Expand All @@ -155,7 +136,7 @@ void getExtRefInfo_should_return_expected_list_of_ExtRefInfo() {
@Tag("issue-321")
void TestGetDAI() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS1"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS1"));
// When
var dataAttributeRefs = lDeviceAdapter.getDAI(new DataAttributeRef(),true);
// Then
Expand All @@ -170,7 +151,7 @@ void TestGetDAI() {
assertThat(dataAttributeRefs).hasSize(4);

// Given
lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.findLDeviceAdapterByLdInst("LD_INS2").get());
filter.setLnClass("ANCR");
filter.setLnInst("1");
// When
Expand All @@ -183,7 +164,7 @@ void TestGetDAI() {
@Tag("issue-321")
void addPrivate_with_type_and_source_should_create_Private() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
TPrivate tPrivate = new TPrivate();
tPrivate.setType("Private Type");
tPrivate.setSource("Private Source");
Expand Down Expand Up @@ -230,7 +211,7 @@ void getLDeviceStatus_should_succeed() {
@Test
void getLNAdaptersIncludingLN0_should_return_expected_list_of_AbstractLNAdapter() {
//Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iedAdapter.getLDeviceAdapterByLdInst("LD_INS2"));
//When
List<AbstractLNAdapter<?>> lnAdapters = lDeviceAdapter.getLNAdaptersIncludingLN0();
//Then
Expand Down

0 comments on commit 64214cf

Please sign in to comment.