-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CGMES export] UUID of fullModel on each file should be unique (#2888)
* CGMES post-processor to remove grounds (#2877) Signed-off-by: Luma <zamarrenolm@aia.es> Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com> * UUID of fullModel should be unique Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com> * Revert "UUID of fullModel should be unique" This reverts commit 7cbce1d. Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com> * Add scenario time and version in CgmesObjectReference used to generate FullModel UUID Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com> * [Shortcircuit API] Fix javadoc (#2887) Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com> * Fix checkstyle Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com> * unit test Signed-off-by: Luma <zamarrenolm@aia.es> * fix sonar issue Signed-off-by: Luma <zamarrenolm@aia.es> --------- Signed-off-by: Luma <zamarrenolm@aia.es> Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com> Co-authored-by: Luma <zamarrenolm@aia.es> (cherry picked from commit a22b33e)
- Loading branch information
1 parent
a2bce56
commit c55ad6c
Showing
2 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/issues/ModelIdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.cgmes.conversion.test.export.issues; | ||
|
||
import com.powsybl.cgmes.conversion.CgmesExport; | ||
import com.powsybl.cgmes.extensions.CgmesSshMetadataAdder; | ||
import com.powsybl.commons.PowsyblException; | ||
import com.powsybl.commons.test.AbstractSerDeTest; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.test.NetworkTest1Factory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>} | ||
*/ | ||
class ModelIdTest extends AbstractSerDeTest { | ||
|
||
private static final Pattern REGEX_FULL_MODEL_ID = Pattern.compile("FullModel rdf:about=\"(.*?)\""); | ||
|
||
@Test | ||
void testModelIds() throws IOException { | ||
Network network = NetworkTest1Factory.create("minimal-network"); | ||
|
||
// We will export the case for two different times: t0 and t1 | ||
ZonedDateTime t0 = ZonedDateTime.of(2020, 1, 1, 0, 0, 30, 0, ZoneId.systemDefault()); | ||
ZonedDateTime t1 = ZonedDateTime.of(2020, 1, 1, 1, 0, 30, 0, ZoneId.systemDefault()); | ||
Properties exportParams = new Properties(); | ||
exportParams.put(CgmesExport.NAMING_STRATEGY, "cgmes"); | ||
|
||
// Check ids of the different export parts (EQ, SSH, SV, TP) are different | ||
network.setCaseDate(t0); | ||
Map<String, String> ids0 = exportedIds(network, exportParams); | ||
Set<String> uniqueIds = new HashSet<>(ids0.values()); | ||
assertEquals(ids0.size(), uniqueIds.size()); | ||
|
||
// Check we get different ids when scenarioTime changes | ||
network.setCaseDate(t1); | ||
Map<String, String> ids1 = exportedIds(network, exportParams); | ||
assertNotEquals(ids0.get("SSH"), ids1.get("SSH")); | ||
assertNotEquals(ids0.get("SV"), ids1.get("SV")); | ||
assertNotEquals(ids0.get("TP"), ids1.get("TP")); | ||
|
||
// Check that we get different ids when version changes | ||
// The way to force a different version number in the output | ||
// is to give a previous version number inside metadata extension | ||
// Export will increase the version number available in the metadata | ||
network.newExtension(CgmesSshMetadataAdder.class) | ||
.setId("not-relevant") | ||
.setDescription("not-relevant") | ||
.setSshVersion(42) | ||
.setModelingAuthoritySet("not-relevant") | ||
.addDependency("not-relevant") | ||
.add(); | ||
Map<String, String> ids1v = exportedIds(network, exportParams); | ||
// We only have added previous version for SSH data, so only SSH id must have changed | ||
assertNotEquals(ids1.get("SSH"), ids1v.get("SSH")); | ||
assertEquals(ids1.get("SV"), ids1v.get("SV")); | ||
} | ||
|
||
String modelId(String xml) { | ||
Matcher matcher = REGEX_FULL_MODEL_ID.matcher(xml); | ||
if (matcher.find()) { | ||
return matcher.group(1); | ||
} else { | ||
throw new PowsyblException("missing model id"); | ||
} | ||
} | ||
|
||
private String read(String basename, String profile) throws IOException { | ||
String instanceFile = String.format("%s_%s.xml", basename, profile); | ||
return Files.readString(tmpDir.resolve(instanceFile)); | ||
} | ||
|
||
private Map<String, String> exportedIds(Network network, Properties exportParams) throws IOException { | ||
String basename = network.getNameOrId(); | ||
network.write("CGMES", exportParams, tmpDir.resolve(basename)); | ||
return Map.of("EQ", modelId(read(basename, "EQ")), | ||
"SSH", modelId(read(basename, "SSH")), | ||
"TP", modelId(read(basename, "TP")), | ||
"SV", modelId(read(basename, "SV"))); | ||
} | ||
} |