From ec11781fb16948059863cdb372f3c41ceb116438 Mon Sep 17 00:00:00 2001 From: Samir Romdhani Date: Fri, 11 Aug 2023 18:01:33 +0200 Subject: [PATCH] refactor tests structure, closes #107, #196, #306 refactor test code to use AssertJ and using Gherkin to define scenarios remove TODOs related to isolated test rule: another issue will cover that update SclRootAdapterTest update RootSDIAdapterTest & SDIAdapterTest update LNAdapterTest refactor(#107, #196, #306): add tag to tests that should be respect isolation principal and best practice update LN0AdapterTest, LNAdapterTest, SDIAdapterTest.. update test classes in scl.com package update HeaderAdapterTesT update test classes in scl.dtt package update ExtRefServiceTest update test classes in scl.sstation package update class name AbstractDTTLevel to DataTypeTemplateTestUtils update test classes in scl.ied package add tag in ExtRefServiceTest update InputsAdapterTest update IEDAdapterTest update DOIAdapterTest update DataSetAdapterTest update DAITrackerTest update ControlBlockAdapterTest update AccessPointAdapterTest Signed-off-by: Samir Romdhani add Tag=issue-321 to tests that should be isolated and respect F(I)RST principles of testing. Signed-off-by: Samir Romdhani update test classes in commons.dto package Signed-off-by: Samir Romdhani update test classes in commons.util package Signed-off-by: Samir Romdhani update ObjectReferenceTest Signed-off-by: Samir Romdhani update SclElementsProviderServiceTest Signed-off-by: Samir Romdhani update sct app module Signed-off-by: Samir Romdhani update ScdExceptionTest Signed-off-by: Samir Romdhani update sct data module Signed-off-by: Samir Romdhani sonar review Signed-off-by: Samir Romdhani update test method name Signed-off-by: Samir Romdhani refactor tests structure :review Signed-off-by: Samir Romdhani refactor tests structure :review - same test name pattern Signed-off-by: Samir Romdhani refactor tests structure: remove unused SclMockedElement class Signed-off-by: Samir Romdhani --- .../SclAutomationServiceIntegrationTest.java | 49 +- .../SclAutomationServiceTest.java | 10 +- .../sct/commons/scl/dtt/LNodeTypeAdapter.java | 2 +- .../compas/sct/commons/ExtRefServiceTest.java | 45 +- .../sct/commons/SclEditorServiceTest.java | 178 ++++--- .../SclElementsProviderServiceTest.java | 78 +-- .../sct/commons/SubstationServiceTest.java | 2 +- .../sct/commons/dto/ConnectedApDTOTest.java | 22 +- .../commons/dto/ControlBlockTargetTest.java | 4 +- .../sct/commons/dto/DaTypeNameTest.java | 26 +- .../sct/commons/dto/DataAttributeRefTest.java | 113 ++-- .../sct/commons/dto/DataSetInfoTest.java | 36 +- .../sct/commons/dto/DoTypeNameTest.java | 24 +- .../commons/dto/ExtRefBindingInfoTest.java | 112 ++-- .../sct/commons/dto/ExtRefInfoTest.java | 37 +- .../sct/commons/dto/ExtRefSignalInfoTest.java | 80 +-- .../sct/commons/dto/ExtRefSourceInfoTest.java | 20 +- .../compas/sct/commons/dto/FCDAInfoTest.java | 39 +- .../compas/sct/commons/dto/HeaderDTOTest.java | 52 +- .../compas/sct/commons/dto/IedDTOTest.java | 35 +- .../sct/commons/dto/LDEPFSettingDataTest.java | 20 +- .../sct/commons/dto/LDeviceDTOTest.java | 41 +- .../compas/sct/commons/dto/LNodeDTOTest.java | 96 ++-- .../commons/dto/LogicalNodeOptionsTest.java | 42 +- .../commons/dto/ReportControlBlockTest.java | 60 ++- .../sct/commons/dto/SMVControlBlockTest.java | 4 +- .../compas/sct/commons/dto/SclDTOTest.java | 93 ++-- .../sct/commons/dto/SubNetworkDTOTest.java | 33 +- .../commons/exception/ScdExceptionTest.java | 24 +- .../sct/commons/scl/ObjectReferenceTest.java | 33 +- .../sct/commons/scl/SclMockedElement.java | 18 - .../sct/commons/scl/SclRootAdapterTest.java | 72 ++- .../sct/commons/scl/com/AbstractComLevel.java | 23 - .../scl/com/CommunicationAdapterTest.java | 103 ++-- .../scl/com/ConnectedAPAdapterTest.java | 107 ++-- .../scl/com/SubNetworkAdapterTest.java | 80 ++- .../sct/commons/scl/dtt/AbstractDTTLevel.java | 45 -- .../sct/commons/scl/dtt/BDAAdapterTest.java | 151 +++--- .../sct/commons/scl/dtt/DAAdapterTest.java | 106 ++-- .../commons/scl/dtt/DATypeAdapterTest.java | 201 ++++--- .../sct/commons/scl/dtt/DOAdapterTest.java | 16 +- .../commons/scl/dtt/DOTypeAdapterTest.java | 212 +++++--- .../scl/dtt/DataTypeTemplateAdapterTest.java | 493 +++++++++++------- .../scl/dtt/DataTypeTemplateTestUtils.java | 26 + .../commons/scl/dtt/EnumTypeAdapterTest.java | 102 ++-- .../commons/scl/dtt/LNodeTypeAdapterTest.java | 280 +++++----- .../commons/scl/header/HeaderAdapterTest.java | 108 ++-- .../sct/commons/scl/icd/IcdHeaderTest.java | 6 +- .../scl/ied/AccessPointAdapterTest.java | 31 +- .../scl/ied/ControlBlockAdapterTest.java | 15 +- .../sct/commons/scl/ied/DAITrackerTest.java | 156 ++++-- .../sct/commons/scl/ied/DOIAdapterTest.java | 141 ++--- .../commons/scl/ied/DataSetAdapterTest.java | 35 +- .../sct/commons/scl/ied/IEDAdapterTest.java | 174 ++++--- .../commons/scl/ied/InputsAdapterTest.java | 12 +- .../commons/scl/ied/LDeviceAdapterTest.java | 135 +++-- .../sct/commons/scl/ied/LN0AdapterTest.java | 363 ++++++++----- .../sct/commons/scl/ied/LNAdapterTest.java | 168 +++--- .../commons/scl/ied/RootSDIAdapterTest.java | 54 +- .../sct/commons/scl/ied/SDIAdapterTest.java | 58 ++- .../commons/scl/sstation/BayAdapterTest.java | 85 +-- .../scl/sstation/FunctionAdapterTest.java | 9 +- .../scl/sstation/LNodeAdapterTest.java | 11 +- .../scl/sstation/SubstationAdapterTest.java | 85 +-- .../scl/sstation/VoltageLevelAdapterTest.java | 81 +-- .../commons/util/ControlBlockEnumTest.java | 10 +- .../commons/util/LdeviceStatusEnumTest.java | 4 +- .../sct/commons/util/PrivateUtilsTest.java | 75 ++- .../util/SettingLDEPFCsvHelperTest.java | 40 +- .../compas/sct/commons/util/UtilsTest.java | 53 +- sct-data/pom.xml | 5 + .../CompasDataAccessExceptionTest.java | 15 +- 72 files changed, 3178 insertions(+), 2196 deletions(-) delete mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclMockedElement.java delete mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/AbstractComLevel.java delete mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/AbstractDTTLevel.java create mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateTestUtils.java diff --git a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java index 1a10626f2..9beb9195a 100644 --- a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java +++ b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java @@ -23,8 +23,7 @@ import java.util.List; import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; class SclAutomationServiceIntegrationTest { @@ -52,17 +51,17 @@ void createSCD_should_return_generatedSCD() { // When SCL scd = sclAutomationService.createSCD(ssd, headerDTO, List.of(std)); // Then - assertNotNull(scd.getHeader().getId()); - assertNull(scd.getHeader().getHistory()); - assertEquals(1, scd.getSubstation().size()); - assertEquals(1, scd.getIED().size()); - assertNotNull(scd.getDataTypeTemplates()); - assertEquals(2, scd.getCommunication().getSubNetwork().size()); + assertThat(scd.getHeader().getId()).isNotNull(); + assertThat(scd.getHeader().getHistory()).isNull(); + assertThat(scd.getSubstation()).hasSize(1); + assertThat(scd.getIED()).hasSize(1); + assertThat(scd.getDataTypeTemplates()).isNotNull(); + assertThat(scd.getCommunication().getSubNetwork()).hasSize(2); assertIsMarshallable(scd); } @Test - void createSCD_With_HItem() { + void createSCD_WithHItem_should_return_generatedSCD() { // Given HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem(); historyItem.setWhat("what"); @@ -76,14 +75,14 @@ void createSCD_With_HItem() { // When SCL scd = sclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3)); // Then - assertNotNull(scd.getHeader().getId()); - assertEquals(1, scd.getHeader().getHistory().getHitem().size()); - assertEquals(1, scd.getSubstation().size()); + assertThat(scd.getHeader().getId()).isNotNull(); + assertThat(scd.getHeader().getHistory().getHitem()).hasSize(1); + assertThat(scd.getSubstation()).hasSize(1); assertIsMarshallable(scd); } @Test - void createSCD_With_HItems() { + void createSCD_WithManyHItem_should_return_generatedSCD() { // Given HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem(); historyItem.setWhat("what"); @@ -101,24 +100,24 @@ void createSCD_With_HItems() { // When SCL scd = sclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3)); // Then - assertNotNull(scd.getHeader().getId()); - assertEquals(1, scd.getHeader().getHistory().getHitem().size()); - assertEquals("what", scd.getHeader().getHistory().getHitem().get(0).getWhat()); + assertThat(scd.getHeader().getId()).isNotNull(); + assertThat(scd.getHeader().getHistory().getHitem()).hasSize(1); + assertThat(scd.getHeader().getHistory().getHitem().get(0).getWhat()).isEqualTo("what"); assertIsMarshallable(scd); } @Test - void createSCD_SSD_Without_Substation() { + void createSCD_whenSSDWithoutSubstation_shouldThrowException() { // Given SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml"); // When & Then List stdListEmpty = List.of(); - assertThrows(ScdException.class, - () -> sclAutomationService.createSCD(ssd, headerDTO, stdListEmpty)); + assertThatThrownBy(() -> sclAutomationService.createSCD(ssd, headerDTO, stdListEmpty)) + .isInstanceOf(ScdException.class); } @Test - void createSCD_should_throw_exception_when_null_ssd() { + void createSCD_whenSSDIsNull_shouldThrowException() { // Given HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem(); historyItem.setWhat("what"); @@ -129,18 +128,20 @@ void createSCD_should_throw_exception_when_null_ssd() { List stdList = List.of(std1); // When & Then - assertThrows(NullPointerException.class, () -> sclAutomationService.createSCD(null, headerDTO, stdList)); + assertThatCode(() -> sclAutomationService.createSCD(null, headerDTO, stdList)) + .isInstanceOf(NullPointerException.class); } @Test - void createSCD_should_throw_exception_when_null_headerDTO() { + void createSCD_whenheaderDTOIsNull_shouldThrowException() { // Given SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml"); SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml"); List stdList = List.of(std1); // When & Then - assertThrows(NullPointerException.class, () -> sclAutomationService.createSCD(ssd, null, stdList)); + assertThatCode(() -> sclAutomationService.createSCD(ssd, null, stdList)) + .isInstanceOf(NullPointerException.class); } @Test @@ -160,7 +161,7 @@ void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() { assertThat(ln0.getDataSet()).isEmpty(); assertThat(ln0.getInputs().getExtRef()).hasSize(2); - assertFalse(ln0.getInputs().getExtRef().get(0).isSetSrcLDInst()); + assertThat(ln0.getInputs().getExtRef().get(0).isSetSrcLDInst()).isFalse(); assertIsMarshallable(scd); } 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 f9e64e100..f2b03508c 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 @@ -114,7 +114,7 @@ void createSCD_with_headerHistory_should_return_generatedSCD() throws Invocation } @Test - void createSCD_should_throw_exception_when_sclEditor_initScl_Fail() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { + void createSCD_when_sclEditor_initScl_Fail_should_throw_exception() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { // Given SCL ssd = (SCL) BeanUtils.cloneBean(scl); SCL std = (SCL) BeanUtils.cloneBean(scl); @@ -126,7 +126,7 @@ void createSCD_should_throw_exception_when_sclEditor_initScl_Fail() throws Invoc } @Test - void createSCD_should_throw_exception_when_sclEditor_addHistoryItem_Fail() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { + void createSCD_when_sclEditor_addHistoryItem_Fail_should_throw_exception() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { // Given SCL ssd = (SCL) BeanUtils.cloneBean(scl); SCL std = (SCL) BeanUtils.cloneBean(scl); @@ -140,7 +140,7 @@ void createSCD_should_throw_exception_when_sclEditor_addHistoryItem_Fail() throw } @Test - void createSCD_should_throw_exception_when_substationEditor_addSubstation_Fail() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { + void createSCD_when_substationEditor_addSubstation_Fail_should_throw_exception() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { // Given SCL ssd = (SCL) BeanUtils.cloneBean(scl); SCL std = (SCL) BeanUtils.cloneBean(scl); @@ -155,7 +155,7 @@ void createSCD_should_throw_exception_when_substationEditor_addSubstation_Fail() } @Test - void createSCD_should_throw_exception_when_sclEditor_importSTDElementsInSCD_Fail() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { + void createSCD_when_sclEditor_importSTDElementsInSCD_Fail_should_throw_exception() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { // Given SCL ssd = (SCL) BeanUtils.cloneBean(scl); SCL std = (SCL) BeanUtils.cloneBean(scl); @@ -172,7 +172,7 @@ void createSCD_should_throw_exception_when_sclEditor_importSTDElementsInSCD_Fail } @Test - void createSCD_should_throw_exception_when_sclEditor_removeAllControlBlocksAndDatasetsAndExtRefSrcBindings_Fail() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { + void createSCD_when_sclEditor_removeAllControlBlocksAndDatasetsAndExtRefSrcBindings_Fail_should_throw_exception() throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { // Given SCL ssd = (SCL) BeanUtils.cloneBean(scl); SCL std = (SCL) BeanUtils.cloneBean(scl); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java index 7e27d6c77..8debf101b 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java @@ -346,7 +346,7 @@ public String getId() { /** * Find bound DOType info * @param signalInfo extRef signal info for binding - * @return DOType info as object contening name, id and adapter + * @return DOType info as object containing name, id and adapter * @throws ScdException throws when DO unknown */ public DataTypeTemplateAdapter.DOTypeInfo findMatchingDOType(ExtRefSignalInfo signalInfo) throws ScdException{ diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java index d7093b917..b1a91aaa2 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java @@ -6,6 +6,7 @@ import org.assertj.core.api.Assertions; import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -38,8 +39,7 @@ import java.util.Optional; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.scl2007b4.model.TFCEnum.ST; import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.*; @@ -559,7 +559,7 @@ void filterDuplicatedExtRefs_should_not_remove_not_duplicated_extrefs() { } @Test - void manageBindingForLDEPF_should_return_noReportAndExtRefUpdateSuccessfully_whenFlowKindIsInternalAndAllExtRefInSameBay() { + void manageBindingForLDEPF_whenFlowKindIsInternalAndAllExtRefInSameBay_should_return_noReportAndExtRefUpdateSuccessfully() { //Given String fileName = "LDEPF_Setting_file.csv"; InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName); @@ -626,7 +626,8 @@ void manageBindingForLDEPF_should_return_noReportAndExtRefUpdateSuccessfully_whe } @Test - void manageBindingForLDEPF_should_return_no_report_when_extRef_withDifferentIedType_update_successfully() { + void manageBindingForLDEPF_when_extRef_withDifferentIedType_update_successfully_should_return_no_report() { + // Given String fileName = "LDEPF_Setting_file.csv"; InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName); InputStreamReader reader = new InputStreamReader(inputStream); @@ -703,7 +704,7 @@ void manageBindingForLDEPF_should_return_no_report_when_extRef_withDifferentIedT } @Test - void manageBindingForLDEPF_should_return_report_when_manyIedSourceFound() { + void manageBindingForLDEPF_when_manyIedSourceFound_should_return_report() { //Given String fileName = "LDEPF_Setting_file.csv"; InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName); @@ -746,7 +747,8 @@ void manageBindingForLDEPF_should_return_report_when_manyIedSourceFound() { } @Test - void manageBindingForLDEPF_should_return_no_report_when_extRefInFlowKindInternalAndExternal_update_successfully() { + void manageBindingForLDEPF_when_extRefInFlowKindInternalAndExternal_update_successfully_should_return_no_report() { + //Given String fileName = "LDEPF_Setting_file.csv"; InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName); InputStreamReader reader = new InputStreamReader(inputStream); @@ -815,24 +817,27 @@ private LDEPFSettingData getLDEPFSettingByAnalogNum(List setti } @Test - void updateExtRefSource_shouldThrowScdException_whenSignalInfoNullOrInvalid() { + @Tag("issue-321") + void updateExtRefSource_whenSignalInfoNullOrInvalid_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_cbs_test.xml"); ExtRefInfo extRefInfo = new ExtRefInfo(); extRefInfo.setHolderIEDName("IED_NAME2"); extRefInfo.setHolderLDInst("LD_INST21"); extRefInfo.setHolderLnClass(TLLN0Enum.LLN_0.value()); - - //When Then assertThat(extRefInfo.getSignalInfo()).isNull(); + //When Then assertThatThrownBy(() -> extRefService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class); // signal = null + //Given extRefInfo.setSignalInfo(new ExtRefSignalInfo()); assertThat(extRefInfo.getSignalInfo()).isNotNull(); + //When Then assertThatThrownBy(() -> extRefService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class);// signal invalid } @Test - void updateExtRefSource_shouldThrowScdException_whenBindingInfoNullOrInvalid() { + @Tag("issue-321") + void updateExtRefSource_whenBindingInfoNullOrInvalid_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_cbs_test.xml"); ExtRefInfo extRefInfo = new ExtRefInfo(); @@ -845,16 +850,19 @@ void updateExtRefSource_shouldThrowScdException_whenBindingInfoNullOrInvalid() { extRefSignalInfo.setPDA("da21.bda211.bda212.bda213"); extRefSignalInfo.setPDO("Do21.sdo21"); extRefInfo.setSignalInfo(extRefSignalInfo); - //When Then assertThat(extRefInfo.getBindingInfo()).isNull(); - assertThatThrownBy(() -> extRefService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class); // binding = null + //When Then + assertThatThrownBy(() -> extRefService.updateExtRefSource(scd, extRefInfo)) + .isInstanceOf(ScdException.class); // binding = null + //Given extRefInfo.setBindingInfo(new ExtRefBindingInfo()); assertThat(extRefInfo.getBindingInfo()).isNotNull(); + //When Then assertThatThrownBy(() -> extRefService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class);// binding invalid } @Test - void updateExtRefSource_shouldThrowScdException_whenBindingInternalByIedName() { + void updateExtRefSource_whenBindingInternalByIedName_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_cbs_test.xml"); ExtRefInfo extRefInfo = new ExtRefInfo(); @@ -878,7 +886,7 @@ void updateExtRefSource_shouldThrowScdException_whenBindingInternalByIedName() { } @Test - void updateExtRefSource_shouldThrowScdException_whenBindingInternaByServiceType() { + void updateExtRefSource_whenBindingInternaByServiceType_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_cbs_test.xml"); ExtRefInfo extRefInfo = new ExtRefInfo(); @@ -903,7 +911,8 @@ void updateExtRefSource_shouldThrowScdException_whenBindingInternaByServiceType( } @Test - void updateExtRefSource_shouldThrowScdException_whenSourceInfoNullOrInvalid() { + @Tag("issue-321") + void updateExtRefSource_whenSourceInfoNullOrInvalid_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_cbs_test.xml"); ExtRefInfo extRefInfo = new ExtRefInfo(); @@ -923,16 +932,18 @@ void updateExtRefSource_shouldThrowScdException_whenSourceInfoNullOrInvalid() { extRefBindingInfo.setLnClass(TLLN0Enum.LLN_0.value()); extRefInfo.setBindingInfo(new ExtRefBindingInfo()); - //When Then assertThat(extRefInfo.getSourceInfo()).isNull(); + //When Then assertThatThrownBy(() -> extRefService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class); // signal = null + //Given extRefInfo.setSourceInfo(new ExtRefSourceInfo()); assertThat(extRefInfo.getSourceInfo()).isNotNull(); + //When Then assertThatThrownBy(() -> extRefService.updateExtRefSource(scd, extRefInfo)).isInstanceOf(ScdException.class);// signal invalid } @Test - void updateExtRefSource_shouldThrowScdException_whenBindingExternalBinding() { + void updateExtRefSource_whenBindingExternalBinding_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_cbs_test.xml"); ExtRefInfo extRefInfo = new ExtRefInfo(); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclEditorServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclEditorServiceTest.java index 0b660677e..5cbcbc0db 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclEditorServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclEditorServiceTest.java @@ -5,6 +5,7 @@ package org.lfenergy.compas.sct.commons; import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -26,7 +27,9 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +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.lfenergy.compas.sct.commons.testhelpers.SclHelper.LD_SUIED; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.getDAIAdapters; import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; @@ -38,7 +41,7 @@ class SclEditorServiceTest { @InjectMocks SclEditorService sclEditorService; - private static Stream sclProviderMissingRequiredObjects() { + private static Stream sclProviderMissingRequiredObjects() { SCL scl1 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingBeh.scd"); SCL scl2 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingLDevicePrivate.scd"); SCL scl3 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingLDevicePrivateAttribute.scd"); @@ -91,78 +94,86 @@ private static Stream sclProviderBasedLDeviceStatus() { ); } + @Test - void testAddHistoryItem() throws ScdException { + void addHistoryItem_should_add_history_elements() throws ScdException { + //Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION); SCL scd = sclRootAdapter.getCurrentElem(); - + //When sclEditorService.addHistoryItem(scd, "who", "what", "why"); - - assertNotNull(scd.getHeader()); + //Then + assertThat(scd.getHeader()).isNotNull(); THeader.History history = scd.getHeader().getHistory(); - assertNotNull(history); - assertEquals(1, history.getHitem().size()); + assertThat(history).isNotNull(); + assertThat(history.getHitem()).hasSize(1); THitem tHitem = history.getHitem().get(0); - assertEquals("who", tHitem.getWho()); - assertEquals("what", tHitem.getWhat()); - assertEquals("why", tHitem.getWhy()); - assertEquals(SclRootAdapter.REVISION, tHitem.getRevision()); - assertEquals(SclRootAdapter.VERSION, tHitem.getVersion()); + 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); assertIsMarshallable(scd); } @Test - void testAddIED() { - + void addIED_should_add_ied_element() { + //Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION); SCL scd = sclRootAdapter.getCurrentElem(); - assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates()); + assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull(); SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml"); - + //When Then assertDoesNotThrow(() -> sclEditorService.addIED(scd, "IED_NAME1", icd)); - assertEquals("IED_NAME1", scd.getIED().get(0).getName()); - assertNotNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates()); - + assertThat(scd.getIED().size()).isNotZero(); + assertThat(scd.getIED().get(0).getName()).isEqualTo("IED_NAME1"); + assertThat(scd.getDataTypeTemplates()).isNotNull(); assertIsMarshallable(scd); } @Test - void testAddSubnetworks() { + @Tag("issue-321") + void addSubnetworks_should_add_subnetwork() { + //Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION); SCL scd = sclRootAdapter.getCurrentElem(); - assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates()); + assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull(); SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml"); - - assertDoesNotThrow(() -> sclEditorService.addIED(scd, "IED_NAME1", icd)); - + //When Then + assertThatCode(() -> sclEditorService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException(); SubNetworkDTO subNetworkDTO = new SubNetworkDTO(); subNetworkDTO.setName("sName1"); subNetworkDTO.setType("IP"); - ConnectedApDTO connectedApDTO = new ConnectedApDTO("IED_NAME1", "AP_NAME"); + ConnectedApDTO connectedApDTO = new ConnectedApDTO("IED_NAME1","AP_NAME"); subNetworkDTO.addConnectedAP(connectedApDTO); - - assertDoesNotThrow(() -> sclEditorService.addSubnetworks(scd, List.of(subNetworkDTO), icd)); + //When Then + assertThatCode(() -> sclEditorService.addSubnetworks(scd, List.of(subNetworkDTO), icd)).doesNotThrowAnyException(); assertIsMarshallable(scd); } @Test - void testAddSubnetworksWithoutCommunicationTagInIcd() { + @Tag("issue-321") + void addSubnetworks_whenNoCommunicationTagInIcd_should_not_add_subnetwork() { + //Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION); SCL scd = sclRootAdapter.getCurrentElem(); - assertNull(sclRootAdapter.getCurrentElem().getDataTypeTemplates()); + assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull(); SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml"); - - assertDoesNotThrow(() -> sclEditorService.addIED(scd, "IED_NAME1", icd)); - - assertDoesNotThrow(() -> sclEditorService.addSubnetworks(scd, List.of(), icd)); + //When Then + assertThatCode(() -> sclEditorService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException(); + //When Then + assertThatCode(() -> sclEditorService.addSubnetworks(scd, List.of(), icd)).doesNotThrowAnyException(); String marshalledScd = assertIsMarshallable(scd); assertThat(marshalledScd).doesNotContain(" sclEditorService.initScl(headerId, "hVersion", "hRevision")); + //Then assertIsMarshallable(scd); } @@ -178,11 +189,13 @@ void initScl_should_create_Private_SCL_FILETYPE() { } @Test + @Tag("issue-321") void updateHeader_should_update_header_tag() { - //Given + //When Then SCL scd = assertDoesNotThrow(() -> sclEditorService.initScl(UUID.randomUUID(), "hVersion", "hRevision")); - UUID hId = UUID.fromString(scd.getHeader().getId()); - HeaderDTO headerDTO = DTO.createHeaderDTO(hId); + //Given + UUID headerId = UUID.fromString(scd.getHeader().getId()); + HeaderDTO headerDTO = DTO.createHeaderDTO(headerId); //When sclEditorService.updateHeader(scd, headerDTO); //Then @@ -190,14 +203,16 @@ void updateHeader_should_update_header_tag() { } @Test - void testUpdateDAI() { + @Tag("issue-321") + void updateDAI_should_not_throw_error() { + //Given DataAttributeRef dataAttributeRef = new DataAttributeRef(); dataAttributeRef.setLnType("unknownID"); SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); - - assertThrows(ScdException.class, () -> sclEditorService.updateDAI( - scd, "IED", "LD", dataAttributeRef - )); + //When Then + assertThatThrownBy(() -> sclEditorService.updateDAI(scd, "IED", "LD", dataAttributeRef)) + .isInstanceOf(ScdException.class); + //Given dataAttributeRef.setLnType("LNO1"); dataAttributeRef.setLnClass(TLLN0Enum.LLN_0.value()); DoTypeName doTypeName = new DoTypeName("Do.sdo1.d"); @@ -206,16 +221,20 @@ void testUpdateDAI() { TVal tVal = new TVal(); tVal.setValue("newValue"); dataAttributeRef.setDaiValues(List.of(tVal)); - assertDoesNotThrow(() -> sclEditorService.updateDAI(scd, "IED_NAME", "LD_INS1", dataAttributeRef)); + //When Then + assertThatCode(() -> sclEditorService.updateDAI(scd, "IED_NAME", "LD_INS1", dataAttributeRef)) + .doesNotThrowAnyException(); assertIsMarshallable(scd); } @Test - void testImportSTDElementsInSCD() { + void testImportSTDElementsInSCD_whenCalledWithOneSTD_shouldNotThrowException() { + //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"); - - assertDoesNotThrow(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES)); + //When Then + assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES)) + .doesNotThrowAnyException(); assertThat(scd.getIED()).hasSize(1); assertThat(scd.getDataTypeTemplates()).hasNoNullFieldsOrProperties(); assertThat(scd.getCommunication().getSubNetwork()).hasSize(2); @@ -223,13 +242,15 @@ void testImportSTDElementsInSCD() { } @Test - void testImportSTDElementsInSCD_with_Multiple_STD() { + void importSTDElementsInSCD_whenCalledWithMultipleSTD_shouldNotThrowException() { + //Given 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"); - - assertDoesNotThrow(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std0, std1, std2), DTO.SUB_NETWORK_TYPES)); + //When Then + assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std0, std1, std2), DTO.SUB_NETWORK_TYPES)) + .doesNotThrowAnyException(); assertThat(scd.getIED()).hasSize(3); assertThat(scd.getDataTypeTemplates()).hasNoNullFieldsOrProperties(); assertThat(scd.getCommunication().getSubNetwork()).hasSize(2); @@ -239,46 +260,50 @@ void testImportSTDElementsInSCD_with_Multiple_STD() { } @Test - void testImportSTDElementsInSCD_Several_STD_Match_Compas_ICDHeader() { + void importSTDElementsInSCD_whenManySTDMatchCompasICDHeader_shouldThrowException() { //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"); + SCL std2 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); + List stds = List.of(std1, std2); //When Then - List stds = List.of(std, std1); - assertThrows(ScdException.class, () -> sclEditorService.importSTDElementsInSCD(scd, stds, DTO.SUB_NETWORK_TYPES)); + assertThatThrownBy(() -> sclEditorService.importSTDElementsInSCD(scd, stds, DTO.SUB_NETWORK_TYPES)) + .isInstanceOf(ScdException.class); assertIsMarshallable(scd); } @Test - void test_importSTDElementsInSCD_should_not_throw_exception_when_SCD_file_contains_same_ICDHeader_in_two_different_functions() { + void importSTDElementsInSCD_whenSCDFileContainsSameICDHeaderInTwoDifferentFunctions_should_not_throw_exception() { //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 - assertDoesNotThrow(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES)); + assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES)).doesNotThrowAnyException(); assertIsMarshallable(scd); } @Test - void testImportSTDElementsInSCD_Compas_ICDHeader_Not_Match() { + void importSTDElementsInSCD_whenCompasICDHeaderNotMatch__shouldThrowException() { //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"); List stdList = List.of(std); //When Then - assertThrows(ScdException.class, () -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES)); + assertThatThrownBy(() -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES)) + .isInstanceOf(ScdException.class) + .hasMessageContaining("COMPAS-ICDHeader is not the same in Substation and in IED"); assertIsMarshallable(scd); } @Test - void testImportSTDElementsInSCD_No_STD_Match() { + void importSTDElementsInSCD_whenNoSTDMatch_shouldThrowException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml"); List stdList = List.of(); //When Then - assertThrows(ScdException.class, () -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES)); - assertIsMarshallable(scd); + assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES)) + .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"); } @Test @@ -347,10 +372,10 @@ void removeControlBlocksAndDatasetAndExtRefSrc_should_remove_srcXXX_attributes_o @ParameterizedTest(name = "{0}") @MethodSource("sclProviderMissingRequiredObjects") - void updateLDeviceStatus_shouldReturnReportWithError_MissingRequiredObject(String testCase, SCL scl, Tuple... errors) { + void updateLDeviceStatus_whenMissingRequiredObject_shouldReturnReportWithError(String testCase, SCL scl, Tuple... errors) { // Given - assertTrue(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").isPresent()); - assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()); + assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED")).isPresent(); + assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); String before = MarshallerWrapper.marshall(scl); // When List sclReportItems = sclEditorService.updateLDeviceStatus(scl); @@ -367,7 +392,7 @@ void updateLDeviceStatus_shouldReturnReportWithError_MissingRequiredObject(Strin @ParameterizedTest(name = "{0}") @MethodSource("sclProviderBasedLDeviceStatus") - void updateLDeviceStatus_shouldReturnReportWithError_WhenLDeviceStatusActiveOrUntestedOrInactive(String testCase, SCL scl, Tuple... errors) { + void updateLDeviceStatus_whenLDeviceStatusActiveOrUntestedOrInactive_shouldReturnReportWithError(String testCase, SCL scl, Tuple... errors) { // Given assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); assertThat(getLDeviceStatusValue(scl, "IedName2", "LDSUIED").get().getValue()).isEqualTo("on"); @@ -389,7 +414,7 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenLDeviceStatusActiveOrUn } @Test - void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceInactive_Test2() { + void updateLDeviceStatus_whenAllLDeviceInactive_shouldReturnReportWithError() { // Given SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test2_LD_STATUS_INACTIVE.scd"); assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); @@ -412,7 +437,6 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceInactive_Test assertThat(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").get().getValue()).isEqualTo("off"); } - @Test void updateLDeviceStatus_shouldReturnUpdatedFile() { // Given @@ -422,7 +446,6 @@ void updateLDeviceStatus_shouldReturnUpdatedFile() { assertThat(getLDeviceStatusValue(givenScl, "IedName2", "LDSUIED")).isPresent(); assertThat(getLDeviceStatusValue(givenScl, "IedName2", "LDSUIED").get().getValue()).isEqualTo("on"); assertThat(getLDeviceStatusValue(givenScl, "IedName3", "LDSUIED")).isEmpty(); - // When List sclReportItems = sclEditorService.updateLDeviceStatus(givenScl); // Then @@ -436,7 +459,7 @@ void updateLDeviceStatus_shouldReturnUpdatedFile() { } @Test - void updateLDeviceStatus_shouldReturnUpdatedFile_when_DAI_Mod_DO_stVal_whatever_it_is_updatable_or_not() { + void updateLDeviceStatus_when_DAI_Mod_DO_stVal_whateverIsUpdatableOrNot_shouldReturnUpdatedFile() { // Given SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue_165_enhance_68_Test_Dai_Updatable.scd"); assertThat(getLDeviceStatusValue(givenScl, "IedName1", "LDSUIED")) @@ -456,25 +479,20 @@ void updateLDeviceStatus_shouldReturnUpdatedFile_when_DAI_Mod_DO_stVal_whatever_ .hasValue("on"); // When List sclReportItems = sclEditorService.updateLDeviceStatus(givenScl); - // Then assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue(); assertThat(getLDeviceStatusValue(givenScl, "IedName1", "LDSUIED")) .map(TVal::getValue) .hasValue("on"); - assertThat(getLDeviceStatusValue(givenScl, "IedName2", "LDSUIED")) .map(TVal::getValue) .hasValue("off"); - assertThat(getLDeviceStatusValue(givenScl, "IedName3", "LDSUIED")) .map(TVal::getValue) .hasValue("off"); - assertThat(getLDeviceStatusValue(givenScl, "IedName4", "LDSUIED")) .map(TVal::getValue) .hasValue("off"); - assertThat(getLDeviceStatusValue(givenScl, "IedName5", "LDSUIED")) .map(TVal::getValue) .hasValue("off"); @@ -496,10 +514,8 @@ private Optional getLDeviceStatusValue(SCL scl, String iedName, String ldI void updateDoInRef_shouldReturnUpdatedFile(String testName, String ldInst, String doName, String daName, String expected) { // Given SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_issue_231_test_ok.xml"); - // When List sclReportItems = sclEditorService.updateDoInRef(givenScl); - // Then assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue(); SclTestMarshaller.assertIsMarshallable(givenScl); @@ -520,23 +536,20 @@ void updateDoInRef_shouldReturnUpdatedFile(String testName, String ldInst, Strin void updateDoInRef_should_not_update_DAI(String testName, String ldInst, String doName, String daName) { // Given SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_issue_231_test_ok.xml"); - // When List sclReportItems = sclEditorService.updateDoInRef(givenScl); - // Then assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue(); assertThat(getValFromDaiName(givenScl, "IED_NAME1", ldInst, doName, daName)).isNotPresent(); } @Test - void updateDoInRef_shouldReturnReportWithError_when_ExtRef_not_coherent() { + @Tag("issue-321") + void updateDoInRef_when_ExtRefNotCoherent_shouldReturnReportWithError() { // Given SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_issue_231_test_ko.xml"); - // When List sclReportItems = sclEditorService.updateDoInRef(givenScl); - // Then assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue(); assertThat(sclReportItems).hasSize(4); @@ -577,7 +590,6 @@ void analyzeDataGroups_should_success() { @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); @@ -624,7 +636,7 @@ void manageMonitoringLns_should_update_and_create_lsvs_and_goose() { } @Test - void manageMonitoringLns_should_not_update_and_not_create_lsvs_and_goose_when_no_extRef() { + void manageMonitoringLns_when_no_extRef_should_not_update_and_not_create_lsvs_and_goose() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/monitoring_lns/scd_monitoring_lsvs_lgos.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -645,7 +657,7 @@ void manageMonitoringLns_should_not_update_and_not_create_lsvs_and_goose_when_no } @Test - void manageMonitoringLns_should_not_update_and_not_create_lsvs_and_goose_when_dai_not_updatable() { + void manageMonitoringLns_when_dai_not_updatable_should_not_update_and_not_create_lsvs_and_goose() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/monitoring_lns/scd_monitoring_lsvs_lgos.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java index 487d242f9..16c9bbe6f 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java @@ -5,6 +5,7 @@ package org.lfenergy.compas.sct.commons; import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.lfenergy.compas.scl2007b4.model.*; @@ -20,8 +21,8 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.createDa; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.createDo; @@ -32,7 +33,7 @@ class SclElementsProviderServiceTest { SclElementsProviderService sclElementsProviderService; @Test - void getExtRefBinders_shouldThrowScdException_whenExtRefNotExist() { + void getExtRefBinders_whenExtRefNotExist_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_binders_test.xml"); @@ -45,7 +46,7 @@ void getExtRefBinders_shouldThrowScdException_whenExtRefNotExist() { } @Test - void getExtRefBinders_shouldReturnSortedListBindingInfo_whenExtRefAndDOExist() { + void getExtRefBinders_whenExtRefAndDOExist_shouldReturnSortedListBindingInfo() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_binders_test.xml"); @@ -74,7 +75,8 @@ void getExtRefBinders_shouldReturnSortedListBindingInfo_whenExtRefAndDOExist() { } @Test - void getExtRefSourceInfo_shouldReturnEmptyList_whenExtRefMatchNoFCDA() { + @Tag("issue-321") + void getExtRefSourceInfo_whenExtRefMatchNoFCDA_shouldReturnEmptyList() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/scd_get_cbs_test.xml"); String iedName = "IED_NAME2"; @@ -82,10 +84,11 @@ void getExtRefSourceInfo_shouldReturnEmptyList_whenExtRefMatchNoFCDA() { String lnClass = TLLN0Enum.LLN_0.value(); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iedAdapter.findLDeviceAdapterByLdInst(ldInst).get()); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); List extRefs = ln0Adapter.getExtRefs(null); - assertFalse(extRefs.isEmpty()); + assertThat(extRefs).isNotEmpty(); ExtRefInfo extRefInfo = new ExtRefInfo(extRefs.get(0)); @@ -101,7 +104,8 @@ void getExtRefSourceInfo_shouldReturnEmptyList_whenExtRefMatchNoFCDA() { } @Test - void getExtRefSourceInfo_shouldReturnListOfControlBlocks_whenExtRefMatchFCDA() { + @Tag("issue-321") + void getExtRefSourceInfo_whenExtRefMatchFCDA_shouldReturnListOfControlBlocks() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-scd-extref-cb/issue_175_scd_get_cbs_test.xml"); String iedName = "IED_NAME2"; @@ -109,10 +113,11 @@ void getExtRefSourceInfo_shouldReturnListOfControlBlocks_whenExtRefMatchFCDA() { String lnClass = TLLN0Enum.LLN_0.value(); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iedAdapter.findLDeviceAdapterByLdInst(ldInst).get()); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); List extRefs = ln0Adapter.getExtRefs(null); - assertFalse(extRefs.isEmpty()); + assertThat(extRefs).isNotEmpty(); ExtRefInfo extRefInfo = new ExtRefInfo(extRefs.get(0)); @@ -128,23 +133,6 @@ void getExtRefSourceInfo_shouldReturnListOfControlBlocks_whenExtRefMatchFCDA() { assertThat(controlBlocks.get(0).getName()).isEqualTo("goose2"); } - private ExtRefSignalInfo createSignalInfo(String pDO, String pDA, String intAddr) { - - final String DESC = "DESC"; - final String P_LN = TLLN0Enum.LLN_0.value(); - final String P_SERV_T = "Report"; - - ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); - signalInfo.setDesc(DESC); - signalInfo.setPDA(pDA); - signalInfo.setPDO(pDO); - signalInfo.setPLN(P_LN); - signalInfo.setPServT(TServiceType.fromValue(P_SERV_T)); - signalInfo.setIntAddr(intAddr); - - return signalInfo; - } - @Test void getDAI_should_return_all_dai() { // given @@ -221,8 +209,8 @@ void getDAI_when_LDevice_not_found_should_throw_exception() { // when & then DataAttributeRef dataAttributeRef = new DataAttributeRef(); - assertThrows(ScdException.class, - () -> sclElementsProviderService.getDAI(scd, "IED_NAME1", "UNKNOWNLD", dataAttributeRef, true)); + assertThatThrownBy(() -> sclElementsProviderService.getDAI(scd, "IED_NAME1", "UNKNOWNLD", dataAttributeRef, true)) + .isInstanceOf(ScdException.class); } @Test @@ -333,11 +321,41 @@ void getDAI_should_filter_updatable_DA_with_sGroup_Val_without_ConfSg() { } @Test - void testGetEnumTypeValues() { + void getEnumTypeValues_whenCalledWithUnknownId_shouldReturnException() { + // Given + SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml"); + // When Then + assertThatThrownBy(() -> sclElementsProviderService.getEnumTypeValues(scd, "unknownID")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown EnumType Id: unknownID"); + } + + @Test + void getEnumTypeValues_whenCalledWithKnownId_shouldNotReturnException() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml"); - assertThrows(ScdException.class, () -> sclElementsProviderService.getEnumTypeValues(scd, "unknwnID")); + // When var enumList = assertDoesNotThrow(() -> sclElementsProviderService.getEnumTypeValues(scd, "RecCycModKind")); - assertFalse(enumList.isEmpty()); + // Then + assertThat(enumList).isNotEmpty(); + } + + private ExtRefSignalInfo createSignalInfo(String pDO, String pDA, String intAddr) { + + final String DESC = "DESC"; + final String P_LN = TLLN0Enum.LLN_0.value(); + final String P_SERV_T = "Report"; + + ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); + signalInfo.setDesc(DESC); + signalInfo.setPDA(pDA); + signalInfo.setPDO(pDO); + signalInfo.setPLN(P_LN); + signalInfo.setPServT(TServiceType.fromValue(P_SERV_T)); + signalInfo.setIntAddr(intAddr); + + return signalInfo; } + } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SubstationServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SubstationServiceTest.java index 9a3bfa060..5ebba1c52 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SubstationServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SubstationServiceTest.java @@ -14,7 +14,7 @@ import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; 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 cdab91e20..82d72d27e 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 @@ -9,25 +9,23 @@ import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter; import org.mockito.Mockito; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; class ConnectedApDTOTest { @Test - void testConstruction(){ + void from_whenCalledWithConnectedAPAdapter_shouldFillValues() { + // Given ConnectedAPAdapter connectedAPAdapter = Mockito.mock(ConnectedAPAdapter.class); + when(connectedAPAdapter.getApName()).thenReturn(DTO.AP_NAME); + when(connectedAPAdapter.getIedName()).thenReturn(DTO.HOLDER_IED_NAME); - Mockito.when(connectedAPAdapter.getApName()).thenReturn(DTO.AP_NAME); - Mockito.when(connectedAPAdapter.getIedName()).thenReturn(DTO.HOLDER_IED_NAME); - + // When ConnectedApDTO connectedApDTO = ConnectedApDTO.from(connectedAPAdapter); - assertEquals(DTO.HOLDER_IED_NAME, connectedApDTO.iedName()); - assertEquals(DTO.AP_NAME, connectedApDTO.apName()); - - connectedApDTO = ConnectedApDTO.from(connectedAPAdapter); - - assertEquals(DTO.HOLDER_IED_NAME, connectedApDTO.iedName()); - assertEquals(DTO.AP_NAME, connectedApDTO.apName()); + //Then + assertThat(connectedApDTO.iedName()).isEqualTo(DTO.HOLDER_IED_NAME); + assertThat(connectedApDTO.apName()).isEqualTo(DTO.AP_NAME); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ControlBlockTargetTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ControlBlockTargetTest.java index c7cec8d8b..83513bcc7 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ControlBlockTargetTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ControlBlockTargetTest.java @@ -48,7 +48,7 @@ void toTClientLn_should_map_object_to_TClientLN() { } @Test - void toTClientLn_should_return_empty_lnInst_when_object_lnInst_is_null() { + void toTClientLn_when_object_lnInst_is_null_should_return_empty_lnInst() { //Given ControlBlockTarget controlBlockTarget = new ControlBlockTarget( AP_REF, IED_NAME, LD_INST, null, LN_CLASS, PREFIX, DESC); @@ -72,7 +72,7 @@ void toIedName_should_map_object_to_IEDName() { } @Test - void toIedName_should_return_null_lnInst_when_object_lnInst_is_empty() { + void toIedName_when_object_lnInst_is_empty_should_return_null_lnInst() { //Given ControlBlockTarget controlBlockTarget = new ControlBlockTarget( AP_REF, IED_NAME, LD_INST, "", LN_CLASS, PREFIX, DESC); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DaTypeNameTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DaTypeNameTest.java index 4e399151b..a0647bef7 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DaTypeNameTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DaTypeNameTest.java @@ -19,7 +19,7 @@ class DaTypeNameTest { @Test - void testConstructorWithRef() { + void constructor_whenCalledWithDaName_shouldFillValues() { // given : nothing // when DaTypeName daTypeName = new DaTypeName("da1.bda1.bda2"); @@ -30,7 +30,7 @@ void testConstructorWithRef() { } @Test - void testConstructorWithRefWhenEmptyStruct() { + void constructor_whenCalledWithDaNameWithDotSeparatedValues_shouldFillValues() { // given : nothing // when DaTypeName daTypeName = new DaTypeName("da1"); @@ -41,18 +41,18 @@ void testConstructorWithRefWhenEmptyStruct() { } @Test - void testConstructorWithRefWithNullName() { + void constructor_whenCalledWithNullDaName_shouldNotFillValues() { // given : nothing // when DaTypeName daTypeName = new DaTypeName(null); // then - assertThat(daTypeName.getName()).isEqualTo(""); + assertThat(daTypeName.getName()).isEmpty(); assertThat(daTypeName.getStructNames()).isNotNull().isEmpty(); assertThat(daTypeName.getDaiValues()).isNotNull().isEmpty(); } @Test - void testConstructor2WithRef() { + void constructor_whenCalledWithDaNameAndStructNames_shouldFillValues() { // given : nothing // when DaTypeName daTypeName = new DaTypeName("da1", "bda1.bda2"); @@ -63,7 +63,7 @@ void testConstructor2WithRef() { } @Test - void testConstructor2WithRefWhenEmptyStruct() { + void constructor_whenCalledWithNullStructNames_shouldNotFillValues() { // given : nothing // when DaTypeName daTypeName = new DaTypeName("da1", null); @@ -74,18 +74,18 @@ void testConstructor2WithRefWhenEmptyStruct() { } @Test - void testConstructor2WithRefWithNullName() { + void constructor_whenCalledWithNullDaNameAndNullStructNames_shouldNotFillValues() { // given : nothing // when DaTypeName daTypeName = new DaTypeName(null, null); // then - assertThat(daTypeName.getName()).isEqualTo(""); + assertThat(daTypeName.getName()).isEmpty(); assertThat(daTypeName.getStructNames()).isNotNull().isEmpty(); assertThat(daTypeName.getDaiValues()).isNotNull().isEmpty(); } @Test - void testConstructorWithNameAndStructNames() { + void constructor_whenCalledWithNameAndStructNames_shouldFillValues() { // given : nothing // when DaTypeName daTypeName = new DaTypeName("da1", "bda1.bda2"); @@ -96,7 +96,7 @@ void testConstructorWithNameAndStructNames() { } @Test - void testEquals() { + void equals_whenCalled_shouldReturnTrue() { // given : nothing DaTypeName da1 = createDa("da1.bda1.bda2", TFCEnum.CF, true, Map.of(0L, "value")); DaTypeName da2 = createDa("da1.bda1.bda2", TFCEnum.CF, true, Map.of(0L, "value")); @@ -107,7 +107,7 @@ void testEquals() { } @Test - void testNotEquals() { + void equals_whenCalled_shouldReturnFalse() { // given : nothing DaTypeName da1 = createDa("da1.bda1.bda2", TFCEnum.CF, true, Map.of(0L, "value")); DaTypeName da2 = createDa("da1.bda1.bda2", TFCEnum.DC, true, Map.of(0L, "value")); @@ -118,7 +118,7 @@ void testNotEquals() { } @Test - void testFrom() { + void from_whenCalledWithDaTypeName_shouldNotFillValues() { // given : nothing DaTypeName da1 = createDa("da1.bda1.bda2", TFCEnum.CF, true, Map.of(0L, "value")); // when @@ -132,7 +132,7 @@ void testFrom() { * Fc value should be in ListFcEnum to be considered as known */ @Test - void isUpdatable_shouldReturnTrue_whenFcKnown_And_valImportIsTrue() { + void isUpdatable_whenFcKnown_And_valImportIsTrue_shouldReturnTrue() { // given DaTypeName da1 = createDa("da1.bda1.bda2", TFCEnum.CF, true, Map.of(0L, "value")); // when diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java index ab15c4f78..566261db8 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.dto; +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; @@ -17,7 +18,9 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.createDa; import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME; import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME; @@ -25,81 +28,89 @@ class DataAttributeRefTest { - public static final String CTL_MODEL = "ctlModel"; @Test - void testGetObjRef(){ + void getObjRef_whenCalledWithAnyLNClassRef_should_return_expected_value(){ + // Given String expected = "IEDLDTM/prelnclass1.do.sdo1.sdo2.da.bda1.bda2"; DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); + // When String objRef = dataAttributeRef.getObjRef("IED","LDTM"); - assertEquals(expected,objRef); + // Then + assertThat(objRef).isEqualTo(expected); } @Test - void testGetObjRefWhenLLN0(){ + void getObjRef_whenCalledWithLLN0Ref_should_return_expected_value(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","LLN0","1"); // when String objRef = dataAttributeRef.getObjRef("IED","LDTM"); // then - assertEquals("IEDLDTM/LLN0.do.sdo1.sdo2.da.bda1.bda2",objRef); + assertThat(objRef).isEqualTo("IEDLDTM/LLN0.do.sdo1.sdo2.da.bda1.bda2"); } @Test - void testGetDataAttributes(){ + void getDataAttributes_should_return_expected_value(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); // when String dataAttributes = dataAttributeRef.getDataAttributes(); // then String expected = "do.sdo1.sdo2.da.bda1.bda2"; - assertEquals(expected, dataAttributes); + assertThat(dataAttributes).isEqualTo(expected); } @Test - void testAddDoStructName(){ + void addDoStructName_when_called_shouldSetDoRefValue(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); dataAttributeRef.setDaName(new DaTypeName()); + assertThat(dataAttributeRef.getDoRef()).isEqualTo("do.sdo1.sdo2"); // when dataAttributeRef.addDoStructName("added_sdo"); // then String expected = "do.sdo1.sdo2.added_sdo"; - assertEquals(expected, dataAttributeRef.getDoRef()); + assertThat(dataAttributeRef.getDoRef()).isEqualTo(expected); } @Test - void testAddDoStructNameWhenNoDoName(){ + void addDoStructName_when_called_with_unDefinedDoName_should_throw_exception(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); dataAttributeRef.setDaName(new DaTypeName()); dataAttributeRef.setDoName(new DoTypeName()); // when & then - assertThrows(IllegalArgumentException.class, () -> dataAttributeRef.addDoStructName("added_sdo")); + assertThatCode(() -> dataAttributeRef.addDoStructName("added_sdo")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("DO name must be defined before adding DO StructName"); } @Test - void testAddDaStructName(){ + void addDaStructName_when_called_shouldSetDaRefValue(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); // when dataAttributeRef.addDaStructName("added_bda"); // then String expected = "da.bda1.bda2.added_bda"; - assertEquals(expected, dataAttributeRef.getDaRef()); + assertThat(dataAttributeRef.getDaRef()).isEqualTo(expected); } @Test - void testAddDaStructNameWhenNoDoName(){ + void addDaStructName_when_called_with_unDefinedDaName_should_throw_exception(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); dataAttributeRef.setDaName(new DaTypeName()); dataAttributeRef.setDoName(new DoTypeName()); // when & then - assertThrows(IllegalArgumentException.class, () -> dataAttributeRef.addDaStructName("added_sda")); + assertThatCode(() -> dataAttributeRef.addDaStructName("added_sda")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("DA name must be defined before adding DA StructName"); + } @Test - void testSetDaiValues(){ + void setDaiValues_when_called_shouldFillSGroupAndValue(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); TVal val = new TVal(); @@ -107,11 +118,11 @@ void testSetDaiValues(){ // when dataAttributeRef.setDaiValues(List.of(val)); // then - assertEquals(Map.of(0L, "test"), dataAttributeRef.getDaName().getDaiValues()); + assertThat(dataAttributeRef.getDaName().getDaiValues()).isEqualTo(Map.of(0L, "test")); } @Test - void testSetDaiValuesWhenMultipleVal(){ + void setDaiValues_when_called_withMultipleVal_shouldFillSGroupAndValue(){ // given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); TVal val1 = new TVal(); @@ -123,39 +134,51 @@ void testSetDaiValuesWhenMultipleVal(){ // when dataAttributeRef.setDaiValues(List.of(val1, val2)); // then - assertEquals(Map.of(0L, "test1", 1L, "test2"), dataAttributeRef.getDaName().getDaiValues()); + assertThat(dataAttributeRef.getDaName().getDaiValues()).isEqualTo(Map.of(0L, "test1", 1L, "test2")); } @Test + @Tag("issue-321") void testCopyFrom() { + // Given DataAttributeRef dataAttributeRef = DTO.createDataAttributeRef("pre","lnclass","1"); + // When DataAttributeRef dataAttributeRef_b = DataAttributeRef.copyFrom(dataAttributeRef); - + // Then assertAll("COPY FROM", - () -> assertEquals(dataAttributeRef_b.getLnClass(), dataAttributeRef.getLnClass()), - () -> assertEquals(dataAttributeRef_b.getPrefix(), dataAttributeRef.getPrefix()), - () -> assertEquals(dataAttributeRef_b.getDaName(), dataAttributeRef.getDaName()), - () -> assertEquals(dataAttributeRef_b.getDoName(), dataAttributeRef.getDoName()), - () -> assertEquals(dataAttributeRef_b.getLnInst(), dataAttributeRef.getLnInst()), - () -> assertEquals(dataAttributeRef_b.getLnType(), dataAttributeRef.getLnType()), + () -> assertThat(dataAttributeRef.getLnClass()).isEqualTo(dataAttributeRef_b.getLnClass()), + () -> assertThat(dataAttributeRef.getPrefix()).isEqualTo(dataAttributeRef_b.getPrefix()), + () -> assertThat(dataAttributeRef.getDaName()).isEqualTo(dataAttributeRef_b.getDaName()), + () -> assertThat(dataAttributeRef.getDoName()).isEqualTo(dataAttributeRef_b.getDoName()), + () -> assertThat(dataAttributeRef.getLnInst()).isEqualTo(dataAttributeRef_b.getLnInst()), + () -> assertThat(dataAttributeRef.getLnType()).isEqualTo(dataAttributeRef_b.getLnType()), () -> assertArrayEquals(dataAttributeRef_b.getSdoNames().toArray(new String[0]), dataAttributeRef.getSdoNames().toArray(new String[0])), () -> assertArrayEquals(dataAttributeRef_b.getBdaNames().toArray(new String[0]), dataAttributeRef.getBdaNames().toArray(new String[0])), - () -> assertEquals(dataAttributeRef_b.getType(), dataAttributeRef.getType()), - () -> assertTrue(dataAttributeRef.isValImport()) + () -> assertThat(dataAttributeRef.getType()).isEqualTo(dataAttributeRef_b.getType()), + () -> assertThat(dataAttributeRef.isValImport()).isTrue() ); + // Given DataAttributeRef dataAttributeRef_t = new DataAttributeRef(); - assertNull(dataAttributeRef_t.getFc()); - assertNull(dataAttributeRef_t.getCdc()); - assertNull(dataAttributeRef_t.getBType()); - assertNull(dataAttributeRef_t.getType()); - assertTrue(dataAttributeRef_t.getBdaNames().isEmpty()); - assertTrue(dataAttributeRef_t.getSdoNames().isEmpty()); - assertThrows(IllegalArgumentException.class, () -> dataAttributeRef_t.setCdc(TPredefinedCDCEnum.WYE)); - assertThrows(IllegalArgumentException.class, () -> dataAttributeRef_t.setBType("BType")); - assertThrows(IllegalArgumentException.class, () -> dataAttributeRef_t.setType("Type")); - assertThrows(IllegalArgumentException.class, () -> dataAttributeRef_t.setFc(TFCEnum.BL)); + assertThat(dataAttributeRef_t.getFc()).isNull(); + assertThat(dataAttributeRef_t.getCdc()).isNull(); + assertThat(dataAttributeRef_t.getBType()).isNull(); + assertThat(dataAttributeRef_t.getType()).isNull(); + assertThat(dataAttributeRef_t.getBdaNames()).isEmpty(); + assertThat(dataAttributeRef_t.getSdoNames()).isEmpty(); + // When Then + assertThatCode(() -> dataAttributeRef_t.setCdc(TPredefinedCDCEnum.WYE)) + .isInstanceOf(IllegalArgumentException.class); + // When Then + assertThatCode(() -> dataAttributeRef_t.setBType("BType")) + .isInstanceOf(IllegalArgumentException.class); + // When Then + assertThatCode(() -> dataAttributeRef_t.setType("Type")) + .isInstanceOf(IllegalArgumentException.class); + // When Then + assertThatCode(() -> dataAttributeRef_t.setFc(TFCEnum.BL)) + .isInstanceOf(IllegalArgumentException.class); } /** @@ -184,7 +207,7 @@ private static Stream daParametersProviderUpdatable() { Arguments.of("should return true when Mod", STVAL_DA_NAME, TFCEnum.MX, false), Arguments.of("should return true when Mod", STVAL_DA_NAME, null, true), Arguments.of("should return true when Mod", STVAL_DA_NAME, null, false), - Arguments.of("should return true when Mod", CTL_MODEL, TFCEnum.CF, true) + Arguments.of("should return true when Mod", "ctlModel", TFCEnum.CF, true) ); } @@ -205,11 +228,11 @@ void isUpdatable_case1(String testName, String daName, TFCEnum fc, boolean valIm private static Stream daParametersProviderNotUpdatable() { return Stream.of( - Arguments.of("should return false when Mod", CTL_MODEL, TFCEnum.CF, false), - Arguments.of("should return false when Mod", CTL_MODEL, TFCEnum.MX, true), - Arguments.of("should return false when Mod", CTL_MODEL, TFCEnum.MX, false), - Arguments.of("should return false when Mod", CTL_MODEL, null, true), - Arguments.of("should return false when Mod", CTL_MODEL, null, false) + Arguments.of("should return false when Mod", "ctlModel", TFCEnum.CF, false), + Arguments.of("should return false when Mod", "ctlModel", TFCEnum.MX, true), + Arguments.of("should return false when Mod", "ctlModel", TFCEnum.MX, false), + Arguments.of("should return false when Mod", "ctlModel", null, true), + Arguments.of("should return false when Mod", "ctlModel", null, false) ); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java index 5b7f81cba..e500555e6 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.dto; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.TDataSet; import org.lfenergy.compas.scl2007b4.model.TLN; @@ -12,26 +13,29 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; class DataSetInfoTest { @Test + @Tag("issue-321") void testConstructor(){ //Given When DataSetInfo dataSetInfo = new DataSetInfo(); - assertNull(dataSetInfo.getName()); + assertThat(dataSetInfo.getName()).isNull(); + //When dataSetInfo = new DataSetInfo("DATA_INFO"); - assertEquals("DATA_INFO",dataSetInfo.getName()); + //Then + assertThat(dataSetInfo.getName()).isEqualTo("DATA_INFO"); + //Given dataSetInfo.setName("DATA_INFO1"); dataSetInfo.addFCDAInfo(new FCDAInfo()); - //Then - assertEquals("DATA_INFO1",dataSetInfo.getName()); - assertFalse(dataSetInfo.getFCDAInfos().isEmpty()); + //When + assertThat(dataSetInfo.getName()).isEqualTo("DATA_INFO1"); + assertThat(dataSetInfo.getFCDAInfos()).isNotEmpty(); } @Test - void testFrom(){ + void from_WhenCalledWithDataSet_ThenValuesAreFilled(){ //Given TDataSet dataSet = new TDataSet(); dataSet.setName("dataset"); @@ -39,12 +43,12 @@ void testFrom(){ //When DataSetInfo dataSetInfo = DataSetInfo.from(dataSet); //Then - assertEquals("dataset", dataSetInfo.getName()); - assertEquals(1,dataSetInfo.getFCDAInfos().size()); + assertThat(dataSetInfo.getName()).isEqualTo("dataset"); + assertThat(dataSetInfo.getFCDAInfos()).hasSize(1); } @Test - void getDataSets_shouldReturnEmptyList_whenNoDataSetInLN(){ + void getDataSets_whenCalledWithNoDataSetInLN_shouldReturnEmptyList(){ //Given LNAdapter lnAdapter = new LNAdapter(null, new TLN()); //When @@ -54,7 +58,7 @@ void getDataSets_shouldReturnEmptyList_whenNoDataSetInLN(){ } @Test - void getDataSets_shouldReturnDataSet_whenLNContainsMatchingFCDA(){ + void getDataSets_whenCalledWithLNContainsMatchingFCDA_shouldReturnDataSet(){ //Given TDataSet dataSet = new TDataSet(); dataSet.setName("datasetName"); @@ -71,10 +75,10 @@ void getDataSets_shouldReturnDataSet_whenLNContainsMatchingFCDA(){ @Test - void isValid_shouldReturnFalse_whenNameSizeMore32() { + void isValid_whenNameSizeMore32_shouldReturnFalse() { //Given DataSetInfo dataSetInfo = new DataSetInfo(); - assertNull(dataSetInfo.getName()); + assertThat(dataSetInfo.getName()).isNull(); dataSetInfo = new DataSetInfo("DATA_INFO_TEST_CHARACTERE_NAME_MORE_THAN_32_CHARACTERES"); //When boolean isValid = dataSetInfo.isValid(); @@ -82,9 +86,9 @@ void isValid_shouldReturnFalse_whenNameSizeMore32() { assertThat(isValid).isFalse(); } @Test - void isValid_shouldReturnFalse_whenFCDAInfoEmpty() { + void isValid_whenFCDAInfoEmpty_shouldReturnFalse() { DataSetInfo dataSetInfo = new DataSetInfo(); - assertNull(dataSetInfo.getName()); + assertThat(dataSetInfo.getName()).isNull(); dataSetInfo = new DataSetInfo("DATA_INFO"); //When boolean isValid = dataSetInfo.isValid(); @@ -94,7 +98,7 @@ void isValid_shouldReturnFalse_whenFCDAInfoEmpty() { } @Test - void isValid_shouldReturnTrue_whenFCDAInfosValid() { + void isValid_whenFCDAInfosValidshouldReturnTrue() { //Given TDataSet dataSet = new TDataSet(); dataSet.setName("dataset"); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DoTypeNameTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DoTypeNameTest.java index e9d384807..f00382bac 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DoTypeNameTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DoTypeNameTest.java @@ -15,7 +15,7 @@ class DoTypeNameTest { @Test - void testConstructorWithRef() { + void constructor_whenCalledWithDoName_shouldFillValues() { // given : nothing // when DoTypeName doTypeName = new DoTypeName("do1.bdo1.bdo2"); @@ -25,7 +25,7 @@ void testConstructorWithRef() { } @Test - void testConstructorWithRefWhenEmptyStruct() { + void constructor_whenCalledWithDoNameWithDotSeparatedValues_shouldFillValues() { // given : nothing // when DoTypeName doTypeName = new DoTypeName("do1"); @@ -35,17 +35,17 @@ void testConstructorWithRefWhenEmptyStruct() { } @Test - void testConstructorWithRefWithNullName() { + void constructor_whenCalledWithNullDoName_shouldNotFillValues() { // given : nothing // when DoTypeName doTypeName = new DoTypeName(null); // then - assertThat(doTypeName.getName()).isEqualTo(""); + assertThat(doTypeName.getName()).isEmpty(); assertThat(doTypeName.getStructNames()).isNotNull().isEmpty(); } @Test - void testConstructor2WithRef() { + void constructor_whenCalledWithDoNameAndSdoNames_shouldFillValues() { // given : nothing // when DoTypeName doTypeName = new DoTypeName("do1", "bdo1.bdo2"); @@ -55,7 +55,7 @@ void testConstructor2WithRef() { } @Test - void testConstructor2WithRefWhenEmptyStruct() { + void constructor_whenCalledWithNullSdoNames_shouldNotFillValues() { // given : nothing // when DoTypeName doTypeName = new DoTypeName("do1", null); @@ -65,17 +65,17 @@ void testConstructor2WithRefWhenEmptyStruct() { } @Test - void testConstructor2WithRefWithNullName() { + void constructor_whenCalledWithNullDoNameAndNullSdoNames_shouldNotFillValues() { // given : nothing // when DoTypeName doTypeName = new DoTypeName(null, null); // then - assertThat(doTypeName.getName()).isEqualTo(""); + assertThat(doTypeName.getName()).isEmpty(); assertThat(doTypeName.getStructNames()).isNotNull().isEmpty(); } @Test - void testConstructorWithNameAndStructNames() { + void constructor_whenCalledWithNameAndSdoNames_shouldFillValues() { // given : nothing // when DoTypeName doTypeName = new DoTypeName("do1", "bdo1.bdo2"); @@ -86,7 +86,7 @@ void testConstructorWithNameAndStructNames() { } @Test - void testEquals() { + void equals_whenCalled_shouldReturnTrue() { // given : nothing DoTypeName do1 = createDo("do1.bdo1.bdo2", TPredefinedCDCEnum.DPS); DoTypeName do2 = createDo("do1.bdo1.bdo2", TPredefinedCDCEnum.DPS); @@ -97,7 +97,7 @@ void testEquals() { } @Test - void testNotEquals() { + void equals_whenCalled_shouldReturnFalse() { // given : nothing DoTypeName do1 = createDo("do1.bdo1.bdo2", TPredefinedCDCEnum.DPS); DoTypeName do2 = createDo("do1.bdo1.bdo2", TPredefinedCDCEnum.ACD); @@ -108,7 +108,7 @@ void testNotEquals() { } @Test - void testFrom() { + void from_whenCalledWithDoTypeName_shouldNotFillValues() { // given : nothing DoTypeName do1 = createDo("do1.bdo1.bdo2", TPredefinedCDCEnum.DPS); // when diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefBindingInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefBindingInfoTest.java index 4951b53d6..e9a8f1072 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefBindingInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefBindingInfoTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.dto; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.exception.ScdException; @@ -13,107 +14,130 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.sct.commons.dto.DTO.P_DA; import static org.lfenergy.compas.sct.commons.dto.DTO.P_DO; class ExtRefBindingInfoTest { @Test - void testConstruction() { + @Tag("issue-321") + void constructor_whenCalled_shouldFillValues() { ExtRefBindingInfo bindingInfo = DTO.createExtRefBindingInfo_Remote(); ExtRefBindingInfo bindingInfo_bis = DTO.createExtRefBindingInfo_Remote(); + // When ExtRefBindingInfo bindingInfo_ter = new ExtRefBindingInfo(DTO.createExtRef()); + // When ExtRefBindingInfo bindingInfo_qt = new ExtRefBindingInfo(); - assertEquals(bindingInfo, bindingInfo_ter); - assertEquals(bindingInfo, bindingInfo_bis); - assertNotEquals(null, bindingInfo); - assertNotEquals(bindingInfo, bindingInfo_qt); + // Then + assertThat(bindingInfo_ter).isEqualTo(bindingInfo); + assertThat(bindingInfo_bis).isEqualTo(bindingInfo); + assertThat(bindingInfo).isNotNull(); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setDaName(bindingInfo.getDaName()); - assertNotEquals(bindingInfo, bindingInfo_qt); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setDoName(bindingInfo.getDoName()); - assertNotEquals(bindingInfo, bindingInfo_qt); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setIedName(bindingInfo.getIedName()); - assertNotEquals(bindingInfo, bindingInfo_qt); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setLdInst(bindingInfo.getLdInst()); - assertNotEquals(bindingInfo, bindingInfo_qt); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setLnInst(bindingInfo.getLnInst()); - assertNotEquals(bindingInfo, bindingInfo_qt); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setLnClass(bindingInfo.getLnClass()); - assertNotEquals(bindingInfo, bindingInfo_qt); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setPrefix(bindingInfo.getPrefix()); - assertNotEquals(bindingInfo, bindingInfo_qt); + assertThat(bindingInfo_qt).isNotEqualTo(bindingInfo); bindingInfo_qt.setServiceType(bindingInfo.getServiceType()); - assertEquals(bindingInfo, bindingInfo_qt); - assertEquals(bindingInfo.hashCode(), bindingInfo_qt.hashCode()); + assertThat(bindingInfo_qt).hasSameHashCodeAs(bindingInfo); } @Test + @Tag("issue-321") void testIsValid() { + // Given ExtRefBindingInfo bindingInfo = DTO.createExtRefBindingInfo_Remote(); - assertTrue(bindingInfo.isValid()); + // When Then + assertThat(bindingInfo.isValid()).isTrue(); bindingInfo.setLnClass("PIOC"); bindingInfo.setLnInst(""); - assertFalse(bindingInfo.isValid()); + // When Then + assertThat(bindingInfo.isValid()).isFalse(); bindingInfo.setDoName(new DoTypeName("do.sdo1.sdoError")); - assertFalse(bindingInfo.isValid()); + // When Then + assertThat(bindingInfo.isValid()).isFalse(); bindingInfo.setDaName(new DaTypeName("")); - assertFalse(bindingInfo.isValid()); + // When Then + assertThat(bindingInfo.isValid()).isFalse(); bindingInfo.setLnClass(""); - assertFalse(bindingInfo.isValid()); + // When Then + assertThat(bindingInfo.isValid()).isFalse(); bindingInfo.setLdInst(""); - assertFalse(bindingInfo.isValid()); + // When Then + assertThat(bindingInfo.isValid()).isFalse(); bindingInfo.setIedName(""); - assertFalse(bindingInfo.isValid()); - + // When Then + assertThat(bindingInfo.isValid()).isFalse(); } @Test + @Tag("issue-321") void testIsWrappedIn() { + // Given TExtRef extRef = DTO.createExtRef(); ExtRefBindingInfo bindingInfo = new ExtRefBindingInfo(); - assertFalse(bindingInfo.isWrappedIn(extRef)); + // When Then + assertThat(bindingInfo.isWrappedIn(extRef)).isFalse(); bindingInfo.setIedName(extRef.getIedName()); - assertFalse(bindingInfo.isWrappedIn(extRef)); + // When Then + assertThat(bindingInfo.isWrappedIn(extRef)).isFalse(); bindingInfo.setLdInst(extRef.getLdInst()); - assertFalse(bindingInfo.isWrappedIn(extRef)); + // When Then + assertThat(bindingInfo.isWrappedIn(extRef)).isFalse(); if (!extRef.getLnClass().isEmpty()) { bindingInfo.setLnClass(extRef.getLnClass().get(0)); - assertFalse(bindingInfo.isWrappedIn(extRef)); + // When Then + assertThat(bindingInfo.isWrappedIn(extRef)).isFalse(); bindingInfo.setLnInst(extRef.getLnInst()); - assertFalse(bindingInfo.isWrappedIn(extRef)); + // When Then + assertThat(bindingInfo.isWrappedIn(extRef)).isFalse(); bindingInfo.setPrefix(extRef.getPrefix()); - assertFalse(bindingInfo.isWrappedIn(extRef)); + // When Then + assertThat(bindingInfo.isWrappedIn(extRef)).isFalse(); } - bindingInfo.setServiceType(extRef.getServiceType()); - assertTrue(bindingInfo.isWrappedIn(extRef)); + // When Then + assertThat(bindingInfo.isWrappedIn(extRef)).isTrue(); } @Test + @Tag("issue-321") void testIsNull() { + // Given ExtRefBindingInfo bindingInfo = new ExtRefBindingInfo(); - assertTrue(bindingInfo.isNull()); + // When Then + assertThat(bindingInfo.isNull()).isTrue(); bindingInfo.setServiceType(TServiceType.REPORT); - assertFalse(bindingInfo.isNull()); + // When Then + assertThat(bindingInfo).isNotNull(); } @Test - void compareTo_should_return_0_when_ExtRefBindingInfo_the_same() { + void compareTo_when_ExtRefBindingInfo_the_same_should_return_0() { // Given ExtRefBindingInfo bindingInfo1 = DTO.createExtRefBindingInfo_Remote(); ExtRefBindingInfo bindingInfo2 = DTO.createExtRefBindingInfo_Remote(); @@ -126,7 +150,7 @@ void compareTo_should_return_0_when_ExtRefBindingInfo_the_same() { } @Test - void compareTo_should_return_positive_int_when_first_ExtRefBindingInfo_is_major_in_alphabetical_order() { + void compareTo_when_first_ExtRefBindingInfo_is_major_in_alphabetical_order_should_return_positive_int() { // Given ExtRefBindingInfo bindingInfo1 = DTO.createExtRefBindingInfo_Remote(); ExtRefBindingInfo bindingInfo2 = DTO.createExtRefBindingInfo_Source(); @@ -139,7 +163,7 @@ void compareTo_should_return_positive_int_when_first_ExtRefBindingInfo_is_major_ } @Test - void compareTo_should_return_negative_int_when_first_ExtRefBindingInfo_is_minor_in_alphabetical_order() { + void compareTo_when_first_ExtRefBindingInfo_is_minor_in_alphabetical_order_should_return_negative_int() { // Given ExtRefBindingInfo bindingInfo1 = DTO.createExtRefBindingInfo_Source(); ExtRefBindingInfo bindingInfo2 = DTO.createExtRefBindingInfo_Remote(); @@ -152,16 +176,18 @@ void compareTo_should_return_negative_int_when_first_ExtRefBindingInfo_is_minor_ } @Test - void findAndUpdateDAInfos_shouldThrowException_whenDAUnknown() { + @Tag("issue-321") + void findAndUpdateDAInfos_whenDAUnknown_shouldThrowException() { //Given ExtRefBindingInfo bindingInfo = DTO.createExtRefBindingInfo_Source(); ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); sclRootAdapter.getCurrentElem().setDataTypeTemplates(new TDataTypeTemplates()); - DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow( - sclRootAdapter::getDataTypeTemplateAdapter); + //When Then + DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow(sclRootAdapter::getDataTypeTemplateAdapter); + //Given TDA tda = new TDA(); tda.setName(P_DA); tda.setFc(TFCEnum.CF); @@ -188,7 +214,8 @@ void findAndUpdateDAInfos_shouldThrowException_whenDAUnknown() { } @Test - void findAndUpdateDAInfos_shouldThrowException_whenDANotCoherentWithDO() { + @Tag("issue-321") + void findAndUpdateDAInfos_whenDANotCoherentWithDO_shouldThrowException() { //Given ExtRefBindingInfo bindingInfo = DTO.createExtRefBindingInfo_Source(); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); @@ -196,9 +223,10 @@ void findAndUpdateDAInfos_shouldThrowException_whenDANotCoherentWithDO() { signalInfo.setPDA("P_DA"); SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); sclRootAdapter.getCurrentElem().setDataTypeTemplates(new TDataTypeTemplates()); - DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow( - sclRootAdapter::getDataTypeTemplateAdapter); + //When Then + DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow(sclRootAdapter::getDataTypeTemplateAdapter); + //Given TDA tda = new TDA(); tda.setName("P_DA"); tda.setFc(TFCEnum.CF); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfoTest.java index 38e9d9ff9..c455ce16c 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfoTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.dto; +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; @@ -15,27 +16,32 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; class ExtRefInfoTest { @Test - void testConstruction(){ + @Tag("issue-321") + void constructor_whenCalled_shouldFillValues(){ + // When ExtRefInfo extRefInfo = createExtRef(); - assertEquals(DTO.DESC,extRefInfo.getSignalInfo().getDesc()); - assertEquals(DTO.P_DA,extRefInfo.getSignalInfo().getPDA()); - assertEquals(DTO.P_DO,extRefInfo.getSignalInfo().getPDO()); - assertTrue(extRefInfo.getSignalInfo().getPLN().contains(DTO.P_LN)); - assertEquals(DTO.INT_ADDR, extRefInfo.getSignalInfo().getIntAddr()); - assertEquals(TServiceType.fromValue(DTO.P_SERV_T),extRefInfo.getSignalInfo().getPServT()); - assertNotNull(extRefInfo.getBindingInfo()); - assertNotNull(extRefInfo.getSourceInfo()); - + // Then + assertThat(extRefInfo.getSignalInfo().getDesc()).isEqualTo(DTO.DESC); + assertThat(extRefInfo.getSignalInfo().getPDA()).isEqualTo(DTO.P_DA); + assertThat(extRefInfo.getSignalInfo().getPDO()).isEqualTo(DTO.P_DO); + assertThat(extRefInfo.getSignalInfo().getPLN()).contains(DTO.P_LN); + assertThat(extRefInfo.getSignalInfo().getIntAddr()).isEqualTo(DTO.INT_ADDR); + assertThat(extRefInfo.getSignalInfo().getPServT()).isEqualTo(TServiceType.fromValue(DTO.P_SERV_T)); + assertThat(extRefInfo.getBindingInfo()).isNotNull(); + assertThat(extRefInfo.getSourceInfo()).isNotNull(); + + // Given TExtRef extRef = ExtRefSignalInfo.initExtRef(extRefInfo.getSignalInfo()); + // When ExtRefInfo extRefInfo1 = new ExtRefInfo(extRef); - assertNotNull(extRefInfo1.getBindingInfo()); - assertNotNull(extRefInfo1.getSourceInfo()); + // Then + assertThat(extRefInfo1.getBindingInfo()).isNotNull(); + assertThat(extRefInfo1.getSourceInfo()).isNotNull(); } private ExtRefInfo createExtRef(){ @@ -48,12 +54,11 @@ private ExtRefInfo createExtRef(){ } @Test - void checkMatchingFCDA_shouldreturnTrue_whenContentMatch() { + void checkMatchingFCDA_whenContentMatch_should_return_True() { //Given ExtRefInfo extRefInfo = new ExtRefInfo(); extRefInfo.setBindingInfo(DTO.createExtRefBindingInfo_Remote()); extRefInfo.setSignalInfo(DTO.createExtRefSignalInfo()); - TFCDA tfcda = new TFCDA(); tfcda.setLdInst(DTO.createExtRefBindingInfo_Remote().getLdInst()); tfcda.getLnClass().add(DTO.createExtRefBindingInfo_Remote().getLnClass()); @@ -68,7 +73,7 @@ void checkMatchingFCDA_shouldreturnTrue_whenContentMatch() { @ParameterizedTest(name = "{0}") @MethodSource("provideIncompleteExtRefInfo") - void checkMatchingFCDA(String testCase, TFCDA fcda, ExtRefBindingInfo bindingInfo, ExtRefSignalInfo signalInfo) { + void checkMatchingFCDA_whenCalled_should_return_false(String testCase, TFCDA fcda, ExtRefBindingInfo bindingInfo, ExtRefSignalInfo signalInfo) { //Given ExtRefInfo extRefInfo = new ExtRefInfo(); extRefInfo.setBindingInfo(bindingInfo); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSignalInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSignalInfoTest.java index 323ee4a94..51bf784d0 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSignalInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSignalInfoTest.java @@ -4,79 +4,91 @@ package org.lfenergy.compas.sct.commons.dto; -import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.TExtRef; import org.lfenergy.compas.scl2007b4.model.TServiceType; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; -@Slf4j class ExtRefSignalInfoTest { + @Test - void testConstruction(){ + void constructor_whenCalled_shouldFillValues() { + // When ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); - log.info("Signal : {}",signalInfo); - assertEquals(DTO.DESC,signalInfo.getDesc()); - assertEquals(DTO.P_DA,signalInfo.getPDA()); - assertEquals(DTO.P_DO,signalInfo.getPDO()); - assertEquals(DTO.P_LN,signalInfo.getPLN()); - assertEquals(DTO.INT_ADDR, signalInfo.getIntAddr()); - assertEquals(TServiceType.fromValue(DTO.P_SERV_T),signalInfo.getPServT()); - + // Then + assertThat(signalInfo.getDesc()).isEqualTo(DTO.DESC); + assertThat(signalInfo.getPDA()).isEqualTo(DTO.P_DA); + assertThat(signalInfo.getPDO()).isEqualTo(DTO.P_DO); + assertThat(signalInfo.getPLN()).isEqualTo(DTO.P_LN); + assertThat(signalInfo.getIntAddr()).isEqualTo(DTO.INT_ADDR); + assertThat(signalInfo.getPServT()).isEqualTo(TServiceType.fromValue(DTO.P_SERV_T)); } @Test - void testInitExtRef(){ + void initExtRef_whenCalledWithExtRefSignalInfo_shouldFillValues(){ + // When ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); TExtRef extRef = ExtRefSignalInfo.initExtRef(signalInfo); - - assertEquals(DTO.DESC,extRef.getDesc()); - assertEquals(DTO.P_DA,extRef.getPDA()); - assertEquals(DTO.P_DO,extRef.getPDO()); - assertTrue(extRef.getPLN().contains(DTO.P_LN)); - assertEquals(DTO.INT_ADDR, extRef.getIntAddr()); - assertEquals(TServiceType.fromValue(DTO.P_SERV_T),extRef.getPServT()); + // Then + assertThat(signalInfo.getDesc()).isEqualTo(DTO.DESC); + assertThat(signalInfo.getPDA()).isEqualTo(DTO.P_DA); + assertThat(signalInfo.getPDO()).isEqualTo(DTO.P_DO); + assertThat(extRef.getPLN()).asList().contains(DTO.P_LN); + assertThat(signalInfo.getIntAddr()).isEqualTo(DTO.INT_ADDR); + assertThat(signalInfo.getPServT()).isEqualTo(TServiceType.fromValue(DTO.P_SERV_T)); } @Test + @Tag("issue-321") void testIsWrappedIn(){ - + // Given TExtRef tExtRef = DTO.createExtRef(); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(tExtRef); ExtRefSignalInfo signalInfo1 = new ExtRefSignalInfo(); - assertTrue(signalInfo.isWrappedIn(tExtRef)); - - assertFalse(signalInfo1.isWrappedIn(tExtRef)); + // When Then + assertThat(signalInfo.isWrappedIn(tExtRef)).isTrue(); + // When Then + assertThat(signalInfo1.isWrappedIn(tExtRef)).isFalse(); signalInfo1.setDesc(signalInfo.getDesc()); - assertFalse(signalInfo1.isWrappedIn(tExtRef)); + // When Then + assertThat(signalInfo1.isWrappedIn(tExtRef)).isFalse(); signalInfo1.setPDA(signalInfo.getPDA()); - assertFalse(signalInfo1.isWrappedIn(tExtRef)); + // When Then + assertThat(signalInfo1.isWrappedIn(tExtRef)).isFalse(); signalInfo1.setPDO(signalInfo.getPDO()); - assertFalse(signalInfo1.isWrappedIn(tExtRef)); + // When Then + assertThat(signalInfo1.isWrappedIn(tExtRef)).isFalse(); signalInfo1.setIntAddr(signalInfo.getIntAddr()); - assertFalse(signalInfo1.isWrappedIn(tExtRef)); + // When Then + assertThat(signalInfo1.isWrappedIn(tExtRef)).isFalse(); signalInfo1.setPLN(signalInfo.getPLN()); - assertFalse(signalInfo1.isWrappedIn(tExtRef)); + // When Then + assertThat(signalInfo1.isWrappedIn(tExtRef)).isFalse(); signalInfo1.setPServT(signalInfo.getPServT()); - assertTrue(signalInfo1.isWrappedIn(tExtRef)); + // When Then + assertThat(signalInfo1.isWrappedIn(tExtRef)).isTrue(); } @Test + @Tag("issue-321") void testIsValid(){ + // Given ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); - assertTrue(signalInfo.isValid()); - + assertThat(signalInfo.isValid()).isTrue(); signalInfo.setIntAddr(""); - assertFalse(signalInfo.isValid()); + // When + assertThat(signalInfo.isValid()).isFalse(); signalInfo.setPDO(""); - assertFalse(signalInfo.isValid()); + // When + assertThat(signalInfo.isValid()).isFalse(); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSourceInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSourceInfoTest.java index da31d0dcd..96c64634a 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSourceInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ExtRefSourceInfoTest.java @@ -4,24 +4,30 @@ package org.lfenergy.compas.sct.commons.dto; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + class ExtRefSourceInfoTest { @Test + @Tag("issue-321") void testConstruction(){ + // Given ExtRefSourceInfo sourceInfo = DTO.createExtRefSourceInfo(); ExtRefSourceInfo bindingInfo_bis = DTO.createExtRefSourceInfo(); + // When ExtRefSourceInfo bindingInfo_ter = new ExtRefSourceInfo(DTO.createExtRef()); + // When ExtRefSourceInfo bindingInfo_qt = new ExtRefSourceInfo(); - assertEquals(sourceInfo,bindingInfo_ter); - assertEquals(sourceInfo.hashCode(),bindingInfo_ter.hashCode()); - assertEquals(sourceInfo,bindingInfo_bis); - assertNotEquals(null, sourceInfo); - assertNotEquals(sourceInfo, bindingInfo_qt); - assertNotEquals(sourceInfo, new ExtRefSourceInfo()); + // Then + assertThat(bindingInfo_ter).isEqualTo(sourceInfo).hasSameHashCodeAs(sourceInfo); + assertThat(bindingInfo_bis).isEqualTo(sourceInfo); + assertThat(sourceInfo).isNotNull(); + assertThat(bindingInfo_qt).isNotEqualTo(sourceInfo); + assertThat(new ExtRefSourceInfo()).isNotEqualTo(sourceInfo); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java index 1b730c708..2cc2612d9 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.dto; +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; @@ -14,14 +15,13 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; class FCDAInfoTest { @Test - void testConstructor(){ - + @Tag("issue-321") + void constructor_whenCalled_shouldFillValues(){ + // Given TFCDA tfcda = new TFCDA(); tfcda.setDoName("doName"); tfcda.setDaName("daName.bda1.bda2.bda3"); @@ -31,13 +31,14 @@ void testConstructor(){ tfcda.setLnInst("LNInst"); tfcda.setPrefix("pre"); tfcda.setIx(1L); - + // When FCDAInfo fcdaInfo = new FCDAInfo("dataSet",tfcda); - assertEquals("daName",fcdaInfo.getDaName().getName()); - assertEquals("doName",fcdaInfo.getDoName().getName()); - assertEquals(tfcda.getDaName(),fcdaInfo.getDaName().toString()); - assertEquals(3,fcdaInfo.getDaName().getStructNames().size()); - + // Then + assertThat(fcdaInfo.getDaName().getName()).isEqualTo("daName"); + assertThat(fcdaInfo.getDoName().getName()).isEqualTo("doName"); + assertThat(fcdaInfo.getDaName()).hasToString(tfcda.getDaName()); + assertThat(fcdaInfo.getDaName().getStructNames()).hasSize(3); + // When FCDAInfo fcdaInfo1 = new FCDAInfo(); fcdaInfo1.setIx(fcdaInfo.getIx()); fcdaInfo1.setLdInst(fcdaInfo.getLdInst()); @@ -47,25 +48,23 @@ void testConstructor(){ fcdaInfo1.setDoName(fcdaInfo.getDoName()); fcdaInfo1.setFc(fcdaInfo.getFc()); fcdaInfo1.setPrefix(fcdaInfo.getPrefix()); - assertEquals("daName",fcdaInfo1.getDaName().getName()); - assertEquals("doName",fcdaInfo1.getDoName().getName()); - assertEquals(tfcda.getDaName(),fcdaInfo1.getDaName().toString()); - + // Then + assertThat(fcdaInfo1.getDaName().getName()).isEqualTo("daName"); + assertThat(fcdaInfo1.getDoName().getName()).isEqualTo("doName"); + assertThat(fcdaInfo1.getDaName()).hasToString(tfcda.getDaName()); TFCDA tfcda1 = fcdaInfo1.getFCDA(); - - assertEquals(tfcda1.getFc(),fcdaInfo1.getFc()); - - assertTrue(fcdaInfo1.isValid()); + assertThat(fcdaInfo1.getFc()).isEqualTo(tfcda1.getFc()); + assertThat(fcdaInfo1.isValid()).isTrue(); } @ParameterizedTest(name = "{0}") @MethodSource("providerFCDAInfoObjects") - void checkFCDACompatibilitiesForBinding(String testCase, FCDAInfo fcdaInfo, FCDAInfo expectedFcdaInfo) { + void checkFCDACompatibilitiesForBinding_whenCalled_shouldReturnFalse(String testCase, FCDAInfo fcdaInfo, FCDAInfo expectedFcdaInfo) { assertThat(fcdaInfo.checkFCDACompatibilitiesForBinding(expectedFcdaInfo)).isFalse(); } @Test - void checkFCDACompatibilitiesForBinding_shouldReturnTrue_whensameContent() { + void checkFCDACompatibilitiesForBinding_whenCalledWithSameContent_shouldReturnTrue() { //Given TFCDA tfcda = new TFCDA(); tfcda.setLdInst(DTO.createExtRefBindingInfo_Remote().getLdInst()); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/HeaderDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/HeaderDTOTest.java index 531373b63..9680e6ba5 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/HeaderDTOTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/HeaderDTOTest.java @@ -7,39 +7,38 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.THitem; -import java.time.LocalDateTime; import java.util.UUID; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; class HeaderDTOTest { @Test - void testConstructor(){ + void constructor_whenCalled_shouldFillValues(){ + // Given UUID id = UUID.randomUUID(); + // When HeaderDTO headerDTO = DTO.createHeaderDTO(id); - - - assertEquals(id,headerDTO.getId()); - assertEquals("1.0",headerDTO.getVersion()); - assertEquals("1.0",headerDTO.getRevision()); - - assertFalse(headerDTO.getHistoryItems().isEmpty()); + // Then + assertThat(headerDTO.getId()).isEqualTo(id); + assertThat(headerDTO.getVersion()).isEqualTo("1.0"); + assertThat(headerDTO.getRevision()).isEqualTo("1.0"); + assertThat(headerDTO.getHistoryItems()).asList().isNotEmpty(); HeaderDTO.HistoryItem historyItem = headerDTO.getHistoryItems().get(0); - assertEquals("1.0",historyItem.getRevision()); - assertEquals("1.0",historyItem.getVersion()); - assertEquals("what",historyItem.getWhat()); - assertEquals("why",historyItem.getWhy()); - assertEquals("who",historyItem.getWho()); - assertEquals(DTO.NOW_STR,historyItem.getWhen()); - + assertThat(historyItem.getRevision()).isEqualTo("1.0"); + assertThat(historyItem.getVersion()).isEqualTo("1.0"); + assertThat(historyItem.getWhat()).isEqualTo("what"); + assertThat(historyItem.getWhy()).isEqualTo("why"); + assertThat(historyItem.getWho()).isEqualTo("who"); + assertThat(historyItem.getWhen()).isEqualTo(DTO.NOW_STR); headerDTO = new HeaderDTO(id,"1.0","1.0"); - assertEquals("1.0",headerDTO.getVersion()); - assertEquals("1.0",headerDTO.getRevision()); + assertThat(headerDTO.getVersion()).isEqualTo("1.0"); + assertThat(headerDTO.getRevision()).isEqualTo("1.0"); } @Test - void testHItemFrom(){ + void from_WhenCalledWithHitem_shouldFillValues(){ + // Given THitem tHitem = new THitem(); tHitem.setRevision("1.0"); tHitem.setVersion("1.0"); @@ -47,12 +46,13 @@ void testHItemFrom(){ tHitem.setWho("who"); tHitem.setWhy("why"); tHitem.setWhen(DTO.NOW_STR); - + // When HeaderDTO.HistoryItem historyItem = HeaderDTO.HistoryItem.from(tHitem); - assertEquals("1.0",historyItem.getRevision()); - assertEquals("1.0",historyItem.getVersion()); - assertEquals("what",historyItem.getWhat()); - assertEquals("why",historyItem.getWhy()); - assertEquals("who",historyItem.getWho()); + // Then + assertThat(historyItem.getRevision()).isEqualTo("1.0"); + assertThat(historyItem.getVersion()).isEqualTo("1.0"); + assertThat(historyItem.getWhat()).isEqualTo("what"); + assertThat(historyItem.getWhy()).isEqualTo("why"); + assertThat(historyItem.getWho()).isEqualTo("who"); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/IedDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/IedDTOTest.java index d0e3910e1..ebde50733 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/IedDTOTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/IedDTOTest.java @@ -10,39 +10,46 @@ import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; class IedDTOTest { @Test - void testConstruction(){ + void constructor_whenCalled_shouldFillValues(){ + // When IedDTO iedDTO = DTO.createIedDTO(); - + // Then assertAll("IedDTO", - () -> assertEquals(DTO.HOLDER_IED_NAME, iedDTO.getName()), - () -> assertFalse(iedDTO.getLDevices().isEmpty()) + () -> assertThat(iedDTO.getName()).isEqualTo(DTO.HOLDER_IED_NAME), + () -> assertThat(iedDTO.getLDevices()).isNotEmpty() ); - assertEquals(DTO.HOLDER_IED_NAME, new IedDTO(DTO.HOLDER_IED_NAME).getName()); + assertThat(new IedDTO(DTO.HOLDER_IED_NAME).getName()).isEqualTo(DTO.HOLDER_IED_NAME); } @Test - void testFrom() throws Exception { + void from_whenCalledWithIEDAdapter_shouldFillValues() { + // When SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); - + // When IedDTO iedDTO = IedDTO.from(iAdapter,null); - assertFalse(iedDTO.getLDevices().isEmpty()); + // Then + assertThat(iedDTO.getLDevices()).isNotEmpty(); } @Test - void testAddLDevice(){ + void addLDevice_whenCalled_shouldUpdateLDevicesList(){ + // Given IedDTO iedDTO = new IedDTO(); - assertTrue(iedDTO.getLDevices().isEmpty()); + assertThat(iedDTO.getLDevices()).isEmpty(); + // When iedDTO.addLDevice(DTO.HOLDER_LD_INST, "LDName"); - assertFalse(iedDTO.getLDevices().isEmpty()); - - assertTrue(iedDTO.getLDeviceDTO(DTO.HOLDER_LD_INST).isPresent()); + // Then + assertThat(iedDTO.getLDevices()).isNotEmpty(); + assertThat(iedDTO.getLDeviceDTO(DTO.HOLDER_LD_INST)).isPresent(); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDEPFSettingDataTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDEPFSettingDataTest.java index b504e09be..f6f597e2c 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDEPFSettingDataTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDEPFSettingDataTest.java @@ -7,12 +7,12 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.TExtRef; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.Assertions.assertThat; class LDEPFSettingDataTest { @Test - void isMatchExtRef_with_DigitalSettingData_should_return_true_when_ExtRefDescMatch() { + void isMatchExtRef_with_DigitalSettingData_when_ExtRefDescMatch_should_return_true() { //Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelDigitalNum(22).lnClass("PTRC") @@ -28,7 +28,7 @@ void isMatchExtRef_with_DigitalSettingData_should_return_true_when_ExtRefDescMat } @Test - void isMatchExtRef_with_DigitalSettingData_should_return_false_when_ExtRefDesc_DigitalNum_NotMatch() { + void isMatchExtRef_with_DigitalSettingData_when_ExtRefDesc_DigitalNum_NotMatch_should_return_false() { //Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelDigitalNum(22).lnClass("PTRC") @@ -45,7 +45,7 @@ void isMatchExtRef_with_DigitalSettingData_should_return_false_when_ExtRefDesc_D @Test - void isMatchExtRef_with_DigitalSettingData_should_return_false_when_ExtRefDesc_DaName_NotMatch() { + void isMatchExtRef_with_DigitalSettingData_when_ExtRefDesc_DaName_NotMatch_should_return_false() { //Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelDigitalNum(22).lnClass("PTRC") @@ -62,7 +62,7 @@ void isMatchExtRef_with_DigitalSettingData_should_return_false_when_ExtRefDesc_D @Test - void isMatchExtRef_with_AnalogSettingData_should_return_true_when_ExtRefDescMatch() { + void isMatchExtRef_with_AnalogSettingData_when_ExtRefDescMatch_should_return_true() { //Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelAnalogNum(22).lnClass("PTRC") @@ -78,7 +78,7 @@ void isMatchExtRef_with_AnalogSettingData_should_return_true_when_ExtRefDescMatc } @Test - void isMatchExtRef_with_AnalogSettingData_should_return_false_when_ExtRefDesc_DigitalNum_NotMatch() { + void isMatchExtRef_with_AnalogSettingData_when_ExtRefDesc_DigitalNum_NotMatch_should_return_false() { //Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelAnalogNum(22).lnClass("PTRC") @@ -95,7 +95,7 @@ void isMatchExtRef_with_AnalogSettingData_should_return_false_when_ExtRefDesc_Di @Test - void isMatchExtRef_with_AnalogSettingData_should_return_false_when_ExtRefDesc_DaName_NotMatch() { + void isMatchExtRef_with_AnalogSettingData_when_ExtRefDesc_DaName_NotMatch_should_return_false() { //Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelAnalogNum(22).lnClass("PTRC") @@ -111,7 +111,7 @@ void isMatchExtRef_with_AnalogSettingData_should_return_false_when_ExtRefDesc_Da } @Test - void isMatchExtRef_should_return_true_when_ExtRefMatch() { + void isMatchExtRef_when_ExtRefMatch_should_return_true() { // Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelDigitalNum(22).lnClass("PTRC") @@ -127,7 +127,7 @@ void isMatchExtRef_should_return_true_when_ExtRefMatch() { } @Test - void isMatchExtRef_should_return_false_when_ExtRefPLN_NotMatch() { + void isMatchExtRef_when_ExtRefPLN_NotMatch_should_return_false() { // Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelDigitalNum(22).lnClass("PTRC") @@ -143,7 +143,7 @@ void isMatchExtRef_should_return_false_when_ExtRefPLN_NotMatch() { } @Test - void isMatchExtRef_should_return_false_when_ExtRefPDO_NotMatch() { + void isMatchExtRef_when_ExtRefPDO_NotMatch_should_return_false() { // Given LDEPFSettingData ldepfSettingData = LDEPFSettingData.builder() .channelDigitalNum(22).lnClass("PTRC") diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java index 736853d7e..128e29246 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java @@ -5,6 +5,7 @@ package org.lfenergy.compas.sct.commons.dto; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.SCL; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; @@ -14,43 +15,53 @@ import java.util.Set; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertAll; class LDeviceDTOTest { @Test - void testConstruction(){ + void constructor_whenCalled_shouldFillValues() { + // When LDeviceDTO lDeviceDTO = DTO.createLdDTO(); - + // Then assertAll("LD_DTO", - () -> assertEquals(DTO.HOLDER_LD_INST, lDeviceDTO.getLdInst()), - () -> assertEquals(DTO.LD_NAME, lDeviceDTO.getLdName()), - () -> assertFalse(lDeviceDTO.getLNodes().isEmpty()) + () -> assertThat(lDeviceDTO.getLdInst()).isEqualTo(DTO.HOLDER_LD_INST), + () -> assertThat(lDeviceDTO.getLdName()).isEqualTo(DTO.LD_NAME), + () -> assertThat(lDeviceDTO.getLNodes()).isNotEmpty() ); - Set nodeDTOs = Set.of(DTO.createLNodeDTO(),DTO.createLNodeDTO()); lDeviceDTO.addAll(nodeDTOs); - assertEquals(3,lDeviceDTO.getLNodes().size()); + assertThat(lDeviceDTO.getLNodes()).hasSize(3); } @Test - void testAddLNOde(){ + void addLNode_whenCalled_shouldNotUpdateLNodeList(){ + // Given LDeviceDTO lDeviceDTO = new LDeviceDTO(); - assertTrue(lDeviceDTO.getLNodes().isEmpty()); - lDeviceDTO.addLNode(DTO.HOLDER_LN_CLASS,DTO.HOLDER_LN_INST,DTO.HOLDER_LN_PREFIX,DTO.LN_TYPE); - assertFalse(lDeviceDTO.getLNodes().isEmpty()); + assertThat(lDeviceDTO.getLNodes()).isEmpty(); + // When + lDeviceDTO.addLNode(DTO.HOLDER_LN_CLASS, DTO.HOLDER_LN_INST, DTO.HOLDER_LN_PREFIX, DTO.LN_TYPE); + // Then + assertThat(lDeviceDTO.getLNodes()).isNotEmpty(); } @Test - //@Disabled - void testFromLDAdapter() throws Exception { + @Tag("issue-321") + void from_whenCalledWithLDeviceAdapter_shouldFillValues() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get()); + // When LDeviceDTO lDeviceDTO = LDeviceDTO.from(lDeviceAdapter,null); - assertNotNull(lDeviceDTO); + // Then + assertThat(lDeviceDTO).isNotNull(); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java index a6ef62b05..3a92cbe91 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.dto; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.TExtRef; import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter; @@ -15,47 +16,61 @@ import java.util.List; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.when; class LNodeDTOTest { @Test + @Tag("issue-321") void testConstructor(){ + // When LNodeDTO lNodeDTO = new LNodeDTO(); lNodeDTO.setNodeClass(DTO.HOLDER_LN_CLASS); lNodeDTO.setInst(DTO.HOLDER_LN_INST); lNodeDTO.setPrefix(DTO.HOLDER_LN_PREFIX); lNodeDTO.setNodeType(DTO.LN_TYPE); + // Then assertAll("LNODE", - ()-> assertTrue(lNodeDTO.getGooseControlBlocks().isEmpty()), - ()-> assertTrue(lNodeDTO.getDataAttributeRefs().isEmpty()), - ()-> assertTrue(lNodeDTO.getDatSets().isEmpty()), - ()-> assertTrue(lNodeDTO.getExtRefs().isEmpty()), - ()-> assertEquals(DTO.HOLDER_LN_INST,lNodeDTO.getInst()), - ()-> assertEquals(DTO.HOLDER_LN_CLASS,lNodeDTO.getNodeClass()), - ()-> assertEquals(DTO.LN_TYPE,lNodeDTO.getNodeType()), - ()-> assertEquals(DTO.HOLDER_LN_PREFIX,lNodeDTO.getPrefix()) + ()-> assertThat(lNodeDTO.getGooseControlBlocks()).isEmpty(), + ()-> assertThat(lNodeDTO.getDataAttributeRefs()).isEmpty(), + ()-> assertThat(lNodeDTO.getDatSets()).isEmpty(), + ()-> assertThat(lNodeDTO.getExtRefs()).isEmpty(), + ()-> assertThat(lNodeDTO.getInst()).isEqualTo(DTO.HOLDER_LN_INST), + ()-> assertThat(lNodeDTO.getNodeClass()).isEqualTo(DTO.HOLDER_LN_CLASS), + ()-> assertThat(lNodeDTO.getNodeType()).isEqualTo(DTO.LN_TYPE), + ()-> assertThat(lNodeDTO.getPrefix()).isEqualTo(DTO.HOLDER_LN_PREFIX) ); + // When lNodeDTO.addDataAttributeRef(DataAttributeRef.builder().daName(new DaTypeName("da1")).build()); + // When lNodeDTO.addExtRefInfo(new ExtRefInfo()); + // When lNodeDTO.addControlBlock(new ReportControlBlock("rpt", "rptID", "rptDatSet")); + // When lNodeDTO.addDataSet(new DataSetInfo()); - + // When lNodeDTO.addAllControlBlocks(List.of(new SMVControlBlock("smv", "smvID", "smvDatSet"))); + // When lNodeDTO.addAllDatSets(List.of(new DataSetInfo())); + // When lNodeDTO.addAllExtRefInfo(List.of(new ExtRefInfo())); + // When lNodeDTO.addAllDataAttributeRef(List.of(DataAttributeRef.builder().daName(new DaTypeName("da2")).build())); - - assertEquals(2, lNodeDTO.getExtRefs().size()); - assertEquals(2, lNodeDTO.getDatSets().size()); - assertEquals(1, lNodeDTO.getSmvControlBlocks().size()); - assertEquals(1, lNodeDTO.getReportControlBlocks().size()); - assertEquals(2, lNodeDTO.getDataAttributeRefs().size()); + // Then + assertThat(lNodeDTO.getExtRefs()).hasSize(2); + assertThat(lNodeDTO.getDatSets()).hasSize(2); + assertThat(lNodeDTO.getSmvControlBlocks()).hasSize(1); + assertThat(lNodeDTO.getReportControlBlocks()).hasSize(1); + assertThat(lNodeDTO.getDataAttributeRefs()).hasSize(2); } @Test - void testFrom(){ + void from_whenCalledWithLNAdapter_shouldFillValues(){ + // When IEDAdapter iedAdapter = mock(IEDAdapter.class); LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); when(iedAdapter.getName()).thenReturn(DTO.HOLDER_IED_NAME); @@ -78,27 +93,29 @@ void testFrom(){ TExtRef extRef = DTO.createExtRef(); when(lnAdapter.getExtRefs(null)).thenReturn(List.of(extRef)); + // When LNodeDTO lNodeDTO = LNodeDTO.from(lnAdapter, new LogicalNodeOptions(true,true,false,false)); - assertNotNull(lNodeDTO); + // Then + assertThat(lNodeDTO).isNotNull(); assertAll("LNODE", - ()-> assertEquals(DTO.HOLDER_LN_INST,lNodeDTO.getInst()), - ()-> assertEquals(DTO.HOLDER_LN_CLASS,lNodeDTO.getNodeClass()), - ()-> assertEquals(DTO.LN_TYPE,lNodeDTO.getNodeType()), - ()-> assertEquals(DTO.HOLDER_LN_PREFIX,lNodeDTO.getPrefix()), - () -> assertEquals(1,lNodeDTO.getExtRefs().size()) + ()-> assertThat(lNodeDTO.getInst()).isEqualTo(DTO.HOLDER_LN_INST), + ()-> assertThat(lNodeDTO.getNodeClass()).isEqualTo(DTO.HOLDER_LN_CLASS), + ()-> assertThat(lNodeDTO.getNodeType()).isEqualTo(DTO.LN_TYPE), + ()-> assertThat(lNodeDTO.getPrefix()).isEqualTo(DTO.HOLDER_LN_PREFIX), + () -> assertThat(lNodeDTO.getExtRefs()).hasSize(1) ); ExtRefInfo extRefInfo = lNodeDTO.getExtRefs().iterator().next(); - - assertEquals(DTO.HOLDER_IED_NAME,extRefInfo.getHolderIEDName()); - assertEquals(DTO.HOLDER_LD_INST,extRefInfo.getHolderLDInst()); - assertEquals(DTO.HOLDER_LN_CLASS,extRefInfo.getHolderLnClass()); - assertEquals(DTO.HOLDER_LN_INST,extRefInfo.getHolderLnInst()); - assertEquals(DTO.HOLDER_LN_PREFIX,extRefInfo.getHolderLnPrefix()); + assertThat(extRefInfo.getHolderIEDName()).isEqualTo(DTO.HOLDER_IED_NAME); + assertThat(extRefInfo.getHolderLDInst()).isEqualTo(DTO.HOLDER_LD_INST); + assertThat(extRefInfo.getHolderLnClass()).isEqualTo(DTO.HOLDER_LN_CLASS); + assertThat(extRefInfo.getHolderLnInst()).isEqualTo(DTO.HOLDER_LN_INST); + assertThat(extRefInfo.getHolderLnPrefix()).isEqualTo(DTO.HOLDER_LN_PREFIX); } @Test - void testExtractExtRefInfo(){ + void extractExtRefInfo_whenCalledWithLNAdapter_shouldFillValues(){ + // Given LNAdapter lnAdapter = mock(LNAdapter.class); when(lnAdapter.getLNClass()).thenReturn(DTO.HOLDER_LN_CLASS); when(lnAdapter.getLNInst()).thenReturn(DTO.HOLDER_LN_INST); @@ -106,19 +123,18 @@ void testExtractExtRefInfo(){ when(lnAdapter.getPrefix()).thenReturn(DTO.HOLDER_LN_PREFIX); when(lnAdapter.hasInputs()).thenReturn(true); - TExtRef extRef = DTO.createExtRef(); when(lnAdapter.getExtRefs(null)).thenReturn(List.of(extRef)); - - + // When LNodeDTO lNodeDTO = LNodeDTO.extractExtRefInfo(lnAdapter); - assertNotNull(lNodeDTO); + // Then + assertThat(lNodeDTO).isNotNull(); assertAll("LNODE", - ()-> assertEquals(DTO.HOLDER_LN_INST,lNodeDTO.getInst()), - ()-> assertEquals(DTO.HOLDER_LN_CLASS,lNodeDTO.getNodeClass()), - ()-> assertEquals(DTO.LN_TYPE,lNodeDTO.getNodeType()), - ()-> assertEquals(DTO.HOLDER_LN_PREFIX,lNodeDTO.getPrefix()), - ()-> assertEquals(1,lNodeDTO.getExtRefs().size()) + ()-> assertThat(lNodeDTO.getInst()).isEqualTo(DTO.HOLDER_LN_INST), + ()-> assertThat(lNodeDTO.getNodeClass()).isEqualTo(DTO.HOLDER_LN_CLASS), + ()-> assertThat(lNodeDTO.getNodeType()).isEqualTo(DTO.LN_TYPE), + ()-> assertThat(lNodeDTO.getPrefix()).isEqualTo(DTO.HOLDER_LN_PREFIX), + () -> assertThat(lNodeDTO.getExtRefs()).hasSize(1) ); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LogicalNodeOptionsTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LogicalNodeOptionsTest.java index 5e0c7a696..b5ceeff15 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LogicalNodeOptionsTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LogicalNodeOptionsTest.java @@ -4,35 +4,41 @@ package org.lfenergy.compas.sct.commons.dto; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + class LogicalNodeOptionsTest { @Test - void testConstructor(){ + @Tag("issue-321") + void constructor_whenCalled_shouldFillValues() { + // When LogicalNodeOptions logicalNodeOptions = new LogicalNodeOptions(); - assertFalse(logicalNodeOptions.isWithExtRef()); - assertFalse(logicalNodeOptions.isWithCB()); - assertFalse(logicalNodeOptions.isWithDatSet()); - assertFalse(logicalNodeOptions.isWithDataAttributeRef()); + // Then + assertThat(logicalNodeOptions.isWithExtRef()).isFalse(); + assertThat(logicalNodeOptions.isWithCB()).isFalse(); + assertThat(logicalNodeOptions.isWithDatSet()).isFalse(); + assertThat(logicalNodeOptions.isWithDataAttributeRef()).isFalse(); logicalNodeOptions.setWithCB(true); logicalNodeOptions.setWithDatSet(false); logicalNodeOptions.setWithExtRef(false); logicalNodeOptions.setWithDataAttributeRef(false); - - assertFalse(logicalNodeOptions.isWithExtRef()); - assertTrue(logicalNodeOptions.isWithCB()); - assertFalse(logicalNodeOptions.isWithDatSet()); - assertFalse(logicalNodeOptions.isWithDataAttributeRef()); - - logicalNodeOptions = new LogicalNodeOptions(true,false, - true,false); - assertTrue(logicalNodeOptions.isWithExtRef()); - assertTrue(logicalNodeOptions.isWithCB()); - assertFalse(logicalNodeOptions.isWithDatSet()); - assertFalse(logicalNodeOptions.isWithDataAttributeRef()); + // Then + assertThat(logicalNodeOptions.isWithExtRef()).isFalse(); + assertThat(logicalNodeOptions.isWithCB()).isTrue(); + assertThat(logicalNodeOptions.isWithDatSet()).isFalse(); + assertThat(logicalNodeOptions.isWithDataAttributeRef()).isFalse(); + + // When + logicalNodeOptions = new LogicalNodeOptions(true,false, true,false); + // Then + assertThat(logicalNodeOptions.isWithExtRef()).isTrue(); + assertThat(logicalNodeOptions.isWithCB()).isTrue(); + assertThat(logicalNodeOptions.isWithDatSet()).isFalse(); + assertThat(logicalNodeOptions.isWithDataAttributeRef()).isFalse(); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlockTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlockTest.java index f8df27c2c..315d16ee6 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlockTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlockTest.java @@ -5,6 +5,7 @@ package org.lfenergy.compas.sct.commons.dto; import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.exception.ScdException; @@ -14,7 +15,7 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; class ReportControlBlockTest { @@ -50,12 +51,6 @@ void constructor_should_fill_default_values() { @Test void constructor_should_copy_all_data_from_TReportControl() { // Given - /* - optFields - rptEnabled - trgOps - - */ TReportControl tReportControl = createTReportControl(); // When ReportControlBlock reportControlBlock = new ReportControlBlock(tReportControl); @@ -148,61 +143,80 @@ void addToLN_should_add_ControlBlock_to_given_LN() { } @Test - void testGetServiceType() { + void getControlBlockEnum_when_Called_should_return_expected_type() { + // Given ReportControlBlock reportControlBlock = new ReportControlBlock(NAME, ID, DATASET_REF); - assertEquals(TServiceType.REPORT, reportControlBlock.getServiceType()); + // When Then + assertThat(reportControlBlock.getControlBlockEnum()).isEqualTo(ControlBlockEnum.REPORT); } @Test + @Tag("issue-321") void testValidateCB() { + // Given ReportControlBlock reportControlBlock = createReportControlBlock(); - assertDoesNotThrow(reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).doesNotThrowAnyException(); reportControlBlock.setDataSetRef(null); - assertDoesNotThrow(reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).doesNotThrowAnyException(); - assertFalse(reportControlBlock.getTargets().isEmpty()); + assertThat(reportControlBlock.getTargets()).isNotEmpty(); reportControlBlock.getTargets().set(0, new ControlBlockTarget("AP_REF", null, DTO.HOLDER_LD_INST, DTO.HOLDER_LN_INST, DTO.HOLDER_LN_CLASS, DTO.HOLDER_LN_PREFIX)); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); reportControlBlock.getTargets().set(0, new ControlBlockTarget("AP_REF", "", DTO.HOLDER_LD_INST, DTO.HOLDER_LN_INST, DTO.HOLDER_LN_CLASS, DTO.HOLDER_LN_PREFIX)); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); reportControlBlock.getTargets().set(0, new ControlBlockTarget("AP_REF", DTO.HOLDER_LD_INST, "", DTO.HOLDER_LN_INST, DTO.HOLDER_LN_CLASS, DTO.HOLDER_LN_PREFIX)); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); reportControlBlock.setDataSetRef(""); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); reportControlBlock.setName(null); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); reportControlBlock.setName(""); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); reportControlBlock.setId(null); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); reportControlBlock.setId(""); - assertThrows(ScdException.class, reportControlBlock::validateCB); + // When Then + assertThatCode(reportControlBlock::validateCB).isInstanceOf(ScdException.class); } @Test + @Tag("issue-321") void testGetControlBlockServiceSetting(){ + // Given ReportControlBlock reportControlBlock = createReportControlBlock(); - assertEquals(TServiceSettingsNoDynEnum.FIX, reportControlBlock.getControlBlockServiceSetting(null)); + // When Then + assertThat(reportControlBlock.getControlBlockServiceSetting(null)).isEqualTo(TServiceSettingsNoDynEnum.FIX); TServices tServices = Mockito.mock(TServices.class); TReportSettings reportSettings = Mockito.mock(TReportSettings.class); Mockito.when(tServices.getReportSettings()).thenReturn(reportSettings); Mockito.when(reportSettings.getCbName()).thenReturn(TServiceSettingsNoDynEnum.CONF); - assertEquals(TServiceSettingsNoDynEnum.CONF,reportControlBlock.getControlBlockServiceSetting(tServices)); + // When Then + assertThat(reportControlBlock.getControlBlockServiceSetting(tServices)).isEqualTo(TServiceSettingsNoDynEnum.CONF); Mockito.when(tServices.getReportSettings()).thenReturn(null); - assertEquals(TServiceSettingsNoDynEnum.FIX,reportControlBlock.getControlBlockServiceSetting(tServices)); + // When Then + assertThat(reportControlBlock.getControlBlockServiceSetting(tServices)).isEqualTo(TServiceSettingsNoDynEnum.FIX); } @Test diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlockTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlockTest.java index 487cc8248..9a6f0b774 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlockTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlockTest.java @@ -15,7 +15,9 @@ import java.util.UUID; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.lfenergy.compas.scl2007b4.model.TSampledValueControl.SmvOpts; class SMVControlBlockTest { diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SclDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SclDTOTest.java index c40bde465..6b5fe7a04 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SclDTOTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/SclDTOTest.java @@ -7,60 +7,67 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.header.HeaderAdapter; -import org.mockito.Mockito; import java.util.UUID; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class SclDTOTest { - @Test - void testConstructor(){ + void from_whenCalledWithSclRootAdapter_shouldFillValues(){ + // Given UUID id = UUID.randomUUID(); - SclRootAdapter sclRootAdapter = Mockito.mock(SclRootAdapter.class); - HeaderAdapter headerAdapter = Mockito.mock(HeaderAdapter.class); - Mockito.when(sclRootAdapter.getSclVersion()).thenReturn(SclRootAdapter.VERSION); - Mockito.when(sclRootAdapter.getSclRevision()).thenReturn(SclRootAdapter.REVISION); - Mockito.when(sclRootAdapter.getSclRelease()).thenReturn(SclRootAdapter.RELEASE); - Mockito.when(sclRootAdapter.getHeaderAdapter()).thenReturn(headerAdapter); - Mockito.when(headerAdapter.getHeaderId()).thenReturn(id.toString()); - Mockito.when(headerAdapter.getHeaderRevision()).thenReturn("hRevision"); - Mockito.when(headerAdapter.getHeaderVersion()).thenReturn("hVersion"); - - + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + HeaderAdapter headerAdapter = mock(HeaderAdapter.class); + when(sclRootAdapter.getSclVersion()).thenReturn(SclRootAdapter.VERSION); + when(sclRootAdapter.getSclRevision()).thenReturn(SclRootAdapter.REVISION); + when(sclRootAdapter.getSclRelease()).thenReturn(SclRootAdapter.RELEASE); + when(sclRootAdapter.getHeaderAdapter()).thenReturn(headerAdapter); + when(headerAdapter.getHeaderId()).thenReturn(id.toString()); + when(headerAdapter.getHeaderRevision()).thenReturn("hRevision"); + when(headerAdapter.getHeaderVersion()).thenReturn("hVersion"); + // When SclDTO sclDTO = SclDTO.from(sclRootAdapter); - SclDTO finalSclDTO = sclDTO; - assertAll("SCL_DTO", - () -> assertNotNull(finalSclDTO.getHeader()), - () -> assertEquals(id, finalSclDTO.getHeader().getId()), - () -> assertEquals("hVersion",finalSclDTO.getHeader().getVersion()), - () -> assertEquals("hRevision",finalSclDTO.getHeader().getRevision()) - ); + // Then + assertThat(sclDTO.getHeader()).isNotNull(); + assertThat(sclDTO.getHeader().getId()).isEqualTo(id); + assertThat(sclDTO.getHeader().getVersion()).isEqualTo("hVersion"); + assertThat(sclDTO.getHeader().getRevision()).isEqualTo("hRevision"); + } + + @Test + void constructor_whenCalledWithoutParameter_shouldFillValues(){ + // When SclDTO sclDTO1 = new SclDTO(); - sclDTO1.setHeader(sclDTO.getHeader()); - sclDTO1.setRelease(sclDTO.getRelease()); - sclDTO1.setId(sclDTO.getId()); - sclDTO1.setRevision(sclDTO.getRevision()); - sclDTO1.setVersion(sclDTO.getVersion()); - assertAll("SCL_DTO", - () -> assertNotNull(sclDTO1.getHeader()), - () -> assertEquals(id, sclDTO1.getHeader().getId()), - () -> assertEquals("hVersion",sclDTO1.getHeader().getVersion()), - () -> assertEquals("hRevision",sclDTO1.getHeader().getRevision()) - ); + HeaderDTO headerDTO = new HeaderDTO(); + UUID id = UUID.randomUUID(); + headerDTO.setId(id); + headerDTO.setRevision("hRevision"); + headerDTO.setVersion("hVersion"); + sclDTO1.setHeader(headerDTO); + sclDTO1.setId(id); + sclDTO1.setRelease(SclRootAdapter.RELEASE); + sclDTO1.setRevision(SclRootAdapter.REVISION); + sclDTO1.setVersion(SclRootAdapter.VERSION); + // Then + assertThat(sclDTO1.getHeader()).isNotNull(); + assertThat(sclDTO1.getHeader().getId()).isEqualTo(id); + assertThat(sclDTO1.getHeader().getVersion()).isEqualTo("hVersion"); + assertThat(sclDTO1.getHeader().getRevision()).isEqualTo("hRevision"); + } - sclDTO = new SclDTO(id); - assertEquals("",sclDTO.getWho()); - assertEquals("",sclDTO.getWhen()); - assertEquals("",sclDTO.getWhat()); - assertEquals("",sclDTO.getWhy()); + @Test + void constructor_whenCalledWithID_shouldFillValues(){ + // When + SclDTO sclDTO = new SclDTO(UUID.randomUUID()); sclDTO.setHeader(DTO.createHeaderDTO(UUID.randomUUID())); - - assertEquals("who",sclDTO.getWho()); - assertEquals(DTO.NOW_STR,sclDTO.getWhen()); - assertEquals("what",sclDTO.getWhat()); - assertEquals("why",sclDTO.getWhy()); + // Then + assertThat(sclDTO.getWho()).isEqualTo("who"); + assertThat(sclDTO.getWhen()).isEqualTo(DTO.NOW_STR); + assertThat(sclDTO.getWhat()).isEqualTo("what"); + assertThat(sclDTO.getWhy()).isEqualTo("why"); } } \ No newline at end of file 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 ffd5623bd..628b2ab8e 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 @@ -15,23 +15,31 @@ 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 { @Test - void testConstructor(){ + void constructor_whenCalledWithoutParameters_shouldNotFillValues() { + // When SubNetworkDTO subNetworkDTO = new SubNetworkDTO(); - assertTrue(subNetworkDTO.getConnectedAPs().isEmpty()); + // Then + assertThat(subNetworkDTO.getName()).isNull(); + assertThat(subNetworkDTO.getConnectedAPs()).isEmpty(); + } - subNetworkDTO = new SubNetworkDTO("sName","IP"); - assertEquals("sName",subNetworkDTO.getName()); - assertEquals("IP",subNetworkDTO.getType()); + @Test + void constructor_whenCalledWithParameters_shouldFillValues() { + // When + SubNetworkDTO subNetworkDTO = new SubNetworkDTO("sName","IP"); + // Then + assertThat(subNetworkDTO.getName()).isEqualTo("sName"); + assertThat(subNetworkDTO.getType()).isEqualTo("IP"); } @Test - void testFrom(){ + void from_whenCalledWithSubNetworkAdapter_shouldFillValues(){ + // Given SubNetworkAdapter subNetworkAdapter = Mockito.mock(SubNetworkAdapter.class); ConnectedAPAdapter connectedAPAdapter = Mockito.mock(ConnectedAPAdapter.class); when(subNetworkAdapter.getConnectedAPAdapters()).thenReturn(List.of(connectedAPAdapter)); @@ -39,12 +47,12 @@ void testFrom(){ when(subNetworkAdapter.getType()).thenReturn(SubNetworkDTO.SubnetworkType.IP.toString()); when(connectedAPAdapter.getApName()).thenReturn(DTO.AP_NAME); when(connectedAPAdapter.getIedName()).thenReturn(DTO.HOLDER_IED_NAME); - + // When SubNetworkDTO subNetworkDTO = SubNetworkDTO.from(subNetworkAdapter); - assertEquals("sName",subNetworkDTO.getName()); - assertEquals("IP",subNetworkDTO.getType()); - assertFalse(subNetworkDTO.getConnectedAPs().isEmpty()); - + // Then + assertThat(subNetworkDTO.getName()).isEqualTo("sName"); + assertThat(subNetworkDTO.getType()).isEqualTo("IP"); + assertThat(subNetworkDTO.getConnectedAPs()).isNotEmpty(); } @Test @@ -68,6 +76,5 @@ void createDefaultSubnetwork_should_return_filtered_subnetwork_list() { assertThat(subNetworkDTOS).hasSize(2); SubNetworkDTO expectedSubNetwork = subNetworkDTOS.stream().filter(subNetworkDTO -> !subNetworkDTO.getConnectedAPs().isEmpty()).findFirst().orElse(new SubNetworkDTO()); assertThat(expectedSubNetwork.getConnectedAPs()).hasSize(1); - } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/exception/ScdExceptionTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/exception/ScdExceptionTest.java index 63746e822..885f97274 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/exception/ScdExceptionTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/exception/ScdExceptionTest.java @@ -6,7 +6,8 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + class ScdExceptionTest { private static final String MSG = "MSG"; @@ -14,13 +15,22 @@ class ScdExceptionTest { private static final String CAUSE_MSG = "CAUSE_MSG"; @Test - void testInit() { + void constructor_whenCalledWithMessage_shouldFillValues() { + // When ScdException exception = new ScdException(MSG); - assertEquals(MSG, exception.getMessage()); - exception = new ScdException(ANOTHER_MSG, new RuntimeException(CAUSE_MSG)); - assertEquals(ANOTHER_MSG, exception.getMessage()); - assertEquals(RuntimeException.class, exception.getCause().getClass()); - assertEquals(CAUSE_MSG, exception.getCause().getMessage()); + // Then + assertThat(exception.getMessage()).isEqualTo(MSG); } + @Test + void constructor_whenCalledWithMessageAndThrowable_shouldFillValues() { + // When + ScdException exception = new ScdException(ANOTHER_MSG, new RuntimeException(CAUSE_MSG)); + // Then + assertThat(exception.getMessage()).isEqualTo(ANOTHER_MSG); + assertThat(exception.getCause().getClass()).isEqualTo(RuntimeException.class); + assertThat(exception.getCause().getMessage()).isEqualTo(CAUSE_MSG); + } + + } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ObjectReferenceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ObjectReferenceTest.java index 837d64c91..db48d8a0c 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ObjectReferenceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ObjectReferenceTest.java @@ -6,25 +6,44 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class ObjectReferenceTest { @Test - void testConstructor(){ + void constructor_whenCalled_shouldFillValues() { + // Given String ref = "IED_NAME_LD_NAME/PR_LN_INST.doi.sdoi.sdai.bdai.bda"; + // When ObjectReference objRef = new ObjectReference(ref); objRef.init(); - assertEquals("IED_NAME_LD_NAME",objRef.getLdName()); - assertEquals("PR_LN_INST",objRef.getLNodeName()); - assertEquals("doi.sdoi.sdai.bdai.bda",objRef.getDataAttributes()); + // Then + assertThat(objRef.getLdName()).isEqualTo("IED_NAME_LD_NAME"); + assertThat(objRef.getLNodeName()).isEqualTo("PR_LN_INST"); + assertThat(objRef.getDataAttributes()).isEqualTo("doi.sdoi.sdai.bdai.bda"); + } + @Test + void constructor_whenCalledWithInvalidLdName_shouldReturnException() { + // Given String ref0 = "IED_NAME_LD_NAMEPR_LN_INST.doi.sdoi.sdai.bdai.bda"; - assertThrows(IllegalArgumentException.class, () ->new ObjectReference(ref0)); + // When Then + assertThatThrownBy(() ->new ObjectReference(ref0)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Malformed ObjRef : IED_NAME_LD_NAMEPR_LN_INST.doi.sdoi.sdai.bdai.bda"); + } + @Test + void constructor_whenCalledWithInvalidLNodeName_shouldReturnException() { + // Given String ref1 = "IED_NAME_LD_NAME/PR_LN_INST"; - assertThrows(IllegalArgumentException.class, () ->new ObjectReference(ref1)); + // When Then + assertThatThrownBy(() ->new ObjectReference(ref1)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Malformed ObjRef : IED_NAME_LD_NAME/PR_LN_INST"); + } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclMockedElement.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclMockedElement.java deleted file mode 100644 index 00a13d468..000000000 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclMockedElement.java +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl; - -public abstract class SclMockedElement

{ - protected P sclElementAdapter; - protected T sclElement; - - public void init(){ - sclElementAdapter = (P) getMockedSclParentAdapter(); - completeInit(); - } - protected abstract SclElementAdapter getMockedSclParentAdapter(); - protected abstract void completeInit() ; - -} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java index 3b7b5e720..99bfd7ba0 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapterTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.scl; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.SCL; import org.lfenergy.compas.scl2007b4.model.TPrivate; @@ -15,62 +16,77 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable; class SclRootAdapterTest { - @Test + @Tag("issue-321") void testConstruction() { + // Given AtomicReference sclRootAdapterAtomicReference = new AtomicReference<>(); - assertDoesNotThrow(() -> - sclRootAdapterAtomicReference.set(new SclRootAdapter("hID", "hVersion", "hRevision")) - ); - + assertThatCode(() -> sclRootAdapterAtomicReference.set(new SclRootAdapter("hID", "hVersion", "hRevision"))) + .doesNotThrowAnyException(); SclRootAdapter sclRootAdapter = sclRootAdapterAtomicReference.get(); - assertThrows(ScdException.class, - () -> sclRootAdapter.addHeader("hID1","hVersion1","hRevision1")); - - assertTrue(sclRootAdapter.amChildElementRef()); - assertEquals(SclRootAdapter.RELEASE, sclRootAdapter.getSclRelease()); - assertEquals(SclRootAdapter.VERSION, sclRootAdapter.getSclVersion()); - assertEquals(SclRootAdapter.REVISION, sclRootAdapter.getSclRevision()); + // When Then + // addHeader is not the purpose of this test + assertThatCode(() -> sclRootAdapter.addHeader("hID1","hVersion1","hRevision1")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("SCL already contains header"); + assertThat(sclRootAdapter.amChildElementRef()).isTrue(); + assertThat(sclRootAdapter.getSclRelease()).isEqualTo(SclRootAdapter.RELEASE); + assertThat(sclRootAdapter.getSclVersion()).isEqualTo(SclRootAdapter.VERSION); + assertThat(sclRootAdapter.getSclRevision()).isEqualTo(SclRootAdapter.REVISION); assertIsMarshallable(sclRootAdapter.getCurrentElem()); - + // Given SCL scd = new SCL(); - assertThrows(IllegalArgumentException.class, () -> new SclRootAdapter(scd)); + // When Then + assertThatCode(() -> new SclRootAdapter(scd)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid SCD: no tag Header found"); } @Test - void addIED() { - + // Test name should be modified to reflect each test case. + @Tag("issue-321") + void testAddIED() { + //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-root-test-schema-conf/add_ied_test.xml"); SCL icd1 = SclTestMarshaller.getSCLFromFile("/scl-root-test-schema-conf/icd1_to_add_test.xml"); SCL icd2 = SclTestMarshaller.getSCLFromFile("/scl-root-test-schema-conf/icd2_to_add_test.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); SCL icd = new SCL(); - assertThrows(ScdException.class, () -> sclRootAdapter.addIED(icd, "IED_NAME1")); - assertDoesNotThrow(() -> sclRootAdapter.addIED(icd1, "IED_NAME1")); - assertThrows(ScdException.class, () -> sclRootAdapter.addIED(icd1, "IED_NAME1")); - assertDoesNotThrow(() -> sclRootAdapter.addIED(icd2, "IED_NAME2")); + //When Then + assertThatCode(() -> sclRootAdapter.addIED(icd, "IED_NAME1")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("No IED to import from ICD file"); + //When Then + assertThatCode(() -> sclRootAdapter.addIED(icd1, "IED_NAME1")) + .doesNotThrowAnyException(); + //When Then + assertThatCode(() -> sclRootAdapter.addIED(icd1, "IED_NAME1")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("SCL file already contains IED: IED_NAME1"); + //When Then + assertThatCode(() -> sclRootAdapter.addIED(icd2, "IED_NAME2")) + .doesNotThrowAnyException(); assertIsMarshallable(scd); } @Test - void addPrivate() { + void addPrivate_should_create_private() { + //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-root-test-schema-conf/add_ied_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(sclRootAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(sclRootAdapter.getCurrentElem().getPrivate()).isEmpty(); + //When sclRootAdapter.addPrivate(tPrivate); - assertEquals(1, sclRootAdapter.getCurrentElem().getPrivate().size()); + //Then + assertThat(sclRootAdapter.getCurrentElem().getPrivate()).hasSize(1); assertIsMarshallable(scd); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/AbstractComLevel.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/AbstractComLevel.java deleted file mode 100644 index 61effdf30..000000000 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/AbstractComLevel.java +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl.com; - -import org.lfenergy.compas.scl2007b4.model.TCommunication; -import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; - -import org.lfenergy.compas.sct.commons.scl.SclMockedElement; -import org.mockito.Mockito; - -public abstract class AbstractComLevel

extends SclMockedElement{ - - - public SclElementAdapter getMockedSclParentAdapter(){ - CommunicationAdapter dataTypeTemplateAdapter = Mockito.mock(CommunicationAdapter.class); - TCommunication tCommunication = Mockito.mock(TCommunication.class); - Mockito.when(dataTypeTemplateAdapter.getCurrentElem()).thenReturn(tCommunication); - - return dataTypeTemplateAdapter; - } -} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/CommunicationAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/CommunicationAdapterTest.java index 3115a3f19..95e64a9e7 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/CommunicationAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/CommunicationAdapterTest.java @@ -4,31 +4,47 @@ package org.lfenergy.compas.sct.commons.scl.com; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class CommunicationAdapterTest { @Test - void testAmChildElementRef() throws ScdException { - SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); - sclRootAdapter.getCurrentElem().setCommunication(new TCommunication()); - CommunicationAdapter cAdapter = sclRootAdapter.getCommunicationAdapter(true); - assertTrue(cAdapter.amChildElementRef()); + void constructor_whenCalledWithNoRelationBetweenSCLAndCommunication_shouldThrowException() { + //Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + TCommunication communication = new TCommunication(); + //When Then + assertThatCode(() -> new CommunicationAdapter(sclRootAdapter, communication)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); + } - CommunicationAdapter finalCAdapter = new CommunicationAdapter(sclRootAdapter); - TCommunication tCommunication = new TCommunication(); - assertThrows(IllegalArgumentException.class, - () -> finalCAdapter.setCurrentElem(tCommunication)); + @Test + void constructor_whenCalledWithExistingRelationBetweenSCLAndCommunication_shouldNotThrowException() { + //Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + SCL scl = new SCL(); + TCommunication communication = new TCommunication(); + scl.setCommunication(communication); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + //When Then + assertThatCode(() -> new CommunicationAdapter(sclRootAdapter, communication)).doesNotThrowAnyException(); } @Test - void testAddSubnetwork() throws ScdException { + @Tag("issue-321") + void testAddSubnetwork() { + // Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); TIED tied = new TIED(); tied.setName("IED_NAME"); @@ -40,62 +56,67 @@ void testAddSubnetwork() throws ScdException { tied.getAccessPoint().add(tAccessPoint2); sclRootAdapter.getCurrentElem().getIED().add(tied); CommunicationAdapter communicationAdapter = sclRootAdapter.getCommunicationAdapter(true); - assertDoesNotThrow( - () -> communicationAdapter.addSubnetwork("snName", "snType", - "IED_NAME", "apName") - ); - assertDoesNotThrow( - () -> communicationAdapter.addSubnetwork("snName", "snType", - "IED_NAME", "apName2") - ); - - assertThrows( - ScdException.class, - () -> communicationAdapter.addSubnetwork("snName", "snType", - "IED_NAME1", "apName") - ); - assertThrows( - ScdException.class, - () -> communicationAdapter.addSubnetwork("snName", "snType", - "IED_NAME", "apName1") - ); + // When Then + assertThatCode(() -> communicationAdapter.addSubnetwork("snName", "snType", + "IED_NAME", "apName")) + .doesNotThrowAnyException(); + // When Then + assertThatCode(() -> communicationAdapter.addSubnetwork("snName", "snType", + "IED_NAME", "apName2")) + .doesNotThrowAnyException(); + // When Then + assertThatCode(() -> communicationAdapter.addSubnetwork("snName", "snType", + "IED_NAME1", "apName")) + .isInstanceOf(ScdException.class) + .hasMessage("IED.name 'IED_NAME1' not found in SCD"); + // When Then + assertThatCode(() -> communicationAdapter.addSubnetwork("snName", "snType", + "IED_NAME", "apName1")) + .isInstanceOf(ScdException.class) + .hasMessage("Unknown AccessPoint :apName1 in IED :IED_NAME"); } @Test - void testFindSubnetworkByName() throws ScdException { + void getSubnetworkByName_should_return_SubNetworkAdapter() { + // Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); CommunicationAdapter communicationAdapter = sclRootAdapter.getCommunicationAdapter(true); TSubNetwork tSubNetwork = new TSubNetwork(); tSubNetwork.setName("snName"); communicationAdapter.getCurrentElem().getSubNetwork().add(tSubNetwork); - - assertTrue(communicationAdapter.getSubnetworkByName("snName").isPresent()); - assertFalse(communicationAdapter.getSubnetworkByName("snName_NO").isPresent()); + // When Then + assertThat(communicationAdapter.getSubnetworkByName("snName")).isPresent(); + assertThat(communicationAdapter.getSubnetworkByName("snName_NO")).isEmpty(); } @Test - void testGetSubNetworkAdapters(){ + void getSubNetworkAdapters_should_return_list_of_SubNetworkAdapter(){ + // Given CommunicationAdapter communicationAdapter = new CommunicationAdapter(null,new TCommunication()); - assertTrue(communicationAdapter.getSubNetworkAdapters().isEmpty()); + assertThat(communicationAdapter.getSubNetworkAdapters()).isEmpty(); TSubNetwork tSubNetwork = new TSubNetwork(); tSubNetwork.setName("snName"); communicationAdapter.getCurrentElem().getSubNetwork().add(tSubNetwork); - assertFalse(communicationAdapter.getSubNetworkAdapters().isEmpty()); + // When Then + assertThat(communicationAdapter.getSubNetworkAdapters()).isNotEmpty(); } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + // Given CommunicationAdapter communicationAdapter = new CommunicationAdapter(null,new TCommunication()); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(communicationAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(communicationAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When communicationAdapter.addPrivate(tPrivate); - assertEquals(1, communicationAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(communicationAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test - void elementXPath() { + void elementXPath_should_return_expected_xpath_value() { // Given CommunicationAdapter communicationAdapter = new CommunicationAdapter(null,new TCommunication()); // When 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 522ecd2c4..5961c82ce 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 @@ -5,7 +5,7 @@ package org.lfenergy.compas.sct.commons.scl.com; import org.assertj.core.groups.Tuple; -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.CsvSource; @@ -17,73 +17,108 @@ import java.math.BigDecimal; import java.util.List; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class ConnectedAPAdapterTest { - private SubNetworkAdapter subNetworkAdapter; - - @BeforeEach - void setUp() { - subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); - TConnectedAP tConnectedAP = newConnectedAp(DTO.HOLDER_IED_NAME, DTO.AP_NAME); - subNetworkAdapter.getCurrentElem().getConnectedAP().add(tConnectedAP); + @Test + void constructor_whenCalledWithNoRelationBetweenSubNetworkAndConnectedAP_shouldThrowException() { + //Given + SubNetworkAdapter subNetworkAdapter = mock(SubNetworkAdapter.class); + when(subNetworkAdapter.getCurrentElem()).thenReturn(new TSubNetwork()); + TConnectedAP connectedAP = new TConnectedAP(); + //When Then + assertThatCode(() -> new ConnectedAPAdapter(subNetworkAdapter, connectedAP)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void testAmChildElementRef() { - ConnectedAPAdapter connectedAPAdapter = assertDoesNotThrow( - () -> subNetworkAdapter.getConnectedAPAdapter(DTO.HOLDER_IED_NAME, DTO.AP_NAME) - ); - - assertEquals(DTO.HOLDER_IED_NAME, connectedAPAdapter.getIedName()); - assertEquals(DTO.AP_NAME, connectedAPAdapter.getApName()); + void constructor_whenCalledWithExistingRelationBetweenSubNetworkAndConnectedAP_shouldNotThrowException() { + //Given + SubNetworkAdapter subNetworkAdapter = mock(SubNetworkAdapter.class); + TSubNetwork subNetwork = new TSubNetwork(); + TConnectedAP connectedAP = new TConnectedAP(); + subNetwork.getConnectedAP().add(connectedAP); + when(subNetworkAdapter.getCurrentElem()).thenReturn(subNetwork); + //When Then + assertThatCode(() -> new ConnectedAPAdapter(subNetworkAdapter, connectedAP)) + .doesNotThrowAnyException(); } @Test - void addPrivate() { - ConnectedAPAdapter connectedAPAdapter = subNetworkAdapter.getConnectedAPAdapter(DTO.HOLDER_IED_NAME, DTO.AP_NAME); + void addPrivate_with_type_and_source_should_create_Private() { + //Given + SubNetworkAdapter subNetworkAdapter = mock(SubNetworkAdapter.class); + TSubNetwork subNetwork = new TSubNetwork(); + TConnectedAP connectedAP = new TConnectedAP(); + subNetwork.getConnectedAP().add(connectedAP); + when(subNetworkAdapter.getCurrentElem()).thenReturn(subNetwork); + ConnectedAPAdapter connectedAPAdapter = new ConnectedAPAdapter(subNetworkAdapter, connectedAP); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(connectedAPAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(connectedAPAdapter.getCurrentElem().getPrivate()).isEmpty(); + //When connectedAPAdapter.addPrivate(tPrivate); - assertEquals(1, connectedAPAdapter.getCurrentElem().getPrivate().size()); + //Then + assertThat(connectedAPAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test - void testCopyAddressAndPhysConnFromIcd_withFilledCommunication() { + void copyAddressAndPhysConnFromIcd_when_apName_exist_in_ICD_Communication_should_update_subNetwork() { // GIVEN - ConnectedAPAdapter connectedAPAdapter = assertDoesNotThrow( - () -> subNetworkAdapter.getConnectedAPAdapter(DTO.HOLDER_IED_NAME, DTO.AP_NAME) - ); - + SubNetworkAdapter subNetworkAdapter = mock(SubNetworkAdapter.class); + TSubNetwork subNetwork = new TSubNetwork(); + TConnectedAP connectedAP = newConnectedAp(DTO.HOLDER_IED_NAME, DTO.AP_NAME); + subNetwork.getConnectedAP().add(connectedAP); + when(subNetworkAdapter.getCurrentElem()).thenReturn(subNetwork); + ConnectedAPAdapter connectedAPAdapter = new ConnectedAPAdapter(subNetworkAdapter, connectedAP); SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_with_filled_communication.xml"); SclRootAdapter icdRootAdapter = new SclRootAdapter(icd); - // WHEN connectedAPAdapter.copyAddressAndPhysConnFromIcd(icdRootAdapter.getCurrentElem()); - // THEN assertThat(connectedAPAdapter.getCurrentElem().getAddress()).isNotNull(); - assertThat(connectedAPAdapter.getCurrentElem().getPhysConn()).isNotNull(); + assertThat(connectedAPAdapter.getCurrentElem().getPhysConn()).isNotEmpty(); assertThat(connectedAPAdapter.getCurrentElem().getGSE()).isEmpty(); } @Test - void testCopyAddressAndPhysConnFromIcd_withEmptyIcd() { + void copyAddressAndPhysConnFromIcd_when_apName_not_exist_in_ICD_Communication_should_not_update_subNetwork() { // GIVEN - ConnectedAPAdapter connectedAPAdapter = assertDoesNotThrow( - () -> subNetworkAdapter.getConnectedAPAdapter(DTO.HOLDER_IED_NAME, DTO.AP_NAME) - ); + SubNetworkAdapter subNetworkAdapter = mock(SubNetworkAdapter.class); + TSubNetwork subNetwork = new TSubNetwork(); + TConnectedAP connectedAP = new TConnectedAP(); + subNetwork.getConnectedAP().add(connectedAP); + when(subNetworkAdapter.getCurrentElem()).thenReturn(subNetwork); + ConnectedAPAdapter connectedAPAdapter = new ConnectedAPAdapter(subNetworkAdapter, connectedAP); + SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_with_filled_communication.xml"); + SclRootAdapter icdRootAdapter = new SclRootAdapter(icd); + // WHEN + connectedAPAdapter.copyAddressAndPhysConnFromIcd(icdRootAdapter.getCurrentElem()); + // THEN + assertThat(connectedAPAdapter.getCurrentElem().getAddress()).isNull(); + assertThat(connectedAPAdapter.getCurrentElem().getPhysConn()).isEmpty(); + assertThat(connectedAPAdapter.getCurrentElem().getGSE()).isEmpty(); + } + @Test + void copyAddressAndPhysConnFromIcd_whenCalledWithEmptyIcd_shouldNotUpdateSubNetwork() { + // GIVEN + SubNetworkAdapter subNetworkAdapter = mock(SubNetworkAdapter.class); + TSubNetwork subNetwork = new TSubNetwork(); + TConnectedAP connectedAP = newConnectedAp(DTO.HOLDER_IED_NAME, DTO.AP_NAME); + subNetwork.getConnectedAP().add(connectedAP); + when(subNetworkAdapter.getCurrentElem()).thenReturn(subNetwork); + ConnectedAPAdapter connectedAPAdapter = new ConnectedAPAdapter(subNetworkAdapter, connectedAP); // WHEN connectedAPAdapter.copyAddressAndPhysConnFromIcd(null); - // THEN assertThat(connectedAPAdapter.getCurrentElem().getAddress()).isNull(); assertThat(connectedAPAdapter.getCurrentElem().getPhysConn()).isEmpty(); @@ -93,7 +128,7 @@ void testCopyAddressAndPhysConnFromIcd_withEmptyIcd() { @ParameterizedTest @CsvSource(value = {"IED_NAME;AP_NAME;ConnectedAP[@apName=\"AP_NAME\" and @iedName=\"IED_NAME\"]", ";;ConnectedAP[not(@apName) and not(@iedName)]"} , delimiter = ';') - void elementXPath(String iedName, String apName, String message) { + void elementXPath_should_return_expected_xpath_value(String iedName, String apName, String message) { // Given ConnectedAPAdapter connectedAPAdapter = newConnectedApAdapter(iedName, apName); // When @@ -122,9 +157,11 @@ void updateGseOrCreateIfNotExists_should_create_GSE(){ } @Test + @Tag("issue-321") void updateGseOrCreateIfNotExists_when_exists_should_update_GSE(){ // Given ConnectedAPAdapter connectedAPAdapter = newConnectedApAdapter("IED_NAME", "AP_NAME"); + // When connectedAPAdapter.updateGseOrCreateIfNotExists("ldinst", "cbName", List.of(SclConstructorHelper.newP("APPID", "0001")), newDurationInMilliSec(5), newDurationInMilliSec(10)); // When diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java index 9e339474c..3f846bc3e 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/com/SubNetworkAdapterTest.java @@ -6,6 +6,7 @@ import org.assertj.core.api.Assertions; import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -20,47 +21,64 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class SubNetworkAdapterTest { @Test - void testAmChildElementRef() { - CommunicationAdapter communicationAdapter = new CommunicationAdapter(null,new TCommunication()); - TSubNetwork tSubNetwork = new TSubNetwork(); - tSubNetwork.setName("sName"); - tSubNetwork.setType("sType"); - communicationAdapter.getCurrentElem().getSubNetwork().add(tSubNetwork); - - SubNetworkAdapter subNetworkAdapter = assertDoesNotThrow( - () -> new SubNetworkAdapter(communicationAdapter,tSubNetwork) - ); - - assertEquals("sName",subNetworkAdapter.getName()); - assertEquals("sType",subNetworkAdapter.getType()); - + void constructor_whenCalledWithNoRelationBetweenCommunicationAndSubNetwork_shouldThrowException() { + //Given + CommunicationAdapter communicationAdapter = mock(CommunicationAdapter.class); + when(communicationAdapter.getCurrentElem()).thenReturn(new TCommunication()); + TSubNetwork subNetwork = new TSubNetwork(); + //When Then + assertThatCode(() -> new SubNetworkAdapter(communicationAdapter,subNetwork)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } + @Test + void constructor_whenCalledWithExistingRelationBetweenCommunicationAndSubNetwork_shouldNotThrowException() { + //Given + CommunicationAdapter communicationAdapter = mock(CommunicationAdapter.class); + TCommunication communication = new TCommunication(); + TSubNetwork subNetwork = new TSubNetwork(); + communication.getSubNetwork().add(subNetwork); + when(communicationAdapter.getCurrentElem()).thenReturn(communication); + //When Then + assertThatCode(() -> new SubNetworkAdapter(communicationAdapter, subNetwork)) + .doesNotThrowAnyException(); + } @Test - void testAddConnectedAP() { + @Tag("issue-321") + void addConnectedAP_should_update_list_of_connectedAp() { + // Given SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); - assertTrue(subNetworkAdapter.getCurrentElem().getConnectedAP().isEmpty()); + assertThat(subNetworkAdapter.getCurrentElem().getConnectedAP()).isEmpty(); + // When subNetworkAdapter.addConnectedAP(DTO.HOLDER_IED_NAME,DTO.AP_NAME); - assertEquals(1,subNetworkAdapter.getCurrentElem().getConnectedAP().size()); + // Then + assertThat(subNetworkAdapter.getCurrentElem().getConnectedAP()).hasSize(1); TConnectedAP tConnectedAP = subNetworkAdapter.getCurrentElem().getConnectedAP().get(0); - assertEquals(DTO.HOLDER_IED_NAME, tConnectedAP.getIedName()); - assertEquals(DTO.AP_NAME, tConnectedAP.getApName()); - + assertThat(tConnectedAP.getIedName()).isEqualTo(DTO.HOLDER_IED_NAME); + assertThat(tConnectedAP.getApName()).isEqualTo(DTO.AP_NAME); + // When subNetworkAdapter.addConnectedAP(DTO.HOLDER_IED_NAME,DTO.AP_NAME); - assertEquals(1,subNetworkAdapter.getCurrentElem().getConnectedAP().size()); + // Then + assertThat(subNetworkAdapter.getCurrentElem().getConnectedAP()).hasSize(1); } @Test + @Tag("issue-321") void getConnectedAPAdapters_should_return_all_ConnectedAP() { // Given SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); + // When subNetworkAdapter.addConnectedAP(DTO.HOLDER_IED_NAME, DTO.AP_NAME); + // When subNetworkAdapter.addConnectedAP(DTO.HOLDER_IED_NAME_2, DTO.AP_NAME_2); // When List connectedAPAdapter = subNetworkAdapter.getConnectedAPAdapters(); @@ -73,9 +91,11 @@ void getConnectedAPAdapters_should_return_all_ConnectedAP() { } @Test + @Tag("issue-321") void getConnectedAPAdapter_should_get_element() { // Given SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); + // When subNetworkAdapter.addConnectedAP(DTO.HOLDER_IED_NAME,DTO.AP_NAME); // When ConnectedAPAdapter connectedAPAdapter = subNetworkAdapter.getConnectedAPAdapter(DTO.HOLDER_IED_NAME, DTO.AP_NAME); @@ -94,9 +114,11 @@ void getConnectedAPAdapter_when_not_found_should_throw_exception() { } @Test + @Tag("issue-321") void findConnectedAPAdapter_should_get_element() { // Given SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); + // When subNetworkAdapter.addConnectedAP(DTO.HOLDER_IED_NAME,DTO.AP_NAME); // When Optional connectedAPAdapter = subNetworkAdapter.findConnectedAPAdapter(DTO.HOLDER_IED_NAME, DTO.AP_NAME); @@ -106,7 +128,7 @@ void findConnectedAPAdapter_should_get_element() { } @Test - void findConnectedAPAdapter_when_not_found_shouldreturn_empty() { + void findConnectedAPAdapter_when_not_found_should_return_empty() { // Given SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); // When @@ -116,20 +138,23 @@ void findConnectedAPAdapter_when_not_found_shouldreturn_empty() { } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + //Given SubNetworkAdapter subNetworkAdapter = new SubNetworkAdapter(null, new TSubNetwork()); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(subNetworkAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(subNetworkAdapter.getCurrentElem().getPrivate()).isEmpty(); + //When subNetworkAdapter.addPrivate(tPrivate); - assertEquals(1, subNetworkAdapter.getCurrentElem().getPrivate().size()); + //Then + assertThat(subNetworkAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @ParameterizedTest @CsvSource(value = {"sName;sType;SubNetwork[@name=\"sName\"]", ";;SubNetwork[not(@name)]"} , delimiter = ';') - void elementXPath(String sName, String sType, String message) { + void elementXPath_should_return_expected_xpath_value(String sName, String sType, String message) { // Given TSubNetwork tSubNetwork = new TSubNetwork(); tSubNetwork.setName(sName); @@ -139,7 +164,6 @@ void elementXPath(String sName, String sType, String message) { String elementXPath = subNetworkAdapter.elementXPath(); // Then assertThat(elementXPath).isEqualTo(message); - } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/AbstractDTTLevel.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/AbstractDTTLevel.java deleted file mode 100644 index a358d3c84..000000000 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/AbstractDTTLevel.java +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl.dtt; - -import org.lfenergy.compas.scl2007b4.model.SCL; -import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates; -import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; -import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; -import org.mockito.Mockito; - - -public abstract class AbstractDTTLevel

{ - public static final String SCD_DTT = "/dtt-test-schema-conf/scd_dtt_import_test.xml"; - public static final String SCD_DTT_DIFF_CONTENT_SAME_ID = "/dtt-test-schema-conf/scd_dtt_import_sameid-diff-content-test.xml"; - - protected P sclElementAdapter; - protected T sclElement; - - public void init(){ - sclElementAdapter = (P) getMockedSclParentAdapter(); - completeInit(); - } - - protected static DataTypeTemplateAdapter initDttAdapterFromFile(String fileName) throws Exception { - SCL scd = SclTestMarshaller.getSCLFromFile(fileName); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - return new DataTypeTemplateAdapter( - sclRootAdapter, - scd.getDataTypeTemplates() - ); - } - - protected SclElementAdapter getMockedSclParentAdapter(){ - DataTypeTemplateAdapter dataTypeTemplateAdapter = Mockito.mock(DataTypeTemplateAdapter.class); - TDataTypeTemplates tDataTypeTemplates = Mockito.mock(TDataTypeTemplates.class); - Mockito.when(dataTypeTemplateAdapter.getCurrentElem()).thenReturn(tDataTypeTemplates); - - return dataTypeTemplateAdapter; - } - protected abstract void completeInit() ; - -} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java index 8533444d2..df7579c5d 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/BDAAdapterTest.java @@ -4,66 +4,108 @@ package org.lfenergy.compas.sct.commons.scl.dtt; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; -import org.mockito.Mockito; - import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -class BDAAdapterTest extends AbstractDTTLevel { +class BDAAdapterTest { @Test - void testAmChildElementRef() { - init(); - assertDoesNotThrow( - () -> new DATypeAdapter.BDAAdapter(sclElementAdapter,sclElement) - ); + void constructor_whenCalledWithNoRelationBetweenDATypeAndBDA_shouldThrowException() { + //Given + DATypeAdapter daTypeAdapter = mock(DATypeAdapter.class); + when(daTypeAdapter.getCurrentElem()).thenReturn(new TDAType()); + TBDA tbda = new TBDA(); + //When Then + assertThatCode(() -> new DATypeAdapter.BDAAdapter(daTypeAdapter, tbda)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } - @Override - protected SclElementAdapter getMockedSclParentAdapter(){ - DataTypeTemplateAdapter dataTypeTemplateAdapter = (DataTypeTemplateAdapter) super.getMockedSclParentAdapter(); - TDAType tdaType = new TDAType(); - tdaType.setId("ID"); - List tdaTypes = List.of(tdaType); - Mockito.when(dataTypeTemplateAdapter.getCurrentElem().getDAType()).thenReturn(tdaTypes); - DATypeAdapter daTypeAdapter = assertDoesNotThrow( - () -> new DATypeAdapter(dataTypeTemplateAdapter,tdaType) - ); - return daTypeAdapter; + @Test + void constructor_whenCalledWithExistingRelationBetweenDATypeAndBDA_shouldNotThrowException() { + //Given + DATypeAdapter daTypeAdapter = mock(DATypeAdapter.class); + TDAType daType = new TDAType(); + TBDA bda = new TBDA(); + daType.getBDA().add(bda); + when(daTypeAdapter.getCurrentElem()).thenReturn(daType); + //When Then + assertThatCode(() -> new DATypeAdapter.BDAAdapter(daTypeAdapter, bda)).doesNotThrowAnyException(); } @Test + @Tag("issue-321") void tesHasSameContentAs() { - init(); + // Given + DATypeAdapter daTypeAdapter = mock(DATypeAdapter.class); + TDAType daType = new TDAType(); TBDA tbda = createBDA(); - sclElementAdapter.getCurrentElem().getBDA().add(tbda); + daType.getBDA().add(tbda); + when(daTypeAdapter.getCurrentElem()).thenReturn(daType); + //When Then DATypeAdapter.BDAAdapter bdaAdapter = assertDoesNotThrow( - () -> new DATypeAdapter.BDAAdapter(sclElementAdapter,tbda) - ); - assertEquals("ENUM_BDA1", bdaAdapter.getType()); - assertEquals(TPredefinedBasicTypeEnum.ENUM, bdaAdapter.getBType()); - assertEquals("BDA1", bdaAdapter.getName()); - + () -> new DATypeAdapter.BDAAdapter(daTypeAdapter, tbda)); + assertThat(bdaAdapter.getType()).isEqualTo("ENUM_BDA1"); + assertThat(bdaAdapter.getBType()).isEqualTo(TPredefinedBasicTypeEnum.ENUM); + assertThat(bdaAdapter.getName()).isEqualTo("BDA1"); TBDA tbda1 = createBDA(); tbda1.getVal().get(0).setValue("VAL_CHANGED"); - assertFalse(bdaAdapter.hasSameContentAs(tbda1)); - + //When Then + assertThat(bdaAdapter.hasSameContentAs(tbda1)).isFalse(); tbda1.getCount().add("1"); - assertFalse(bdaAdapter.hasSameContentAs(tbda1)); - + //When Then + assertThat(bdaAdapter.hasSameContentAs(tbda1)).isFalse(); tbda1.setValImport(false); - assertFalse(bdaAdapter.hasSameContentAs(tbda1)); - + //When Then + assertThat(bdaAdapter.hasSameContentAs(tbda1)).isFalse(); tbda1.setValKind(TValKindEnum.SET); - assertFalse(bdaAdapter.hasSameContentAs(tbda1)); - + //When Then + assertThat(bdaAdapter.hasSameContentAs(tbda1)).isFalse(); tbda1.setSAddr("SADDR_BDA2"); - assertFalse(bdaAdapter.hasSameContentAs(tbda1)); + //When Then + assertThat(bdaAdapter.hasSameContentAs(tbda1)).isFalse(); + } + + @Test + void addPrivate_with_type_and_source_should_create_Private() { + //Given + DATypeAdapter daTypeAdapter = mock(DATypeAdapter.class); + TDAType daType = new TDAType(); + TBDA tbda = createBDA(); + daType.getBDA().add(tbda); + when(daTypeAdapter.getCurrentElem()).thenReturn(daType); + DATypeAdapter.BDAAdapter bdaAdapter = new DATypeAdapter.BDAAdapter(daTypeAdapter, tbda); + TPrivate tPrivate = new TPrivate(); + tPrivate.setType("Private Type"); + tPrivate.setSource("Private Source"); + assertThat(bdaAdapter.getCurrentElem().getPrivate()).isEmpty(); + //When + bdaAdapter.addPrivate(tPrivate); + //Then + assertThat(bdaAdapter.getCurrentElem().getPrivate()).isNotEmpty(); + } + + @Test + void elementXPath_should_return_expected_xpath_value() { + // Given + DATypeAdapter daTypeAdapter = mock(DATypeAdapter.class); + TDAType daType = new TDAType(); + TBDA tbda = new TBDA(); + daType.getBDA().add(tbda); + when(daTypeAdapter.getCurrentElem()).thenReturn(daType); + DATypeAdapter.BDAAdapter bdaAdapter = new DATypeAdapter.BDAAdapter(daTypeAdapter, tbda); + // When + String result = bdaAdapter.elementXPath(); + // Then + assertThat(result).isEqualTo("BDA[not(@name)]"); } private TBDA createBDA(){ @@ -78,41 +120,8 @@ private TBDA createBDA(){ tVal.setValue("VAL1"); TVal tVal1 = new TVal(); tVal1.setValue("VAL1"); - tbda.getVal().addAll(List.of(tVal,tVal1)); - return tbda; } - @Override - protected void completeInit() { - TBDA tbda = new TBDA(); - tbda.setType("ID_BDA"); - sclElement = tbda; - sclElementAdapter.getCurrentElem().getBDA().add(tbda); - } - - @Test - void addPrivate() { - init(); - DATypeAdapter.BDAAdapter bdaAdapter = new DATypeAdapter.BDAAdapter(sclElementAdapter,sclElement); - TPrivate tPrivate = new TPrivate(); - tPrivate.setType("Private Type"); - tPrivate.setSource("Private Source"); - assertTrue(bdaAdapter.getCurrentElem().getPrivate().isEmpty()); - bdaAdapter.addPrivate(tPrivate); - assertEquals(1, bdaAdapter.getCurrentElem().getPrivate().size()); - } - - @Test - void elementXPath() { - // Given - init(); - DATypeAdapter.BDAAdapter bdaAdapter = new DATypeAdapter.BDAAdapter(sclElementAdapter,sclElement); - // When - String result = bdaAdapter.elementXPath(); - // Then - assertThat(result).isEqualTo("BDA[not(@name)]"); - } - } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DAAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DAAdapterTest.java index 8a87a8f0f..3efba917b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DAAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DAAdapterTest.java @@ -4,90 +4,96 @@ package org.lfenergy.compas.sct.commons.scl.dtt; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl2007b4.model.TDA; -import org.lfenergy.compas.scl2007b4.model.TDOType; -import org.lfenergy.compas.scl2007b4.model.TPredefinedBasicTypeEnum; -import org.lfenergy.compas.scl2007b4.model.TPrivate; +import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.DaTypeName; import org.lfenergy.compas.sct.commons.exception.ScdException; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.SCD_DTT; +import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.initDttAdapterFromFile; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class DAAdapterTest { @Test - void TestConstructor() { - TDOType tdoType = new TDOType(); - tdoType.setId("ID"); - DOTypeAdapter doTypeAdapter = new DOTypeAdapter(null,tdoType); - - TDA tda = new TDA(); - tda.setType("Type"); - tda.setBType(TPredefinedBasicTypeEnum.ENUM); - tda.setName("DA"); - tdoType.getSDOOrDA().add(tda); - - DAAdapter daAdapter = assertDoesNotThrow(() -> doTypeAdapter.getDAAdapterByName("DA").get()); - assertEquals("Type", daAdapter.getType()); - assertEquals(TPredefinedBasicTypeEnum.ENUM, daAdapter.getBType()); - assertEquals("DA", daAdapter.getName()); - } - - @Test - void testHasSameContentAs() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - assertTrue(dttAdapter.getDATypeAdapters().size() > 1); - + @Tag("issue-321") + void testHasSameContentAs() { + //Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); + assertThat(dttAdapter.getDATypeAdapters()).hasSizeGreaterThan(1); DOTypeAdapter doTypeAdapter1 = dttAdapter.getDOTypeAdapters().get(0); DOTypeAdapter doTypeAdapter2 = dttAdapter.getDOTypeAdapters().get(1); + //When Then DAAdapter daAdapter1 = assertDoesNotThrow(() -> doTypeAdapter1.getDAAdapterByName("dataNs").get()); + //When Then DAAdapter daAdapter2 = assertDoesNotThrow(() -> doTypeAdapter2.getDAAdapterByName("angRef").get()); - - assertTrue(daAdapter1.hasSameContentAs(daAdapter1.getCurrentElem())); - assertFalse(daAdapter1.hasSameContentAs(daAdapter2.getCurrentElem())); + //When Then + assertThat(daAdapter1.hasSameContentAs(daAdapter1.getCurrentElem())).isTrue(); + //When Then + assertThat(daAdapter1.hasSameContentAs(daAdapter2.getCurrentElem())).isFalse(); } @Test - void testCheck() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - + @Tag("issue-321") + void testCheck() { + //Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDOTypeAdapterById("DO2").get()); DAAdapter daAdapter = assertDoesNotThrow(() ->doTypeAdapter.getDAAdapterByName("angRef").get()); - assertEquals(TPredefinedBasicTypeEnum.ENUM, daAdapter.getBType()); - assertTrue(daAdapter.isTail()); - assertTrue(daAdapter.getDATypeAdapter().isEmpty()); + assertThat(daAdapter.getBType()).isEqualTo(TPredefinedBasicTypeEnum.ENUM); + assertThat(daAdapter.isTail()).isTrue(); + assertThat(daAdapter.getDATypeAdapter()).isEmpty(); DaTypeName daTypeName = new DaTypeName("angRef"); - assertDoesNotThrow(() -> daAdapter.check(daTypeName)); + //When Then + assertThatCode(() -> daAdapter.check(daTypeName)).doesNotThrowAnyException(); + //Given daTypeName.getDaiValues().put(0L,"Va"); - assertDoesNotThrow(() -> daAdapter.check(daTypeName)); + //When Then + assertThatCode(() -> daAdapter.check(daTypeName)).doesNotThrowAnyException(); + //Given daTypeName.getDaiValues().put(0L,"unknown"); - assertThrows(ScdException.class, () -> daAdapter.check(daTypeName)); + //When Then + assertThatThrownBy(() -> daAdapter.check(daTypeName)) + .isInstanceOf(ScdException.class); } @Test - void addPrivate() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DOTypeAdapter doTypeAdapter = dttAdapter.getDOTypeAdapters().get(0); - DAAdapter daAdapter = assertDoesNotThrow(() -> doTypeAdapter.getDAAdapterByName("dataNs").get()); + void addPrivate_with_type_and_source_should_create_Private() { + //Given + DOTypeAdapter daTypeAdapter = mock(DOTypeAdapter.class); + TDOType tdoType = new TDOType(); + TDA tda = new TDA(); + tdoType.getSDOOrDA().add(tda); + when(daTypeAdapter.getCurrentElem()).thenReturn(tdoType); + DAAdapter daAdapter = new DAAdapter(daTypeAdapter, tda); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(daAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(tda.getPrivate()).isEmpty(); + //When daAdapter.addPrivate(tPrivate); - assertEquals(1, daAdapter.getCurrentElem().getPrivate().size()); + //Then + assertThat(tda.getPrivate()).isNotEmpty(); } @Test - void elementXPath() throws Exception { + void elementXPath_should_return_expected_xpath_value() { // Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DOTypeAdapter doTypeAdapter = dttAdapter.getDOTypeAdapters().get(0); - DAAdapter daAdapter = assertDoesNotThrow(() -> doTypeAdapter.getDAAdapterByName("dataNs").get()); + DOTypeAdapter daTypeAdapter = mock(DOTypeAdapter.class); + TDOType tdoType = new TDOType(); + TDA tda = new TDA(); + tda.setName("dataNs"); + tdoType.getSDOOrDA().add(tda); + when(daTypeAdapter.getCurrentElem()).thenReturn(tdoType); + DAAdapter daAdapter = new DAAdapter(daTypeAdapter, tda); // When String result = daAdapter.elementXPath(); // Then assertThat(result).isEqualTo("DA[name=@name=\"dataNs\" and type=not(@type)]"); } + } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapterTest.java index 51c49746d..6ca4bdedd 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DATypeAdapterTest.java @@ -4,160 +4,196 @@ package org.lfenergy.compas.sct.commons.scl.dtt; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl2007b4.model.TBDA; -import org.lfenergy.compas.scl2007b4.model.TDAType; -import org.lfenergy.compas.scl2007b4.model.TPredefinedBasicTypeEnum; -import org.lfenergy.compas.scl2007b4.model.TPrivate; +import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.DaTypeName; import org.lfenergy.compas.sct.commons.dto.DataAttributeRef; import org.lfenergy.compas.sct.commons.dto.DoTypeName; import org.lfenergy.compas.sct.commons.exception.ScdException; -import org.mockito.Mockito; -import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.SCD_DTT; +import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.initDttAdapterFromFile; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -class DATypeAdapterTest extends AbstractDTTLevel { +class DATypeAdapterTest { - @Override - protected void completeInit() { + @Test + void constructor_whenCalledWithNoRelationBetween_between_DataTypeTemplates_and_DAType() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(new TDataTypeTemplates()); TDAType tdaType = new TDAType(); - tdaType.setId("ID"); - List tdaTypes = new ArrayList<>(); - tdaTypes.add(tdaType); - sclElement = tdaType; - Mockito.when(sclElementAdapter.getCurrentElem().getDAType()).thenReturn(tdaTypes); + //When Then + assertThatCode(() -> new DATypeAdapter(dataTemplateAdapter, tdaType)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void testAmChildElementRef() { - init(); - assertDoesNotThrow( - () -> new DATypeAdapter(sclElementAdapter, sclElement) - ); + void constructor_whenCalledWithExistingRelationBetween_DataTypeTemplates_and_DAType_exist() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDAType tdaType = new TDAType(); + dataTemplate.getDAType().add(tdaType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + //When Then + assertThatCode(() -> new DATypeAdapter(dataTemplateAdapter, tdaType)).doesNotThrowAnyException(); } @Test - void testGetBdaAdapters() { - init(); + void getBdaAdapters_should_return_list_of_BDAAdapter() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDAType tdaType = new TDAType(); TBDA tbda = new TBDA(); tbda.setType("ID_BDA"); - sclElement.getBDA().add(tbda); - - DATypeAdapter daTypeAdapter = assertDoesNotThrow( - () -> new DATypeAdapter(sclElementAdapter, sclElement) - ); - assertFalse(daTypeAdapter.getBdaAdapters().isEmpty()); - assertEquals(daTypeAdapter.getBdaAdapters().get(0).getClass(), DATypeAdapter.BDAAdapter.class); + tdaType.getBDA().add(tbda); + dataTemplate.getDAType().add(tdaType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + DATypeAdapter daTypeAdapter = new DATypeAdapter(dataTemplateAdapter, tdaType); + // When Then + assertThat(daTypeAdapter.getBdaAdapters()).isNotEmpty(); + assertThat(daTypeAdapter.getBdaAdapters().get(0).getClass()).isEqualTo(DATypeAdapter.BDAAdapter.class); } @Test - void testContainsBDAWithEnumTypeID() { - init(); + void containsBDAWithEnumTypeID_should_check_if_DAType_contains_BDA_with_specific_EnumType() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDAType tdaType = new TDAType(); TBDA tbda = new TBDA(); tbda.setType("ID_BDA"); tbda.setBType(TPredefinedBasicTypeEnum.ENUM); tbda.setType("enumTypeId"); - sclElement.getBDA().add(tbda); - - DATypeAdapter daTypeAdapter = assertDoesNotThrow( - () -> new DATypeAdapter(sclElementAdapter, sclElement) - ); - assertTrue(daTypeAdapter.containsBDAWithEnumTypeID("enumTypeId")); - assertFalse(daTypeAdapter.containsBDAWithEnumTypeID("no_enumTypeId")); + tdaType.getBDA().add(tbda); + dataTemplate.getDAType().add(tdaType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + + DATypeAdapter daTypeAdapter = new DATypeAdapter(dataTemplateAdapter, tdaType); + // When Then + assertThat(daTypeAdapter.containsBDAWithEnumTypeID("enumTypeId")).isTrue(); + assertThat(daTypeAdapter.containsBDAWithEnumTypeID("no_enumTypeId")).isFalse(); } @Test - void testContainsStructBdaWithDATypeId() { - init(); + void containsStructBdaWithDATypeId_should_check_if_DAType_contains_StructType() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDAType tdaType = new TDAType(); TBDA tbda = new TBDA(); tbda.setType("ID_BDA"); tbda.setBType(TPredefinedBasicTypeEnum.STRUCT); tbda.setType("daTypeId"); - sclElement.getBDA().add(tbda); - - DATypeAdapter daTypeAdapter = assertDoesNotThrow( - () -> new DATypeAdapter(sclElementAdapter, sclElement) - ); - assertTrue(daTypeAdapter.containsStructBdaWithDATypeId("daTypeId")); - assertFalse(daTypeAdapter.containsStructBdaWithDATypeId("no_daTypeId")); + tdaType.getBDA().add(tbda); + dataTemplate.getDAType().add(tdaType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + DATypeAdapter daTypeAdapter = new DATypeAdapter(dataTemplateAdapter, tdaType); + // When Then + assertThat(daTypeAdapter.containsStructBdaWithDATypeId("daTypeId")).isTrue(); + assertThat(daTypeAdapter.containsStructBdaWithDATypeId("no_daTypeId")).isFalse(); } @Test - void hasSameContentAs() throws Exception { - - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - assertTrue(rcvDttAdapter.getDATypeAdapters().size() > 1); - + @Tag("issue-321") + void hasSameContentAs() { + // Given + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT); + assertThat(rcvDttAdapter.getDATypeAdapters()).hasSizeGreaterThan(1); DATypeAdapter rcvDATypeAdapter = rcvDttAdapter.getDATypeAdapters().get(0); - assertTrue(rcvDATypeAdapter.hasSameContentAs(rcvDATypeAdapter.getCurrentElem())); - assertFalse(rcvDATypeAdapter.hasSameContentAs(rcvDttAdapter.getDATypeAdapters().get(1).getCurrentElem())); + // When Then + assertThat(rcvDATypeAdapter.hasSameContentAs(rcvDATypeAdapter.getCurrentElem())).isTrue(); + // When Then + assertThat(rcvDATypeAdapter.hasSameContentAs(rcvDttAdapter.getDATypeAdapters().get(1).getCurrentElem())).isFalse(); } @Test - void testCheckStructuredData() throws Exception { - - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DATypeAdapter daTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDATypeAdapterById("DA1").get()); + @Tag("issue-321") + void testCheckStructuredData() { + // Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); + DATypeAdapter daTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDATypeAdapterById("DA1").get()); DaTypeName daTypeName = new DaTypeName("origin","origin.ctlVal"); - + // When daTypeAdapter.check(daTypeName); - assertEquals(TPredefinedBasicTypeEnum.ENUM,daTypeName.getBType()); - assertEquals("RecCycModKind",daTypeName.getType()); + // Then + assertThat(daTypeName.getBType()).isEqualTo(TPredefinedBasicTypeEnum.ENUM); + assertThat(daTypeName.getType()).isEqualTo("RecCycModKind"); DaTypeName daTypeName1 = new DaTypeName("origin","origin"); - assertThrows(ScdException.class, () -> daTypeAdapter.check(daTypeName1)); - + // When Then + assertThatCode(() -> daTypeAdapter.check(daTypeName1)) + .isInstanceOf(ScdException.class); + // Given DaTypeName daTypeName2 = new DaTypeName("d","check.ctlVal"); - assertThrows(ScdException.class, () -> daTypeAdapter.check(daTypeName2)); + // When Then + assertThatCode(() -> daTypeAdapter.check(daTypeName2)) + .isInstanceOf(ScdException.class); } @Test - void testGetDataAttributeRefs() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + void getDataAttributeRefs_should_return_list_of_dataAttribute() { + // Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); DATypeAdapter daTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDATypeAdapterById("DA1").get()); DataAttributeRef rootDataAttributeRef = new DataAttributeRef(); rootDataAttributeRef.getDaName().setName("origin"); rootDataAttributeRef.getDoName().setName("StrVal"); + // When List dataAttributeRefs = daTypeAdapter.getDataAttributeRefs(rootDataAttributeRef, new DataAttributeRef()); - assertEquals(2,dataAttributeRefs.size()); - + // When + assertThat(dataAttributeRefs).hasSize(2); } @Test - void getDataAttributeRefByDaName() throws Exception { - - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile( - AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID - ); + void getDataAttributeRefByDaName_should_not_throw_exception() { + // Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); DaTypeName daTypeName = new DaTypeName("antRef","origin.ctlVal"); DoTypeName doTypeName = new DoTypeName("Op.origin"); DataAttributeRef dataAttributeRef = new DataAttributeRef(); dataAttributeRef.setDoName(doTypeName); dataAttributeRef.getDaName().setName("antRef"); - assertTrue(dataAttributeRef.getBdaNames().isEmpty()); + assertThat(dataAttributeRef.getBdaNames()).isEmpty(); DATypeAdapter daTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDATypeAdapterById("DA1").get()); - assertDoesNotThrow(() -> daTypeAdapter.getDataAttributeRefByDaName(daTypeName,0,dataAttributeRef).get()); + // When Then + assertThatCode(() -> daTypeAdapter.getDataAttributeRefByDaName(daTypeName,0,dataAttributeRef).get()) + .doesNotThrowAnyException(); } @Test - void addPrivate() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DATypeAdapter daTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDATypeAdapterById("DA1").get()); + void addPrivate_with_type_and_source_should_create_Private() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDAType tdaType = new TDAType(); + dataTemplate.getDAType().add(tdaType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + + DATypeAdapter daTypeAdapter = new DATypeAdapter(dataTemplateAdapter, tdaType); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertFalse(daTypeAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(daTypeAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When daTypeAdapter.addPrivate(tPrivate); - assertEquals(2, daTypeAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(daTypeAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } + @Test - void elementXPath() throws Exception { + void elementXPath_should_return_expected_xpath_value() { // Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); DATypeAdapter daTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDATypeAdapterById("DA1").get()); // When String result = daTypeAdapter.elementXPath(); @@ -165,4 +201,5 @@ void elementXPath() throws Exception { assertThat(result).isEqualTo("DAType[@id=\"DA1\"]"); } + } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java index 95fa8014a..df34d865e 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOAdapterTest.java @@ -7,25 +7,25 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.TDO; import org.lfenergy.compas.scl2007b4.model.TLNodeType; -import org.mockito.Mockito; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class DOAdapterTest { @Test - void elementXPath() { + void elementXPath_should_return_expected_xpath_value() { // Given - LNodeTypeAdapter lNodeAdapter = Mockito.mock(LNodeTypeAdapter.class); - TLNodeType tlNodeType = Mockito.mock(TLNodeType.class); - Mockito.when(lNodeAdapter.getParentAdapter()).thenReturn(null); - Mockito.when(lNodeAdapter.getCurrentElem()).thenReturn(tlNodeType); - + LNodeTypeAdapter lNodeAdapter = mock(LNodeTypeAdapter.class); + TLNodeType tlNodeType = mock(TLNodeType.class); + when(lNodeAdapter.getParentAdapter()).thenReturn(null); + when(lNodeAdapter.getCurrentElem()).thenReturn(tlNodeType); TDO tdo = new TDO(); tdo.setName("doName"); - Mockito.when(tlNodeType.getDO()).thenReturn(List.of(tdo)); + when(tlNodeType.getDO()).thenReturn(List.of(tdo)); DOAdapter doAdapter = new DOAdapter(lNodeAdapter, tdo); // When String result = doAdapter.elementXPath(); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java index 9f885d402..c0df82559 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.dtt; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -12,94 +13,121 @@ import org.lfenergy.compas.sct.commons.dto.DataAttributeRef; import org.lfenergy.compas.sct.commons.dto.DoTypeName; import org.lfenergy.compas.sct.commons.exception.ScdException; -import org.mockito.Mockito; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -class DOTypeAdapterTest extends AbstractDTTLevel { +class DOTypeAdapterTest { - @Override - protected void completeInit() { + @Test + void constructor_whenCalledWithNoRelationBetweenDataTypeTemplatesAndDOType_shouldThrowException() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(new TDataTypeTemplates()); TDOType tdoType = new TDOType(); - tdoType.setId("ID"); - List tdoTypes = List.of(tdoType); - sclElement = tdoType; - Mockito.when(sclElementAdapter.getCurrentElem().getDOType()).thenReturn(tdoTypes); + //When Then + assertThatCode(() -> new DOTypeAdapter(dataTemplateAdapter, tdoType)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void testAmChildElementRef() { - init(); - assertDoesNotThrow( - () -> new DOTypeAdapter(sclElementAdapter, sclElement) - ); + void constructor_whenCalledWithExistingRelationBetweenDataTypeTemplatesAndDOType_shouldNotThrowException() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDOType tdoType = new TDOType(); + dataTemplate.getDOType().add(tdoType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + //When Then + assertThatCode(() -> new DOTypeAdapter(dataTemplateAdapter, tdoType)).doesNotThrowAnyException(); } @Test - void testContainsDAWithEnumTypeId() { - init(); + void containsDAWithEnumTypeId_should_check_if_DOType_contains_DA_with_specific_EnumType() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDOType tdoType = new TDOType(); TDA tda = new TDA(); tda.setType("ID_BDA"); tda.setBType(TPredefinedBasicTypeEnum.ENUM); tda.setType("enumTypeId"); - sclElement.getSDOOrDA().add(tda); + tdoType.getSDOOrDA().add(tda); + dataTemplate.getDOType().add(tdoType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); - DOTypeAdapter doTypeAdapter = assertDoesNotThrow( - () -> new DOTypeAdapter(sclElementAdapter, sclElement) - ); - assertTrue(doTypeAdapter.containsDAWithEnumTypeId("enumTypeId")); - assertFalse(doTypeAdapter.containsDAWithEnumTypeId("no_enumTypeId")); + DOTypeAdapter doTypeAdapter = new DOTypeAdapter(dataTemplateAdapter, tdoType); + //When Then + assertThat(doTypeAdapter.containsDAWithEnumTypeId("enumTypeId")).isTrue(); + //When Then + assertThat(doTypeAdapter.containsDAWithEnumTypeId("no_enumTypeId")).isFalse(); } @Test - void testContainsDAStructWithDATypeId() { - init(); + @Tag("issue-321") + void containsDAStructWithDATypeId_should_check_if_DOType_contains_StructType() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDOType tdoType = new TDOType(); TDA tda = new TDA(); tda.setType("ID_BDA"); tda.setBType(TPredefinedBasicTypeEnum.STRUCT); tda.setType("daTypeId"); - sclElement.getSDOOrDA().add(tda); + tdoType.getSDOOrDA().add(tda); + dataTemplate.getDOType().add(tdoType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); - DOTypeAdapter doTypeAdapter = assertDoesNotThrow( - () -> new DOTypeAdapter(sclElementAdapter, sclElement) - ); - assertTrue(doTypeAdapter.containsDAStructWithDATypeId("daTypeId")); - assertFalse(doTypeAdapter.containsDAStructWithDATypeId("no_daTypeId")); + DOTypeAdapter doTypeAdapter = new DOTypeAdapter(dataTemplateAdapter, tdoType); + //When Then + assertThat(doTypeAdapter.containsDAStructWithDATypeId("daTypeId")).isTrue(); + //When Then + assertThat(doTypeAdapter.containsDAStructWithDATypeId("no_daTypeId")).isFalse(); } @Test - void hasSameContentAs() throws Exception { - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); - assertTrue(rcvDttAdapter.getDATypeAdapters().size() > 1); - - DOTypeAdapter rcvDOTypeAdapter = rcvDttAdapter.getDOTypeAdapters().get(0); - assertTrue(rcvDOTypeAdapter.hasSameContentAs(rcvDOTypeAdapter.getCurrentElem())); - assertFalse(rcvDOTypeAdapter.hasSameContentAs(rcvDttAdapter.getDOTypeAdapters().get(1).getCurrentElem())); + @Tag("issue-321") + void hasSameContentAs() { + //Given + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); + assertThat(rcvDttAdapter.getDATypeAdapters()).hasSizeGreaterThan(1); + DOTypeAdapter rcvDOTypeAdapter = rcvDttAdapter.getDOTypeAdapters().get(0); + //When Then + assertThat(rcvDOTypeAdapter.hasSameContentAs(rcvDOTypeAdapter.getCurrentElem())).isTrue(); + //When Then + assertThat(rcvDOTypeAdapter.hasSameContentAs(rcvDttAdapter.getDOTypeAdapters().get(1).getCurrentElem())).isFalse(); } @Test - void testCheckAndCompleteStructData() throws Exception { + @Tag("issue-321") + void testCheckAndCompleteStructData() { //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); - DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDOTypeAdapterById("DO2").get()); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); + //When Then + DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO2").get()); DoTypeName doTypeName = new DoTypeName("Op","origin"); - - assertDoesNotThrow(() ->doTypeAdapter.checkAndCompleteStructData(doTypeName)); - assertEquals(TPredefinedCDCEnum.WYE,doTypeName.getCdc()); + //When Then + assertThatCode(() -> doTypeAdapter.checkAndCompleteStructData(doTypeName)).doesNotThrowAnyException(); + assertThat(doTypeName.getCdc()).isEqualTo(TPredefinedCDCEnum.WYE); DoTypeName doTypeName1 = new DoTypeName("Op","toto"); //When Then - assertThatThrownBy(() ->doTypeAdapter.checkAndCompleteStructData(doTypeName1)).isInstanceOf(ScdException.class); + assertThatThrownBy(() -> doTypeAdapter.checkAndCompleteStructData(doTypeName1)).isInstanceOf(ScdException.class); } @Test - void testGetDataAttributeRefs_filter_on_DO() throws Exception { + @Tag("issue-321") + void testGetDataAttributeRefs_filter_on_DO() { // given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDOTypeAdapterById("DO2").get()); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); + // when then + DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO2").get()); + // then DataAttributeRef rootDataAttributeRef = new DataAttributeRef(); rootDataAttributeRef.setDoName(new DoTypeName("Op")); DataAttributeRef filter = new DataAttributeRef(); @@ -109,14 +137,16 @@ void testGetDataAttributeRefs_filter_on_DO() throws Exception { List dataAttributeRefs = doTypeAdapter.getDataAttributeRefs(rootDataAttributeRef, filter); // then - assertEquals(2,dataAttributeRefs.size()); + assertThat(dataAttributeRefs).hasSize(2); } @Test - void testGetDataAttributeRefs_filter_on_DO_and_DA() throws Exception { + void testGetDataAttributeRefs_filter_on_DO_and_DA() { + // given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); + // when then + DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO2").get()); // given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getDOTypeAdapterById("DO2").get()); DataAttributeRef rootDataAttributeRef = new DataAttributeRef(); rootDataAttributeRef.setDoName(new DoTypeName("Op")); DataAttributeRef filter = new DataAttributeRef(); @@ -126,61 +156,73 @@ void testGetDataAttributeRefs_filter_on_DO_and_DA() throws Exception { List dataAttributeRefs = doTypeAdapter.getDataAttributeRefs(rootDataAttributeRef, filter); // then - assertEquals(1,dataAttributeRefs.size()); + assertThat(dataAttributeRefs).hasSize(1); } - @Test - void testFindPathSDO2DA() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile( - AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID - ); + @Tag("issue-321") + void testFindPathSDO2DA() { + // Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO1").get()); - assertThrows(ScdException.class, () -> doTypeAdapter.findPathSDOToDA("origin","unknown")); - assertThrows(ScdException.class, () -> doTypeAdapter.findPathSDOToDA("unknown","antRef")); + // When Then + assertThatCode(() -> doTypeAdapter.findPathSDOToDA("origin","unknown")) + .isInstanceOf(ScdException.class); + // When Then + assertThatCode(() -> doTypeAdapter.findPathSDOToDA("unknown","antRef")) + .isInstanceOf(ScdException.class); + // When Then var pair = assertDoesNotThrow( () -> doTypeAdapter.findPathSDOToDA("origin","antRef") ); - assertEquals("d",pair.getKey()); + assertThat(pair.getKey()).isEqualTo("d"); DOTypeAdapter lastDoTypeAdapter = pair.getValue(); - assertEquals("DO3",lastDoTypeAdapter.getCurrentElem().getId()); + assertThat(lastDoTypeAdapter.getCurrentElem().getId()).isEqualTo("DO3"); } @Test - void getDataAttributeRefByDaName() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile( - AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID - ); + void getDataAttributeRefByDaName_should_not_throw_exception() { + //Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); DaTypeName daTypeName = new DaTypeName("antRef","origin.ctlVal"); DataAttributeRef dataAttributeRef = new DataAttributeRef(); dataAttributeRef.setDoName(new DoTypeName("Op")); DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO2").get()); - assertDoesNotThrow(() -> doTypeAdapter.getDataAttributeRefByDaName(daTypeName,dataAttributeRef)); - assertEquals("Op.origin",dataAttributeRef.getDoName().toString()); - assertEquals("antRef.origin.ctlVal",dataAttributeRef.getDaName().toString()); + // When Then + assertThatCode(() -> doTypeAdapter.getDataAttributeRefByDaName(daTypeName, dataAttributeRef)).doesNotThrowAnyException(); + assertThat(dataAttributeRef.getDoName()).hasToString("Op.origin"); + assertThat(dataAttributeRef.getDaName()).hasToString("antRef.origin.ctlVal"); } @Test - void addPrivate() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile( - AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID - ); - DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO1").get()); + void addPrivate_with_type_and_source_should_create_Private() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDOType tdoType = new TDOType(); + dataTemplate.getDOType().add(tdoType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + DOTypeAdapter doTypeAdapter = new DOTypeAdapter(dataTemplateAdapter, tdoType); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(doTypeAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(doTypeAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When doTypeAdapter.addPrivate(tPrivate); - assertEquals(1, doTypeAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(doTypeAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test - void elementXPath() throws Exception { + void elementXPath_should_return_expected_xpath_value() { // Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile( - AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID - ); - DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO1").get()); + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TDOType tdoType = new TDOType(); + tdoType.setId("DO1"); + dataTemplate.getDOType().add(tdoType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + DOTypeAdapter doTypeAdapter = new DOTypeAdapter(dataTemplateAdapter, tdoType); // When String result = doTypeAdapter.elementXPath(); // Then @@ -189,10 +231,9 @@ void elementXPath() throws Exception { @ParameterizedTest @CsvSource({"angRef,CF,PhaseAngleReferenceKind", "antRef,ST,DA1"}) - void getDAByName(String daName, String fc, String type) throws Exception { + void getDAByName_should_not_throw_exception(String daName, String fc, String type) { // Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile( - AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO2").get()); // When TDA result = assertDoesNotThrow(() -> doTypeAdapter.getDAByName(daName).get()); @@ -201,4 +242,5 @@ void getDAByName(String daName, String fc, String type) throws Exception { .extracting(TDA::getName, TDA::getFc, TDA::getType) .containsExactlyInAnyOrder(daName,TFCEnum.fromValue(fc),type); } + } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateAdapterTest.java index 355bd3cd0..9145d6348 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateAdapterTest.java @@ -4,8 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.dtt; - -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.CsvSource; @@ -14,208 +13,311 @@ import org.lfenergy.compas.sct.commons.dto.ExtRefSignalInfo; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import java.util.Arrays; import java.util.List; import java.util.Optional; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class DataTypeTemplateAdapterTest { - - - DataTypeTemplateAdapter dataTypeTemplateAdapter; - - protected void init(){ - SclRootAdapter sclRootAdapter = null; - try { - sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); - } catch (ScdException e) { - e.printStackTrace(); - } - assert sclRootAdapter != null; - sclRootAdapter.getCurrentElem().setDataTypeTemplates(new TDataTypeTemplates()); - SclRootAdapter finalSclRootAdapter = sclRootAdapter; - dataTypeTemplateAdapter = assertDoesNotThrow( - finalSclRootAdapter::getDataTypeTemplateAdapter - ); + @Test + void constructor_whenCalledWithNoRelationBetweenSCLAndDataTypeTemplates_shouldThrowException() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + // When Then + assertThatCode(() -> new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } - @BeforeEach - public void setUp(){ - init(); - } @Test - void testAmChildElementRef() { - SclRootAdapter sclRootAdapter = dataTypeTemplateAdapter.getParentAdapter(); - TDataTypeTemplates dtt = new TDataTypeTemplates(); - assertThatThrownBy(() -> new DataTypeTemplateAdapter(sclRootAdapter, dtt)) - .isInstanceOf(IllegalArgumentException.class); + void constructor_whenCalledWithExistingRelationBetweenSCLAndDataTypeTemplates_shouldNotThrowException() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + // When Then + assertThatCode(() -> new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate)).doesNotThrowAnyException(); } + @Test + @Tag("issue-321") void testGetLNodeTypeAdapterById() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TLNodeType tlNodeType = new TLNodeType(); tlNodeType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getLNodeType().add(tlNodeType); - Optional lNodeTypeAdapter = - dataTypeTemplateAdapter.getLNodeTypeAdapterById("ID"); - assertTrue(lNodeTypeAdapter.isPresent()); + dataTemplate.getLNodeType().add(tlNodeType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); - lNodeTypeAdapter = dataTypeTemplateAdapter.getLNodeTypeAdapterById("UNKNOWN_ID"); - assertTrue(lNodeTypeAdapter.isEmpty()); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); + // When + Optional lNodeTypeAdapter1 = dataTypeTemplateAdapter.getLNodeTypeAdapterById("ID"); + // Then + assertThat(lNodeTypeAdapter1).isPresent(); + // When + Optional lNodeTypeAdapter2 = dataTypeTemplateAdapter.getLNodeTypeAdapterById("UNKNOWN_ID"); + // Then + assertThat(lNodeTypeAdapter2).isEmpty(); } @Test - void testGetLNodeTypeAdapters() { + void getLNodeTypeAdapters_should_return_list_of_LNodeTypeAdapter() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TLNodeType tlNodeType = new TLNodeType(); tlNodeType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getLNodeType().add(tlNodeType); - assertFalse(dataTypeTemplateAdapter.getLNodeTypeAdapters().isEmpty()); + dataTemplate.getLNodeType().add(tlNodeType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); + // When Then + assertThat(dataTypeTemplateAdapter.getLNodeTypeAdapters()).isNotEmpty(); } @Test + @Tag("issue-321") void testGetDOTypeAdapterById() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TDOType tdoType = new TDOType(); tdoType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getDOType().add(tdoType); - Optional doTypeAdapter = - dataTypeTemplateAdapter.getDOTypeAdapterById("ID"); - assertTrue(doTypeAdapter.isPresent()); + dataTemplate.getDOType().add(tdoType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); - doTypeAdapter = dataTypeTemplateAdapter.getDOTypeAdapterById("UNKNOWN_ID"); - assertTrue(doTypeAdapter.isEmpty()); + // When + Optional doTypeAdapter1 = dataTypeTemplateAdapter.getDOTypeAdapterById("ID"); + // Then + assertThat(doTypeAdapter1).isPresent(); + // When + Optional doTypeAdapter2 = dataTypeTemplateAdapter.getDOTypeAdapterById("UNKNOWN_ID"); + // Then + assertThat(doTypeAdapter2).isEmpty(); } @Test - void testGetDOTypeAdapters() { + void getDOTypeAdapters_should_return_list_of_DOTypeAdapter() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TDOType tdoType = new TDOType(); tdoType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getDOType().add(tdoType); - assertFalse(dataTypeTemplateAdapter.getDOTypeAdapters().isEmpty()); + dataTemplate.getDOType().add(tdoType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); + // When Then + assertThat(dataTypeTemplateAdapter.getDOTypeAdapters()).isNotEmpty(); } @Test + @Tag("issue-321") void testGetDATypeAdapterById() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TDAType tdaType = new TDAType(); tdaType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getDAType().add(tdaType); - Optional daTypeAdapter = - dataTypeTemplateAdapter.getDATypeAdapterById("ID"); - assertTrue(daTypeAdapter.isPresent()); + dataTemplate.getDAType().add(tdaType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); - daTypeAdapter = dataTypeTemplateAdapter.getDATypeAdapterById("UNKNOWN_ID"); - assertTrue(daTypeAdapter.isEmpty()); + // When + Optional daTypeAdapter1 = dataTypeTemplateAdapter.getDATypeAdapterById("ID"); + // Then + assertThat(daTypeAdapter1).isPresent(); + // When + Optional daTypeAdapter2 = dataTypeTemplateAdapter.getDATypeAdapterById("UNKNOWN_ID"); + // Then + assertThat(daTypeAdapter2).isEmpty(); } @Test - void testGetDATypeAdapters() { + void getDATypeAdapters_should_return_list_of_DATypeAdapter() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TDAType tdaType = new TDAType(); tdaType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getDAType().add(tdaType); - assertFalse(dataTypeTemplateAdapter.getDATypeAdapters().isEmpty()); + dataTemplate.getDAType().add(tdaType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); + // When Then + assertThat(dataTypeTemplateAdapter.getDATypeAdapters()).isNotEmpty(); } @Test + @Tag("issue-321") void testGetEnumTypeAdapterById() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TEnumType tEnumType = new TEnumType(); tEnumType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getEnumType().add(tEnumType); - Optional enumTypeAdapter = - dataTypeTemplateAdapter.getEnumTypeAdapterById("ID"); - assertTrue(enumTypeAdapter.isPresent()); + dataTemplate.getEnumType().add(tEnumType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); - enumTypeAdapter = dataTypeTemplateAdapter.getEnumTypeAdapterById("UNKNOWN_ID"); - assertTrue(enumTypeAdapter.isEmpty()); + // When + Optional enumTypeAdapter1 = dataTypeTemplateAdapter.getEnumTypeAdapterById("ID"); + // Then + assertThat(enumTypeAdapter1).isPresent(); + // When + Optional enumTypeAdapter2 = dataTypeTemplateAdapter.getEnumTypeAdapterById("UNKNOWN_ID"); + // Then + assertThat(enumTypeAdapter2).isEmpty(); } @Test - void testGetEnumTypeAdapters() { + void getEnumTypeAdapters_should_return_list_of_EnumTypeAdapter() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TEnumType tEnumType = new TEnumType(); tEnumType.setId("ID"); - dataTypeTemplateAdapter.getCurrentElem().getEnumType().add(tEnumType); - assertFalse(dataTypeTemplateAdapter.getEnumTypeAdapters().isEmpty()); + dataTemplate.getEnumType().add(tEnumType); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); + // When Then + assertThat(dataTypeTemplateAdapter.getEnumTypeAdapters()).isNotEmpty(); } @Test + @Tag("issue-321") void testHasSameID() { + // Given TDAType tdaType1 = new TDAType(); tdaType1.setId("SAME_ID"); - TDAType tdaType2 = new TDAType(); tdaType2.setId("SAME_ID"); - - assertTrue(DataTypeTemplateAdapter.hasSameID(tdaType1,tdaType2)); + // When Then + assertThat(DataTypeTemplateAdapter.hasSameID(tdaType1,tdaType2)).isTrue(); + // Given tdaType2.setId("ANOTHER_ID"); - assertFalse(DataTypeTemplateAdapter.hasSameID(tdaType1,tdaType2)); + // When Then + assertThat(DataTypeTemplateAdapter.hasSameID(tdaType1,tdaType2)).isFalse(); } @Test + @Tag("issue-321") void testHasSamePrivates() { - + // Given TDAType tdaType1 = new TDAType(); TPrivate aPrivate1 = new TPrivate(); aPrivate1.setType("A_PRIVATE1"); aPrivate1.setSource("A_URI_1"); tdaType1.getPrivate().add(aPrivate1); - TDAType tdaType2 = new TDAType(); - assertFalse(DataTypeTemplateAdapter.hasSamePrivates(tdaType1,tdaType2)); - + // When Then + assertThat(DataTypeTemplateAdapter.hasSamePrivates(tdaType1,tdaType2)).isFalse(); + // Given TPrivate aPrivate2 = new TPrivate(); aPrivate2.setType("A_PRIVATE1"); aPrivate2.setSource("A_URI_2"); tdaType2.getPrivate().add(aPrivate2); - assertFalse(DataTypeTemplateAdapter.hasSamePrivates(tdaType1,tdaType2)); - + // When Then + assertThat(DataTypeTemplateAdapter.hasSamePrivates(tdaType1,tdaType2)).isFalse(); + // Given aPrivate2.setSource("A_URI_1"); - assertTrue(DataTypeTemplateAdapter.hasSamePrivates(tdaType1,tdaType2)); + // When Then + assertThat(DataTypeTemplateAdapter.hasSamePrivates(tdaType1,tdaType2)).isTrue(); } @Test - void testFindDATypesWhichBdaContainsEnumTypeId() throws Exception { + void findDATypesWhichBdaContainsEnumTypeId_when_BDA_containing_specified_EnumTypeID_should_return_DATypeAdapters() { + // Given String enumTypeId = "RecCycModKind"; - DataTypeTemplateAdapter dataTypeTemplateAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + DataTypeTemplateAdapter dataTypeTemplateAdapter = initDttAdapterFromFile(SCD_DTT); + // When List daTypeAdapters = dataTypeTemplateAdapter.findDATypesWhichBdaContainsEnumTypeId(enumTypeId); - assertEquals(1,daTypeAdapters.size()); + // Then + assertThat(daTypeAdapters).hasSize(1); } @Test - void testFindDOTypesWhichDAContainsEnumTypeId() throws Exception { + @Tag("issue-321") + void testFindDOTypesWhichDAContainsEnumTypeId() { + // Given String enumTypeId = "PhaseAngleReferenceKind"; - DataTypeTemplateAdapter dataTypeTemplateAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + DataTypeTemplateAdapter dataTypeTemplateAdapter = initDttAdapterFromFile(SCD_DTT); + // When List doTypeAdapters = dataTypeTemplateAdapter.findDOTypesWhichDAContainsEnumTypeId(enumTypeId); - assertEquals(1,doTypeAdapters.size()); - + // Then + assertThat(doTypeAdapters).hasSize(1); + // Given enumTypeId = "RecCycModKind"; + // When doTypeAdapters = dataTypeTemplateAdapter.findDOTypesWhichDAContainsEnumTypeId(enumTypeId); - assertTrue(doTypeAdapters.isEmpty()); + // Then + assertThat(doTypeAdapters).isEmpty(); } @Test - void testFindDATypesFromStructBdaWithDATypeId() throws Exception { - DataTypeTemplateAdapter dataTypeTemplateAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + @Tag("issue-321") + void testFindDATypesFromStructBdaWithDATypeId() { + // Given + DataTypeTemplateAdapter dataTypeTemplateAdapter = initDttAdapterFromFile(SCD_DTT); String daTypeId = "DA2"; + // When List daTypeAdapters = dataTypeTemplateAdapter.findDATypesFromStructBdaWithDATypeId(daTypeId); - - assertEquals(1,daTypeAdapters.size()); + // Then + assertThat(daTypeAdapters).hasSize(1); + // Given daTypeId = "DA1"; - + // When daTypeAdapters = dataTypeTemplateAdapter.findDATypesFromStructBdaWithDATypeId(daTypeId); - assertTrue(daTypeAdapters.isEmpty()); + // Then + assertThat(daTypeAdapters).isEmpty(); } @Test - void testFindDOTypesWhichDAContainsStructWithDATypeId() throws Exception { - DataTypeTemplateAdapter dataTypeTemplateAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + void findDOTypesWhichDAContainsStructWithDATypeId_when_DA_containing_specific_StructDaTypeID_should_return_DOTypeAdapters() { + // Given + DataTypeTemplateAdapter dataTypeTemplateAdapter = initDttAdapterFromFile(SCD_DTT); String daTypeId = "DA1"; + // When List doTypeAdapters = dataTypeTemplateAdapter.findDOTypesWhichDAContainsStructWithDATypeId(daTypeId); - assertEquals(1,doTypeAdapters.size()); + // Then + assertThat(doTypeAdapters).hasSize(1); } @Test @@ -245,27 +347,39 @@ void retrieveSdoOrDO_shouldReturnListWithTwoElements() { } @Test - void testFindDOTypesFromSDOWithDOTypeId() throws Exception { - DataTypeTemplateAdapter dataTypeTemplateAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + @Tag("issue-321") + void testFindDOTypesFromSDOWithDOTypeId() { + // Given + DataTypeTemplateAdapter dataTypeTemplateAdapter = initDttAdapterFromFile(SCD_DTT); String doTypeId = "DO4"; + // When List doTypeList = dataTypeTemplateAdapter.findDOTypesFromSDOWithDOTypeId(doTypeId); - assertEquals(1,doTypeList.size()); - + // Then + assertThat(doTypeList).hasSize(1); + // Given doTypeId = "UnknownDOID"; + // When doTypeList = dataTypeTemplateAdapter.findDOTypesFromSDOWithDOTypeId(doTypeId); - assertTrue(doTypeList.isEmpty()); + // Then + assertThat(doTypeList).isEmpty(); } @Test - void testFindLNodeTypesFromDoWithDoTypeId() throws Exception { - DataTypeTemplateAdapter dataTypeTemplateAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + @Tag("issue-321") + void testFindLNodeTypesFromDoWithDoTypeId() { + // Given + DataTypeTemplateAdapter dataTypeTemplateAdapter = initDttAdapterFromFile(SCD_DTT); String doTypeId = "DO1"; + // When List lNodeTypeAdapters = dataTypeTemplateAdapter.findLNodeTypesFromDoWithDoTypeId(doTypeId); - assertEquals(1,lNodeTypeAdapters.size()); - + // Then + assertThat(lNodeTypeAdapters).hasSize(1); + // Given doTypeId = "UnknownDOID"; + // When lNodeTypeAdapters = dataTypeTemplateAdapter.findLNodeTypesFromDoWithDoTypeId(doTypeId); - assertTrue(lNodeTypeAdapters.isEmpty()); + // Then + assertThat(lNodeTypeAdapters).isEmpty(); } @ParameterizedTest @@ -276,21 +390,32 @@ void testFindLNodeTypesFromDoWithDoTypeId() throws Exception { "IED_NAME_Z6A2chUEHc7a15MvIUbQTVvioCgzOcWlNMfOzNbfjLJaueNf9T2GmQP7ShgYFr3SfYex5HdwvC5tRr9oAp0lmSwtqx" + "x1cHEKLMgKX7hZuUWCpKYPJ3I1fmE7NVIvVOtB1JsIOSGclfQfLGDEFjFG7vIozpkijZ0ugtZSOZuCavC5v5JL58yHO1RWCpYVdM" + "Dp4JhChU4YjhAhVGbOykJi0b4pc0saXoqf0q5imWmXiiuMuq0sc25IVA"}) - void generateDttId_shouldReturnIEdNameWithDTTId_whenBothLessThan255(String iedName, String dttId, String newDTTId) { + void generateDttId_whenBothLessThan255_shouldReturnIEdNameWithDTTId(String iedName, String dttId, String newDTTId) { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + DataTypeTemplateAdapter dataTypeTemplateAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); + // When Then assertThat(dataTypeTemplateAdapter.generateDttId(iedName, dttId)).hasSizeLessThan(256) .isEqualTo(newDTTId); } @Test - void importEnumTypes_shouldAddNewEnum_whenDifferentContent() throws Exception { + @Tag("issue-321") + void importEnumTypes_whenDifferentContent_shouldAddNewEnum() { //Given - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DataTypeTemplateAdapter prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT); + DataTypeTemplateAdapter prvDttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); Optional enumTypeAdapter = rcvDttAdapter.getEnumTypeAdapterById("PhaseAngleReferenceKind"); int rcvDTTEnumValsSize = enumTypeAdapter.get().getCurrentElem().getEnumVal().size(); //When rcvDttAdapter.importEnumType("IEDName",prvDttAdapter); + //When Optional rcvEnumTypeAdapter = rcvDttAdapter.getEnumTypeAdapterById("PhaseAngleReferenceKind"); //Then assertThat(rcvDttAdapter.getEnumTypeAdapters()) @@ -299,91 +424,101 @@ void importEnumTypes_shouldAddNewEnum_whenDifferentContent() throws Exception { } @Test - void importEnumTypes_shouldUpdateExistingEnum_whenSameContent() throws Exception { + void importEnumTypes_whenSameContent_shouldUpdateExistingEnum() { //Given - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DataTypeTemplateAdapter prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT); + DataTypeTemplateAdapter prvDttAdapter = initDttAdapterFromFile(SCD_DTT); //When rcvDttAdapter.importEnumType("IEDName",prvDttAdapter); //Then assertThat(rcvDttAdapter.getEnumTypeAdapters()).hasSize(prvDttAdapter.getEnumTypeAdapters().size()); } - @Test - void testImportDTT() throws Exception { - // - DataTypeTemplateAdapter prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + @Tag("issue-321") + void testImportDTT() { + // Given + DataTypeTemplateAdapter prvDttAdapter = initDttAdapterFromFile(SCD_DTT); + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT); int nbLNodeType = rcvDttAdapter.getLNodeTypeAdapters().size(); + // When rcvDttAdapter.importDTT("IEDName",prvDttAdapter); - assertEquals(nbLNodeType,rcvDttAdapter.getLNodeTypeAdapters().size()); - - prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + // Then + assertThat(rcvDttAdapter.getLNodeTypeAdapters()).hasSize(nbLNodeType); + // Given + prvDttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); + // When var mapOldNewId =rcvDttAdapter.importDTT("IEDName",prvDttAdapter); - assertTrue(nbLNodeType < rcvDttAdapter.getLNodeTypeAdapters().size()); - assertFalse(mapOldNewId.isEmpty()); + // Then + assertThat(rcvDttAdapter.getLNodeTypeAdapters()).hasSizeGreaterThan(nbLNodeType); + assertThat(mapOldNewId).isNotEmpty(); } @Test - void testImportLNodeType() throws Exception { - // - DataTypeTemplateAdapter prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - + @Tag("issue-321") + void testImportLNodeType() { + // Given + DataTypeTemplateAdapter prvDttAdapter = initDttAdapterFromFile(SCD_DTT); + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT); int nbLNodeType = rcvDttAdapter.getLNodeTypeAdapters().size(); + // When rcvDttAdapter.importLNodeType("IEDName",prvDttAdapter); - assertEquals(nbLNodeType,rcvDttAdapter.getLNodeTypeAdapters().size()); - - prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + // Then + assertThat(rcvDttAdapter.getLNodeTypeAdapters()).hasSize(nbLNodeType); + // Given + prvDttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); + // When var mapOldNewId = rcvDttAdapter.importLNodeType("IEDName",prvDttAdapter); - assertTrue(nbLNodeType < rcvDttAdapter.getLNodeTypeAdapters().size()); - assertFalse(mapOldNewId.isEmpty()); - - System.out.println(MarshallerWrapper.marshall(rcvDttAdapter.getParentAdapter().getCurrentElem())); - System.out.println(MarshallerWrapper.marshall(prvDttAdapter.getParentAdapter().getCurrentElem())); + // Then + assertThat(rcvDttAdapter.getLNodeTypeAdapters()).hasSizeGreaterThan(nbLNodeType); + assertThat(mapOldNewId).isNotEmpty(); } @Test - void testImportDOType() throws Exception { - DataTypeTemplateAdapter prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - + @Tag("issue-321") + void testImportDOType() { + // Given + DataTypeTemplateAdapter prvDttAdapter = initDttAdapterFromFile(SCD_DTT); + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT); int nbDOType = rcvDttAdapter.getDOTypeAdapters().size(); + // When rcvDttAdapter.importDOType("IEDName",prvDttAdapter); - assertEquals(nbDOType,rcvDttAdapter.getDOTypeAdapters().size()); - - prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + // Then + assertThat(rcvDttAdapter.getDOTypeAdapters()).hasSize(nbDOType); + // Given + prvDttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); + // When rcvDttAdapter.importDOType("IEDName",prvDttAdapter); - assertTrue(nbDOType < rcvDttAdapter.getDOTypeAdapters().size()); - - System.out.println(MarshallerWrapper.marshall(rcvDttAdapter.getParentAdapter().getCurrentElem())); - System.out.println(MarshallerWrapper.marshall(prvDttAdapter.getParentAdapter().getCurrentElem())); + // Then + assertThat(rcvDttAdapter.getDOTypeAdapters()).hasSizeGreaterThan(nbDOType); } @Test - void testImportDAType() throws Exception { - DataTypeTemplateAdapter rcvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - DataTypeTemplateAdapter prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + @Tag("issue-321") + void testImportDAType() { + // Given + DataTypeTemplateAdapter rcvDttAdapter = initDttAdapterFromFile(SCD_DTT); + DataTypeTemplateAdapter prvDttAdapter = initDttAdapterFromFile(SCD_DTT); int nbDAType = rcvDttAdapter.getDATypeAdapters().size(); - + // When rcvDttAdapter.importDAType("IEDName",prvDttAdapter); - assertEquals(nbDAType,rcvDttAdapter.getDATypeAdapters().size()); - prvDttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); - + // Then + assertThat(rcvDttAdapter.getDATypeAdapters()).hasSize(nbDAType); + // Given + prvDttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); + // When rcvDttAdapter.importDAType("IEDName",prvDttAdapter); - assertTrue(nbDAType < rcvDttAdapter.getDATypeAdapters().size()); - System.out.println(MarshallerWrapper.marshall(prvDttAdapter.getParentAdapter().getCurrentElem())); - System.out.println(MarshallerWrapper.marshall(rcvDttAdapter.getParentAdapter().getCurrentElem())); + // Then + assertThat(rcvDttAdapter.getDATypeAdapters()).hasSizeGreaterThan(nbDAType); } @ParameterizedTest @CsvSource({"A,LN1,No coherence or path between DOType(DO2) and DA(A)", "antRef,LN1,Invalid ExtRef signal: no coherence between pDO(Op.origin) and pDA(antRef)", "antRef.origin.ctlVal,LN_Type1,Unknown LNodeType:LN_Type1"}) - void getBinderDataAttributeRef_shouldThrowScdException_whenDONotContainDA(String pDA, String lnType, String message) throws Exception { + void getBinderDataAttributeRef_whenDONotContainDA_shouldThrowScdException(String pDA, String lnType, String message) throws Exception { //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); signalInfo.setPLN("PIOC"); signalInfo.setPDO("Op.origin"); @@ -395,9 +530,9 @@ void getBinderDataAttributeRef_shouldThrowScdException_whenDONotContainDA(String } @Test - void getBinderDataAttributeRef_shouldThrowScdException_whenLnClassNotMatches() throws Exception { + void getBinderDataAttributeRef_whenLnClassNotMatches_shouldThrowScdException() { //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); LNodeTypeAdapter lNodeTypeAdapter = dttAdapter.getLNodeTypeAdapterById("LN1").get(); lNodeTypeAdapter.getCurrentElem().unsetLnClass(); @@ -412,9 +547,9 @@ void getBinderDataAttributeRef_shouldThrowScdException_whenLnClassNotMatches() t } @Test - void getBinderDataAttributeRef_shouldThrowScdException_whenDOIdNotFound() throws Exception { + void getBinderDataAttributeRef_whenDOIdNotFound_shouldThrowScdException() { //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); signalInfo.setPLN("PIOC"); @@ -426,9 +561,9 @@ void getBinderDataAttributeRef_shouldThrowScdException_whenDOIdNotFound() throws } @Test - void getBinderDataAttributeRef_shouldReturnBindingInfoWithoutDO_whenSignalPDOEmpty() throws Exception { + void getBinderDataAttributeRef_whenSignalPDOEmpty_shouldReturnBindingInfoWithoutDO() { //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); signalInfo.setPLN("PIOC"); @@ -442,9 +577,9 @@ void getBinderDataAttributeRef_shouldReturnBindingInfoWithoutDO_whenSignalPDOEmp } @Test - void getBinderDataAttributeRef_shouldReturnBindingInfoWithoutDA_whenSignalPDAEmpty() throws Exception { + void getBinderDataAttributeRef_whenSignalPDAEmpty_shouldReturnBindingInfoWithoutDA() { //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); signalInfo.setPLN("PIOC"); @@ -460,9 +595,9 @@ void getBinderDataAttributeRef_shouldReturnBindingInfoWithoutDA_whenSignalPDAEmp } @Test - void getBinderDataAttributeRef_shouldReturnBindingInfo_whenExist() throws Exception { + void getBinderDataAttributeRef_whenExist_shouldReturnBindingInfo() { //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); signalInfo.setPLN("PIOC"); @@ -476,20 +611,28 @@ void getBinderDataAttributeRef_shouldReturnBindingInfo_whenExist() throws Except } @Test - void addPrivate() throws Exception { - //Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + void addPrivate_should_throw_exception() { + // Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + SCL scl = new SCL(); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + scl.setDataTypeTemplates(dataTemplate); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + + DataTypeTemplateAdapter dttAdapter = new DataTypeTemplateAdapter(sclRootAdapter, dataTemplate); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); //When Then - assertThrows(UnsupportedOperationException.class, () -> dttAdapter.addPrivate(tPrivate)); + assertThatCode(() -> dttAdapter.addPrivate(tPrivate)) + .isInstanceOf(UnsupportedOperationException.class); } @Test - void elementXPath() throws Exception { + void elementXPath_should_return_expected_xpath_value() { // Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); // When String result = dttAdapter.elementXPath(); // Then diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateTestUtils.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateTestUtils.java new file mode 100644 index 000000000..7dc02d6f3 --- /dev/null +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DataTypeTemplateTestUtils.java @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2021 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.scl.dtt; + +import lombok.experimental.UtilityClass; +import org.lfenergy.compas.scl2007b4.model.SCL; +import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; + +@UtilityClass +public class DataTypeTemplateTestUtils { + public static final String SCD_DTT = "/dtt-test-schema-conf/scd_dtt_import_test.xml"; + public static final String SCD_DTT_DIFF_CONTENT_SAME_ID = "/dtt-test-schema-conf/scd_dtt_import_sameid-diff-content-test.xml"; + + public static DataTypeTemplateAdapter initDttAdapterFromFile(String fileName) { + SCL scd = SclTestMarshaller.getSCLFromFile(fileName); + SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + return new DataTypeTemplateAdapter( + sclRootAdapter, + scd.getDataTypeTemplates() + ); + } + +} diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/EnumTypeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/EnumTypeAdapterTest.java index 1f0efcb27..ac561dae4 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/EnumTypeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/EnumTypeAdapterTest.java @@ -4,42 +4,51 @@ package org.lfenergy.compas.sct.commons.scl.dtt; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl2007b4.model.TEnumType; -import org.lfenergy.compas.scl2007b4.model.TEnumVal; -import org.lfenergy.compas.scl2007b4.model.TPrivate; -import org.mockito.Mockito; - -import java.util.List; +import org.lfenergy.compas.scl2007b4.model.*; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -class EnumTypeAdapterTest extends AbstractDTTLevel { +class EnumTypeAdapterTest { - @Override - protected void completeInit() { - TEnumType tEnumType = new TEnumType(); - tEnumType.setId("ID"); - List tEnumTypes = List.of(tEnumType); - sclElement = tEnumType; - Mockito.when(sclElementAdapter.getCurrentElem().getEnumType()).thenReturn(tEnumTypes); + @Test + void constructor_whenCalledWithNoRelationBetweenDataTypeTemplatesAndEnumType_shouldThrowException() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(new TDataTypeTemplates()); + TEnumType enumType = new TEnumType(); + //When Then + assertThatCode(() -> new EnumTypeAdapter(dataTemplateAdapter, enumType)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void testAmChildElement(){ - init(); - assertDoesNotThrow( - () -> new EnumTypeAdapter(sclElementAdapter,sclElement) - ); + void constructor_whenCalledWithExistingRelationBetweenDataTypeTemplatesAndEnumType_shouldNotThrowException() { + //Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TEnumType enumType = new TEnumType(); + dataTemplate.getEnumType().add(enumType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + //When Then + assertThatCode(() -> new EnumTypeAdapter(dataTemplateAdapter, enumType)).doesNotThrowAnyException(); } @Test + @Tag("issue-321") void testHasSameContentAs(){ - init(); - EnumTypeAdapter enumTypeAdapter = assertDoesNotThrow( - () -> new EnumTypeAdapter(sclElementAdapter,sclElement) - ); + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TEnumType enumType = new TEnumType(); + dataTemplate.getEnumType().add(enumType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + EnumTypeAdapter enumTypeAdapter = new EnumTypeAdapter(dataTemplateAdapter, enumType); TEnumVal sameEnumVal = new TEnumVal(); sameEnumVal.setValue("sameValue"); sameEnumVal.setOrd(1); @@ -47,42 +56,49 @@ void testHasSameContentAs(){ enumTypeAdapter.getCurrentElem().getEnumVal().add(sameEnumVal); TEnumType anotherEnumType = new TEnumType(); anotherEnumType.getEnumVal().add(sameEnumVal); - - assertTrue(enumTypeAdapter.hasSameContentAs(anotherEnumType)); - assertFalse(enumTypeAdapter.hasSameContentAs(new TEnumType())); // empty enumType - + // When Then + assertThat(enumTypeAdapter.hasSameContentAs(anotherEnumType)).isTrue(); + // When Then + assertThat(enumTypeAdapter.hasSameContentAs(new TEnumType())).isFalse(); // empty enumType TEnumVal notSameEnumVal = new TEnumVal(); notSameEnumVal.setValue("notSameValue"); notSameEnumVal.setOrd(1); notSameEnumVal.setDesc("Another desc"); anotherEnumType = new TEnumType(); anotherEnumType.getEnumVal().add(notSameEnumVal); - assertFalse(enumTypeAdapter.hasSameContentAs(anotherEnumType)); + // When Then + assertThat(enumTypeAdapter.hasSameContentAs(anotherEnumType)).isFalse(); } @Test - void addPrivate() { - init(); - EnumTypeAdapter enumTypeAdapter = assertDoesNotThrow( - () -> new EnumTypeAdapter(sclElementAdapter,sclElement) - ); - + void addPrivate_with_type_and_source_should_create_Private() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TEnumType enumType = new TEnumType(); + dataTemplate.getEnumType().add(enumType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + EnumTypeAdapter enumTypeAdapter = new EnumTypeAdapter(dataTemplateAdapter, enumType); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(enumTypeAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(enumTypeAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When enumTypeAdapter.addPrivate(tPrivate); - assertEquals(1, enumTypeAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(enumTypeAdapter.getCurrentElem().getPrivate()).hasSize(1); } - @Test - void elementXPath() { + void elementXPath_should_return_expected_xpath_value() { // Given - init(); - EnumTypeAdapter enumTypeAdapter = assertDoesNotThrow( - () -> new EnumTypeAdapter(sclElementAdapter,sclElement) - ); + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TEnumType enumType = new TEnumType(); + enumType.setId("ID"); + dataTemplate.getEnumType().add(enumType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + EnumTypeAdapter enumTypeAdapter = new EnumTypeAdapter(dataTemplateAdapter, enumType); // When String result = enumTypeAdapter.elementXPath(); // Then diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java index 521b6affb..4dcb052e0 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java @@ -4,198 +4,218 @@ package org.lfenergy.compas.sct.commons.scl.dtt; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.mockito.Mockito; -import java.util.ArrayList; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.sct.commons.dto.DTO.P_DO; +import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -class LNodeTypeAdapterTest extends AbstractDTTLevel { - @Override - protected void completeInit() { - TLNodeType tlNodeType = new TLNodeType(); - tlNodeType.setId("ID"); - List tlNodeTypes = new ArrayList<>(); - tlNodeTypes.add(tlNodeType); - sclElement = tlNodeType; - Mockito.when(sclElementAdapter.getCurrentElem().getLNodeType()).thenReturn(tlNodeTypes); +class LNodeTypeAdapterTest { + + @Test + void constructor_whenCalledWithNoRelationBetweenDataTypeTemplatesAndLNodeType_shouldThrowException() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(new TDataTypeTemplates()); + TLNodeType nodeType = new TLNodeType(); + // When Then + assertThatCode(() -> new LNodeTypeAdapter(dataTemplateAdapter, nodeType)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void testAmChildElementRef() { - init(); - assertDoesNotThrow( - () -> new LNodeTypeAdapter(sclElementAdapter,sclElement) - ); + void constructor_whenCalledWithExistingRelationBetweenDataTypeTemplatesAndLNodeType_shouldNotThrowException() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TLNodeType nodeType = new TLNodeType(); + dataTemplate.getLNodeType().add(nodeType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + // When Then + assertThatCode(() -> new LNodeTypeAdapter(dataTemplateAdapter, nodeType)).doesNotThrowAnyException(); } @Test + @Tag("issue-321") void testHasSameContentAs() { - init(); + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TLNodeType tlNodeType = createLNOdeType(); TLNodeType tlNodeType1 = createLNOdeType(); - sclElement = tlNodeType; - sclElementAdapter.getCurrentElem().getLNodeType().add(tlNodeType); - LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow( - () -> new LNodeTypeAdapter(sclElementAdapter,tlNodeType) - ); - - assertEquals(DTO.HOLDER_LN_CLASS,lNodeTypeAdapter.getLNClass()); - assertTrue(lNodeTypeAdapter.getDOTypeId("Op").isPresent()); - - assertTrue(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); - assertEquals(3,tlNodeType1.getDO().size()); - + dataTemplate.getLNodeType().add(tlNodeType); + dataTemplate.getLNodeType().add(tlNodeType1); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + LNodeTypeAdapter lNodeTypeAdapter = new LNodeTypeAdapter(dataTemplateAdapter, tlNodeType); + assertThat(lNodeTypeAdapter.getLNClass()).isEqualTo(DTO.HOLDER_LN_CLASS); + assertThat(lNodeTypeAdapter.getDOTypeId("Op")).isPresent(); + + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isTrue(); + assertThat(tlNodeType1.getDO()).hasSize(3); + // Given tlNodeType1.getDO().get(2).setAccessControl("AC"); - assertFalse(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); - + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isFalse(); + // Given tlNodeType1.getDO().get(2).setTransient(true); - assertFalse(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); - + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isFalse(); + // Given tlNodeType1.getDO().get(2).setName("NAME"); - assertFalse(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); - + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isFalse(); + // Given tlNodeType1.getDO().get(2).setType("DO11"); - assertFalse(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); - + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isFalse(); + // Given TDO tdo = new TDO(); tdo.setType("DO12"); tdo.setName("OpPPP"); tlNodeType1.getDO().add(tdo); - assertFalse(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); - + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isFalse(); + // Given tlNodeType1.setIedType("ANOTHER_TYPE"); - assertFalse(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); - + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isFalse(); + // Given TPrivate aPrivate = new TPrivate(); aPrivate.setType("TYPE"); aPrivate.setSource("https://a.com"); tlNodeType1.getPrivate().add(aPrivate); - assertFalse(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)); + // When Then + assertThat(lNodeTypeAdapter.hasSameContentAs(tlNodeType1)).isFalse(); } @Test - void containsDOWithDOTypeId() { - init(); - TLNodeType tlNodeType = createLNOdeType(); - TLNodeType tlNodeType1 = createLNOdeType(); - sclElement = tlNodeType; - sclElementAdapter.getCurrentElem().getLNodeType().add(tlNodeType); - LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow( - () -> new LNodeTypeAdapter(sclElementAdapter,tlNodeType) - ); - - assertTrue(lNodeTypeAdapter.containsDOWithDOTypeId("DO1")); - assertFalse(lNodeTypeAdapter.containsDOWithDOTypeId("DO11")); - } - - - private TLNodeType createLNOdeType(){ - TLNodeType tlNodeType = new TLNodeType(); - tlNodeType.setId("BDA1"); - tlNodeType.setIedType("IEDTYPE"); - tlNodeType.getLnClass().add(DTO.HOLDER_LN_CLASS); - + void containsDOWithDOTypeId_should_check_if_LNodeType_contains_DO_with_specific_DOType_ID() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); TDO tdo = new TDO(); tdo.setType("DO1"); - tdo.setName("Op"); - - TDO tdo1 = new TDO(); - tdo1.setType("DO2"); - tdo1.setName("Beh"); - - TDO tdo2 = new TDO(); - tdo2.setType("DO3"); - tdo2.setName("StrVal"); - - tlNodeType.getDO().addAll(List.of(tdo,tdo1,tdo2)); - return tlNodeType; + TLNodeType tlNodeType = new TLNodeType(); + tlNodeType.getDO().add(tdo); + dataTemplate.getLNodeType().add(tlNodeType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + LNodeTypeAdapter lNodeTypeAdapter = new LNodeTypeAdapter(dataTemplateAdapter, tlNodeType); + // When Then + assertThat(lNodeTypeAdapter.containsDOWithDOTypeId("DO1")).isTrue(); + // When Then + assertThat(lNodeTypeAdapter.containsDOWithDOTypeId("DO11")).isFalse(); } + @Test - void testGetDataAttributeRefs() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getLNodeTypeAdapterById("LN1").get()); + @Tag("issue-321") + void testGetDataAttributeRefs() { + // Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); + LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getLNodeTypeAdapterById("LN1").get()); DataAttributeRef rootDataAttributeRef = new DataAttributeRef(); rootDataAttributeRef.setDoName(new DoTypeName("Op")); DataAttributeRef filter = new DataAttributeRef(); filter.setDoName(new DoTypeName("Op.res")); + // When var dataAttributeRefs = lNodeTypeAdapter.getDataAttributeRefs(filter); - assertEquals(2,dataAttributeRefs.size()); - + // Then + assertThat(dataAttributeRefs).hasSize(2); + // Given filter.setDoName(new DoTypeName("Op.res")); filter.setDaName(new DaTypeName("d")); + // When dataAttributeRefs = lNodeTypeAdapter.getDataAttributeRefs(filter); - assertEquals(1,dataAttributeRefs.size()); - + // Then + assertThat(dataAttributeRefs).hasSize(1); + // Given filter.setDoName(new DoTypeName("Op.res")); filter.setDaName(new DaTypeName("antRef")); - assertTrue(lNodeTypeAdapter.getDataAttributeRefs(filter).isEmpty()); + // When Then + assertThat(lNodeTypeAdapter.getDataAttributeRefs(filter)).isEmpty(); } @Test - void testCheck() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getLNodeTypeAdapterById("LN1").get()); + @Tag("issue-321") + void testCheck() { + // Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); + LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getLNodeTypeAdapterById("LN1").get()); DoTypeName doTypeName1 = new DoTypeName(""); DaTypeName daTypeName1 = new DaTypeName(""); + // When Then assertThatThrownBy(() -> lNodeTypeAdapter.check(doTypeName1,daTypeName1)).isInstanceOf(ScdException.class); DoTypeName doTypeName2 = new DoTypeName("do"); DaTypeName daTypeName2 = new DaTypeName(""); + // When Then assertThatThrownBy(() -> lNodeTypeAdapter.check(doTypeName2,daTypeName2)).isInstanceOf(ScdException.class); DoTypeName doTypeName3 = new DoTypeName("do"); DaTypeName daTypeName3 = new DaTypeName("da"); + // When Then assertThatThrownBy(() -> lNodeTypeAdapter.check(doTypeName3,daTypeName3)).isInstanceOf(ScdException.class); DoTypeName doTypeName = new DoTypeName("Op.res"); DaTypeName daTypeName = new DaTypeName("d"); - - assertDoesNotThrow(() -> lNodeTypeAdapter.check(doTypeName,daTypeName)); + // When Then + assertThatCode(() -> lNodeTypeAdapter.check(doTypeName,daTypeName)).doesNotThrowAnyException(); doTypeName.setName("StrVal"); doTypeName.getStructNames().clear(); daTypeName.setName("origin"); daTypeName.getStructNames().clear(); daTypeName.setStructNames(List.of("origin","ctlVal")); - assertDoesNotThrow(() -> lNodeTypeAdapter.check(doTypeName,daTypeName)); + // When Then + assertThatCode(() -> lNodeTypeAdapter.check(doTypeName,daTypeName)).doesNotThrowAnyException(); } @Test - void getDataAttributeRefByDaName() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile( - AbstractDTTLevel.SCD_DTT_DIFF_CONTENT_SAME_ID - ); + void getDataAttributeRefByDaName_should_return_list_of_DataAttributeRef() { + // Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); DaTypeName daTypeName = new DaTypeName("antRef","origin.ctlVal"); LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getLNodeTypeAdapterById("LN1").get()); + // When List dataAttributeRefs = assertDoesNotThrow(()-> lNodeTypeAdapter.getDataAttributeRefByDaName(daTypeName)); - assertEquals(2,dataAttributeRefs.size()); + // Then + assertThat(dataAttributeRefs).hasSize(2); } @Test - void addPrivate() throws Exception { - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); - LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getLNodeTypeAdapterById("LN1").get()); + void addPrivate_with_type_and_source_should_create_Private() { + // Given + DataTypeTemplateAdapter dataTemplateAdapter = mock(DataTypeTemplateAdapter.class); + TDataTypeTemplates dataTemplate = new TDataTypeTemplates(); + TLNodeType nodeType = new TLNodeType(); + dataTemplate.getLNodeType().add(nodeType); + when(dataTemplateAdapter.getCurrentElem()).thenReturn(dataTemplate); + LNodeTypeAdapter lNodeTypeAdapter = new LNodeTypeAdapter(dataTemplateAdapter, nodeType); + assertThat(lNodeTypeAdapter.getCurrentElem().getPrivate()).isEmpty(); + TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertFalse(lNodeTypeAdapter.getCurrentElem().getPrivate().isEmpty()); + // When lNodeTypeAdapter.addPrivate(tPrivate); - assertEquals(2, lNodeTypeAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(lNodeTypeAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test - void elementXPath() throws Exception { + void elementXPath_should_return_expected_xpath_value() { // Given - DataTypeTemplateAdapter dttAdapter = AbstractDTTLevel.initDttAdapterFromFile(AbstractDTTLevel.SCD_DTT); + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT); LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() ->dttAdapter.getLNodeTypeAdapterById("LN1").get()); // When String result = lNodeTypeAdapter.elementXPath(); @@ -204,15 +224,12 @@ void elementXPath() throws Exception { } @Test - void checkMatchingDOType_shouldFindOneDO() { - //Given - ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); - signalInfo.setPDO("P_DO12"); - + @Tag("issue-321") + void findMatchingDOType_shouldFindOneDO() { + // Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); sclRootAdapter.getCurrentElem().setDataTypeTemplates(new TDataTypeTemplates()); - DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow( - sclRootAdapter::getDataTypeTemplateAdapter); + DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow(sclRootAdapter::getDataTypeTemplateAdapter); TDO tdo= new TDO(); tdo.setName("P_DO"); @@ -228,25 +245,28 @@ void checkMatchingDOType_shouldFindOneDO() { dttAdapter.getCurrentElem().getLNodeType().add(tlNodeType); LNodeTypeAdapter lNodeTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getLNodeTypeAdapterById("ID").get()); + + ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); + signalInfo.setPDO("P_DO12"); //When DataTypeTemplateAdapter.DOTypeInfo expectedDoTypeInfo = assertDoesNotThrow(() -> lNodeTypeAdapter.findMatchingDOType(signalInfo)); //Then assertThat(expectedDoTypeInfo.getDoTypeId()).isEqualTo("DO1"); assertThat(expectedDoTypeInfo.getDoTypeName().getName()).isEqualTo("P_DO12"); assertThat(expectedDoTypeInfo.getDoTypeAdapter()).isNotNull(); - } @Test - void checkMatchingDOType_shouldThrowException_whenDOUnknown() { + @Tag("issue-321") + void checkMatchingDOType_whenDOUnknown_shouldThrowException() { //Given ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); - SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); sclRootAdapter.getCurrentElem().setDataTypeTemplates(new TDataTypeTemplates()); - DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow( - sclRootAdapter::getDataTypeTemplateAdapter); + //When Then + DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow(sclRootAdapter::getDataTypeTemplateAdapter); + //Given TDO tdo= new TDO(); tdo.setName(P_DO); tdo.setType("DO1"); @@ -268,16 +288,18 @@ void checkMatchingDOType_shouldThrowException_whenDOUnknown() { } @Test - void checkMatchingDOType_shouldThrowException_whenDONotReferenced() { + @Tag("issue-321") + void checkMatchingDOType_whenDONotReferenced_shouldThrowException() { //Given ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); signalInfo.setPDO("P_DO"); SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); sclRootAdapter.getCurrentElem().setDataTypeTemplates(new TDataTypeTemplates()); - DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow( - sclRootAdapter::getDataTypeTemplateAdapter); + //When Then + DataTypeTemplateAdapter dttAdapter = assertDoesNotThrow(sclRootAdapter::getDataTypeTemplateAdapter); + //Given TDO tdo= new TDO(); tdo.setName("P_DO"); tdo.setType("DO2"); @@ -298,4 +320,24 @@ void checkMatchingDOType_shouldThrowException_whenDONotReferenced() { .hasMessage("P_DO: No referenced to DO id : DO2, scl file not valid"); } + + private TLNodeType createLNOdeType(){ + TLNodeType tlNodeType = new TLNodeType(); + tlNodeType.setId("BDA1"); + tlNodeType.setIedType("IEDTYPE"); + tlNodeType.getLnClass().add(DTO.HOLDER_LN_CLASS); + TDO tdo = new TDO(); + tdo.setType("DO1"); + tdo.setName("Op"); + TDO tdo1 = new TDO(); + tdo1.setType("DO2"); + tdo1.setName("Beh"); + TDO tdo2 = new TDO(); + tdo2.setType("DO3"); + tdo2.setName("StrVal"); + tlNodeType.getDO().addAll(List.of(tdo,tdo1,tdo2)); + return tlNodeType; + } + + } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java index 8079a0f28..fc99fbd45 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/header/HeaderAdapterTest.java @@ -3,79 +3,93 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.sct.commons.scl.header; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -import org.lfenergy.compas.scl2007b4.model.THeader; -import org.lfenergy.compas.scl2007b4.model.THitem; -import org.lfenergy.compas.scl2007b4.model.TPrivate; -import org.lfenergy.compas.sct.commons.exception.ScdException; +import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class HeaderAdapterTest { @Test - void testAmChildElementRef() throws ScdException { - SclRootAdapter sclRootAdapter = - new SclRootAdapter("hID","hVersion","hRevision"); - sclRootAdapter.getCurrentElem().setHeader(new THeader()); - HeaderAdapter hAdapter = sclRootAdapter.getHeaderAdapter(); - assertTrue(hAdapter.amChildElementRef()); - - assertThrows(IllegalArgumentException.class, - () ->new HeaderAdapter(sclRootAdapter,new THeader())); + void constructor_whenCalledWithNoRelationBetweenSCLAndHeader_shouldThrowException() { + //Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + THeader header = new THeader(); + //When Then + assertThatCode(() -> new HeaderAdapter(sclRootAdapter, header)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void testAddHistoryItem() throws ScdException { - SclRootAdapter sclRootAdapter = new SclRootAdapter( - "hID","hVersion","hRevision" - ); - - HeaderAdapter hAdapter = sclRootAdapter.getHeaderAdapter(); - assertEquals("hID", hAdapter.getHeaderId()); - assertEquals("hVersion", hAdapter.getHeaderVersion()); - assertEquals("hRevision", hAdapter.getHeaderRevision()); - - hAdapter.addHistoryItem("who","what","why"); + void constructor_whenCalledWithExistingRelationBetweenSCLAndHeader_shouldNotThrowException() { + //Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + SCL scl = new SCL(); + THeader header = new THeader(); + scl.setHeader(header); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + //When Then + assertThatCode(() -> new HeaderAdapter(sclRootAdapter, header)).doesNotThrowAnyException(); + } - assertNotNull(hAdapter.getCurrentElem().getHistory()); - Assertions.assertFalse(hAdapter.getHistoryItems().isEmpty()); - THitem tHitem = hAdapter.getHistoryItems().get(0); + @Test + @Tag("issue-321") + // test here should be only for addHistoryItem method + void testAddHistoryItem() { + //Given + SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); + HeaderAdapter headerAdapter = sclRootAdapter.getHeaderAdapter(); + assertThat(headerAdapter.getHeaderId()).isEqualTo("hID"); + assertThat(headerAdapter.getHeaderVersion()).isEqualTo("hVersion"); + assertThat(headerAdapter.getHeaderRevision()).isEqualTo("hRevision"); + //When + headerAdapter.addHistoryItem("who","what","why"); + //Then + assertThat(headerAdapter.getCurrentElem().getHistory()).isNotNull(); + assertThat(headerAdapter.getHistoryItems()).isNotEmpty(); + THitem tHitem = headerAdapter.getHistoryItems().get(0); assertAll("HISTORY", - () -> assertEquals("who", tHitem.getWho()), - () -> assertEquals("what", tHitem.getWhat()), - () -> assertEquals("why", tHitem.getWhy()), - () -> Assertions.assertEquals(hAdapter.getCurrentElem().getRevision(), tHitem.getRevision()), - () -> Assertions.assertEquals(hAdapter.getCurrentElem().getVersion(), tHitem.getVersion()) - ); - - hAdapter.updateRevision("newRevision"); - hAdapter.updateVersion("newVersion"); - assertEquals("newVersion", hAdapter.getHeaderVersion()); - assertEquals("newRevision", hAdapter.getHeaderRevision()); + () -> assertThat(tHitem.getWho()).isEqualTo("who"), + () -> assertThat(tHitem.getWhat()).isEqualTo("what"), + () -> assertThat(tHitem.getWhy()).isEqualTo("why"), + () -> assertThat(tHitem.getRevision()).isEqualTo(headerAdapter.getCurrentElem().getRevision()), + () -> assertThat(tHitem.getVersion()).isEqualTo(headerAdapter.getCurrentElem().getVersion())); + //When + headerAdapter.updateRevision("newRevision"); + //When + headerAdapter.updateVersion("newVersion"); + //Then + assertThat(headerAdapter.getHeaderVersion()).isEqualTo("newVersion"); + assertThat(headerAdapter.getHeaderRevision()).isEqualTo("newRevision"); } @Test - void addPrivate() { - SclRootAdapter sclRootAdapter = new SclRootAdapter( - "hID","hVersion","hRevision" - ); - HeaderAdapter hAdapter = sclRootAdapter.getHeaderAdapter(); + void addPrivate_should_throw_UnsupportedOperationException() { + //Given + SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); + HeaderAdapter headerAdapter = sclRootAdapter.getHeaderAdapter(); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertThrows(UnsupportedOperationException.class, () -> hAdapter.addPrivate(tPrivate)); + //When THen + assertThatCode(() -> headerAdapter.addPrivate(tPrivate)) + .isInstanceOf(UnsupportedOperationException.class); } @ParameterizedTest @CsvSource(value = {"hID;hVersion;hRevision;Header[@id=\"hID\" and @version=\"hVersion\" and @revision=\"hRevision\"]", ";;;Header[not(@id) and not(@version) and not(@revision)]"} , delimiter = ';') - void elementXPath(String hID, String hVersion, String hRevision,String message) { + void elementXPath_should_return_expected_xpath_value(String hID, String hVersion, String hRevision,String message) { // Given THeader tHeader = new THeader(); tHeader.setId(hID); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/icd/IcdHeaderTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/icd/IcdHeaderTest.java index dde0d3dbd..bc117fe4a 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/icd/IcdHeaderTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/icd/IcdHeaderTest.java @@ -19,7 +19,7 @@ class IcdHeaderTest { @Test - void toTCompasICDHeader() { + void toTCompasICDHeader_shouldReturnCompasICDHeaderObject() { //Given IcdHeader icdHeader = new IcdHeader(createHeader()); //When @@ -31,7 +31,7 @@ void toTCompasICDHeader() { } @Test - void getIcdSystemVersionUUID() { + void getIcdSystemVersionUUID_shouldReturnExpectedValue() { //Given IcdHeader icdHeader = new IcdHeader(createHeader()); //When @@ -41,7 +41,7 @@ void getIcdSystemVersionUUID() { } @Test - void testToString() { + void toString_shouldReturnExpectedValue() { //Given IcdHeader icdHeader = new IcdHeader(createHeader()); //When diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapterTest.java index 9afe7d472..50bfe3996 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapterTest.java @@ -10,7 +10,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.dto.DTO; import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; @@ -20,32 +19,30 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class AccessPointAdapterTest { @Test - void amChildElementRef() { + void amChildElementRef_whenCalledWithExistingRelationBetweenIEDAndAccessPoint_shouldReturnTrue() { //Given - SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); + IEDAdapter iedAdapter = mock(IEDAdapter.class); TIED tied = new TIED(); - tied.setName(DTO.HOLDER_IED_NAME); TAccessPoint tAccessPoint = new TAccessPoint(); tAccessPoint.setName("AP_NAME"); - tAccessPoint.setServices(new TServices()); tied.getAccessPoint().add(tAccessPoint); - sclRootAdapter.getCurrentElem().getIED().add(tied); - IEDAdapter iAdapter = sclRootAdapter.getIEDAdapterByName(DTO.HOLDER_IED_NAME); - //When - AccessPointAdapter accessPointAdapter = new AccessPointAdapter(iAdapter, iAdapter.getCurrentElem().getAccessPoint().get(0)); - //Then + when(iedAdapter.getCurrentElem()).thenReturn(tied); + + AccessPointAdapter accessPointAdapter = new AccessPointAdapter(iedAdapter, tAccessPoint); + // When Then assertThat(accessPointAdapter.amChildElementRef()).isTrue(); - assertThat(accessPointAdapter.getCurrentElem().getServices()).isNotNull(); } @ParameterizedTest @CsvSource(value = {"AP_NAME;AccessPoint[@name=\"AP_NAME\"]", ";AccessPoint[not(@name)]"} , delimiter = ';') - void elementXPath(String apName, String message) { + void elementXPath_should_return_expected_xpath_value(String apName, String message) { // Given TAccessPoint tAccessPoint = new TAccessPoint(); tAccessPoint.setName(apName); @@ -57,7 +54,7 @@ void elementXPath(String apName, String message) { } @Test - void getXPath() { + void getXPath_should_return_expected_xpath_value() { // Given TIED tied = new TIED(); tied.setName("IED_NAME"); @@ -167,7 +164,7 @@ public static AccessPointAdapter provideAPForCheckLimitationForIED() { } @Test - void checkControlsLimitation_should_succeed_when_ConfReportControl_is_missing() { + void checkControlsLimitation_when_ConfReportControl_is_missing_should_succeed() { //Given AccessPointAdapter accessPointAdapter = provideAPForCheckLimitationForIED(); accessPointAdapter.getCurrentElem().getServices().setConfReportControl(null); @@ -178,7 +175,7 @@ void checkControlsLimitation_should_succeed_when_ConfReportControl_is_missing() } @Test - void checkControlsLimitation_should_succeed_when_GOOSE_is_missing() { + void checkControlsLimitation_when_GOOSE_is_missing_should_succeed() { //Given AccessPointAdapter accessPointAdapter = provideAPForCheckLimitationForIED(); accessPointAdapter.getCurrentElem().getServices().setGOOSE(null); @@ -189,7 +186,7 @@ void checkControlsLimitation_should_succeed_when_GOOSE_is_missing() { } @Test - void checkControlsLimitation_should_succeed_when_ConfDataSet_is_missing() { + void checkControlsLimitation_when_ConfDataSet_is_missing_should_succeed() { //Given AccessPointAdapter accessPointAdapter = provideAPForCheckLimitationForIED(); accessPointAdapter.getCurrentElem().getServices().setConfDataSet(null); @@ -200,7 +197,7 @@ void checkControlsLimitation_should_succeed_when_ConfDataSet_is_missing() { } @Test - void checkControlsLimitation_should_succeed_when_Services_is_missing() { + void checkControlsLimitation_when_Services_is_missing_should_succeed() { //Given AccessPointAdapter accessPointAdapter = provideAPForCheckLimitationForIED(); accessPointAdapter.getCurrentElem().setServices(null); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java index 7ce9234c4..ada6a9645 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java @@ -5,10 +5,10 @@ package org.lfenergy.compas.sct.commons.scl.ied; import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.SclReportItem; -import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclHelper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; @@ -37,11 +37,14 @@ void getName_should_return_name(){ } @Test + @Tag("issue-321") void addTargetIfNotExists_should_add_target(){ // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-ln-adapter/scd_with_ln.xml"); LN0Adapter ln0 = findLn0(scd, "IED_NAME1", "LD_INST11"); + // When ln0.createDataSetIfNotExists("datSet", ControlBlockEnum.GSE); + // When ControlBlockAdapter controlBlockAdapter = ln0.createControlBlockIfNotExists("cbName", "cbId", "datSet", ControlBlockEnum.GSE); LNAdapter targetLn = findLn(scd, "IED_NAME2", "LD_INST21", "ANCR", "1", "prefix"); // When @@ -60,12 +63,15 @@ void addTargetIfNotExists_should_add_target(){ } @Test + @Tag("issue-321") void configureNetwork_should_add_GSE_element() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-ln-adapter/scd_with_ln.xml"); TConnectedAP connectedAP = SclHelper.addConnectedAp(scd, "SUB_NETWORK_NAME", "AP_NAME", "IED_NAME1"); LN0Adapter ln0 = findLn0(scd, "IED_NAME1", "LD_INST11"); + // When ln0.createDataSetIfNotExists("datSet", ControlBlockEnum.GSE); + // When ControlBlockAdapter controlBlockAdapter = ln0.createControlBlockIfNotExists("cbName", "cbId", "datSet", ControlBlockEnum.GSE); // When Optional sclReportItem = controlBlockAdapter.configureNetwork(10L, "00-01-02-04-05", 11, (byte) 12, SclConstructorHelper.newDurationInMilliSec(3), @@ -89,12 +95,15 @@ void configureNetwork_should_add_GSE_element() { } @Test + @Tag("issue-321") void configureNetwork_should_add_SMV_element() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-ln-adapter/scd_with_ln.xml"); TConnectedAP connectedAP = SclHelper.addConnectedAp(scd, "SUB_NETWORK_NAME", "AP_NAME", "IED_NAME1"); LN0Adapter ln0 = findLn0(scd, "IED_NAME1", "LD_INST11"); + // When ln0.createDataSetIfNotExists("datSet", ControlBlockEnum.SAMPLED_VALUE); + // When ControlBlockAdapter controlBlockAdapter = ln0.createControlBlockIfNotExists("cbName", "cbId", "datSet", ControlBlockEnum.SAMPLED_VALUE); // When Optional sclReportItem = controlBlockAdapter.configureNetwork(10L, "00-01-02-04-05", 11, (byte) 12, null, null); @@ -113,12 +122,15 @@ void configureNetwork_should_add_SMV_element() { } @Test + @Tag("issue-321") void configureNetwork_when_connectApNotFound_should_return_sclReportItem() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-ln-adapter/scd_with_ln.xml"); SclHelper.addConnectedAp(scd, "SUB_NETWORK_NAME", "AP_NAME", "IED_NAME2"); // ConnectedAp for IED_NAME2 instead of IED_NAME1 LN0Adapter ln0 = findLn0(scd, "IED_NAME1", "LD_INST11"); + // When ln0.createDataSetIfNotExists("datSet", ControlBlockEnum.SAMPLED_VALUE); + // When ControlBlockAdapter controlBlockAdapter = ln0.createControlBlockIfNotExists("cbName", "cbId", "datSet", ControlBlockEnum.SAMPLED_VALUE); // When Optional sclReportItem = controlBlockAdapter.configureNetwork(10L, "00-01-02-04-05", 11, (byte) 12, null, null); @@ -126,5 +138,4 @@ void configureNetwork_when_connectApNotFound_should_return_sclReportItem() { assertThat(sclReportItem).isPresent(); } - } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java index ae38fdb9f..001ed76c7 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.ied; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.DaTypeName; @@ -12,124 +13,152 @@ import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.AssertionsForClassTypes.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; class DAITrackerTest { @Test + // Test should be modified to reflect each test case and remove no concerned test and assertions. + @Tag("issue-321") void testInit(){ + // Given LN0Adapter ln0Adapter = new LN0Adapter(null,new LN0()); DoTypeName doTypeName = new DoTypeName(); DaTypeName daTypeName = new DaTypeName(); DAITracker daiTracker = new DAITracker(ln0Adapter, doTypeName, daTypeName); - assertEquals(-2, daiTracker.getIndexDoType()); - assertEquals(-2, daiTracker.getIndexDaType()); - assertNull(daiTracker.getBdaiOrDaiAdapter()); - assertNull(daiTracker.getDoiOrSdoiAdapter()); - - assertNotNull(daiTracker.getLnAdapter()); - assertNotNull(daiTracker.getDaTypeName()); - assertNotNull(daiTracker.getDoTypeName()); - - assertThrows( - NullPointerException.class, - () -> new DAITracker(null, doTypeName, daTypeName) - ); - - assertThrows( - NullPointerException.class, - () -> new DAITracker(ln0Adapter,null, daTypeName) - ); - assertThrows( - NullPointerException.class, - () -> new DAITracker(ln0Adapter, doTypeName,null) - ); + assertThat(daiTracker.getIndexDoType()).isEqualTo(-2); + assertThat(daiTracker.getIndexDaType()).isEqualTo(-2); + assertThat(daiTracker.getBdaiOrDaiAdapter()).isNull(); + assertThat(daiTracker.getDoiOrSdoiAdapter()).isNull(); + + assertThat(daiTracker.getLnAdapter()).isNotNull(); + assertThat(daiTracker.getDaTypeName()).isNotNull(); + assertThat(daiTracker.getDoTypeName()).isNotNull(); + //When Then + assertThatThrownBy(() -> new DAITracker(null, doTypeName, daTypeName)) + .isInstanceOf(NullPointerException.class); + //When Then + assertThatThrownBy(() -> new DAITracker(ln0Adapter,null, daTypeName)) + .isInstanceOf(NullPointerException.class); + //When Then + assertThatThrownBy(() -> new DAITracker(ln0Adapter, doTypeName,null)) + .isInstanceOf(NullPointerException.class); } @Test - void testSearch() throws Exception { + @Tag("issue-321") + void testSearch() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get()); + + // Given AbstractLNAdapter lnAdapter = AbstractLNAdapter.builder() .withLDeviceAdapter(lDeviceAdapter) .withLnClass(TLLN0Enum.LLN_0.value()) .build(); - DoTypeName doTypeName = new DoTypeName("Do.sdo1.d"); DaTypeName daTypeName = new DaTypeName("antRef.bda1.bda2.bda3"); - DAITracker daiTracker = new DAITracker(lnAdapter,doTypeName,daTypeName); + // When DAITracker.MatchResult matchResult = daiTracker.search(); - assertEquals(DAITracker.MatchResult.FULL_MATCH,matchResult); + // Then + assertThat(matchResult).isEqualTo(DAITracker.MatchResult.FULL_MATCH); + // When Then lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").isPresent() ? iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get() : null); + + // Given lnAdapter = AbstractLNAdapter.builder() .withLDeviceAdapter(lDeviceAdapter) .withLnClass(TLLN0Enum.LLN_0.value()) .build(); - daiTracker = new DAITracker(lnAdapter,doTypeName,daTypeName); + // When matchResult = daiTracker.search(); - assertEquals(DAITracker.MatchResult.FAILED,matchResult); + // Then + assertThat(matchResult).isEqualTo(DAITracker.MatchResult.FAILED); + // Given lnAdapter = AbstractLNAdapter.builder() .withLDeviceAdapter(lDeviceAdapter) .withLnClass("ANCR") .withLnInst("1") .build(); - doTypeName = new DoTypeName("StrVal"); daiTracker = new DAITracker(lnAdapter,doTypeName,daTypeName); + // When matchResult = daiTracker.search(); - assertEquals(DAITracker.MatchResult.PARTIAL_MATCH,matchResult); + // Then + assertThat(matchResult).isEqualTo(DAITracker.MatchResult.PARTIAL_MATCH); + // When Then lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LD_INS3").isPresent() ? iAdapter.findLDeviceAdapterByLdInst("LD_INS3").get() : null); + + // Given lnAdapter = AbstractLNAdapter.builder() .withLDeviceAdapter(lDeviceAdapter) .withLnClass(TLLN0Enum.LLN_0.value()) .build(); - doTypeName = new DoTypeName("Do.sdo1.d"); daiTracker = new DAITracker(lnAdapter,doTypeName,daTypeName); + // When matchResult = daiTracker.search(); - assertEquals(DAITracker.MatchResult.PARTIAL_MATCH,matchResult); + // Then + assertThat(matchResult).isEqualTo(DAITracker.MatchResult.PARTIAL_MATCH); + // Given doTypeName = new DoTypeName("Do"); daTypeName = new DaTypeName("da3"); daiTracker = new DAITracker(lnAdapter,doTypeName,daTypeName); + // When matchResult = daiTracker.search(); - assertEquals(DAITracker.MatchResult.PARTIAL_MATCH,matchResult); - - + // Then + assertThat(matchResult).isEqualTo(DAITracker.MatchResult.PARTIAL_MATCH); + // Given doTypeName = new DoTypeName("Do"); daTypeName = new DaTypeName("da2"); daiTracker = new DAITracker(lnAdapter,doTypeName,daTypeName); + // When matchResult = daiTracker.search(); - assertEquals(DAITracker.MatchResult.FULL_MATCH,matchResult); + // Then + assertThat(matchResult).isEqualTo(DAITracker.MatchResult.FULL_MATCH); } @Test - void testMatchResult(){ + @Tag("issue-321") + // Useless test + void testMatchResult() { + // Given DAITracker.MatchResult matchResult = DAITracker.MatchResult.FAILED; - assertEquals("FAILED",matchResult.toString()); + // Then + assertThat(matchResult).hasToString("FAILED"); + // Given matchResult = DAITracker.MatchResult.fromValue("FULL_MATCH"); - assertEquals(DAITracker.MatchResult.FULL_MATCH, matchResult); - - assertNull(DAITracker.MatchResult.fromValue("DUMMY")); + // Then + assertThat(matchResult).isEqualTo(DAITracker.MatchResult.FULL_MATCH); + assertThat(DAITracker.MatchResult.fromValue("DUMMY")).isNull(); } @Test - void testValidateBoundedDAI() throws Exception { - + @Tag("issue-321") + void testValidateBoundedDAI() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/scd_with_dai_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LDSUIED").isPresent() ? iAdapter.findLDeviceAdapterByLdInst("LDSUIED").get() : null); + // Given AbstractLNAdapter lnAdapter = AbstractLNAdapter.builder() .withLDeviceAdapter(lDeviceAdapter) .withLnClass(TLLN0Enum.LLN_0.value()) @@ -139,38 +168,57 @@ void testValidateBoundedDAI() throws Exception { DaTypeName daTypeName = new DaTypeName("setMag.f"); DAITracker daiTracker = new DAITracker(lnAdapter,doTypeName,daTypeName); - assertDoesNotThrow(daiTracker::validateBoundedDAI); + // When Then + assertThatCode(daiTracker::validateBoundedDAI).doesNotThrowAnyException(); doTypeName.setCdc(TPredefinedCDCEnum.ING); - assertThrows(ScdException.class, daiTracker::validateBoundedDAI); + // When Then + assertThatThrownBy(daiTracker::validateBoundedDAI) + .isInstanceOf(ScdException.class); daTypeName.addDaiValue(0L,"80.78"); - assertDoesNotThrow(daiTracker::validateBoundedDAI); + // When Then + assertThatCode(daiTracker::validateBoundedDAI).doesNotThrowAnyException(); daTypeName.addDaiValue(0L,"45.9"); - assertThrows(ScdException.class, daiTracker::validateBoundedDAI); + // When Then + assertThatThrownBy(daiTracker::validateBoundedDAI) + .isInstanceOf(ScdException.class); daTypeName.addDaiValue(0L,"1000"); - assertThrows(ScdException.class, daiTracker::validateBoundedDAI); + // When Then + assertThatThrownBy( daiTracker::validateBoundedDAI) + .isInstanceOf(ScdException.class); } @Test + @Tag("issue-321") void testGetDaiNumericValue() { + // Given DaTypeName daTypeName = new DaTypeName("setMag.f"); DoTypeName doTypeName = new DoTypeName("StrVal1"); DAITracker daiTracker = new DAITracker(new LN0Adapter(null, new LN0()),doTypeName,daTypeName); - double val = assertDoesNotThrow( ()->daiTracker.getDaiNumericValue(daTypeName,13.0)); - assertEquals(13.0,val); + // When Then + double val = assertDoesNotThrow( ()-> daiTracker.getDaiNumericValue(daTypeName,13.0)); + assertThat(val).isEqualTo(13.0); + // Given daTypeName.addDaiValue(0L,"45.9"); - assertThrows(NumberFormatException.class, ()->daiTracker.getDaiNumericValue(daTypeName,13.0)); + // When Then + assertThatThrownBy(()-> daiTracker.getDaiNumericValue(daTypeName,13.0)) + .isInstanceOf(NumberFormatException.class); + // Given daTypeName.setBType(TPredefinedBasicTypeEnum.DBPOS); - assertThrows(NumberFormatException.class, ()->daiTracker.getDaiNumericValue(daTypeName,13.0)); + // When Then + assertThatThrownBy(()-> daiTracker.getDaiNumericValue(daTypeName,13.0)) + .isInstanceOf(NumberFormatException.class); + // Given daTypeName.setBType(TPredefinedBasicTypeEnum.FLOAT_32); - assertDoesNotThrow(()->daiTracker.getDaiNumericValue(daTypeName,13.0)); + // When Then + assertThatCode(()-> daiTracker.getDaiNumericValue(daTypeName,13.0)).doesNotThrowAnyException(); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java index 0ba358149..43df3a0d4 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java @@ -6,8 +6,8 @@ import org.apache.commons.lang3.tuple.Pair; import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.DaTypeName; import org.lfenergy.compas.sct.commons.dto.DoTypeName; @@ -16,7 +16,6 @@ import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.CommonConstants; -import org.mockito.junit.jupiter.MockitoExtension; import java.util.*; @@ -25,32 +24,13 @@ import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newVal; -@ExtendWith(MockitoExtension.class) class DOIAdapterTest { - private static Optional getDaiValOfDoi(DOIAdapter doiAdapter, String daName) { - return doiAdapter.getDataAdapterByName(daName).getCurrentElem().getVal().stream().findFirst(); - } - - private static TExtRef givenExtRef(int num, boolean withCbName) { - TExtRef extRef1 = new TExtRef(); - extRef1.setIedName("IED_NAME_" + num); - extRef1.setDesc("ExtRef_desc_" + num); - extRef1.setLdInst("LD_INST_" + num); - extRef1.setSrcPrefix("SRC_PREFIX_" + num); - extRef1.setSrcLNInst("SRC_LN_INST_" + num); - extRef1.getLnClass().add("ANCR"); - extRef1.setLnInst(Integer.toString(num)); - extRef1.setPrefix("PREFIX_" + num); - extRef1.setDoName("DO_NAME_" + num); - if (withCbName) { - extRef1.setSrcCBName("CB_NAME_" + num); - } - return extRef1; - } - @Test + // Test should be modified to reflect each test case and remove no concerned test and assertions. + @Tag("issue-321") void testConstructor() { + // Given LN0 ln0 = new LN0(); LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); @@ -58,54 +38,65 @@ void testConstructor() { tdoi.setName("Do"); ln0.getDOI().add(tdoi); // test amChildElement + // When Then DOIAdapter doiAdapter = assertDoesNotThrow(() -> new DOIAdapter(ln0Adapter, tdoi)); // test tree map + // Given TSDI tsdi = new TSDI(); tsdi.setName("sdo2"); tdoi.getSDIOrDAI().add(tsdi); + // When Then assertThatCode(() -> doiAdapter.getStructuredDataAdapterByName("sdo2")).doesNotThrowAnyException(); + // When Then assertThatThrownBy(() -> doiAdapter.getStructuredDataAdapterByName("sdo3")).isInstanceOf(ScdException.class); + // Given TDAI tdai = new TDAI(); tdai.setName("angRef"); tdoi.getSDIOrDAI().add(tdai); + // When Then assertThatCode(() -> doiAdapter.getDataAdapterByName("angRef")).doesNotThrowAnyException(); + // When Then assertThatThrownBy(() -> doiAdapter.getStructuredDataAdapterByName("bda")).isInstanceOf(ScdException.class); + // When Then assertThatThrownBy(() -> doiAdapter.getDataAdapterByName("bda")).isInstanceOf(ScdException.class); } @Test + @Tag("issue-321") void testInnerDAIAdapter() { // Given - final String TOTO = "toto"; - + String doName = "Do"; + String daName = "angRef"; // When - DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "angRef"); - + DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter(doName, daName); // Then assertThat(daiAdapter.getCurrentElem().isSetValImport()).isFalse(); + // Given daiAdapter.setValImport(true); + // When Then assertThat(daiAdapter.getCurrentElem().isSetValImport()).isTrue(); } @Test + @Tag("issue-321") void testInnerDAIAdapterTestUpdateWithMapAsArg() { // Given final String TOTO = "toto"; DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); daiAdapter.setValImport(true); - // update DAI val final Map vals = Collections.singletonMap(0L, TOTO); + // update DAI val + // When Then assertThatCode(() -> daiAdapter.update(vals)).doesNotThrowAnyException(); assertThat(daiAdapter.getCurrentElem().getVal()).isNotEmpty(); TVal tVal = daiAdapter.getCurrentElem().getVal().get(0); assertThat(tVal.isSetSGroup()).isFalse(); - + // Given final Map vals2 = new HashMap<>(); vals2.put(1L, TOTO); vals2.put(0L, TOTO); - // When Then assertThatCode(() -> daiAdapter.update(vals2)).doesNotThrowAnyException(); assertThat(daiAdapter.getCurrentElem().getVal()).isNotEmpty(); @@ -114,22 +105,28 @@ void testInnerDAIAdapterTestUpdateWithMapAsArg() { } @Test + @Tag("issue-321") void testInnerDAIAdapterTestUpdate() { // Given final String TOTO = "toto"; + // When DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); daiAdapter.setValImport(false); + // When Then assertThatThrownBy(() -> daiAdapter.update(0L, TOTO)).isInstanceOf(ScdException.class); + // Given daiAdapter.setValImport(true); + // When Then assertThatCode(() -> daiAdapter.update(0L, TOTO)).doesNotThrowAnyException(); - + // Given final Map vals2 = new HashMap<>(); vals2.put(1L, TOTO); vals2.put(2L, TOTO); - // When Then assertThatCode(() -> daiAdapter.update(vals2)).doesNotThrowAnyException(); + // Given vals2.put(2L, TOTO + "1"); + // When Then assertThatCode(() -> daiAdapter.update(vals2)).doesNotThrowAnyException(); } @@ -142,7 +139,7 @@ void DAIAdapter_update_when_valImport_is_set_to_true_should_update_val() { daiAdapter.getCurrentElem().getVal().add(newVal("oldValue")); // When daiAdapter.update(0L, newValue); - + // Then assertThat(daiAdapter.getCurrentElem().getVal()).hasSize(1) .first().extracting(TVal::getValue, TVal::isSetSGroup) .containsExactly("newValue", false); @@ -157,7 +154,7 @@ void DAIAdapter_update_when_valImport_is_not_set_should_update_val() { daiAdapter.getCurrentElem().getVal().add(newVal("oldValue")); // When daiAdapter.update(0L, newValue); - + // Then assertThat(daiAdapter.getCurrentElem().getVal()).hasSize(1) .first().extracting(TVal::getValue, TVal::isSetSGroup) .containsExactly("newValue", false); @@ -175,7 +172,7 @@ void DAIAdapter_update_when_sGroup_is_set_should_update_single_val() { daiAdapter.getCurrentElem().getVal().add(newVal("oldValue2", sGroup2)); // When daiAdapter.update(sGroup2, newValue); - + // Then assertThat(daiAdapter.getCurrentElem().getVal()).extracting(TVal::getValue, TVal::getSGroup) .containsExactly( Tuple.tuple("oldValue1", sGroup1), @@ -201,32 +198,39 @@ void DAIAdapter_update_when_valImport_is_set_to_false_but_da_is_Mod_StVal_should daiAdapter.setValImport(false); // When daiAdapter.update(0L, newValue); - + // Then assertThat(daiAdapter.getCurrentElem().getVal()).hasSize(1) .first().extracting(TVal::getValue, TVal::isSetSGroup) .containsExactly("newValue", false); } @Test + @Tag("issue-321") void testFindDeepestMatch() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get()); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); + // When Then DOIAdapter doiAdapter = assertDoesNotThrow(() -> ln0Adapter.getDOIAdapterByName("Do")); + // Given DoTypeName doTypeName = new DoTypeName("Do.sdo1.d"); DaTypeName daTypeName = new DaTypeName("antRef.bda1.bda2.bda3"); Pair pair = doiAdapter.findDeepestMatch( doTypeName.getStructNames(), 0, false ); + // When SDIAdapter lastSDOIAdapter = (SDIAdapter) pair.getLeft(); + // Then assertThat(pair.getRight()).isEqualTo(1); assertThat(lastSDOIAdapter) .isNotNull() .isInstanceOf(SDIAdapter.class); - + // When IDataParentAdapter firstDAIAdapter = lastSDOIAdapter.getStructuredDataAdapterByName(daTypeName.getName()); // When @@ -253,23 +257,22 @@ private DOIAdapter.DAIAdapter initInnerDAIAdapter(String doName, String daName) } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { // Given DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); + assertThat(daiAdapter.getCurrentElem().getPrivate()).isEmpty(); + TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertThat(daiAdapter.getCurrentElem().getPrivate()).isEmpty(); - // When daiAdapter.addPrivate(tPrivate); - // Then - assertThat(daiAdapter.getCurrentElem().getPrivate()).hasSize(1); + assertThat(daiAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test - void elementXPath_doi() { + void DOI_elementXPath_should_return_expected_xpath_value() { // Given TDOI tdoi = new TDOI(); tdoi.setName("doName"); @@ -284,7 +287,7 @@ void elementXPath_doi() { } @Test - void elementXPath_dai() { + void DAI_elementXPath_should_return_expected_xpath_value() { // Given DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); // When @@ -294,7 +297,7 @@ void elementXPath_dai() { } @Test - void findDataAdapterByName_should_return_DAIAdapter_when_DA_name_exist() { + void findDataAdapterByName_when_DA_name_exist_should_return_DAIAdapter() { // Given DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); DOIAdapter doiAdapter = daiAdapter.getParentAdapter(); @@ -310,7 +313,7 @@ void findDataAdapterByName_should_return_DAIAdapter_when_DA_name_exist() { } @Test - void findDataAdapterByName_should_return_DAIAdapter_when_DA_name_dont_exist() { + void findDataAdapterByName_when_DA_name_not_exist_should_return_Empty() { // Given DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); DOIAdapter doiAdapter = daiAdapter.getParentAdapter(); @@ -323,7 +326,7 @@ void findDataAdapterByName_should_return_DAIAdapter_when_DA_name_dont_exist() { } @Test - void updateDaiFromExtRef_should_update_setSrcXX_values_when_ExtRef_desc_suffix_ends_with_1() { + void updateDaiFromExtRef_when_ExtRef_desc_suffix_ends_with_1_should_update_setSrcXX_values() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); TDAI daiSrcRef = new TDAI(); @@ -349,7 +352,7 @@ void updateDaiFromExtRef_should_update_setSrcXX_values_when_ExtRef_desc_suffix_e } @Test - void updateDaiFromExtRef_should_update_setSrcRef_value_but_not_setSrcCB_when_ExtRef_dont_contains_CB() { + void updateDaiFromExtRef_when_ExtRef_not_contains_CB_should_update_setSrcRef_value_but_not_setSrcCB() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); TDAI daiSrcRef = new TDAI(); @@ -370,7 +373,7 @@ void updateDaiFromExtRef_should_update_setSrcRef_value_but_not_setSrcCB_when_Ext } @Test - void updateDaiFromExtRef_should_update_setSrcXX_and_setTstXX_values_when_ExtRef_desc_suffix_ends_with_1_and_3() { + void updateDaiFromExtRef_when_ExtRef_desc_suffix_ends_with_1_and_3_should_update_setSrcXX_and_setTstXX_values() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); TDAI daiSrcRef = new TDAI(); @@ -409,7 +412,7 @@ void updateDaiFromExtRef_should_update_setSrcXX_and_setTstXX_values_when_ExtRef_ } @Test - void updateDaiFromExtRef_should_update_only_setSrcRef_and_setTstRef_values_when_ExtRef_desc_suffix_ends_with_1_and_3_without_CB() { + void updateDaiFromExtRef_when_ExtRef_desc_suffix_ends_with_1_and_3_without_CB_should_update_only_setSrcRef_and_setTstRef_values() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); TDAI daiSrcRef = new TDAI(); @@ -446,7 +449,7 @@ void updateDaiFromExtRef_should_update_only_setSrcRef_and_setTstRef_values_when_ } @Test - void updateDaiFromExtRef_should_return_warning_report_when_none_ExtRef_endin_with_1() { + void updateDaiFromExtRef_when_none_ExtRef_endin_with_1_should_return_warning_report() { // Given DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); DOIAdapter doiAdapter = daiAdapter.getParentAdapter(); @@ -469,7 +472,7 @@ void updateDaiFromExtRef_should_return_warning_report_when_none_ExtRef_endin_wit } @Test - void updateDaiFromExtRef_should_create_DAI_when_no_DAI_name_setSrcRef() { + void updateDaiFromExtRef_when_no_DAI_name_setSrcRef_should_create_DAI() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); @@ -488,7 +491,7 @@ void updateDaiFromExtRef_should_create_DAI_when_no_DAI_name_setSrcRef() { } @Test - void updateDaiFromExtRef_should_return_filled_ReportItem_when_no_ExtRef_in_LNode() { + void updateDaiFromExtRef_when_no_ExtRef_in_LNode_should_return_filled_ReportItem() { // Given DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); DOIAdapter doiAdapter = daiAdapter.getParentAdapter(); @@ -505,7 +508,7 @@ void updateDaiFromExtRef_should_return_filled_ReportItem_when_no_ExtRef_in_LNode } @Test - void updateDaiFromExtRef_should_compose_correct_name_when_optional_ExtRef_attributes_are_missing() { + void updateDaiFromExtRef_when_optional_ExtRef_attributes_are_missing_should_compose_correct_name() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); TDAI daiSrcRef = new TDAI(); @@ -552,7 +555,7 @@ void updateDaiFromExtRef_should_compose_correct_name_when_optional_ExtRef_attrib } @Test - void updateDaiFromExtRef_should_throw_exception_when_ExtRef_desc_dont_end_with__1() { + void updateDaiFromExtRef_when_ExtRef_desc_not_end_with_1_should_throw_exception() { // Given DOIAdapter.DAIAdapter daiAdapter = initInnerDAIAdapter("Do", "da"); DOIAdapter doiAdapter = daiAdapter.getParentAdapter(); @@ -573,7 +576,7 @@ void updateDaiFromExtRef_should_throw_exception_when_ExtRef_desc_dont_end_with__ } @Test - void updateDai_should_create_and_update_value_when_dai_not_present_in_do_and_is_updatable() { + void updateDai_when_dai_not_present_in_do_and_is_updatable_should_create_and_update_value() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); // When @@ -586,7 +589,7 @@ void updateDai_should_create_and_update_value_when_dai_not_present_in_do_and_is_ } @Test - void updateDai_should_update_value_when_dai_present_in_do_and_is_updatable() { + void updateDai_when_dai_present_in_do_and_is_updatable_should_update_value() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); TVal tVal = new TVal(); @@ -608,7 +611,7 @@ void updateDai_should_update_value_when_dai_present_in_do_and_is_updatable() { } @Test - void updateDai_should_not_update_value_and_return_warning_message_when_dai_is_not_updatable() { + void updateDai_when_dai_is_not_updatable_should_not_update_value_and_return_warning_message() { // Given DOIAdapter doiAdapter = createDOIAdapterInScl(); TVal tVal = new TVal(); @@ -631,6 +634,26 @@ void updateDai_should_not_update_value_and_return_warning_message_when_dai_is_no .isEqualTo("old value"); } + private static Optional getDaiValOfDoi(DOIAdapter doiAdapter, String daName) { + return doiAdapter.getDataAdapterByName(daName).getCurrentElem().getVal().stream().findFirst(); + } + + private static TExtRef givenExtRef(int num, boolean withCbName) { + TExtRef extRef1 = new TExtRef(); + extRef1.setIedName("IED_NAME_" + num); + extRef1.setDesc("ExtRef_desc_" + num); + extRef1.setLdInst("LD_INST_" + num); + extRef1.setSrcPrefix("SRC_PREFIX_" + num); + extRef1.setSrcLNInst("SRC_LN_INST_" + num); + extRef1.getLnClass().add("ANCR"); + extRef1.setLnInst(Integer.toString(num)); + extRef1.setPrefix("PREFIX_" + num); + extRef1.setDoName("DO_NAME_" + num); + if (withCbName) { + extRef1.setSrcCBName("CB_NAME_" + num); + } + return extRef1; + } private DOIAdapter createDOIAdapterInScl() { TDOI tdoi = new TDOI(); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java index 30c159b6e..654ac3285 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java @@ -14,16 +14,19 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class DataSetAdapterTest { @Test - void amChildElementRef_should_succeed() { + void amChildElementRef__whenCalledWithExistingRelationBetweenLNAndDatSet_shouldReturnTrue() { //Given + LN0Adapter ln0Adapter = mock(LN0Adapter.class); LN0 ln0 = new LN0(); TDataSet dataSet = new TDataSet(); ln0.getDataSet().add(dataSet); - LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); + when(ln0Adapter.getCurrentElem()).thenReturn(ln0); DataSetAdapter dataSetAdapter = new DataSetAdapter(ln0Adapter, dataSet); //When boolean result = dataSetAdapter.amChildElementRef(); @@ -32,14 +35,14 @@ void amChildElementRef_should_succeed() { } @Test - void elementXPath_should_return_relative_xpath() { + void elementXPath_should_return_expected_xpath_value() { //Given TDataSet dataSet = new TDataSet(); dataSet.setName("dataSetName"); DataSetAdapter dataSetAdapter = new DataSetAdapter(null, dataSet); //When String elementXPath = dataSetAdapter.elementXPath(); - //Then, + //Then assertThat(elementXPath).isEqualTo("DataSet[@name=\"dataSetName\"]"); } @@ -87,8 +90,8 @@ void createFCDAIfNotExists_should_create_new_FCDA() { void createFCDAIfNotExists_when_FCDA_already_exists_should_not_create_FCDA() { //Given TDataSet dataSet = new TDataSet(); - TFCDA existingFcda = createFCDA(); - dataSet.getFCDA().add(existingFcda); + TFCDA existingFCDA = createFCDA(); + dataSet.getFCDA().add(existingFCDA); DataSetAdapter dataSetAdapter = new DataSetAdapter(null, dataSet); //When TFCDA result = dataSetAdapter.createFCDAIfNotExists("LDINST", null, "LLN0", null, "DoName", "daName", TFCEnum.ST); @@ -96,18 +99,18 @@ void createFCDAIfNotExists_when_FCDA_already_exists_should_not_create_FCDA() { assertThat(dataSet.getFCDA()).hasSize(1) .first() .isSameAs(result) - .isSameAs(existingFcda); + .isSameAs(existingFCDA); } private static TFCDA createFCDA() { - TFCDA existingFcda = new TFCDA(); - existingFcda.setLdInst("LDINST"); - existingFcda.setPrefix(""); - existingFcda.getLnClass().add("LLN0"); - existingFcda.setLnInst(""); - existingFcda.setDoName("DoName"); - existingFcda.setDaName("daName"); - existingFcda.setFc(TFCEnum.ST); - return existingFcda; + TFCDA existingFCDA = new TFCDA(); + existingFCDA.setLdInst("LDINST"); + existingFCDA.setPrefix(""); + existingFCDA.getLnClass().add("LLN0"); + existingFCDA.setLnInst(""); + existingFCDA.setDoName("DoName"); + existingFCDA.setDaName("daName"); + existingFCDA.setFc(TFCEnum.ST); + return existingFCDA; } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java index 4d24f57ef..5b7bcea31 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.ied; +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; @@ -18,7 +19,6 @@ import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.MonitoringLnClassEnum; -import org.mockito.Mockito; import java.util.HashMap; import java.util.List; @@ -26,11 +26,11 @@ import java.util.Optional; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class IEDAdapterTest { @@ -38,26 +38,55 @@ class IEDAdapterTest { @Test - void testAmChildElementRef() throws ScdException { + // Test should be modified to reflect each test case and remove no concerned test and assertions. + @Tag("issue-321") + void testAmChildElementRef() { + // Given SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); TIED tied = new TIED(); tied.setName(DTO.HOLDER_IED_NAME); - tied.setServices(new TServices()); sclRootAdapter.getCurrentElem().getIED().add(tied); IEDAdapter iAdapter = sclRootAdapter.getIEDAdapterByName(DTO.HOLDER_IED_NAME); - assertTrue(iAdapter.amChildElementRef()); - assertNotNull(iAdapter.getServices()); - assertEquals(DTO.HOLDER_IED_NAME,iAdapter.getName()); - - IEDAdapter fAdapter = new IEDAdapter(sclRootAdapter); + // When Then + assertThat(iAdapter.amChildElementRef()).isTrue(); + assertThat(iAdapter.getServices()).isNotNull(); + assertThat(iAdapter.getName()).isEqualTo(DTO.HOLDER_IED_NAME); + // Given + IEDAdapter iedAdapter = new IEDAdapter(sclRootAdapter); TIED tied1 = new TIED(); - assertThrows(IllegalArgumentException.class, - () ->fAdapter.setCurrentElem(tied1)); + // When Then + assertThatThrownBy(() -> iedAdapter.setCurrentElem(tied1)) + .isInstanceOf(IllegalArgumentException.class); + // When Then: test other class here + assertThatThrownBy(() -> sclRootAdapter.getIEDAdapterByName(DTO.HOLDER_IED_NAME + "1")) + .isInstanceOf(ScdException.class); + } + + @Test + void constructor_whenCalledWithNoRelationBetweenSCLAndIED_shouldThrowException() { + //Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + when(sclRootAdapter.getCurrentElem()).thenReturn(new SCL()); + TIED tied = new TIED(); + //When Then - assertThrows(ScdException.class, - () -> sclRootAdapter.getIEDAdapterByName(DTO.HOLDER_IED_NAME + "1")); + assertThatCode(() -> new IEDAdapter(sclRootAdapter, tied)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); + } + @Test + void constructor_whenCalledWithExistingRelationBetweenSCLAndIED_shouldNotThrowException() { + //Given + SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); + SCL scl = new SCL(); + TIED tied = new TIED(); + scl.getIED().add(tied); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + //When Then + assertThatCode(() -> new IEDAdapter(sclRootAdapter, tied)) + .doesNotThrowAnyException(); } @Test @@ -121,88 +150,100 @@ void getLDeviceAdapterByLdInst_when_not_found_should_throw_exception() { } @Test - void testUpdateLDeviceNodesType() { - + @Tag("issue-321") + void updateLDeviceNodesType_should_not_throw_exception() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile(SCD_IED_U_TEST); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow( () -> sclRootAdapter.getIEDAdapterByName(DTO.HOLDER_IED_NAME)); - - assertTrue(iAdapter.streamLDeviceAdapters().count() >= 2); + assertThat(iAdapter.streamLDeviceAdapters()).hasSizeGreaterThanOrEqualTo(2); Map pairOldNewId = new HashMap<>(); pairOldNewId.put("LNO1", DTO.HOLDER_IED_NAME + "_LNO1"); pairOldNewId.put("LNO2", DTO.HOLDER_IED_NAME + "_LNO2"); - assertDoesNotThrow( () ->iAdapter.updateLDeviceNodesType(pairOldNewId)); - + // When Then + assertThatCode(() -> iAdapter.updateLDeviceNodesType(pairOldNewId)).doesNotThrowAnyException(); LDeviceAdapter lDeviceAdapter = iAdapter.streamLDeviceAdapters().findFirst().get(); - assertEquals(DTO.HOLDER_IED_NAME + "_LNO1",lDeviceAdapter.getLN0Adapter().getLnType()); + assertThat(lDeviceAdapter.getLN0Adapter().getLnType()).isEqualTo(DTO.HOLDER_IED_NAME + "_LNO1"); } @Test + @Tag("issue-321") void testGetExtRefBinders() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); + // Given ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); signalInfo.setPDO("Do.sdo1"); signalInfo.setPDA("da.bda1.bda2.bda3"); - assertDoesNotThrow(() ->iAdapter.getExtRefBinders(signalInfo)); - + // When Then + assertThatCode(() -> iAdapter.getExtRefBinders(signalInfo)).doesNotThrowAnyException(); + // Given signalInfo.setPDO("Do.sdo1.errorSdo"); - assertThrows(ScdException.class, () ->iAdapter.getExtRefBinders(signalInfo)); + // When Then + assertThatThrownBy(() -> iAdapter.getExtRefBinders(signalInfo)) + .isInstanceOf(ScdException.class); } @Test - void TestIsSettingConfig() { + @Tag("issue-321") + void testIsSettingConfig() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); - - assertTrue(iAdapter.isSettingConfig("LD_INS1")); - - assertThrows(IllegalArgumentException.class,() -> iAdapter.isSettingConfig("UnknownLD")); + // When Then + assertThat(iAdapter.isSettingConfig("LD_INS1")).isTrue(); + // When Then + assertThatThrownBy(() -> iAdapter.isSettingConfig("UnknownLD")) + .isInstanceOf(IllegalArgumentException.class); } @Test + @Tag("issue-321") void testMatches() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); - + // Given ObjectReference objectReference = new ObjectReference("IED_NAMELD_INS3/LLN0.Do.da2"); objectReference.init(); - assertTrue(iAdapter.matches(objectReference)); - + // When Then + assertThat(iAdapter.matches(objectReference)).isTrue(); + // Given objectReference = new ObjectReference("IED_NAMELD_INS2/ANCR1.dataSet"); objectReference.init(); - assertTrue(iAdapter.matches(objectReference)); + // When Then + assertThat(iAdapter.matches(objectReference)).isTrue(); } @Test - void addPrivate() { - SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); - SCL scl = mock(SCL.class); - Mockito.when(sclRootAdapter.getCurrentElem()).thenReturn(scl); - TIED tied = new TIED(); - Mockito.when(scl.getIED()).thenReturn(List.of(tied)); - IEDAdapter iAdapter = new IEDAdapter(sclRootAdapter, tied); + void addPrivate_with_type_and_source_should_create_Private() { + // Given + IEDAdapter iedAdapter = new IEDAdapter(null, new TIED()); + assertThat(iedAdapter.getCurrentElem().getPrivate()).isEmpty(); + TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(iAdapter.getCurrentElem().getPrivate().isEmpty()); - iAdapter.addPrivate(tPrivate); - assertEquals(1, iAdapter.getCurrentElem().getPrivate().size()); + // When + iedAdapter.addPrivate(tPrivate); + // Then + assertThat(iedAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test - void elementXPath() { + void elementXPath_should_return_expected_xpath_value() { // Given - SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class); - SCL scl = mock(SCL.class); - Mockito.when(sclRootAdapter.getCurrentElem()).thenReturn(scl); TIED tied = new TIED(); tied.setName("iedName"); - Mockito.when(scl.getIED()).thenReturn(List.of(tied)); - IEDAdapter iAdapter = new IEDAdapter(sclRootAdapter, tied); + IEDAdapter iAdapter = new IEDAdapter(null, tied); // When String result = iAdapter.elementXPath(); // Then @@ -317,13 +358,15 @@ void getCompasSystemVersion_should_return_compas_icd_header(){ @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_not_update_ln_when_no_extRef(String testCase, MonitoringLnClassEnum lnClassEnum, String doName) { + @Tag("issue-321") + void manageMonitoringLns_when_no_extRef_should_not_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName) { // Given IEDAdapter iedAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1); // When List sclReportItems = iedAdapter.manageMonitoringLns(); - // Then + // When LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(LD_SUIED); + // Then assertThat(sclReportItems).isEmpty(); assertThat(lDeviceAdapter.getLNAdapters()) .hasSize(1); @@ -332,12 +375,15 @@ void manageMonitoringLns_should_not_update_ln_when_no_extRef(String testCase, Mo @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_not_create_ln_when_no_init_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { + @Tag("issue-321") + void manageMonitoringLns_when_no_init_ln_should_not_create_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { // Given IEDAdapter iedAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1); TExtRef tExtRef = createExtRefExample("CB_Name", tServiceType); + // When LDeviceAdapter lDAdapter = iedAdapter.getLDeviceAdapterByLdInst("LD_ADD"); lDAdapter.getLN0Adapter().getCurrentElem().getInputs().getExtRef().add(tExtRef); + // When LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(LD_SUIED); lDeviceAdapter.getCurrentElem().unsetLN(); // When @@ -351,16 +397,19 @@ void manageMonitoringLns_should_not_create_ln_when_no_init_ln(String testCase, M @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_update_ln_when_one_extRef_and_dai_updatable(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { + @Tag("issue-321") + void manageMonitoringLns_when_one_extRef_and_dai_updatable_should_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { // Given IEDAdapter iedAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1); TExtRef tExtRef = createExtRefExample("CB_Name", tServiceType); + // When LDeviceAdapter lDAdapter = iedAdapter.getLDeviceAdapterByLdInst("LD_ADD"); lDAdapter.getLN0Adapter().getCurrentElem().getInputs().getExtRef().add(tExtRef); // When List sclReportItems = iedAdapter.manageMonitoringLns(); - // Then + // When LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(LD_SUIED); + // Then assertThat(sclReportItems).isEmpty(); assertThat(lDeviceAdapter.getLNAdapters()) .hasSize(1) @@ -374,19 +423,23 @@ void manageMonitoringLns_should_update_ln_when_one_extRef_and_dai_updatable(Stri @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_not_update_ln_when_one_extRef_and_dai_not_updatable(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { + @Tag("issue-321") + void manageMonitoringLns_when_one_extRef_and_dai_not_updatable_should_not_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { // Given SclRootAdapter sclRootAdapter = createIedsInScl(lnClassEnum.value(), doName); sclRootAdapter.getDataTypeTemplateAdapter().getDOTypeAdapterById("REF").get().getDAAdapterByName("setSrcRef") .get().getCurrentElem().setValImport(false); + // When IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(IED_NAME_1); TExtRef tExtRef = createExtRefExample("CB_Name", tServiceType); + // When LDeviceAdapter lDAdapter = iedAdapter.getLDeviceAdapterByLdInst("LD_ADD"); lDAdapter.getLN0Adapter().getCurrentElem().getInputs().getExtRef().add(tExtRef); // When List sclReportItems = iedAdapter.manageMonitoringLns(); - // Then + // When LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(LD_SUIED); + // Then assertThat(sclReportItems).isNotEmpty() .extracting(SclReportItem::message) .containsExactly("The DAI cannot be updated"); @@ -397,17 +450,20 @@ void manageMonitoringLns_should_not_update_ln_when_one_extRef_and_dai_not_updata @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_update_ln_when_2_extRef_and_dai_updatable(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { + @Tag("issue-321") + void manageMonitoringLns_when_2_extRef_and_dai_updatable_should_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { // Given IEDAdapter iedAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1); TExtRef tExtRef1 = createExtRefExample("CB_Name_1", tServiceType); TExtRef tExtRef2 = createExtRefExample("CB_Name_2", tServiceType); + // When LDeviceAdapter lDAdapter = iedAdapter.getLDeviceAdapterByLdInst("LD_ADD"); lDAdapter.getLN0Adapter().getCurrentElem().getInputs().getExtRef().addAll(List.of(tExtRef1, tExtRef2)); // When List sclReportItems = iedAdapter.manageMonitoringLns(); - // Then + // When LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(LD_SUIED); + // Then assertThat(sclReportItems).isEmpty(); assertThat(lDeviceAdapter.getLNAdapters()) .hasSize(2) 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 f6323b99c..b4a3c5aa0 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,8 +4,8 @@ package org.lfenergy.compas.sct.commons.scl.ied; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -13,9 +13,7 @@ import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; 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.mockito.junit.jupiter.MockitoExtension; import org.opentest4j.AssertionFailedError; import java.util.List; @@ -27,22 +25,23 @@ import static org.junit.jupiter.api.Named.named; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; -@ExtendWith(MockitoExtension.class) class InputsAdapterTest { @Test + @Tag("issue-321") void constructor_should_succeed() { // Given TInputs tInputs = new TInputs(); LN0 ln0 = new LN0(); ln0.setInputs(tInputs); + // When LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); // When && Then assertThatNoException().isThrownBy(() -> new InputsAdapter(ln0Adapter, tInputs)); } @Test - void elementXPath_should_succeed() { + void elementXPath_should_return_expected_xpath_value() { // Given TInputs tInputs = new TInputs(); InputsAdapter inputsAdapter = new InputsAdapter(null, tInputs); @@ -111,7 +110,6 @@ void updateAllSourceDataSetsAndControlBlocks_should_succeed() { List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(); // Then assertThat(sclReportItems).isEmpty(); - System.out.println(MarshallerWrapper.marshall(scd)); } @ParameterizedTest @@ -194,7 +192,7 @@ public static Stream provideCreateFCDA() { @ParameterizedTest @MethodSource("provideDoNotCreateFCDA") - void updateAllSourceDataSetsAndControlBlocks_should_not_create_FCDA_when_no_valid_source_Da_found(String extRefDesc) { + void updateAllSourceDataSetsAndControlBlocks_when_no_valid_source_Da_found_should_not_create_FCDA(String extRefDesc) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java index 2868d52a1..b2a775cc4 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java @@ -6,6 +6,7 @@ import org.assertj.core.api.Assertions; 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; @@ -23,10 +24,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.Random; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter.MOD_DO_TYPE_NAME; import static org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter.STVAL_DA_TYPE_NAME; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; @@ -46,28 +48,55 @@ public void init() { } @Test - void testUpdateLDName() { + void updateLDName_when_ldName_pass_33_characters_should_throw_exception() { + // Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get()); lDeviceAdapter.updateLDName(); - assertEquals("IED_NAMELD_INS1",lDeviceAdapter.getLdName()); - iAdapter.setIEDName("VERY_VERY_VERY_VERY_VERY_VERY_LONG_IED_NAME"); - assertThrows(ScdException.class, ()-> lDeviceAdapter.updateLDName()); + assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED_NAMELD_INS1"); + assertThat(lDeviceAdapter.getInst()).isEqualTo("LD_INS1"); + String iedName = new Random().ints(97, 122) + .limit(27) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString(); + iAdapter.setIEDName(iedName); + // When Then + assertThatThrownBy(lDeviceAdapter::updateLDName) + .isInstanceOf(ScdException.class) + .hasMessageContaining("has more than 33 characters"); + } - assertEquals("LD_INS1", lDeviceAdapter.getInst()); + @Test + void updateLDName_when_ldName_less_than_33_characters_should_not_throw_exception() { + // Given + LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get()); + lDeviceAdapter.updateLDName(); + assertThat(lDeviceAdapter.getLdName()).isEqualTo("IED_NAMELD_INS1"); + assertThat(lDeviceAdapter.getInst()).isEqualTo("LD_INS1"); + String iedName = new Random().ints(97, 122) + .limit(26) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString(); + iAdapter.setIEDName(iedName); + // When Then + assertThatCode(lDeviceAdapter::updateLDName).doesNotThrowAnyException(); + assertThat(lDeviceAdapter.getLdName()).isEqualTo(iedName+"LD_INS1"); } @Test + @Tag("issue-321") void testGetLNAdapters() { + // Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get()); - - assertEquals(1,lDeviceAdapter.getLNAdapters().size()); - + assertThat(lDeviceAdapter.getLNAdapters()).hasSize(1); + // When Then assertDoesNotThrow(() -> lDeviceAdapter.getLNAdapter("ANCR","1",null)); - assertThrows(ScdException.class, () -> lDeviceAdapter.getLNAdapter("ANCR","1","pr")); + // When Then + assertThatThrownBy(() -> lDeviceAdapter.getLNAdapter("ANCR","1","pr")) + .isInstanceOf(ScdException.class); } @Test - void findLnAdapter_should_return_adapter(){ + void findLnAdapter_shouldReturnAdapter(){ // Given LDeviceAdapter lDeviceAdapter = iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get(); // When @@ -78,7 +107,7 @@ void findLnAdapter_should_return_adapter(){ } @Test - void getExtRefBinders_shouldReturnExtRefBindingInfo_whenExist() { + void getExtRefBinders_whenExist_shouldReturnExtRefBindingInfo() { //Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get()); ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); @@ -90,7 +119,7 @@ void getExtRefBinders_shouldReturnExtRefBindingInfo_whenExist() { } @Test - void getExtRefBinders_shouldReturnEmptyList_whenpLNNotMatch() { + void getExtRefBinders_when_PLN_NotMatch_shouldReturnEmptyList() { //Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2")); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); @@ -101,7 +130,7 @@ void getExtRefBinders_shouldReturnEmptyList_whenpLNNotMatch() { } @Test - void getExtRefBinders_shouldReturnEmptyList_whenpLNNotSet() { + void getExtRefBinders_when_PLN_NotSet_shouldReturnEmptyList() { //Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2")); ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); @@ -111,47 +140,63 @@ void getExtRefBinders_shouldReturnEmptyList_whenpLNNotSet() { } @Test - void testGetExtRefInfo() { + @Tag("issue-321") + void getExtRefInfo_should_return_expected_list_of_ExtRefInfo() { + // Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2")); - List extRefInfoList = assertDoesNotThrow(()-> lDeviceAdapter.getExtRefInfo()); - assertEquals(2,extRefInfoList.size()); + // When + List extRefInfoList = assertDoesNotThrow(lDeviceAdapter::getExtRefInfo); + // Then + assertThat(extRefInfoList).hasSize(2); } @Test + @Tag("issue-321") void TestGetDAI() { + // Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS1")); + // When var dataAttributeRefs = lDeviceAdapter.getDAI(new DataAttributeRef(),true); - assertEquals(4,dataAttributeRefs.size()); - - + // Then + assertThat(dataAttributeRefs).hasSize(4); + // Given DataAttributeRef filter = new DataAttributeRef(); filter.setLnClass(TLLN0Enum.LLN_0.value()); + // When dataAttributeRefs = lDeviceAdapter.getDAI(filter,true); - assertEquals(4,dataAttributeRefs.size()); + // Then + assertThat(dataAttributeRefs).hasSize(4); + // Given lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.findLDeviceAdapterByLdInst("LD_INS2").get()); filter.setLnClass("ANCR"); filter.setLnInst("1"); + // When dataAttributeRefs = lDeviceAdapter.getDAI(filter,true); - assertEquals(2,dataAttributeRefs.size()); + // Then + assertThat(dataAttributeRefs).hasSize(2); } @Test - void addPrivate() { + @Tag("issue-321") + void addPrivate_with_type_and_source_should_create_Private() { + // Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2")); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(lDeviceAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(lDeviceAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When lDeviceAdapter.addPrivate(tPrivate); - assertEquals(1, lDeviceAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(lDeviceAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @ParameterizedTest @CsvSource(value = {"ldInst;LDevice[@inst=\"ldInst\"]", ";LDevice[not(@inst)]"} , delimiter = ';') - void elementXPath(String ldInst, String message) { + void elementXPath_should_return_expected_xpath_value(String ldInst, String message) { // Given TLDevice tlDevice = new TLDevice(); tlDevice.setInst(ldInst); @@ -182,7 +227,7 @@ void getLDeviceStatus_should_succeed() { } @Test - void getLNAdaptersInclundigLN0() { + void getLNAdaptersIncludingLN0_should_return_expected_list_of_AbstractLNAdapter() { //Given LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(()-> iAdapter.getLDeviceAdapterByLdInst("LD_INS2")); //When @@ -196,7 +241,7 @@ void getLNAdaptersInclundigLN0() { @ParameterizedTest(name = "{0}") @MethodSource("provideHasDataSetCreationCapabilityTrue") - void hasDataSetCreationCapability_should_return_true_when_attribute_exists(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { + void hasDataSetCreationCapability_when_attribute_exists_should_return_true(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -265,7 +310,7 @@ private static Stream provideHasDataSetCreationCapabilityTrue() { @ParameterizedTest(name = "{0}") @MethodSource("provideHasDataSetCreationCapabilityFalse") - void hasDataSetCreationCapability_should_return_false_when_wrong_attribute(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { + void hasDataSetCreationCapability_when_wrong_attribute_should_return_false(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -311,7 +356,7 @@ private static Stream provideHasDataSetCreationCapabilityFalse() { @ParameterizedTest @EnumSource(ControlBlockEnum.class) - void hasDataSetCreationCapability_should_return_false_when_no_existing_services_attribute(ControlBlockEnum controlBlockEnum) { + void hasDataSetCreationCapability_when_no_existing_services_attribute_should_return_false(ControlBlockEnum controlBlockEnum) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -326,7 +371,7 @@ void hasDataSetCreationCapability_should_return_false_when_no_existing_services_ } @Test - void hasDataSetCreationCapability_should_throw_exception_when_parameter_is_null() { + void hasDataSetCreationCapability_when_parameter_is_null_should_throw_exception() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -342,7 +387,7 @@ void hasDataSetCreationCapability_should_throw_exception_when_parameter_is_null( @ParameterizedTest(name = "{0}") @MethodSource("provideHasControlBlockCreationCapabilityTrue") - void hasControlBlockCreationCapability_should_return_true_when_attribute_exists(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { + void hasControlBlockCreationCapability_when_attribute_exists_should_return_true(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -387,7 +432,7 @@ private static Stream provideHasControlBlockCreationCapabilityTrue() @ParameterizedTest(name = "{0}") @MethodSource("provideHasControlBlockCreationCapabilityFalse") - void hasControlBlockCreationCapability_should_return_false_when_wrong_attribute(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { + void hasControlBlockCreationCapability_when_wrong_attribute_should_return_false(String testCase, TServices tServices, ControlBlockEnum controlBlockEnum) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -432,7 +477,7 @@ private static Stream provideHasControlBlockCreationCapabilityFalse() @ParameterizedTest @EnumSource(ControlBlockEnum.class) - void hasControlBlockCreationCapability_should_return_false_when_no_existing_services_attribute(ControlBlockEnum controlBlockEnum) { + void hasControlBlockCreationCapability_when_no_existing_services_attribute_should_return_false(ControlBlockEnum controlBlockEnum) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -447,7 +492,7 @@ void hasControlBlockCreationCapability_should_return_false_when_no_existing_serv } @Test - void hasControlBlockCreationCapability_should_throw_exception_when_parameter_is_null() { + void hasControlBlockCreationCapability_when_parameter_is_null_should_throw_exception() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -462,7 +507,7 @@ void hasControlBlockCreationCapability_should_throw_exception_when_parameter_is_ @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_not_update_ln_when_no_extRef(String testCase, MonitoringLnClassEnum lnClassEnum, String doName) { + void manageMonitoringLns_when_no_extRef_should_not_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName) { // Given LDeviceAdapter lDeviceAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1).getLDeviceAdapterByLdInst(LD_SUIED); // When @@ -476,7 +521,7 @@ void manageMonitoringLns_should_not_update_ln_when_no_extRef(String testCase, Mo @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_not_create_ln_when_no_init_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName) { + void manageMonitoringLns_when_no_init_ln_should_not_create_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName) { // Given LDeviceAdapter lDeviceAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1).getLDeviceAdapterByLdInst(LD_SUIED); lDeviceAdapter.getCurrentElem().unsetLN(); @@ -492,7 +537,7 @@ void manageMonitoringLns_should_not_create_ln_when_no_init_ln(String testCase, M @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_update_ln_when_one_extRef_and_dai_updatable(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { + void manageMonitoringLns_when_one_extRef_and_dai_updatable_should_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { // Given LDeviceAdapter lDeviceAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1).getLDeviceAdapterByLdInst(LD_SUIED); TExtRef tExtRef = createExtRefExample("CB_Name", tServiceType); @@ -513,7 +558,7 @@ void manageMonitoringLns_should_update_ln_when_one_extRef_and_dai_updatable(Stri @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_not_update_ln_when_one_extRef_and_dai_not_updatable(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { + void manageMonitoringLns_when_one_extRef_and_dai_not_updatable_should_not_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { // Given SclRootAdapter sclRootAdapter = createIedsInScl(lnClassEnum.value(), doName); sclRootAdapter.getDataTypeTemplateAdapter().getDOTypeAdapterById("REF").get().getDAAdapterByName("setSrcRef") @@ -535,7 +580,7 @@ void manageMonitoringLns_should_not_update_ln_when_one_extRef_and_dai_not_updata @ParameterizedTest(name = "{0}") @MethodSource("provideLnClassAndDoType") - void manageMonitoringLns_should_update_ln_when_2_extRef_and_dai_updatable(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { + void manageMonitoringLns_when_2_extRef_and_dai_updatable_should_update_ln(String testCase, MonitoringLnClassEnum lnClassEnum, String doName, TServiceType tServiceType) { // Given LDeviceAdapter lDeviceAdapter = createIedsInScl(lnClassEnum.value(), doName).getIEDAdapterByName(IED_NAME_1).getLDeviceAdapterByLdInst(LD_SUIED); TLN copiedLN1 = copySclElement(lDeviceAdapter.getLNAdapters().get(0).getCurrentElem(), TLN.class); @@ -561,7 +606,7 @@ void manageMonitoringLns_should_update_ln_when_2_extRef_and_dai_updatable(String } @Test - void getExtRefBuyReferenceForActifLDEPF_should_return_existingExtRef_when_LDEPF_active_and_bay_exists() { + void getExtRefBuyReferenceForActifLDEPF_when_LDEPF_active_and_bay_exists_should_return_existingExtRef() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -575,7 +620,7 @@ void getExtRefBuyReferenceForActifLDEPF_should_return_existingExtRef_when_LDEPF_ } @Test - void getExtRefBayReferenceForActifLDEPF_should_return_fatal_errors_when_NoPrivateBuyNorIcdHeader() { + void getExtRefBayReferenceForActifLDEPF_when_NoPrivateBuyNorIcdHeader_should_return_fatal_errors() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -594,7 +639,7 @@ void getExtRefBayReferenceForActifLDEPF_should_return_fatal_errors_when_NoPrivat } @Test - void getExtRefBayReferenceForActifLDEPF_should_return_fatal_errors_when_DOI_Mod_notExists() { + void getExtRefBayReferenceForActifLDEPF_when_DOI_Mod_notExists_should_return_fatal_errors() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -611,7 +656,7 @@ void getExtRefBayReferenceForActifLDEPF_should_return_fatal_errors_when_DOI_Mod_ } @Test - void getExtRefBayReferenceForActifLDEPF_should_not_return_existingExtRef_when_LDEPF_NotActive() { + void getExtRefBayReferenceForActifLDEPF_when_LDEPF_NotActive_should_not_return_existingExtRef() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java index 000d694d2..33ce8d924 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.ied; +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; @@ -24,16 +25,14 @@ import java.util.function.Function; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Named.named; import static org.lfenergy.compas.scl2007b4.model.TSampledValueControl.SmvOpts; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; class LN0AdapterTest { @@ -41,63 +40,52 @@ class LN0AdapterTest { private static final String CB_NAME = "cbName"; @Test - void testAmChildElementRef() throws ScdException { + void constructor_whenCalledWithNoRelationBetweenLDeviceAndLN0_shouldThrowException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); - TLDevice tlDevice = mock(TLDevice.class); - when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); + when(lDeviceAdapter.getCurrentElem()).thenReturn(new TLDevice()); LN0 ln0 = new LN0(); - ln0.setLnType("LT1"); - when(tlDevice.getLN0()).thenReturn(ln0); - LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); - - assertEquals(LN0.class, ln0Adapter.getElementClassType()); - assertEquals("LT1", ln0Adapter.getLnType()); - assertEquals(TLLN0Enum.LLN_0.value(), ln0Adapter.getLNClass()); - assertFalse(ln0Adapter.hasInputs()); - ln0.setInputs(new TInputs()); - assertTrue(ln0Adapter.hasInputs()); - assertTrue(ln0Adapter.isLN0()); - - assertTrue(ln0Adapter.getLNInst().isEmpty()); - assertTrue(ln0Adapter.getPrefix().isEmpty()); - assertTrue(ln0Adapter.getCurrentElem().getGSEControl().isEmpty()); - assertTrue(ln0Adapter.getCurrentElem().getSampledValueControl().isEmpty()); - assertTrue(ln0Adapter.getCurrentElem().getReportControl().isEmpty()); - - LN0 ln01 = new LN0(); - assertThrows(IllegalArgumentException.class, () -> new LN0Adapter(lDeviceAdapter, ln01)); + // When Then + assertThatCode(() -> new LN0Adapter(lDeviceAdapter, ln0)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } - // AbstractLNAdapter class test @Test - void containsFCDA() { + void constructor_whenCalledWithExistingRelationBetweenLDeviceAndLN0_shouldNotThrowException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); - TLDevice tlDevice = mock(TLDevice.class); - when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); + TLDevice tlDevice = new TLDevice(); LN0 ln0 = new LN0(); - when(tlDevice.getLN0()).thenReturn(ln0); - assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + tlDevice.setLN0(ln0); + when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); + // When Then + assertThatCode(() -> new LN0Adapter(lDeviceAdapter, ln0)).doesNotThrowAnyException(); } @Test - void isExtRefExist_shouldThrowScdException_whenNoInputsInLN0() { - //Given + @Tag("issue-321") + void isExtRefExist_whenNoInputsInLN0_shouldThrowScdException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = mock(TLDevice.class); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); LN0 ln0 = new LN0(); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + // Given ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); - //When Then + // When Then assertThatThrownBy(() -> ln0Adapter.isExtRefExist(signalInfo)) .isInstanceOf(ScdException.class) .hasMessage("No Inputs for LN or no ExtRef signal to check"); } @Test - void isExtRefExist_shouldThrowScdException_whenSignalNotValid() { - //Given + @Tag("issue-321") + void isExtRefExist_whenSignalNotValid_shouldThrowScdException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = mock(TLDevice.class); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); @@ -107,18 +95,20 @@ void isExtRefExist_shouldThrowScdException_whenSignalNotValid() { tInputs.getExtRef().add(tExtRef); ln0.setInputs(tInputs); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + // Given ExtRefSignalInfo signalInfo = new ExtRefSignalInfo(); - //When Then + // When Then assertThatThrownBy(() -> ln0Adapter.isExtRefExist(signalInfo)) .isInstanceOf(ScdException.class) .hasMessage("Invalid or missing attributes in ExtRef signal info"); } - @Test - void isExtRefExist_shouldThrowScdException_whenSignalNull() { - //Given + @Tag("issue-321") + void isExtRefExist_whenSignalNull_shouldThrowScdException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = mock(TLDevice.class); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); @@ -128,16 +118,18 @@ void isExtRefExist_shouldThrowScdException_whenSignalNull() { tInputs.getExtRef().add(extRef); ln0.setInputs(tInputs); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); - //When Then + // When Then assertThatThrownBy(() -> ln0Adapter.isExtRefExist(null)) .isInstanceOf(ScdException.class) .hasMessage("No Inputs for LN or no ExtRef signal to check"); } @Test - void isExtRefExist_shouldThrowScdException_whenNotExistInTargetLN() { - //Given + @Tag("issue-321") + void isExtRefExist_whenNotExistInTargetLN_shouldThrowScdException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = mock(TLDevice.class); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); @@ -148,44 +140,52 @@ void isExtRefExist_shouldThrowScdException_whenNotExistInTargetLN() { tInputs.getExtRef().add(extRef); ln0.setInputs(tInputs); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + // Given ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); - //When Then + // When Then assertThatThrownBy(() -> ln0Adapter.isExtRefExist(signalInfo)) .isInstanceOf(ScdException.class) .hasMessage("ExtRef signal does not exist in target LN"); } @Test - void isExtRefExist_shouldNotThrowException_whenExtRefExist() { - //Given + @Tag("issue-321") + void isExtRefExist_whenExtRefExist_shouldNotThrowException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = mock(TLDevice.class); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); LN0 ln0 = new LN0(); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + // Given TInputs tInputs = new TInputs(); TExtRef extRef = DTO.createExtRef(); tInputs.getExtRef().add(extRef); ln0.setInputs(tInputs); ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); - //When Then + // When Then assertDoesNotThrow(() -> ln0Adapter.isExtRefExist(signalInfo)); } @Test - void isExtRefExist_shouldNotThrowException_whenExtRefExistWithPDA() { - //Given + @Tag("issue-321") + void isExtRefExist_whenExtRefExistWithPDA_shouldNotThrowException() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = mock(TLDevice.class); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); LN0 ln0 = new LN0(); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + // Given TInputs tInputs = new TInputs(); TExtRef extRef = DTO.createExtRef(); tInputs.getExtRef().add(extRef); @@ -193,40 +193,52 @@ void isExtRefExist_shouldNotThrowException_whenExtRefExistWithPDA() { ExtRefSignalInfo signalInfo = DTO.createExtRefSignalInfo(); signalInfo.setPDA("Da.papa"); - //When Then + // When Then assertDoesNotThrow(() -> ln0Adapter.isExtRefExist(signalInfo)); } @Test + @Tag("issue-321") void testGetDataSetWith() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = mock(TLDevice.class); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); LN0 ln0 = new LN0(); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + // Given TDataSet tDataSet = new TDataSet(); ln0.getDataSet().add(tDataSet); + // When List tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(null); - assertFalse(tDataSets.isEmpty()); + // Then + assertThat(tDataSets).isNotEmpty(); + // Given ExtRefInfo extRefInfo = DTO.createExtRefInfo(); extRefInfo = Mockito.spy(extRefInfo); - TFCDA tfcda = new TFCDA(); tDataSet.getFCDA().add(tfcda); + // When tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(extRefInfo); - assertTrue(tDataSets.isEmpty()); + // Then + assertThat(tDataSets).isEmpty(); - Mockito.doReturn(true).when(extRefInfo).checkMatchingFCDA(any(TFCDA.class)); + doReturn(true).when(extRefInfo).checkMatchingFCDA(any(TFCDA.class)); + // When tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(extRefInfo); - assertFalse(tDataSets.isEmpty()); + // Then + assertThat(tDataSets).isNotEmpty(); } @Test + @Tag("issue-321") void testGetControlBlocks() { + // Given LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); IEDAdapter iedAdapter = mock(IEDAdapter.class); TLDevice tlDevice = mock(TLDevice.class); @@ -235,7 +247,9 @@ void testGetControlBlocks() { when(iedAdapter.getName()).thenReturn("IED_NAME"); LN0 ln0 = new LN0(); when(tlDevice.getLN0()).thenReturn(ln0); + // When Then LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); + // Given TGSEControl tgseControl = new TGSEControl(); tgseControl.setDatSet("GSE_REF"); TSampledValueControl tSampledValueControl = new TSampledValueControl(); @@ -249,8 +263,9 @@ void testGetControlBlocks() { TDataSet tDataSetGSE = new TDataSet(); tDataSetGSE.setName(DTO.CB_DATASET_REF); + // When Then List controlBlocks = ln0Adapter.getControlBlocks(List.of(tDataSetGSE), null); - assertTrue(controlBlocks.isEmpty()); + assertThat(controlBlocks).isEmpty(); tDataSetGSE.setName("GSE_REF"); TDataSet tDataSetSMV = new TDataSet(); @@ -260,52 +275,53 @@ void testGetControlBlocks() { List tDataSets = List.of(tDataSetGSE, tDataSetSMV, tDataSetRPT); + // When Then controlBlocks = ln0Adapter.getControlBlocks(tDataSets, TServiceType.REPORT); assertThat(controlBlocks).hasSize(1); + // When Then controlBlocks = ln0Adapter.getControlBlocks(tDataSets, TServiceType.SMV); assertThat(controlBlocks).hasSize(1); + // When Then controlBlocks = ln0Adapter.getControlBlocks(tDataSets, TServiceType.GOOSE); assertThat(controlBlocks).hasSize(1); + // When Then controlBlocks = ln0Adapter.getControlBlocks(tDataSets, null); assertThat(controlBlocks).hasSize(3); } @Test - void testGetControlSetByBindingInfo() { - + void getControlBlocksForMatchingFCDA_should_return_expected_Items() { + // Given LN0 ln0 = new LN0(); LN0Adapter ln0Adapter = Mockito.spy(new LN0Adapter(null, ln0)); when(ln0Adapter.getCurrentElem()).thenReturn(ln0); - TInputs tInputs = new TInputs(); TExtRef extRef = DTO.createExtRef(); tInputs.getExtRef().add(extRef); ln0.setInputs(tInputs); - ExtRefInfo extRefBindingInfo = DTO.createExtRefInfo(); - Mockito.doReturn(List.of(new TDataSet())) - .when(ln0Adapter).getDataSetMatchingExtRefInfo(any(ExtRefInfo.class)); - - Mockito.doReturn(List.of(new ReportControlBlock("rpt", "rptID", "rptDatSet"))) - .when(ln0Adapter).getControlBlocks( - any(List.class), any(TServiceType.class)); - + doReturn(List.of(new TDataSet())).when(ln0Adapter).getDataSetMatchingExtRefInfo(any(ExtRefInfo.class)); + doReturn(List.of(new ReportControlBlock("rpt", "rptID", "rptDatSet"))) + .when(ln0Adapter).getControlBlocks(any(List.class), any(TServiceType.class)); + // When List controlBlocks = ln0Adapter.getControlBlocksForMatchingFCDA(extRefBindingInfo); - assertFalse(controlBlocks.isEmpty()); - assertEquals(TServiceType.REPORT, controlBlocks.get(0).getServiceType()); + // Then + assertThat(controlBlocks).isNotEmpty(); + assertThat(controlBlocks.get(0).getServiceType()).isEqualTo(TServiceType.REPORT); } @Test - void testGetDOIAdapters() { + void getDOIAdapters_should_return_expected_list_of_DOIAdapter() { + // Given LN0 ln0 = new LN0(); - LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); - TDOI tdoi = new TDOI(); tdoi.setName("Do"); ln0.getDOI().add(tdoi); - assertFalse(ln0Adapter.getDOIAdapters().isEmpty()); - assertEquals("Do", ln0Adapter.getDOIAdapters().get(0).getCurrentElem().getName()); + LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); + // When Then + assertThat(ln0Adapter.getDOIAdapters()).isNotEmpty(); + assertThat(ln0Adapter.getDOIAdapters().get(0).getCurrentElem().getName()).isEqualTo("Do"); } @Test @@ -360,7 +376,10 @@ private static LN0Adapter createLn0AdapterWithDoi(String doiName) { } @Test - void testGetDOIAdapterByName() { + // Test should be modified to reflect each test case. + @Tag("issue-321") + void getDOIAdapterByName_should_return_expected_DOIAdapter() { + // Given IEDAdapter iedAdapter = mock(IEDAdapter.class); TIED tied = new TIED(); when(iedAdapter.getCurrentElem()).thenReturn(tied); @@ -370,35 +389,46 @@ void testGetDOIAdapterByName() { when(lDeviceAdapter.amChildElementRef()).thenReturn(true); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); when(lDeviceAdapter.getParentAdapter()).thenReturn(iedAdapter); - LN0 ln0 = new LN0(); tlDevice.setLN0(ln0); LN0Adapter ln0Adapter = new LN0Adapter(lDeviceAdapter, ln0); - TDOI tdoi = new TDOI(); tdoi.setName("Do"); ln0.getDOI().add(tdoi); - assertDoesNotThrow(() -> ln0Adapter.getDOIAdapterByName("Do")); - assertThrows(ScdException.class, () -> ln0Adapter.getDOIAdapterByName("Dod")); + // When Then + assertThatCode(() -> ln0Adapter.getDOIAdapterByName("Do")) + .doesNotThrowAnyException(); + // When Then + assertThatCode(() -> ln0Adapter.getDOIAdapterByName("Dod")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown DOI(Dod)"); } @Test + // Test should be modified to reflect each test case. + @Tag("issue-321") void testFindMatch() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile(SCD_IED_U_TEST); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LD_INS1").get()); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); DoTypeName doTypeName = new DoTypeName("Do.sdo1.d"); DaTypeName daTypeName = new DaTypeName("antRef.bda1.bda2.bda3"); + // When Then AbstractDAIAdapter daiAdapter = (AbstractDAIAdapter) assertDoesNotThrow(() -> ln0Adapter.findMatch(doTypeName, daTypeName).get()); - assertEquals("bda3", daiAdapter.getCurrentElem().getName()); - assertEquals("Completed-diff", daiAdapter.getCurrentElem().getVal().get(0).getValue()); - + assertThat(daiAdapter.getCurrentElem().getName()).isEqualTo("bda3"); + assertThat(daiAdapter.getCurrentElem().getVal().get(0).getValue()).isEqualTo("Completed-diff"); DoTypeName doTypeName2 = new DoTypeName("Do.sdo1"); - assertFalse(ln0Adapter.findMatch(doTypeName2, daTypeName).isPresent()); + // When Then + assertThat(ln0Adapter.findMatch(doTypeName2, daTypeName)).isEmpty(); } + @Tag("issue-321") + // Test should be modified to reflect each test case. @ParameterizedTest @EnumSource(value = ControlBlockEnum.class, mode = EnumSource.Mode.EXCLUDE, names = "LOG") void hasControlBlock_should_return_true(ControlBlockEnum controlBlockEnum) { @@ -415,7 +445,9 @@ void hasControlBlock_should_return_true(ControlBlockEnum controlBlockEnum) { ln0.getLnClass().add(TLLN0Enum.LLN_0.value()); when(tlDevice.getLN0()).thenReturn(ln0); LN0Adapter ln0Adapter = new LN0Adapter(lDeviceAdapter, ln0); + // When ln0Adapter.createDataSetIfNotExists("datSet", controlBlockEnum); + // When ln0Adapter.createControlBlockIfNotExists(CB_NAME, "id", "datSet", controlBlockEnum); // When @@ -424,6 +456,8 @@ void hasControlBlock_should_return_true(ControlBlockEnum controlBlockEnum) { assertThat(found).isTrue(); } + @Tag("issue-321") + // Test should be modified to reflect each test case. @Test void hasControlBlock_when_wrong_controlBlockEnum_should_return_false() { // Given @@ -439,7 +473,9 @@ void hasControlBlock_when_wrong_controlBlockEnum_should_return_false() { ln0.getLnClass().add(TLLN0Enum.LLN_0.value()); when(tlDevice.getLN0()).thenReturn(ln0); LN0Adapter ln0Adapter = new LN0Adapter(lDeviceAdapter, ln0); + // When ln0Adapter.createDataSetIfNotExists("datSet", ControlBlockEnum.GSE); + // When ln0Adapter.createControlBlockIfNotExists(CB_NAME, "id", "datSet", ControlBlockEnum.GSE); // When @@ -449,25 +485,31 @@ void hasControlBlock_when_wrong_controlBlockEnum_should_return_false() { } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + // Given LN0 tln = new LN0(); tln.getLnClass().add(TLLN0Enum.LLN_0.value()); LN0Adapter lnAdapter = new LN0Adapter(null, tln); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(lnAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(lnAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When lnAdapter.addPrivate(tPrivate); - assertEquals(1, lnAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(lnAdapter.getCurrentElem().getPrivate()).hasSize(1); } @Test + @Tag("issue-321") void testGetDAI() { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LDSUIED").get()); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); DataAttributeRef filter = new DataAttributeRef(); @@ -481,117 +523,138 @@ void testGetDAI() { daTypeName.setBType(TPredefinedBasicTypeEnum.ENUM); daTypeName.setFc(TFCEnum.ST); filter.setDaName(daTypeName); - //When + // When var dataAttributeRefs = ln0Adapter.getDAI(filter, false); - //Then - assertFalse(dataAttributeRefs.isEmpty()); - assertEquals(1, dataAttributeRefs.size()); - assertNotNull(dataAttributeRefs.get(0).getDaName().getType()); - assertEquals("BehaviourModeKind", dataAttributeRefs.get(0).getDaName().getType()); + // Then + assertThat(dataAttributeRefs).hasSize(1); + assertThat(dataAttributeRefs.get(0).getDaName().getType()).isEqualTo("BehaviourModeKind"); } @Test - void getEnumValue_shouldReturnNothing_whenEnumUnknow() { - //Given + @Tag("issue-321") + void getEnumValue_whenEnumUnknown_shouldReturnNothing() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.getLDeviceAdapterByLdInst("LDSUIED")); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); - //When + // When Set enumValues = ln0Adapter.getEnumValues("Behaviour"); - //Then + // Then assertThat(enumValues).isEmpty(); } @Test - void getEnumValue_shouldReturnEnumValues_whenEnumKnown() { - //Given + @Tag("issue-321") + void getEnumValue_whenEnumKnown_shouldReturnEnumValues() { + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LDSUIED").get()); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); - //When + // When Set enumValues = ln0Adapter.getEnumValues("BehaviourModeKind"); - //Then - assertEquals(5, enumValues.size()); - assertThat(enumValues).containsExactlyInAnyOrder("blocked", "test", "test/blocked", "off", "on"); + // Then + assertThat(enumValues).hasSize(5) + .containsExactlyInAnyOrder("blocked", "test", "test/blocked", "off", "on"); } @ParameterizedTest + @Tag("issue-321") @MethodSource("provideControlBlocks") void addControlBlock_should_add_ControlBlock(ControlBlock controlBlock) { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.getLDeviceAdapterByLdInst("LDSUIED")); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); + // When ln0Adapter.createDataSetIfNotExists(controlBlock.getDataSetRef(), controlBlock.getControlBlockEnum()); int initialControlBlockCount = ln0Adapter.getTControlsByType(controlBlock.getControlBlockEnum().getControlBlockClass()).size(); - //When + // When ln0Adapter.addControlBlock(controlBlock); - //Then + // Then assertThat(ln0Adapter.getTControlsByType(controlBlock.getControlBlockEnum().getControlBlockClass())).hasSize(initialControlBlockCount + 1); } @Test + @Tag("issue-321") void addControlBlock_should_add_ReportControlBlock() { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.getLDeviceAdapterByLdInst("LDSUIED")); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); + // When ln0Adapter.createDataSetIfNotExists("rptDatSet", ControlBlockEnum.REPORT); ReportControlBlock reportControlBlock = new ReportControlBlock("rpt", "rptID", "rptDatSet"); int reportCBInitSize = ln0Adapter.getCurrentElem().getReportControl().size(); - //When + // When ln0Adapter.addControlBlock(reportControlBlock); - //Then + // Then assertThat(ln0Adapter.getCurrentElem().getReportControl()).hasSize(reportCBInitSize + 1); } @Test + @Tag("issue-321") void addControlBlock_should_add_GooseControlBlock() { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.getLDeviceAdapterByLdInst("LDSUIED")); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); + // When ln0Adapter.createDataSetIfNotExists("datSet", ControlBlockEnum.GSE); GooseControlBlock gooseControlBlock = new GooseControlBlock("gse", "gseID", "datSet"); int reportCBInitSize = ln0Adapter.getCurrentElem().getReportControl().size(); - //When + // When ln0Adapter.addControlBlock(gooseControlBlock); - //Then + // Then assertThat(ln0Adapter.getCurrentElem().getGSEControl()).hasSize(reportCBInitSize + 1); } @Test + @Tag("issue-321") void addControlBlock_should_add_SMVControlBlock() { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.getLDeviceAdapterByLdInst("LDSUIED")); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); + // When ln0Adapter.createDataSetIfNotExists("smvDatSet", ControlBlockEnum.SAMPLED_VALUE); SMVControlBlock smvControlBlock = new SMVControlBlock("smv", "smvID", "smvDatSet"); int reportCBInitSize = ln0Adapter.getCurrentElem().getReportControl().size(); - //When + // When ln0Adapter.addControlBlock(smvControlBlock); - //Then + // Then assertThat(ln0Adapter.getCurrentElem().getSampledValueControl()).hasSize(reportCBInitSize + 1); } @ParameterizedTest @MethodSource("provideControlBlocks") + @Tag("issue-321") void addControlBlock_when_accessPoint_does_not_have_capability_should_throw_exception(ControlBlock controlBlock) { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); @@ -599,7 +662,7 @@ void addControlBlock_when_accessPoint_does_not_have_capability_should_throw_exce LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); ln0Adapter.createDataSetIfNotExists("dataSet", ControlBlockEnum.REPORT); ln0Adapter.getParentLDevice().getAccessPoint().setServices(new TServices()); - //When & Then + // When & Then assertThatThrownBy(() -> ln0Adapter.addControlBlock(controlBlock)) .isInstanceOf(ScdException.class) .hasMessageContaining("because IED/AccessPoint does not have capability to create ControlBlock"); @@ -607,16 +670,20 @@ void addControlBlock_when_accessPoint_does_not_have_capability_should_throw_exce @ParameterizedTest @MethodSource("provideControlBlocks") + @Tag("issue-321") void addControlBlock_when_controlBlock_already_exists_should_throw_exception(ControlBlock controlBlock) { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.getLDeviceAdapterByLdInst("LDSUIED")); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); + // When ln0Adapter.createDataSetIfNotExists("dataSet", ControlBlockEnum.REPORT); ln0Adapter.addControlBlock(controlBlock); - //When & Then + // When & Then assertThatThrownBy(() -> ln0Adapter.addControlBlock(controlBlock)) .isInstanceOf(ScdException.class) .hasMessageContaining("because it already exists"); @@ -624,14 +691,17 @@ void addControlBlock_when_controlBlock_already_exists_should_throw_exception(Con @ParameterizedTest @MethodSource("provideControlBlocks") + @Tag("issue-321") void addControlBlock_when_dataSet_does_not_exist_should_throw_exception(ControlBlock controlBlock) { - //Given + // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); + // When Then IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED4d4fe1a8cda64cf88a5ee4176a1a0eef")); + // When Then LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.getLDeviceAdapterByLdInst("LDSUIED")); LN0Adapter ln0Adapter = lDeviceAdapter.getLN0Adapter(); - //When & Then + // When & Then assertThatThrownBy(() -> ln0Adapter.addControlBlock(controlBlock)) .isInstanceOf(ScdException.class) .hasMessageContaining("because target DataSet dataSet does not exists"); @@ -666,7 +736,7 @@ private static Stream provideGetTControlsByType() { } @Test - void elementXPath() { + void elementXPath_should_return_expected_xpath_value() { // Given LN0 tln = new LN0(); tln.getLnClass().add(TLLN0Enum.LLN_0.value()); @@ -742,6 +812,7 @@ void createDataSetIfNotExists_when_ied_does_not_have_creation_capabilities_shoul } @Test + @Tag("issue-321") void createControlBlockIfNotExists_should_create_GSEControl() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-ln-adapter/scd_with_ln.xml"); @@ -750,6 +821,7 @@ void createControlBlockIfNotExists_should_create_GSEControl() { final String NEW_DATASET_NAME = "newDataSet"; final String NEW_CB_NAME = "newControlBlock"; final String NEW_CB_ID = "newControlBlockId"; + // When sourceLn0.createDataSetIfNotExists(NEW_DATASET_NAME, ControlBlockEnum.GSE); // When sourceLn0.createControlBlockIfNotExists(NEW_CB_NAME, NEW_CB_ID, NEW_DATASET_NAME, ControlBlockEnum.GSE); @@ -763,6 +835,7 @@ void createControlBlockIfNotExists_should_create_GSEControl() { } @Test + @Tag("issue-321") void createControlBlockIfNotExists_should_create_SampledValueControl() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-ln-adapter/scd_with_ln.xml"); @@ -771,6 +844,7 @@ void createControlBlockIfNotExists_should_create_SampledValueControl() { final String NEW_DATASET_NAME = "newDataSet"; final String NEW_CB_NAME = "newControlBlock"; final String NEW_CB_ID = "newControlBlockId"; + // When sourceLn0.createDataSetIfNotExists(NEW_DATASET_NAME, ControlBlockEnum.SAMPLED_VALUE); // When sourceLn0.createControlBlockIfNotExists(NEW_CB_NAME, NEW_CB_ID, NEW_DATASET_NAME, ControlBlockEnum.SAMPLED_VALUE); @@ -791,6 +865,7 @@ void createControlBlockIfNotExists_should_create_SampledValueControl() { } @Test + @Tag("issue-321") void createControlBlockIfNotExists_should_create_ReportControl() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scl-ln-adapter/scd_with_ln.xml"); @@ -800,6 +875,7 @@ void createControlBlockIfNotExists_should_create_ReportControl() { final String NEW_DATASET_NAME = "newDataSet"; final String NEW_CB_NAME = "newControlBlock"; final String NEW_CB_ID = "newControlBlockId"; + // When sourceLn0.createDataSetIfNotExists(NEW_DATASET_NAME, ControlBlockEnum.REPORT); // When sourceLn0.createControlBlockIfNotExists(NEW_CB_NAME, NEW_CB_ID, NEW_DATASET_NAME, ControlBlockEnum.REPORT); @@ -828,7 +904,7 @@ void createControlBlockIfNotExists_should_create_ReportControl() { @Test void getFCDAs_should_return_list_of_FCDAs() { - + // Given TFCDA tfcda = new TFCDA(); tfcda.setFc(TFCEnum.CF); TFCDA tfcda1 = new TFCDA(); @@ -861,10 +937,10 @@ void getFCDAs_should_return_list_of_FCDAs() { tExtRef.setSrcCBName("gse1"); tExtRef.setServiceType(TServiceType.GOOSE); - //When + // When List result = ln0Adapter.getFCDAs(tExtRef); - //Then + // Then assertThat(result).hasSize(2) .containsExactlyInAnyOrder(tfcda, tfcda1); @@ -872,7 +948,7 @@ void getFCDAs_should_return_list_of_FCDAs() { @Test void getFCDAs_should_return_empty_list_of_FCDAs() { - + // Givens TDataSet tDataSet2 = new TDataSet(); tDataSet2.setName("smv_dat_set"); @@ -889,17 +965,17 @@ void getFCDAs_should_return_empty_list_of_FCDAs() { tExtRef.setSrcCBName("smv1"); tExtRef.setServiceType(TServiceType.SMV); - //When + // When List result = ln0Adapter.getFCDAs(tExtRef); - //Then + // Then assertThat(result).isEmpty(); } @Test - void getFCDAs_should_throw_Exception_when_DataSet_not_present() { - + void getFCDAs_when_DataSet_not_present_should_throw_Exception() { + // Given LN0 ln0 = new LN0(); LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); @@ -907,7 +983,7 @@ void getFCDAs_should_throw_Exception_when_DataSet_not_present() { tExtRef.setSrcCBName("smv1"); tExtRef.setServiceType(TServiceType.SMV); - //When Then + // When Then assertThatThrownBy(() -> ln0Adapter.getFCDAs(tExtRef)) .isInstanceOf(ScdException.class) .hasMessage("Control Block smv1 not found in /LN0"); @@ -934,7 +1010,7 @@ void updateDoInRef_should_return_error_message(String testName, String ldInst, S } @Test - void updateDoInRef_should_return_error_message_when_no_Val_in_DAI_purpose() { + void updateDoInRef_when_no_Val_in_DAI_purpose_should_return_error_message() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_test.xml"); LN0Adapter sourceLn0 = findLn0(scd, "IED_NAME1", "LD_Without_Val_in_DAI_purpose"); @@ -949,7 +1025,7 @@ void updateDoInRef_should_return_error_message_when_no_Val_in_DAI_purpose() { } @Test - void updateDoInRef_should_not_treat_LN0_when_DAI_name_purpose_not_compliant() { + void updateDoInRef_when_DAI_name_purpose_not_compliant_should_not_treat_LN0() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_test.xml"); LN0Adapter sourceLn0 = findLn0(scd, "IED_NAME1", "LD_Without_purpose"); @@ -964,11 +1040,13 @@ void updateDoInRef_should_not_treat_LN0_when_DAI_name_purpose_not_compliant() { } @Test - void updateDoInRef_should_update_setSrcRef_and_not_setSrcCB_when_one_ExtRef_desc_matches() { + @Tag("issue-321") + void updateDoInRef_when_one_ExtRef_desc_matches_should_update_setSrcRef_and_not_setSrcCB() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_test.xml"); LN0Adapter sourceLn0 = findLn0(scd, "IED_NAME1", "LD_WITH_1_InRef_without_cbName"); String doiNameInRef = "InRef7"; + // When List daiValList = sourceLn0.getDOIAdapterByName(doiNameInRef).getDataAdapterByName(SETSRCREF_DA_NAME).getCurrentElem().getVal(); String originalSetSrcCB = getDaiValue(sourceLn0, doiNameInRef, SETSRCCB_DA_NAME); String expectedSrcRef = "IED_NAME1LD_WITH_1_InRef/PRANCR1.Do11.sdo11"; @@ -989,7 +1067,7 @@ void updateDoInRef_should_update_setSrcRef_and_not_setSrcCB_when_one_ExtRef_desc } @Test - void updateDoInRef_should_update_setSrcRef_and_setSrcCB_when_one_ExtRef_desc_matches() { + void updateDoInRef_when_one_ExtRef_desc_matches_should_update_setSrcRef_and_setSrcCB() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_test.xml"); LN0Adapter sourceLn0 = findLn0(scd, "IED_NAME1", "LD_WITH_1_InRef"); @@ -1014,7 +1092,7 @@ void updateDoInRef_should_update_setSrcRef_and_setSrcCB_when_one_ExtRef_desc_mat } @Test - void updateDoInRef_should_update_setSrcRef_and_setSrcCB_and_setTstRef_and_setTstCB_when_ExtRef_desc_matches() { + void updateDoInRef_when_ExtRef_desc_matches_should_update_setSrcRef_and_setSrcCB_and_setTstRef_and_setTstCB() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_test.xml"); LN0Adapter sourceLn0 = findLn0(scd, "IED_NAME1", "LD_WITH_3_InRef"); @@ -1050,7 +1128,7 @@ void updateDoInRef_should_update_setSrcRef_and_setSrcCB_and_setTstRef_and_setTst } @Test - void updateDoInRef_should_not_update_setSrcRef_and_setSrcCB_and_setTstRef_and_setTstCB_when_ExtRef_desc_matches_and_dais_not_updatable() { + void updateDoInRef_when_ExtRef_desc_matches_and_dais_not_updatable_should_not_update_setSrcRef_and_setSrcCB_and_setTstRef_and_setTstCB() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_test.xml"); LN0Adapter sourceLn0 = findLn0(scd, "IED_NAME1", "LD_WITH_3_InRef"); @@ -1085,6 +1163,7 @@ void updateDoInRef_should_not_update_setSrcRef_and_setSrcCB_and_setTstRef_and_se @Test + @Tag("issue-321") void streamControlBlocks_should_return_all_GSEControlBlocks() { // Given IEDAdapter iedAdapter = mock(IEDAdapter.class); @@ -1097,9 +1176,13 @@ void streamControlBlocks_should_return_all_GSEControlBlocks() { tlDevice.setLN0(ln0); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); LN0Adapter ln0Adapter = new LN0Adapter(lDeviceAdapter, ln0); + // When ln0Adapter.createDataSetIfNotExists("datSet1", ControlBlockEnum.GSE); + // When ln0Adapter.createDataSetIfNotExists("datSet2", ControlBlockEnum.SAMPLED_VALUE); + // When ln0Adapter.createControlBlockIfNotExists("cbNameGSE", "cbId1", "datSet1", ControlBlockEnum.GSE); + // When ln0Adapter.createControlBlockIfNotExists("cbNameSMV", "cbId2", "datSet2", ControlBlockEnum.SAMPLED_VALUE); // When Stream result = ln0Adapter.streamControlBlocks(ControlBlockEnum.GSE); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterTest.java index 63851eb22..f3c1997ac 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterTest.java @@ -4,8 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.ied; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -16,7 +15,6 @@ import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; -import org.mockito.Mockito; import java.util.Arrays; import java.util.List; @@ -25,9 +23,11 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.sct.commons.testhelpers.DataTypeUtils.*; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class LNAdapterTest { @@ -50,38 +50,46 @@ void setUp() { } @Test - void testAmChildElementRef() { - TLN tln = new TLN(); - LNAdapter lnAdapter = initLNAdapter(tln); - - assertEquals(TLN.class, lnAdapter.getElementClassType()); - assertEquals(DTO.LN_TYPE, lnAdapter.getLnType()); - assertEquals(DTO.HOLDER_LN_CLASS, lnAdapter.getLNClass()); - assertFalse(lnAdapter.hasInputs()); - tln.setInputs(new TInputs()); - assertTrue(lnAdapter.hasInputs()); - assertFalse(lnAdapter.isLN0()); - - assertEquals(DTO.HOLDER_LN_INST, lnAdapter.getLNInst()); - assertEquals(DTO.HOLDER_LN_PREFIX, lnAdapter.getPrefix()); - assertTrue(lnAdapter.getCurrentElem().getReportControl().isEmpty()); + void constructor_whenCalledWithNoRelationBetweenLDeviceAndLN_shouldThrowException() { + //Given + LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); + when(lDeviceAdapter.getCurrentElem()).thenReturn(new TLDevice()); + TLN ln = new TLN(); + //When Then + assertThatCode(() -> new LNAdapter(lDeviceAdapter, ln)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); + } - assertThrows(IllegalArgumentException.class, () -> new LNAdapter(lnAdapter.getParentAdapter(), new TLN())); + @Test + void constructor_whenCalledWithExistingRelationBetweenLDeviceAndLN_shouldNotThrowException() { + //Given + LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); + TLDevice tlDevice = new TLDevice(); + TLN ln = new TLN(); + tlDevice.getLN().add(ln); + when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); + //When Then + assertThatCode(() -> new LNAdapter(lDeviceAdapter, ln)).doesNotThrowAnyException(); } @Test + // Test should be modified to reflect each test case. + @Tag("issue-321") void testGetExtRefs() { + //Given TLN tln = new TLN(); LNAdapter lnAdapter = initLNAdapter(tln); - - assertTrue(lnAdapter.getExtRefs(null).isEmpty()); + assertThat(lnAdapter.getExtRefs(null)).isEmpty(); TInputs tInputs = new TInputs(); TExtRef extRef = DTO.createExtRef(); ExtRefSignalInfo extRefSignalInfo = new ExtRefSignalInfo(extRef); tInputs.getExtRef().add(DTO.createExtRef()); tln.setInputs(tInputs); - assertEquals(1, lnAdapter.getExtRefs(null).size()); - assertEquals(1, lnAdapter.getExtRefs(extRefSignalInfo).size()); + //When Then + assertThat(lnAdapter.getExtRefs(null)).hasSize(1); + //When Then + assertThat(lnAdapter.getExtRefs(extRefSignalInfo)).hasSize(1); } @Test @@ -113,37 +121,37 @@ void findDataSetByName_when_not_found_should_return_empty() { } @Test - void updateExtRefBindingInfo_shouldUpdateBindingInfo_whenBindingInfoNull() { + void updateExtRefBindingInfo_whenBindingInfoNull_shouldUpdateBindingInfo() { //Given ExtRefInfo extRefInfo = DTO.createExtRefInfo(); TExtRef extRef = ExtRefSignalInfo.initExtRef(extRefInfo.getSignalInfo()); - assertNull(extRef.getIedName()); + assertThat(extRef.getIedName()).isNull(); LNAdapter lnAdapter = initLNAdapter(new TLN()); extRefInfo.setBindingInfo(null); extRefInfo.setSourceInfo(null); extRef = ExtRefSignalInfo.initExtRef(extRefInfo.getSignalInfo()); - assertNull(extRef.getIedName()); + assertThat(extRef.getIedName()).isNull(); //When lnAdapter.updateExtRefBindingInfo(extRef, extRefInfo); //Then - assertNull(extRef.getIedName()); - assertNull(extRef.getSrcLDInst()); + assertThat(extRef.getIedName()).isNull(); + assertThat(extRef.getSrcLDInst()).isNull(); } @Test - void updateExtRefBindingInfo_shouldUpdateBindingInfo_whenNotBindingInfoNull() { + void updateExtRefBindingInfo_whenNotBindingInfoNull_shouldUpdateBindingInfo() { //Given ExtRefInfo extRefInfo = DTO.createExtRefInfo(); TExtRef extRef = ExtRefSignalInfo.initExtRef(extRefInfo.getSignalInfo()); - assertNull(extRef.getIedName()); + assertThat(extRef.getIedName()).isNull(); LNAdapter lnAdapter = initLNAdapter(new TLN()); extRefInfo.getBindingInfo().setServiceType(null); //When lnAdapter.updateExtRefBindingInfo(extRef, extRefInfo); //Then - assertEquals(extRefInfo.getBindingInfo().getServiceType(), extRefInfo.getSignalInfo().getPServT()); - assertEquals(extRefInfo.getBindingInfo().getIedName(), extRef.getIedName()); - assertEquals(extRefInfo.getSourceInfo().getSrcLDInst(), extRef.getSrcLDInst()); + assertThat(extRefInfo.getSignalInfo().getPServT()).isEqualTo(extRefInfo.getBindingInfo().getServiceType()); + assertThat(extRef.getIedName()).isEqualTo(extRefInfo.getBindingInfo().getIedName()); + assertThat(extRef.getSrcLDInst()).isEqualTo(extRefInfo.getSourceInfo().getSrcLDInst()); } @Test @@ -167,8 +175,8 @@ void updateExtRefBinders_shouldUpdateExtRefs() { //When Then assertDoesNotThrow(() -> lnAdapter.updateExtRefBinders(info)); List tExtRefs = lnAdapter.getExtRefs(null); - assertEquals(1, tExtRefs.size()); - assertEquals(info.getBindingInfo().getIedName(), tExtRefs.get(0).getIedName()); + assertThat(tExtRefs).hasSize(1); + assertThat(tExtRefs.get(0).getIedName()).isEqualTo(info.getBindingInfo().getIedName()); } @@ -197,9 +205,8 @@ private static Stream extRefInfoAndMessage() { ); } - @Test - void updateExtRefBinders_shouldUpdateExtRefs_whenManyExtRefMatch() { + void updateExtRefBinders_whenManyExtRefMatch_shouldUpdateExtRefs() { //Given TExtRef tExtRef = DTO.createExtRef(); TInputs inputs = new TInputs(); @@ -214,7 +221,7 @@ void updateExtRefBinders_shouldUpdateExtRefs_whenManyExtRefMatch() { } @Test - void should_throw_ScdException_when_the_given_binding_info_does_not_match_the_found_TExtRef_binding_info() { + void extractExtRefFromExtRefInfo_when_the_given_binding_info_does_not_match_the_found_TExtRef_binding_info_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-cb/scd_get_cbs_test.xml"); @@ -230,11 +237,13 @@ void should_throw_ScdException_when_the_given_binding_info_does_not_match_the_fo //When //Then - assertThrows(ScdException.class, () -> lnAdapter.extractExtRefFromExtRefInfo(extRefInfo)); + assertThatCode(() -> lnAdapter.extractExtRefFromExtRefInfo(extRefInfo)) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown TExtRef with signal info [pDO(FACntRs1.res),intAddr(INT_ADDR)] in IED_NAMELD_INST_H/LLN0"); } @Test - void should_throw_ScdException_when_the_given_binding_info_does_not_refer_to_an_existing_IED_LDevice_and_LNode_in_the_SCL() { + void extractExtRefFromExtRefInfo_when_the_given_binding_info_does_not_refer_to_an_existing_IED_LDevice_and_LNode_in_the_SCL_shouldThrowScdException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-cb/scd_get_cbs_test.xml"); @@ -260,11 +269,13 @@ void should_throw_ScdException_when_the_given_binding_info_does_not_refer_to_an_ //When //Then - assertThrows(ScdException.class, () -> lnAdapter.extractExtRefFromExtRefInfo(extRefInfo)); + assertThatCode(() -> lnAdapter.extractExtRefFromExtRefInfo(extRefInfo)) + .isInstanceOf(ScdException.class) + .hasMessageContaining("No relation between binding info and the matched TExtRef"); } @Test - void should_check_with_success_extRefInfo_coherence() { + void checkExtRefInfoCoherence_withExtRefInfoCoherence_shouldNotThrowException() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-cb/scd_get_cbs_test.xml"); @@ -340,12 +351,12 @@ void should_extract_ExtRef_from_ExtRefInfo() { TExtRef extRef = assertDoesNotThrow(() -> lnAdapter.extractExtRefFromExtRefInfo(extRefInfo)); //Then - assertEquals(extRefInfo.getSignalInfo().getPDO(), extRef.getPDO()); + assertThat(extRef.getPDO()).isEqualTo(extRefInfo.getSignalInfo().getPDO()); } @ParameterizedTest @MethodSource("provideIncompleteExtRefInfo") - void should_throw_exception_when_trying_update_extRefSource_with_wrong_arguments(ExtRefInfo incompleteExtrefInfo) { + void updateExtRefSource_when_trying_update_extRefSource_with_wrong_arguments_shouldNotTHrowException(ExtRefInfo incompleteExtrefInfo) { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-cb/scd_get_cbs_test.xml"); @@ -383,8 +394,7 @@ private static Stream provideIncompleteExtRefInfo() { } @Test - void testUpdateExtRefSource() { - + void updateExtRefSource_should_not_throw_exception() { //Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-cb/scd_get_cbs_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -429,35 +439,41 @@ private ExtRefInfo givenCompleteExtRefInfo() { } @Test - void testAddDOI() { + void addDOI_should_not_throw_exception() { + //Given TLN tln = new TLN(); tln.getLnClass().add(DTO.HOLDER_LN_CLASS); tln.setPrefix(DTO.HOLDER_LN_PREFIX); tln.setInst(DTO.HOLDER_LN_INST); LNAdapter lnAdapter = new LNAdapter(null, tln); - + //When DOIAdapter doiAdapter = lnAdapter.addDOI("Do"); - assertEquals("Do", doiAdapter.getCurrentElem().getName()); + //Then + assertThat(doiAdapter.getCurrentElem().getName()).isEqualTo("Do"); } @Test + // Test should be modified to reflect a specific test case. + @Tag("issue-321") void testGetLNodeName() { + //Given TLN tln = new TLN(); tln.getLnClass().add(DTO.HOLDER_LN_CLASS); tln.setPrefix(DTO.HOLDER_LN_PREFIX); tln.setInst(DTO.HOLDER_LN_INST); AbstractLNAdapter lnAdapter = new LNAdapter(null, tln); String exp = DTO.HOLDER_LN_PREFIX + DTO.HOLDER_LN_CLASS + DTO.HOLDER_LN_INST; - assertEquals(exp, lnAdapter.getLNodeName()); - + //When Then + assertThat(lnAdapter.getLNodeName()).isEqualTo(exp); LN0 ln0 = new LN0(); ln0.getLnClass().add(TLLN0Enum.LLN_0.value()); lnAdapter = new LN0Adapter(null, ln0); - assertEquals(TLLN0Enum.LLN_0.value(), lnAdapter.getLNodeName()); + //When Then + assertThat(lnAdapter.getLNodeName()).isEqualTo(TLLN0Enum.LLN_0.value()); } @Test - void updateDAI_should_throw_ScdException_when_DataAttributeRef_is_empty() { + void updateDAI_when_DataAttributeRef_is_empty_should_throw_ScdException() { // Given DataAttributeRef dataAttributeRef = new DataAttributeRef(); SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); @@ -470,7 +486,7 @@ void updateDAI_should_throw_ScdException_when_DataAttributeRef_is_empty() { } @Test - void updateDAI_should_throw_ScdException_when_DataAttributeRef_DA_name_is_not_defined() { + void updateDAI_when_DataAttributeRef_DA_name_is_not_defined_should_throw_ScdException() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); AbstractLNAdapter lnAdapter = findLn0(scd, "IED_NAME", "LD_INS1"); @@ -483,7 +499,7 @@ void updateDAI_should_throw_ScdException_when_DataAttributeRef_DA_name_is_not_de } @Test - void updateDAI_should_throw_ScdException_when_DataAttributeRef_DO_name_is_not_defined() { + void updateDAI_when_DataAttributeRef_DO_name_is_not_defined_should_throw_ScdException() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); AbstractLNAdapter lnAdapter = findLn0(scd, "IED_NAME", "LD_INS1"); @@ -496,7 +512,7 @@ void updateDAI_should_throw_ScdException_when_DataAttributeRef_DO_name_is_not_de } @Test - void updateDAI_should_not_update_DAI_Val_when_DTT_Fc_not_allowed_to_update() { + void updateDAI_when_DTT_Fc_not_allowed_to_update_should_not_update_DAI_Val() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); AbstractLNAdapter lnAdapter = findLn0(scd, "IED_NAME", "LD_INS1"); @@ -517,7 +533,7 @@ void updateDAI_should_not_update_DAI_Val_when_DTT_Fc_not_allowed_to_update() { } @Test - void updateDAI_should_update_DOI_SDI_DAI_that_exists_when_data_updatable() { + void updateDAI_when_data_updatable_should_update_DOI_SDI_DAI_that_exists() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); AbstractLNAdapter lnAdapter = findLn0(scd, "IED_NAME", "LD_INS1"); @@ -533,7 +549,7 @@ void updateDAI_should_update_DOI_SDI_DAI_that_exists_when_data_updatable() { } @Test - void updateDAI_should_update_DOI_DAI_that_exists_when_data_updatable() { + void updateDAI_when_data_updatable_should_update_DOI_DAI_that_exists() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); AbstractLNAdapter lnAdapter = findLn0(scd, "IED_NAME", "LD_INS1"); @@ -549,7 +565,7 @@ void updateDAI_should_update_DOI_DAI_that_exists_when_data_updatable() { } @Test - void updateDAI_should_create_DOI_SDI_DAI_elements_with_new_value_when_data_updatable() { + void updateDAI_when_data_updatable_should_create_DOI_SDI_DAI_elements_with_new_value() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); AbstractLNAdapter lnAdapter = findLn0(scd, "IED_NAME", "LD_INS2"); @@ -565,7 +581,7 @@ void updateDAI_should_create_DOI_SDI_DAI_elements_with_new_value_when_data_updat } @Test - void updateDAI_should_create_DOI_DAI_elements_with_new_value_when_data_updatable() { + void updateDAI_when_data_updatable_should_create_DOI_DAI_elements_with_new_value() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); AbstractLNAdapter lnAdapter = findLn0(scd, "IED_NAME", "LD_INS2"); @@ -582,7 +598,7 @@ void updateDAI_should_create_DOI_DAI_elements_with_new_value_when_data_updatable } @Test - void updateDAI_should_not_update_DAI_values_when_not_updatable() { + void updateDAI_when_not_updatable_should_not_update_DAI_values() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -747,30 +763,34 @@ void updateDAI_with_SDO_and_BDA_when_already_instantiated_should_do_nothing() { } @Test - void testGetDAI() { + void getDAI_should_return_list_of_data_attribute() { + //Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/scd_with_dai_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); LDeviceAdapter lDeviceAdapter = assertDoesNotThrow(() -> iAdapter.findLDeviceAdapterByLdInst("LDSUIED").get()); LNAdapter lnAdapter = lDeviceAdapter.getLNAdapter("PIOC", "1", null); + //When var dataAttributeRefs = lnAdapter.getDAI(new DataAttributeRef(), true); - assertFalse(dataAttributeRefs.isEmpty()); + //Then + assertThat(dataAttributeRefs).isNotEmpty(); } private LNAdapter initLNAdapter(TLN tln) { - LDeviceAdapter lDeviceAdapter = Mockito.mock(LDeviceAdapter.class); - TLDevice tlDevice = Mockito.mock(TLDevice.class); - Mockito.when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); + LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); + TLDevice tlDevice = mock(TLDevice.class); + when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); tln.getLnClass().add(DTO.HOLDER_LN_CLASS); tln.setInst(DTO.HOLDER_LN_INST); tln.setLnType(DTO.LN_TYPE); tln.setPrefix(DTO.HOLDER_LN_PREFIX); - Mockito.when(tlDevice.getLN()).thenReturn(List.of(tln)); + when(tlDevice.getLN()).thenReturn(List.of(tln)); return assertDoesNotThrow(() -> new LNAdapter(lDeviceAdapter, tln)); } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + //Given SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/scd_with_dai_test.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); IEDAdapter iAdapter = assertDoesNotThrow(() -> sclRootAdapter.getIEDAdapterByName("IED_NAME")); @@ -779,13 +799,15 @@ void addPrivate() { TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(lnAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(lnAdapter.getCurrentElem().getPrivate()).isEmpty(); + //When lnAdapter.addPrivate(tPrivate); - assertEquals(1, lnAdapter.getCurrentElem().getPrivate().size()); + //Then + assertThat( lnAdapter.getCurrentElem().getPrivate()).hasSize(1); } @Test - void elementXPath() { + void elementXPath_should_return_expected_xpath_value() { // Given TLN tln = new TLN(); LNAdapter lnAdapter = initLNAdapter(tln); @@ -829,7 +851,7 @@ void getTControlsByType_should_return_list_of_report_control_blocks() { @ParameterizedTest @MethodSource("provideGetTControlsByTypeException") - void getTControlsByType_should_throw_when_unsupported_controlBlock_for_ln(Class tControlClass) { + void getTControlsByType_when_unsupported_controlBlock_for_ln_should_throwException(Class tControlClass) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); LNAdapter lnAdapter = findLn(scd, "IED4d4fe1a8cda64cf88a5ee4176a1a0eef", "LDSUIED", "LPAI", "1", null); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java index 4148e4934..f7bc68044 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/RootSDIAdapterTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.ied; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.TDAI; import org.lfenergy.compas.scl2007b4.model.TDOI; @@ -12,60 +13,80 @@ import org.lfenergy.compas.sct.commons.exception.ScdException; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; class RootSDIAdapterTest { + @Test + @Tag("issue-321") void testConstructor() { + //Given TDOI doi = new TDOI(); doi.setName("Do"); DOIAdapter doiAdapter = new DOIAdapter(null,doi); TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); doi.getSDIOrDAI().add(tsdi); + //When Then RootSDIAdapter rootSDIAdapter = assertDoesNotThrow(() -> new RootSDIAdapter(doiAdapter,tsdi)); - // test tree map TSDI tSdi2 = new TSDI(); tSdi2.setName("sdo2"); tsdi.getSDIOrDAI().add(tSdi2); - assertDoesNotThrow(() -> rootSDIAdapter.getStructuredDataAdapterByName("sdo2")); - assertThrows(ScdException.class, () -> rootSDIAdapter.getStructuredDataAdapterByName("sdo3")); + //When Then + assertThatCode(() -> rootSDIAdapter.getStructuredDataAdapterByName("sdo2")) + .doesNotThrowAnyException(); + //When Then + assertThatCode(() -> rootSDIAdapter.getStructuredDataAdapterByName("sdo3")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown SDI (sdo3) in this DOI or SDI (sdo1)"); TDAI tdai = new TDAI(); tdai.setName("angRef"); tsdi.getSDIOrDAI().add(tdai); - assertDoesNotThrow(() -> rootSDIAdapter.getDataAdapterByName("angRef")); - assertThrows(ScdException.class, () -> rootSDIAdapter.getStructuredDataAdapterByName("bda")); - assertThrows(ScdException.class, () -> rootSDIAdapter.getDataAdapterByName("bda")); + //When Then + assertThatCode(() -> rootSDIAdapter.getDataAdapterByName("angRef")).doesNotThrowAnyException(); + //When Then + assertThatCode(() -> rootSDIAdapter.getStructuredDataAdapterByName("bda")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown SDI (bda) in this DOI or SDI (sdo1)"); + //When Then + assertThatCode(() -> rootSDIAdapter.getDataAdapterByName("bda")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown DAI (bda) in this SDI (sdo1)"); } @Test - void testInnerDAIAdapter(){ + void innerDAIAdapter_should_not_throw_exception(){ + //Given TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); RootSDIAdapter rootSDIAdapter = new RootSDIAdapter(null,tsdi); - TDAI tdai = new TDAI(); tdai.setName("angRef"); tsdi.getSDIOrDAI().add(tdai); - RootSDIAdapter.DAIAdapter daiAdapter = assertDoesNotThrow(() -> new RootSDIAdapter.DAIAdapter(rootSDIAdapter,tdai)); + //When Then + assertThatCode(() -> new RootSDIAdapter.DAIAdapter(rootSDIAdapter,tdai)).doesNotThrowAnyException(); } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + //Given TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); RootSDIAdapter rootSDIAdapter = new RootSDIAdapter(null,tsdi); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(rootSDIAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(rootSDIAdapter.getCurrentElem().getPrivate()).isEmpty(); + //When rootSDIAdapter.addPrivate(tPrivate); - assertEquals(1, rootSDIAdapter.getCurrentElem().getPrivate().size()); + //Then + assertThat(rootSDIAdapter.getCurrentElem().getPrivate()).hasSize(1); } @Test - void elementXPath_sdi() { + void rootSDIAdapter_elementXPath_should_return_expected_xpath_value() { // Given TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); @@ -77,15 +98,16 @@ void elementXPath_sdi() { } @Test - void elementXPath_dai() { + @Tag("issue-321") + void daiAdapter_elementXPath_should_return_expected_xpath_value() { // Given TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); RootSDIAdapter rootSDIAdapter = new RootSDIAdapter(null,tsdi); - TDAI tdai = new TDAI(); tdai.setName("angRef"); tsdi.getSDIOrDAI().add(tdai); + // When Then RootSDIAdapter.DAIAdapter daiAdapter = assertDoesNotThrow(() -> new RootSDIAdapter.DAIAdapter(rootSDIAdapter,tdai)); // When String result = daiAdapter.elementXPath(); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java index 00095e2d4..16663bae2 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/SDIAdapterTest.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.sct.commons.scl.ied; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -12,67 +13,84 @@ import org.lfenergy.compas.scl2007b4.model.TSDI; import org.lfenergy.compas.sct.commons.exception.ScdException; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; class SDIAdapterTest { + @Test + @Tag("issue-321") void testConstructor() { + //Given TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); RootSDIAdapter rootSDIAdapter = new RootSDIAdapter(null,tsdi); - TSDI tSdi1 = new TSDI(); tSdi1.setName("sdo2"); tsdi.getSDIOrDAI().add(tSdi1); - // test amChildElement + //When Then SDIAdapter sdiAdapter = assertDoesNotThrow(() -> new SDIAdapter(rootSDIAdapter,tSdi1)); - // test tree map TSDI tSdi2 = new TSDI(); tSdi2.setName("sdo2"); tSdi1.getSDIOrDAI().add(tSdi2); - assertDoesNotThrow(() -> sdiAdapter.getStructuredDataAdapterByName("sdo2")); - assertThrows(ScdException.class, () -> sdiAdapter.getStructuredDataAdapterByName("sdo3")); + //When Then + assertThatCode(() -> sdiAdapter.getStructuredDataAdapterByName("sdo2")) + .doesNotThrowAnyException(); + //When Then + assertThatCode(() -> sdiAdapter.getStructuredDataAdapterByName("sdo3")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown SDI (sdo3) in this DOI or SDI (sdo2)"); TDAI tdai = new TDAI(); tdai.setName("angRef"); tSdi1.getSDIOrDAI().add(tdai); - assertDoesNotThrow(() -> sdiAdapter.getDataAdapterByName("angRef")); - assertThrows(ScdException.class, () -> sdiAdapter.getStructuredDataAdapterByName("bda")); - assertThrows(ScdException.class, () -> sdiAdapter.getDataAdapterByName("bda")); + //When Then + assertThatCode(() -> sdiAdapter.getDataAdapterByName("angRef")).doesNotThrowAnyException(); + //When Then + assertThatCode(() -> sdiAdapter.getStructuredDataAdapterByName("bda")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown SDI (bda) in this DOI or SDI (sdo2)"); + //When Then + assertThatCode(() -> sdiAdapter.getDataAdapterByName("bda")) + .isInstanceOf(ScdException.class) + .hasMessageContaining("Unknown DAI (bda) in this SDI (sdo2)"); } @Test - void testInnerDAIAdapter(){ + @Tag("issue-321") + void innerDAIAdapter_should_not_throw_exception(){ + //Given TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); + //When SDIAdapter sdiAdapter = new SDIAdapter(null,tsdi); - TDAI tdai = new TDAI(); tdai.setName("angRef"); tsdi.getSDIOrDAI().add(tdai); - SDIAdapter.DAIAdapter daiAdapter = assertDoesNotThrow(() -> new SDIAdapter.DAIAdapter(sdiAdapter,tdai)); - + //When Then + assertDoesNotThrow(() -> new SDIAdapter.DAIAdapter(sdiAdapter,tdai)); } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + //Given TSDI tsdi = new TSDI(); tsdi.setName("sdo1"); SDIAdapter sdiAdapter = new SDIAdapter(null,tsdi); TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(sdiAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(sdiAdapter.getCurrentElem().getPrivate()).isEmpty(); + //When sdiAdapter.addPrivate(tPrivate); - assertEquals(1, sdiAdapter.getCurrentElem().getPrivate().size()); + //Then + assertThat(sdiAdapter.getCurrentElem().getPrivate()).hasSize(1); } @ParameterizedTest - @CsvSource(value = {"sdo1;SDI[@name=\"sdo1\"]", ";SDI[not(@name)]"} - , delimiter = ';') - void elementXPath(String sdo, String message) { + @CsvSource(value = {"sdo1;SDI[@name=\"sdo1\"]", ";SDI[not(@name)]"}, delimiter = ';') + void elementXPath_should_return_expected_xpath_value(String sdo, String message) { // Given TSDI tsdi = new TSDI(); tsdi.setName(sdo); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/BayAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/BayAdapterTest.java index e36aab2c9..abe24d50b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/BayAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/BayAdapterTest.java @@ -8,71 +8,92 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.exception.ScdException; -import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class BayAdapterTest { + private final VoltageLevelAdapter vLevelAdapter = mock(VoltageLevelAdapter.class); private BayAdapter bayAdapter; - private VoltageLevelAdapter vLevelAdapter; - @BeforeEach - public void init() throws ScdException { - SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); + @BeforeEach + public void init() { TSubstation tSubstation = new TSubstation(); tSubstation.setName("SUBSTATION"); - sclRootAdapter.getCurrentElem().getSubstation().add(tSubstation); - SubstationAdapter ssAdapter = sclRootAdapter.getSubstationAdapter("SUBSTATION"); TVoltageLevel tVoltageLevel = new TVoltageLevel(); tVoltageLevel.setName("VOLTAGE_LEVEL"); - ssAdapter.getCurrentElem().getVoltageLevel().add(tVoltageLevel); - vLevelAdapter = ssAdapter.getVoltageLevelAdapter("VOLTAGE_LEVEL").get(); TBay tBay = new TBay(); tBay.setName("BAY"); tBay.getFunction().add(new TFunction()); - vLevelAdapter.getCurrentElem().getBay().add(tBay); - bayAdapter = vLevelAdapter.getBayAdapter("BAY").get(); + tVoltageLevel.getBay().add(tBay); + tSubstation.getVoltageLevel().add(tVoltageLevel); + when(vLevelAdapter.getCurrentElem()).thenReturn(tVoltageLevel); + bayAdapter = new BayAdapter(vLevelAdapter, tBay); + } + + @Test + void amChildElementRef_whenCalledWithExistingRelationBetweenVoltageLevelAndBay_shouldReturnTrue() { + // Given : init + // When Then + assertThat(bayAdapter.amChildElementRef()).isTrue(); } @Test - void testAmChildElementRef() { - assertTrue(bayAdapter.amChildElementRef()); + void amChildElementRef_when_no_Bay_given_should_return_false() { + // When + BayAdapter bayAdapter1 = new BayAdapter(vLevelAdapter); + // Then + assertThat(bayAdapter1.getParentAdapter()).isNotNull(); + assertThat(bayAdapter1.getCurrentElem()).isNull(); + assertThat(bayAdapter1.amChildElementRef()).isFalse(); } + @Test - void testController() { - BayAdapter expectedBayAdapter = new BayAdapter(vLevelAdapter); - assertNotNull(expectedBayAdapter.getParentAdapter()); - assertNull(expectedBayAdapter.getCurrentElem()); - assertFalse(expectedBayAdapter.amChildElementRef()); + void constructor_whenCalledWithUnknown_shouldThrowException() { + // When Then + assertThatCode(() -> new BayAdapter(vLevelAdapter, "BAY_1")) + .isInstanceOf(ScdException.class) + .hasMessage("Unknown Bay name :BAY_1"); } @Test - void testControllerWithVoltageLevelName() { - assertThrows(ScdException.class, - () -> new BayAdapter(vLevelAdapter, "BAY_1")); + void constructor_whenCalledKnownVoltageLevelName_shouldNotThrowException() { + // Given + TBay tBay = new TBay(); + tBay.setName("BAY_1"); + vLevelAdapter.getCurrentElem().getBay().add(tBay); + // When Then + assertThatCode(() -> new BayAdapter(vLevelAdapter, "BAY_1")).doesNotThrowAnyException(); } @Test - void testSetCurrentElemInAdapter() { + void setCurrentElement_whenCalledWithNoRelationBetweenVoltageLevelAndBay_shouldThrowException() { + // Given TBay tBay1 = new TBay(); - assertThrows(IllegalArgumentException.class, - () ->bayAdapter.setCurrentElem(tBay1)); + // When Then + assertThatThrownBy(() -> bayAdapter.setCurrentElem(tBay1)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + // Given TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(bayAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(bayAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When bayAdapter.addPrivate(tPrivate); - assertEquals(1, bayAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(bayAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test @@ -81,7 +102,7 @@ void elementXPath_should_succeed() { // When String result = bayAdapter.elementXPath(); // Then - assertEquals("Bay[@name=\"BAY\"]", result); + assertThat(result).isEqualTo("Bay[@name=\"BAY\"]"); } @Test @@ -91,15 +112,15 @@ void elementXPath_when_name_is_missing_should_succeed() { // When String result = bayAdapter.elementXPath(); // Then - assertEquals("Bay[not(@name)]", result); + assertThat(result).isEqualTo("Bay[not(@name)]"); } @Test - void streamFunctionAdapters() { + void streamFunctionAdapters_should_return_expected_list() { // Given : init // When Stream result = bayAdapter.streamFunctionAdapters(); // Then - assertEquals(1, result.count()); + assertThat(result).hasSize(1); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/FunctionAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/FunctionAdapterTest.java index 95fb84948..246f1889b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/FunctionAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/FunctionAdapterTest.java @@ -10,18 +10,21 @@ import org.lfenergy.compas.scl2007b4.model.TFunction; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class FunctionAdapterTest { + private final BayAdapter bayAdapter = mock(BayAdapter.class); private FunctionAdapter functionAdapter; @BeforeEach void setUp() { TBay tBay = new TBay(); - BayAdapter bayAdapter = new BayAdapter(null, tBay); TFunction tFunction = new TFunction(); tFunction.setName("functionName"); tBay.getFunction().add(tFunction); + when(bayAdapter.getCurrentElem()).thenReturn(tBay); functionAdapter = new FunctionAdapter(bayAdapter, tFunction); } @@ -35,7 +38,7 @@ void amChildElementRef_should_succeed() { } @Test - void amChildElementRef_when_parent_does_not_contain_function_should_be_false() { + void amChildElementRef_when_parent_does_not_contain_function_shouldReturnFalse() { // Given : setUp functionAdapter.getParentAdapter().getCurrentElem().getFunction().clear(); // When @@ -45,7 +48,7 @@ void amChildElementRef_when_parent_does_not_contain_function_should_be_false() { } @Test - void elementXPath() { + void elementXPath_should_return_expected_xpath_value() { // Given : setUp // When String result = functionAdapter.elementXPath(); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/LNodeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/LNodeAdapterTest.java index 106b69ada..2af5b52a8 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/LNodeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/LNodeAdapterTest.java @@ -4,7 +4,6 @@ package org.lfenergy.compas.sct.commons.scl.sstation; -import jakarta.xml.bind.JAXBElement; import org.junit.jupiter.api.Test; import org.junit.platform.commons.support.HierarchyTraversalMode; import org.junit.platform.commons.support.ReflectionSupport; @@ -56,18 +55,18 @@ void constructor_when_LNode_is_not_child_of_parent_should_throw_exception() { } @Test - void addPrivate_should_succeed() { + void addPrivate_with_type_and_source_should_create_Private() { // Given TLNode tlNode = new TLNode(); LNodeAdapter lNodeAdapter = new LNodeAdapter(null, tlNode); - TPrivate tPrivate = PrivateUtils.createPrivate(TCompasSclFileType.SCD); + assertThat(tlNode.getPrivate()).isEmpty(); + TPrivate tPrivate = new TPrivate(); + tPrivate.setType("Private Type"); + tPrivate.setSource("Private Source"); // When lNodeAdapter.addPrivate(tPrivate); // Then assertThat(tlNode.getPrivate()).hasSize(1); - assertThat(tlNode.getPrivate().get(0).getContent()).hasSize(1).first().isInstanceOf(JAXBElement.class); - JAXBElement jaxbElement = (JAXBElement) tlNode.getPrivate().get(0).getContent().get(0); - assertThat(jaxbElement.getValue()).isEqualTo(TCompasSclFileType.SCD); } @Test diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java index e54e39756..f7d1abdc2 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/SubstationAdapterTest.java @@ -11,86 +11,101 @@ import org.lfenergy.compas.scl2007b4.model.TPrivate; import org.lfenergy.compas.scl2007b4.model.TSubstation; import org.lfenergy.compas.scl2007b4.model.TVoltageLevel; -import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class SubstationAdapterTest { - private SclRootAdapter sclRootAdapter; - private SubstationAdapter ssAdapter; + private final SclRootAdapter sclRootAdapter = mock(SclRootAdapter.class);; + private SubstationAdapter substationAdapter; @BeforeEach - public void init() throws ScdException { - sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); + public void init() { + SCL scl = new SCL(); TSubstation tSubstation = new TSubstation(); tSubstation.setName("SUBSTATION"); - sclRootAdapter.getCurrentElem().getSubstation().add(tSubstation); - ssAdapter = sclRootAdapter.getSubstationAdapter("SUBSTATION"); + scl.getSubstation().add(tSubstation); + when(sclRootAdapter.getCurrentElem()).thenReturn(scl); + substationAdapter = new SubstationAdapter(sclRootAdapter, tSubstation); } @Test - void testAmChildElementRef() { - assertTrue(ssAdapter.amChildElementRef()); + void amChildElementRef_whenCalledWithExistingRelationBetweenSCLAndSubstation_shouldReturnTrue() { + // Given : init + // When Then + assertThat(substationAdapter.amChildElementRef()).isTrue(); } @Test - void testController() { - SubstationAdapter expectedSubstationAdapter = new SubstationAdapter(sclRootAdapter, sclRootAdapter.getCurrentElem().getSubstation().get(0)); - assertNotNull(expectedSubstationAdapter.getParentAdapter()); - assertNotNull(expectedSubstationAdapter.getCurrentElem()); - assertTrue(expectedSubstationAdapter.amChildElementRef()); + void amChildElementRef_when_no_Substation_given_should_return_false() { + // When + SubstationAdapter substationAdapter1 = new SubstationAdapter(sclRootAdapter); + // Then + assertThat(substationAdapter1.getParentAdapter()).isNotNull(); + assertThat(substationAdapter1.getCurrentElem()).isNull(); + assertThat(substationAdapter1.amChildElementRef()).isFalse(); } @Test - void testSetCurrentElement() { - SubstationAdapter ssfAdapter = new SubstationAdapter(sclRootAdapter); + void setCurrentElement_whenCalledWithNoRelationBetweenSCLAndSubstation_shouldThrowException() { + // Given TSubstation tSubstation1 = new TSubstation(); - assertThrows(IllegalArgumentException.class, - () ->ssfAdapter.setCurrentElem(tSubstation1)); + // When Then + assertThatThrownBy(() -> substationAdapter.setCurrentElem(tSubstation1)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } @Test - void testGetSubstationAdapter() { - assertThrows(ScdException.class, - () -> sclRootAdapter.getSubstationAdapter("SUBSTATION1")); + void getVoltageLevelAdapter_when_exist_should_return_not_empty_list_of_VoltageLevelAdapter() { + // Given + TVoltageLevel tVoltageLevel = new TVoltageLevel(); + tVoltageLevel.setName("VOLTAGE_LEVEL1"); + substationAdapter.getCurrentElem().getVoltageLevel().add(tVoltageLevel); + //When Then + assertThat(substationAdapter.getVoltageLevelAdapter("VOLTAGE_LEVEL1")).isNotEmpty(); } @Test - void testGetVoltageLevelAdapter() { - TVoltageLevel tVoltageLevel = new TVoltageLevel(); - tVoltageLevel.setName("VOLTAGE_LEVEL"); - ssAdapter.getCurrentElem().getVoltageLevel().add(tVoltageLevel); - assertFalse(ssAdapter.getVoltageLevelAdapter("VOLTAGE_LEVEL1").isPresent()); + void getVoltageLevelAdapter_when_not_exist_should_return_empty_list_of_VoltageLevelAdapter() { + // Given : init + //When Then + assertThat(substationAdapter.getVoltageLevelAdapter("VOLTAGE_LEVEL1")).isEmpty(); } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + // Given TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(ssAdapter.getCurrentElem().getPrivate().isEmpty()); - ssAdapter.addPrivate(tPrivate); - assertEquals(1, ssAdapter.getCurrentElem().getPrivate().size()); + assertThat(substationAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When + substationAdapter.addPrivate(tPrivate); + // Then + assertThat(substationAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } @Test - void getIedAndLDeviceNamesForLN0FromLNode_shouldReturnListOf1Pair_WhenLNodeContainsLN0() throws Exception { + void getIedAndLDeviceNamesForLN0FromLNode_whenLNodeContainsLN0_shouldReturnListOf1Pair() { // Given SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_Template.scd"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scl); - SubstationAdapter substationAdapter = sclRootAdapter.getSubstationAdapter(); + substationAdapter = sclRootAdapter.getSubstationAdapter(); // When List> iedNameLdInstList = substationAdapter.getIedAndLDeviceNamesForLN0FromLNode(); // Then - assertEquals(1, iedNameLdInstList.size()); - assertThat(iedNameLdInstList).containsExactly(Pair.of("IedName1", "LDSUIED")); + assertThat(iedNameLdInstList) + .hasSize(1) + .containsExactly(Pair.of("IedName1", "LDSUIED")); } } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/VoltageLevelAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/VoltageLevelAdapterTest.java index 72d081c1e..1ba4ce996 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/VoltageLevelAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/sstation/VoltageLevelAdapterTest.java @@ -6,75 +6,88 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl2007b4.model.TBay; -import org.lfenergy.compas.scl2007b4.model.TPrivate; -import org.lfenergy.compas.scl2007b4.model.TSubstation; -import org.lfenergy.compas.scl2007b4.model.TVoltageLevel; -import org.lfenergy.compas.sct.commons.exception.ScdException; -import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.scl2007b4.model.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class VoltageLevelAdapterTest { + private final SubstationAdapter substationAdapter = mock(SubstationAdapter.class); private VoltageLevelAdapter vLevelAdapter; - private SubstationAdapter ssAdapter; @BeforeEach - public void init() throws ScdException { - SclRootAdapter sclRootAdapter = new SclRootAdapter("hID","hVersion","hRevision"); + public void init() { TSubstation tSubstation = new TSubstation(); tSubstation.setName("SUBSTATION"); - sclRootAdapter.getCurrentElem().getSubstation().add(tSubstation); - ssAdapter = sclRootAdapter.getSubstationAdapter("SUBSTATION"); TVoltageLevel tVoltageLevel = new TVoltageLevel(); tVoltageLevel.setName("VOLTAGE_LEVEL"); - ssAdapter.getCurrentElem().getVoltageLevel().add(tVoltageLevel); - vLevelAdapter = ssAdapter.getVoltageLevelAdapter("VOLTAGE_LEVEL") - .orElse(new VoltageLevelAdapter(ssAdapter, "VOLTAGE_LEVEL")); + tSubstation.getVoltageLevel().add(tVoltageLevel); + when(substationAdapter.getCurrentElem()).thenReturn(tSubstation); + vLevelAdapter = new VoltageLevelAdapter(substationAdapter, tVoltageLevel); } @Test - void testController() { - VoltageLevelAdapter expectedTVoltageLevel = new VoltageLevelAdapter(ssAdapter); - assertNotNull(expectedTVoltageLevel.getParentAdapter()); - assertNull(expectedTVoltageLevel.getCurrentElem()); - assertFalse(expectedTVoltageLevel.amChildElementRef()); + void amChildElementRef_whenCalledWithExistingRelationBetweenSubstationAndVoltageLevel_shouldReturnTrue() { + // Given : init + // When Then + assertThat(vLevelAdapter.amChildElementRef()).isTrue(); } @Test - void testControllerWithVoltageLevelName(){ - assertThrows(ScdException.class, - () -> new VoltageLevelAdapter(ssAdapter, "VOLTAGE_LEVEL_1")); + void amChildElementRef_when_no_VoltageLevel_given_should_return_false() { + // When + VoltageLevelAdapter voltageLevelAdapter = new VoltageLevelAdapter(substationAdapter); + // Then + assertThat(voltageLevelAdapter.getParentAdapter()).isNotNull(); + assertThat(voltageLevelAdapter.getCurrentElem()).isNull(); + assertThat(voltageLevelAdapter.amChildElementRef()).isFalse(); } @Test - void testAmChildElementRef() { - assertTrue(vLevelAdapter.amChildElementRef()); + void setCurrentElement_whenCalledWithNoRelationBetweenSubstationAndVoltageLevel_shouldThrowException() { + // Given + TVoltageLevel tVoltageLevel1 = new TVoltageLevel(); + // When Then + assertThatThrownBy(() -> vLevelAdapter.setCurrentElem(tVoltageLevel1)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No relation between SCL parent element and child"); } + @Test - void testSetCurrentElemInAdapter() { - TVoltageLevel tVoltageLevel1 = new TVoltageLevel(); - assertThrows(IllegalArgumentException.class, - () ->vLevelAdapter.setCurrentElem(tVoltageLevel1)); + void getBayAdapter_when_no_BayAdapter_exist_should_return_empty() { + // Given + TBay tBay = new TBay(); + tBay.setName("BAY"); + vLevelAdapter.getCurrentElem().getBay().add(tBay); + // When Then + assertThat(vLevelAdapter.getBayAdapter("BAY1")).isEmpty(); } + @Test - void testGetBayAdapter() { + void getBayAdapter_when_exist_should_return_expected_BayAdapter() { + // Given TBay tBay = new TBay(); tBay.setName("BAY"); vLevelAdapter.getCurrentElem().getBay().add(tBay); - assertFalse(vLevelAdapter.getBayAdapter("BAY1").isPresent()); + // When Then + assertThat(vLevelAdapter.getBayAdapter("BAY")).isPresent(); } @Test - void addPrivate() { + void addPrivate_with_type_and_source_should_create_Private() { + // Given TPrivate tPrivate = new TPrivate(); tPrivate.setType("Private Type"); tPrivate.setSource("Private Source"); - assertTrue(vLevelAdapter.getCurrentElem().getPrivate().isEmpty()); + assertThat(vLevelAdapter.getCurrentElem().getPrivate()).isEmpty(); + // When vLevelAdapter.addPrivate(tPrivate); - assertEquals(1, vLevelAdapter.getCurrentElem().getPrivate().size()); + // Then + assertThat(vLevelAdapter.getCurrentElem().getPrivate()).isNotEmpty(); } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/ControlBlockEnumTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/ControlBlockEnumTest.java index 2f1264397..7aa300377 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/ControlBlockEnumTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/ControlBlockEnumTest.java @@ -4,7 +4,6 @@ package org.lfenergy.compas.sct.commons.util; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -13,6 +12,9 @@ import java.util.stream.Stream; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThat; + class ControlBlockEnumTest { @ParameterizedTest @@ -22,7 +24,7 @@ void from_should_map_ServiceType_to_ControlBlockEnumTest(TServiceType tServiceTy //When ControlBlockEnum result = ControlBlockEnum.from(tServiceType); //Then - Assertions.assertThat(result).isEqualTo(expected); + assertThat(result).isEqualTo(expected); } @Test @@ -30,7 +32,7 @@ void from_POOL_should_throw_exception() { //Given TServiceType pollServiceType = TServiceType.POLL; //When & Then - Assertions.assertThatThrownBy(() -> ControlBlockEnum.from(pollServiceType)) + assertThatThrownBy(() -> ControlBlockEnum.from(pollServiceType)) .isInstanceOf(IllegalArgumentException.class); } @@ -41,7 +43,7 @@ void from_should_map_Class_to_ControlBlockEnumTest(Class tCo //When ControlBlockEnum result = ControlBlockEnum.from(tControlClass); //Then - Assertions.assertThat(result).isEqualTo(expected); + assertThat(result).isEqualTo(expected); } public static Stream provideFromTControlClass() { diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/LdeviceStatusEnumTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/LdeviceStatusEnumTest.java index ad226b1e2..e7d9f48ef 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/LdeviceStatusEnumTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/LdeviceStatusEnumTest.java @@ -15,7 +15,7 @@ class LdeviceStatusEnumTest { @ParameterizedTest @CsvSource({"on,ON", "off,OFF"}) - void fromValue(String ldeviceStatus, String expected) { + void fromValue_withKnownStatus_shouldNotThrowException(String ldeviceStatus, String expected) { //Given //When LdeviceStatus ldeviceStatusEnum = LdeviceStatus.fromValue(ldeviceStatus); @@ -24,7 +24,7 @@ void fromValue(String ldeviceStatus, String expected) { } @Test - void fromValue() { + void fromValue_withUnknownStatus_shouldThrowException() { //Given String ldeviceStatus = "patate"; //When diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java index 2f8e3e13f..d2efb9f62 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java @@ -6,6 +6,7 @@ import jakarta.xml.bind.JAXBElement; 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.MethodSource; @@ -24,7 +25,6 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; class PrivateUtilsTest { @@ -223,7 +223,7 @@ void removePrivates_should_remove_privates() { } @Test - void removePrivates_should_do_nothing_when_no_private_match_type() { + void removePrivates_when_no_private_match_type_should_do_nothing() { // Given : setUp TBaseElement baseElement = new SCL(); baseElement.getPrivate().add(privateSCD); @@ -234,11 +234,13 @@ void removePrivates_should_do_nothing_when_no_private_match_type() { } @Test + @Tag("issue-321") void removePrivates_should_remove_privates_of_given_type() { // Given : setUp TBaseElement baseElement = new SCL(); baseElement.getPrivate().add(privateSCD); TCompasICDHeader tCompasICDHeader = objectFactory.createTCompasICDHeader(); + // When baseElement.getPrivate().add(PrivateUtils.createPrivate(tCompasICDHeader)); // When PrivateUtils.removePrivates(baseElement, PrivateEnum.COMPAS_ICDHEADER); @@ -264,11 +266,13 @@ void removePrivates_should_not_set_private() { } @Test - void createMapICDSystemVersionUuidAndSTDFile_Should_return_empty_map_when_no_ICDSystemVersionUUID() { + @Tag("issue-321") + void createMapICDSystemVersionUuidAndSTDFile_when_no_ICDSystemVersionUUID_should_return_empty_map() { //Given SCL scl1 = new SCL(); TIED tied1 = new TIED(); TCompasICDHeader compasICDHeader1 = new TCompasICDHeader(); + //When TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); tied1.getPrivate().add(tPrivate1); scl1.getIED().add(tied1); @@ -282,6 +286,7 @@ void createMapICDSystemVersionUuidAndSTDFile_Should_return_empty_map_when_no_ICD } @Test + @Tag("issue-321") void createMapICDSystemVersionUuidAndSTDFile_Should_return_map_with_two_lines() { //Given SCL scl1 = new SCL(); @@ -296,9 +301,12 @@ void createMapICDSystemVersionUuidAndSTDFile_Should_return_map_with_two_lines() compasICDHeader2.setICDSystemVersionUUID("UUID-2"); TCompasICDHeader compasICDHeader3 = new TCompasICDHeader(); compasICDHeader3.setICDSystemVersionUUID("UUID-2"); - TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); - TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); - TPrivate tPrivate3 = PrivateUtils.createPrivate(compasICDHeader3); + //When + TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); + //When + TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); + //When + TPrivate tPrivate3 = PrivateUtils.createPrivate(compasICDHeader3); tied1.getPrivate().add(tPrivate1); tied2.getPrivate().add(tPrivate2); tied3.getPrivate().add(tPrivate3); @@ -315,6 +323,7 @@ void createMapICDSystemVersionUuidAndSTDFile_Should_return_map_with_two_lines() } @Test + @Tag("issue-321") void checkSTDCorrespondanceWithLNodeCompasICDHeadershoul_throw_scdEception(){ //Given TCompasICDHeader compasICDHeader1 = new TCompasICDHeader(); @@ -324,8 +333,10 @@ void checkSTDCorrespondanceWithLNodeCompasICDHeadershoul_throw_scdEception(){ compasICDHeader2.setHeaderId("ID-2"); compasICDHeader2.setHeaderVersion("VER-2"); compasICDHeader2.setHeaderRevision("REV-2"); - TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); - TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); + //When + TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); + //When + TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); PrivateLinkedToStds privateLinkedToSTDs1 = new PrivateLinkedToStds(tPrivate1,Collections.singletonList(new SCL())); PrivateLinkedToStds privateLinkedToSTDs2 = new PrivateLinkedToStds(tPrivate2, Arrays.asList(new SCL(), new SCL())); @@ -342,14 +353,17 @@ void checkSTDCorrespondanceWithLNodeCompasICDHeadershoul_throw_scdEception(){ } @Test + @Tag("issue-321") void checkSTDCorrespondanceWithLNodeCompasICDHeader_should_pass(){ //Given TCompasICDHeader compasICDHeader1 = new TCompasICDHeader(); compasICDHeader1.setICDSystemVersionUUID("UUID-1"); TCompasICDHeader compasICDHeader2 = new TCompasICDHeader(); compasICDHeader2.setICDSystemVersionUUID("UUID-2"); - TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); - TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); + //When + TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); + //When + TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); PrivateLinkedToStds privateLinkedToSTDs1 = new PrivateLinkedToStds(tPrivate1,Collections.singletonList(new SCL())); PrivateLinkedToStds privateLinkedToSTDs2 = new PrivateLinkedToStds(tPrivate2, Collections.singletonList(new SCL())); @@ -359,11 +373,13 @@ void checkSTDCorrespondanceWithLNodeCompasICDHeader_should_pass(){ stringSCLMap.put("UUID-2", privateLinkedToSTDs2); //When Then - assertDoesNotThrow(() -> PrivateUtils.checkSTDCorrespondanceWithLNodeCompasICDHeader(stringSCLMap)); + assertThatCode(() -> PrivateUtils.checkSTDCorrespondanceWithLNodeCompasICDHeader(stringSCLMap)) + .doesNotThrowAnyException(); } @Test + @Tag("issue-321") void stdCheckFormatExceptionMessage_should_return_formatted_message_with_Private_data() { //Given TCompasICDHeader compasICDHeader = new TCompasICDHeader(); @@ -381,6 +397,7 @@ void stdCheckFormatExceptionMessage_should_return_formatted_message_with_Private } @Test + @Tag("issue-321") void createMapIEDNameAndPrivate_should_return_map_of_three_items() { //Given SCL scl = new SCL(); @@ -393,9 +410,12 @@ void createMapIEDNameAndPrivate_should_return_map_of_three_items() { compasICDHeader2.setIEDName("IED-2"); TCompasICDHeader compasICDHeader3 = new TCompasICDHeader(); compasICDHeader3.setIEDName("IED-3"); - TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); - TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); - TPrivate tPrivate3 = PrivateUtils.createPrivate(compasICDHeader3); + //When + TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); + //When + TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); + //When + TPrivate tPrivate3 = PrivateUtils.createPrivate(compasICDHeader3); tlNode1.getPrivate().add(tPrivate1); tlNode2.getPrivate().add(tPrivate2); tlNode3.getPrivate().add(tPrivate3); @@ -420,12 +440,14 @@ void createMapIEDNameAndPrivate_should_return_map_of_three_items() { } @Test - void createMapIEDNameAndPrivate_should_return_empty_map_when_no_compasicdheader_present_under_substation() { + @Tag("issue-321") + void createMapIEDNameAndPrivate_when_no_compasIcdHeaderPresent_under_substation_should_return_empty_map() { //Given SCL scl = new SCL(); TLNode tlNode1 = new TLNode(); TCompasBay compasBay = new TCompasBay(); compasBay.setUUID("UUID"); + //When TPrivate tPrivate1 = PrivateUtils.createPrivate(compasBay); tlNode1.getPrivate().add(tPrivate1); TFunction tFunction = new TFunction(); @@ -446,6 +468,7 @@ void createMapIEDNameAndPrivate_should_return_empty_map_when_no_compasicdheader_ } @Test + @Tag("issue-321") void comparePrivateCompasICDHeaders_should_return_true_equality_not_check_for_IEDNane_BayLabel_IEDinstance() { // Given TCompasICDHeader compasICDHeader1 = new TCompasICDHeader(); @@ -453,8 +476,10 @@ void comparePrivateCompasICDHeaders_should_return_true_equality_not_check_for_IE compasICDHeader1.setBayLabel("BAY-1"); compasICDHeader1.setIEDSubstationinstance(BigInteger.ONE); TCompasICDHeader compasICDHeader2 = new TCompasICDHeader(); - TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); - TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); + // When + TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); + // When + TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); // When boolean result = PrivateUtils.comparePrivateCompasICDHeaders(tPrivate1,tPrivate2); @@ -463,6 +488,7 @@ void comparePrivateCompasICDHeaders_should_return_true_equality_not_check_for_IE } @Test + @Tag("issue-321") void comparePrivateCompasICDHeaders_should_return_false_equality_not_check_for_IEDNane_BayLabel_IEDinstance() { // Given TCompasICDHeader compasICDHeader1 = new TCompasICDHeader(); @@ -472,8 +498,10 @@ void comparePrivateCompasICDHeaders_should_return_false_equality_not_check_for_I compasICDHeader1.setICDSystemVersionUUID("UUID-1"); TCompasICDHeader compasICDHeader2 = new TCompasICDHeader(); compasICDHeader2.setICDSystemVersionUUID("UUID-2"); - TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); - TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); + // When + TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); + // When + TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); // When boolean result = PrivateUtils.comparePrivateCompasICDHeaders(tPrivate1,tPrivate2); @@ -482,6 +510,7 @@ void comparePrivateCompasICDHeaders_should_return_false_equality_not_check_for_I } @Test + @Tag("issue-321") void comparePrivateCompasICDHeaders_should_return_true() { // Given TCompasICDHeader compasICDHeader1 = new TCompasICDHeader(); @@ -491,8 +520,10 @@ void comparePrivateCompasICDHeaders_should_return_true() { compasICDHeader1.setICDSystemVersionUUID("UUID-1"); TCompasICDHeader compasICDHeader2 = new TCompasICDHeader(); compasICDHeader2.setICDSystemVersionUUID("UUID-1"); - TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); - TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); + // When + TPrivate tPrivate1 = PrivateUtils.createPrivate(compasICDHeader1); + // When + TPrivate tPrivate2 = PrivateUtils.createPrivate(compasICDHeader2); // When boolean result = PrivateUtils.comparePrivateCompasICDHeaders(tPrivate1,tPrivate2); @@ -501,6 +532,7 @@ void comparePrivateCompasICDHeaders_should_return_true() { } @Test + @Tag("issue-321") void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate() { // Given TCompasICDHeader stdCompasICDHeader = new TCompasICDHeader(); @@ -510,6 +542,7 @@ void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate() { lNodeCompasICDHeader.setIEDName("IED-1"); lNodeCompasICDHeader.setBayLabel("BAY-1"); lNodeCompasICDHeader.setIEDSubstationinstance(BigInteger.ONE); + // When TPrivate stdTPrivate = PrivateUtils.createPrivate(stdCompasICDHeader); // When diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/SettingLDEPFCsvHelperTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/SettingLDEPFCsvHelperTest.java index 1abbb3e47..6eda32fb4 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/SettingLDEPFCsvHelperTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/SettingLDEPFCsvHelperTest.java @@ -40,7 +40,7 @@ void readCsvFile_should_return_settings() { } @Test - void getLDPFSettingMatchingExtRef_should_return_NoSetting_whenNotMatchExtRefDescValue() { + void getLDPFSettingMatchingExtRef_whenNotMatchExtRefDescValue_should_return_NoSetting() { // Given TExtRef tExtRef = new TExtRef(); tExtRef.setDesc("desc1"); @@ -54,7 +54,7 @@ void getLDPFSettingMatchingExtRef_should_return_NoSetting_whenNotMatchExtRefDesc } @Test - void getLDPFSettingMatchingExtRef_should_return_digitalSetting_whenMatchExtRef() { + void getLDPFSettingMatchingExtRef_whenMatchExtRef_should_return_digitalSetting() { // Given TExtRef tExtRef = new TExtRef(); tExtRef.setDesc("DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_Y_general_1"); @@ -69,7 +69,7 @@ void getLDPFSettingMatchingExtRef_should_return_digitalSetting_whenMatchExtRef() } @Test - void getLDPFSettingMatchingExtRef_should_return_analogSetting_whenMatchExtRef() { + void getLDPFSettingMatchingExtRef_whenMatchExtRef_should_return_analogSetting() { // Given TExtRef tExtRef = new TExtRef(); tExtRef.setDesc("DYN_LDEPF_ANALOG CHANNEL 1_1_AnalogueValue_Y_instMag_1"); @@ -84,7 +84,7 @@ void getLDPFSettingMatchingExtRef_should_return_analogSetting_whenMatchExtRef() } @Test - void getLDPFSettingMatchingExtRef_should_return_NoSetting_whenNotMatchExtRefPLNValue() { + void getLDPFSettingMatchingExtRef_whenNotMatchExtRefPLNValue_should_return_NoSetting() { // Given TExtRef tExtRef = new TExtRef(); tExtRef.setDesc("DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_Y_general_1"); @@ -98,7 +98,7 @@ void getLDPFSettingMatchingExtRef_should_return_NoSetting_whenNotMatchExtRefPLNV } @Test - void getLDPFSettingMatchingExtRef_should_return_NoSetting_when_AllSettingsNotMatchExtRefWithUnknownPDOValue() { + void getLDPFSettingMatchingExtRef_when_AllSettingsNotMatchExtRefWithUnknownPDOValue_should_return_NoSetting() { // Given TExtRef tExtRef = new TExtRef(); tExtRef.setDesc("DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_Y_general_1"); @@ -112,7 +112,7 @@ void getLDPFSettingMatchingExtRef_should_return_NoSetting_when_AllSettingsNotMat } @Test - void getIedSources_should_return_oneIedSource_whenFlowKindIsInternalAndMatchAllVerification() { + void getIedSources_whenFlowKindIsInternalAndMatchAllVerification_should_return_oneIedSource() { // Given String fileName = "LDEPF_Setting_file.csv"; InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName); @@ -145,7 +145,7 @@ void getIedSources_should_return_oneIedSource_whenFlowKindIsInternalAndMatchAllV } @Test - void getIedSources_should_return_OneIedSource_whenFlowKindIsInternal() { + void getIedSources_whenFlowKindIsInternal_should_return_OneIedSource() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_iedSources_in_different_bay.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -169,7 +169,7 @@ void getIedSources_should_return_OneIedSource_whenFlowKindIsInternal() { @Test - void getIedSources_should_return_TwoIedSources_whenFlowKindIsExternalAndTwoIedSourcesFoundWithTheSameBayUUID() { + void getIedSources_whenFlowKindIsExternalAndTwoIedSourcesFoundWithTheSameBayUUID_should_return_TwoIedSources() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_External_iedSources_in_same_bay.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -194,7 +194,7 @@ void getIedSources_should_return_TwoIedSources_whenFlowKindIsExternalAndTwoIedSo } @Test - void getIedSources_should_return_TwoIedSources_whenFlowKindIsExternalAndTwoIedSourcesFoundWithTheSameICDHeader() { + void getIedSources_whenFlowKindIsExternalAndTwoIedSourcesFoundWithTheSameICDHeader_should_return_TwoIedSources() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_iedSources_in_different_bay.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -226,7 +226,7 @@ void getIedSources_should_return_TwoIedSources_whenFlowKindIsExternalAndTwoIedSo "NO_EXISTING_INST_OF_LDEVICE_SOURCE", "LDEVICE_INVALID" }) - void getIedSources_should_return_NoIedSource_whenLDevice(String ldInst) { + void getIedSources_whenLDeviceInstEqual_shouldReturnNoIedSource(String ldInst) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_iedSources_in_different_bay.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -250,7 +250,7 @@ void getIedSources_should_return_NoIedSource_whenLDevice(String ldInst) { } @Test - void getIedSources_should_return_NoIedSource_whenFlowKindIsInternalAndNoExistingLNodeSource() { + void getIedSources_whenFlowKindIsInternalAndNoExistingLNodeSource_should_return_NoIedSource() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_iedSources_in_different_bay.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -275,7 +275,7 @@ void getIedSources_should_return_NoIedSource_whenFlowKindIsInternalAndNoExisting @Test - void getIedSources_should_return_NoIedSource_whenFlowKindIsInternalAndLNodeSourceIsOff() { + void getIedSources_whenFlowKindIsInternalAndLNodeSourceIsOff_should_return_NoIedSource() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_iedSources_in_different_bay.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -299,7 +299,7 @@ void getIedSources_should_return_NoIedSource_whenFlowKindIsInternalAndLNodeSourc } @Test - void getIedSources_should_return_OneIedSource_whenFlowKindIsInternalAndDataTypeTemplateIsValid() { + void getIedSources_whenFlowKindIsInternalAndDataTypeTemplateIsValid_should_return_OneIedSource() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_dataTypeTemplateValid.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -320,7 +320,7 @@ void getIedSources_should_return_OneIedSource_whenFlowKindIsInternalAndDataTypeT } @Test - void getIedSources_should_return_IedSource_whenFlowKindIsExternalAndDataTypeTemplateIsValid() { + void getIedSources_whenFlowKindIsExternalAndDataTypeTemplateIsValid_should_return_IedSource() { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_dataTypeTemplateValid.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -343,7 +343,7 @@ void getIedSources_should_return_IedSource_whenFlowKindIsExternalAndDataTypeTemp @ParameterizedTest @MethodSource("provideInternalAndExternalLDEPFSetting") - void getIedSources_should_return_IedSource_whenInternalAndExternalFlowKindAreApplied(final LDEPFSettingData setting, final boolean isInSameBay) { + void getIedSources_whenInternalAndExternalFlowKindAreApplied_should_return_IedSource(final LDEPFSettingData setting, final boolean isInSameBay) { // Given SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_dataTypeTemplateValid.xml"); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -359,7 +359,7 @@ void getIedSources_should_return_IedSource_whenInternalAndExternalFlowKindAreApp @ParameterizedTest @MethodSource("provideInvalidDoName") - void getIedSources_should_return_NoSource_whenInvalidDoName(final SCL scd, final LDEPFSettingData setting) { + void getIedSources_whenInvalidDoName_should_return_NoSource(final SCL scd, final LDEPFSettingData setting) { // Given SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); TCompasBay compasBay = getCompasBayUUID(new SclRootAdapter(scd), "IED_NAME1"); @@ -372,7 +372,7 @@ void getIedSources_should_return_NoSource_whenInvalidDoName(final SCL scd, final @ParameterizedTest @MethodSource("provideInvalidSdoName") - void getIedSources_should_return_NoSource_whenInvalidSdoName(final SCL scd, final LDEPFSettingData setting) { + void getIedSources_whenInvalidSdoName_should_return_NoSource(final SCL scd, final LDEPFSettingData setting) { // Given SettingLDEPFCsvHelper settingLDEPFCsvHelper = new SettingLDEPFCsvHelper(reader); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -386,7 +386,7 @@ void getIedSources_should_return_NoSource_whenInvalidSdoName(final SCL scd, fina @ParameterizedTest @MethodSource("provideInvalidDaName") - void getIedSources_should_return_NoSource_whenInvalidDaName(final SCL scd, final LDEPFSettingData setting) { + void getIedSources_whenInvalidDaName_should_return_NoSource(final SCL scd, final LDEPFSettingData setting) { // Given SettingLDEPFCsvHelper settingLDEPFCsvHelper = new SettingLDEPFCsvHelper(reader); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -400,7 +400,7 @@ void getIedSources_should_return_NoSource_whenInvalidDaName(final SCL scd, final @ParameterizedTest @MethodSource("provideInvalidBdaName") - void getIedSources_should_return_NoSource_whenInvalidBdaName(final SCL scd, final LDEPFSettingData setting) { + void getIedSources_whenInvalidBdaName_should_return_NoSource(final SCL scd, final LDEPFSettingData setting) { // Given SettingLDEPFCsvHelper settingLDEPFCsvHelper = new SettingLDEPFCsvHelper(reader); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); @@ -414,7 +414,7 @@ void getIedSources_should_return_NoSource_whenInvalidBdaName(final SCL scd, fina @ParameterizedTest @MethodSource("provideInvalidSbdaName") - void getIedSources_should_return_NoSource_whenInvalidSbdaName(final SCL scd, final LDEPFSettingData setting) { + void getIedSources_whenInvalidSbdaName_should_return_NoSource(final SCL scd, final LDEPFSettingData setting) { // Given SettingLDEPFCsvHelper settingLDEPFCsvHelper = new SettingLDEPFCsvHelper(reader); SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/UtilsTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/UtilsTest.java index 0b7157abd..788b466d3 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/UtilsTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/UtilsTest.java @@ -22,7 +22,6 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.createExtRefExample; import static org.lfenergy.compas.sct.commons.util.Utils.copySclElement; @@ -43,7 +42,7 @@ void entering_should_return_text() { // When String entering = Utils.entering(); // Then - assertEquals(">>> Entering: ::entering_should_return_text", entering); + assertThat(entering).isEqualTo(">>> Entering: ::entering_should_return_text"); } @Test @@ -52,7 +51,7 @@ void leaving_should_return_text() { // When String leaving = Utils.leaving(); // Then - assertEquals("<<< Leaving: ::leaving_should_return_text", leaving); + assertThat(leaving).isEqualTo("<<< Leaving: ::leaving_should_return_text"); } @Test @@ -61,7 +60,7 @@ void leaving_should_return_text_with_time() { // When String leaving = Utils.leaving(System.nanoTime()); // Then - assertTrue(leaving.matches("<<< Leaving: ::leaving_should_return_text_with_time - Timer duration: .* sec."), leaving); + assertThat(leaving).matches("<<< Leaving: ::leaving_should_return_text_with_time - Timer duration: .* sec."); } @Test @@ -70,11 +69,11 @@ void leaving_should_return_text_with_invalid_time() { // When String leaving = Utils.leaving(-1L); // Then - assertEquals("<<< Leaving: ::leaving_should_return_text_with_invalid_time", leaving); + assertThat(leaving).isEqualTo("<<< Leaving: ::leaving_should_return_text_with_invalid_time"); } @Test - void equalsOrNotSet_should_return_true_when_both_values_are_not_set() { + void equalsOrNotSet_when_both_values_are_not_set_should_return_true() { // Given Optional object1 = Optional.empty(); Optional object2 = Optional.empty(); @@ -82,12 +81,12 @@ void equalsOrNotSet_should_return_true_when_both_values_are_not_set() { boolean result1 = Utils.equalsOrNotSet(object1, object2, Optional::isPresent, Optional::get); boolean result2 = Utils.equalsOrNotSet(object2, object1, Optional::isPresent, Optional::get); // Then - assertTrue(result1); - assertTrue(result2); + assertThat(result1).isTrue(); + assertThat(result2).isTrue(); } @Test - void equalsOrNotSet_should_return_true_when_both_values_are_set_and_equal() { + void equalsOrNotSet_when_both_values_are_set_and_equal_should_return_true() { // Given Optional object1 = Optional.of(1L); Optional object2 = Optional.of(1L); @@ -95,12 +94,12 @@ void equalsOrNotSet_should_return_true_when_both_values_are_set_and_equal() { boolean result1 = Utils.equalsOrNotSet(object1, object2, Optional::isPresent, Optional::get); boolean result2 = Utils.equalsOrNotSet(object2, object1, Optional::isPresent, Optional::get); // Then - assertTrue(result1); - assertTrue(result2); + assertThat(result1).isTrue(); + assertThat(result2).isTrue(); } @Test - void equalsOrNotSet_should_return_false_when_both_values_are_set_but_differ() { + void equalsOrNotSet_when_both_values_are_set_but_differ_should_return_false() { // Given Optional object1 = Optional.of(1L); Optional object2 = Optional.of(2L); @@ -108,12 +107,12 @@ void equalsOrNotSet_should_return_false_when_both_values_are_set_but_differ() { boolean result1 = Utils.equalsOrNotSet(object1, object2, Optional::isPresent, Optional::get); boolean result2 = Utils.equalsOrNotSet(object2, object1, Optional::isPresent, Optional::get); // Then - assertFalse(result1); - assertFalse(result2); + assertThat(result1).isFalse(); + assertThat(result2).isFalse(); } @Test - void equalsOrNotSet_should_return_false_when_one_is_set_and_the_other_is_not() { + void equalsOrNotSet_when_one_is_set_and_the_other_is_not_should_return_false() { // Given Optional object1 = Optional.of(1L); Optional object2 = Optional.empty(); @@ -121,18 +120,20 @@ void equalsOrNotSet_should_return_false_when_one_is_set_and_the_other_is_not() { boolean result1 = Utils.equalsOrNotSet(object1, object2, Optional::isPresent, Optional::get); boolean result2 = Utils.equalsOrNotSet(object2, object1, Optional::isPresent, Optional::get); // Then - assertFalse(result1); - assertFalse(result2); + assertThat(result1).isFalse(); + assertThat(result2).isFalse(); } @Test - void equalsOrNotSet_should_throw_exception_when_value_is_null_and_isSet_is_misleading() { + void equalsOrNotSet_when_value_is_null_and_isSet_is_misleading_should_throw_exception() { // Given Optional object1 = Optional.of(1L); Optional object2 = Optional.empty(); // When & Then - assertThrows(NoSuchElementException.class, () -> Utils.equalsOrNotSet(object1, object2, o -> true, Optional::get)); - assertThrows(NoSuchElementException.class, () -> Utils.equalsOrNotSet(object2, object1, o -> true, Optional::get)); + assertThatCode(() -> Utils.equalsOrNotSet(object1, object2, o -> true, Optional::get)) + .isInstanceOf(NoSuchElementException.class); + assertThatCode(() -> Utils.equalsOrNotSet(object2, object1, o -> true, Optional::get)) + .isInstanceOf(NoSuchElementException.class); } @Test @@ -143,7 +144,7 @@ void xpathAttributeFilter_should_succeed() { // When String result = Utils.xpathAttributeFilter(attributeName, attributeValue); // Then - assertEquals("@name=\"value\"", result); + assertThat(result).isEqualTo("@name=\"value\""); } @Test @@ -154,7 +155,7 @@ void xpathAttributeFilter_when_value_is_null_should_succeed() { // When String result = Utils.xpathAttributeFilter(attributeName, attributeValue); // Then - assertEquals("not(@name)", result); + assertThat(result).isEqualTo("not(@name)"); } @Test @@ -165,7 +166,7 @@ void xpathAttributeFilter_when_value_is_collection_should_succeed() { // When String result = Utils.xpathAttributeFilter(attributeName, attributeValue); // Then - assertEquals("@name=\"value1 value2\"", result); + assertThat(result).isEqualTo("@name=\"value1 value2\""); } @Test @@ -176,7 +177,7 @@ void xpathAttributeFilter_when_value_is_collection_should_ignore_null_values() { // When String result = Utils.xpathAttributeFilter(attributeName, attributeValue); // Then - assertEquals("@name=\"value1 value2\"", result); + assertThat(result).isEqualTo("@name=\"value1 value2\""); } @ParameterizedTest @@ -187,7 +188,7 @@ void xpathAttributeFilter_when_empty_collection_should_succeed(Collection> xpathAttributeFilterEmptyCollectionSource() { @@ -435,7 +436,7 @@ void sequence_should_return_empty_iterator(){ } @Test - void sequence_should_throw_exception_when_MAX_VALUE(){ + void sequence_when_MAX_VALUE_should_throw_exception(){ // Given long startInclusive = 1; long endInclusive = Long.MAX_VALUE; diff --git a/sct-data/pom.xml b/sct-data/pom.xml index 88da7f986..27a1fbcf7 100644 --- a/sct-data/pom.xml +++ b/sct-data/pom.xml @@ -38,6 +38,11 @@ junit-jupiter-engine test + + org.assertj + assertj-core + test + diff --git a/sct-data/src/test/java/org/lfenergy/compas/sct/data/repository/CompasDataAccessExceptionTest.java b/sct-data/src/test/java/org/lfenergy/compas/sct/data/repository/CompasDataAccessExceptionTest.java index 0becef4eb..853e7e973 100644 --- a/sct-data/src/test/java/org/lfenergy/compas/sct/data/repository/CompasDataAccessExceptionTest.java +++ b/sct-data/src/test/java/org/lfenergy/compas/sct/data/repository/CompasDataAccessExceptionTest.java @@ -6,17 +6,18 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; class CompasDataAccessExceptionTest { @Test - void testConstructor(){ - CompasDataAccessException ex = new CompasDataAccessException("msg",new RuntimeException()); - assertEquals("msg",ex.getLocalizedMessage()); - assertNotNull(ex.getCause()); - assertEquals(RuntimeException.class,ex.getCause().getClass()); - + void constructor_whenCalled_shouldFillValues(){ + // When + CompasDataAccessException compasDataAccessException = new CompasDataAccessException("msg",new RuntimeException()); + // Then + assertThat(compasDataAccessException.getLocalizedMessage()).isEqualTo("msg"); + assertThat(compasDataAccessException.getCause()).isNotNull(); + assertThat(compasDataAccessException.getCause().getClass()).isEqualTo(RuntimeException.class); } } \ No newline at end of file