Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed Oct 15, 2024
1 parent 4d2ef34 commit e6d251d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static com.powsybl.commons.test.ComparisonUtils.assertXmlEquals;
import static com.powsybl.dynaflow.DynaFlowConstants.DYNAFLOW_NAME;
import static com.powsybl.dynaflow.DynaFlowConstants.IIDM_FILENAME;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -136,6 +137,18 @@ void testCallingBadVersionDynawo() throws IOException {
assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, contingencies, runParameters));
}

@Test
void loadDynaflowParameters() {
DynaFlowSecurityAnalysisProvider provider = new DynaFlowSecurityAnalysisProvider();
Map<String, String> properties = Map.of("timeOfEvent", Double.toString(23d));
assertThat(provider.loadSpecificParameters(properties))
.isNotEmpty()
.get()
.isInstanceOf(DynaFlowSecurityAnalysisParameters.class)
.hasFieldOrPropertyWithValue("timeOfEvent", 23.);

}

private static Network buildNetwork() {
Network network = EurostagTutorialExample1Factory.create();
network.setCaseDate(ZonedDateTime.parse("2023-03-23T16:40:48.060+01:00"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
Expand All @@ -40,4 +43,13 @@ void serializeWithDefaultDynaflowSaParameters() throws IOException {
roundTripTest(parameters, JsonSecurityAnalysisParameters::write,
JsonSecurityAnalysisParameters::read, "/dynaflow_sa_default_serialization.json");
}

@Test
void update() {
SecurityAnalysisParameters parameters = SecurityAnalysisParameters.load();
JsonSecurityAnalysisParameters.update(parameters, getClass().getResourceAsStream("/dynaflow_sa_update.json"));
DynaFlowSecurityAnalysisParameters dynaFlowSaParameters = parameters.getExtension(DynaFlowSecurityAnalysisParameters.class);
assertNotNull(dynaFlowSaParameters);
assertEquals(14., dynaFlowSaParameters.getTimeOfEvent());
}
}
35 changes: 35 additions & 0 deletions dynaflow/src/test/resources/dynaflow_sa_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version" : "1.2",
"increased-violations-parameters" : {
"flow-proportional-threshold" : 0.1,
"low-voltage-proportional-threshold" : 0.0,
"low-voltage-absolute-threshold" : 0.0,
"high-voltage-proportional-threshold" : 0.0,
"high-voltage-absolute-threshold" : 0.0
},
"intermediate-results-in-operator-strategy" : false,
"load-flow-parameters" : {
"version" : "1.9",
"voltageInitMode" : "UNIFORM_VALUES",
"transformerVoltageControlOn" : false,
"phaseShifterRegulationOn" : false,
"useReactiveLimits" : true,
"twtSplitShuntAdmittance" : false,
"shuntCompensatorVoltageControlOn" : false,
"readSlackBus" : true,
"writeSlackBus" : true,
"dc" : false,
"distributedSlack" : true,
"balanceType" : "PROPORTIONAL_TO_GENERATION_P_MAX",
"dcUseTransformerRatio" : true,
"countriesToBalance" : [ ],
"connectedComponentMode" : "MAIN",
"hvdcAcEmulation" : true,
"dcPowerFactor" : 1.0
},
"extensions" : {
"DynaFlowSecurityAnalysisParameters" : {
"timeOfEvent" : 14.0
}
}
}

0 comments on commit e6d251d

Please sign in to comment.