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 Jun 27, 2024
1 parent 5e68693 commit 61a0d23
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 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 @@ -169,8 +170,8 @@ public String getXPath() {
*/
public void updateLDName() throws ScdException {
String newLdName = parentAdapter.getCurrentElem().getName() + currentElem.getInst();
if (newLdName.length() > 33) {
throw new ScdException(newLdName + "(IED.name + LDevice.inst) has more than 33 characters");
if (newLdName.length() > MAXIMUM_LENGHT_LD_NAME_BY_XSD) {
throw new ScdException("LDName (IED.name + LDevice.inst) has more than 64 characters ("+newLdName+") wich is not allowed by xsd");
}
// renaming ldName
currentElem.setLdName(newLdName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,52 @@

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_less_than_64_characters_should_not_throw_exception() {
// Given
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get());
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);

//When
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");

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

@Test
void updateLDName_when_ldName_less_than_33_characters_should_not_throw_exception() {
void updateLDName_when_ldName_pass_64_characters_should_throw_exception() {
// 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(26)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
iAdapter.setIEDName(iedName);
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().getFirst();
TLDevice tlDevice = tied.getAccessPoint().getFirst().getServer().getLDevice().getFirst();
tlDevice.setInst("LDSUIED***********************");
LDeviceAdapter lDeviceAdapter = new LDeviceAdapter(new IEDAdapter(new SclRootAdapter(std), tied), tlDevice);

// When Then
assertThatCode(lDeviceAdapter::updateLDName).doesNotThrowAnyException();
assertThat(lDeviceAdapter.getLdName()).isEqualTo(iedName+"LD_INS1");
assertThatThrownBy(lDeviceAdapter::updateLDName)
.isInstanceOf(ScdException.class)
.hasMessage("LDName (IED.name + LDevice.inst) has more than 64 characters (IED4d4fe1a8cda64cf88a5ee4176a1a0eefLDSUIED***********************)" +
" wich is not allowed by xsd");
}

@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 +96,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 +107,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 +119,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 +130,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 +141,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 +152,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 +167,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 +180,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 +227,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 61a0d23

Please sign in to comment.