From 64214cfc3333ebbd25e7e616250b7fe141447f8b Mon Sep 17 00:00:00 2001 From: gleizesDor <115622893+gleizesDor@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:44:31 +0200 Subject: [PATCH] feat(#405): Remove LDname limitation Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com> --- .../commons/scl/ldevice/LDeviceAdapter.java | 10 +-- .../scl/ldevice/LDeviceAdapterTest.java | 63 +++++++------------ 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java index ff5cea878..005b5e521 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java @@ -66,6 +66,7 @@ public class LDeviceAdapter extends SclElementAdapter { 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 @@ -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); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java index c39113499..6e12e9abc 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java @@ -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)); @@ -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 = lDeviceAdapter.findLnAdapter("ANCR", "1", null); // Then @@ -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"); @@ -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 @@ -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)); @@ -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 extRefInfoList = assertDoesNotThrow(lDeviceAdapter::getExtRefInfo); // Then @@ -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 @@ -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 @@ -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"); @@ -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> lnAdapters = lDeviceAdapter.getLNAdaptersIncludingLN0(); //Then