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

Code cleanup to correct issues reported by Sonar (Severity: high - part 2) #2974

Merged
merged 142 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
625fd76
add test to avoid NullPointerException
rolnico Apr 5, 2024
5c8d233
fix return statement in MergedBus
rolnico Apr 5, 2024
6f77f25
add test to avoid potential ArrayIndexOutOfBoundsException
rolnico Apr 5, 2024
624c337
BREAKING CHANGE - Change JsonTypeInfo to avoid unsafe Jackson deseria…
rolnico Apr 5, 2024
aa523f1
fix GeneratorModificationActionTest
rolnico Apr 5, 2024
489d5ff
remove peek usage
rolnico Apr 8, 2024
c5d232c
remove duplicated tests
rolnico Apr 8, 2024
05de80b
remove exceptions not thrown
rolnico Apr 8, 2024
7f23910
if simplifications
rolnico Apr 8, 2024
bcd721f
removed unused methods
rolnico Apr 8, 2024
21da610
use Supplier from java instead if guava
rolnico Apr 8, 2024
b3ce26c
use Supplier from java instead if guava
rolnico Apr 8, 2024
9867b6d
ParsingContext declared final
rolnico Apr 8, 2024
6792363
XmlStaxContext declared final
rolnico Apr 8, 2024
266e337
replaced deprecated method for ZipFile with SeekableByteChannel
rolnico Apr 8, 2024
1a38ad6
swapped from deprecated org.apache.commons.compress.utils.IOUtils to …
rolnico Apr 8, 2024
0afcfbc
removed deprecated .newInstance method call
rolnico Apr 8, 2024
e81dc90
EmptyModuleConfigRepository declared final
rolnico Apr 8, 2024
8541b77
removed old deprecated methods + replaced guava supplier by java supp…
rolnico Apr 8, 2024
d836935
replaced deprecated Zipfile constructor by builder
rolnico Apr 8, 2024
59fd06e
replaced supplier
rolnico Apr 8, 2024
d7a6662
fix
rolnico Apr 8, 2024
06cbf2c
fix
rolnico Apr 8, 2024
0e3d1b7
fix StandardCharsets.UTF_8
rolnico Apr 8, 2024
4e1cf4a
fix
rolnico Apr 8, 2024
7a8c0eb
fix
rolnico Apr 8, 2024
af70c7f
replace supplier
rolnico Apr 8, 2024
05235c0
replace ZipFile by builder
rolnico Apr 8, 2024
afe04ce
catch Exception instead of Throwable
rolnico Apr 8, 2024
f5ef925
group logic in createComputationManager for shortTime and longTime co…
rolnico Apr 8, 2024
64af211
replace supplier
rolnico Apr 8, 2024
b66d047
remove deprecated methods in PlatformConfigNamedProvider
rolnico Apr 8, 2024
e7d471b
clean DynamicSimulationParameters
rolnico Apr 8, 2024
5398858
replace supplier
rolnico Apr 8, 2024
57d9ba1
clean Networks
rolnico Apr 8, 2024
6c1b6b7
remove old deprecated methods in StandbyAutomaton
rolnico Apr 8, 2024
85c9d41
remove old deprecated methods in StandbyAutomaton
rolnico Apr 8, 2024
d7bfc1d
remove old deprecated methods in StandbyAutomatonAdder
rolnico Apr 8, 2024
cb18318
Renamed "RL" to match the regular expression '^[A-Z][0-9]?$'.
rolnico Apr 8, 2024
920a3a1
Renamed "OWNER" to match the regular expression '^[A-Z][0-9]?$'.
rolnico Apr 8, 2024
2ee5055
Renamed "OWNER" to match the regular expression '^[A-Z][0-9]?$'.
rolnico Apr 8, 2024
44955f5
fix ReactiveCapabilityCurveAdderImpl
rolnico Apr 8, 2024
3f346ef
Rename "RL" to match the regular expression '^[A-Z][0-9]?$'.
rolnico Apr 8, 2024
c58e61a
changed supplier
rolnico Apr 8, 2024
d761eee
extract closeAndUseGarbageCollector in XMLImporter
rolnico Apr 8, 2024
aa5618b
fix Networks
rolnico Apr 8, 2024
4bb71e7
use List.of
rolnico Apr 8, 2024
a663970
remove import
rolnico Apr 8, 2024
6068329
concat duplicated test in one parametrized
rolnico Apr 8, 2024
3997949
use Map.of
rolnico Apr 8, 2024
e3ffea3
streams in try with resources
rolnico Apr 8, 2024
f64f4d4
remove import
rolnico Apr 8, 2024
0f92791
changed supplier + Stream.toList()
rolnico Apr 8, 2024
3af20d2
fix logger class
rolnico Apr 8, 2024
4e4273a
fix ValidationUtils
rolnico Apr 8, 2024
79f771e
make inner classes static in AbstractValidationFormatterWriter
rolnico Apr 8, 2024
ab5be9c
removed deprecated method UndirectedGraph.getMaxVertex
rolnico Apr 8, 2024
eeb2475
removed blank lines
rolnico Apr 8, 2024
3ff8441
fix map with preserved order
rolnico Apr 10, 2024
46103a3
fix PsseExporter issues
rolnico Apr 10, 2024
66c58ea
simplify condition
rolnico Apr 10, 2024
f14362b
swap Supplier
rolnico Apr 10, 2024
11ef1a7
swap Supplier
rolnico Apr 10, 2024
480ef80
swap Supplier
rolnico Apr 10, 2024
41b3e94
swap Supplier + string variable
rolnico Apr 10, 2024
350bbd3
swap Supplier
rolnico Apr 10, 2024
5dd35e4
replace 3 tests with one parametrized
rolnico Apr 10, 2024
5fb9736
fix ExporterTest issues
rolnico Apr 10, 2024
2a36e4e
swap supplier
rolnico Apr 10, 2024
02a54ff
replaced 3 tests with one parametrized
rolnico Apr 10, 2024
fe39abe
fix TimeSeriesMetadata issues
rolnico Apr 10, 2024
dc113b4
replace ImmutableMap with Collections.unmodifiableMap(LinkedHashMap)
rolnico Apr 10, 2024
aafadaa
replace XMLSchema.STRING with XSD.STRING
rolnico Apr 10, 2024
f6381cf
replace XMLSchema.STRING with XSD.STRING
rolnico Apr 10, 2024
8194926
regroup 17 tests in 4 parametrized tests
rolnico Apr 10, 2024
d2688d6
fix JsonActionTest issues
rolnico Apr 10, 2024
03410ff
fix JsonActionTest issues
rolnico Apr 10, 2024
52daf55
fix PreDefinedConditionTest issue
rolnico Apr 10, 2024
b8c69bb
fix issues with no assertions visible
rolnico Apr 10, 2024
e44bfb3
fix issues in AmplUtil
rolnico Apr 10, 2024
e9c775b
replace identical strings with variable
rolnico Apr 10, 2024
3165118
replace identical strings with variables
rolnico Apr 10, 2024
b40d390
replace identical strings with variables
rolnico Apr 11, 2024
d88b69e
extract internal methods in CgmesConformity1NetworkCatalog
rolnico Apr 11, 2024
eb46874
delete unused variables + add corresponding comments
rolnico Apr 11, 2024
dbfd45a
reduce method complexity
rolnico Apr 11, 2024
11ad702
reduce method complexity
rolnico Apr 11, 2024
fe8527a
constant instead of duplicated String
rolnico Apr 11, 2024
f31770f
Remove usage of generic wildcard type.
rolnico Apr 11, 2024
484a868
reduce method complexity
rolnico Apr 11, 2024
e616aa0
reduce method complexity
rolnico Apr 11, 2024
14c4ea1
reduce method complexity
rolnico Apr 11, 2024
04377b0
reduce method complexity
rolnico Apr 11, 2024
badf4ae
reduce method complexity
rolnico Apr 11, 2024
90e044b
reduce method complexity
rolnico Apr 11, 2024
d3636f0
reduce method complexity
rolnico Apr 11, 2024
215923c
make MapModuleConfigTest abstract and remove empty test
rolnico Apr 11, 2024
cf33aa1
fix issues
rolnico Apr 11, 2024
e9ba4e6
rename newly abstract class
rolnico Apr 11, 2024
177d79a
reduce method complexity
rolnico Apr 11, 2024
5a809c7
add fail assertions in try-catch
rolnico Apr 11, 2024
52b9d36
replace duplicated string with constant
rolnico Apr 11, 2024
6197b70
replace blank line
rolnico Apr 11, 2024
6cbb923
reduce method complexity
rolnico Apr 11, 2024
577431d
Use static access with "com.powsybl.iidm.network.LoadingLimits" for "…
rolnico Apr 11, 2024
6bea7ec
reduce method complexity
rolnico Apr 11, 2024
f58b6ed
Define a constant instead of duplicating this literal "properties[" 3…
rolnico Apr 11, 2024
1fa540c
reduce method complexity
rolnico Apr 11, 2024
f0c1916
reduce method complexity
rolnico Apr 11, 2024
d246196
Define a constant instead of duplicating this literal " not found" 3 …
rolnico Apr 11, 2024
0f9aff1
reduce method complexity
rolnico Apr 11, 2024
16444af
fix method name
rolnico Apr 11, 2024
584d6fc
add assertion in test
rolnico Apr 11, 2024
6ed5330
reduce method complexity
rolnico Apr 11, 2024
e09fc23
add assertion in case of failure
rolnico Apr 11, 2024
b585e89
replace duplicated string
rolnico Apr 11, 2024
5520c61
replace duplicated string
rolnico Apr 11, 2024
45b5168
Use static access with "com.powsybl.iidm.network.LoadingLimits" for "…
rolnico Apr 11, 2024
8ea07c8
add assertions in case of failure
rolnico Apr 11, 2024
f1b96f7
fix imports
rolnico Apr 11, 2024
c1e2f08
add assertion if failure
rolnico Apr 11, 2024
dd5e065
fix test
rolnico Apr 11, 2024
e17a94e
fix import
rolnico Apr 11, 2024
1f00a26
fix javadoc
rolnico Apr 11, 2024
48ea1bc
add assertion in test
rolnico Apr 11, 2024
7520aa3
add assertion in test
rolnico Apr 11, 2024
33fb7f0
add assertion in test
rolnico Apr 11, 2024
7cf7441
replace duplicated strings with constants
rolnico Apr 11, 2024
1fb5090
replace duplicated strings with constants
rolnico Apr 11, 2024
3e3e299
replace duplicated strings with constants
rolnico Apr 11, 2024
e2850cd
fix imports
rolnico Apr 11, 2024
3dd6772
Merge branch 'refs/heads/main' into nro/cleanup_severity_high_2
rolnico Apr 25, 2024
b9bb3fc
fix import
rolnico Apr 25, 2024
209b1e3
fix class names
rolnico Apr 25, 2024
0a22c28
fix LocalComputationManager
rolnico Apr 25, 2024
7e92d99
rename compareYyy methods to assertYyyEquals
rolnico Apr 25, 2024
1f254f7
fix for review
rolnico Apr 25, 2024
0d610e4
remove unused import
rolnico Apr 25, 2024
d46a8eb
fix checkstyle
rolnico Apr 25, 2024
415d9d4
fix issues
rolnico Apr 25, 2024
29057af
remove fail()
rolnico Apr 25, 2024
1c0ced1
Merge branch 'refs/heads/main' into nro/cleanup_severity_high_2
rolnico Apr 25, 2024
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 @@ -92,7 +92,7 @@ void actionsReadV10() {
ActionList actionList = ActionList.readJsonInputStream(getClass().getResourceAsStream("/ActionFileTestV1.0.json"));
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
actionList.writeJsonOutputStream(bos);
ComparisonUtils.compareTxt(getClass().getResourceAsStream("/ActionFileTest.json"), new ByteArrayInputStream(bos.toByteArray()));
ComparisonUtils.assertTxtEquals(getClass().getResourceAsStream("/ActionFileTest.json"), new ByteArrayInputStream(bos.toByteArray()));
} catch (Exception e) {
// Should not happen
fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.InputStream;
import java.util.Properties;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static com.powsybl.commons.test.ComparisonUtils.assertTxtEquals;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand All @@ -33,7 +33,7 @@ class AmplNetworkWriterTest extends AbstractSerDeTest {

private void assertEqualsToRef(MemDataSource dataSource, String suffix, String refFileName) throws IOException {
try (InputStream actual = new ByteArrayInputStream(dataSource.getData(suffix, "txt"))) {
compareTxt(getClass().getResourceAsStream("/" + refFileName), actual);
assertTxtEquals(getClass().getResourceAsStream("/" + refFileName), actual);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,38 @@ public void tearDown() throws IOException {
* <li>Transform the given data with the transformer function provided. This might be used to add a roundtrip on
* other formats prior to the XML roundtrip.</li>
* <li>Write the transformed data to a temporary XML file thanks to the given write function.</li>
* <li>Compare the obtained XML file with the given reference file thanks to {@link ComparisonUtils#compareXml}.</li>
* <li>Compare the obtained XML file with the given reference file thanks to {@link ComparisonUtils#assertXmlEquals}.</li>
* <li>Read the same XML file with the given read function.</li>
* <li>Write the data read in the previous step to a new temporary XML file.</li>
* <li>Compare the new obtained XML file with the first obtained XML file byte by byte using {@link Files#mismatch}.</li>
* <li>Return the data read 3 steps above.</li>
* </ul>
*/
protected <T> T roundTripXmlTest(T data, BiFunction<T, Path, T> transformer, BiConsumer<T, Path> write, Function<Path, T> read, String ref) throws IOException {
return roundTripTest(data, transformer, write, read, ComparisonUtils::compareXml, ref);
return roundTripTest(data, transformer, write, read, ComparisonUtils::assertXmlEquals, ref);
}

/**
* Roundtrip test on the given data. The following steps occur:
* <ul>
* <li>Write the given data to a temporary file thanks to the given write function.</li>
* <li>Compare the obtained file with the given reference file thanks to {@link ComparisonUtils#compareTxt}.</li>
* <li>Compare the obtained file with the given reference file thanks to {@link ComparisonUtils#assertTxtEquals}.</li>
* <li>Read the same file with the given read function.</li>
* <li>Write the data read in the previous step to a new temporary file.</li>
* <li>Compare the new obtained file with the first obtained file byte by byte using {@link Files#mismatch}.</li>
* <li>Return the data read 3 steps above.</li>
* </ul>
*/
protected <T> T roundTripTest(T data, BiConsumer<T, Path> write, Function<Path, T> read, String ref) throws IOException {
return roundTripTest(data, write, read, ComparisonUtils::compareTxt, ref);
return roundTripTest(data, write, read, ComparisonUtils::assertTxtEquals, ref);
}

/**
* Write the given data with given write function, and compare the resulting XML file to given reference.
* @return the path of written file.
*/
protected <T> Path writeXmlTest(T data, BiConsumer<T, Path> write, String ref) throws IOException {
return writeTest(data, write, ComparisonUtils::compareXml, ref);
return writeTest(data, write, ComparisonUtils::assertXmlEquals, ref);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class ComparisonUtils {
private ComparisonUtils() {
}

public static void compareXml(InputStream expected, InputStream actual) {
public static void assertXmlEquals(InputStream expected, InputStream actual) {
Diff myDiff = DiffBuilder.compare(expected).withTest(actual).ignoreWhitespace().ignoreComments().build();
boolean hasDiff = myDiff.hasDifferences();
if (hasDiff) {
Expand All @@ -38,23 +38,23 @@ public static void compareXml(InputStream expected, InputStream actual) {
assertFalse(hasDiff);
}

public static void compareTxt(InputStream expected, InputStream actual) {
public static void assertTxtEquals(InputStream expected, InputStream actual) {
try {
compareTxt(expected, new String(ByteStreams.toByteArray(actual), StandardCharsets.UTF_8));
assertTxtEquals(expected, new String(ByteStreams.toByteArray(actual), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static void compareBytes(InputStream expected, InputStream actual) {
public static void assertBytesEquals(InputStream expected, InputStream actual) {
try {
assertArrayEquals(expected.readAllBytes(), actual.readAllBytes());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static void compareTxt(InputStream expected, InputStream actual, List<Integer> excludedLines) {
public static void assertTxtEquals(InputStream expected, InputStream actual, List<Integer> excludedLines) {
BufferedReader expectedReader = new BufferedReader(new InputStreamReader(expected));
List<String> expectedLines = expectedReader.lines().toList();
BufferedReader actualReader = new BufferedReader(new InputStreamReader(actual));
Expand All @@ -67,23 +67,23 @@ public static void compareTxt(InputStream expected, InputStream actual, List<Int
}
}

public static void compareTxt(InputStream expected, String actual) {
public static void assertTxtEquals(InputStream expected, String actual) {
try {
compareTxt(new String(ByteStreams.toByteArray(expected), StandardCharsets.UTF_8), actual);
assertTxtEquals(new String(ByteStreams.toByteArray(expected), StandardCharsets.UTF_8), actual);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static void compareTxt(String expected, InputStream actual) {
public static void assertTxtEquals(String expected, InputStream actual) {
try {
compareTxt(expected, new String(ByteStreams.toByteArray(actual), StandardCharsets.UTF_8));
assertTxtEquals(expected, new String(ByteStreams.toByteArray(actual), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static void compareTxt(String expected, String actual) {
public static void assertTxtEquals(String expected, String actual) {
String expectedStr = TestUtil.normalizeLineSeparator(expected);
String actualStr = TestUtil.normalizeLineSeparator(actual);
assertEquals(expectedStr, actualStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.google.common.jimfs.Jimfs;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.FileSystem;
Expand All @@ -28,12 +27,12 @@
/**
* @author Yichen TANG {@literal <yichen.tang at rte-france.com>}
*/
class MapModuleConfigTest {
abstract class AbstractMapModuleConfigTest {

protected FileSystem fileSystem;

@BeforeEach
void setUp() throws IOException {
void setUp() {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
}

Expand All @@ -42,11 +41,6 @@ void tearDown() throws IOException {
fileSystem.close();
}

@Test
void emptyTest() {
// sonar issue
}

protected void assertModConfig(ModuleConfig modConfig) {
Path p = fileSystem.getPath("/tmp");
Path p2 = fileSystem.getPath("/home");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @author Yichen TANG {@literal <yichen.tang at rte-france.com>}
*/
class EnvironmentModuleConfigRepositoryTest extends MapModuleConfigTest {
class EnvironmentModuleConfigRepositoryTest extends AbstractMapModuleConfigTest {

@Test
void test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
class PropertiesPlatformConfigTest extends MapModuleConfigTest {
class PropertiesPlatformConfigTest extends AbstractMapModuleConfigTest {

PropertiesPlatformConfigTest() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static com.powsybl.commons.test.ComparisonUtils.assertTxtEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -71,7 +71,7 @@ void testDump() throws IOException {

String expectedStr = "TYPE;value1;1" + System.lineSeparator();
try (InputStream in = Files.newInputStream(outputFile)) {
compareTxt(expectedStr, in);
assertTxtEquals(expectedStr, in);
} catch (Exception e) {
fail(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,9 @@ private ExecutionReport execute(Path workingDir, List<CommandExecution> commandE
for (CommandExecution commandExecution : commandExecutionList) {
Command command = commandExecution.getCommand();
CountDownLatch latch = new CountDownLatch(commandExecution.getExecutionCount());
IntStream.range(0, commandExecution.getExecutionCount()).forEach(idx ->
executionSubmitter.execute(() -> {
try {
enter();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Executing command {} in working directory {}",
command.toString(idx), workingDir);
}
preProcess(workingDir, command, idx);
Stopwatch stopwatch = null;
if (LOGGER.isDebugEnabled()) {
stopwatch = Stopwatch.createStarted();
}
int exitValue = process(workingDir, commandExecution, idx, variables, computationParameters);
if (stopwatch != null) {
stopwatch.stop();
LOGGER.debug("Command {} executed in {} ms",
command.toString(idx), stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
postProcess(workingDir, commandExecution, idx, exitValue, errors, monitor);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.warn(e.getMessage(), e);
} catch (Exception e) {
LOGGER.warn(e.getMessage(), e);
} finally {
latch.countDown();
exit();
}
})
);
ExecutionParameters executionParameters = new ExecutionParameters(workingDir, commandExecution, variables, computationParameters, executionSubmitter,
command, latch, errors, monitor);
IntStream.range(0, commandExecution.getExecutionCount()).forEach(idx -> performSingleExecution(executionParameters, idx));
latch.await();
}

Expand All @@ -201,6 +173,46 @@ private ExecutionReport execute(Path workingDir, List<CommandExecution> commandE
return new DefaultExecutionReport(workingDir, errors);
}

private record ExecutionParameters(Path workingDir, CommandExecution commandExecution,
Map<String, String> variables, ComputationParameters computationParameters,
ExecutorService executionSubmitter, Command command, CountDownLatch latch,
List<ExecutionError> errors, ExecutionMonitor monitor) {
}

private void performSingleExecution(ExecutionParameters executionParameters, int idx) {
executionParameters.executionSubmitter.execute(() -> {
try {
enter();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Executing command {} in working directory {}",
executionParameters.command.toString(idx), executionParameters.workingDir);
}
preProcess(executionParameters.workingDir, executionParameters.command, idx);
Stopwatch stopwatch = null;
if (LOGGER.isDebugEnabled()) {
stopwatch = Stopwatch.createStarted();
}
int exitValue = process(executionParameters.workingDir, executionParameters.commandExecution, idx,
executionParameters.variables, executionParameters.computationParameters);
if (stopwatch != null) {
stopwatch.stop();
LOGGER.debug("Command {} executed in {} ms",
executionParameters.command.toString(idx), stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
postProcess(executionParameters.workingDir, executionParameters.commandExecution, idx, exitValue,
executionParameters.errors, executionParameters.monitor);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.warn(e.getMessage(), e);
} catch (Exception e) {
LOGGER.warn(e.getMessage(), e);
} finally {
executionParameters.latch.countDown();
exit();
}
});
}

private void preProcess(Path workingDir, Command command, int executionIndex) throws IOException {
// pre-processing
for (InputFile file : command.getInputFiles()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void readVersion11() {
.getResourceAsStream("/identifierContingencyListv1_1.json")));
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
WRITER.writeValue(bos, contingencyList);
ComparisonUtils.compareTxt(getClass().getResourceAsStream("/identifierContingencyListReferenceForLessThan1_2.json"), new ByteArrayInputStream(bos.toByteArray()));
ComparisonUtils.assertTxtEquals(getClass().getResourceAsStream("/identifierContingencyListReferenceForLessThan1_2.json"), new ByteArrayInputStream(bos.toByteArray()));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -73,7 +73,7 @@ void readVersion10() {
.getResourceAsStream("/identifierContingencyListv1_0.json")));
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
WRITER.writeValue(bos, contingencyList);
ComparisonUtils.compareTxt(getClass().getResourceAsStream("/identifierContingencyListReferenceForLessThan1_2.json"), new ByteArrayInputStream(bos.toByteArray()));
ComparisonUtils.assertTxtEquals(getClass().getResourceAsStream("/identifierContingencyListReferenceForLessThan1_2.json"), new ByteArrayInputStream(bos.toByteArray()));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void roundTrip() throws IOException {
void writeExtension() throws IOException {
DynamicSimulationParameters parameters = new DynamicSimulationParameters();
parameters.addExtension(DummyExtension.class, new DummyExtension());
writeTest(parameters, JsonDynamicSimulationParameters::write, ComparisonUtils::compareTxt, "/DynamicSimulationParametersWithExtension.json");
writeTest(parameters, JsonDynamicSimulationParameters::write, ComparisonUtils::assertTxtEquals, "/DynamicSimulationParametersWithExtension.json");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class DynamicSimulationTool implements Tool {
private static final String PARAMETERS_FILE = "parameters-file";
private static final String OUTPUT_FILE = "output-file";
private static final String OUTPUT_LOG_FILE = "output-log-file";
private static final String GROOVY = "groovy";

@Override
public Command getCommand() {
Expand Down Expand Up @@ -175,7 +176,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception {

private DynamicModelsSupplier createDynamicModelsSupplier(Path path, String providerName) {
String extension = FilenameUtils.getExtension(path.toString());
if (extension.equals("groovy")) {
if (extension.equals(GROOVY)) {
return new GroovyDynamicModelsSupplier(path, GroovyExtension.find(DynamicModelGroovyExtension.class, providerName));
} else {
throw new PowsyblException("Unsupported dynamic model format: " + extension);
Expand All @@ -184,7 +185,7 @@ private DynamicModelsSupplier createDynamicModelsSupplier(Path path, String prov

private EventModelsSupplier createEventModelsSupplier(Path path, String providerName) {
String extension = FilenameUtils.getExtension(path.toString());
if (extension.equals("groovy")) {
if (extension.equals(GROOVY)) {
return new GroovyEventModelsSupplier(path, GroovyExtension.find(EventModelGroovyExtension.class, providerName));
} else {
throw new PowsyblException("Unsupported events format: " + extension);
Expand All @@ -193,7 +194,7 @@ private EventModelsSupplier createEventModelsSupplier(Path path, String provider

private CurvesSupplier createCurvesSupplier(Path path, String providerName) {
String extension = FilenameUtils.getExtension(path.toString());
if (extension.equals("groovy")) {
if (extension.equals(GROOVY)) {
return new GroovyCurvesSupplier(path, GroovyExtension.find(CurveGroovyExtension.class, providerName));
} else {
throw new PowsyblException("Unsupported curves format: " + extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void testDynamicSimulationWithOutputFile() throws IOException {
"timeLine" : [ ]
}""";
assertCommandSuccessful(new String[]{"dynamic-simulation", "--case-file", "/network.xiidm", "--dynamic-models-file", "/dynamicModels.groovy", "--output-file", "outputTest.json"}, expectedOut);
ComparisonUtils.compareTxt(expectedOutputFile, Files.newInputStream(fileSystem.getPath("outputTest.json")));
ComparisonUtils.assertTxtEquals(expectedOutputFile, Files.newInputStream(fileSystem.getPath("outputTest.json")));
}

@Test
Expand All @@ -110,7 +110,7 @@ void testDynamicSimulationWithOutputLogFile() throws IOException {
"+---------+" + System.lineSeparator());
String expectedOutputFile = "Dynamic Simulation Tool\n";
assertCommandSuccessful(new String[]{"dynamic-simulation", "--case-file", "/network.xiidm", "--dynamic-models-file", "/dynamicModels.groovy", "--output-log-file", "outputTest.log"}, expectedOut);
ComparisonUtils.compareTxt(expectedOutputFile, Files.newInputStream(fileSystem.getPath("outputTest.log")));
ComparisonUtils.assertTxtEquals(expectedOutputFile, Files.newInputStream(fileSystem.getPath("outputTest.log")));
}

@Test
Expand Down
Loading