From 71ebbd50cda1e6c0593c8129577c808cd1f35165 Mon Sep 17 00:00:00 2001 From: aDiaite Date: Thu, 29 Sep 2022 17:10:26 +0200 Subject: [PATCH] apply correction after code review Signed-off-by: Aliou DIAITE --- .../sct/commons/dto/ResumedDataTemplate.java | 2 +- .../compas/sct/commons/dto/SclReport.java | 2 +- .../sct/commons/scl/LDeviceActivation.java | 43 +++--- .../compas/sct/commons/scl/SclService.java | 4 +- .../sct/commons/scl/dtt/DATypeAdapter.java | 2 +- .../compas/sct/commons/scl/dtt/DOAdapter.java | 2 +- .../sct/commons/scl/dtt/LNodeTypeAdapter.java | 2 +- .../commons/scl/ied/AbstractLNAdapter.java | 4 +- .../sct/commons/scl/ied/DOIAdapter.java | 4 +- .../sct/commons/scl/ied/LN0Adapter.java | 63 +++----- .../sct/commons/scl/ied/RootSDIAdapter.java | 4 +- .../sct/commons/scl/ied/SDIAdapter.java | 4 +- .../scl/sstation/SubstationAdapter.java | 7 +- .../sct/commons/util/CommonConstants.java | 3 + .../commons/scl/LDeviceActivationTest.java | 138 +++++++++++++++--- .../sct/commons/scl/SclServiceTest.java | 97 ++++++------ .../commons/scl/SubstationServiceTest.java | 3 - .../scl/com/ConnectedAPAdapterTest.java | 19 +-- .../scl/com/SubNetworkAdapterTest.java | 20 +-- .../sct/commons/scl/dtt/BDAAdapterTest.java | 2 +- .../sct/commons/scl/dtt/DOAdapterTest.java | 2 +- .../commons/scl/dtt/LNodeTypeAdapterTest.java | 2 +- .../commons/scl/header/HeaderAdapterTest.java | 21 +-- .../sct/commons/scl/ied/DOIAdapterTest.java | 6 +- .../commons/scl/ied/LDeviceAdapterTest.java | 18 ++- .../sct/commons/scl/ied/LN0AdapterTest.java | 12 +- .../commons/scl/ied/RootSDIAdapterTest.java | 4 +- .../sct/commons/scl/ied/SDIAdapterTest.java | 17 ++- .../scl/sstation/SubstationAdapterTest.java | 17 +-- 29 files changed, 300 insertions(+), 224 deletions(-) diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ResumedDataTemplate.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ResumedDataTemplate.java index dd702a8c9..c0022cb1d 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ResumedDataTemplate.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ResumedDataTemplate.java @@ -323,7 +323,7 @@ public boolean isValImport(){ return daName.isValImport(); } - public ResumedDataTemplate setNewVal(String daiValue) { + public ResumedDataTemplate setVal(String daiValue) { TVal newDaiVal = new TVal(); newDaiVal.setValue(daiValue); this.setDaiValues(List.of(newDaiVal)); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReport.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReport.java index 2a9e42679..7a62b4bf0 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReport.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReport.java @@ -19,7 +19,7 @@ @Builder public class SclReport { - private SclRootAdapter scdFile; + private SclRootAdapter sclRootAdapter; private List errorDescriptionList = new ArrayList<>(); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivation.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivation.java index 9bf8d8c85..59dc6db7e 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivation.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivation.java @@ -10,7 +10,6 @@ import org.lfenergy.compas.scl2007b4.model.TCompasLDeviceStatus; import org.lfenergy.compas.sct.commons.util.STValEnum; -import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -23,11 +22,9 @@ public class LDeviceActivation { private final List> iedNameLdInstList; - - private TCompasLDeviceStatus compasLDeviceStatus; private boolean isUpdatable; private String newVal; - private List errorMessages = new ArrayList<>(); + private String errorMessage; public LDeviceActivation(List> iedNameLdInstList) { this.iedNameLdInstList = iedNameLdInstList; @@ -42,13 +39,11 @@ public LDeviceActivation(List> iedNameLdInstList) { */ public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasLDeviceStatus compasLDeviceStatus, Set enumValues) { if (!enumValues.contains(STValEnum.ON.value) && !enumValues.contains(STValEnum.OFF.value)) { - errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.", - iedName, ldInst)); + errorMessage = "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'."; } if (!enumValues.contains(STValEnum.ON.value) && enumValues.contains(STValEnum.OFF.value)) { - if (isAuthorized(iedName, ldInst)) { - errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be set to 'on' but has been selected into SSD: this case should not occur.", - iedName, ldInst)); + if (isDeclaredInSubstation(iedName, ldInst)) { + errorMessage = "The LDevice cannot be set to 'on' but has been selected into SSD."; } else { isUpdatable = true; newVal = STValEnum.OFF.value; @@ -56,10 +51,10 @@ public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasL } if(compasLDeviceStatus.equals(TCompasLDeviceStatus.ACTIVE) || compasLDeviceStatus.equals(TCompasLDeviceStatus.UNTESTED)){ - isAuthorizedToActivateLDevice(iedName, ldInst, enumValues); + checkAuthorisationToActivateLDevice(iedName, ldInst, enumValues); } if(compasLDeviceStatus.equals(TCompasLDeviceStatus.INACTIVE)){ - isAuthorizedToDeactivateLDevice(iedName, ldInst, enumValues); + checkAuthorisationToDeactivateLDevice(iedName, ldInst, enumValues); } } @@ -69,19 +64,18 @@ public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasL * @param ldInst LDevice inst value * @param enumValues enum values */ - private void isAuthorizedToActivateLDevice(String iedName, String ldInst, Set enumValues) { + private void checkAuthorisationToActivateLDevice(String iedName, String ldInst, Set enumValues) { if (!enumValues.contains(STValEnum.OFF.value) && enumValues.contains(STValEnum.ON.value)) { - if (isAuthorized(iedName, ldInst)) { + if (isDeclaredInSubstation(iedName, ldInst)) { isUpdatable = true; newVal = STValEnum.ON.value; } else { - errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be set to 'off' but has not been selected into SSD: this case should not occur.", - iedName, ldInst)); + errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD."; } } if (enumValues.contains(STValEnum.ON.value) && enumValues.contains(STValEnum.OFF.value)) { isUpdatable = true; - if (isAuthorized(iedName, ldInst)) { + if (isDeclaredInSubstation(iedName, ldInst)) { newVal = STValEnum.ON.value; } else { newVal = STValEnum.OFF.value; @@ -96,20 +90,17 @@ private void isAuthorizedToActivateLDevice(String iedName, String ldInst, Set enumValues) { + private void checkAuthorisationToDeactivateLDevice(String iedName, String ldInst, Set enumValues) { if (!enumValues.contains(STValEnum.OFF.value) && enumValues.contains(STValEnum.ON.value)) { - if (isAuthorized(iedName, ldInst)) { - errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s is not qualified into STD but has been selected into SSD: this case should not occur.", - iedName, ldInst)); + if (isDeclaredInSubstation(iedName, ldInst)) { + errorMessage = "The LDevice is not qualified into STD but has been selected into SSD."; } else { - errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be set to 'off' but has not been selected into SSD: this case should not occur.", - iedName, ldInst)); + errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD."; } } if (enumValues.contains(STValEnum.ON.value) && enumValues.contains(STValEnum.OFF.value)) { - if (isAuthorized(iedName, ldInst)) { - errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s is not qualified into STD but has been selected into SSD: this case should not occur.", - iedName, ldInst)); + if (isDeclaredInSubstation(iedName, ldInst)) { + errorMessage = "The LDevice is not qualified into STD but has been selected into SSD."; } else { isUpdatable = true; newVal = STValEnum.OFF.value; @@ -123,7 +114,7 @@ private void isAuthorizedToDeactivateLDevice(String iedName, String ldInst, Set< * @param ldInst LDevice inst value * @return Returns whether a pair of IED name and LDevice inst are referenced in Substation...LNode list */ - private boolean isAuthorized(String iedName, String ldInst){ + private boolean isDeclaredInSubstation(String iedName, String ldInst){ return iedNameLdInstList.contains(Pair.of(iedName, ldInst)); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java index 597ba0d25..1c8f4246f 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java @@ -689,7 +689,7 @@ public static void removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(final S public static SclReport updateLDeviceStatus(SCL scd) { SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); SubstationAdapter substationAdapter = sclRootAdapter.getSubstationAdapter(); - final List> iedNameLdInstList = substationAdapter.getLDevicesFromLNode(true); + final List> iedNameLdInstList = substationAdapter.getIedAndLDeviceNamesForLN0FromLNode(); List errors = sclRootAdapter.getIEDAdapters().stream() .map(IEDAdapter::getLDeviceAdapters) .flatMap(Collection::stream) @@ -701,7 +701,7 @@ public static SclReport updateLDeviceStatus(SCL scd) { }); SclReport sclReport = new SclReport(); sclReport.getErrorDescriptionList().addAll(errors); - sclReport.setScdFile(sclRootAdapter); + sclReport.setSclRootAdapter(sclRootAdapter); return sclReport; } } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapter.java index 32c02403f..67428e237 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapter.java @@ -399,7 +399,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("BDA[name=%s]", + return String.format("BDA[%s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null)); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapter.java index 75fbb6445..131781765 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapter.java @@ -56,7 +56,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("DO[name=%s and type=%s]", + return String.format("DO[%s and %s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null), Utils.xpathAttributeFilter("type", currentElem.isSetType() ? currentElem.getType() : null)); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java index 92d2878c8..c10bb1a26 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java @@ -74,7 +74,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("LNodeType[id=%s and lnClass=%s]", + return String.format("LNodeType[%s and %s]", Utils.xpathAttributeFilter("id", currentElem.isSetId() ? currentElem.getId() : null), Utils.xpathAttributeFilter("lnClass", currentElem.isSetLnClass() ? currentElem.getLnClass() : null)); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java index c22ffa730..1138fa98e 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java @@ -96,13 +96,13 @@ public static LNAdapterBuilder builder(){ * @param enumType enum Type * @return Enum value list */ - public Set getEnumValue(String enumType) { + public Set getEnumValues(String enumType) { Optional enumTypeAdapter = parentAdapter .getParentAdapter().getParentAdapter().getDataTypeTemplateAdapter() .getEnumTypeAdapterById(enumType); if(enumTypeAdapter.isEmpty()){ - return new HashSet<>(); + return Collections.emptySet(); } return enumTypeAdapter.get().getCurrentElem().getEnumVal() .stream().map(TEnumVal::getValue) diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java index 35a546c09..ecd34e231 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java @@ -59,7 +59,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("DOI[name=%s]", + return String.format("DOI[%s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null)); } @@ -170,7 +170,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("DAI[name=%s]", + return String.format("DAI[%s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null)); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java index 729685594..92deae202 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java @@ -16,7 +16,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; + +import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; /** * A representation of the model object @@ -88,7 +89,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("LN[lnClass=LLN0 and %s and %s]", + return String.format("LN[lnClass=\"LLN0\" and %s and %s]", Utils.xpathAttributeFilter("inst", currentElem.isSetInst() ? currentElem.getInst() : null), Utils.xpathAttributeFilter("lnType", currentElem.isSetLnType() ? currentElem.getLnType() : null)); } @@ -176,44 +177,33 @@ public List checkAndUpdateLDeviceStatus(List daiBehList = getDAI(daiBehFilter, false); if (daiBehList.isEmpty()) { - buildErrorMessage(errors, getXPath(), - "The IED@%s/LDevice@%s doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'", - iedName, ldInst); + errors.add(buildErrorDescriptionMessage("The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'")); return errors; } - Set enumValues = getEnumValue(daiBehList.get(0).getDaName().getType()); + Set enumValues = getEnumValues(daiBehList.get(0).getDaName().getType()); List compasLDevicePrivateList = PrivateService.getCompasPrivates(getParentAdapter().getCurrentElem(), TCompasLDevice.class); if (compasLDevicePrivateList.isEmpty()) { - buildErrorMessage(errors, getXPath(), - "The IED@%s/LDevice@%s doesn't have a Private compas:LDevice.", - iedName, ldInst); + errors.add(buildErrorDescriptionMessage("The LDevice doesn't have a Private compas:LDevice.")); return errors; } if (!compasLDevicePrivateList.get(0).isSetLDeviceStatus()) { - buildErrorMessage(errors, getXPath(), - "The IED@%s/LDevice@%s Private compas:LDevice doesn't have the attribute 'LDeviceStatus'", - iedName, ldInst); + errors.add(buildErrorDescriptionMessage("The Private compas:LDevice doesn't have the attribute 'LDeviceStatus'")); return errors; } TCompasLDeviceStatus compasLDeviceStatus = compasLDevicePrivateList.get(0).getLDeviceStatus(); DaTypeName daTypeNameMod = new DaTypeName(); - daTypeNameMod.setName(targetDaName); - ResumedDataTemplate daiModFilter = getResumedDataTemplate(targetDoName, daTypeNameMod); + daTypeNameMod.setName(STVAL); + ResumedDataTemplate daiModFilter = getResumedDataTemplate(MOD_DO_NAME, daTypeNameMod); List daiModList = getDAI(daiModFilter, false); if (daiModList.isEmpty()) { - buildErrorMessage(errors, getXPath(), - "The IED@%s/LDevice@%s doesn't have a DO @name='Mod'", - iedName, ldInst); + errors.add(buildErrorDescriptionMessage("The LDevice doesn't have a DO @name='Mod'")); return errors; } ResumedDataTemplate newDaModToSetInLN0 = daiModList.get(0); @@ -221,36 +211,23 @@ public List checkAndUpdateLDeviceStatus(List errorDescriptionList = lDeviceActivation.getErrorMessages() - .stream() - .map(errorMessage -> SclReport.ErrorDescription.builder() - .xpath(getXPath()) - .message(errorMessage) - .build()) - .collect(Collectors.toList()); - errors.addAll(errorDescriptionList); + if(lDeviceActivation.getErrorMessage() != null) { + errors.add(buildErrorDescriptionMessage(lDeviceActivation.getErrorMessage()));} } return errors; } /** - * Update ErrorDescription list of SclReport object with given xpath and message - * @param errors input parameter - * @param xpath input parameter - * @param message input parameter - * @param iedName input parameter - * @param ldInst input parameter + * builds message with message content and xpath + * @param message message to return + * @return error description with message and xpath as SclReport.ErrorDescription object */ - private void buildErrorMessage(List errors, String xpath, String message, String iedName, String ldInst) { - String msg = String.format(message, iedName, ldInst); - errors.add(SclReport.ErrorDescription.builder() - .message(msg) - .xpath(xpath) - .build()); + private SclReport.ErrorDescription buildErrorDescriptionMessage(String message){ + return SclReport.ErrorDescription.builder().message(message).xpath(getXPath()).build(); } } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapter.java index 3e7282e4b..b6fbe737d 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapter.java @@ -55,7 +55,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("SDI[name=%s]", + return String.format("SDI[%s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null)); } @@ -162,7 +162,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("DAI[name=%s]", + return String.format("DAI[%s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null)); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapter.java index 1194680a1..5c861dd12 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapter.java @@ -60,7 +60,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("SDI[name=%s]", + return String.format("SDI[%s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null)); } @@ -171,7 +171,7 @@ protected boolean amChildElementRef() { @Override protected String elementXPath() { - return String.format("DAI[name=%s]", + return String.format("DAI[%s]", Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null)); } } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapter.java index a3ee0b701..02d9ce17c 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapter.java @@ -120,16 +120,15 @@ public Stream streamVoltageLevelAdapters() { } /** - * Gets a pair of IedName and LDevice inst from Substation LNodes for given LN type object - * @param isLN0 filter for LN type + * Gets a pair of IedName and LDevice inst from Substation LNodes for LN0 type object * @return a pair of Ied name and LDevice inst attributes */ - public List> getLDevicesFromLNode(boolean isLN0) { + public List> getIedAndLDeviceNamesForLN0FromLNode() { return streamVoltageLevelAdapters() .flatMap(VoltageLevelAdapter::streamBayAdapters) .flatMap(BayAdapter::streamFunctionAdapters) .flatMap(functionAdapter -> functionAdapter.getCurrentElem().getLNode().stream()) - .filter(tlNode -> !isLN0 || tlNode.getLnClass().contains(TLLN0Enum.LLN_0.value())) + .filter(tlNode -> tlNode.getLnClass().contains(TLLN0Enum.LLN_0.value())) .map(tlNode -> Pair.of(tlNode.getIedName(), tlNode.getLdInst())) .collect(Collectors.toList()); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/CommonConstants.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/CommonConstants.java index f44b632de..fb9f7ee03 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/CommonConstants.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/CommonConstants.java @@ -15,6 +15,9 @@ public final class CommonConstants { public static final String HEADER_ID = "headerId"; public static final String HEADER_VERSION = "headerVersion"; public static final String HEADER_REVISION = "headerRevision"; + public static String BEHAVIOUR_DO_NAME = "Beh"; + public static String MOD_DO_NAME = "Mod"; + public static String STVAL = "stVal"; /** * Private Controlller, should not be instanced diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivationTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivationTest.java index d3c7f5aa7..c553282be 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivationTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivationTest.java @@ -7,6 +7,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; import org.lfenergy.compas.scl2007b4.model.TCompasLDeviceStatus; @@ -19,7 +20,7 @@ class LDeviceActivationTest { @ParameterizedTest @ValueSource(strings = {"ACTIVE", "UNTESTED"}) - void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_ValidEnum_And_LDeviceReferencedINLNode(String lDeviceStatus) { + void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_Contains_ON_And_LDeviceReferencedINLNode(String lDeviceStatus) { // Given List> iedNameLdInstList = List.of(Pair.of("iedName1", "ldInst1")); LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); @@ -28,13 +29,28 @@ void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_O lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.fromValue(lDeviceStatus), Set.of("on")); // Then assertThat(lDeviceActivation.isUpdatable()).isTrue(); - assertThat(lDeviceActivation.getErrorMessages()).isEmpty(); - assertThat(lDeviceActivation.getNewVal()).hasToString("on"); + assertThat(lDeviceActivation.getErrorMessage()).isNull(); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("on"); } @ParameterizedTest @ValueSource(strings = {"ACTIVE", "UNTESTED"}) - void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_NoValidEnum_And_LDeviceReferencedINLNode(String lDeviceStatus) { + void checkLDeviceActivationStatus_shouldReturnError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_Contains_ON_And_NotLDeviceReferencedINLNode(String lDeviceStatus) { + // Given + List> iedNameLdInstList = List.of(); + LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); + lDeviceActivation.setNewVal("on"); + // When + lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst2", TCompasLDeviceStatus.valueOf(lDeviceStatus), Set.of("on")); + // Then + assertThat(lDeviceActivation.isUpdatable()).isFalse(); + assertThat(lDeviceActivation.getErrorMessage()).isEqualTo("The LDevice cannot be set to 'off' but has not been selected into SSD."); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("on"); + } + + @ParameterizedTest + @ValueSource(strings = {"ACTIVE", "UNTESTED"}) + void checkLDeviceActivationStatus_shouldReturnError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_Contains_OFF_And_LDeviceReferencedINLNode(String lDeviceStatus) { // Given List> iedNameLdInstList = List.of(Pair.of("iedName1", "ldInst1")); LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); @@ -43,14 +59,44 @@ void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_O lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.valueOf(lDeviceStatus), Set.of("off")); // Then assertThat(lDeviceActivation.isUpdatable()).isFalse(); - assertThat(lDeviceActivation.getErrorMessages()).containsExactly( - "Unexpected error: The IED@iedName1/LDevice@ldInst1 cannot be set to 'on' but has been selected into SSD: this case should not occur."); - assertThat(lDeviceActivation.getNewVal()).hasToString("off"); + assertThat(lDeviceActivation.getErrorMessage()).isEqualTo( + "The LDevice cannot be set to 'on' but has been selected into SSD."); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); } @ParameterizedTest @ValueSource(strings = {"ACTIVE", "UNTESTED"}) - void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_ValidEnum_And_NotLDeviceReferencedINLNode(String lDeviceStatus) { + void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_Contains_OFF_And_NotLDeviceReferencedINLNode(String lDeviceStatus) { + // Given + List> iedNameLdInstList = List.of(); + LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); + lDeviceActivation.setNewVal("on"); + // When + lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.valueOf(lDeviceStatus), Set.of("off")); + // Then + assertThat(lDeviceActivation.isUpdatable()).isTrue(); + assertThat(lDeviceActivation.getErrorMessage()).isNull(); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); + } + + @ParameterizedTest + @ValueSource(strings = {"ACTIVE", "UNTESTED"}) + void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_Contains_ON_And_OFF_And_LDeviceReferencedINLNode(String lDeviceStatus) { + // Given + List> iedNameLdInstList = List.of(Pair.of("iedName1", "ldInst1")); + LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); + lDeviceActivation.setNewVal("off"); + // When + lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.valueOf(lDeviceStatus), Set.of("on", "off")); + // Then + assertThat(lDeviceActivation.isUpdatable()).isTrue(); + assertThat(lDeviceActivation.getErrorMessage()).isNull(); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("on"); + } + + @ParameterizedTest + @ValueSource(strings = {"ACTIVE", "UNTESTED"}) + void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_Or_UNTESTED_And_Contains_ON_And_OFF_And_NotLDeviceReferencedINLNode(String lDeviceStatus) { // Given List> iedNameLdInstList = List.of(); LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); @@ -59,13 +105,42 @@ void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusACTIVE_O lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst2", TCompasLDeviceStatus.valueOf(lDeviceStatus), Set.of("on", "off")); // Then assertThat(lDeviceActivation.isUpdatable()).isTrue(); - assertThat(lDeviceActivation.getErrorMessages()).isEmpty(); - assertThat(lDeviceActivation.getNewVal()).hasToString("off"); + assertThat(lDeviceActivation.getErrorMessage()).isNull(); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); } + @ParameterizedTest + @CsvSource(value = {"ACTIVE; iedName1; ldInst1","INACTIVE; iedName1; ldInst1", "UNTESTED; iedName1; ldInst1", "ACTIVE;;","INACTIVE;;", "UNTESTED;;"}, delimiter = ';') + void checkLDeviceActivationStatus_shouldReturnError_when_Contains_Not_ON_Nor_OFF(String lDeviceStatus, String iedName, String ldInst) { + // Given + List> iedNameLdInstList = List.of(Pair.of(iedName, ldInst)); + LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); + lDeviceActivation.setNewVal("off"); + // When + lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.valueOf(lDeviceStatus), Set.of()); + // Then + assertThat(lDeviceActivation.isUpdatable()).isFalse(); + assertThat(lDeviceActivation.getErrorMessage()).isEqualTo( + "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'."); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); + } + + @Test + void checkLDeviceActivationStatus_shouldReturnError_when_LDeviceStatusINACTIVE_And_Contains_ON_And_LDeviceReferencedINLNode() { + // Given + List> iedNameLdInstList = List.of(Pair.of("iedName1", "ldInst1")); + LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); + lDeviceActivation.setNewVal("on"); + // When + lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.INACTIVE, Set.of("on")); + // Then + assertThat(lDeviceActivation.isUpdatable()).isFalse(); + assertThat(lDeviceActivation.getErrorMessage()).isEqualTo("The LDevice is not qualified into STD but has been selected into SSD."); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("on"); + } @Test - void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusINACTIVE_And_ValidEnum_And_NotLDeviceReferencedINLNode() { + void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusINACTIVE_And_Contains_ON_And_OFF_And_NotLDeviceReferencedINLNode() { // Given List> iedNameLdInstList = List.of(); LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); @@ -74,11 +149,40 @@ void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusINACTIVE lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.INACTIVE, Set.of("on", "off")); // Then assertThat(lDeviceActivation.isUpdatable()).isTrue(); - assertThat(lDeviceActivation.getErrorMessages()).isEmpty(); - assertThat(lDeviceActivation.getNewVal()).hasToString("off"); + assertThat(lDeviceActivation.getErrorMessage()).isNull(); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); + } + + @Test + void checkLDeviceActivationStatus_shouldReturnError_when_LDeviceStatusINACTIVE_And_Contains_ON_And_NotLDeviceReferencedINLNode() { + // Given + List> iedNameLdInstList = List.of(); + LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); + lDeviceActivation.setNewVal("on"); + // When + lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.INACTIVE, Set.of("on")); + // Then + assertThat(lDeviceActivation.isUpdatable()).isFalse(); + assertThat(lDeviceActivation.getErrorMessage()).isEqualTo("The LDevice cannot be set to 'off' but has not been selected into SSD."); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("on"); + } + + @Test + void checkLDeviceActivationStatus_shouldReturnNoError_when_LDeviceStatusINACTIVE_And_Contains_OFF_And_NotLDeviceReferencedINLNode() { + // Given + List> iedNameLdInstList = List.of(); + LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); + lDeviceActivation.setNewVal("on"); + // When + lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.INACTIVE, Set.of("off")); + // Then + assertThat(lDeviceActivation.isUpdatable()).isTrue(); + assertThat(lDeviceActivation.getErrorMessage()).isNull(); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); } + @Test - void checkLDeviceActivationStatus_shouldReturnError_when_LDeviceStatusINACTIVE_And_ValidEnum_And_LDeviceReferencedINLNode() { + void checkLDeviceActivationStatus_shouldReturnError_when_LDeviceStatusINACTIVE_And_Contains_ON_And_OFF_And_LDeviceReferencedINLNode() { // Given List> iedNameLdInstList = List.of(Pair.of("iedName1", "ldInst1")); LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLdInstList); @@ -87,9 +191,9 @@ void checkLDeviceActivationStatus_shouldReturnError_when_LDeviceStatusINACTIVE_A lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", TCompasLDeviceStatus.INACTIVE, Set.of("on", "off")); // Then assertThat(lDeviceActivation.isUpdatable()).isFalse(); - assertThat(lDeviceActivation.getErrorMessages()).containsExactly( - "Unexpected error: The IED@iedName1/LDevice@ldInst1 is not qualified into STD but has been selected into SSD: this case should not occur."); - assertThat(lDeviceActivation.getNewVal()).hasToString("off"); + assertThat(lDeviceActivation.getErrorMessage()).isEqualTo( + "The LDevice is not qualified into STD but has been selected into SSD."); + assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java index 6acba5073..2f2d7d137 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclServiceTest.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.DynamicTest.dynamicTest; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.createDa; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.createDo; import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; @@ -712,14 +711,14 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingDOBeh() throws E String before = createWrapper().marshall(scl); // When SclReport sclReport = SclService.updateLDeviceStatus(scl); - String after = createWrapper().marshall(sclReport.getScdFile().getCurrentElem()); // Then + String after = createWrapper().marshall(sclReport.getSclRootAdapter().getCurrentElem()); assertFalse(sclReport.isSuccess()); assertThat(sclReport.getErrorDescriptionList()) .hasSize(1) .extracting(SclReport.ErrorDescription::getMessage) .containsExactly( - "The IED@IedName1/LDevice@LDSUIED doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'"); + "The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'"); assertEquals(before, after); } @Test @@ -735,10 +734,10 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingLDevicePrivate() assertThat(sclReport.getErrorDescriptionList()) .hasSize(1) .containsExactly(SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType1\"]") - .message("The IED@IedName1/LDevice@LDSUIED doesn't have a Private compas:LDevice.") + .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]") + .message("The LDevice doesn't have a Private compas:LDevice.") .build()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); } @Test @@ -754,10 +753,10 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingLDevicePrivateAt assertThat(sclReport.getErrorDescriptionList()) .hasSize(1) .containsExactly(SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType1\"]") - .message("The IED@IedName1/LDevice@LDSUIED Private compas:LDevice doesn't have the attribute 'LDeviceStatus'") + .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]") + .message("The Private compas:LDevice doesn't have the attribute 'LDeviceStatus'") .build()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); } @Test @@ -773,10 +772,10 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingDOMod() throws E assertThat(sclReport.getErrorDescriptionList()) .hasSize(1) .containsExactly(SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType1\"]") - .message("The IED@IedName1/LDevice@LDSUIED doesn't have a DO @name='Mod'") + .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]") + .message("The LDevice doesn't have a DO @name='Mod'") .build()); - assertEquals( "off",getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertEquals( "off",getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); } @Test @@ -793,19 +792,19 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceActive() thro assertThat(sclReport.getErrorDescriptionList()) .hasSize(3) .contains(SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType1\"]") - .message("Unexpected error: The IED@IedName1/LDevice@LDSUIED cannot be set to 'off' but has not been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]") + .message("The LDevice cannot be set to 'off' but has not been selected into SSD.") .build(), SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType2\"]") - .message("Unexpected error: The IED@IedName2/LDevice@LDSUIED cannot be set to 'on' but has been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]") + .message("The LDevice cannot be set to 'on' but has been selected into SSD.") .build(), SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType3\"]") - .message("Unexpected error: The IED@IedName3/LDevice@LDSUIED cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.") + .xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]") + .message("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.") .build()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); - assertEquals("on", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent()); } @@ -824,19 +823,19 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceUntested() th assertThat(sclReport.getErrorDescriptionList()) .hasSize(3) .contains(SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType1\"]") - .message("Unexpected error: The IED@IedName1/LDevice@LDSUIED cannot be set to 'off' but has not been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]") + .message("The LDevice cannot be set to 'off' but has not been selected into SSD.") .build(), SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType2\"]") - .message("Unexpected error: The IED@IedName2/LDevice@LDSUIED cannot be set to 'on' but has been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]") + .message("The LDevice cannot be set to 'on' but has been selected into SSD.") .build(), SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType3\"]") - .message("Unexpected error: The IED@IedName3/LDevice@LDSUIED cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.") + .xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]") + .message("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.") .build()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); - assertEquals("on", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent()); } @@ -854,19 +853,19 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceInactive_Test assertThat(sclReport.getErrorDescriptionList()) .hasSize(3) .contains(SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType1\"]") - .message("Unexpected error: The IED@IedName1/LDevice@LDSUIED is not qualified into STD but has been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]") + .message("The LDevice is not qualified into STD but has been selected into SSD.") .build(), SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType2\"]") - .message("Unexpected error: The IED@IedName2/LDevice@LDSUIED cannot be set to 'on' but has been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]") + .message("The LDevice cannot be set to 'on' but has been selected into SSD.") .build(), SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType3\"]") - .message("Unexpected error: The IED@IedName3/LDevice@LDSUIED cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.") + .xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]") + .message("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.") .build()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); - assertEquals("on", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent()); } @@ -884,15 +883,15 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceInactive_Test assertThat(sclReport.getErrorDescriptionList()) .hasSize(2) .contains(SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType1\"]") - .message("Unexpected error: The IED@IedName1/LDevice@LDSUIED cannot be set to 'off' but has not been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]") + .message("The LDevice cannot be set to 'off' but has not been selected into SSD.") .build(), SclReport.ErrorDescription.builder() - .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=LLN0 and @inst=\"\" and @lnType=\"LNType2\"]") - .message("Unexpected error: The IED@IedName2/LDevice@LDSUIED is not qualified into STD but has been selected into SSD: this case should not occur.") + .xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]") + .message("The LDevice is not qualified into STD but has been selected into SSD.") .build()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); - assertEquals("on", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); assertTrue(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent()); assertEquals("off", getLDeviceStatusValue(scl, "IedName3", "LDSUIED").get().getValue()); } @@ -914,14 +913,14 @@ void updateLDeviceStatus_shouldReturnUpdatedFile() throws Exception { SclReport sclReport = SclService.updateLDeviceStatus(givenScl); // Then assertTrue(sclReport.isSuccess()); - assertTrue(getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").isPresent()); - assertEquals("on", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); + assertTrue(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").isPresent()); + assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue()); - assertTrue(getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName2", "LDSUIED").isPresent()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); + assertTrue(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").isPresent()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue()); - assertTrue(getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName3", "LDSUIED").isPresent()); - assertEquals("off", getLDeviceStatusValue(sclReport.getScdFile().getCurrentElem(), "IedName3", "LDSUIED").get().getValue()); + assertTrue(getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName3", "LDSUIED").isPresent()); + assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName3", "LDSUIED").get().getValue()); } @Test @@ -936,7 +935,7 @@ void updateLDeviceStatus_shouldReturnError_when_DaiNotUpdatable() throws Excepti // When // Then - assertThatCode(() -> SclService.updateLDeviceStatus(givenScl)) + assertThatCode(() -> SclService.updateLDeviceStatus(givenScl)) .isInstanceOf(ScdException.class) .hasMessage("DAI (Mod -stVal) cannot be updated"); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SubstationServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SubstationServiceTest.java index 17c045dad..16d46ef35 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SubstationServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SubstationServiceTest.java @@ -4,15 +4,12 @@ package org.lfenergy.compas.sct.commons.scl; -import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.SCL; import org.lfenergy.compas.scl2007b4.model.TSubstation; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; -import java.util.List; - import static org.junit.jupiter.api.Assertions.*; import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapterTest.java index cb292b9fe..c868c8a82 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapterTest.java @@ -6,6 +6,8 @@ import org.junit.jupiter.api.BeforeEach; 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.SCL; import org.lfenergy.compas.scl2007b4.model.TConnectedAP; import org.lfenergy.compas.scl2007b4.model.TPrivate; @@ -90,20 +92,19 @@ void testCopyAddressAndPhysConnFromIcd_withEmptyIcd() { assertThat(connectedAPAdapter.getCurrentElem().getGSE()).isEmpty(); } - @Test - void elementXPath() { + @ParameterizedTest + @CsvSource(value = {"IED_NAME;AP_NAME;ConnectedAP[@apName=\"IED_NAME\" and @iedName=\"IED_NAME\"]", ";;ConnectedAP[not(@apName) and not(@iedName)]"} + , delimiter = ';') + void elementXPath(String iedName, String apName, String message) { // Given TConnectedAP tConnectedAP = new TConnectedAP(); - tConnectedAP.setApName(DTO.HOLDER_IED_NAME); - tConnectedAP.setIedName(DTO.AP_NAME); - ConnectedAPAdapter connectedAPAdapter = new ConnectedAPAdapter(null, new TConnectedAP()); - ConnectedAPAdapter namedConnectedAPAdapter = new ConnectedAPAdapter(null, tConnectedAP); + tConnectedAP.setApName(iedName); + tConnectedAP.setIedName(apName); + ConnectedAPAdapter connectedAPAdapter = new ConnectedAPAdapter(null, tConnectedAP); // When String elementXPath = connectedAPAdapter.elementXPath(); - String namedElementXPath = namedConnectedAPAdapter.elementXPath(); // Then - assertThat(elementXPath).isEqualTo("ConnectedAP[not(@apName) and not(@iedName)]"); - assertThat(namedElementXPath).isEqualTo("ConnectedAP[@apName=\"IED_NAME\" and @iedName=\"IED_NAME\"]"); + assertThat(elementXPath).isEqualTo(message); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java index 198ee6df1..494968162 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java @@ -5,6 +5,8 @@ package org.lfenergy.compas.sct.commons.scl.com; 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.TCommunication; import org.lfenergy.compas.scl2007b4.model.TConnectedAP; import org.lfenergy.compas.scl2007b4.model.TPrivate; @@ -76,20 +78,20 @@ void addPrivate() { assertEquals(1, subNetworkAdapter.getCurrentElem().getPrivate().size()); } - @Test - void elementXPath() { + @ParameterizedTest + @CsvSource(value = {"sName;sType;SubNetwork[@name=\"sName\"]", ";;SubNetwork[not(@name)]"} + , delimiter = ';') + void elementXPath(String sName, String sType, String message) { // Given TSubNetwork tSubNetwork = new TSubNetwork(); - tSubNetwork.setName("sName"); - tSubNetwork.setType("sType"); - SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); - SubNetworkAdapter namedSubNetworkAdapter = new SubNetworkAdapter(null, tSubNetwork); + tSubNetwork.setName(sName); + tSubNetwork.setType(sType); + SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, tSubNetwork); // When String elementXPath = subNetworkAdapter.elementXPath(); - String namedElementXPath = namedSubNetworkAdapter.elementXPath(); // Then - assertThat(elementXPath).isEqualTo("SubNetwork[not(@name)]"); - assertThat(namedElementXPath).isEqualTo("SubNetwork[@name=\"sName\"]"); + assertThat(elementXPath).isEqualTo(message); + } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java index 3a26b19ca..8533444d2 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java @@ -112,7 +112,7 @@ void elementXPath() { // When String result = bdaAdapter.elementXPath(); // Then - assertThat(result).isEqualTo("BDA[name=not(@name)]"); + assertThat(result).isEqualTo("BDA[not(@name)]"); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java index ddf07d47a..95fa8014a 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java @@ -30,6 +30,6 @@ void elementXPath() { // When String result = doAdapter.elementXPath(); // Then - assertThat(result).isEqualTo("DO[name=@name=\"doName\" and type=not(@type)]"); + assertThat(result).isEqualTo("DO[@name=\"doName\" and not(@type)]"); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java index f5408bb63..09a305bed 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java @@ -207,6 +207,6 @@ void elementXPath() throws Exception { // When String result = lNodeTypeAdapter.elementXPath(); // Then - assertThat(result).isEqualTo("LNodeType[id=@id=\"LN1\" and lnClass=@lnClass=\"PIOC\"]"); + assertThat(result).isEqualTo("LNodeType[@id=\"LN1\" and @lnClass=\"PIOC\"]"); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java index 232032197..8079a0f28 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Assertions; 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.THeader; import org.lfenergy.compas.scl2007b4.model.THitem; import org.lfenergy.compas.scl2007b4.model.TPrivate; @@ -70,21 +72,20 @@ void addPrivate() { assertThrows(UnsupportedOperationException.class, () -> hAdapter.addPrivate(tPrivate)); } - @Test - void elementXPath() { + @ParameterizedTest + @CsvSource(value = {"hID;hVersion;hRevision;Header[@id=\"hID\" and @version=\"hVersion\" and @revision=\"hRevision\"]", ";;;Header[not(@id) and not(@version) and not(@revision)]"} + , delimiter = ';') + void elementXPath(String hID, String hVersion, String hRevision,String message) { // Given THeader tHeader = new THeader(); - tHeader.setId("hID"); - tHeader.setVersion("hVersion"); - tHeader.setRevision("hRevision"); - HeaderAdapter headerAdapter = new HeaderAdapter(null, new THeader()); - HeaderAdapter namedHeaderAdapter = new HeaderAdapter(null, tHeader); + tHeader.setId(hID); + tHeader.setVersion(hVersion); + tHeader.setRevision(hRevision); + HeaderAdapter headerAdapter = new HeaderAdapter(null, tHeader); // When String elementXPathResult = headerAdapter.elementXPath(); - String namedElementXPathResult = namedHeaderAdapter.elementXPath(); // Then - assertThat(elementXPathResult).isEqualTo("Header[not(@id) and not(@version) and not(@revision)]"); - assertThat(namedElementXPathResult).isEqualTo("Header[@id=\"hID\" and @version=\"hVersion\" and @revision=\"hRevision\"]"); + assertThat(elementXPathResult).isEqualTo(message); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java index 7bd23c7bc..4c6d9a30f 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java @@ -169,8 +169,8 @@ void elementXPath_doi() { String elementXPathResult = doiAdapter.elementXPath(); String namedElementXPathResult = namedDoiAdapter.elementXPath(); // Then - assertThat(elementXPathResult).isEqualTo("DOI[name=not(@name)]"); - assertThat(namedElementXPathResult).isEqualTo("DOI[name=@name=\"doName\"]"); + assertThat(elementXPathResult).isEqualTo("DOI[not(@name)]"); + assertThat(namedElementXPathResult).isEqualTo("DOI[@name=\"doName\"]"); } @Test @@ -180,7 +180,7 @@ void elementXPath_dai() { // When String result = daiAdapter.elementXPath(); // Then - assertThat(result).isEqualTo("DAI[name=@name=\"da\"]"); + assertThat(result).isEqualTo("DAI[@name=\"da\"]"); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java index 7f3e325f6..4c5f893cb 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java @@ -6,6 +6,8 @@ import org.junit.jupiter.api.BeforeEach; 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.SCL; import org.lfenergy.compas.scl2007b4.model.TLDevice; import org.lfenergy.compas.scl2007b4.model.TLLN0Enum; @@ -103,18 +105,18 @@ void addPrivate() { assertEquals(1, lDeviceAdapter.getCurrentElem().getPrivate().size()); } - @Test - void elementXPath() { + @ParameterizedTest + @CsvSource(value = {"ldInst;LDevice[@inst=\"ldInst\"]", ";LDevice[not(@inst)]"} + , delimiter = ';') + void elementXPath(String ldInst, String message) { // Given TLDevice tlDevice = new TLDevice(); - tlDevice.setInst("ldInst"); - LDeviceAdapter lDeviceAdapter = new LDeviceAdapter(null, new TLDevice()); - LDeviceAdapter namedLDeviceAdapter = new LDeviceAdapter(null, tlDevice); + tlDevice.setInst(ldInst); + LDeviceAdapter lDeviceAdapter = new LDeviceAdapter(null, tlDevice); // When String elementXPathResult = lDeviceAdapter.elementXPath(); - String namedElementXPathResult = namedLDeviceAdapter.elementXPath(); // Then - assertThat(elementXPathResult).isEqualTo("LDevice[not(@inst)]"); - assertThat(namedElementXPathResult).isEqualTo("LDevice[@inst=\"ldInst\"]"); + assertThat(elementXPathResult).isEqualTo(message); + } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java index ebfc629e6..b0387c69c 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java @@ -331,6 +331,7 @@ void addPrivate() { @Test void testGetDAI() throws Exception { + //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); @@ -347,14 +348,18 @@ void testGetDAI() throws Exception { daTypeName.setBType(TPredefinedBasicTypeEnum.ENUM); daTypeName.setFc(TFCEnum.ST); filter.setDaName(daTypeName); + //When var rDtts = ln0Adapter.getDAI(filter,false); + //Then assertFalse(rDtts.isEmpty()); assertEquals(1,rDtts.size()); assertNotNull(rDtts.get(0).getDaName().getType()); + assertEquals("BehaviourModeKind", rDtts.get(0).getDaName().getType()); } @Test void getEnumValue() throws Exception { + //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); @@ -372,8 +377,11 @@ void getEnumValue() throws Exception { daTypeName.setFc(TFCEnum.ST); daTypeName.setType("BehaviourModeKind"); filter.setDaName(daTypeName); - Set enumValues = ln0Adapter.getEnumValue(filter.getType()); + //When + Set enumValues = ln0Adapter.getEnumValues(filter.getType()); + //Then assertEquals(5, enumValues.size()); + assertThat(enumValues).containsExactlyInAnyOrder("blocked", "test", "test/blocked", "off", "on"); } @Test @@ -385,6 +393,6 @@ void elementXPath() { // When String result = lnAdapter.elementXPath(); // Then - assertThat(result).isEqualTo("LN[lnClass=LLN0 and not(@inst) and not(@lnType)]"); + assertThat(result).isEqualTo("LN[lnClass=\"LLN0\" and not(@inst) and not(@lnType)]"); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java index 8411f2772..dd436deaa 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java @@ -80,7 +80,7 @@ void elementXPath_sdi() { // When String result = rootSDIAdapter.elementXPath(); // Then - assertThat(result).isEqualTo("SDI[name=@name=\"sdo1\"]"); + assertThat(result).isEqualTo("SDI[@name=\"sdo1\"]"); } @Test @@ -97,7 +97,7 @@ void elementXPath_dai() { // When String result = daiAdapter.elementXPath(); // Then - assertThat(result).isEqualTo("DAI[name=@name=\"angRef\"]"); + assertThat(result).isEqualTo("DAI[@name=\"angRef\"]"); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java index 4af7db7b1..adc454ae2 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java @@ -5,6 +5,8 @@ package org.lfenergy.compas.sct.commons.scl.ied; 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.TDAI; import org.lfenergy.compas.scl2007b4.model.TPrivate; import org.lfenergy.compas.scl2007b4.model.TSDI; @@ -73,19 +75,18 @@ void addPrivate() { assertEquals(1, sdiAdapter.getCurrentElem().getPrivate().size()); } - @Test - void elementXPath() { + @ParameterizedTest + @CsvSource(value = {"sdo1;SDI[@name=\"sdo1\"]", ";SDI[not(@name)]"} + , delimiter = ';') + void elementXPath(String sdo, String message) { // Given TSDI tsdi = new TSDI(); - tsdi.setName("sdo1"); - SDIAdapter sdiAdapter = new SDIAdapter(null,new TSDI()); - SDIAdapter namedSDIAdapter = new SDIAdapter(null,tsdi); + tsdi.setName(sdo); + SDIAdapter sdiAdapter = new SDIAdapter(null,tsdi); // When String sdiAdapterResult = sdiAdapter.elementXPath(); - String namedSdiAdapterResult = namedSDIAdapter.elementXPath(); // Then - assertThat(sdiAdapterResult).isEqualTo("SDI[name=not(@name)]"); - assertThat(namedSdiAdapterResult).isEqualTo("SDI[name=@name=\"sdo1\"]"); + assertThat(sdiAdapterResult).isEqualTo(message); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java index 12a088c25..0ea8e5143 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java @@ -17,6 +17,7 @@ import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; class SubstationAdapterTest { @@ -78,28 +79,18 @@ void addPrivate() { assertEquals(1, ssAdapter.getCurrentElem().getPrivate().size()); } - @Test - void getLDevicesFromLNode_test1_withoutLN0() throws Exception { - // Given - SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/scd-with-substation-lnode.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scl); - SubstationAdapter substationAdapter = sclRootAdapter.getSubstationAdapter(); - // When - List> iedNameLdInstList = substationAdapter.getLDevicesFromLNode(false); - // Then - assertEquals(2, iedNameLdInstList.size()); - } @Test - void getLDevicesFromLNode_test2_withLN0() throws Exception { + void getIedAndLDeviceNamesForLN0FromLNode_shouldReturnListOf1Pair_WhenLNodeContainsLN0() throws Exception { // Given SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_Template.scd"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scl); SubstationAdapter substationAdapter = sclRootAdapter.getSubstationAdapter(); // When - List> iedNameLdInstList = substationAdapter.getLDevicesFromLNode(true); + List> iedNameLdInstList = substationAdapter.getIedAndLDeviceNamesForLN0FromLNode(); // Then assertEquals(1, iedNameLdInstList.size()); + assertThat(iedNameLdInstList).containsExactly(Pair.of("IedName1", "LDSUIED")); } } \ No newline at end of file