Skip to content

Commit

Permalink
Update SclEditorService to SclService
Browse files Browse the repository at this point in the history
Signed-off-by: Samir Romdhani <samir.romdhani@rte-france.com>
  • Loading branch information
samirromdhani committed Oct 31, 2023
1 parent 57e0fbc commit c09e89f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.lfenergy.compas.scl2007b4.model.LN0;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.sct.commons.ControlBlockService;
import org.lfenergy.compas.sct.commons.SclEditorService;
import org.lfenergy.compas.sct.commons.SclService;
import org.lfenergy.compas.sct.commons.SubstationService;
import org.lfenergy.compas.sct.commons.api.ControlBlockEditor;
import org.lfenergy.compas.sct.commons.api.SclEditor;
Expand All @@ -31,7 +31,7 @@
class SclAutomationServiceIntegrationTest {

private SclAutomationService sclAutomationService ;
private static final SclEditor sclEditor = new SclEditorService() ;
private static final SclEditor sclEditor = new SclService() ;
private static final SubstationEditor substationEditor = new SubstationService() ;
private static final ControlBlockEditor controlBlockEditor = new ControlBlockService() ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.lfenergy.compas.sct.commons.util.PrivateEnum.COMPAS_ICDHEADER;

@Slf4j
public class SclEditorService implements SclEditor {
public class SclService implements SclEditor {

@Override
public SCL initScl(final UUID hId, final String hVersion, final String hRevision) throws ScdException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import static org.lfenergy.compas.sct.commons.util.PrivateEnum.COMPAS_SCL_FILE_TYPE;

@ExtendWith(MockitoExtension.class)
class SclEditorServiceTest {
class SclServiceTest {

@InjectMocks
SclEditorService sclEditorService;
SclService sclService;

private static Stream<Arguments> sclProviderMissingRequiredObjects() {
SCL scl1 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingBeh.scd");
Expand Down Expand Up @@ -100,7 +100,7 @@ void addHistoryItem_should_add_history_elements() throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter("hId", SclRootAdapter.VERSION, SclRootAdapter.REVISION);
SCL scd = sclRootAdapter.getCurrentElem();
//When
sclEditorService.addHistoryItem(scd, "who", "what", "why");
sclService.addHistoryItem(scd, "who", "what", "why");
//Then
assertThat(scd.getHeader()).isNotNull();
THeader.History history = scd.getHeader().getHistory();
Expand All @@ -123,7 +123,7 @@ void addIED_should_add_ied_element() {
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));
assertDoesNotThrow(() -> sclService.addIED(scd, "IED_NAME1", icd));
assertThat(scd.getIED().size()).isNotZero();
assertThat(scd.getIED().get(0).getName()).isEqualTo("IED_NAME1");
assertThat(scd.getDataTypeTemplates()).isNotNull();
Expand All @@ -139,14 +139,14 @@ void addSubnetworks_should_add_subnetwork() {
assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
//When Then
assertThatCode(() -> sclEditorService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
assertThatCode(() -> sclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
SubNetworkDTO subNetworkDTO = new SubNetworkDTO();
subNetworkDTO.setName("sName1");
subNetworkDTO.setType("IP");
ConnectedApDTO connectedApDTO = new ConnectedApDTO("IED_NAME1","AP_NAME");
subNetworkDTO.addConnectedAP(connectedApDTO);
//When Then
assertThatCode(() -> sclEditorService.addSubnetworks(scd, List.of(subNetworkDTO), icd)).doesNotThrowAnyException();
assertThatCode(() -> sclService.addSubnetworks(scd, List.of(subNetworkDTO), icd)).doesNotThrowAnyException();
assertIsMarshallable(scd);
}

Expand All @@ -159,9 +159,9 @@ void addSubnetworks_whenNoCommunicationTagInIcd_should_not_add_subnetwork() {
assertThat(sclRootAdapter.getCurrentElem().getDataTypeTemplates()).isNull();
SCL icd = SclTestMarshaller.getSCLFromFile("/scl-srv-import-ieds/ied_1_test.xml");
//When Then
assertThatCode(() -> sclEditorService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
assertThatCode(() -> sclService.addIED(scd, "IED_NAME1", icd)).doesNotThrowAnyException();
//When Then
assertThatCode(() -> sclEditorService.addSubnetworks(scd, List.of(), icd)).doesNotThrowAnyException();
assertThatCode(() -> sclService.addSubnetworks(scd, List.of(), icd)).doesNotThrowAnyException();
String marshalledScd = assertIsMarshallable(scd);
assertThat(marshalledScd).doesNotContain("<Communication");
}
Expand All @@ -171,7 +171,7 @@ void testInitScl_With_headerId_shouldNotThrowError() {
//Given
UUID headerId = UUID.randomUUID();
//When
SCL scd = assertDoesNotThrow(() -> sclEditorService.initScl(headerId, "hVersion", "hRevision"));
SCL scd = assertDoesNotThrow(() -> sclService.initScl(headerId, "hVersion", "hRevision"));
//Then
assertIsMarshallable(scd);
}
Expand All @@ -181,7 +181,7 @@ void initScl_should_create_Private_SCL_FILETYPE() {
// Given
UUID headerId = UUID.randomUUID();
// When Then
SCL scd = assertDoesNotThrow(() -> sclEditorService.initScl(headerId, "hVersion", "hRevision"));
SCL scd = assertDoesNotThrow(() -> sclService.initScl(headerId, "hVersion", "hRevision"));
assertThat(scd.getPrivate()).isNotEmpty();
assertThat(scd.getPrivate().get(0).getType()).isEqualTo(COMPAS_SCL_FILE_TYPE.getPrivateType());
assertIsMarshallable(scd);
Expand All @@ -191,12 +191,12 @@ void initScl_should_create_Private_SCL_FILETYPE() {
@Tag("issue-321")
void updateHeader_should_update_header_tag() {
//When Then
SCL scd = assertDoesNotThrow(() -> sclEditorService.initScl(UUID.randomUUID(), "hVersion", "hRevision"));
SCL scd = assertDoesNotThrow(() -> sclService.initScl(UUID.randomUUID(), "hVersion", "hRevision"));
//Given
UUID headerId = UUID.fromString(scd.getHeader().getId());
HeaderDTO headerDTO = DTO.createHeaderDTO(headerId);
//When
sclEditorService.updateHeader(scd, headerDTO);
sclService.updateHeader(scd, headerDTO);
//Then
assertIsMarshallable(scd);
}
Expand All @@ -209,7 +209,7 @@ void updateDAI_should_not_throw_error() {
dataAttributeRef.setLnType("unknownID");
SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml");
//When Then
assertThatThrownBy(() -> sclEditorService.updateDAI(scd, "IED", "LD", dataAttributeRef))
assertThatThrownBy(() -> sclService.updateDAI(scd, "IED", "LD", dataAttributeRef))
.isInstanceOf(ScdException.class);
//Given
dataAttributeRef.setLnType("LNO1");
Expand All @@ -221,7 +221,7 @@ void updateDAI_should_not_throw_error() {
tVal.setValue("newValue");
dataAttributeRef.setDaiValues(List.of(tVal));
//When Then
assertThatCode(() -> sclEditorService.updateDAI(scd, "IED_NAME", "LD_INS1", dataAttributeRef))
assertThatCode(() -> sclService.updateDAI(scd, "IED_NAME", "LD_INS1", dataAttributeRef))
.doesNotThrowAnyException();
assertIsMarshallable(scd);
}
Expand All @@ -232,7 +232,7 @@ void testImportSTDElementsInSCD_whenCalledWithOneSTD_shouldNotThrowException() {
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
//When Then
assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES))
assertThatCode(() -> sclService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES))
.doesNotThrowAnyException();
assertThat(scd.getIED()).hasSize(1);
assertThat(scd.getDataTypeTemplates()).hasNoNullFieldsOrProperties();
Expand All @@ -248,7 +248,7 @@ void importSTDElementsInSCD_whenCalledWithMultipleSTD_shouldNotThrowException()
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");
//When Then
assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std0, std1, std2), DTO.SUB_NETWORK_TYPES))
assertThatCode(() -> sclService.importSTDElementsInSCD(scd, List.of(std0, std1, std2), DTO.SUB_NETWORK_TYPES))
.doesNotThrowAnyException();
assertThat(scd.getIED()).hasSize(3);
assertThat(scd.getDataTypeTemplates()).hasNoNullFieldsOrProperties();
Expand All @@ -266,7 +266,7 @@ void importSTDElementsInSCD_whenManySTDMatchCompasICDHeader_shouldThrowException
SCL std2 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
List<SCL> stds = List.of(std1, std2);
//When Then
assertThatThrownBy(() -> sclEditorService.importSTDElementsInSCD(scd, stds, DTO.SUB_NETWORK_TYPES))
assertThatThrownBy(() -> sclService.importSTDElementsInSCD(scd, stds, DTO.SUB_NETWORK_TYPES))
.isInstanceOf(ScdException.class);
assertIsMarshallable(scd);
}
Expand All @@ -277,7 +277,7 @@ void importSTDElementsInSCD_whenSCDFileContainsSameICDHeaderInTwoDifferentFuncti
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd_with_same_compas_icd_header_in_different_functions.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
//When Then
assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES)).doesNotThrowAnyException();
assertThatCode(() -> sclService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES)).doesNotThrowAnyException();
assertIsMarshallable(scd);
}

Expand All @@ -288,7 +288,7 @@ void importSTDElementsInSCD_whenCompasICDHeaderNotMatch__shouldThrowException()
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std_with_same_ICDSystemVersionUUID.xml");
List<SCL> stdList = List.of(std);
//When Then
assertThatThrownBy(() -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES))
assertThatThrownBy(() -> sclService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES))
.isInstanceOf(ScdException.class)
.hasMessageContaining("COMPAS-ICDHeader is not the same in Substation and in IED");
assertIsMarshallable(scd);
Expand All @@ -300,7 +300,7 @@ void importSTDElementsInSCD_whenNoSTDMatch_shouldThrowException() {
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml");
List<SCL> stdList = List.of();
//When Then
assertThatCode(() -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES))
assertThatCode(() -> sclService.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");
}
Expand All @@ -313,7 +313,7 @@ void updateLDeviceStatus_whenMissingRequiredObject_shouldReturnReportWithError(S
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
String before = MarshallerWrapper.marshall(scl);
// When
List<SclReportItem> sclReportItems = sclEditorService.updateLDeviceStatus(scl);
List<SclReportItem> sclReportItems = sclService.updateLDeviceStatus(scl);
// Then
String after = MarshallerWrapper.marshall(scl);
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse();
Expand All @@ -334,7 +334,7 @@ void updateLDeviceStatus_whenLDeviceStatusActiveOrUntestedOrInactive_shouldRetur
assertThat(getLDeviceStatusValue(scl, "IedName3", "LDSUIED")).isEmpty();
String before = MarshallerWrapper.marshall(scl);
// When
List<SclReportItem> sclReportItems = sclEditorService.updateLDeviceStatus(scl);
List<SclReportItem> sclReportItems = sclService.updateLDeviceStatus(scl);
// Then
String after = MarshallerWrapper.marshall(scl);
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse();
Expand All @@ -356,7 +356,7 @@ void updateLDeviceStatus_whenAllLDeviceInactive_shouldReturnReportWithError() {
assertThat(getLDeviceStatusValue(scl, "IedName2", "LDSUIED").get().getValue()).isEqualTo("on");
assertThat(getLDeviceStatusValue(scl, "IedName3", "LDSUIED")).isEmpty();
// When
List<SclReportItem> sclReportItems = sclEditorService.updateLDeviceStatus(scl);
List<SclReportItem> sclReportItems = sclService.updateLDeviceStatus(scl);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse();
assertThat(sclReportItems)
Expand All @@ -382,7 +382,7 @@ void updateLDeviceStatus_shouldReturnUpdatedFile() {
assertThat(getLDeviceStatusValue(givenScl, "IedName2", "LDSUIED").get().getValue()).isEqualTo("on");
assertThat(getLDeviceStatusValue(givenScl, "IedName3", "LDSUIED")).isEmpty();
// When
List<SclReportItem> sclReportItems = sclEditorService.updateLDeviceStatus(givenScl);
List<SclReportItem> sclReportItems = sclService.updateLDeviceStatus(givenScl);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
assertThat(getLDeviceStatusValue(givenScl, "IedName1", "LDSUIED")).isPresent();
Expand Down Expand Up @@ -413,7 +413,7 @@ void updateLDeviceStatus_when_DAI_Mod_DO_stVal_whateverIsUpdatableOrNot_shouldRe
.map(TVal::getValue)
.hasValue("on");
// When
List<SclReportItem> sclReportItems = sclEditorService.updateLDeviceStatus(givenScl);
List<SclReportItem> sclReportItems = sclService.updateLDeviceStatus(givenScl);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
assertThat(getLDeviceStatusValue(givenScl, "IedName1", "LDSUIED"))
Expand Down Expand Up @@ -450,7 +450,7 @@ void updateDoInRef_shouldReturnUpdatedFile(String testName, String ldInst, Strin
// Given
SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_issue_231_test_ok.xml");
// When
List<SclReportItem> sclReportItems = sclEditorService.updateDoInRef(givenScl);
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
SclTestMarshaller.assertIsMarshallable(givenScl);
Expand All @@ -472,7 +472,7 @@ void updateDoInRef_should_not_update_DAI(String testName, String ldInst, String
// Given
SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_issue_231_test_ok.xml");
// When
List<SclReportItem> sclReportItems = sclEditorService.updateDoInRef(givenScl);
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
assertThat(getValFromDaiName(givenScl, "IED_NAME1", ldInst, doName, daName)).isNotPresent();
Expand All @@ -484,7 +484,7 @@ void updateDoInRef_when_ExtRefNotCoherent_shouldReturnReportWithError() {
// Given
SCL givenScl = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_issue_231_test_ko.xml");
// When
List<SclReportItem> sclReportItems = sclEditorService.updateDoInRef(givenScl);
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
assertThat(sclReportItems).hasSize(4);
Expand All @@ -511,7 +511,7 @@ void manageMonitoringLns_should_update_and_create_lsvs_and_goose() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/monitoring_lns/scd_monitoring_lsvs_lgos.xml");
// When
List<SclReportItem> sclReportItems = sclEditorService.manageMonitoringLns(scd);
List<SclReportItem> sclReportItems = sclService.manageMonitoringLns(scd);
//Then
assertThat(sclReportItems).isEmpty();
LDeviceAdapter lDeviceAdapter = new SclRootAdapter(scd).getIEDAdapterByName("IED_NAME1").getLDeviceAdapterByLdInst(LD_SUIED);
Expand All @@ -533,7 +533,7 @@ void manageMonitoringLns_when_no_extRef_should_not_update_and_not_create_lsvs_an
LDeviceAdapter lDeviceAdapter21 = sclRootAdapter.getIEDAdapterByName("IED_NAME1").getLDeviceAdapterByLdInst("LD_INST21");
lDeviceAdapter21.getLN0Adapter().getCurrentElem().setInputs(null);
// When
List<SclReportItem> sclReportItems = sclEditorService.manageMonitoringLns(scd);
List<SclReportItem> sclReportItems = sclService.manageMonitoringLns(scd);
//Then
assertThat(sclReportItems).isEmpty();
LDeviceAdapter lDeviceAdapter = sclRootAdapter.getIEDAdapterByName("IED_NAME1").getLDeviceAdapterByLdInst(LD_SUIED);
Expand All @@ -555,7 +555,7 @@ void manageMonitoringLns_when_dai_not_updatable_should_not_update_and_not_create
getDAIAdapters(lDeviceAdapter, "LSVS", "SvCBRef", "setSrcRef")
.forEach(daiAdapter -> daiAdapter.getCurrentElem().setValImport(false));
// When
List<SclReportItem> sclReportItems = sclEditorService.manageMonitoringLns(scd);
List<SclReportItem> sclReportItems = sclService.manageMonitoringLns(scd);
//Then
assertThat(sclReportItems)
.isNotEmpty()
Expand Down

0 comments on commit c09e89f

Please sign in to comment.