diff --git a/pom.xml b/pom.xml
index 97a37d1d8..05b408939 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,7 @@
1.18.305.5.02.13.4.1
+ 1.9.4
@@ -111,6 +112,11 @@
compas-scl-xsd${compas-scl-xsd.version}
+
+ org.lfenergy.compas.core
+ commons
+ ${compas-core.version}
+ ch.qos.logbacklogback-classic
@@ -126,6 +132,11 @@
jackson-databind${jackson-databind.version}
+
+ commons-beanutils
+ commons-beanutils
+ ${commons-beanutils.version}
+
diff --git a/sct-app/pom.xml b/sct-app/pom.xml
index 2edf11adc..3e8c9df02 100644
--- a/sct-app/pom.xml
+++ b/sct-app/pom.xml
@@ -57,6 +57,10 @@
org.mockitomockito-junit-jupiter
+
+ commons-beanutils
+ commons-beanutils
+
diff --git a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java
index d33199d9b..6a3a6886e 100644
--- a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java
+++ b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java
@@ -35,7 +35,7 @@
class SclAutomationServiceTest {
@InjectMocks
- private SclAutomationService sclAutomationService ;
+ private SclAutomationService sclAutomationService;
@Mock
private SclEditor sclEditor;
@Mock
diff --git a/sct-commons/pom.xml b/sct-commons/pom.xml
index a7e978f7a..366670104 100644
--- a/sct-commons/pom.xml
+++ b/sct-commons/pom.xml
@@ -18,12 +18,15 @@
SCT-COMMONS
- 5.7.14.0.04.0.3
+
+ org.lfenergy.compas.core
+ commons
+ commons-iocommons-io
@@ -84,11 +87,6 @@
assertj-coretest
-
- com.opencsv
- opencsv
- ${opencsv.version}
-
@@ -234,6 +232,23 @@
false
+
+ da_cb_com
+
+ xjc
+
+
+
+ ${project.basedir}/src/main/resources/xsd/CB_COMM_V1.xsd
+
+
+ ${project.basedir}/src/main/resources/binding_configuration.xjb
+
+ org.lfenergy.compas.sct.commons.model.da_cb_com
+ true
+ false
+
+
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java
index 9f01aa8ec..ff7bd802e 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java
@@ -8,10 +8,10 @@
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.api.ControlBlockEditor;
-import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.model.cbcom.*;
+import org.lfenergy.compas.sct.commons.model.da_cb_com.FCDAs;
import org.lfenergy.compas.sct.commons.scl.ControlService;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
@@ -58,41 +58,11 @@ public List analyzeDataGroups(SCL scd) {
}
@Override
- public List createDataSetAndControlBlocks(SCL scd, Set allowedFcdas) {
- checkFcdaInitDataPresence(allowedFcdas);
+ public List createDataSetAndControlBlocks(SCL scd, FCDAs allowedFcdas) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
- Stream lDeviceAdapters = sclRootAdapter.streamIEDAdapters().flatMap(IEDAdapter::streamLDeviceAdapters);
- return createDataSetAndControlBlocks(lDeviceAdapters, allowedFcdas);
- }
-
- @Override
- public List createDataSetAndControlBlocks(SCL scd, String targetIedName, Set allowedFcdas) {
- checkFcdaInitDataPresence(allowedFcdas);
- SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
- IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(targetIedName);
- return createDataSetAndControlBlocks(iedAdapter.streamLDeviceAdapters(), allowedFcdas);
-
- }
-
- @Override
- public List createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, Set allowedFcdas) {
- requireNotBlank(targetIedName, "IED.name parameter is missing");
- checkFcdaInitDataPresence(allowedFcdas);
- SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
- IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(targetIedName);
- LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(targetLDeviceInst);
- return createDataSetAndControlBlocks(Stream.of(lDeviceAdapter), allowedFcdas);
- }
-
- private void checkFcdaInitDataPresence(Set allowedFcdas) {
- if (allowedFcdas == null || allowedFcdas.isEmpty()) {
- throw new ScdException("Accepted FCDAs list is empty, you should initialize allowed FCDA lists with CsvHelper class before");
- }
- }
-
- private List createDataSetAndControlBlocks(Stream lDeviceAdapters, Set allowedFcdas) {
- return lDeviceAdapters
- .map(lDeviceAdapter -> lDeviceAdapter.createDataSetAndControlBlocks(allowedFcdas))
+ return sclRootAdapter.streamIEDAdapters()
+ .flatMap(IEDAdapter::streamLDeviceAdapters)
+ .map(lDeviceAdapter -> lDeviceAdapter.createDataSetAndControlBlocks(allowedFcdas.getFCDA()))
.flatMap(List::stream)
.toList();
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ControlBlockEditor.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ControlBlockEditor.java
index 8235dd5ea..179b4d101 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ControlBlockEditor.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ControlBlockEditor.java
@@ -6,13 +6,12 @@
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
-import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.model.cbcom.CBCom;
+import org.lfenergy.compas.sct.commons.model.da_cb_com.FCDAs;
import org.lfenergy.compas.sct.commons.util.Utils;
import java.util.List;
-import java.util.Set;
/**
* Service class that will be used to create, update or delete elements related to the {@link TExtRef TExtRef} object.
@@ -20,9 +19,6 @@
*
*
ExtRef features
*
- *
{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, Set) Create DataSet and ControlBlock based on the TExtRef}
- *
{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, String, Set) Create DataSet and ControlBlock based on the TExtRef in given IED}
- *
{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, String, String, Set) Create DataSet and ControlBlock based on the TExtRef in given IED and LDevice}
*
{@link ControlBlockEditor#configureNetworkForAllControlBlocks Configure the network for the ControlBlocks}
*
{@link ControlBlockEditor#removeAllControlBlocksAndDatasetsAndExtRefSrcBindings Removes all ControlBlocks and DataSets for all LNs in SCL}
*
{@link ControlBlockEditor#analyzeDataGroups(SCL)} Checks Control Blocks, DataSets and FCDA number limitation into Access Points }
@@ -39,7 +35,6 @@ public interface ControlBlockEditor {
*/
void removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(final SCL scl);
-
/**
* Checks Control Blocks, DataSets and FCDA number limitation into Access Points
*
@@ -48,7 +43,6 @@ public interface ControlBlockEditor {
*/
List analyzeDataGroups(SCL scd);
-
/**
* Create All DataSet and ControlBlock in the SCL based on the ExtRef
*
@@ -56,28 +50,7 @@ public interface ControlBlockEditor {
* @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
* @return list of encountered errors
*/
- List createDataSetAndControlBlocks(SCL scd, Set allowedFcdas);
-
- /**
- * Create All DataSet and ControlBlock for the ExtRef in given IED
- *
- * @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
- * @param targetIedName the name of the IED where the ExtRef are
- * @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
- * @return list of encountered errors
- */
- List createDataSetAndControlBlocks(SCL scd, String targetIedName, Set allowedFcdas);
-
- /**
- * Create All DataSet and ControlBlock for the ExtRef in given IED and LDevice
- *
- * @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
- * @param targetIedName the name of the IED where the ExtRef are
- * @param targetLDeviceInst the name of the LDevice where the ExtRef are
- * @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
- * @return list of encountered errors
- */
- List createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, Set allowedFcdas);
+ List createDataSetAndControlBlocks(SCL scd, FCDAs allowedFcdas);
/**
* Configure the network for all the ControlBlocks.
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FcdaForDataSetsCreation.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FcdaForDataSetsCreation.java
deleted file mode 100644
index 3d50a150e..000000000
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FcdaForDataSetsCreation.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * // SPDX-FileCopyrightText: 2023 RTE FRANCE
- * //
- * // SPDX-License-Identifier: Apache-2.0
- */
-
-package org.lfenergy.compas.sct.commons.dto;
-
-import com.opencsv.bean.CsvBindByPosition;
-import lombok.AllArgsConstructor;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-
-@NoArgsConstructor
-@AllArgsConstructor
-@Getter
-@EqualsAndHashCode
-public class FcdaForDataSetsCreation {
-
- @CsvBindByPosition(position = 0)
- private String lnClass;
- @CsvBindByPosition(position = 1)
- private String doName;
- @CsvBindByPosition(position = 2)
- private String daName;
- @CsvBindByPosition(position = 3)
- private String fc;
-}
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 46ebb27f5..d68d2febf 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
@@ -9,9 +9,9 @@
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
-import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
+import org.lfenergy.compas.sct.commons.model.da_cb_com.TFCDA;
import org.lfenergy.compas.sct.commons.scl.ExtRefService;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
@@ -202,7 +202,7 @@ private AbstractLNAdapter> getLNAdapter() {
return parentAdapter;
}
- public List updateAllSourceDataSetsAndControlBlocks(Set allowedFcdas) {
+ public List updateAllSourceDataSetsAndControlBlocks(List allowedFcdas) {
String currentBayUuid = getIedAdapter().getPrivateCompasBay().map(TCompasBay::getUUID).orElse(null);
if (StringUtils.isBlank(currentBayUuid)) {
return List.of(getIedAdapter().buildFatalReportItem(MESSAGE_IED_MISSING_COMPAS_BAY_UUID));
@@ -235,7 +235,7 @@ private boolean areBindingAttributesPresent(TExtRef tExtRef) {
&& StringUtils.isNotBlank(tExtRef.getDoName());
}
- private Optional updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid, Set allowedFcdas) {
+ private Optional updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid, List allowedFcdas) {
if (extRef.getServiceType() == null) {
return fatalReportItem(extRef, MESSAGE_SERVICE_TYPE_MISSING);
}
@@ -326,7 +326,7 @@ private static String generateDataSetSuffix(TExtRef extRef, DataAttributeRef sou
+ (isBayInternal ? "I" : "E");
}
- private Optional removeFilteredSourceDas(TExtRef extRef, final Set sourceDas, Set allowedFcdas) {
+ private Optional removeFilteredSourceDas(TExtRef extRef, final Set sourceDas, List allowedFcdas) {
sourceDas.removeIf(da -> da.getFc() != TFCEnum.MX && da.getFc() != TFCEnum.ST);
return switch (extRef.getServiceType()) {
case GOOSE, SMV -> {
@@ -338,7 +338,7 @@ private Optional removeFilteredSourceDas(TExtRef extRef, final Se
};
}
- private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, Set allowedFcdas) {
+ private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, List allowedFcdas) {
String lnClass = dataAttributeRef.getLnClass();
String doName = dataAttributeRef.getDoName().toStringWithoutInst();
String daName = dataAttributeRef.getDaName().toString();
@@ -346,7 +346,10 @@ private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, Set tfcda.getFCDAdoName().equals(doName)
+ && tfcda.getFCDAdaName().equals(daName)
+ && tfcda.getFCDAlnClass().equals(lnClass)
+ && tfcda.getFCDAfc().value().equals(fc));
}
private Optional removeFilterSourceDaForReport(TExtRef extRef, Set sourceDas) {
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java
index 26c1361c2..a45a21bec 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java
@@ -357,7 +357,7 @@ public List> getLNAdaptersIncludingLN0() {
return aLNAdapters;
}
- public List createDataSetAndControlBlocks(Set allowedFcdas) {
+ public List createDataSetAndControlBlocks(List allowedFcdas) {
LN0Adapter ln0Adapter = getLN0Adapter();
if (!ln0Adapter.hasInputs()) {
return Collections.emptyList();
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/CsvUtils.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/CsvUtils.java
deleted file mode 100644
index fa87b8210..000000000
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/CsvUtils.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// SPDX-FileCopyrightText: 2023 RTE FRANCE
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package org.lfenergy.compas.sct.commons.util;
-
-import com.opencsv.bean.ColumnPositionMappingStrategy;
-import com.opencsv.bean.CsvToBeanBuilder;
-import com.opencsv.enums.CSVReaderNullFieldIndicator;
-
-import java.io.*;
-import java.nio.charset.Charset;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Utility class to parse CSV files.
- * This utility class intention is to normalize all CSV inputs in the project:
- * - Separator is {@link CsvUtils#SEPARATOR}.
- * - Lines starting with {@link CsvUtils#COMMENT_PREFIX} will be ignored. Allow to write copyright and headers at the beginning of the file for example.
- * - blank lines are ignored
- */
-public final class CsvUtils {
- private static final char SEPARATOR = ';';
- private static final String COMMENT_PREFIX = "#";
-
- private CsvUtils() {
- throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
- }
-
- /**
- * Read CSV from a resource
- *
- * @param resourcePath path of the resource
- * @param charset charset of the resource
- * @param targetClass Each row will be mapped to this class.
- * @return list of rows, mapped as targetClass
- */
- public static List parseRows(String resourcePath, Charset charset, Class targetClass) {
- InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(resourcePath), "Resource not found: " + resourcePath);
- InputStreamReader csvReader = new InputStreamReader(inputStream, charset);
- return parseRows(csvReader, targetClass);
- }
-
- /**
- * Read CSV from a Reader.
- * Reader will be automatically closed when the method returns or throw an exception.
- *
- * @param csvSource CSV input
- * @param targetClass Each row will be mapped to this class.
- * @return list of rows, mapped as targetClass
- */
- public static List parseRows(Reader csvSource, Class targetClass) {
- ColumnPositionMappingStrategy columnPositionMappingStrategy = new ColumnPositionMappingStrategy<>();
- columnPositionMappingStrategy.setType(targetClass);
- try (csvSource) {
- return new CsvToBeanBuilder(csvSource)
- .withType(targetClass)
- .withSeparator(SEPARATOR)
- .withIgnoreLeadingWhiteSpace(true)
- .withIgnoreEmptyLine(true)
- .withFieldAsNull(CSVReaderNullFieldIndicator.EMPTY_SEPARATORS)
- .withFilter(line -> line != null && line.length > 0 && (line[0] == null || !line[0].stripLeading().startsWith(COMMENT_PREFIX)))
- .withMappingStrategy(columnPositionMappingStrategy)
- .build()
- .parse();
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- }
-}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/FcdaCsvHelper.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/FcdaCsvHelper.java
deleted file mode 100644
index d4a20ad51..000000000
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/FcdaCsvHelper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-// SPDX-FileCopyrightText: 2023 RTE FRANCE
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package org.lfenergy.compas.sct.commons.util;
-
-import lombok.Getter;
-import org.lfenergy.compas.scl2007b4.model.SCL;
-import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
-
-import java.io.Reader;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * This class is a helper method to load FCDA from a CSV files for use with
- * {@link org.lfenergy.compas.sct.commons.ControlBlockService#createDataSetAndControlBlocks(SCL, Set)}
- * {@link org.lfenergy.compas.sct.commons.ControlBlockService#createDataSetAndControlBlocks(SCL, String, Set)}
- * {@link org.lfenergy.compas.sct.commons.ControlBlockService#createDataSetAndControlBlocks(SCL, String, String, Set)}
- * Use the getter to access the list of parsed FCDA.
- *
- * @see CsvUtils
- */
-public class FcdaCsvHelper {
-
- @Getter
- private final Set fcdaForDataSets;
-
- /**
- * Constructor
- * Provide the CSV files as a Reader. For example, you can create a reader like this :
- * new InputStreamReader(getClass().getClassLoader().getResourceAsStream(fileName), StandardCharsets.UTF_8);
- *
- * @param csvSourceForDataSetAndControlBlocks a reader that provides the FCDA datas for DataSets and Control Blocks creation as CSV
- */
- public FcdaCsvHelper(Reader csvSourceForDataSetAndControlBlocks) {
- fcdaForDataSets = new HashSet<>(CsvUtils.parseRows(csvSourceForDataSetAndControlBlocks, FcdaForDataSetsCreation.class));
- }
-
-
-}
diff --git a/sct-commons/src/main/resources/xsd/CB_COMM_V1.xsd b/sct-commons/src/main/resources/xsd/CB_COMM_V1.xsd
new file mode 100644
index 000000000..27eb3e21e
--- /dev/null
+++ b/sct-commons/src/main/resources/xsd/CB_COMM_V1.xsd
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java
index 3a720f6de..7d63077ad 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java
@@ -12,10 +12,10 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.ControlBlockTarget;
-import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.model.cbcom.*;
+import org.lfenergy.compas.sct.commons.model.da_cb_com.FCDAs;
import org.lfenergy.compas.sct.commons.scl.ControlService;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
@@ -25,18 +25,14 @@
import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter;
import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter;
import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter;
+import org.lfenergy.compas.sct.commons.testhelpers.DaComTestMarshallerHelper;
import org.lfenergy.compas.sct.commons.testhelpers.FCDARecord;
import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
-import org.lfenergy.compas.sct.commons.util.CsvUtils;
import org.lfenergy.compas.sct.commons.util.PrivateEnum;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -51,12 +47,9 @@ class ControlBlockEditorServiceTest {
ControlBlockEditorService controlBlockEditorService;
- private Set allowedFcdas;
-
@BeforeEach
void init() {
controlBlockEditorService = new ControlBlockEditorService(new ControlService());
- allowedFcdas = new HashSet<>(CsvUtils.parseRows("FcdaCandidates.csv", StandardCharsets.UTF_8, FcdaForDataSetsCreation.class));
}
@Test
@@ -130,29 +123,11 @@ void removeControlBlocksAndDatasetAndExtRefSrc_should_remove_srcXXX_attributes_o
assertIsMarshallable(scl);
}
-
- private static Stream provideAllowedFcdaListEmptyOrNull() {
- return Stream.of(
- Arguments.of("Set of allowed FCDA is null", null),
- Arguments.of("Set of allow FCDA is Empty", Collections.EMPTY_SET)
- );
- }
-
- @ParameterizedTest(name = "{0}")
- @MethodSource("provideAllowedFcdaListEmptyOrNull")
- void createDataSetAndControlBlocks_should_Throw_Exception_when_list_allowed_fcda_not_initialized(String testName, Set fcdaForDataSets) {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When Then
- assertThatCode(() -> controlBlockEditorService.createDataSetAndControlBlocks(scd, fcdaForDataSets))
- .isInstanceOf(ScdException.class)
- .hasMessage("Accepted FCDAs list is empty, you should initialize allowed FCDA lists with CsvHelper class before");
- }
-
@Test
void createDataSetAndControlBlocks_should_create_DataSet() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
+ FCDAs allowedFcdas = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml").getFCDAs();
// When
List sclReportItems = controlBlockEditorService.createDataSetAndControlBlocks(scd, allowedFcdas);
// Then
@@ -184,6 +159,7 @@ void createDataSetAndControlBlocks_should_create_DataSet() {
void createDataSetAndControlBlocks_should_create_ControlBlocks() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
+ FCDAs allowedFcdas = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml").getFCDAs();
// When
List sclReportItems = controlBlockEditorService.createDataSetAndControlBlocks(scd, allowedFcdas);
// Then
@@ -217,6 +193,7 @@ void createDataSetAndControlBlocks_should_create_ControlBlocks() {
void createDataSetAndControlBlocks_should_set_ExtRef_srcXXX_attributes() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
+ FCDAs allowedFcdas = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml").getFCDAs();
// When
List sclReportItems = controlBlockEditorService.createDataSetAndControlBlocks(scd, allowedFcdas);
// Then
@@ -242,110 +219,11 @@ void createDataSetAndControlBlocks_should_set_ExtRef_srcXXX_attributes() {
.containsExactly("CB_LD_INST21_CYCI", "LD_INST21");
}
- @ParameterizedTest(name = "{0}")
- @MethodSource("provideAllowedFcdaListEmptyOrNull")
- void createDataSetAndControlBlocks_with_targetIedName_should_Throw_Exception_when_list_allowed_fcda_not_initialized(String testName, Set fcdaForDataSets) {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When Then
- assertThatCode(() -> controlBlockEditorService.createDataSetAndControlBlocks(scd, "IED_NAME1", fcdaForDataSets))
- .isInstanceOf(ScdException.class)
- .hasMessage("Accepted FCDAs list is empty, you should initialize allowed FCDA lists with CsvHelper class before");
- }
-
- @Test
- void createDataSetAndControlBlocks_when_targetIedName_is_provided_should_succeed() {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When
- List sclReportItems = controlBlockEditorService.createDataSetAndControlBlocks(scd, "IED_NAME1", allowedFcdas);
- // Then
- assertThat(sclReportItems).isEmpty();
- assertThat(streamAllDataSets(scd)).hasSize(6);
- List ln0s = streamAllLn0Adapters(scd).map(SclElementAdapter::getCurrentElem).toList();
- assertThat(ln0s).flatMap(TLN0::getGSEControl).hasSize(3);
- assertThat(ln0s).flatMap(TLN0::getSampledValueControl).hasSize(1);
- assertThat(ln0s).flatMap(TLN0::getReportControl).hasSize(2);
- MarshallerWrapper.assertValidateXmlSchema(scd);
- }
-
- @Test
- void createDataSetAndControlBlocks_when_targetIedName_is_provided_and_no_ext_ref_should_do_nothing() {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When
- List sclReportItems = controlBlockEditorService.createDataSetAndControlBlocks(scd, "IED_NAME2", allowedFcdas);
- // Then
- assertThat(sclReportItems).isEmpty();
- assertThat(streamAllDataSets(scd)).isEmpty();
- }
-
- @Test
- void createDataSetAndControlBlocks_when_targetIedName_is_not_found_should_throw_exception() {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When & Then
- assertThatThrownBy(() -> controlBlockEditorService.createDataSetAndControlBlocks(scd, "non_existing_IED_name", allowedFcdas))
- .isInstanceOf(ScdException.class)
- .hasMessage("IED.name 'non_existing_IED_name' not found in SCD");
- }
-
- @ParameterizedTest(name = "{0}")
- @MethodSource("provideAllowedFcdaListEmptyOrNull")
- void createDataSetAndControlBlocks_with_targetIedName_and_targetLDeviceInst_should_Throw_Exception_when_list_allowed_fcda_not_initialized(String testName, Set fcdaForDataSets) {
- // Given
- SCL scd = new SCL();
- // When Then
- assertThatCode(() -> controlBlockEditorService.createDataSetAndControlBlocks(scd, "IED_NAME1", "LD_INST11", fcdaForDataSets))
- .isInstanceOf(ScdException.class)
- .hasMessage("Accepted FCDAs list is empty, you should initialize allowed FCDA lists with CsvHelper class before");
- }
-
- @Test
- void createDataSetAndControlBlocks_when_targetIedName_and_targetLDeviceInst_is_provided_should_succeed() {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When
- List sclReportItems = controlBlockEditorService.createDataSetAndControlBlocks(scd, "IED_NAME1", "LD_INST11", allowedFcdas);
- // Then
- assertThat(sclReportItems).isEmpty();
- }
-
- @Test
- void createDataSetAndControlBlocks_when_targetIedName_is_not_found_and_targetLDeviceInst_is_provided_should_throw_exception() {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When & Then
- assertThatThrownBy(() -> controlBlockEditorService.createDataSetAndControlBlocks(scd, "non_existing_IED_name", "LD_INST11", allowedFcdas))
- .isInstanceOf(ScdException.class)
- .hasMessage("IED.name 'non_existing_IED_name' not found in SCD");
- }
-
- @Test
- void createDataSetAndControlBlocks_when_targetIedName_and_targetLDeviceInst_is_not_found_should_throw_exception() {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When & Then
- assertThatThrownBy(() -> controlBlockEditorService.createDataSetAndControlBlocks(scd, "IED_NAME1", "non_existing_LDevice_inst", allowedFcdas))
- .isInstanceOf(ScdException.class)
- .hasMessage("LDevice.inst 'non_existing_LDevice_inst' not found in IED 'IED_NAME1'");
- }
-
- @Test
- void createDataSetAndControlBlocks_when_targetLDeviceInst_is_provided_without_targetIedName_should_throw_exception() {
- // Given
- SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- // When & Then
- assertThatThrownBy(() -> controlBlockEditorService.createDataSetAndControlBlocks(scd, null, "LD_INST11", allowedFcdas))
- .isInstanceOf(ScdException.class)
- .hasMessage("IED.name parameter is missing");
- }
-
-
@Test
void updateAllSourceDataSetsAndControlBlocks_should_sort_FCDA_inside_DataSet_and_avoid_duplicates() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success_test_fcda_sort.xml");
+ FCDAs allowedFcdas = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml").getFCDAs();
// When
List sclReportItems = controlBlockEditorService.createDataSetAndControlBlocks(scd, allowedFcdas);
// Then
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 9378964a9..fb2ea5acf 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
@@ -4,25 +4,23 @@
package org.lfenergy.compas.sct.commons.scl.ied;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.lfenergy.compas.scl2007b4.model.*;
-import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
+import org.lfenergy.compas.sct.commons.model.da_cb_com.DACOMM;
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.scl.ln.LN0Adapter;
+import org.lfenergy.compas.sct.commons.testhelpers.DaComTestMarshallerHelper;
import org.lfenergy.compas.sct.commons.testhelpers.FCDARecord;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
-import org.lfenergy.compas.sct.commons.util.CsvUtils;
import org.opentest4j.AssertionFailedError;
-import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -33,13 +31,6 @@
class InputsAdapterTest {
- private Set allowedFcdas;
-
- @BeforeEach
- void init() {
- allowedFcdas = new HashSet<>(CsvUtils.parseRows("FcdaCandidates.csv", StandardCharsets.UTF_8, FcdaForDataSetsCreation.class));
- }
-
@Test
@Tag("issue-321")
void constructor_should_succeed() {
@@ -70,7 +61,8 @@ void updateAllSourceDataSetsAndControlBlocks_should_report_Target_Ied_missing_Pr
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_ied_errors.xml");
InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME1", "LD_INST11");
// When
- List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
+// List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
+ List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(List.of());
// Then
assertThat(sclReportItems).containsExactly(
SclReportItem.error("/SCL/IED[@name=\"IED_NAME1\"]",
@@ -84,7 +76,7 @@ void updateAllSourceDataSetsAndControlBlocks_should_report_Source_Ied_missing_Pr
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_ied_errors.xml");
InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME3", "LD_INST31");
// When
- List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
+ List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(List.of());
// Then
assertThat(sclReportItems).containsExactly(
SclReportItem.error("/SCL/IED[@name=\"IED_NAME3\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST31\"]/LN0/Inputs/ExtRef[@desc=\"Source IED is " +
@@ -99,7 +91,7 @@ void updateAllSourceDataSetsAndControlBlocks_should_report_ExtRef_attribute_miss
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_extref_errors.xml");
InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME1", "LD_INST11");
// When
- List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
+ List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(List.of());
// Then
assertThat(sclReportItems).containsExactlyInAnyOrder(
SclReportItem.error("/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]/LN0/Inputs/" +
@@ -120,7 +112,7 @@ void updateAllSourceDataSetsAndControlBlocks_should_succeed() {
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME1", "LD_INST11");
// When
- List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
+ List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(List.of());
// Then
assertThat(sclReportItems).isEmpty();
}
@@ -140,8 +132,9 @@ void updateAllSourceDataSetsAndControlBlocks_should_create_dataset_and_fcda_for_
String expectedSourceIedName = splitPath[IED_NAME_PART];
String expectedSourceLDeviceInst = splitPath[LDEVICE_INST_PART];
String expectedDataSetName = splitPath[DATASET_NAME_PART];
+ DACOMM dacomm = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml");
// When
- List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
+ List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(dacomm.getFCDAs().getFCDA());
// Then
assertThat(sclReportItems).isEmpty();
DataSetAdapter dataSet = findDataSet(scd, expectedSourceIedName, expectedSourceLDeviceInst, expectedDataSetName);
@@ -210,8 +203,9 @@ void updateAllSourceDataSetsAndControlBlocks_when_no_valid_source_Da_found_shoul
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(allowedFcdas);
+ List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(dacomm.getFCDAs().getFCDA());
// Then
assertThat(sclReportItems).isEmpty();
assertThat(sclRootAdapter.streamIEDAdapters()
@@ -243,8 +237,9 @@ void updateAllSourceDataSetsAndControlBlocks_when_AccessPoint_does_not_have_data
TExtRef extRef = inputsAdapter.getCurrentElem().getExtRef().get(0);
LDeviceAdapter sourceLDevice = findLDevice(sclRootAdapter.getCurrentElem(), extRef.getIedName(), extRef.getLdInst());
sourceLDevice.getAccessPoint().setServices(new TServices());
+ DACOMM dacomm = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml");
// When
- List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
+ List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(dacomm.getFCDAs().getFCDA());
// Then
assertThat(sclReportItems).hasSize(1)
.first().extracting(SclReportItem::message).asString()
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/DaComParamTestMarshaller.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/DaComParamTestMarshaller.java
new file mode 100644
index 000000000..72c8fd5a7
--- /dev/null
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/DaComParamTestMarshaller.java
@@ -0,0 +1,34 @@
+// SPDX-FileCopyrightText: 2021 RTE FRANCE
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package org.lfenergy.compas.sct.commons.testhelpers;
+
+import jakarta.xml.bind.Marshaller;
+import jakarta.xml.bind.Unmarshaller;
+import org.lfenergy.compas.core.commons.MarshallerWrapper;
+import org.lfenergy.compas.sct.commons.model.da_cb_com.DACOMM;
+
+public class DaComParamTestMarshaller extends MarshallerWrapper {
+
+ public DaComParamTestMarshaller(Unmarshaller jaxbUnmarshaller, Marshaller jaxbMarshaller) {
+ super(jaxbUnmarshaller, jaxbMarshaller);
+ }
+
+ @Override
+ protected Class getResultClass() {
+ return DACOMM.class;
+ }
+
+ public static class Builder extends MarshallerWrapper.Builder {
+ public Builder() {
+ withProperties("da_cb_comm-marshaller-config.yml");
+ }
+
+ @Override
+ protected DaComParamTestMarshaller createMarshallerWrapper(Unmarshaller jaxbUnmarshaller,
+ Marshaller jaxbMarshaller) {
+ return new DaComParamTestMarshaller(jaxbUnmarshaller, jaxbMarshaller);
+ }
+ }
+}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/DaComTestMarshallerHelper.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/DaComTestMarshallerHelper.java
new file mode 100644
index 000000000..5d9eba3de
--- /dev/null
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/DaComTestMarshallerHelper.java
@@ -0,0 +1,25 @@
+// SPDX-FileCopyrightText: 2021 RTE FRANCE
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package org.lfenergy.compas.sct.commons.testhelpers;
+
+import org.apache.commons.io.IOUtils;
+import org.lfenergy.compas.sct.commons.model.da_cb_com.DACOMM;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+
+public class DaComTestMarshallerHelper {
+
+ public static DACOMM getDACOMMFromFile(String filename) {
+ byte[] rawXml;
+ try {
+ rawXml = IOUtils.resourceToByteArray(filename);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ return new DaComParamTestMarshaller.Builder().build().unmarshall(rawXml);
+ }
+
+}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/CsvUtilsTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/CsvUtilsTest.java
deleted file mode 100644
index d245b7b3f..000000000
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/CsvUtilsTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// SPDX-FileCopyrightText: 2023 RTE FRANCE
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package org.lfenergy.compas.sct.commons.util;
-
-import com.opencsv.bean.CsvBindByPosition;
-import lombok.*;
-import org.assertj.core.groups.Tuple;
-import org.junit.jupiter.api.Test;
-
-import java.io.StringReader;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class CsvUtilsTest {
-
- private static final Tuple ROW_1 = Tuple.tuple("cel1x1", "cel1x2", "cel1x3");
- private static final Tuple ROW_2 = Tuple.tuple("cel2x1", "cel2x2", "cel2x3");
-
- @Test
- void parseRows_should_parse_rows() {
- //Given
- StringReader csvReader = new StringReader("""
- cel1x1;cel1x2;cel1x3
- cel2x1;cel2x2;cel2x3
- """);
- //When
- List rows = CsvUtils.parseRows(csvReader, Row.class);
- //Then
- assertThat(rows).extracting(Row::getCol1, Row::getCol2, Row::getCol3)
- .containsExactly(
- ROW_1,
- ROW_2
- );
- }
-
- @Test
- void parseRows_should_ignore_empty_lines() {
- //Given
- StringReader csvReader = new StringReader("""
- cel1x1;cel1x2;cel1x3
-
- cel2x1;cel2x2;cel2x3
- """);
- //When
- List rows = CsvUtils.parseRows(csvReader, Row.class);
- //Then
- assertThat(rows).extracting(Row::getCol1, Row::getCol2, Row::getCol3)
- .containsExactly(
- ROW_1,
- ROW_2
- );
- }
-
- @Test
- void parseRows_should_treat_empty_string_as_null() {
- //Given
- StringReader csvReader = new StringReader("""
- ;cel1x2;cel1x3
- cel2x1;;cel2x3
- cel3x1;cel3x2;
- """);
- //When
- List rows = CsvUtils.parseRows(csvReader, Row.class);
- //Then
- assertThat(rows).extracting(Row::getCol1, Row::getCol2, Row::getCol3)
- .containsExactly(
- Tuple.tuple(null, "cel1x2", "cel1x3"),
- Tuple.tuple("cel2x1", null, "cel2x3"),
- Tuple.tuple("cel3x1", "cel3x2", null)
- );
- }
-
- @Test
- void parseRows_should_ignore_comment_lines() {
- //Given
- StringReader csvReader = new StringReader("""
- cel1x1;cel1x2;cel1x3
-
- # other comment line with indentation
- line with # in the middle should not be ignored;a;b
- """);
- //When
- List rows = CsvUtils.parseRows(csvReader, Row.class);
- //Then
- assertThat(rows).extracting(Row::getCol1, Row::getCol2, Row::getCol3)
- .containsExactly(
- ROW_1,
- Tuple.tuple("line with # in the middle should not be ignored", "a", "b")
- );
- }
-
- @Test
- void parseRows_with_resource_path_should_parse_rows() {
- //Given
- String resourcePath = "csvutils/csv_utils_test_file.csv";
- //When
- List rows = CsvUtils.parseRows(resourcePath, StandardCharsets.UTF_8, Row.class);
- //Then
- assertThat(rows).extracting(Row::getCol1, Row::getCol2, Row::getCol3)
- .containsExactly(
- ROW_1,
- ROW_2
- );
- }
-
- @NoArgsConstructor
- @AllArgsConstructor
- @Getter
- @Setter
- @EqualsAndHashCode
- public static class Row {
- @CsvBindByPosition(position = 0)
- private String col1;
- @CsvBindByPosition(position = 1)
- private String col2;
- @CsvBindByPosition(position = 2)
- private String col3;
- }
-
-}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/FcdaCsvHelperTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/FcdaCsvHelperTest.java
deleted file mode 100644
index d3b6ec399..000000000
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/FcdaCsvHelperTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// SPDX-FileCopyrightText: 2023 RTE FRANCE
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package org.lfenergy.compas.sct.commons.util;
-
-import org.assertj.core.groups.Tuple;
-import org.junit.jupiter.api.Test;
-import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
-
-import java.io.StringReader;
-import java.util.Set;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class FcdaCsvHelperTest {
-
- @Test
- void constructor_should_initialize_list_of_FcdaForDataSets() {
- //Given
- StringReader csvSourceForDataSetAndControlBlocks = new StringReader("GAPC;Ind1;stVal;ST");
- //When
- FcdaCsvHelper fcdaCsvHelper = new FcdaCsvHelper(csvSourceForDataSetAndControlBlocks);
- //Then
- Set fcdaForDataSets = fcdaCsvHelper.getFcdaForDataSets();
- assertThat(fcdaForDataSets)
- .isNotNull()
- .hasSize(1);
- }
-
- @Test
- void get_return_list_of_FcdaForDataSets() {
- //Given
- StringReader csvSourceForDataSetAndControlBlocks = new StringReader("""
- GAPC;Ind1;stVal;ST
- LLN0;Health;ctVal;MX
- """);
- FcdaCsvHelper fcdaCsvHelper = new FcdaCsvHelper(csvSourceForDataSetAndControlBlocks);
- //When
- Set fcdaForDataSets = fcdaCsvHelper.getFcdaForDataSets();
- //Then
- assertThat(fcdaForDataSets).hasSize(2)
- .extracting(FcdaForDataSetsCreation::getLnClass, FcdaForDataSetsCreation::getDoName, FcdaForDataSetsCreation::getDaName, FcdaForDataSetsCreation::getFc)
- .containsExactly(Tuple.tuple("LLN0", "Health", "ctVal", "MX"), Tuple.tuple("GAPC", "Ind1", "stVal", "ST"));
- }
-}
diff --git a/sct-commons/src/test/resources/cb_comm/Template_DA_COMM_v1.xml b/sct-commons/src/test/resources/cb_comm/Template_DA_COMM_v1.xml
new file mode 100644
index 000000000..193c2526e
--- /dev/null
+++ b/sct-commons/src/test/resources/cb_comm/Template_DA_COMM_v1.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sct-commons/src/test/resources/csvutils/csv_utils_test_file.csv b/sct-commons/src/test/resources/csvutils/csv_utils_test_file.csv
deleted file mode 100644
index 77151a08a..000000000
--- a/sct-commons/src/test/resources/csvutils/csv_utils_test_file.csv
+++ /dev/null
@@ -1,7 +0,0 @@
-# SPDX-FileCopyrightText: 2022 RTE FRANCE
-#
-# SPDX-License-Identifier: Apache-2.0
-
-#col1;col2;col3
-cel1x1;cel1x2;cel1x3
-cel2x1;cel2x2;cel2x3
diff --git a/sct-commons/src/test/resources/da_cb_comm-marshaller-config.yml b/sct-commons/src/test/resources/da_cb_comm-marshaller-config.yml
new file mode 100644
index 000000000..a0592ce21
--- /dev/null
+++ b/sct-commons/src/test/resources/da_cb_comm-marshaller-config.yml
@@ -0,0 +1,12 @@
+# SPDX-FileCopyrightText: 2021 Alliander N.V.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+## YAML Template.
+---
+compas:
+ scl:
+ schemas:
+ - xsdPath: "xsd/CB_COMM_V1.xsd"
+ namespace: "http://www.rte-france.com"
+ contextPath: "org.lfenergy.compas.sct.commons.model.da_cb_com"