Skip to content

Commit

Permalink
Fix code smells
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed Jul 8, 2024
1 parent 248b80a commit 91b6b42
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected void setup(String parametersFile, String networkParametersFile, String
List<DynamicModelGroovyExtension> dynamicModelGroovyExtensions = GroovyExtension.find(DynamicModelGroovyExtension.class, DynawoSimulationProvider.NAME);
dynamicModelsSupplier = new GroovyDynamicModelsSupplier(workingDir.resolve("dynamicModels.groovy"), dynamicModelGroovyExtensions);
} else {
dynamicModelsSupplier = (n, NO_OP) -> Collections.emptyList();
dynamicModelsSupplier = (n, r) -> Collections.emptyList();
}

// Event models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
public final class DynawoSimulationReports {

private static final String DYNAMIC_ID_FIELD = "dynamicId";

private DynawoSimulationReports() {
}

Expand All @@ -37,7 +39,7 @@ public static void reportDuplicateStaticId(ReportNode reportNode, String duplica
.withMessageTemplate("duplicateStaticId", "Duplicate static id found: ${duplicateId} -> model ${modelName} ${dynamicId} will be skipped")
.withUntypedValue("duplicateId", duplicateId)
.withUntypedValue("modelName", modelName)
.withUntypedValue("dynamicId", dynamicId)
.withUntypedValue(DYNAMIC_ID_FIELD, dynamicId)
.withSeverity(TypedValue.WARN_SEVERITY)
.add();
}
Expand All @@ -57,7 +59,7 @@ public static void reportEmptyAutomaton(ReportNode reportNode, String automatonN
.withMessageTemplate("emptyAutomaton",
"${automatonName} ${dynamicId} equipment ${equipmentId} is not a ${expectedModels}, the automation system will be skipped")
.withUntypedValue("automatonName", automatonName)
.withUntypedValue("dynamicId", dynamicId)
.withUntypedValue(DYNAMIC_ID_FIELD, dynamicId)
.withUntypedValue("equipmentId", equipmentId)
.withUntypedValue("expectedModels", expectedModels)
.withSeverity(TypedValue.WARN_SEVERITY)
Expand All @@ -69,7 +71,7 @@ public static void reportEmptyListAutomaton(ReportNode reportNode, String automa
.withMessageTemplate("emptyListAutomaton",
"None of ${automatonName} ${dynamicId} equipments are ${expectedModels}, the automation system will be skipped")
.withUntypedValue("automatonName", automatonName)
.withUntypedValue("dynamicId", dynamicId)
.withUntypedValue(DYNAMIC_ID_FIELD, dynamicId)
.withUntypedValue("expectedModels", expectedModels)
.withSeverity(TypedValue.WARN_SEVERITY)
.add();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public final class BuilderReports {

private static final String FIELD_NAME = "fieldName";
private static final String EQUIPMENT_TYPE_FIELD = "equipmentType";

private BuilderReports() {
}
Expand Down Expand Up @@ -83,7 +84,7 @@ public static void reportFieldNotSet(ReportNode reportNode, String fieldName) {
public static void reportStaticIdUnknown(ReportNode reportNode, String fieldName, String staticId, String equipmentType) {
reportNode.newReportNode()
.withMessageTemplate("unknownStaticIdToDynamic", "'${fieldName}' field value '${staticId}' not found for equipment type(s) ${equipmentType}")
.withUntypedValue("equipmentType", equipmentType)
.withUntypedValue(EQUIPMENT_TYPE_FIELD, equipmentType)
.withUntypedValue(FIELD_NAME, fieldName)
.withUntypedValue("staticId", staticId)
.withSeverity(TypedValue.WARN_SEVERITY)
Expand All @@ -93,7 +94,7 @@ public static void reportStaticIdUnknown(ReportNode reportNode, String fieldName
public static void reportDifferentNetwork(ReportNode reportNode, String fieldName, String staticId, String equipmentType) {
reportNode.newReportNode()
.withMessageTemplate("wrongNetwork", "'${fieldName}' field value ${equipmentType} ${staticId} does not belong to the builder network")
.withUntypedValue("equipmentType", equipmentType)
.withUntypedValue(EQUIPMENT_TYPE_FIELD, equipmentType)
.withUntypedValue(FIELD_NAME, fieldName)
.withUntypedValue("staticId", staticId)
.withSeverity(TypedValue.WARN_SEVERITY)
Expand All @@ -103,7 +104,7 @@ public static void reportDifferentNetwork(ReportNode reportNode, String fieldNam
public static void reportUnknownStaticIdHandling(ReportNode reportNode, String fieldName, String staticId, String equipmentType) {
reportNode.newReportNode()
.withMessageTemplate("staticIdUnknown", "'${fieldName}' field value '${staticId}' not found for equipment type(s) ${equipmentType}, id will be used as pure dynamic model id")
.withUntypedValue("equipmentType", equipmentType)
.withUntypedValue(EQUIPMENT_TYPE_FIELD, equipmentType)
.withUntypedValue(FIELD_NAME, fieldName).withUntypedValue("staticId", staticId)
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DynawoParametersTest extends AbstractSerDeTest {
private InMemoryPlatformConfig platformConfig;

@BeforeEach
@Override
public void setUp() throws IOException {
super.setUp();
platformConfig = new InMemoryPlatformConfig(fileSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@
*/
class BuilderConfigTest {

private static Network NETWORK;
private static ModelConfigsHandler MODEL_CONFIGS_HANDLER;
private static Network network;
private static ModelConfigsHandler modelConfigsHandler;

@BeforeAll
static void setup() {
NETWORK = EurostagTutorialExample1Factory.create();
MODEL_CONFIGS_HANDLER = ModelConfigsHandler.getInstance();
network = EurostagTutorialExample1Factory.create();
modelConfigsHandler = ModelConfigsHandler.getInstance();
}

@Test
void testModelBuilders() {
for (BuilderConfig builderConfig : MODEL_CONFIGS_HANDLER.getBuilderConfigs()) {
for (BuilderConfig builderConfig : modelConfigsHandler.getBuilderConfigs()) {
String modelName = builderConfig.getModelInfos().iterator().next().name();
ModelBuilder<DynamicModel> handlerBuilder = MODEL_CONFIGS_HANDLER.getModelBuilder(NETWORK, modelName, ReportNode.NO_OP);
ModelBuilder<DynamicModel> configBuilder = builderConfig.getBuilderConstructor().createBuilder(NETWORK, modelName, ReportNode.NO_OP);
ModelBuilder<DynamicModel> handlerBuilder = modelConfigsHandler.getModelBuilder(network, modelName, ReportNode.NO_OP);
ModelBuilder<DynamicModel> configBuilder = builderConfig.getBuilderConstructor().createBuilder(network, modelName, ReportNode.NO_OP);
assertNotNull(handlerBuilder);
assertEquals(handlerBuilder.getClass(), configBuilder.getClass());
}
}

@Test
void testEventBuilders() {
for (EventBuilderConfig eventBuilderConfig : MODEL_CONFIGS_HANDLER.getEventBuilderConfigs()) {
ModelBuilder<EventModel> handlerBuilder = MODEL_CONFIGS_HANDLER.getEventModelBuilder(NETWORK, eventBuilderConfig.getEventModelInfo().name(), ReportNode.NO_OP);
ModelBuilder<EventModel> configBuilder = eventBuilderConfig.getBuilderConstructor().createBuilder(NETWORK, ReportNode.NO_OP);
for (EventBuilderConfig eventBuilderConfig : modelConfigsHandler.getEventBuilderConfigs()) {
ModelBuilder<EventModel> handlerBuilder = modelConfigsHandler.getEventModelBuilder(network, eventBuilderConfig.getEventModelInfo().name(), ReportNode.NO_OP);
ModelBuilder<EventModel> configBuilder = eventBuilderConfig.getBuilderConstructor().createBuilder(network, ReportNode.NO_OP);
assertNotNull(handlerBuilder);
assertEquals(handlerBuilder.getClass(), configBuilder.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.util.function.Function;
import java.util.stream.Stream;
Expand Down Expand Up @@ -55,7 +54,7 @@ protected void addDynamicModels(Function< Network, BlackBoxModel> hvdcConstructo

@ParameterizedTest(name = "{0}")
@MethodSource("provideModels")
void writeModel(String dydName, Function< Network, BlackBoxModel> hvdcConstructor, Function< Network, BlackBoxModel> disconnectConstructor) throws SAXException, IOException, XMLStreamException {
void writeModel(String dydName, Function< Network, BlackBoxModel> hvdcConstructor, Function< Network, BlackBoxModel> disconnectConstructor) throws SAXException, IOException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", dydName, tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -58,7 +57,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "cla_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand All @@ -40,7 +39,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "cla_tl_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -41,7 +40,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", "tap_changer_empty_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -55,7 +54,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", "tap_changer_blocking_empty_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.util.function.Function;
import java.util.stream.Stream;
Expand Down Expand Up @@ -51,7 +50,7 @@ protected void addDynamicModels(Function< Network, BlackBoxModel> constructor) {

@ParameterizedTest(name = "{0}")
@MethodSource("provideHvdc")
void writeHvdcModel(String dydName, Function< Network, BlackBoxModel> constructor) throws SAXException, IOException, XMLStreamException {
void writeHvdcModel(String dydName, Function< Network, BlackBoxModel> constructor) throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", dydName, tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.util.function.Function;
import java.util.stream.Stream;
Expand Down Expand Up @@ -49,7 +48,7 @@ protected void addDynamicModels(Function< Network, BlackBoxModel> loadConstructo

@ParameterizedTest(name = "{0}")
@MethodSource("provideLoads")
void writeLoadModel(String dydName, Function< Network, BlackBoxModel> loadConstructor) throws SAXException, IOException, XMLStreamException {
void writeLoadModel(String dydName, Function< Network, BlackBoxModel> loadConstructor) throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", dydName + ".xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand All @@ -37,7 +36,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", "node_fault_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -46,7 +45,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", "omega_ref_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.util.function.Function;
import java.util.stream.Stream;
Expand Down Expand Up @@ -58,7 +57,7 @@ protected void addDynamicModels(Function<Network, BlackBoxModel> phaseShifterCon

@ParameterizedTest(name = "{0}")
@MethodSource("providePhaseShifter")
void writeLoadModel(String dydName, Function<Network, BlackBoxModel> phaseShifterConstructor, boolean dynamicTransformer) throws SAXException, IOException, XMLStreamException {
void writeLoadModel(String dydName, Function<Network, BlackBoxModel> phaseShifterConstructor, boolean dynamicTransformer) throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", dydName + ".xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -47,7 +46,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", "set_point_inf_bus_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand All @@ -35,7 +34,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "shunt_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -44,7 +43,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "svarc_sba_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand All @@ -35,7 +34,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "svarc_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
Expand Down Expand Up @@ -71,7 +70,7 @@ protected void addDynamicModels() {
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
void writeModel() throws SAXException, IOException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", "tap_changer_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME));
Expand Down
Loading

0 comments on commit 91b6b42

Please sign in to comment.