Skip to content

Commit

Permalink
Add extension and basename in report node + unit test
Browse files Browse the repository at this point in the history
Signed-off-by: CARON Alice <[email protected]>
  • Loading branch information
alicecaron committed Feb 4, 2025
1 parent f22791a commit a942c20
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Network importData(ReadOnlyDataSource ds, NetworkFactory networkFactory,

private Network importData1(ReadOnlyDataSource ds, NetworkFactory networkFactory, Properties p, ReportNode reportNode) {
CgmesModel cgmes = readCgmes(ds, p, reportNode);
ReportNode conversionReportNode = CgmesReports.importingCgmesFileReport(reportNode);
ReportNode conversionReportNode = CgmesReports.importingCgmesFileReport(reportNode, ds.getBaseName(), ds.getDataExtension());
return new Conversion(cgmes, config(p), activatedPreProcessors(p), activatedPostProcessors(p), networkFactory).convert(conversionReportNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ public static void missingMandatoryAttributeReport(ReportNode reportNode, String
.add();
}

public static ReportNode importingCgmesFileReport(ReportNode reportNode) {
public static ReportNode importingCgmesFileReport(ReportNode reportNode, String basename, String extension) {
return reportNode.newReportNode()
.withMessageTemplate("CGMESConversion", "Importing CGMES file(s)")
.withMessageTemplate("CGMESConversion", "Importing CGMES file(s) with basename '${basename}' and extension '${extension}'")
.withUntypedValue("basename", basename)
.withUntypedValue("extension", extension)
.add();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.powsybl.cgmes.conversion.test;

import com.powsybl.cgmes.conversion.CgmesReports;
import com.powsybl.commons.datasource.ReadOnlyDataSource;
import com.powsybl.commons.datasource.ResourceDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.commons.report.ReportNode;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
class CgmesReportsTest {

@Test
void importingCgmesFileReportTest() {
ReportNode reportRoot = ReportNode.newRootReportNode().withMessageTemplate("test", "Test reports").build();
ReadOnlyDataSource ds = new ResourceDataSource("CGMES import file(s)", new ResourceSet("/", "GeneratingUnitTypes.xml", "groundTest.xml"));
ReportNode reportNode = CgmesReports.importingCgmesFileReport(reportRoot, ds.getBaseName(), ds.getDataExtension());
assertEquals("Importing CGMES file(s) with basename 'CGMES import file(s)' and extension ''", reportNode.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Instance file MicroGridTestConfiguration_BC_BE_EQ_V2.xml
Instance file MicroGridTestConfiguration_BC_BE_SV_V2.xml
Instance file MicroGridTestConfiguration_BC_BE_SSH_V2.xml
+ Importing CGMES file(s)
+ Importing CGMES file(s) with basename 'MicroGridTestConfiguration_BC_BE' and extension ''
Applying preprocessors.
Building mappings.
Converting Substation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Instance file MicroGridTestConfiguration_BC_BE_TP_V2.xml
Instance file MicroGridTestConfiguration_BC_BE_EQ_V2.xml
Instance file MicroGridTestConfiguration_BC_BE_SSH_V2.xml
+ Importing CGMES file(s)
+ Importing CGMES file(s) with basename 'MicroGridTestConfiguration_BC_BE' and extension ''
Applying preprocessors.
Building mappings.
Converting Substation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Instance file MicroGridTestConfiguration_BC_BE_GL_V2.xml
Instance file MicroGridTestConfiguration_BC_BE_SSH_V2.xml
Instance file MicroGridTestConfiguration_BC_BE_DY_V2.xml
+ Importing CGMES file(s)
+ Importing CGMES file(s) with basename 'MicroGridTestConfiguration_BC_BE' and extension ''
Applying preprocessors.
Building mappings.
Converting Substation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Instance file MiniGridTestConfiguration_BC_EQ_v3.0.0.xml
Instance file MiniGridTestConfiguration_BC_SV_v3.0.0.xml
Instance file MiniGridTestConfiguration_BC_TP_v3.0.0.xml
+ Importing CGMES file(s)
+ Importing CGMES file(s) with basename 'MiniGridTestConfiguration_BC' and extension ''
Applying preprocessors.
Building mappings.
Converting Substation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public class TypedValue {
* @param type a string representing the value type (see the public constants for some generic types)
*/
public TypedValue(Object value, String type) {
this.value = Objects.requireNonNull(value);
this.value = null == value ? "" : value;
this.type = Objects.requireNonNull(type);
if (!(value instanceof Float || value instanceof Double || value instanceof Integer || value instanceof Long || value instanceof Boolean || value instanceof String)) {
if (!(this.value instanceof Float || this.value instanceof Double || this.value instanceof Integer || this.value instanceof Long || this.value instanceof Boolean || this.value instanceof String)) {
throw new PowsyblException("TypedValue expects only Float, Double, Integer, Long and String values (value is an instance of " + value.getClass() + ")");
}
}
Expand Down

0 comments on commit a942c20

Please sign in to comment.