Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CGMES] Add new parameter to make ModelDescription custom #2628

Merged
merged 8 commits into from
Jul 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.FictitiousSwitchFactory;
import com.powsybl.iidm.network.util.Networks;
import com.powsybl.iidm.xml.ExportOptions;
import com.powsybl.iidm.xml.NetworkXml;
import com.powsybl.triplestore.api.TripleStoreFactory;
import org.junit.jupiter.api.Test;

Expand All @@ -40,9 +42,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.*;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import static com.powsybl.cgmes.conversion.test.export.ExportXmlCompare.compareEQNetworks;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -477,6 +481,27 @@ void testModelDescription() throws IOException {
assertEquals(modelDescription, sshMetadata.getDescription());
}

@Test
void testModelDescriptionClosingXML() throws IOException {
Network network = EurostagTutorialExample1Factory.create();

// Security test
// Checking that putting end-tag does not corrupt the file
String modelDescription = "powsybl community</md:Model.modelingAuthoritySet></md:FullModel>";
Properties params = new Properties();
params.put(CgmesExport.MODEL_DESCRIPTION, modelDescription);

FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
colinepiloquet marked this conversation as resolved.
Show resolved Hide resolved
Path tmpDir = Files.createDirectory(fileSystem.getPath("tmp"));
ZipFileDataSource zip = new ZipFileDataSource(tmpDir.resolve("."), "output");
new CgmesExport().export(network, params, zip);

// check network can be reimported and that ModelDescription still includes end-tag
Network network2 = Network.read(tmpDir.resolve("output.zip"));
CgmesSshMetadata sshMetadata = network2.getExtension(CgmesSshMetadata.class);
assertEquals(modelDescription, sshMetadata.getDescription());
}

private static void checkDanglingLineParams(DanglingLine expected, DanglingLine actual) {
assertEquals(expected.getR(), actual.getR(), EPSILON);
assertEquals(expected.getX(), actual.getX(), EPSILON);
Expand Down