From 66c01cae64bf2dcc7d69670f32af4311dfbf701a Mon Sep 17 00:00:00 2001 From: Samir Romdhani Date: Wed, 4 Dec 2024 16:47:42 +0100 Subject: [PATCH 1/2] feat / deconstructing compas-flow Signed-off-by: Samir Romdhani --- .../sct/commons/ExtRefEditorService.java | 138 +-------- .../compas/sct/commons/api/ExtRefEditor.java | 22 -- .../compas/sct/commons/scl/ExtRefService.java | 26 +- .../sct/commons/scl/ied/InputsAdapter.java | 111 ------- .../sct/commons/ExtRefEditorServiceTest.java | 288 +----------------- .../sct/commons/scl/ExtRefServiceTest.java | 33 -- .../commons/scl/ied/InputsAdapterTest.java | 58 ++-- ...eate_dataset_and_controlblocks_success.xml | 24 +- .../scd_extref_flow_debind_success.xml | 101 ------ ...extref_flow_debind_volatagelevelname_0.xml | 76 ----- ..._flow_debind_volatagelevelname_unknown.xml | 76 ----- .../scd_extref_flow_not_debind.xml | 101 ------ ...w_not_debind_volatagelevelname_unknown.xml | 76 ----- ..._lnode_several_ied_matching_compasFlow.xml | 131 -------- ..._extref_iedname_based_on_lnode_success.xml | 99 ------ ...tref_iedname_fails_no_Compas_ICDHeader.xml | 95 ------ .../scd_set_extref_iedname_success.xml | 79 ----- ..._set_extref_iedname_with_extref_errors.xml | 14 +- ...scd_set_extref_iedname_with_ied_errors.xml | 101 ------ 19 files changed, 41 insertions(+), 1608 deletions(-) delete mode 100644 sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_success.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_0.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_unknown.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind_volatagelevelname_unknown.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_several_ied_matching_compasFlow.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_success.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_fails_no_Compas_ICDHeader.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_success.xml delete mode 100644 sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_ied_errors.xml diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java index 010873e38..e68ddd7c8 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 RTE FRANCE +// SPDX-FileCopyrightText: 2023 2024 RTE FRANCE // // SPDX-License-Identifier: Apache-2.0 @@ -20,7 +20,6 @@ import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; -import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.util.ActiveStatus; import org.lfenergy.compas.sct.commons.util.PrivateEnum; import org.lfenergy.compas.sct.commons.util.PrivateUtils; @@ -28,8 +27,6 @@ import java.math.BigInteger; import java.util.*; -import java.util.function.BinaryOperator; -import java.util.function.Function; import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.*; @@ -38,18 +35,10 @@ @RequiredArgsConstructor public class ExtRefEditorService implements ExtRefEditor { private static final String INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO = "Invalid or missing attributes in ExtRef binding info"; - private static final Map voltageCodification = Map.of( - "3", "HT", - "4", "HT", - "5", "THT", - "6", "THT", - "7", "THT" - ); private final IedService iedService; private final LdeviceService ldeviceService; private final LnEditor lnEditor; - private final ExtRefService extRefService; private final DataTypeTemplatesService dataTypeTemplatesService; /** @@ -274,31 +263,6 @@ public TExtRef updateExtRefSource(SCL scd, ExtRefInfo extRefInfo) throws ScdExce return anLNAdapter.updateExtRefSource(extRefInfo); } - @Override - public List updateAllExtRefIedNames(SCL scd) { - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - List iedErrors = validateIed(sclRootAdapter); - if (!iedErrors.isEmpty()) { - return iedErrors; - } - Map icdSystemVersionToIed = sclRootAdapter.streamIEDAdapters() - .collect(Collectors.toMap( - iedAdapter -> iedAdapter.getCompasICDHeader() - .map(TCompasICDHeader::getICDSystemVersionUUID) - .orElseThrow(), // Value presence is checked by method validateIed called above - Function.identity() - )); - - return sclRootAdapter.streamIEDAdapters() - .flatMap(IEDAdapter::streamLDeviceAdapters) - .filter(LDeviceAdapter::hasLN0) - .map(LDeviceAdapter::getLN0Adapter) - .filter(LN0Adapter::hasInputs) - .map(LN0Adapter::getInputsAdapter) - .map(inputsAdapter -> inputsAdapter.updateAllExtRefIedNames(icdSystemVersionToIed)) - .flatMap(List::stream).toList(); - } - @Override public List manageBindingForLDEPF(SCL scd, EPF epf) { List sclReportItems = new ArrayList<>(); @@ -456,116 +420,20 @@ private String computeDaiValue(AbstractLNAdapter lnAdapter, TExtRef extRef, S return extRef.getIedName() + extRef.getLdInst() + "/" + trimToEmpty(extRef.getPrefix()) + - extRef.getLnClass().get(0) + + extRef.getLnClass().getFirst() + trimToEmpty(extRef.getLnInst()) + "." + extRef.getDoName() + "." + Q_DA_NAME; } else { return extRef.getIedName() + extRef.getLdInst() + "/" + trimToEmpty(extRef.getPrefix()) + - extRef.getLnClass().get(0) + + extRef.getLnClass().getFirst() + trimToEmpty(extRef.getLnInst()) + "." + extRef.getDoName() + "." + daName; } } - @Override - public void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd) { - scd.getSubstation() - .stream() - .flatMap(tSubstation -> tSubstation.getVoltageLevel().stream()) - .map(TVoltageLevel::getName) - .filter(tVoltageLevelName -> !"0".equals(tVoltageLevelName)) - .forEach(tVoltageLevelName -> scd.getIED().stream() - .flatMap(ldeviceService::getLdevices) - .filter(TLDevice::isSetLN0) - .filter(tlDevice -> tlDevice.getLN0().isSetInputs()) - .forEach(tlDevice -> { - String flowSource = voltageCodification.get(tVoltageLevelName); - extRefService.getCompasFlows(tlDevice) - .filter(TCompasFlow::isSetFlowSourceVoltageLevel) - .filter(TCompasFlow::isSetExtRefiedName) - .forEach(tCompasFlow -> { - if (!tCompasFlow.getFlowSourceVoltageLevel().equals(flowSource)) { - //debind extRefs correspondind to compas flow - extRefService.getMatchingExtRefs(tlDevice, tCompasFlow) - .forEach(extRefService::clearExtRefBinding); - //debind all compas flow - extRefService.clearCompasFlowBinding(tCompasFlow); - } - }); - }) - ); - } - - - @Override - public List updateIedNameBasedOnLnode(SCL scl) { - Map bayByTopoKey = scl.getSubstation().stream() - .flatMap(tSubstation -> tSubstation.getVoltageLevel().stream()) - .flatMap(tVoltageLevel -> tVoltageLevel.getBay().stream()) - .map(tBay -> PrivateUtils.extractCompasPrivate(tBay, TCompasTopo.class) - .filter(tCompasTopo -> isNotBlank(tCompasTopo.getNode()) && Objects.nonNull(tCompasTopo.getNodeOrder())) - .map(tCompasTopo -> new BayTopoKey(tBay, new TopoKey(tCompasTopo.getNode(), tCompasTopo.getNodeOrder()))) - ) - .flatMap(Optional::stream) - .collect(Collectors.toMap(BayTopoKey::topoKey, BayTopoKey::bay)); - - List sclReportItems = new ArrayList<>(); - scl.getIED().stream() - .flatMap(ldeviceService::getLdevices) - .forEach(tlDevice -> - extRefService.getCompasFlows(tlDevice) - .filter(tCompasFlow -> Objects.nonNull(tCompasFlow.getFlowSourceBayNode()) && Objects.nonNull(tCompasFlow.getFlowSourceBayNodeOrder())) - .forEach(tCompasFlow -> - Optional.ofNullable(bayByTopoKey.get(new TopoKey(tCompasFlow.getFlowSourceBayNode().toString(), tCompasFlow.getFlowSourceBayNodeOrder()))) - .flatMap(tBay -> tBay.getFunction().stream() - .flatMap(tFunction -> tFunction.getLNode().stream()) - .filter(tlNode -> Objects.equals(tlNode.getLdInst(), tCompasFlow.getExtRefldinst()) - && Objects.equals(tlNode.getLnInst(), tCompasFlow.getExtReflnInst()) - && Utils.lnClassEquals(tlNode.getLnClass(), tCompasFlow.getExtReflnClass()) - && Objects.equals(tlNode.getPrefix(), tCompasFlow.getExtRefprefix())) - .filter(tlNode -> { - Optional tCompasICDHeader = PrivateUtils.extractCompasPrivate(tlNode, TCompasICDHeader.class); - if (tCompasICDHeader.isPresent()) { - return Objects.equals(tCompasFlow.getFlowSourceIEDType(), tCompasICDHeader.get().getIEDType()) - && Objects.equals(tCompasFlow.getFlowIEDSystemVersioninstance(), tCompasICDHeader.get().getIEDSystemVersioninstance()) - && Objects.equals(tCompasFlow.getFlowSourceIEDredundancy(), tCompasICDHeader.get().getIEDredundancy()); - } else { - sclReportItems.add(SclReportItem.error("", ("The substation LNode with following attributes : IedName:%s / LdInst:%s / LnClass:%s / LnInst:%s " + - "does not contain the needed (COMPAS - ICDHeader) private") - .formatted(tlNode.getIedName(), tlNode.getLdInst(), tlNode.getLnClass().getFirst(), tlNode.getLnInst()))); - return false; - } - }) - .map(TLNode::getIedName) - .reduce(checkOnlyOneIed(tCompasFlow, tBay, sclReportItems)) - ) - .ifPresentOrElse(iedName -> { - extRefService.getMatchingExtRefs(tlDevice, tCompasFlow).forEach(tExtRef -> tExtRef.setIedName(iedName)); - tCompasFlow.setExtRefiedName(iedName); - }, - () -> { - extRefService.getMatchingExtRefs(tlDevice, tCompasFlow).forEach(extRefService::clearExtRefBinding); - extRefService.clearCompasFlowBinding(tCompasFlow); - } - ) - ) - ); - return sclReportItems; - } - - private static BinaryOperator checkOnlyOneIed(TCompasFlow tCompasFlow, TBay tBay, List sclReportItems) { - return (iedName1, iedName2) -> { - sclReportItems.add(SclReportItem.error("", - ("Several LNode@IedName ('%s', '%s') are found in the bay '%s' for the following compas-flow attributes :" + - " @FlowSourceIEDType '%s' @FlowSourceIEDredundancy '%s' @FlowIEDSystemVersioninstance '%s'"). - formatted(iedName1, iedName2, tBay.getName(), tCompasFlow.getFlowSourceIEDType(), tCompasFlow.getFlowSourceIEDredundancy(), tCompasFlow.getFlowIEDSystemVersioninstance()))); - return iedName1; - }; - } - record TopoKey(String FlowNode, BigInteger FlowNodeOrder) { } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefEditor.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefEditor.java index f817f382b..3f47a1787 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefEditor.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefEditor.java @@ -21,7 +21,6 @@ *
    *
  1. {@link ExtRefEditor#updateExtRefBinders Update the TExtRef reference object for given ExtRefBindingInfo model}
  2. *
  3. {@link ExtRefEditor#updateExtRefSource Update the TExtRef reference object for given ExtRefSourceInfo model}
  4. - *
  5. {@link ExtRefEditor#updateAllExtRefIedNames Update the iedName attribute in all TExtRef}
  6. *
  7. {@link ExtRefEditor#manageBindingForLDEPF Manage TExtRef Binding For LDevice (inst=LDEPF) within LDEPF configuration}
  8. *
* @@ -47,13 +46,6 @@ public interface ExtRefEditor { */ TExtRef updateExtRefSource(SCL scd, ExtRefInfo extRefInfo) throws ScdException; - /** - * Updates iedName attribute of all ExtRefs in the Scd. - * - * @return list of encountered errors - */ - List updateAllExtRefIedNames(SCL scd); - /** * ExtRef Binding For LDevice (inst=LDEPF) that matching EPF configuration * @@ -71,18 +63,4 @@ public interface ExtRefEditor { */ void epfPostProcessing(SCL scd); - /** - * Debinding of Private CompasFlows and ExtRef signals based on voltageLevel - * - * @param scd SCL file in which ExtRef and Private CompasFlow should be debind - */ - void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd); - - /** - * Update compas:Flow.ExtRefiedName and ExtRef.iedName, based on Substation LNode iedName - * @param scd SCL - * @return list of encoutered errors - */ - List updateIedNameBasedOnLnode(SCL scd); - } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java index 8040d4917..1bb0b49fe 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java @@ -1,5 +1,5 @@ /* - * // SPDX-FileCopyrightText: 2023 RTE FRANCE + * // SPDX-FileCopyrightText: 2023 2024 RTE FRANCE * // * // SPDX-License-Identifier: Apache-2.0 */ @@ -52,18 +52,6 @@ public Stream getMatchingCompasFlows(TInputs inputs, TExtRef tExtRe .filter(compasFlow -> isMatchingExtRef(compasFlow, tExtRef)); } - /** - * Retrieves ExtRefs corresponding to given CompasFlow - * - * @param tlDevice LDevice containing CompasFlows and ExtRefs - * @param tCompasFlow corresponding to Extrefs we are searching - * @return stream of matching ExtRefs - */ - public Stream getMatchingExtRefs(TLDevice tlDevice, TCompasFlow tCompasFlow) { - return getExtRefs(tlDevice) - .filter(tExtRef -> isMatchingExtRef(tCompasFlow, tExtRef)); - } - /** * Debind ExtRef * @@ -85,18 +73,6 @@ public void clearExtRefBinding(TExtRef extRef) { extRef.unsetSrcLNClass(); } - /** - * Debind CompasFlow - * - * @param tCompasFlow to debind - */ - public void clearCompasFlowBinding(TCompasFlow tCompasFlow) { - tCompasFlow.setExtRefiedName(null); - tCompasFlow.setExtRefldinst(null); - tCompasFlow.setExtReflnClass(null); - tCompasFlow.setExtReflnInst(null); - tCompasFlow.setExtRefprefix(null); - } /** * Check if extRef matches CompasFlow diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java index 57b5108a6..8353088cc 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java @@ -18,9 +18,7 @@ import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; -import org.lfenergy.compas.sct.commons.util.ActiveStatus; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; -import org.lfenergy.compas.sct.commons.util.PrivateUtils; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.*; @@ -40,8 +38,6 @@ @Slf4j public class InputsAdapter extends SclElementAdapter { - private static final String MESSAGE_NO_MATCHING_COMPAS_FLOW = "The signal ExtRef has no matching compas:Flow Private"; - private static final String MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS = "The signal ExtRef has more than one matching compas:Flow Private"; private static final String MESSAGE_SOURCE_LDEVICE_NOT_FOUND = "The signal ExtRef ExtRefldinst does not match any " + "LDevice with same inst attribute in source IED %s"; private static final String MESSAGE_SOURCE_LN_NOT_FOUND = "The signal ExtRef lninst, doName or daName does not match any " + @@ -50,11 +46,6 @@ public class InputsAdapter extends SclElementAdapter { private static final String MESSAGE_INVALID_SERVICE_TYPE = "The signal ExtRef ServiceType attribute is unexpected : %s"; private static final String MESSAGE_IED_MISSING_COMPAS_BAY_UUID = "IED is missing Private/compas:Bay@UUID attribute"; private static final String MESSAGE_EXTREF_DESC_MALFORMED = "ExtRef.serviceType=Report but ExtRef.desc attribute is malformed"; - private static final String MESSAGE_EXTREF_IEDNAME_DOES_NOT_MATCH_ANY_SYSTEM_VERSION_UUID = "The signal ExtRef iedName does not match any " + - "IED/Private/compas:ICDHeader@ICDSystemVersionUUID"; - private static final String MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED = "The signal ExtRef source LDevice %s status is undefined"; - private static final String MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF = "The signal ExtRef source LDevice %s status is neither \"on\" nor \"off\""; - private static final String MESSAGE_SOURCE_LDEVICE_STATUS_OFF = "The signal ExtRef source LDevice %s status is off"; private static final String MESSAGE_SOURCE_IED_NOT_FOUND = "Source IED not found in SCD"; private static final String MESSAGE_SOURCE_IED_MISSING_COMPAS_BAY_UUID = "Source IED is missing Private/compas:Bay@UUID attribute"; private static final String MESSAGE_UNABLE_TO_CREATE_DATASET_OR_CONTROLBLOCK = "Could not create DataSet or ControlBlock for this ExtRef : "; @@ -62,8 +53,6 @@ public class InputsAdapter extends SclElementAdapter { private static final int EXTREF_DESC_DA_NAME_POSITION = -2; - private final ExtRefService extRefService = new ExtRefService(); - /** * Constructor * @@ -89,98 +78,6 @@ protected String elementXPath() { return "Inputs"; } - /** - * Update iedName of all ExtRefs in this "Inputs" element. - * - * @return list of encountered errors - */ - public List updateAllExtRefIedNames(Map icdSystemVersionToIed) { - Optional optionalLDeviceStatus = getLDeviceAdapter().getLDeviceStatus(); - if (optionalLDeviceStatus.isEmpty()) { - optionalLDeviceStatus = Optional.of(ActiveStatus.ON.getValue()); - } - try { - ActiveStatus lDeviceStatus = ActiveStatus.fromValue(optionalLDeviceStatus.get()); - return switch (lDeviceStatus) { - case ON -> currentElem.getExtRef().stream() - .filter(tExtRef -> StringUtils.isNotBlank(tExtRef.getIedName()) && StringUtils.isNotBlank(tExtRef.getDesc())) - .map(extRef -> updateExtRefIedName(extRef, icdSystemVersionToIed.get(extRef.getIedName()))) - .flatMap(Optional::stream) - .toList(); - case OFF -> { - currentElem.getExtRef().forEach(extRefService::clearExtRefBinding); - yield Collections.emptyList(); - } - }; - } catch (IllegalArgumentException e) { - return List.of(getLDeviceAdapter().buildFatalReportItem(e.getMessage())); - } - } - - /** - * Find matching CompasFlow private and set ExtRef iedName accordingly - * - * @param extRef extRef whose iedName will be updated - * @return Error if ExtRef could not be updated - */ - private Optional updateExtRefIedName(TExtRef extRef, IEDAdapter sourceIed) { - List matchingCompasFlows = extRefService.getMatchingCompasFlows(currentElem, extRef).toList(); - if (!singleMatch(matchingCompasFlows)) { - return fatalReportItem(extRef, - matchingCompasFlows.isEmpty() ? MESSAGE_NO_MATCHING_COMPAS_FLOW : MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS); - } - TCompasFlow compasFlow = matchingCompasFlows.get(0); - if (compasFlow.getFlowStatus() == TCompasFlowStatus.INACTIVE) { - extRefService.clearExtRefBinding(extRef); - return Optional.empty(); - } - Optional sourceValidationError = validateExtRefSource(extRef, sourceIed); - if (sourceValidationError.isPresent()) { - extRefService.clearExtRefBinding(extRef); - return sourceValidationError; - } - String sourceIedName = PrivateUtils.extractCompasPrivate(sourceIed.getCurrentElem(), TCompasICDHeader.class) - .map(TCompasICDHeader::getIEDName).orElse(""); - extRef.setIedName(sourceIedName); - compasFlow.setExtRefiedName(sourceIedName); - log.debug(String.format("extRef.desc=%s, iedName=%s%n", extRef.getDesc(), sourceIedName)); - return Optional.empty(); - } - - private Optional validateExtRefSource(TExtRef extRef, IEDAdapter sourceIed) { - if (sourceIed == null) { - return warningReportItem(extRef, MESSAGE_EXTREF_IEDNAME_DOES_NOT_MATCH_ANY_SYSTEM_VERSION_UUID); - } - Optional optionalSourceLDevice = sourceIed.findLDeviceAdapterByLdInst(extRef.getLdInst()); - if (optionalSourceLDevice.isEmpty()) { - return warningReportItem(extRef, String.format(MESSAGE_SOURCE_LDEVICE_NOT_FOUND, sourceIed.getXPath())); - } - LDeviceAdapter sourceLDevice = optionalSourceLDevice.get(); - if (sourceLDevice.findSourceDA(extRef).isEmpty()) { - return warningReportItem(extRef, String.format(MESSAGE_SOURCE_LN_NOT_FOUND, optionalSourceLDevice.get().getXPath())); - } - Optional optionalSourceLDeviceStatus = sourceLDevice.getLDeviceStatus(); - if (optionalSourceLDeviceStatus.isEmpty()) { - return fatalReportItem(extRef, String.format(MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED, - sourceLDevice.getXPath())); - } - return optionalSourceLDeviceStatus.map(sourceLDeviceStatus -> { - try { - ActiveStatus lDeviceStatus = ActiveStatus.fromValue(sourceLDeviceStatus); - return switch (lDeviceStatus) { - case OFF -> SclReportItem.warning(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_OFF, sourceLDevice.getXPath())); - case ON -> null; - }; - } catch (IllegalArgumentException e) { - return SclReportItem.error(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF, sourceLDevice.getXPath())); - } - }); - } - - private boolean singleMatch(List matchingCompasFlows) { - return matchingCompasFlows.size() == 1; - } - private Optional warningReportItem(TExtRef extRef, String message) { return Optional.of(SclReportItem.warning(extRefXPath(extRef.getDesc()), message)); } @@ -210,19 +107,11 @@ public List updateAllSourceDataSetsAndControlBlocks(List a return currentElem.getExtRef().stream() .filter(this::areBindingAttributesPresent) .filter(this::isExternalBound) - .filter(this::matchingCompasFlowIsActiveOrUntested) .map(extRef -> updateSourceDataSetsAndControlBlocks(extRef, currentBayUuid, allowedFcdas)) .flatMap(Optional::stream) .toList(); } - private boolean matchingCompasFlowIsActiveOrUntested(TExtRef extRef) { - return extRefService.getMatchingCompasFlows(currentElem, extRef).findFirst() - .map(TCompasFlow::getFlowStatus) - .filter(flowStatus -> flowStatus == TCompasFlowStatus.ACTIVE || flowStatus == TCompasFlowStatus.UNTESTED) - .isPresent(); - } - private boolean isExternalBound(TExtRef tExtRef) { return !tExtRef.getIedName().equals(getIedAdapter().getName()); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java index 098c92533..6bb6d2332 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java @@ -4,7 +4,6 @@ package org.lfenergy.compas.sct.commons; -import org.assertj.core.api.Assertions; import org.assertj.core.api.SoftAssertions; import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.BeforeEach; @@ -19,10 +18,8 @@ import org.lfenergy.compas.sct.commons.model.epf.*; import org.lfenergy.compas.sct.commons.scl.ExtRefService; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; -import org.lfenergy.compas.sct.commons.util.PrivateUtils; import java.util.List; import java.util.Optional; @@ -40,177 +37,7 @@ class ExtRefEditorServiceTest { @BeforeEach void init() { - extRefEditorService = new ExtRefEditorService(new IedService(), new LdeviceService(), new LnService(), new ExtRefService(), new DataTypeTemplatesService()); - } - - @Test - void updateAllExtRefIedNames_should_update_iedName_and_ExtRefIedName() { - // Given : An ExtRef with a matching compas:Flow - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_success.xml"); - // When - extRefEditorService.updateAllExtRefIedNames(scd); - // Then - TExtRef extRef = findExtRef(scd, "IED_NAME1", "LD_INST11", "STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1"); - assertThat(extRef.getIedName()).isEqualTo("IED_NAME2"); - - TInputs inputs = findLDevice(scd, "IED_NAME1", "LD_INST11") - .getLN0Adapter() - .getCurrentElem() - .getInputs(); - Assertions.assertThat(PrivateUtils.extractCompasPrivate(inputs, TCompasFlow.class)) - .map(TCompasFlow::getExtRefiedName) - .hasValue("IED_NAME2"); - } - - @Test - void updateAllExtRefIedNames_should_return_success_status() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_success.xml"); - // When - List sclReportItems = extRefEditorService.updateAllExtRefIedNames(scd); - // Then - assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)) - .overridingErrorMessage(String.valueOf(sclReportItems)) - .isTrue(); - } - - @ParameterizedTest(name = "{0}") - @MethodSource("updateAllExtRefIedNamesErrors") - void updateAllExtRefIedNames_should_report_errors(String testCase, SCL scl, SclReportItem... errors) { - // Given : scl parameter - // When - List sclReportItems = extRefEditorService.updateAllExtRefIedNames(scl); - // Then : the sclReport should report all errors described in the comments in the SCD file - assertThat(sclReportItems).isNotNull(); - assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse(); - assertThat(sclReportItems).containsExactlyInAnyOrder(errors); - } - - public static Stream updateAllExtRefIedNamesErrors() { - return - Stream.of(Arguments.of( - "Errors on ExtRefs", - SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml"), - new SclReportItem[]{ - SclReportItem.error( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"No matching compas:Flow\"]", - "The signal ExtRef has no matching compas:Flow Private"), - SclReportItem.error( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"Matching two compas:Flow\"]", - "The signal ExtRef has more than one matching compas:Flow Private"), - SclReportItem.error( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST13\"]", - "The status test does not exist. It should be among [on, off]"), - SclReportItem.warning( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/" + - "LDevice[@inst=\"LD_INST14\"]/LN0/Inputs/ExtRef[@desc=\"STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1\"]", - "The signal ExtRef lninst, doName or daName does not match any source " + - "in LDevice /SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST14\"]"), - SclReportItem.warning( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"ExtRef does not match any ICDSystemVersionUUID\"]", - "The signal ExtRef iedName does not match any IED/Private/compas:ICDHeader@ICDSystemVersionUUID"), - SclReportItem.warning( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"ExtRefldinst does not match any LDevice inst in source IED\"]", - "The signal ExtRef ExtRefldinst does not match any LDevice with same inst attribute in source IED /SCL/IED[@name=\"IED_NAME2\"]"), - SclReportItem.warning( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"ExtRef does not match any LN in source LDevice\"]", - "The signal ExtRef lninst, doName or daName does not match any source in LDevice " + - "/SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST21\"]"), - SclReportItem.warning( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"Source LDevice is off for this ExtRef\"]", - "The signal ExtRef source LDevice /SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST22\"] status is off"), - SclReportItem.error( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"Source LDevice is undefined for this ExtRef\"]", - "The signal ExtRef source LDevice /SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST23\"] status is " + - "undefined"), - SclReportItem.error( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + - "/LN0/Inputs/ExtRef[@desc=\"Source LDevice is neither on nor off for this ExtRef\"]", - "The signal ExtRef source LDevice /SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST24\"] " + - "status is neither \"on\" nor \"off\"") - }), - Arguments.of( - "Errors on IEDs", - SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_with_ied_errors.xml"), - new SclReportItem[]{ - SclReportItem.error( - "/SCL/IED[@name=\"IED_NAME1\"], /SCL/IED[@name=\"IED_NAME2\"]", - "/IED/Private/compas:ICDHeader[@ICDSystemVersionUUID] must be unique but the same ICDSystemVersionUUID was found on several IED."), - SclReportItem.error("/SCL/IED[@name=\"IED_NAME3\"]", "IED has no Private COMPAS-ICDHeader element"), - SclReportItem.error("/SCL/IED[@name=\"IED_NAME4\"]", "IED private COMPAS-ICDHeader as no icdSystemVersionUUID or iedName attribute"), - SclReportItem.error("/SCL/IED[@name=\"IED_NAME5\"]", "IED private COMPAS-ICDHeader as no icdSystemVersionUUID or iedName attribute") - }) - ); - } - - @Test - void updateAllExtRefIedNames_when_not_bindable_should_clear_binding() { - // Given : see comments in SCD file - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml"); - // When - extRefEditorService.updateAllExtRefIedNames(scd); - // Then - assertExtRefIsNotBound(findExtRef(scd, "IED_NAME1", "LD_INST12", "ExtRef target LDevice status is off")); - assertExtRefIsNotBound(findExtRef(scd, "IED_NAME1", "LD_INST11", "Match compas:Flow but FlowStatus is INACTIVE")); - assertExtRefIsNotBound(findExtRef(scd, "IED_NAME1", "LD_INST11", "ExtRef does not match any ICDSystemVersionUUID")); - assertExtRefIsNotBound(findExtRef(scd, "IED_NAME1", "LD_INST11", "ExtRefldinst does not match any LDevice inst in source IED")); - assertExtRefIsNotBound(findExtRef(scd, "IED_NAME1", "LD_INST11", "ExtRef does not match any LN in source LDevice")); - assertExtRefIsNotBound(findExtRef(scd, "IED_NAME1", "LD_INST11", "Source LDevice is off for this ExtRef")); - } - - @Test - void updateAllExtRefIedNames_when_lDevice_off_should_remove_binding() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml"); - // When - List sclReportItems = extRefEditorService.updateAllExtRefIedNames(scd); - // Then - assertThat(sclReportItems).isNotNull(); - LDeviceAdapter lDeviceAdapter = findLDeviceByLdName(scd, "IED_NAME1LD_INST12"); - assertThat(lDeviceAdapter.getLDeviceStatus()).hasValue("off"); - assertThat(lDeviceAdapter.getLN0Adapter().getInputsAdapter().getCurrentElem().getExtRef()) - .allSatisfy(this::assertExtRefIsNotBound); - } - - @Test - void updateAllExtRefIedNames_when_FlowStatus_INACTIVE_should_remove_binding() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml"); - // When - List sclReportItems = extRefEditorService.updateAllExtRefIedNames(scd); - // Then - assertThat(sclReportItems).isNotNull(); - LDeviceAdapter lDeviceAdapter = findLDeviceByLdName(scd, "IED_NAME1LD_INST11"); - assertThat(lDeviceAdapter.getLDeviceStatus()).hasValue("on"); - Optional optionalTExtRef = lDeviceAdapter.getCurrentElem().getLN0().getInputs().getExtRef().stream() - .filter(tExtRef -> "Match compas:Flow but FlowStatus is INACTIVE".equals(tExtRef.getDesc())) - .findFirst(); - assertThat(optionalTExtRef).isPresent(); - TExtRef extRef = optionalTExtRef.get(); - assertExtRefIsNotBound(extRef); - } - - private void assertExtRefIsNotBound(TExtRef extRef) { - assertThat(extRef.isSetIedName()).isFalse(); - assertThat(extRef.isSetLdInst()).isFalse(); - assertThat(extRef.isSetPrefix()).isFalse(); - assertThat(extRef.isSetLnClass()).isFalse(); - assertThat(extRef.isSetLnInst()).isFalse(); - assertThat(extRef.isSetDoName()).isFalse(); - assertThat(extRef.isSetDaName()).isFalse(); - assertThat(extRef.isSetServiceType()).isFalse(); - assertThat(extRef.isSetSrcLDInst()).isFalse(); - assertThat(extRef.isSetSrcPrefix()).isFalse(); - assertThat(extRef.isSetSrcLNClass()).isFalse(); - assertThat(extRef.isSetSrcLNInst()).isFalse(); - assertThat(extRef.isSetSrcCBName()).isFalse(); + extRefEditorService = new ExtRefEditorService(new IedService(), new LdeviceService(), new LnService(), new DataTypeTemplatesService()); } @Test @@ -844,119 +671,6 @@ void updateExtRefSource_whenBindingExternalBinding_shouldThrowScdException() { assertThat(extRef.getSrcLNClass()).contains(extRefInfo.getBindingInfo().getLnClass()); } - @ParameterizedTest(name = "{0}") - @MethodSource("provideFlowAndExtRefForDebinding") - void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(String testCase, SCL scd, Tuple extRef1, Tuple flow1, Tuple extRef2, Tuple flow2) { - //Given - //Then - extRefEditorService.debindCompasFlowsAndExtRefsBasedOnVoltageLevel(scd); - //When - TInputs tInputs = findInputs(scd); - assertThat(tInputs.getExtRef().stream().filter(tExtRef -> tExtRef.getDesc().equals("Desc_1"))) - .extracting(TExtRef::getIedName, TExtRef::getLdInst) - .containsExactly(extRef1); - assertThat(PrivateUtils.getPrivateStream(tInputs.getPrivate(), TCompasFlow.class).filter(tCompasFlow -> tCompasFlow.getDataStreamKey().equals("Desc_1"))) - .extracting(TCompasFlow::getExtRefiedName, TCompasFlow::getExtRefldinst, TCompasFlow::getExtReflnClass, TCompasFlow::getExtReflnInst) - .containsExactly(flow1); - assertThat(tInputs.getExtRef().stream().filter(tExtRef -> tExtRef.getDesc().equals("Desc_2"))) - .extracting(TExtRef::getIedName, TExtRef::getLdInst) - .containsExactly(extRef2); - assertThat(PrivateUtils.getPrivateStream(tInputs.getPrivate(), TCompasFlow.class).filter(tCompasFlow -> tCompasFlow.getDataStreamKey().equals("Desc_2"))) - .extracting(TCompasFlow::getExtRefiedName, TCompasFlow::getExtRefldinst, TCompasFlow::getExtReflnClass, TCompasFlow::getExtReflnInst) - .containsExactly(flow2); - } - - private static Stream provideFlowAndExtRefForDebinding() { - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-flow-debind/scd_extref_flow_debind_success.xml"); - SCL scdVoltageLevel0 = SclTestMarshaller.getSCLFromFile("/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_0.xml"); - SCL scdVoltageLevelUnknown = SclTestMarshaller.getSCLFromFile("/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_unknown.xml"); - SCL scdUnsetExtRefIedName = SclTestMarshaller.getSCLFromFile("/scd-extref-flow-debind/scd_extref_flow_not_debind.xml"); - SCL scdVLevelUnknownUnsetFlowSourceVoltageLevel = SclTestMarshaller.getSCLFromFile("/scd-extref-flow-debind/scd_extref_flow_not_debind_volatagelevelname_unknown.xml"); - Tuple tupleExtRef1 = Tuple.tuple("System_Version_IED_NAME1", "LD_INST11"); - Tuple tupleExtRef2 = Tuple.tuple("System_Version_IED_NAME2", "LD_INST21"); - Tuple tupleExtRefDebind = Tuple.tuple(null, null); - Tuple tupleFlow1 = Tuple.tuple("System_Version_IED_NAME1", "LD_INST11", "LLN0", null); - Tuple tupleFlow2 = Tuple.tuple("System_Version_IED_NAME2", "LD_INST21", "ANCR", "1"); - Tuple tupleFlowNoExtRefIedName = Tuple.tuple(null, "LD_INST21", "ANCR", "1"); - Tuple tupleFlowDebind = Tuple.tuple(null, null, null, null); - - return Stream.of( - Arguments.of("case known voltageLevel should debind THT flow and corresponding ExtRef", scd, tupleExtRef1, tupleFlow1, tupleExtRefDebind, tupleFlowDebind), - Arguments.of("case voltageLevel 0 should do nothing", scdVoltageLevel0, tupleExtRef1, tupleFlow1, tupleExtRef2, tupleFlow2), - Arguments.of("case unknown voltageLevel should debind all CompasFlow and corresponding ExtRef", scdVoltageLevelUnknown, tupleExtRefDebind, tupleFlowDebind, tupleExtRefDebind, tupleFlowDebind), - Arguments.of("case known voltageLevel should not debind because no ExtRefIedName", scdUnsetExtRefIedName, tupleExtRef1, tupleFlow1, tupleExtRef2, tupleFlowNoExtRefIedName), - Arguments.of("case unknown voltageLevel should not debind because unset FlowSourceVoltageLevel", scdVLevelUnknownUnsetFlowSourceVoltageLevel, tupleExtRef1, tupleFlow1, tupleExtRef2, tupleFlow2) - ); - - } - - - private TInputs findInputs(SCL scd) { - IedService iedService = new IedService(); - LdeviceService ldeviceService = new LdeviceService(); - return iedService.findIed(scd, tied -> tied.getName().equals("IED_NAME1")) - .flatMap(tied -> ldeviceService.findLdevice(tied, tlDevice -> tlDevice.getInst().equals("LD_INST11"))) - .map(tlDevice -> tlDevice.getLN0().getInputs()) - .orElseThrow(); - - } - - @Test - void updateIedNameBasedOnLnode_should_update_CompasFlow_and_ExtRef_iedName() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_success.xml"); - // When - extRefEditorService.updateIedNameBasedOnLnode(scd); - // Then - assertThat(findCompasFlow(scd, "IED_NAME1", "LD_INST11", "STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1").getExtRefiedName()) - .isEqualTo("IED_NAME2"); - assertThat(findExtRef(scd, "IED_NAME1", "LD_INST11", "STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1").getIedName()) - .isEqualTo("IED_NAME2"); - } - - @Test - void updateIedNameBasedOnLnode_when_no_matching_lnode_should_clear_binding() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_success.xml"); - PrivateUtils.extractCompasPrivate(scd.getSubstation().get(0).getVoltageLevel().get(0).getBay().get(0), TCompasTopo.class).orElseThrow().setNode("99"); - // When - extRefEditorService.updateIedNameBasedOnLnode(scd); - // Then - TCompasFlow compasFlow = findCompasFlow(scd, "IED_NAME1", "LD_INST11", "STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1"); - assertThat(compasFlow) - .extracting(TCompasFlow::getExtRefiedName, TCompasFlow::getExtRefldinst, TCompasFlow::getExtRefprefix, TCompasFlow::getExtReflnClass, TCompasFlow::getExtReflnInst) - .containsOnlyNulls(); - assertExtRefIsNotBound(findExtRef(scd, "IED_NAME1", "LD_INST11", "STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1")); - - } - - @Test - void updateIedNameBasedOnLnode_when_several_ied_match_compasFlow_should_return_an_error() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_several_ied_matching_compasFlow.xml"); - // When - List result = extRefEditorService.updateIedNameBasedOnLnode(scd); - // Then - assertThat(result) - .extracting(SclReportItem::isError, SclReportItem::message) - .containsExactly(Tuple.tuple(true, - "Several LNode@IedName ('IED_NAME2', 'IED_NAME3') are found in the bay 'BAY_1' for the following compas-flow attributes " + - ": @FlowSourceIEDType 'SCU' @FlowSourceIEDredundancy 'A' @FlowIEDSystemVersioninstance '1'")); - } - - @Test - void updateIedNameBasedOnLnode_when_no_Compas_ICD_Header_should_return_an_error() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_fails_no_Compas_ICDHeader.xml"); - // When - List result = extRefEditorService.updateIedNameBasedOnLnode(scd); - // Then - assertThat(result) - .extracting(SclReportItem::isError, SclReportItem::message) - .containsExactly(Tuple.tuple(true, - "The substation LNode with following attributes : IedName:IED_NAME2 / LdInst:LD_INST21 / LnClass:ANCR / LnInst:1 does not contain the needed (COMPAS - ICDHeader) private")); - } - @Test void epfPostProcessing_when_exist_unused_channel_should_update_setSrcRef() { // Given diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java index 04c6057c6..4e762b213 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java @@ -102,26 +102,6 @@ void getMatchingCompasFlows_should_succeed() { .containsExactly(Tuple.tuple("Desc_1", "IED_Name_1")); } - @Test - void getMatchingExtRefs_should_succeed() { - //Given - TLDevice tlDevice = new TLDevice(); - tlDevice.setLN0(new LN0()); - TInputs tInputs = new TInputs(); - TExtRef tExtRef1 = createExtRef("Desc_1", "IED_Name_1", "LD_INST_1"); - TExtRef tExtRef2 = createExtRef("Desc_2", "IED_Name_2", "LD_INST_2"); - tInputs.getExtRef().add(tExtRef1); - tInputs.getExtRef().add(tExtRef2); - TCompasFlow tCompasFlow = createCompasFlow("Desc_1", "IED_Name_1", "LD_INST_1"); - tlDevice.getLN0().setInputs(tInputs); - //When - Stream tExtRefStream = extRefService.getMatchingExtRefs(tlDevice, tCompasFlow); - //Then - assertThat(tExtRefStream).hasSize(1) - .map(TExtRef::getIedName, TExtRef::getLdInst, TExtRef::getDesc) - .containsExactly(Tuple.tuple("IED_Name_1", "LD_INST_1", "Desc_1")); - } - @Test void clearExtRefBinding_should_remove_binding() { //Given @@ -135,19 +115,6 @@ void clearExtRefBinding_should_remove_binding() { assertThat(tExtRef.getDesc()).isEqualTo("Desc_1"); } - @Test - void clearCompasFlowBinding_should_remove_binding() { - //Given - TCompasFlow compasFlow = createCompasFlow("Desc_1", "IED_Name_1", "LD_INST_1"); - //When - extRefService.clearCompasFlowBinding(compasFlow); - //Then - assertThat(compasFlow) - .extracting(TCompasFlow::getExtRefiedName, TCompasFlow::getExtRefldinst, TCompasFlow::getExtReflnClass, TCompasFlow::getExtReflnInst, TCompasFlow::getExtRefprefix) - .containsOnlyNulls(); - assertThat(compasFlow.getDataStreamKey()).isEqualTo("Desc_1"); - } - @ParameterizedTest @MethodSource("provideExtRefsFedBySameControlBlock") void isExtRefFeedBySameControlBlock_should_return_true(TExtRef tExtRef1, TExtRef tExtRef2) { diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java index fb7acaf25..f1a530199 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java @@ -191,11 +191,7 @@ public static Stream provideCreateFCDA() { Arguments.of(named("should ignore instance number when checking FCDA Candidate file (DO with SDO)", "test no daName and doName with instance number and SDO"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", - List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoWithInst2.subDo", "daNameST", TFCEnum.ST))), - Arguments.of(named("hould include UNTESTED FlowStatus", - "test include compas:Flow.FlowStatus UNTESTED"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", - List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", "daNameST", TFCEnum.ST))) + List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoWithInst2.subDo", "daNameST", TFCEnum.ST))) ); } @@ -218,16 +214,41 @@ void updateAllSourceDataSetsAndControlBlocks_when_no_valid_source_Da_found_shoul .allMatch(ln0Adapter -> !ln0Adapter.getCurrentElem().isSetDataSet()); } + @ParameterizedTest + @MethodSource("provideDoCreateFCDA") + void updateAllSourceDataSetsAndControlBlocks_when_valid_source_Da_found_should_create_FCDA(String extRefDesc, String extRefIedName) { + // Given + SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml"); + SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + InputsAdapter inputsAdapter = keepOnlyThisExtRef(sclRootAdapter, extRefDesc); + DACOMM dacomm = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml"); + // When + List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(dacomm.getFCDAs().getFCDA()); + // Then + assertThat(sclReportItems).isEmpty(); + assertThat(sclRootAdapter.streamIEDAdapters() + .filter(iedAdapter -> iedAdapter.getName().equals(extRefIedName)) + .flatMap(IEDAdapter::streamLDeviceAdapters) + .filter(LDeviceAdapter::hasLN0) + .map(LDeviceAdapter::getLN0Adapter)) + .allMatch(ln0Adapter -> ln0Adapter.getCurrentElem().isSetDataSet()); + } + public static Stream provideDoNotCreateFCDA() { return Stream.of( - Arguments.of(named("should not create FCDA for source Da different from MX and ST", - "test daName BL")), - Arguments.of(named("should not create FCDA for extref with a binding internal to the IED", - "test ignore internal binding")), - Arguments.of(named("should not create FCDA for extref with missing binding attributes", - "test ignore missing bindings attributes")), - Arguments.of(named("should not create FCDA for ExtRef with compas:Flow.FlowStatus INACTIVE", - "test ignore when compas:Flow.FlowStatus is neither ACTIVE nor UNTESTED")) + Arguments.of(named("should not create FCDA for source Da different from MX and ST", + "test daName BL")), + Arguments.of(named("should not create FCDA for extref with a binding internal to the IED", + "test ignore internal binding")), + Arguments.of(named("should not create FCDA for extref with missing binding attributes", + "test ignore missing bindings attributes")) + ); + } + + public static Stream provideDoCreateFCDA() { + return Stream.of( + Arguments.of(named("should create FCDA", "test bay internal"), "IED_NAME2"), + Arguments.of(named("should create FCDA", "test bay external"), "IED_NAME3") ); } @@ -305,15 +326,4 @@ void filterDuplicatedExtRefs_should_not_remove_not_duplicated_extrefs() { .hasSize(6); } - @Test - void updateAllExtRefIedNames_when_DOI_Mod_and_DAI_stVal_notExists_should_not_produce_error() { - // Given - SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd"); - InputsAdapter inputsAdapter = findInputs(scl, "IedName1", "LDSUIED"); - // When - List sclReportItems = inputsAdapter.updateAllExtRefIedNames(Map.of()); - // Then - assertThat(sclReportItems).isEmpty(); - } - } diff --git a/sct-commons/src/test/resources/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml b/sct-commons/src/test/resources/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml index e235d298a..86134bd86 100644 --- a/sct-commons/src/test/resources/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml +++ b/sct-commons/src/test/resources/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml @@ -1,5 +1,5 @@ - + @@ -26,24 +26,6 @@ - - - - - - - - - - - - - - - - - - @@ -66,14 +48,10 @@ - - - - diff --git a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_success.xml b/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_success.xml deleted file mode 100644 index df00a06ea..000000000 --- a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_success.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - -
- - - 90 - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_0.xml b/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_0.xml deleted file mode 100644 index e55aa6aef..000000000 --- a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_0.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - -
- - - 90 - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_unknown.xml b/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_unknown.xml deleted file mode 100644 index ff48290d5..000000000 --- a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_debind_volatagelevelname_unknown.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - -
- - - 90 - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind.xml b/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind.xml deleted file mode 100644 index 07c30b052..000000000 --- a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - -
- - - 90 - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind_volatagelevelname_unknown.xml b/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind_volatagelevelname_unknown.xml deleted file mode 100644 index 44eb48233..000000000 --- a/sct-commons/src/test/resources/scd-extref-flow-debind/scd_extref_flow_not_debind_volatagelevelname_unknown.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - -
- - - 90 - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_several_ied_matching_compasFlow.xml b/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_several_ied_matching_compasFlow.xml deleted file mode 100644 index 039ec0be5..000000000 --- a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_several_ied_matching_compasFlow.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - -
- - - 0 - - - - - - - - - - - - - - - - on - - - - - - - - - - - on - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_success.xml b/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_success.xml deleted file mode 100644 index 3cb543dbb..000000000 --- a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_based_on_lnode_success.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - -
- - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_fails_no_Compas_ICDHeader.xml b/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_fails_no_Compas_ICDHeader.xml deleted file mode 100644 index 4565f43be..000000000 --- a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_fails_no_Compas_ICDHeader.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - -
- - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_success.xml b/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_success.xml deleted file mode 100644 index 7cd696da4..000000000 --- a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_success.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - -
- - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - - - - on - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - diff --git a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml b/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml index f5a281d3d..0b2aba414 100644 --- a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml +++ b/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml @@ -1,5 +1,5 @@ - + @@ -24,18 +24,6 @@ - - - - - - - - - - - - diff --git a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_ied_errors.xml b/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_ied_errors.xml deleted file mode 100644 index ad441a2cf..000000000 --- a/sct-commons/src/test/resources/scd-extref-iedname/scd_set_extref_iedname_with_ied_errors.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - on - off - test - - - From d83efeb9e75cb821b7e8feeb41db43987c5d1987 Mon Sep 17 00:00:00 2001 From: Samir Romdhani Date: Mon, 9 Dec 2024 11:30:39 +0100 Subject: [PATCH 2/2] feat / review deconstructing compas-flow Signed-off-by: Samir Romdhani --- .../sct/commons/ExtRefEditorService.java | 52 -------- .../sct/commons/ExtRefEditorServiceTest.java | 1 - .../commons/scl/ied/InputsAdapterTest.java | 57 ++------ ...t_Missing_ModstVal_In_LN0_when_binding.scd | 124 ------------------ 4 files changed, 10 insertions(+), 224 deletions(-) delete mode 100644 sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java index e68ddd7c8..221b133f5 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java @@ -15,19 +15,15 @@ import org.lfenergy.compas.sct.commons.model.epf.TCBScopeType; import org.lfenergy.compas.sct.commons.model.epf.TChannel; import org.lfenergy.compas.sct.commons.model.epf.TChannelType; -import org.lfenergy.compas.sct.commons.scl.ExtRefService; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.util.ActiveStatus; -import org.lfenergy.compas.sct.commons.util.PrivateEnum; import org.lfenergy.compas.sct.commons.util.PrivateUtils; import org.lfenergy.compas.sct.commons.util.Utils; -import java.math.BigInteger; import java.util.*; -import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.*; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; @@ -325,48 +321,6 @@ public void epfPostProcessing(SCL scd) { }))); } - private List validateIed(SclRootAdapter sclRootAdapter) { - List iedErrors = new ArrayList<>(checkIedCompasIcdHeaderAttributes(sclRootAdapter)); - iedErrors.addAll(checkIedUnityOfIcdSystemVersionUuid(sclRootAdapter)); - return iedErrors; - } - - private List checkIedCompasIcdHeaderAttributes(SclRootAdapter sclRootAdapter) { - return sclRootAdapter.streamIEDAdapters() - .map(iedAdapter -> { - Optional compasPrivate = iedAdapter.getCompasICDHeader(); - if (compasPrivate.isEmpty()) { - return iedAdapter.buildFatalReportItem(String.format("IED has no Private %s element", PrivateEnum.COMPAS_ICDHEADER.getPrivateType())); - } - if (isBlank(compasPrivate.get().getICDSystemVersionUUID()) - || isBlank(compasPrivate.get().getIEDName())) { - return iedAdapter.buildFatalReportItem(String.format("IED private %s as no icdSystemVersionUUID or iedName attribute", - PrivateEnum.COMPAS_ICDHEADER.getPrivateType())); - } - return null; - } - ).filter(Objects::nonNull) - .toList(); - } - - private List checkIedUnityOfIcdSystemVersionUuid(SclRootAdapter sclRootAdapter) { - Map> systemVersionToIedList = sclRootAdapter.getCurrentElem().getIED().stream() - .collect(Collectors.groupingBy(ied -> PrivateUtils.extractCompasPrivate(ied, TCompasICDHeader.class) - .map(TCompasICDHeader::getICDSystemVersionUUID) - .orElse(""))); - - return systemVersionToIedList.entrySet().stream() - .filter(entry -> isNotBlank(entry.getKey())) - .filter(entry -> entry.getValue().size() > 1) - .map(entry -> SclReportItem.error(entry.getValue().stream() - .map(tied -> new IEDAdapter(sclRootAdapter, tied)) - .map(IEDAdapter::getXPath) - .collect(Collectors.joining(", ")), - "/IED/Private/compas:ICDHeader[@ICDSystemVersionUUID] must be unique" + - " but the same ICDSystemVersionUUID was found on several IED.")) - .toList(); - } - private void updateLDEPFExtRefBinding(TExtRef extRef, TIED iedSource, TChannel setting) { extRef.setIedName(iedSource.getName()); extRef.setLdInst(setting.getLDInst()); @@ -434,12 +388,6 @@ private String computeDaiValue(AbstractLNAdapter lnAdapter, TExtRef extRef, S } } - record TopoKey(String FlowNode, BigInteger FlowNodeOrder) { - } - - record BayTopoKey(TBay bay, TopoKey topoKey) { - } - private record DoNameAndDaName(String doName, String daName) { } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java index 6bb6d2332..bdb7547cc 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java @@ -16,7 +16,6 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.model.epf.*; -import org.lfenergy.compas.sct.commons.scl.ExtRefService; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java index f1a530199..c464fd56b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java @@ -153,44 +153,34 @@ void updateAllSourceDataSetsAndControlBlocks_should_create_dataset_and_fcda_for_ public static Stream provideCreateFCDA() { return Stream.of( Arguments.of(named("should include signal internal to a Bay", - "test bay internal"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test bay internal"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", "daNameST", TFCEnum.ST))), Arguments.of(named("should include signal external to a Bay", - "test bay external"), - "IED_NAME3/LD_INST31/DS_LD_INST31_GSE", + "test bay external"), "IED_NAME3/LD_INST31/DS_LD_INST31_GSE", List.of(new FCDARecord("LD_INST31", "ANCR", "1", "", "DoName", "daNameST", TFCEnum.ST))), Arguments.of(named("keep source DA with fc = ST", - "test daName ST"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test daName ST"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", "daNameST", TFCEnum.ST))), Arguments.of(named("keep source DA with fc = MX", - "test daName MX"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GMI", + "test daName MX"), "IED_NAME2/LD_INST21/DS_LD_INST21_GMI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", "daNameMX", TFCEnum.MX))), Arguments.of(named("for GOOSE, should keep only valid fcda candidates", - "test ServiceType is GOOSE, no daName and DO contains ST and MX, but only ST is FCDA candidate"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test ServiceType is GOOSE, no daName and DO contains ST and MX, but only ST is FCDA candidate"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "OtherDoName", "daNameST", TFCEnum.ST))), Arguments.of(named("for SMV, should keep only valid fcda candidates", - "test ServiceType is SMV, no daName and DO contains ST and MX, but only ST is FCDA candidate"), - "IED_NAME2/LD_INST21/DS_LD_INST21_SVI", + "test ServiceType is SMV, no daName and DO contains ST and MX, but only ST is FCDA candidate"), "IED_NAME2/LD_INST21/DS_LD_INST21_SVI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "OtherDoName", "daNameST", TFCEnum.ST))), Arguments.of(named("for Report, should get source daName from ExtRef.desc to deduce FC ST", - "test ServiceType is Report_daReportST_1"), - "IED_NAME2/LD_INST21/DS_LD_INST21_DQCI", + "test ServiceType is Report_daReportST_1"), "IED_NAME2/LD_INST21/DS_LD_INST21_DQCI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", null, TFCEnum.ST))), Arguments.of(named("for Report, should get source daName from ExtRef.desc to deduce FC MX", - "test ServiceType is Report_daReportMX_1"), - "IED_NAME2/LD_INST21/DS_LD_INST21_CYCI", + "test ServiceType is Report_daReportMX_1"), "IED_NAME2/LD_INST21/DS_LD_INST21_CYCI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", null, TFCEnum.MX))), Arguments.of(named("should ignore instance number when checking FCDA Candidate file", - "test no daName and doName with instance number"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test no daName and doName with instance number"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoWithInst1", "daNameST", TFCEnum.ST))), Arguments.of(named("should ignore instance number when checking FCDA Candidate file (DO with SDO)", - "test no daName and doName with instance number and SDO"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test no daName and doName with instance number and SDO"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoWithInst2.subDo", "daNameST", TFCEnum.ST))) ); } @@ -214,26 +204,6 @@ void updateAllSourceDataSetsAndControlBlocks_when_no_valid_source_Da_found_shoul .allMatch(ln0Adapter -> !ln0Adapter.getCurrentElem().isSetDataSet()); } - @ParameterizedTest - @MethodSource("provideDoCreateFCDA") - void updateAllSourceDataSetsAndControlBlocks_when_valid_source_Da_found_should_create_FCDA(String extRefDesc, String extRefIedName) { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - InputsAdapter inputsAdapter = keepOnlyThisExtRef(sclRootAdapter, extRefDesc); - DACOMM dacomm = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml"); - // When - List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(dacomm.getFCDAs().getFCDA()); - // Then - assertThat(sclReportItems).isEmpty(); - assertThat(sclRootAdapter.streamIEDAdapters() - .filter(iedAdapter -> iedAdapter.getName().equals(extRefIedName)) - .flatMap(IEDAdapter::streamLDeviceAdapters) - .filter(LDeviceAdapter::hasLN0) - .map(LDeviceAdapter::getLN0Adapter)) - .allMatch(ln0Adapter -> ln0Adapter.getCurrentElem().isSetDataSet()); - } - public static Stream provideDoNotCreateFCDA() { return Stream.of( Arguments.of(named("should not create FCDA for source Da different from MX and ST", @@ -245,13 +215,6 @@ public static Stream provideDoNotCreateFCDA() { ); } - public static Stream provideDoCreateFCDA() { - return Stream.of( - Arguments.of(named("should create FCDA", "test bay internal"), "IED_NAME2"), - Arguments.of(named("should create FCDA", "test bay external"), "IED_NAME3") - ); - } - @Test void updateAllSourceDataSetsAndControlBlocks_when_AccessPoint_does_not_have_dataset_creation_capability_should_report_error() { // Given diff --git a/sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd b/sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd deleted file mode 100644 index 4d99bef72..000000000 --- a/sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - SCD - -
- - - -
- - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - -
-

00000001

-
-
-
- - -
-

Adresse IP du serveur Syslog

-
-
-
-
- - SAMU - SAMU - - - - - - - - - - - - - - - - - 01.00.000 - - - 01.00.000 - - - - - - - - - - - - - - - - - - - - - - - - - - - - blocked - test - test/blocked - off - on - - - -