From 0aed2527f4b42230eb4027d985c28486bd8ff81d Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Fri, 18 Oct 2024 11:45:30 +0200 Subject: [PATCH] Factorize writing of CGMES profiles Signed-off-by: Romain Courtier --- .../powsybl/cgmes/conversion/test/ConversionUtil.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java index df608a0f11b..449e7f76f20 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/ConversionUtil.java @@ -7,6 +7,7 @@ */ package com.powsybl.cgmes.conversion.test; +import com.powsybl.cgmes.conversion.CgmesExport; import com.powsybl.cgmes.conversion.CgmesImportPostProcessor; import com.powsybl.cgmes.conversion.Conversion; import com.powsybl.cgmes.model.CgmesModel; @@ -97,6 +98,16 @@ public static Network readCgmesResources(Properties properties, String dir, Stri return Network.read(ds, properties); } + public static String writeCgmesProfile(Network network, String profile, Path outDir) throws IOException { + return writeCgmesProfile(network, profile, outDir, new Properties()); + } + + public static String writeCgmesProfile(Network network, String profile, Path outDir, Properties properties) throws IOException { + properties.put(CgmesExport.PROFILES, List.of(profile)); + network.write("CGMES", properties, outDir.resolve("CgmesExport")); + return Files.readString(outDir.resolve("CgmesExport_" + profile + ".xml")); + } + public static String getFirstMatch(String text, Pattern pattern) { Matcher matcher = pattern.matcher(text); if (matcher.find()) {