Skip to content

Commit

Permalink
add parameterized test
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 3, 2022
1 parent 3462385 commit 5f6d6e4
Showing 1 changed file with 76 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
package org.lfenergy.compas.sct.commons.scl;

import org.apache.commons.lang3.StringUtils;
import org.assertj.core.groups.Tuple;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
Expand All @@ -14,6 +18,7 @@

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
Expand Down Expand Up @@ -703,170 +708,100 @@ void removeControlBlocksAndDatasetAndExtRefSrc_should_remove_srcXXX_attributes_o
assertIsMarshallable(scl);
}


@Test
void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingDOBeh() throws Exception {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingBeh.scd");
String before = createWrapper().marshall(scl);
// When
SclReport sclReport = SclService.updateLDeviceStatus(scl);
// Then
String after = createWrapper().marshall(sclReport.getSclRootAdapter().getCurrentElem());
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(1)
.extracting(SclReport.ErrorDescription::getMessage)
.containsExactly(
"The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'");
assertEquals(before, after);
}
@Test
void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingLDevicePrivate() throws Exception {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingLDevicePrivate.scd");
assertTrue(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").isPresent());
assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue());
// When
SclReport sclReport = SclService.updateLDeviceStatus(scl);
// Then
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(1)
.containsExactly(SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")
.message("The LDevice doesn't have a Private compas:LDevice.")
.build());
assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue());
}

@Test
void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingLDevicePrivateAttribute() throws Exception {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingLDevicePrivateAttribute.scd");
assertTrue(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").isPresent());
assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue());
// When
SclReport sclReport = SclService.updateLDeviceStatus(scl);
// Then
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(1)
.containsExactly(SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")
.message("The Private compas:LDevice doesn't have the attribute 'LDeviceStatus'")
.build());
assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue());
private static Stream<Arguments> sclProviderMissingRequiredObjects() throws Exception {
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");
SCL scl4 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingMod.scd");
Tuple[] scl1Errors = new Tuple[]{Tuple.tuple("The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")};
Tuple[] scl2Errors = new Tuple[]{Tuple.tuple("The LDevice doesn't have a Private compas:LDevice.",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")};
Tuple[] scl3Errors = new Tuple[]{Tuple.tuple("The Private compas:LDevice doesn't have the attribute 'LDeviceStatus'",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")};
Tuple[] scl4Errors = new Tuple[]{Tuple.tuple("The LDevice doesn't have a DO @name='Mod'",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")};
return Stream.of(
Arguments.of("MissingDOBeh",scl1, scl1Errors),
Arguments.of("MissingLDevicePrivate",scl2, scl2Errors),
Arguments.of("MissingLDevicePrivateAttribute",scl3, scl3Errors),
Arguments.of("MissingDOMod",scl4, scl4Errors)
);
}

@Test
void updateLDeviceStatus_shouldReturnReportWithError_WhenMissingDOMod() throws Exception {
@ParameterizedTest(name = "{0}")
@MethodSource("sclProviderMissingRequiredObjects")
void updateLDeviceStatus_shouldReturnReportWithError_MissingRequiredObject(String testCase, SCL scl, Tuple... errors) {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_KO_MissingMod.scd");
assertTrue(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").isPresent());
assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue());
String before = createWrapper().marshall(scl);
// When
SclReport sclReport = SclService.updateLDeviceStatus(scl);
// Then
String after = createWrapper().marshall(sclReport.getSclRootAdapter().getCurrentElem());
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(1)
.containsExactly(SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")
.message("The LDevice doesn't have a DO @name='Mod'")
.build());
assertEquals( "off",getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue());
}

@Test
void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceActive() throws Exception {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_LD_STATUS_ACTIVE.scd");
assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue());
assertEquals("on", getLDeviceStatusValue(scl, "IedName2", "LDSUIED").get().getValue());
assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent());
// When
SclReport sclReport = SclService.updateLDeviceStatus(scl);
// Then
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(3)
.contains(SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")
.message("The LDevice cannot be set to 'off' but has not been selected into SSD.")
.build(),
SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]")
.message("The LDevice cannot be set to 'on' but has been selected into SSD.")
.build(),
SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]")
.message("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.")
.build());
.hasSize(1)
.extracting(SclReport.ErrorDescription::getMessage, SclReport.ErrorDescription::getXpath)
.containsExactly(errors);
assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue());
assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue());
assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent());
assertEquals(before, after);
}


