From 3d3b05c40717551c6096bc6c3591a08f80dccfc1 Mon Sep 17 00:00:00 2001 From: Samir Romdhani Date: Fri, 7 Jun 2024 16:51:35 +0200 Subject: [PATCH 1/2] added isUpdatable in DoLinkedToDa Signed-off-by: massifben <105049157+massifben@users.noreply.github.com> --- .../sct/commons/DataTypeTemplatesService.java | 9 ++- .../compas/sct/commons/LnService.java | 17 ++--- .../compas/sct/commons/api/LnEditor.java | 5 +- .../sct/commons/domain/DataAttribute.java | 14 ++++ .../sct/commons/domain/DoLinkedToDa.java | 32 +++++++- .../commons/domain/DoLinkedToDaFilter.java | 48 ++++++++---- .../commons/DataTypeTemplatesServiceTest.java | 19 ++--- .../compas/sct/commons/LnServiceTest.java | 25 ++----- .../sct/commons/domain/DataAttributeTest.java | 75 +++++++++++++++++++ .../domain/DoLinkedToDaFilterTest.java | 41 ++++++++++ .../sct/commons/domain/DoLinkedToDaTest.java | 53 +++++++++++++ 11 files changed, 271 insertions(+), 67 deletions(-) create mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DataAttributeTest.java create mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilterTest.java diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java index 4a7673f1b..b72c0b4b2 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java @@ -75,8 +75,8 @@ public Stream getAllDoLinkedToDa(TDataTypeTemplates dtt) { public Stream getFilteredDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter) { return lnodeTypeService.findLnodeType(dtt, tlNodeType -> tlNodeType.getId().equals(lNodeTypeId)) .stream() - .flatMap(tlNodeType -> doService.getFilteredDos(tlNodeType, tdo -> StringUtils.isBlank(doLinkedToDaFilter.getDoName()) - || (StringUtils.isNotBlank(doLinkedToDaFilter.getDoName()) && doLinkedToDaFilter.getDoName().equals(tdo.getName()))) + .flatMap(tlNodeType -> doService.getFilteredDos(tlNodeType, tdo -> StringUtils.isBlank(doLinkedToDaFilter.doName()) + || doLinkedToDaFilter.doName().equals(tdo.getName())) .flatMap(tdo -> { DoLinkedToDa doLinkedToDa = new DoLinkedToDa(); DataObject dataObject = new DataObject(); @@ -88,8 +88,9 @@ public Stream getFilteredDoLinkedToDa(TDataTypeTemplates dtt, Stri .flatMap(tdoType -> { doLinkedToDa.getDataObject().setCdc(tdoType.getCdc()); return doTypeService.getAllSDOLinkedToDa(dtt, tdoType, doLinkedToDa).stream() - .filter(doLinkedToDa1 -> StringUtils.isBlank(doLinkedToDaFilter.getDoName()) || doLinkedToDa1.getDoRef().startsWith(doLinkedToDaFilter.getDoRef()) - && StringUtils.isBlank(doLinkedToDaFilter.getDaName()) || doLinkedToDa1.getDaRef().startsWith(doLinkedToDaFilter.getDaRef())); + .filter(doLinkedToDa1 -> StringUtils.isBlank(doLinkedToDaFilter.doName()) + || (doLinkedToDa1.getDoRef().startsWith(doLinkedToDaFilter.getDoRef()) && StringUtils.isBlank(doLinkedToDaFilter.daName())) + || doLinkedToDa1.getDaRef().startsWith(doLinkedToDaFilter.getDaRef())); }); })); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java index 3c7d69440..27b2d7eee 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java @@ -7,10 +7,7 @@ import lombok.extern.slf4j.Slf4j; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.api.LnEditor; -import org.lfenergy.compas.sct.commons.domain.DaVal; -import org.lfenergy.compas.sct.commons.domain.DataAttribute; -import org.lfenergy.compas.sct.commons.domain.DataObject; -import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa; +import org.lfenergy.compas.sct.commons.domain.*; import org.lfenergy.compas.sct.commons.util.ActiveStatus; import java.util.Collection; @@ -92,12 +89,12 @@ public Stream getActiveLns(TLDevice tlDevice) { } @Override - public Optional getDOAndDAInstances(TAnyLN tAnyLN, DataObject dataObject, DataAttribute dataAttribute) { - List structNamesList = new ArrayList<>(dataObject.getSdoNames()); - structNamesList.add(dataAttribute.getDaName()); - structNamesList.addAll(dataAttribute.getBdaNames()); + public Optional getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLinkedToDaFilter) { + List structNamesList = new ArrayList<>(doLinkedToDaFilter.sdoNames()); + structNamesList.add(doLinkedToDaFilter.daName()); + structNamesList.addAll(doLinkedToDaFilter.bdaNames()); - return tAnyLN.getDOI().stream().filter(doi -> doi.getName().equals(dataObject.getDoName())) + return tAnyLN.getDOI().stream().filter(doi -> doi.getName().equals(doLinkedToDaFilter.doName())) .findFirst() .flatMap(doi -> { if(structNamesList.size() > 1) { @@ -151,7 +148,7 @@ public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT } public void completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLinkedToDa doLinkedToDa) { - getDOAndDAInstances(anyLN, doLinkedToDa.getDataObject(), doLinkedToDa.getDataAttribute()) + getDOAndDAInstances(anyLN, doLinkedToDa.toFilter()) .ifPresent(tdai -> { if(tdai.isSetVal()) { doLinkedToDa.getDataAttribute().addDaVal(tdai.getVal()); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java index 9af2f9e5a..889433c17 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java @@ -6,15 +6,14 @@ import org.lfenergy.compas.scl2007b4.model.TAnyLN; import org.lfenergy.compas.scl2007b4.model.TDAI; -import org.lfenergy.compas.sct.commons.domain.DataAttribute; -import org.lfenergy.compas.sct.commons.domain.DataObject; import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa; +import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter; import java.util.Optional; public interface LnEditor { - Optional getDOAndDAInstances(TAnyLN tAnyLN, DataObject dataObject, DataAttribute dataAttribute); + Optional getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLinkedToDaFilter); void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedToDa); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataAttribute.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataAttribute.java index 76fbc3b72..0123295b0 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataAttribute.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataAttribute.java @@ -46,5 +46,19 @@ public String toString(){ return daName + (getBdaNames().isEmpty() ? StringUtils.EMPTY : "." + String.join(".", getBdaNames())); } + /** + * Check if DA Object is updatable + * @return boolean value of DA state + */ + public boolean isUpdatable(){ + return isValImport() && + (fc == TFCEnum.CF || + fc == TFCEnum.DC || + fc == TFCEnum.SG || + fc == TFCEnum.SP || + fc == TFCEnum.ST || + fc == TFCEnum.SE + ); + } } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java index 7925bbe62..7a1d86a48 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java @@ -5,7 +5,11 @@ package org.lfenergy.compas.sct.commons.domain; -import lombok.*; +import lombok.Getter; +import lombok.Setter; + +import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME; +import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME; @Getter @@ -30,5 +34,29 @@ public String getDaRef() { return dataAttribute != null ? dataAttribute.toString() : ""; } -} + /** + * Checks if DA/DO is updatable + * + * @return true if updatable, false otherwise + */ + public boolean isUpdatable() { + return isDOModDAstVal() || dataAttribute.isUpdatable(); + } + /** + * Checks if DO is Mod and DA is stVal + * + * @return true if DO is "Mod" and DA is "stVal", false otherwise + */ + private boolean isDOModDAstVal() { + return dataObject.getDoName().equals(MOD_DO_NAME) && dataAttribute.getDaName().equals(STVAL_DA_NAME); + } + + /** + * Create DoLinkedToDaFilter from this + * @return new DoLinkedToDaFilter instance with same data Object and data Attribute Ref + */ + public DoLinkedToDaFilter toFilter() { + return DoLinkedToDaFilter.from(getDoRef(), getDaRef()); + } +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilter.java index 49905de68..dbbe8fc1a 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilter.java @@ -5,28 +5,46 @@ package org.lfenergy.compas.sct.commons.domain; -import lombok.Getter; -import lombok.Setter; import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; -@Getter -@Setter -public class DoLinkedToDaFilter { +public record DoLinkedToDaFilter(String doName, List sdoNames, String daName, List bdaNames) { - private String doName; - private String daName; - private List sdoNames = new ArrayList<>(); - private List bdaNames = new ArrayList<>(); - - public String getDoRef() { - return doName + (getSdoNames().isEmpty() ? StringUtils.EMPTY : "." + String.join(".", getSdoNames())); + public DoLinkedToDaFilter(String doName, List sdoNames, String daName, List bdaNames) { + this.doName = StringUtils.isBlank(doName) ? null : doName; + this.sdoNames = sdoNames == null ? Collections.emptyList() : List.copyOf(sdoNames); + this.daName = StringUtils.isBlank(daName) ? null : daName; + this.bdaNames = bdaNames == null ? Collections.emptyList() : List.copyOf(bdaNames); + } + public DoLinkedToDaFilter(){ + this(null,null,null,null); } - public String getDaRef() { - return daName + (getBdaNames().isEmpty() ? StringUtils.EMPTY : "." + String.join(".", getBdaNames())); + public static DoLinkedToDaFilter from(String doNames, String daNames) { + String doName = null; + List sdoNames = null; + String daName = null; + List bdaNames = null; + if (StringUtils.isNotBlank(doNames)){ + doName = doNames.split("\\.")[0]; + sdoNames = Arrays.stream(doNames.split("\\.")).skip(1).toList(); + } + if (StringUtils.isNotBlank(daNames)){ + daName = daNames.split("\\.")[0]; + bdaNames = Arrays.stream(daNames.split("\\.")).skip(1).toList(); + } + return new DoLinkedToDaFilter(doName, sdoNames, daName, bdaNames); } +public String getDoRef() { + return doName + (sdoNames().isEmpty() ? StringUtils.EMPTY : "." + String.join(".", sdoNames())); +} + +public String getDaRef() { + return daName + (bdaNames().isEmpty() ? StringUtils.EMPTY : "." + String.join(".", bdaNames())); +} + } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java index 0e197a1ed..f9d5898d1 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java @@ -185,8 +185,7 @@ void getFilteredDOAndDA_when_given_DoName_should_return_expected_dataReference() TDataTypeTemplates dtt = initDttFromFile("/dtt-test-schema-conf/scd_dtt_do_sdo_da_bda_test.xml"); String lNodeTypeId = "LNodeType0"; - DoLinkedToDaFilter doLinkedToDaFilter = new DoLinkedToDaFilter(); - doLinkedToDaFilter.setDoName("SecondDoName"); + DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("SecondDoName", ""); //When DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); @@ -208,9 +207,7 @@ void getFilteredDOAndDA_when_given_DO_with_one_structName_should_return_expected TDataTypeTemplates dtt = initDttFromFile("/dtt-test-schema-conf/scd_dtt_do_sdo_da_bda_test.xml"); String lNodeTypeId = "LNodeType0"; - DoLinkedToDaFilter doLinkedToDaFilter = new DoLinkedToDaFilter(); - doLinkedToDaFilter.setDoName("FirstDoName"); - doLinkedToDaFilter.setSdoNames(List.of("sdoName1")); + DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("FirstDoName.sdoName1", ""); //When DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); List result = dataTypeTemplatesService.getFilteredDoLinkedToDa(dtt, lNodeTypeId, doLinkedToDaFilter).toList(); @@ -232,9 +229,7 @@ void getFilteredDOAndDA_when_given_DO_with_many_structName_should_return_expecte TDataTypeTemplates dtt = initDttFromFile("/dtt-test-schema-conf/scd_dtt_do_sdo_da_bda_test.xml"); String lNodeTypeId = "LNodeType0"; - DoLinkedToDaFilter doLinkedToDaFilter = new DoLinkedToDaFilter(); - doLinkedToDaFilter.setDoName("FirstDoName"); - doLinkedToDaFilter.setSdoNames(List.of("sdoName1", "sdoName21")); + DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("FirstDoName.sdoName1.sdoName21", ""); //When DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); List result = dataTypeTemplatesService.getFilteredDoLinkedToDa(dtt, lNodeTypeId, doLinkedToDaFilter).toList(); @@ -255,11 +250,7 @@ void getFilteredDOAndDA_when_given_DO_and_DA_with_structNames_should_return_expe TDataTypeTemplates dtt = initDttFromFile("/dtt-test-schema-conf/scd_dtt_do_sdo_da_bda_test.xml"); String lNodeTypeId = "LNodeType0"; - DoLinkedToDaFilter doLinkedToDaFilter = new DoLinkedToDaFilter(); - doLinkedToDaFilter.setDoName("FirstDoName"); - doLinkedToDaFilter.setSdoNames(List.of("sdoName2")); - doLinkedToDaFilter.setDaName("structDaName1"); - doLinkedToDaFilter.setBdaNames(List.of("structBdaName1", "enumBdaName22")); + DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("FirstDoName.sdoName2", "structDaName1.structBdaName1.enumBdaName22"); //When DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); @@ -538,4 +529,4 @@ void getAllDOAndDA_should_return_all_dataReference() { ); } -} \ No newline at end of file +} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java index 5049c1bd4..b0eb87112 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java @@ -10,10 +10,7 @@ import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.domain.DaVal; -import org.lfenergy.compas.sct.commons.domain.DataAttribute; -import org.lfenergy.compas.sct.commons.domain.DataObject; -import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa; +import org.lfenergy.compas.sct.commons.domain.*; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.ActiveStatus; @@ -171,15 +168,10 @@ void getDOAndDAInstance_should_return_true_when_DO_and_DA_instances_exists() { new LinkedList<>(List.of("antRef","bda1", "bda2", "bda3")), "new value",null ); - DataObject dataObject = new DataObject(); - dataObject.setDoName("Do"); - dataObject.setSdoNames(List.of("sdo1","d")); - DataAttribute dataAttribute = new DataAttribute(); - dataAttribute.setDaName("antRef"); - dataAttribute.setBdaNames(List.of("bda1","bda2","bda3")); + DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("Do.sdo1.d", "antRef.bda1.bda2.bda3"); //When LnService lnService = new LnService(); - Optional optionalTDAI = lnService.getDOAndDAInstances(tAnyLN, dataObject, dataAttribute); + Optional optionalTDAI = lnService.getDOAndDAInstances(tAnyLN, doLinkedToDaFilter); //Then assertThat(optionalTDAI).isPresent(); assertThat(optionalTDAI.get().getName()).isEqualTo("bda3"); @@ -194,15 +186,10 @@ void getDOAndDAInstance_should_return_false_when_DO_and_DA_instances_not_exists( new LinkedList<>(List.of("antRef","bda1", "bda2", "bda3")), "new value",null ); - DataObject dataObject = new DataObject(); - dataObject.setDoName("Do"); - dataObject.setSdoNames(List.of("sdo1","d")); - DataAttribute dataAttribute = new DataAttribute(); - dataAttribute.setDaName("antRef"); - dataAttribute.setBdaNames(List.of("unknown","bda2","bda3")); + DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("Do.sdo1.d", "antRef.unknown.bda2.bda3"); //When LnService lnService = new LnService(); - Optional optionalTDAI = lnService.getDOAndDAInstances(tAnyLN, dataObject, dataAttribute); + Optional optionalTDAI = lnService.getDOAndDAInstances(tAnyLN, doLinkedToDaFilter); //Then assertThat(optionalTDAI).isEmpty(); } @@ -594,4 +581,4 @@ private TDAI initDOAndDAInstances(TAnyLN tAnyLN, } -} \ No newline at end of file +} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DataAttributeTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DataAttributeTest.java new file mode 100644 index 000000000..41f3f23ab --- /dev/null +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DataAttributeTest.java @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2024 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.domain; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.lfenergy.compas.scl2007b4.model.TFCEnum; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class DataAttributeTest { + + @Test + void isUpdatable_should_return_true_whenValImportIsTrue() { + // Given + DataAttribute dataAttribute = new DataAttribute(); + dataAttribute.setDaName("daName"); + dataAttribute.setBdaNames(List.of("bdaName1")); + dataAttribute.setValImport(true); + dataAttribute.setFc(TFCEnum.SE); + // When Then + assertThat(dataAttribute.isUpdatable()).isTrue(); + } + + @Test + void isUpdatable_should_return_false_whenValImportIsFalse() { + // Given + DataAttribute dataAttribute = new DataAttribute(); + dataAttribute.setDaName("daName"); + dataAttribute.setBdaNames(List.of("bdaName1")); + dataAttribute.setValImport(false); + dataAttribute.setFc(TFCEnum.SE); + // When Then + assertThat(dataAttribute.isUpdatable()).isFalse(); + } + + + @Test + void isUpdatable_should_return_true_whenFcIsNotAppropriate() { + // Given + DataAttribute dataAttribute = new DataAttribute(); + dataAttribute.setDaName("daName"); + dataAttribute.setBdaNames(List.of("bdaName1")); + dataAttribute.setValImport(true); + dataAttribute.setFc(TFCEnum.MX); + // When Then + assertThat(dataAttribute.isUpdatable()).isFalse(); + } + + + @ParameterizedTest + @CsvSource(value = {"MX:true:false", "CF:true:true", "CF:false:false", + "DC:false:false", "DC:false:false", + "SG:false:false", "SG:false:false", + "SP:false:false", "SP:false:false", + "ST:false:false", "ST:false:false", + "SE:false:false", "SE:false:false"}, delimiter = ':') + void isUpdatable_should_return_ExpectedValue(String fcVal, boolean valImport, boolean expected) { + // Given + DataAttribute dataAttribute = new DataAttribute(); + dataAttribute.setDaName("daName"); + dataAttribute.setBdaNames(List.of("bdaName1")); + dataAttribute.setValImport(valImport); + dataAttribute.setFc(TFCEnum.valueOf(fcVal)); + // When Then + assertThat(dataAttribute.isUpdatable()).isEqualTo(expected); + + } + +} \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilterTest.java new file mode 100644 index 000000000..8a4190331 --- /dev/null +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaFilterTest.java @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2024 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.domain; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +class DoLinkedToDaFilterTest { + + public static Stream provideDoLinkedToDaFilter() { + return Stream.of( + Arguments.of(null, null, new DoLinkedToDaFilter(null, null, null, null)), + Arguments.of("", "", new DoLinkedToDaFilter(null, null, null, null)), + Arguments.of("Do", "", new DoLinkedToDaFilter("Do", null, null, null)), + Arguments.of("", "da", new DoLinkedToDaFilter(null, null, "da", null)), + Arguments.of("Do", "da", new DoLinkedToDaFilter("Do", null, "da", null)), + Arguments.of("Do.sdo", "da", new DoLinkedToDaFilter("Do", List.of("sdo"), "da", null)), + Arguments.of("Do", "da.bda", new DoLinkedToDaFilter("Do", null, "da", List.of("bda"))), + Arguments.of("Do.sdo", "da.bda", new DoLinkedToDaFilter("Do", List.of("sdo"), "da", List.of("bda"))), + Arguments.of("Do.sdo1.sdo2.sdo3.sdo4", "da.bda1.bda2.bda3.bda4", new DoLinkedToDaFilter("Do", List.of("sdo1", "sdo2", "sdo3", "sdo4"), "da", List.of("bda1", "bda2", "bda3", "bda4"))) + ); + } + + @ParameterizedTest + @MethodSource("provideDoLinkedToDaFilter") + void from_should_parse_DO_and_DA(String doNames, String daNames, DoLinkedToDaFilter expected) { + // Given : parameters + // When + DoLinkedToDaFilter result = DoLinkedToDaFilter.from(doNames, daNames); + // Then + assertThat(result).isEqualTo(expected); + } +} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java index b694c17e9..a3a6aaaaf 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java @@ -67,4 +67,57 @@ void test_getDaRef() { assertThat(doLinkedToDa.getDaRef()).isEqualTo("daName.bdaName1"); } + @Test + void isUpdatable_should_return_true_whenIsDOModDAstVal() { + // Given + DataObject dataObject = new DataObject(); + dataObject.setDoName("Mod"); + DataAttribute dataAttribute = new DataAttribute(); + dataAttribute.setDaName("stVal"); + + DoLinkedToDa doLinkedToDa = new DoLinkedToDa(); + doLinkedToDa.setDataObject(dataObject); + doLinkedToDa.setDataAttribute(dataAttribute); + // When Then + assertThat(doLinkedToDa.isUpdatable()).isTrue(); + } + + @Test + void isUpdatable_should_return_true_whenValImportIsTrue() { + // Given + DataObject dataObject = new DataObject(); + dataObject.setDoName("doName"); + dataObject.setSdoNames(List.of("sdoName1")); + DataAttribute dataAttribute = new DataAttribute(); + dataAttribute.setDaName("daName"); + dataAttribute.setBdaNames(List.of("bdaName1")); + dataAttribute.setValImport(true); + dataAttribute.setFc(TFCEnum.SE); + + DoLinkedToDa doLinkedToDa = new DoLinkedToDa(); + doLinkedToDa.setDataObject(dataObject); + doLinkedToDa.setDataAttribute(dataAttribute); + // When Then + assertThat(doLinkedToDa.isUpdatable()).isTrue(); + } + + @Test + void isUpdatable_should_return_false_whenValImportIsFalse() { + // Given + DataObject dataObject = new DataObject(); + dataObject.setDoName("doName"); + dataObject.setSdoNames(List.of("sdoName1")); + DataAttribute dataAttribute = new DataAttribute(); + dataAttribute.setDaName("daName"); + dataAttribute.setBdaNames(List.of("bdaName1")); + dataAttribute.setValImport(false); + dataAttribute.setFc(TFCEnum.SE); + + DoLinkedToDa doLinkedToDa = new DoLinkedToDa(); + doLinkedToDa.setDataObject(dataObject); + doLinkedToDa.setDataAttribute(dataAttribute); + // When Then + assertThat(doLinkedToDa.isUpdatable()).isFalse(); + } + } \ No newline at end of file From c2a362461087bc8c27c2df959df70912069e1f81 Mon Sep 17 00:00:00 2001 From: gleizesDor <115622893+gleizesDor@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:04:10 +0200 Subject: [PATCH 2/2] feat(#401): Update compas-core to 0.21.0 Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 803f681e7..89e49f079 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 0.8.11 - 0.20.0 + 0.21.0 0.0.4