stds, Map subNetworkDTOSet = SubNetworkDTO.createDefaultSubnetwork(iedName, comAdapter, comMap);
- addSubnetworks(scdRootAdapter.getCurrentElem(), subNetworkDTOSet, Optional.of(std));
+ TCommunication communication = stdRootAdapter.getCurrentElem().getCommunication();
+ List subNetworkDTOSet = SubNetworkDTO.createDefaultSubnetwork(iedName, communication, subNetworkTypes);
+ addSubnetworks(scdRootAdapter.getCurrentElem(), subNetworkDTOSet, std);
}
});
- return scdRootAdapter.getCurrentElem();
}
@@ -570,7 +553,7 @@ public static List updateLDeviceStatus(SCL scd) {
.map(LDeviceAdapter::getLN0Adapter)
.map(ln0Adapter -> ln0Adapter.updateLDeviceStatus(iedNameLdInstList))
.flatMap(Optional::stream)
- .collect(Collectors.toList());
+ .toList();
}
/**
@@ -587,7 +570,7 @@ public static List analyzeDataGroups(SCL scd) {
list.addAll(iedAdapter.checkDataGroupCoherence());
list.addAll(iedAdapter.checkBindingDataGroupCoherence());
return list;
- }).flatMap(Collection::stream).collect(Collectors.toList());
+ }).flatMap(Collection::stream).toList();
}
/**
@@ -603,7 +586,7 @@ public static List updateDoInRef(SCL scd) {
.map(LDeviceAdapter::getLN0Adapter)
.map(LN0Adapter::updateDoInRef)
.flatMap(List::stream)
- .collect(Collectors.toList());
+ .toList();
}
/**
@@ -618,6 +601,6 @@ public static List manageMonitoringLns(SCL scd) {
.filter(iedAdapter -> !iedAdapter.getName().contains(IED_TEST_NAME))
.map(IEDAdapter::manageMonitoringLns)
.flatMap(List::stream)
- .collect(Collectors.toList());
+ .toList();
}
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SubstationService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SubstationService.java
index 995dade2f..8e92407dd 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SubstationService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SubstationService.java
@@ -43,11 +43,10 @@ private SubstationService() {
* Adds or Updates Substation section in SCL
* @param scd SCL file in which Substation should be added/updated
* @param ssd SCL file from which Substation should be copied
- * @return SCL SCD object
* @throws ScdException throws when SCD contents already another Substation, or with different name, or contents
* more than one Substation
*/
- public static SCL addSubstation(@NonNull SCL scd, @NonNull SCL ssd) throws ScdException {
+ public static void addSubstation(@NonNull SCL scd, @NonNull SCL ssd) throws ScdException {
if (scd.getSubstation().size() > 1) {
throw new ScdException(String.format("SCD file must have 0 or 1 Substation, but got %d", scd.getSubstation().size()));
}
@@ -57,7 +56,6 @@ public static SCL addSubstation(@NonNull SCL scd, @NonNull SCL ssd) throws ScdEx
TSubstation ssdTSubstation = ssd.getSubstation().get(0);
if (scd.getSubstation().isEmpty()) {
scd.getSubstation().add(ssdTSubstation);
- return scd;
} else {
TSubstation scdTSubstation = scd.getSubstation().get(0);
if (scdTSubstation.getName().equalsIgnoreCase(ssdTSubstation.getName())) {
@@ -65,7 +63,6 @@ public static SCL addSubstation(@NonNull SCL scd, @NonNull SCL ssd) throws ScdEx
for (TVoltageLevel tvl : ssdTSubstation.getVoltageLevel()) {
updateVoltageLevel(scdSubstationAdapter, tvl);
}
- return scdSubstationAdapter.getParentAdapter().getCurrentElem();
} else
throw new ScdException("SCD file must have only one Substation and the Substation name from SSD file is" +
" different from the one in SCD file. The files are rejected.");
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapter.java
index f2fcfb0e9..3569f4ef6 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapter.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/com/ConnectedAPAdapter.java
@@ -73,19 +73,17 @@ public String getApName() {
/**
* Copies Address and PhysicalConnection nodes from ICD file
- * @param icd ICD file
+ * @param icd ICD object
* @see Issue !76
* Copies Address and PhysicalConnection nodes from ICD file
*/
- public void copyAddressAndPhysConnFromIcd(Optional icd) {
- if (icd.isPresent() && icd.get().getCommunication() != null) {
- icd.stream()
- .map(SCL::getCommunication)
+ public void copyAddressAndPhysConnFromIcd(SCL icd) {
+ if (icd != null && icd.getCommunication() != null) {
+ icd.getCommunication().getSubNetwork().stream()
+ .flatMap(tSubNetwork -> tSubNetwork.getConnectedAP().stream())
+ .filter(connectedAP -> connectedAP.getApName().equals(currentElem.getApName()))
.findFirst()
- .flatMap(com -> com.getSubNetwork().stream()
- .flatMap(subNet -> subNet.getConnectedAP().stream()
- .filter(connAP -> connAP.getApName().equals(currentElem.getApName())))
- .findFirst()).ifPresent(connectedAP -> {
+ .ifPresent(connectedAP -> {
currentElem.setAddress(connectedAP.getAddress());
currentElem.getPhysConn().addAll(connectedAP.getPhysConn());
});
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTOTest.java
index c4e5fba9f..cdab91e20 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTOTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTOTest.java
@@ -20,14 +20,14 @@ void testConstruction(){
Mockito.when(connectedAPAdapter.getApName()).thenReturn(DTO.AP_NAME);
Mockito.when(connectedAPAdapter.getIedName()).thenReturn(DTO.HOLDER_IED_NAME);
- ConnectedApDTO connectedApDTO = new ConnectedApDTO(connectedAPAdapter);
+ ConnectedApDTO connectedApDTO = ConnectedApDTO.from(connectedAPAdapter);
- assertEquals(DTO.HOLDER_IED_NAME, connectedApDTO.getIedName());
- assertEquals(DTO.AP_NAME, connectedApDTO.getApName());
+ assertEquals(DTO.HOLDER_IED_NAME, connectedApDTO.iedName());
+ assertEquals(DTO.AP_NAME, connectedApDTO.apName());
connectedApDTO = ConnectedApDTO.from(connectedAPAdapter);
- assertEquals(DTO.HOLDER_IED_NAME, connectedApDTO.getIedName());
- assertEquals(DTO.AP_NAME, connectedApDTO.getApName());
+ assertEquals(DTO.HOLDER_IED_NAME, connectedApDTO.iedName());
+ assertEquals(DTO.AP_NAME, connectedApDTO.apName());
}
}
\ No newline at end of file
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DTO.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DTO.java
index a31c47d99..7193c0129 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DTO.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DTO.java
@@ -4,13 +4,10 @@
package org.lfenergy.compas.sct.commons.dto;
-import org.apache.commons.lang3.tuple.Pair;
import org.lfenergy.compas.scl2007b4.model.*;
import java.time.LocalDateTime;
-import java.util.Arrays;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
public class DTO {
@@ -20,15 +17,6 @@ public class DTO {
public static final String AP_NAME = "AP_NAME";
public static final String AP_NAME_2 = "AP_NAME_2";
- public static ConnectedApDTO createCapDTO() {
-
- ConnectedApDTO cap = new ConnectedApDTO();
- cap.setApName(AP_NAME);
- cap.setIedName(HOLDER_IED_NAME);
-
- return cap;
- }
-
/*-----------------------------------------------*/
/* ExtRefInfo */
/*-----------------------------------------------*/
@@ -313,5 +301,7 @@ public static HeaderDTO.HistoryItem createHeaderItem(String now) {
return historyItem;
}
- public static final Map, List> comMap = Map.of(Pair.of("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString()), Arrays.asList("PROCESS_AP", "TOTO_AP_GE"), Pair.of("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString()), Arrays.asList("ADMIN_AP", "TATA_AP_EFFACEC"));
+ public static final List SUB_NETWORK_TYPES = List.of(
+ new SubNetworkTypeDTO("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString(), List.of("PROCESS_AP", "TOTO_AP_GE")),
+ new SubNetworkTypeDTO("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString(), List.of("ADMIN_AP", "TATA_AP_EFFACEC")));
}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SubNetworkDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SubNetworkDTOTest.java
index e9471bc07..ffd5623bd 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SubNetworkDTOTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SubNetworkDTOTest.java
@@ -4,20 +4,19 @@
package org.lfenergy.compas.sct.commons.dto;
-import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
-import org.lfenergy.compas.sct.commons.scl.com.CommunicationAdapter;
+import org.lfenergy.compas.scl2007b4.model.TCommunication;
+import org.lfenergy.compas.scl2007b4.model.TConnectedAP;
+import org.lfenergy.compas.scl2007b4.model.TSubNetwork;
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;
import org.lfenergy.compas.sct.commons.scl.com.SubNetworkAdapter;
import org.mockito.Mockito;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.when;
class SubNetworkDTOTest {
@@ -35,11 +34,11 @@ void testConstructor(){
void testFrom(){
SubNetworkAdapter subNetworkAdapter = Mockito.mock(SubNetworkAdapter.class);
ConnectedAPAdapter connectedAPAdapter = Mockito.mock(ConnectedAPAdapter.class);
- Mockito.when(subNetworkAdapter.getConnectedAPAdapters()).thenReturn(List.of(connectedAPAdapter));
- Mockito.when(subNetworkAdapter.getName()).thenReturn("sName");
- Mockito.when(subNetworkAdapter.getType()).thenReturn(SubNetworkDTO.SubnetworkType.IP.toString());
- Mockito.when(connectedAPAdapter.getApName()).thenReturn(DTO.AP_NAME);
- Mockito.when(connectedAPAdapter.getIedName()).thenReturn(DTO.HOLDER_IED_NAME);
+ when(subNetworkAdapter.getConnectedAPAdapters()).thenReturn(List.of(connectedAPAdapter));
+ when(subNetworkAdapter.getName()).thenReturn("sName");
+ when(subNetworkAdapter.getType()).thenReturn(SubNetworkDTO.SubnetworkType.IP.toString());
+ when(connectedAPAdapter.getApName()).thenReturn(DTO.AP_NAME);
+ when(connectedAPAdapter.getIedName()).thenReturn(DTO.HOLDER_IED_NAME);
SubNetworkDTO subNetworkDTO = SubNetworkDTO.from(subNetworkAdapter);
assertEquals("sName",subNetworkDTO.getName());
@@ -49,23 +48,23 @@ void testFrom(){
}
@Test
- void testCreateDefaultSubnetwork() {
- CommunicationAdapter comAdapter = Mockito.mock(CommunicationAdapter.class);
- SubNetworkAdapter subNetworkAdapter = Mockito.mock(SubNetworkAdapter.class);
- ConnectedAPAdapter connectedAPAdapter = Mockito.mock(ConnectedAPAdapter.class);
-
- Mockito.when(comAdapter.getSubNetworkAdapters()).thenReturn(List.of(subNetworkAdapter));
- Mockito.when(subNetworkAdapter.getConnectedAPAdapters()).thenReturn(List.of(connectedAPAdapter));
- Mockito.when(subNetworkAdapter.getName()).thenReturn("sName");
- Mockito.when(subNetworkAdapter.getType()).thenReturn(SubNetworkDTO.SubnetworkType.IP.toString());
- Mockito.when(connectedAPAdapter.getApName()).thenReturn("PROCESS_AP");
- Mockito.when(connectedAPAdapter.getIedName()).thenReturn("IEDName");
-
- final Map, List> comMap = Map.of(
- Pair.of("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString()), Arrays.asList("PROCESS_AP", "TOTO_AP_GE"),
- Pair.of("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString()), Arrays.asList("ADMIN_AP","TATA_AP_EFFACEC"));
-
- Set subNetworkDTOS = SubNetworkDTO.createDefaultSubnetwork("IEDName", comAdapter, comMap);
+ void createDefaultSubnetwork_should_return_filtered_subnetwork_list() {
+ //When
+ TCommunication communication = Mockito.mock(TCommunication.class);
+ TSubNetwork subNetwork1 = new TSubNetwork();
+ subNetwork1.setName("sName");
+ subNetwork1.setName(SubNetworkDTO.SubnetworkType.IP.toString());
+ TConnectedAP connectedAP1 = new TConnectedAP();
+ connectedAP1.setApName("PROCESS_AP");
+ connectedAP1.setIedName("IEDName");
+ subNetwork1.getConnectedAP().add(connectedAP1);
+ when(communication.getSubNetwork()).thenReturn(List.of(subNetwork1));
+ List subNetworkTypes =List.of(
+ new SubNetworkTypeDTO("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString(), List.of("PROCESS_AP", "TOTO_AP_GE")),
+ new SubNetworkTypeDTO("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString(), List.of("ADMIN_AP", "TATA_AP_EFFACEC")));
+ //When
+ List subNetworkDTOS = SubNetworkDTO.createDefaultSubnetwork("IEDName", communication, subNetworkTypes);
+ //Then
assertThat(subNetworkDTOS).hasSize(2);
SubNetworkDTO expectedSubNetwork = subNetworkDTOS.stream().filter(subNetworkDTO -> !subNetworkDTO.getConnectedAPs().isEmpty()).findFirst().orElse(new SubNetworkDTO());
assertThat(expectedSubNetwork.getConnectedAPs()).hasSize(1);
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java
index 0d45ac7e9..67841a625 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java
@@ -65,7 +65,6 @@ void updateAllExtRefIedNames_should_update_iedName_and_ExtRefIedName() {
.getLN0Adapter()
.getCurrentElem()
.getInputs();
- //TODO PrivateService methods should not appear in then section
assertThat(PrivateService.extractCompasPrivate(inputs, TCompasFlow.class))
.map(TCompasFlow::getExtRefiedName)
.hasValue("IED_NAME2");
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java
index dde10b714..cbee0d90c 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java
@@ -239,7 +239,6 @@ void removePrivates_should_remove_privates_of_given_type() {
TBaseElement baseElement = new SCL();
baseElement.getPrivate().add(privateSCD);
TCompasICDHeader tCompasICDHeader = objectFactory.createTCompasICDHeader();
- //TODO not should appear in given section, only one When step - PrivateService.createPrivate
baseElement.getPrivate().add(PrivateService.createPrivate(tCompasICDHeader));
// When
PrivateService.removePrivates(baseElement, PrivateEnum.COMPAS_ICDHEADER);
@@ -270,7 +269,6 @@ void createMapICDSystemVersionUuidAndSTDFile_Should_return_empty_map_when_no_ICD
SCL scl1 = new SCL();
TIED tied1 = new TIED();
TCompasICDHeader compasICDHeader1 = new TCompasICDHeader();
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
tied1.getPrivate().add(tPrivate1);
scl1.getIED().add(tied1);
@@ -298,11 +296,8 @@ void createMapICDSystemVersionUuidAndSTDFile_Should_return_map_with_two_lines()
compasICDHeader2.setICDSystemVersionUUID("UUID-2");
TCompasICDHeader compasICDHeader3 = new TCompasICDHeader();
compasICDHeader3.setICDSystemVersionUUID("UUID-2");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate3 = PrivateService.createPrivate(compasICDHeader3);
tied1.getPrivate().add(tPrivate1);
tied2.getPrivate().add(tPrivate2);
@@ -329,9 +324,7 @@ void checkSTDCorrespondanceWithLNodeCompasICDHeadershoul_throw_scdEception(){
compasICDHeader2.setHeaderId("ID-2");
compasICDHeader2.setHeaderVersion("VER-2");
compasICDHeader2.setHeaderRevision("REV-2");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
PrivateService.PrivateLinkedToSTDs privateLinkedToSTDs1 = new PrivateService.PrivateLinkedToSTDs(tPrivate1,Collections.singletonList(new SCL()));
@@ -355,9 +348,7 @@ void checkSTDCorrespondanceWithLNodeCompasICDHeader_should_pass(){
compasICDHeader1.setICDSystemVersionUUID("UUID-1");
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
compasICDHeader2.setICDSystemVersionUUID("UUID-2");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
PrivateService.PrivateLinkedToSTDs privateLinkedToSTDs1 = new PrivateService.PrivateLinkedToSTDs(tPrivate1,Collections.singletonList(new SCL()));
@@ -379,7 +370,6 @@ void stdCheckFormatExceptionMessage_should_return_formatted_message_with_Private
compasICDHeader.setHeaderId("ID-1");
compasICDHeader.setHeaderVersion("VER-1");
compasICDHeader.setICDSystemVersionUUID("UUID-1");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate = PrivateService.createPrivate(compasICDHeader);
//When
@@ -403,11 +393,8 @@ void createMapIEDNameAndPrivate_should_return_map_of_three_items() {
compasICDHeader2.setIEDName("IED-2");
TCompasICDHeader compasICDHeader3 = new TCompasICDHeader();
compasICDHeader3.setIEDName("IED-3");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate3 = PrivateService.createPrivate(compasICDHeader3);
tlNode1.getPrivate().add(tPrivate1);
tlNode2.getPrivate().add(tPrivate2);
@@ -439,7 +426,6 @@ void createMapIEDNameAndPrivate_should_return_empty_map_when_no_compasicdheader_
TLNode tlNode1 = new TLNode();
TCompasBay compasBay = new TCompasBay();
compasBay.setUUID("UUID");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasBay);
tlNode1.getPrivate().add(tPrivate1);
TFunction tFunction = new TFunction();
@@ -467,9 +453,7 @@ void comparePrivateCompasICDHeaders_should_return_true_equality_not_check_for_IE
compasICDHeader1.setBayLabel("BAY-1");
compasICDHeader1.setIEDSubstationinstance(BigInteger.ONE);
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
// When
@@ -488,9 +472,7 @@ void comparePrivateCompasICDHeaders_should_return_false_equality_not_check_for_I
compasICDHeader1.setICDSystemVersionUUID("UUID-1");
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
compasICDHeader2.setICDSystemVersionUUID("UUID-2");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
// When
@@ -509,9 +491,7 @@ void comparePrivateCompasICDHeaders_should_return_true() {
compasICDHeader1.setICDSystemVersionUUID("UUID-1");
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
compasICDHeader2.setICDSystemVersionUUID("UUID-1");
- //TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
- //TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
// When
@@ -530,7 +510,6 @@ void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate() {
lNodeCompasICDHeader.setIEDName("IED-1");
lNodeCompasICDHeader.setBayLabel("BAY-1");
lNodeCompasICDHeader.setIEDSubstationinstance(BigInteger.ONE);
- //TODO not should appear in given section, only one When step
TPrivate stdTPrivate = PrivateService.createPrivate(stdCompasICDHeader);
// When
@@ -538,7 +517,6 @@ void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate() {
// Then
TCompasICDHeader result = PrivateService.extractCompasICDHeader(stdTPrivate).get();
- //FIXME is this the 'When' extractCompasICDHeader ??? so why test named copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate
assertThat(result).extracting(TCompasICDHeader::getICDSystemVersionUUID, TCompasICDHeader::getIEDName,
TCompasICDHeader::getIEDSubstationinstance, TCompasICDHeader::getBayLabel)
.containsExactlyInAnyOrder("UUID-2", "IED-1", BigInteger.ONE, "BAY-1");
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 91cf6df10..38717da8f 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
@@ -24,8 +24,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.*;
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.SclHelper.LD_SUIED;
@@ -89,156 +88,144 @@ private static Stream sclProviderBasedLDeviceStatus() {
}
@Test
- void addHistoryItem_should_add_history_elements() throws ScdException {
- //Given
+ void testAddHistoryItem() throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- //When
+
SclService.addHistoryItem(scd, "who", "what", "why");
- //Then
- assertThat(scd.getHeader()).isNotNull();
+
+ assertNotNull(scd.getHeader());
THeader.History history = scd.getHeader().getHistory();
- assertThat(history).isNotNull();
- assertThat(history.getHitem()).hasSize(1);
+ assertNotNull(history);
+ assertEquals(1, history.getHitem().size());
THitem tHitem = history.getHitem().get(0);
- assertThat(tHitem.getWho()).isEqualTo("who");
- assertThat(tHitem.getWhat()).isEqualTo("what");
- assertThat(tHitem.getWhy()).isEqualTo("why");
- assertThat(tHitem.getRevision()).isEqualTo(SclRootAdapter.REVISION);
- assertThat(tHitem.getVersion()).isEqualTo(SclRootAdapter.VERSION);
+ assertEquals("who", tHitem.getWho());
+ assertEquals("what", tHitem.getWhat());
+ assertEquals("why", tHitem.getWhy());
+ assertEquals(SclRootAdapter.REVISION, tHitem.getRevision());
+ assertEquals(SclRootAdapter.VERSION, tHitem.getVersion());
assertIsMarshallable(scd);
}
@Test
- void addIED_should_add_ied_element() {
- //Given
+ void testAddIED() {
+
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
+ assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
- assertThat(scd.getIED()).isEmpty();
- //When Then
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
- assertThat(scd.getIED().size()).isNotZero();
- assertThat(scd.getIED().get(0).getName()).isEqualTo("IED_NAME1");
- assertThat(scd.getDataTypeTemplates()).isNotNull();
+
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd));
+ assertEquals("IED_NAME1", scd.getIED().get(0).getName());
+ assertNotNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
+
assertIsMarshallable(scd);
}
@Test
- void addSubnetworks_should_add_subnetwork() {
- //Given
+ void testAddSubnetworks() {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
+ assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
+
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd));
+
SubNetworkDTO subNetworkDTO = new SubNetworkDTO();
subNetworkDTO.setName("sName1");
subNetworkDTO.setType("IP");
- ConnectedApDTO connectedApDTO = new ConnectedApDTO();
- connectedApDTO.setApName("AP_NAME");
- connectedApDTO.setIedName("IED_NAME1");
+ ConnectedApDTO connectedApDTO = new ConnectedApDTO("IED_NAME1", "AP_NAME");
subNetworkDTO.addConnectedAP(connectedApDTO);
- //When Then
- assertThatCode(() -> SclService.addSubnetworks(scd, Set.of(subNetworkDTO), Optional.of(icd)).get()).doesNotThrowAnyException();
+
+ assertDoesNotThrow(() -> SclService.addSubnetworks(scd, List.of(subNetworkDTO), icd));
assertIsMarshallable(scd);
}
@Test
- void addSubnetworks_should_not_add_subnetwork_when_withoutCommunicationTagInIcd() {
- //Given
+ void testAddSubnetworksWithoutCommunicationTagInIcd() {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
+ assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
- //When Then
- assertThatCode(() -> SclService.addSubnetworks(scd, new HashSet<>(), Optional.of(icd))).doesNotThrowAnyException();
+
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd));
+
+ assertDoesNotThrow(() -> SclService.addSubnetworks(scd, List.of(), icd));
String marshalledScd = assertIsMarshallable(scd);
assertThat(marshalledScd).doesNotContain(" SclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
- //TODO not should appear in given section, only one When step
- Set subNetworkDTOSet = new HashSet<>(SclService.getSubnetwork(icd));
- //When Then
- assertThatCode(() -> SclService.addSubnetworks(scd, subNetworkDTOSet, Optional.of(icd))).doesNotThrowAnyException();
+
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd));
+
+ List subNetworkDTOSet = SclService.getSubnetwork(icd);
+ assertDoesNotThrow(() -> SclService.addSubnetworks(scd, subNetworkDTOSet, icd));
+
String marshalledScd = assertIsMarshallable(scd);
assertThat(marshalledScd).contains("", "PhysConn");
}
@Test
- void addSubnetworks_should_add_subnetwork_element_when_withoutImportingIcdAddressAndPhysConn() {
- //Given
+ void testAddSubnetworksWithoutImportingIcdAddressAndPhysConn() {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
+ assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_with_filled_communication.xml");
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
- //When Then
- Set subNetworkDTOSet = new HashSet<>(SclService.getSubnetwork(icd));
- assertThatCode(() -> SclService.addSubnetworks(scd, subNetworkDTOSet, Optional.empty())).doesNotThrowAnyException();
+
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd));
+
+ List subNetworkDTOSet = SclService.getSubnetwork(icd);
+ assertDoesNotThrow(() -> SclService.addSubnetworks(scd, subNetworkDTOSet, null));
+
String marshalledScd = assertIsMarshallable(scd);
assertThat(marshalledScd).doesNotContain("", "PhysConn");
}
@Test
- void getSubnetwork_should_return_list() {
- //Given
+ void testGetSubnetwork() {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
+ assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
+
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd));
+
SubNetworkDTO subNetworkDTO = new SubNetworkDTO();
subNetworkDTO.setName("sName1");
subNetworkDTO.setType("IP");
- ConnectedApDTO connectedApDTO = new ConnectedApDTO();
- connectedApDTO.setApName("AP_NAME");
- connectedApDTO.setIedName("IED_NAME1");
+ ConnectedApDTO connectedApDTO = new ConnectedApDTO("IED_NAME1", "AP_NAME");
subNetworkDTO.addConnectedAP(connectedApDTO);
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addSubnetworks(scd, Set.of(subNetworkDTO), Optional.of(icd))).doesNotThrowAnyException();
- //When
- List subNetworkDTOS = SclService.getSubnetwork(scd);
- //Then
- assertThat(subNetworkDTOS).hasSize(1);
+
+ assertDoesNotThrow(() -> SclService.addSubnetworks(scd, List.of(subNetworkDTO), icd));
+
+ List subNetworkDTOS = assertDoesNotThrow(() -> SclService.getSubnetwork(scd));
+ assertEquals(1, subNetworkDTOS.size());
}
@Test
- void getExtRefInfo_should_throw_exception_when_unknown_ldInst() {
- //Given
+ void testGetExtRefInfo() {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
+ assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
- //TODO not should appear in given section, only one When step
- var extRefInfos = SclService.getExtRefInfo(scd, "IED_NAME1", "LD_INST11");
- assertThat(extRefInfos).hasSize(1);
- assertThat(extRefInfos.get(0).getHolderIEDName()).isEqualTo("IED_NAME1");
- //When Then
- assertThatThrownBy(() -> SclService.getExtRefInfo(scd, "IED_NAME1", "UNKNOWN_LD"))
- .isInstanceOf(ScdException.class)
- .hasMessageContaining("Unknown LDevice (UNKNOWN_LD) in IED (IED_NAME1)");
+
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd));
+ var extRefInfos = assertDoesNotThrow(() -> SclService.getExtRefInfo(scd, "IED_NAME1", "LD_INST11"));
+ assertEquals(1, extRefInfos.size());
+
+ assertEquals("IED_NAME1", extRefInfos.get(0).getHolderIEDName());
+
+ assertThrows(ScdException.class, () -> SclService.getExtRefInfo(scd, "IED_NAME1", "UNKNOWN_LD"));
}
@Test
- void getExtRefBinders_shouldThrowScdException_whenExtRefNotExist() {
+ void getExtRefBinders_shouldThowScdException_whenExtRefNotExist() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_binders_test.xml");
@@ -280,18 +267,15 @@ void getExtRefBinders_shouldReturnSortedListBindingInfo_whenExtRefAndDOExist() {
}
@Test
- void updateExtRefBinders_should_not_throw_exception() {
- //Given
+ void testUpdateExtRefBinders() {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
- assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
+ assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates());
SCL icd1 = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
SCL icd2 = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_2_test.xml");
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME1", icd1)).doesNotThrowAnyException();
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.addIED(scd, "IED_NAME2", icd2)).doesNotThrowAnyException();
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME1", icd1));
+ assertDoesNotThrow(() -> SclService.addIED(scd, "IED_NAME2", icd2));
ExtRefSignalInfo signalInfo = createSignalInfo(
"Do11.sdo11", "da11.bda111.bda112.bda113", "INT_ADDR11"
@@ -319,11 +303,15 @@ void updateExtRefBinders_should_not_throw_exception() {
extRefInfo.setBindingInfo(bindingInfo);
lNodeDTO.getExtRefs().add(extRefInfo);
- //TODO not should appear in given section, only one When step
- assertThatCode(() -> SclService.updateExtRefBinders(scd, extRefInfo)).doesNotThrowAnyException();
+ assertDoesNotThrow(
+ () -> SclService.updateExtRefBinders(scd, extRefInfo)
+ );
+
extRefInfo.setHolderLDInst("UNKNOWN_LD");
- //When Then
- assertThatThrownBy(() -> SclService.updateExtRefBinders(scd, extRefInfo)).isInstanceOf(ScdException.class);
+ assertThrows(
+ ScdException.class,
+ () -> SclService.updateExtRefBinders(scd, extRefInfo)
+ );
assertIsMarshallable(scd);
}
@@ -339,7 +327,7 @@ void getExtRefSourceInfo_shouldReturnEmptyList_whenExtRefMatchNoFCDA() {
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iedAdapter.findLDeviceAdapterByLdInst(ldInst).get());
LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter();
List extRefs = ln0Adapter.getExtRefs(null);
- assertThat(extRefs.isEmpty()).isFalse();
+ assertFalse(extRefs.isEmpty());
ExtRefInfo extRefInfo = new ExtRefInfo(extRefs.get(0));
@@ -366,7 +354,7 @@ void getExtRefSourceInfo_shouldReturnListOfControlBlocks_whenExtRefMatchFCDA() {
LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iedAdapter.findLDeviceAdapterByLdInst(ldInst).get());
LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter();
List extRefs = ln0Adapter.getExtRefs(null);
- assertThat(extRefs).isNotEmpty();
+ assertFalse(extRefs.isEmpty());
ExtRefInfo extRefInfo = new ExtRefInfo(extRefs.get(0));
@@ -391,13 +379,11 @@ void updateExtRefSource_shouldThrowScdException_whenSignalInfoNullOrInvalid() {
extRefInfo.setHolderLDInst("LD_INST21");
extRefInfo.setHolderLnClass(TLLN0Enum.LLN_0.value());
- //TODO not should appear in given section, only one When step
//When Then
assertThat(extRefInfo.getSignalInfo()).isNull();
assertThatThrownBy(() -> SclService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class); // signal = null
extRefInfo.setSignalInfo(new ExtRefSignalInfo());
assertThat(extRefInfo.getSignalInfo()).isNotNull();
- //When Then
assertThatThrownBy(() -> SclService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class);// signal invalid
}
@@ -415,14 +401,11 @@ void updateExtRefSource_shouldThrowScdException_whenBindingInfoNullOrInvalid() {
extRefSignalInfo.setPDA("da21.bda211.bda212.bda213");
extRefSignalInfo.setPDO("Do21.sdo21");
extRefInfo.setSignalInfo(extRefSignalInfo);
-
- //TODO only one When step (updateExtRefSource called twice)
//When Then
assertThat(extRefInfo.getBindingInfo()).isNull();
assertThatThrownBy(() -> SclService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class); // binding = null
extRefInfo.setBindingInfo(new ExtRefBindingInfo());
assertThat(extRefInfo.getBindingInfo()).isNotNull();
- //When Then
assertThatThrownBy(() -> SclService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class);// binding invalid
}
@@ -496,13 +479,11 @@ void updateExtRefSource_shouldThrowScdException_whenSourceInfoNullOrInvalid() {
extRefBindingInfo.setLnClass(TLLN0Enum.LLN_0.value());
extRefInfo.setBindingInfo(new ExtRefBindingInfo());
- //TODO only one When step (updateExtRefSource called twice)
//When Then
assertThat(extRefInfo.getSourceInfo()).isNull();
assertThatThrownBy(() -> SclService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class); // signal = null
extRefInfo.setSourceInfo(new ExtRefSourceInfo());
assertThat(extRefInfo.getSourceInfo()).isNotNull();
- //When Then
assertThatThrownBy(() -> SclService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class);// signal invalid
}
@@ -634,8 +615,8 @@ void getDAI_when_LDevice_not_found_should_throw_exception() {
// when & then
DataAttributeRef dataAttributeRef = new DataAttributeRef();
- assertThatThrownBy(() -> SclService.getDAI(scd, "IED_NAME1", "UNKNOWNLD", dataAttributeRef, true))
- .isInstanceOf(ScdException.class);
+ assertThrows(ScdException.class,
+ () -> SclService.getDAI(scd, "IED_NAME1", "UNKNOWNLD", dataAttributeRef, true));
}
@Test
@@ -746,26 +727,18 @@ void getDAI_should_filter_updatable_DA_with_sGroup_Val_without_ConfSg() {
}
@Test
- void initScl_shouldNotThrowError() {
- SCL scd = assertDoesNotThrow(() -> SclService.initScl(Optional.empty(), "hVersion", "hRevision"));
- assertIsMarshallable(scd);
- }
-
- @Test
- void initScl_shouldNotThrowError_when_hId_provided() {
- // Given
- UUID hid = UUID.randomUUID();
- // When Then
- SCL scd = assertDoesNotThrow(() -> SclService.initScl(Optional.of(hid), "hVersion", "hRevision"));
+ void testInitScl_With_headerId_shouldNotThrowError() {
+ UUID headerId = UUID.randomUUID();
+ SCL scd = assertDoesNotThrow(() -> SclService.initScl(headerId, "hVersion", "hRevision"));
assertIsMarshallable(scd);
}
@Test
void initScl_should_create_Private_SCL_FILETYPE() {
// Given
- UUID hid = UUID.randomUUID();
+ UUID headerId = UUID.randomUUID();
// When Then
- SCL scd = assertDoesNotThrow(() -> SclService.initScl(Optional.of(hid), "hVersion", "hRevision"));
+ SCL scd = assertDoesNotThrow(() -> SclService.initScl(headerId, "hVersion", "hRevision"));
assertThat(scd.getPrivate()).isNotEmpty();
assertThat(scd.getPrivate().get(0).getType()).isEqualTo(COMPAS_SCL_FILE_TYPE.getPrivateType());
assertIsMarshallable(scd);
@@ -774,7 +747,7 @@ void initScl_should_create_Private_SCL_FILETYPE() {
@Test
void updateHeader_should_update_header_tag() {
//Given
- SCL scd = assertDoesNotThrow(() -> SclService.initScl(Optional.empty(), "hVersion", "hRevision"));
+ SCL scd = assertDoesNotThrow(() -> SclService.initScl(UUID.randomUUID(), "hVersion", "hRevision"));
UUID hId = UUID.fromString(scd.getHeader().getId());
HeaderDTO headerDTO = DTO.createHeaderDTO(hId);
//When
@@ -784,13 +757,14 @@ void updateHeader_should_update_header_tag() {
}
@Test
- void updateDAI_should_not_throw_error() {
+ void testUpdateDAI() {
DataAttributeRef dataAttributeRef = new DataAttributeRef();
dataAttributeRef.setLnType("unknownID");
SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml");
- //TODO not should appear in given section
- assertThatThrownBy(() -> SclService.updateDAI(scd, "IED", "LD", dataAttributeRef))
- .isInstanceOf(ScdException.class);
+
+ assertThrows(ScdException.class, () -> SclService.updateDAI(
+ scd, "IED", "LD", dataAttributeRef
+ ));
dataAttributeRef.setLnType("LNO1");
dataAttributeRef.setLnClass(TLLN0Enum.LLN_0.value());
DoTypeName doTypeName = new DoTypeName("Do.sdo1.d");
@@ -799,95 +773,89 @@ void updateDAI_should_not_throw_error() {
TVal tVal = new TVal();
tVal.setValue("newValue");
dataAttributeRef.setDaiValues(List.of(tVal));
- //When Then
- assertThatCode(() -> SclService.updateDAI(scd, "IED_NAME", "LD_INS1", dataAttributeRef)).doesNotThrowAnyException();
+ assertDoesNotThrow(() -> SclService.updateDAI(scd, "IED_NAME", "LD_INS1", dataAttributeRef));
assertIsMarshallable(scd);
}
@Test
- void getEnumTypeElements_should_return_list() {
- //Given
+ void testGetEnumTypeValues() {
SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
- //TODO not should appear in given section
- assertThatThrownBy(() -> SclService.getEnumTypeElements(scd, "unknwnID"))
- .isInstanceOf(ScdException.class);
- //When Then
- var enumList = assertDoesNotThrow(() -> SclService.getEnumTypeElements(scd, "RecCycModKind"));
- assertThat(enumList).isNotEmpty();
+ assertThrows(ScdException.class, () -> SclService.getEnumTypeValues(scd, "unknwnID"));
+ var enumList = assertDoesNotThrow(() -> SclService.getEnumTypeValues(scd, "RecCycModKind"));
+ assertFalse(enumList.isEmpty());
}
@Test
- void importSTDElementsInSCD_should_std_files_is_scd() {
- //Given
+ void testImportSTDElementsInSCD() {
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
- //When Then
- SCL expectedScd = assertDoesNotThrow(() -> SclService.importSTDElementsInSCD(scd, List.of(std), DTO.comMap));
- assertThat(expectedScd.getIED()).hasSize(1);
- assertThat(expectedScd.getDataTypeTemplates()).hasNoNullFieldsOrProperties();
- assertThat(expectedScd.getCommunication().getSubNetwork()).hasSize(2);
+
+ assertDoesNotThrow(() -> SclService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES));
+ assertThat(scd.getIED()).hasSize(1);
+ assertThat(scd.getDataTypeTemplates()).hasNoNullFieldsOrProperties();
+ assertThat(scd.getCommunication().getSubNetwork()).hasSize(2);
assertIsMarshallable(scd);
}
@Test
- void importSTDElementsInSCD_shouldNotThrowException_when_with_Multiple_STD() {
+ void testImportSTDElementsInSCD_with_Multiple_STD() {
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd_lnode_with_many_compas_icdheader.xml");
SCL std0 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
SCL std1 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std_SITESITE1SCU1.xml");
SCL std2 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std_SITESITE1SCU2.xml");
-
- SCL expectedScd = assertDoesNotThrow(() -> SclService.importSTDElementsInSCD(scd, List.of(std0, std1, std2), DTO.comMap));
- assertThat(expectedScd.getIED()).hasSize(3);
- assertThat(expectedScd.getDataTypeTemplates()).hasNoNullFieldsOrProperties();
- assertThat(expectedScd.getCommunication().getSubNetwork()).hasSize(2);
- assertThat(expectedScd.getCommunication().getSubNetwork().get(0).getConnectedAP()).hasSizeBetween(1, 3);
- assertThat(expectedScd.getCommunication().getSubNetwork().get(1).getConnectedAP()).hasSizeBetween(1, 3);
+ SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
+
+ assertDoesNotThrow(() -> SclService.importSTDElementsInSCD(scd, List.of(std0, std1, std2), DTO.SUB_NETWORK_TYPES));
+ assertThat(scd.getIED()).hasSize(3);
+ assertThat(scd.getDataTypeTemplates()).hasNoNullFieldsOrProperties();
+ assertThat(scd.getCommunication().getSubNetwork()).hasSize(2);
+ assertThat(scd.getCommunication().getSubNetwork().get(0).getConnectedAP()).hasSizeBetween(1, 3);
+ assertThat(scd.getCommunication().getSubNetwork().get(1).getConnectedAP()).hasSizeBetween(1, 3);
assertIsMarshallable(scd);
}
@Test
- void importSTDElementsInSCD_shouldThrowException_when_Several_STD_Match_Compas_ICDHeader() {
+ void testImportSTDElementsInSCD_Several_STD_Match_Compas_ICDHeader() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
SCL std1 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
//When Then
List stds = List.of(std, std1);
- assertThatThrownBy(() -> SclService.importSTDElementsInSCD(scd, stds, DTO.comMap))
- .isInstanceOf(ScdException.class);
+ assertThrows(ScdException.class, () -> SclService.importSTDElementsInSCD(scd, stds, DTO.SUB_NETWORK_TYPES));
assertIsMarshallable(scd);
}
@Test
- void importSTDElementsInSCD_should_not_throw_exception_when_SCD_file_contains_same_ICDHeader_in_two_different_functions() {
+ void test_importSTDElementsInSCD_should_not_throw_exception_when_SCD_file_contains_same_ICDHeader_in_two_different_functions() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd_with_same_compas_icd_header_in_different_functions.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
//When Then
- assertThatCode(() -> SclService.importSTDElementsInSCD(scd, List.of(std), DTO.comMap)).doesNotThrowAnyException();
+ assertDoesNotThrow(() -> SclService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES));
assertIsMarshallable(scd);
}
@Test
- void importSTDElementsInSCD_should_throw_exception_when_Compas_ICDHeader_Not_Match() {
+ void testImportSTDElementsInSCD_Compas_ICDHeader_Not_Match() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std_with_same_ICDSystemVersionUUID.xml");
+ SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
//When Then
- List stds = List.of(std);
- assertThatThrownBy(() -> SclService.importSTDElementsInSCD(scd, stds, DTO.comMap))
- .isInstanceOf(ScdException.class);
+ assertThrows(ScdException.class, () -> SclService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES));
assertIsMarshallable(scd);
}
@Test
- void importSTDElementsInSCD_should_throw_exception_when_No_STD_Match() {
+ void testImportSTDElementsInSCD_No_STD_Match() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml");
+ SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
//When Then
- assertThatCode(() -> SclService.importSTDElementsInSCD(scd, List.of(), DTO.comMap))
- .isInstanceOf(ScdException.class)
- .hasMessage("There is no STD file found corresponding to headerId = f8dbc8c1-2db7-4652-a9d6-0b414bdeccfa, headerVersion = 01.00.00, headerRevision = 01.00.00 and ICDSystemVersionUUID = IED4d4fe1a8cda64cf88a5ee4176a1a0eef");
+ Set stds = new HashSet<>();
+ assertThrows(ScdException.class, () -> SclService.importSTDElementsInSCD(scd, List.of(), DTO.SUB_NETWORK_TYPES));
+ assertIsMarshallable(scd);
}
@Test
@@ -958,8 +926,8 @@ void removeControlBlocksAndDatasetAndExtRefSrc_should_remove_srcXXX_attributes_o
@MethodSource("sclProviderMissingRequiredObjects")
void updateLDeviceStatus_shouldReturnReportWithError_MissingRequiredObject(String testCase, SCL scl, Tuple... errors) {
// Given
- assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED")).isPresent();
- assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
+ assertTrue(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").isPresent());
+ assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue());
String before = MarshallerWrapper.marshall(scl);
// When
List sclReportItems = SclService.updateLDeviceStatus(scl);
@@ -1026,7 +994,6 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceInactive_Test
void updateLDeviceStatus_shouldReturnUpdatedFile() {
// Given
SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_Template.scd");
-
assertThat(getLDeviceStatusValue(givenScl, "IedName1", "LDSUIED")).isPresent();
assertThat(getLDeviceStatusValue(givenScl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
assertThat(getLDeviceStatusValue(givenScl, "IedName2", "LDSUIED")).isPresent();
@@ -1064,7 +1031,6 @@ void updateLDeviceStatus_shouldReturnUpdatedFile_when_DAI_Mod_DO_stVal_whatever_
assertThat(getLDeviceStatusValue(givenScl, "IedName5", "LDSUIED"))
.map(TVal::getValue)
.hasValue("on");
-
// When
List sclReportItems = SclService.updateLDeviceStatus(givenScl);
@@ -1183,10 +1149,12 @@ void analyzeDataGroups_should_success() {
List sclReportItems = SclService.analyzeDataGroups(scd);
//Then
assertThat(sclReportItems).isEmpty();
+
}
@Test
void analyzeDataGroups_should_return_errors_messages() {
+
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/limitation_cb_dataset_fcda/scd_check_limitation_bound_ied_controls_fcda.xml");
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
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 987b8b268..522ecd2c4 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
@@ -64,10 +64,9 @@ void testCopyAddressAndPhysConnFromIcd_withFilledCommunication() {
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_with_filled_communication.xml");
SclRootAdapter icdRootAdapter = new SclRootAdapter(icd);
- Optional opIcd = Optional.of(icdRootAdapter.getCurrentElem());
// WHEN
- connectedAPAdapter.copyAddressAndPhysConnFromIcd(opIcd);
+ connectedAPAdapter.copyAddressAndPhysConnFromIcd(icdRootAdapter.getCurrentElem());
// THEN
assertThat(connectedAPAdapter.getCurrentElem().getAddress()).isNotNull();
@@ -81,10 +80,9 @@ void testCopyAddressAndPhysConnFromIcd_withEmptyIcd() {
ConnectedAPAdapter connectedAPAdapter = assertDoesNotThrow(
() -> subNetworkAdapter.getConnectedAPAdapter(DTO.HOLDER_IED_NAME, DTO.AP_NAME)
);
- Optional opIcd = Optional.empty();
// WHEN
- connectedAPAdapter.copyAddressAndPhysConnFromIcd(opIcd);
+ connectedAPAdapter.copyAddressAndPhysConnFromIcd(null);
// THEN
assertThat(connectedAPAdapter.getCurrentElem().getAddress()).isNull();
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 10f47e1b8..9889c6c5b 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
@@ -56,8 +56,7 @@ void elementXPath_should_succeed() {
void updateAllSourceDataSetsAndControlBlocks_should_report_Target_Ied_missing_Private_compasBay_errors() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_ied_errors.xml");
- SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
- InputsAdapter inputsAdapter = findInputs(sclRootAdapter.getCurrentElem(), "IED_NAME1", "LD_INST11");
+ InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME1", "LD_INST11");
// When
List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks();
// Then
@@ -71,8 +70,7 @@ void updateAllSourceDataSetsAndControlBlocks_should_report_Target_Ied_missing_Pr
void updateAllSourceDataSetsAndControlBlocks_should_report_Source_Ied_missing_Private_compasBay_errors() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_ied_errors.xml");
- SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
- InputsAdapter inputsAdapter = findInputs(sclRootAdapter.getCurrentElem(), "IED_NAME3", "LD_INST31");
+ InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME3", "LD_INST31");
// When
List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks();
// Then
@@ -87,8 +85,7 @@ void updateAllSourceDataSetsAndControlBlocks_should_report_Source_Ied_missing_Pr
void updateAllSourceDataSetsAndControlBlocks_should_report_ExtRef_attribute_missing() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_extref_errors.xml");
- SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
- InputsAdapter inputsAdapter = findInputs(sclRootAdapter.getCurrentElem(), "IED_NAME1", "LD_INST11");
+ InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME1", "LD_INST11");
// When
List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks();
// Then
@@ -109,8 +106,7 @@ void updateAllSourceDataSetsAndControlBlocks_should_report_ExtRef_attribute_miss
void updateAllSourceDataSetsAndControlBlocks_should_succeed() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml");
- SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
- InputsAdapter inputsAdapter = findInputs(sclRootAdapter.getCurrentElem(), "IED_NAME1", "LD_INST11");
+ InputsAdapter inputsAdapter = findInputs(scd, "IED_NAME1", "LD_INST11");
// When
List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks();
// Then
From 74441fd2917efed95fe93988771f3ef4a587f449 Mon Sep 17 00:00:00 2001
From: Samir Romdhani
Date: Wed, 9 Aug 2023 16:29:14 +0200
Subject: [PATCH 3/4] review feedback
Signed-off-by: Samir Romdhani
revert changes related to other issue (Refactor tests structure in compas-sct)
Signed-off-by: Samir Romdhani
---
.../org/lfenergy/compas/sct/commons/dto/ConnectedApDTO.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTO.java
index 3fdaf1500..475cdb5cc 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTO.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTO.java
@@ -6,6 +6,8 @@
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;
+import java.util.Objects;
+
/**
* A representation of the model object Connected AP.
*
From ef3c8b6b17fcd898667df71dfb5058773f784aad Mon Sep 17 00:00:00 2001
From: Samir Romdhani
Date: Fri, 11 Aug 2023 18:33:23 +0200
Subject: [PATCH 4/4] feat: rename SclReportItem#fatal to SclReportItem#error
Signed-off-by: Samir Romdhani
---
.../compas/sct/commons/dto/SclReportItem.java | 18 ++--------
.../compas/sct/commons/scl/ExtRefService.java | 2 +-
.../sct/commons/scl/SclElementAdapter.java | 2 +-
.../commons/scl/ied/AccessPointAdapter.java | 10 +++---
.../sct/commons/scl/ied/InputsAdapter.java | 4 +--
.../sct/commons/scl/ied/LDeviceAdapter.java | 6 ++--
.../sct/commons/scl/ExtRefServiceTest.java | 34 +++++++++----------
.../sct/commons/scl/SclServiceTest.java | 26 +++++++-------
.../scl/ied/AccessPointAdapterTest.java | 16 ++++-----
.../sct/commons/scl/ied/DOIAdapterTest.java | 6 ++--
.../sct/commons/scl/ied/IEDAdapterTest.java | 8 ++---
.../commons/scl/ied/InputsAdapterTest.java | 12 +++----
.../commons/scl/ied/LDeviceAdapterTest.java | 8 ++---
.../sct/commons/scl/ied/LN0AdapterTest.java | 6 ++--
14 files changed, 73 insertions(+), 85 deletions(-)
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReportItem.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReportItem.java
index ad0ac0596..b7a3f03eb 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReportItem.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SclReportItem.java
@@ -1,24 +1,12 @@
-// SPDX-FileCopyrightText: 2022 RTE FRANCE
+// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.sct.commons.dto;
-import lombok.AllArgsConstructor;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.ToString;
+public record SclReportItem(String xpath, String message, boolean isError) {
-@Getter
-@EqualsAndHashCode
-@AllArgsConstructor
-@ToString
-public final class SclReportItem {
- private final String xpath;
- private final String message;
- private final boolean isFatal;
-
- public static SclReportItem fatal(String xpath, String message) {
+ public static SclReportItem error(String xpath, String message) {
return new SclReportItem(xpath, message, true);
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java
index c5a8c2529..00ccd1b23 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java
@@ -95,7 +95,7 @@ private static List checkIedUnityOfIcdSystemVersionUuid(SclRootAd
return systemVersionToIedList.entrySet().stream()
.filter(entry -> StringUtils.isNotBlank(entry.getKey()))
.filter(entry -> entry.getValue().size() > 1)
- .map(entry -> SclReportItem.fatal(entry.getValue().stream()
+ .map(entry -> SclReportItem.error(entry.getValue().stream()
.map(tied -> new IEDAdapter(sclRootAdapter, tied))
.map(IEDAdapter::getXPath)
.collect(Collectors.joining(", ")),
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclElementAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclElementAdapter.java
index 47c07085f..e90297d47 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclElementAdapter.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclElementAdapter.java
@@ -123,6 +123,6 @@ public String getXPath(){
* @return error description with message and current element xpath
*/
public SclReportItem buildFatalReportItem(String message){
- return SclReportItem.fatal(getXPath(), message);
+ return SclReportItem.error(getXPath(), message);
}
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java
index 6b00ec4d8..bc54fe6bf 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java
@@ -90,7 +90,7 @@ public List