From aee0ca342758acb8d1730802273f8b8c86a0a6c5 Mon Sep 17 00:00:00 2001 From: lisrte Date: Tue, 7 Feb 2023 14:28:01 +0100 Subject: [PATCH 1/4] Refactor Dynawaltz DSL local Command executor in unitary tests, fix code smells Signed-off-by: lisrte --- .../DynaWaltzGroovyCurvesSupplierTest.java | 82 ++++++-------- ...AbstractDynaWaltzLocalCommandExecutor.java | 87 --------------- .../ieee/DynaWaltzLocalCommandExecutor.java | 102 ++++++++++++++++++ ...entLimitAutomatonLocalCommandExecutor.java | 47 -------- .../Ieee14CurrentLimitAutomatonTest.java | 14 +-- ...e14DisconnectLineLocalCommandExecutor.java | 47 -------- .../dsl/ieee14/Ieee14DisconnectLineTest.java | 12 +-- .../dsl/ieee14/Ieee14MacroConnectsTest.java | 12 +-- ...ee14MacroconnectsLocalCommandExecutor.java | 47 -------- ...sconnectGeneratorLocalCommandExecutor.java | 47 -------- .../ieee57/Ieee57DisconnectGeneratorTest.java | 12 +-- 11 files changed, 157 insertions(+), 352 deletions(-) delete mode 100644 dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractDynaWaltzLocalCommandExecutor.java create mode 100644 dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java delete mode 100644 dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonLocalCommandExecutor.java delete mode 100644 dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineLocalCommandExecutor.java delete mode 100644 dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroconnectsLocalCommandExecutor.java delete mode 100644 dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorLocalCommandExecutor.java diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java index 5cd1e7bac..a390967da 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java @@ -6,21 +6,6 @@ */ package com.powsybl.dynawaltz.dsl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.util.Arrays; -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; import com.powsybl.dsl.DslException; @@ -35,15 +20,24 @@ import com.powsybl.iidm.network.Load; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.FileSystem; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import static org.junit.Assert.*; /** * @author Marcos de Miguel */ public class DynaWaltzGroovyCurvesSupplierTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - private FileSystem fileSystem; private Network network; @@ -52,10 +46,10 @@ public void setup() throws IOException { fileSystem = Jimfs.newFileSystem(Configuration.unix()); network = EurostagTutorialExample1Factory.create(); - Files.copy(getClass().getResourceAsStream("/curves.groovy"), fileSystem.getPath("/curves.groovy")); - Files.copy(getClass().getResourceAsStream("/curves_dynamicModelId_staticId.groovy"), fileSystem.getPath("/curves_dynamicModelId_staticId.groovy")); - Files.copy(getClass().getResourceAsStream("/curves_variable.groovy"), fileSystem.getPath("/curves_variable.groovy")); - Files.copy(getClass().getResourceAsStream("/curves_variables.groovy"), fileSystem.getPath("/curves_variables.groovy")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/curves.groovy")), fileSystem.getPath("/curves.groovy")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/curves_dynamicModelId_staticId.groovy")), fileSystem.getPath("/curves_dynamicModelId_staticId.groovy")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/curves_variable.groovy")), fileSystem.getPath("/curves_variable.groovy")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/curves_variables.groovy")), fileSystem.getPath("/curves_variables.groovy")); } @After @@ -65,13 +59,8 @@ public void tearDown() throws IOException { @Test public void test() { - - List extensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME); - assertEquals(1, extensions.size()); - assertTrue(extensions.get(0) instanceof DynaWaltzCurveGroovyExtension); - + List extensions = validateGroovyExtension(); CurvesSupplier supplier = new GroovyCurvesSupplier(fileSystem.getPath("/curves.groovy"), extensions); - List curves = supplier.get(network); assertEquals(11, curves.size()); curves.forEach(this::validateCurve); @@ -79,44 +68,33 @@ public void test() { @Test public void testModelIdStaticIdDefined() { - - exception.expect(DslException.class); - exception.expectMessage("Both staticId and dynamicModelId are defined"); - - List extensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME); - assertEquals(1, extensions.size()); - assertTrue(extensions.get(0) instanceof DynaWaltzCurveGroovyExtension); - + List extensions = validateGroovyExtension(); CurvesSupplier supplier = new GroovyCurvesSupplier(fileSystem.getPath("/curves_dynamicModelId_staticId.groovy"), extensions); - supplier.get(network); + DslException exception = assertThrows(DslException.class, () -> supplier.get(network)); + assertEquals("Both staticId and dynamicModelId are defined", exception.getMessage()); } @Test public void testVariableNotDefined() { - - exception.expect(DslException.class); - exception.expectMessage("'variables' field is not set"); - - List extensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME); - assertEquals(1, extensions.size()); - assertTrue(extensions.get(0) instanceof DynaWaltzCurveGroovyExtension); - + List extensions = validateGroovyExtension(); CurvesSupplier supplier = new GroovyCurvesSupplier(fileSystem.getPath("/curves_variable.groovy"), extensions); - supplier.get(network); + DslException exception = assertThrows(DslException.class, () -> supplier.get(network)); + assertEquals("'variables' field is not set", exception.getMessage()); } @Test public void testVariablesNotDefined() { + List extensions = validateGroovyExtension(); + CurvesSupplier supplier = new GroovyCurvesSupplier(fileSystem.getPath("/curves_variables.groovy"), extensions); + DslException exception = assertThrows(DslException.class, () -> supplier.get(network)); + assertEquals("'variables' field is not set", exception.getMessage()); + } - exception.expect(DslException.class); - exception.expectMessage("'variables' field is not set"); - + private List validateGroovyExtension() { List extensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME); assertEquals(1, extensions.size()); assertTrue(extensions.get(0) instanceof DynaWaltzCurveGroovyExtension); - - CurvesSupplier supplier = new GroovyCurvesSupplier(fileSystem.getPath("/curves_variables.groovy"), extensions); - supplier.get(network); + return extensions; } private void validateCurve(Curve curve) { diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractDynaWaltzLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractDynaWaltzLocalCommandExecutor.java deleted file mode 100644 index 49d04ebea..000000000 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractDynaWaltzLocalCommandExecutor.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) 2020, 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/. - */ -package com.powsybl.dynawaltz.dsl.ieee; - -import static org.junit.Assert.assertFalse; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.FileSystem; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import javax.xml.transform.Source; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xmlunit.builder.DiffBuilder; -import org.xmlunit.builder.Input; -import org.xmlunit.diff.Diff; - -import com.powsybl.computation.local.LocalCommandExecutor; -import com.powsybl.dynawaltz.DynaWaltzParameters; -import com.powsybl.iidm.network.Network; - -/** - * @author Marcos de Miguel - */ -public abstract class AbstractDynaWaltzLocalCommandExecutor implements LocalCommandExecutor { - - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDynaWaltzLocalCommandExecutor.class); - - protected final FileSystem fileSystem; - protected final Network network; - protected final DynaWaltzParameters dynaWaltzParameters; - - public AbstractDynaWaltzLocalCommandExecutor(FileSystem fileSystem, Network network, DynaWaltzParameters dynaWaltzParameters) { - this.fileSystem = Objects.requireNonNull(fileSystem); - this.network = Objects.requireNonNull(network); - this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters); - } - - protected abstract void validateInputs(Path workingDir) throws IOException; - - protected abstract void copyOutputs(Path workingDir) throws IOException; - - @Override - public int execute(String program, List args, Path outFile, Path errFile, Path workingDir, Map env) throws IOException { - return execute(program, -1, args, outFile, errFile, workingDir, env); - } - - @Override - public int execute(String program, long timeoutSeconds, List args, Path outFile, Path errFile, Path workingDir, Map env) throws IOException { - try { - validateInputs(workingDir); - copyOutputs(workingDir); - } catch (Throwable throwable) { - LOGGER.error(throwable.toString(), throwable); - return -1; - } - return 0; - } - - @Override - public void stop(Path workingDir) { - } - - @Override - public void stopForcibly(Path workingDir) { - } - - protected static void compareXml(InputStream expected, InputStream actual) { - Source control = Input.fromStream(expected).build(); - Source test = Input.fromStream(actual).build(); - Diff myDiff = DiffBuilder.compare(control).withTest(test).ignoreWhitespace().ignoreComments().build(); - boolean hasDiff = myDiff.hasDifferences(); - if (hasDiff) { - System.err.println(myDiff.toString()); - } - assertFalse(hasDiff); - } -} diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java new file mode 100644 index 000000000..9d84622b9 --- /dev/null +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2020, 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/. + */ +package com.powsybl.dynawaltz.dsl.ieee; + +import com.powsybl.computation.local.LocalCommandExecutor; +import com.powsybl.dynawaltz.DynaWaltzParameters; +import com.powsybl.iidm.network.Network; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.Diff; + +import javax.xml.transform.Source; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.FileSystem; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.*; +import static org.junit.Assert.assertFalse; + +/** + * @author Marcos de Miguel + */ +public class DynaWaltzLocalCommandExecutor implements LocalCommandExecutor { + + private static final Logger LOGGER = LoggerFactory.getLogger(DynaWaltzLocalCommandExecutor.class); + private final FileSystem fileSystem; + private final Network network; + private final DynaWaltzParameters dynaWaltzParameters; + private final String baseDirName; + private final String busSystem; + + public DynaWaltzLocalCommandExecutor(FileSystem fileSystem, Network network, DynaWaltzParameters dynaWaltzParameters, String baseDir, String busSystem) { + this.fileSystem = Objects.requireNonNull(fileSystem); + this.network = Objects.requireNonNull(network); + this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters); + this.baseDirName = baseDir; + this.busSystem = busSystem; + } + + protected void validateInputs(Path workingDir) throws IOException { + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.xiidm"), Files.newInputStream(workingDir.resolve(NETWORK_FILENAME))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.jobs"), Files.newInputStream(workingDir.resolve(JOBS_FILENAME))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.dyd"), Files.newInputStream(workingDir.resolve(DYD_FILENAME))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/" + busSystem + "bus.par"), Files.newInputStream(workingDir.resolve(network.getId() + ".par"))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); + } + + protected void copyOutputs(Path workingDir) throws IOException { + Path output = Files.createDirectories(workingDir.resolve("outputs/curves").toAbsolutePath()); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-outputs/curves.csv")), output.resolve("curves.csv")); + } + + @Override + public int execute(String program, List args, Path outFile, Path errFile, Path workingDir, Map env) { + return execute(program, -1, args, outFile, errFile, workingDir, env); + } + + @Override + public int execute(String program, long timeoutSeconds, List args, Path outFile, Path errFile, Path workingDir, Map env) { + try { + validateInputs(workingDir); + copyOutputs(workingDir); + } catch (Throwable throwable) { + LOGGER.error(throwable.toString(), throwable); + return -1; + } + return 0; + } + + @Override + public void stop(Path workingDir) { + } + + @Override + public void stopForcibly(Path workingDir) { + } + + protected static void compareXml(InputStream expected, InputStream actual) { + Source control = Input.fromStream(expected).build(); + Source test = Input.fromStream(actual).build(); + Diff myDiff = DiffBuilder.compare(control).withTest(test).ignoreWhitespace().ignoreComments().build(); + boolean hasDiff = myDiff.hasDifferences(); + if (hasDiff) { + System.err.println(myDiff); + } + assertFalse(hasDiff); + } +} diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonLocalCommandExecutor.java deleted file mode 100644 index 005873876..000000000 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonLocalCommandExecutor.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2020, 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/. - */ -package com.powsybl.dynawaltz.dsl.ieee14; - -import com.powsybl.dynawaltz.DynaWaltzParameters; -import com.powsybl.dynawaltz.dsl.ieee.AbstractDynaWaltzLocalCommandExecutor; -import com.powsybl.iidm.network.Network; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; - -import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.*; - -/** - * @author Marcos de Miguel - */ -public class Ieee14CurrentLimitAutomatonLocalCommandExecutor extends AbstractDynaWaltzLocalCommandExecutor { - - public Ieee14CurrentLimitAutomatonLocalCommandExecutor(FileSystem fileSystem, Network network, DynaWaltzParameters dynaWaltzParameters) { - super(fileSystem, network, dynaWaltzParameters); - } - - @Override - protected void validateInputs(Path workingDir) throws IOException { - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.xiidm"), Files.newInputStream(workingDir.resolve(NETWORK_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.jobs"), Files.newInputStream(workingDir.resolve(JOBS_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.dyd"), Files.newInputStream(workingDir.resolve(DYD_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/ieee14bus.par"), Files.newInputStream(workingDir.resolve(network.getId() + ".par"))); - compareXml(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); - } - - @Override - protected void copyOutputs(Path workingDir) throws IOException { - Path output = Files.createDirectories(workingDir.resolve("outputs/curves").toAbsolutePath()); - Files.copy(getClass().getResourceAsStream("/ieee14-currentlimitautomaton/dynawaltz-outputs/curves.csv"), output.resolve("curves.csv")); - } - -} diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java index 105d91e08..646d5769c 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java @@ -6,15 +6,15 @@ */ package com.powsybl.dynawaltz.dsl.ieee14; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - +import com.powsybl.dynamicsimulation.DynamicSimulationResult; +import com.powsybl.dynawaltz.dsl.ieee.AbstractIeeeTest; +import com.powsybl.dynawaltz.dsl.ieee.DynaWaltzLocalCommandExecutor; import org.junit.Before; import org.junit.Test; -import com.powsybl.dynamicsimulation.DynamicSimulationResult; -import com.powsybl.dynawaltz.dsl.ieee.AbstractIeeeTest; +import java.io.IOException; + +import static org.junit.Assert.assertNotNull; /** * @author Marcos de Miguel @@ -37,7 +37,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - Ieee14CurrentLimitAutomatonLocalCommandExecutor commandExecutor = new Ieee14CurrentLimitAutomatonLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters)); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineLocalCommandExecutor.java deleted file mode 100644 index 548398071..000000000 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineLocalCommandExecutor.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2020, 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/. - */ -package com.powsybl.dynawaltz.dsl.ieee14; - -import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.*; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; - -import com.powsybl.dynawaltz.DynaWaltzParameters; -import com.powsybl.dynawaltz.dsl.ieee.AbstractDynaWaltzLocalCommandExecutor; -import com.powsybl.iidm.network.Network; - -/** - * @author Marcos de Miguel - */ -public class Ieee14DisconnectLineLocalCommandExecutor extends AbstractDynaWaltzLocalCommandExecutor { - - public Ieee14DisconnectLineLocalCommandExecutor(FileSystem fileSystem, Network network, DynaWaltzParameters dynaWaltzParameters) { - super(fileSystem, network, dynaWaltzParameters); - } - - @Override - protected void validateInputs(Path workingDir) throws IOException { - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.xiidm"), Files.newInputStream(workingDir.resolve(NETWORK_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.jobs"), Files.newInputStream(workingDir.resolve(JOBS_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.dyd"), Files.newInputStream(workingDir.resolve(DYD_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/ieee14bus.par"), Files.newInputStream(workingDir.resolve(network.getId() + ".par"))); - compareXml(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); - } - - @Override - protected void copyOutputs(Path workingDir) throws IOException { - Path output = Files.createDirectories(workingDir.resolve("outputs/curves").toAbsolutePath()); - Files.copy(getClass().getResourceAsStream("/ieee14-disconnectline/dynawaltz-outputs/curves.csv"), output.resolve("curves.csv")); - } - -} diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java index 7121a23cb..38f580bd4 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java @@ -6,15 +6,15 @@ */ package com.powsybl.dynawaltz.dsl.ieee14; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - +import com.powsybl.dynamicsimulation.DynamicSimulationResult; import com.powsybl.dynawaltz.dsl.ieee.AbstractIeeeTest; +import com.powsybl.dynawaltz.dsl.ieee.DynaWaltzLocalCommandExecutor; import org.junit.Before; import org.junit.Test; -import com.powsybl.dynamicsimulation.DynamicSimulationResult; +import java.io.IOException; + +import static org.junit.Assert.assertNotNull; /** * @author Marcos de Miguel @@ -36,7 +36,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - Ieee14DisconnectLineLocalCommandExecutor commandExecutor = new Ieee14DisconnectLineLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters)); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); DynamicSimulationResult result; result = runSimulation(commandExecutor); assertNotNull(result); diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java index 6f822a142..481456364 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java @@ -6,15 +6,15 @@ */ package com.powsybl.dynawaltz.dsl.ieee14; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - +import com.powsybl.dynamicsimulation.DynamicSimulationResult; import com.powsybl.dynawaltz.dsl.ieee.AbstractIeeeTest; +import com.powsybl.dynawaltz.dsl.ieee.DynaWaltzLocalCommandExecutor; import org.junit.Before; import org.junit.Test; -import com.powsybl.dynamicsimulation.DynamicSimulationResult; +import java.io.IOException; + +import static org.junit.Assert.assertNotNull; /** * @author Marcos de Miguel @@ -37,7 +37,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - Ieee14MacroconnectsLocalCommandExecutor commandExecutor = new Ieee14MacroconnectsLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters)); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroconnectsLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroconnectsLocalCommandExecutor.java deleted file mode 100644 index 498a14e0d..000000000 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroconnectsLocalCommandExecutor.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2020, 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/. - */ -package com.powsybl.dynawaltz.dsl.ieee14; - -import com.powsybl.dynawaltz.DynaWaltzParameters; -import com.powsybl.dynawaltz.dsl.ieee.AbstractDynaWaltzLocalCommandExecutor; -import com.powsybl.iidm.network.Network; - -import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.*; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * @author Marcos de Miguel - */ -public class Ieee14MacroconnectsLocalCommandExecutor extends AbstractDynaWaltzLocalCommandExecutor { - - public Ieee14MacroconnectsLocalCommandExecutor(FileSystem fileSystem, Network network, DynaWaltzParameters dynaWaltzParameters) { - super(fileSystem, network, dynaWaltzParameters); - } - - @Override - protected void validateInputs(Path workingDir) throws IOException { - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.xiidm"), Files.newInputStream(workingDir.resolve(NETWORK_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.jobs"), Files.newInputStream(workingDir.resolve(JOBS_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.dyd"), Files.newInputStream(workingDir.resolve(DYD_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/ieee14bus.par"), Files.newInputStream(workingDir.resolve(network.getId() + ".par"))); - compareXml(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); - } - - @Override - protected void copyOutputs(Path workingDir) throws IOException { - Path output = Files.createDirectories(workingDir.resolve("outputs/curves").toAbsolutePath()); - Files.copy(getClass().getResourceAsStream("/ieee14-macroconnects/dynawaltz-outputs/curves.csv"), output.resolve("curves.csv")); - } - -} diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorLocalCommandExecutor.java deleted file mode 100644 index 7fbdb243c..000000000 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorLocalCommandExecutor.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2020, 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/. - */ -package com.powsybl.dynawaltz.dsl.ieee57; - -import com.powsybl.dynawaltz.DynaWaltzParameters; -import com.powsybl.dynawaltz.dsl.ieee.AbstractDynaWaltzLocalCommandExecutor; -import com.powsybl.iidm.network.Network; - -import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.*; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * @author Marcos de Miguel - */ -public class Ieee57DisconnectGeneratorLocalCommandExecutor extends AbstractDynaWaltzLocalCommandExecutor { - - public Ieee57DisconnectGeneratorLocalCommandExecutor(FileSystem fileSystem, Network network, DynaWaltzParameters dynaWaltzParameters) { - super(fileSystem, network, dynaWaltzParameters); - } - - @Override - protected void validateInputs(Path workingDir) throws IOException { - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.xiidm"), Files.newInputStream(workingDir.resolve(NETWORK_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.jobs"), Files.newInputStream(workingDir.resolve(JOBS_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.dyd"), Files.newInputStream(workingDir.resolve(DYD_FILENAME))); - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/ieee57bus.par"), Files.newInputStream(workingDir.resolve(network.getId() + ".par"))); - compareXml(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); - } - - @Override - protected void copyOutputs(Path workingDir) throws IOException { - Path output = Files.createDirectories(workingDir.resolve("outputs/curves").toAbsolutePath()); - Files.copy(getClass().getResourceAsStream("/ieee57-disconnectgenerator/dynawaltz-outputs/curves.csv"), output.resolve("curves.csv")); - } - -} diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java index ebd64f72a..f6f6621ae 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java @@ -6,15 +6,15 @@ */ package com.powsybl.dynawaltz.dsl.ieee57; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - +import com.powsybl.dynamicsimulation.DynamicSimulationResult; import com.powsybl.dynawaltz.dsl.ieee.AbstractIeeeTest; +import com.powsybl.dynawaltz.dsl.ieee.DynaWaltzLocalCommandExecutor; import org.junit.Before; import org.junit.Test; -import com.powsybl.dynamicsimulation.DynamicSimulationResult; +import java.io.IOException; + +import static org.junit.Assert.assertNotNull; /** * @author Marcos de Miguel @@ -36,7 +36,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - Ieee57DisconnectGeneratorLocalCommandExecutor commandExecutor = new Ieee57DisconnectGeneratorLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters)); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee57"); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } From 8e2e63f4f29ba68deecd1f6c7e7a7a929602a3eb Mon Sep 17 00:00:00 2001 From: lisrte Date: Tue, 14 Feb 2023 15:46:43 +0100 Subject: [PATCH 2/4] Fix review Signed-off-by: lisrte --- .../dsl/ieee/DynaWaltzLocalCommandExecutor.java | 10 +++++----- .../dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java | 2 +- .../dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java | 2 +- .../dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java | 2 +- .../dsl/ieee57/Ieee57DisconnectGeneratorTest.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java index 9d84622b9..b084b20ef 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java @@ -8,7 +8,6 @@ import com.powsybl.computation.local.LocalCommandExecutor; import com.powsybl.dynawaltz.DynaWaltzParameters; -import com.powsybl.iidm.network.Network; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xmlunit.builder.DiffBuilder; @@ -30,19 +29,20 @@ /** * @author Marcos de Miguel + * @author Laurent Issertial */ public class DynaWaltzLocalCommandExecutor implements LocalCommandExecutor { private static final Logger LOGGER = LoggerFactory.getLogger(DynaWaltzLocalCommandExecutor.class); private final FileSystem fileSystem; - private final Network network; + private final String networkId; private final DynaWaltzParameters dynaWaltzParameters; private final String baseDirName; private final String busSystem; - public DynaWaltzLocalCommandExecutor(FileSystem fileSystem, Network network, DynaWaltzParameters dynaWaltzParameters, String baseDir, String busSystem) { + public DynaWaltzLocalCommandExecutor(FileSystem fileSystem, String networkId, DynaWaltzParameters dynaWaltzParameters, String baseDir, String busSystem) { this.fileSystem = Objects.requireNonNull(fileSystem); - this.network = Objects.requireNonNull(network); + this.networkId = Objects.requireNonNull(networkId); this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters); this.baseDirName = baseDir; this.busSystem = busSystem; @@ -55,7 +55,7 @@ protected void validateInputs(Path workingDir) throws IOException { compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/" + busSystem + "bus.par"), Files.newInputStream(workingDir.resolve(network.getId() + ".par"))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/" + busSystem + "bus.par"), Files.newInputStream(workingDir.resolve(networkId + ".par"))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java index 646d5769c..711b9d348 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java @@ -37,7 +37,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java index 38f580bd4..ff74f4ad5 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java @@ -36,7 +36,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); DynamicSimulationResult result; result = runSimulation(commandExecutor); assertNotNull(result); diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java index 481456364..1a8bd9cee 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java @@ -37,7 +37,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java index f6f6621ae..2d193ed41 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java @@ -36,7 +36,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network, getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee57"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee57"); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } From 254d8a454051350cac011b0ce7a10ba8b6ac875e Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 21 Feb 2023 16:31:54 +0100 Subject: [PATCH 3/4] Remove busSystem Signed-off-by: Florian Dupuy --- .../dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java | 7 ++----- .../dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java | 2 +- .../dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java | 2 +- .../dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java | 2 +- .../dsl/ieee57/Ieee57DisconnectGeneratorTest.java | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java index b084b20ef..8507bb693 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java @@ -38,14 +38,11 @@ public class DynaWaltzLocalCommandExecutor implements LocalCommandExecutor { private final String networkId; private final DynaWaltzParameters dynaWaltzParameters; private final String baseDirName; - private final String busSystem; - - public DynaWaltzLocalCommandExecutor(FileSystem fileSystem, String networkId, DynaWaltzParameters dynaWaltzParameters, String baseDir, String busSystem) { + public DynaWaltzLocalCommandExecutor(FileSystem fileSystem, String networkId, DynaWaltzParameters dynaWaltzParameters, String baseDir) { this.fileSystem = Objects.requireNonNull(fileSystem); this.networkId = Objects.requireNonNull(networkId); this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters); this.baseDirName = baseDir; - this.busSystem = busSystem; } protected void validateInputs(Path workingDir) throws IOException { @@ -55,7 +52,7 @@ protected void validateInputs(Path workingDir) throws IOException { compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/" + busSystem + "bus.par"), Files.newInputStream(workingDir.resolve(networkId + ".par"))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/" + networkId + ".par"), Files.newInputStream(workingDir.resolve(networkId + ".par"))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java index 711b9d348..a3c861fbb 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java @@ -37,7 +37,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName()); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java index ff74f4ad5..2f9c1c8d7 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java @@ -36,7 +36,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName()); DynamicSimulationResult result; result = runSimulation(commandExecutor); assertNotNull(result); diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java index 1a8bd9cee..375888b5b 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java @@ -37,7 +37,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee14"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName()); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java index 2d193ed41..835f878cf 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java @@ -36,7 +36,7 @@ public void setup() throws IOException { @Test public void testSimulation() throws Exception { - DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName(), "ieee57"); + DynaWaltzLocalCommandExecutor commandExecutor = new DynaWaltzLocalCommandExecutor(fileSystem, network.getId(), getDynaWaltzSimulationParameters(parameters), getWorkingDirName()); DynamicSimulationResult result = runSimulation(commandExecutor); assertNotNull(result); } From 3d607703ba9996e9326567b4f4a1ed683f4d0cd3 Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 21 Feb 2023 16:46:41 +0100 Subject: [PATCH 4/4] Fix checkstyle Signed-off-by: Florian Dupuy --- .../dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java index 8507bb693..669d37f0d 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java @@ -38,6 +38,7 @@ public class DynaWaltzLocalCommandExecutor implements LocalCommandExecutor { private final String networkId; private final DynaWaltzParameters dynaWaltzParameters; private final String baseDirName; + public DynaWaltzLocalCommandExecutor(FileSystem fileSystem, String networkId, DynaWaltzParameters dynaWaltzParameters, String baseDir) { this.fileSystem = Objects.requireNonNull(fileSystem); this.networkId = Objects.requireNonNull(networkId);