From d5090da81dec29439d14ba1fd6ab712a70f177dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Nov 2021 13:59:03 +0000 Subject: [PATCH 1/2] Bump powsybl.version from 4.4.0 to 4.5.0 Bumps `powsybl.version` from 4.4.0 to 4.5.0. Updates `powsybl-cgmes-conversion` from 4.4.0 to 4.5.0 Updates `powsybl-triple-store-impl-rdf4j` from 4.4.0 to 4.5.0 --- updated-dependencies: - dependency-name: com.powsybl:powsybl-cgmes-conversion dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.powsybl:powsybl-triple-store-impl-rdf4j dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 108a1d8..0738a3f 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ SPDX-License-Identifier: Apache-2.0 2.0.2 2.11.0 1.7.32 - 4.4.0 + 4.5.0 1.4.2.Final From 6712dac12db460ac210977b5b79cd4a18b4c2195 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Wed, 10 Nov 2021 16:08:59 +0100 Subject: [PATCH 2/2] Update test and code to handle empty list of files. Signed-off-by: Dennis Labordus --- .../cim/mapping/cgmes/CgmesCimReader.java | 6 ++++++ .../exception/CompasCimMappingErrorCode.java | 1 + .../cim/mapping/cgmes/CgmesCimReaderTest.java | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReader.java b/service/src/main/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReader.java index 5f34d39..3f9ecec 100644 --- a/service/src/main/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReader.java +++ b/service/src/main/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReader.java @@ -8,6 +8,7 @@ import com.powsybl.commons.datasource.ReadOnlyMemDataSource; import com.powsybl.triplestore.api.TripleStoreFactory; import org.apache.commons.io.input.ReaderInputStream; +import org.lfenergy.compas.cim.mapping.exception.CompasCimMappingException; import org.lfenergy.compas.cim.mapping.model.CimData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,6 +21,8 @@ import java.util.Map; import java.util.stream.Collectors; +import static org.lfenergy.compas.cim.mapping.exception.CompasCimMappingErrorCode.NO_DATA_ERROR_CODE; + /** * Class to read the CIM Model into a Java Object Model to be used further for converting it to IEC 61850. */ @@ -35,6 +38,9 @@ public class CgmesCimReader { * @return The Cgmes Model that can be used to convert further to IEC 61850. */ public CgmesModel readModel(List cimData) { + if (cimData == null || cimData.isEmpty()) { + throw new CompasCimMappingException(NO_DATA_ERROR_CODE, "No CIM Data passed!"); + } LOGGER.debug("Create a ReadOnlyDataSource from the input data."); var cimContents = convertCimDataToMap(cimData); var source = new ReadOnlyMemDataSource(); diff --git a/service/src/main/java/org/lfenergy/compas/cim/mapping/exception/CompasCimMappingErrorCode.java b/service/src/main/java/org/lfenergy/compas/cim/mapping/exception/CompasCimMappingErrorCode.java index 0bf95c7..f777eb6 100644 --- a/service/src/main/java/org/lfenergy/compas/cim/mapping/exception/CompasCimMappingErrorCode.java +++ b/service/src/main/java/org/lfenergy/compas/cim/mapping/exception/CompasCimMappingErrorCode.java @@ -12,4 +12,5 @@ public class CompasCimMappingErrorCode { } public static final String UNKNOWN_TYPE_ERROR_CODE = "CIM-0001"; + public static final String NO_DATA_ERROR_CODE = "CIM-0002"; } diff --git a/service/src/test/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReaderTest.java b/service/src/test/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReaderTest.java index 2eee52b..8336b94 100644 --- a/service/src/test/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReaderTest.java +++ b/service/src/test/java/org/lfenergy/compas/cim/mapping/cgmes/CgmesCimReaderTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.cim.mapping.exception.CompasCimMappingException; import org.lfenergy.compas.cim.mapping.model.CimData; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; @@ -17,6 +18,8 @@ import static java.util.Objects.requireNonNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.lfenergy.compas.cim.mapping.exception.CompasCimMappingErrorCode.NO_DATA_ERROR_CODE; @ExtendWith(MockitoExtension.class) class CgmesCimReaderTest { @@ -36,12 +39,21 @@ void readModel_WhenReadingCimModel_ThenCgmesModelReturnedWithSubstations() throw } @Test - void readModel_WhenReadingWithoutCimModel_ThenCgmesModelReturnedWithoutSubstations() { + void readModel_WhenReadingWithEmptyCimDataList_ThenExceptionThrown() { List cimDataList = Collections.emptyList(); - var result = cgmesCimReader.readModel(cimDataList); + var exception = assertThrows(CompasCimMappingException.class, + () -> cgmesCimReader.readModel(cimDataList)); + + assertEquals(NO_DATA_ERROR_CODE, exception.getErrorCode()); + } + + @Test + void readModel_WhenReadingWithNullList_ThenExceptionThrown() { + var exception = assertThrows(CompasCimMappingException.class, + () -> cgmesCimReader.readModel(null)); - assertEquals(0, result.substations().size()); + assertEquals(NO_DATA_ERROR_CODE, exception.getErrorCode()); } private String readFile() throws IOException {