Skip to content

Commit

Permalink
Merge pull request #325 from com-pas/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
samirromdhani authored Sep 6, 2023
2 parents 86d6850 + f2c32a3 commit fdc489d
Show file tree
Hide file tree
Showing 72 changed files with 3,178 additions and 2,196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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<SCL> 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");
Expand All @@ -129,18 +128,20 @@ void createSCD_should_throw_exception_when_null_ssd() {
List<SCL> 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<SCL> stdList = List.of(std1);

// When & Then
assertThrows(NullPointerException.class, () -> sclAutomationService.createSCD(ssd, null, stdList));
assertThatCode(() -> sclAutomationService.createSCD(ssd, null, stdList))
.isInstanceOf(NullPointerException.class);
}

@Test
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -815,24 +817,27 @@ private LDEPFSettingData getLDEPFSettingByAnalogNum(List<LDEPFSettingData> 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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Loading

0 comments on commit fdc489d

Please sign in to comment.