@Test
void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceUntested() throws Exception {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_LD_STATUS_UNTESTED.scd");
assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue());
assertEquals("on", getLDeviceStatusValue(scl, "IedName2", "LDSUIED").get().getValue());
assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent());
// When
SclReport sclReport = SclService.updateLDeviceStatus(scl);
// Then
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(3)
.contains(SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")
.message("The LDevice cannot be set to 'off' but has not been selected into SSD.")
.build(),
SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]")
.message("The LDevice cannot be set to 'on' but has been selected into SSD.")
.build(),
SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]")
.message("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.")
.build());
assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue());
assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue());
assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent());
private static Stream<Arguments> sclProviderBasedLDeviceStatus() throws Exception {
SCL scl1 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_LD_STATUS_ACTIVE.scd");
SCL scl2 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test_LD_STATUS_UNTESTED.scd");
SCL scl3 = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test1_LD_STATUS_INACTIVE.scd");
Tuple[] scl1Errors = new Tuple[]{Tuple.tuple("The LDevice cannot be set to 'off' but has not been selected into SSD.",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]"),
Tuple.tuple("The LDevice cannot be set to 'on' but has been selected into SSD.",
"/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]"),
Tuple.tuple("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.",
"/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]"
)};
Tuple[] scl2Errors = new Tuple[]{Tuple.tuple("The LDevice cannot be set to 'off' but has not been selected into SSD.",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]"),
Tuple.tuple("The LDevice cannot be set to 'on' but has been selected into SSD.",
"/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]"),
Tuple.tuple("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.",
"/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]"
)};
Tuple[] scl3Errors = new Tuple[]{Tuple.tuple("The LDevice is not qualified into STD but has been selected into SSD.",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]"),
Tuple.tuple("The LDevice cannot be set to 'on' but has been selected into SSD.",
"/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]"),
Tuple.tuple("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.",
"/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]"
)};
return Stream.of(
Arguments.of("ACTIVE", scl1, scl1Errors),
Arguments.of("UNTESTED", scl2, scl2Errors),
Arguments.of("INACTIVE", scl3, scl3Errors)
);
}

@Test
void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceInactive_Test1() throws Exception {
@ParameterizedTest(name = "{0}")
@MethodSource("sclProviderBasedLDeviceStatus")
void updateLDeviceStatus_shouldReturnReportWithError_WhenLDeviceStatusActiveOrUntestedOrInactive(String testCase, SCL scl, Tuple... errors) {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/issue68_Test1_LD_STATUS_INACTIVE.scd");
assertEquals("off", getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue());
assertEquals("on", getLDeviceStatusValue(scl, "IedName2", "LDSUIED").get().getValue());
assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent());
String before = createWrapper().marshall(scl);
// When
SclReport sclReport = SclService.updateLDeviceStatus(scl);
// Then
String after = createWrapper().marshall(sclReport.getSclRootAdapter().getCurrentElem());
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(3)
.contains(SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")
.message("The LDevice is not qualified into STD but has been selected into SSD.")
.build(),
SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]")
.message("The LDevice cannot be set to 'on' but has been selected into SSD.")
.build(),
SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName3\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType3\"]")
.message("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.")
.build());
.extracting(SclReport.ErrorDescription::getMessage, SclReport.ErrorDescription::getXpath)
.containsExactly(errors);
assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue());
assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue());
assertFalse(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent());
assertEquals(before, after);
}

@Test
Expand All @@ -882,14 +817,11 @@ void updateLDeviceStatus_shouldReturnReportWithError_WhenAllLDeviceInactive_Test
assertFalse(sclReport.isSuccess());
assertThat(sclReport.getErrorDescriptionList())
.hasSize(2)
.contains(SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]")
.message("The LDevice cannot be set to 'off' but has not been selected into SSD.")
.build(),
SclReport.ErrorDescription.builder()
.xpath("/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]")
.message("The LDevice is not qualified into STD but has been selected into SSD.")
.build());
.extracting(SclReport.ErrorDescription::getMessage, SclReport.ErrorDescription::getXpath)
.containsExactly(Tuple.tuple("The LDevice cannot be set to 'off' but has not been selected into SSD.",
"/SCL/IED[@name=\"IedName1\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType1\"]"),
Tuple.tuple("The LDevice is not qualified into STD but has been selected into SSD.",
"/SCL/IED[@name=\"IedName2\"]/LDevice[@inst=\"LDSUIED\"]/LN[lnClass=\"LLN0\" and @inst=\"\" and @lnType=\"LNType2\"]"));
assertEquals("off", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName1", "LDSUIED").get().getValue());
assertEquals("on", getLDeviceStatusValue(sclReport.getSclRootAdapter().getCurrentElem(), "IedName2", "LDSUIED").get().getValue());
assertTrue(getLDeviceStatusValue(scl, "IedName3", "LDSUIED").isPresent());
Expand Down

0 comments on commit 5f6d6e4

Please sign in to comment.