Skip to content

Commit

Permalink
Merge branch 'main' into add-hvdc-action
Browse files Browse the repository at this point in the history
  • Loading branch information
annetill authored Mar 3, 2023
2 parents 5e5bb78 + 4e7eb72 commit f2b5397
Show file tree
Hide file tree
Showing 933 changed files with 8,399 additions and 7,495 deletions.
4 changes: 2 additions & 2 deletions action/action-dsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
package com.powsybl.action.dsl;

import com.powsybl.contingency.Contingency;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;

/**
* @author Mathieu Bague <mathieu.bague at rte-france.com>
*/
public class ActionDbTest {
class ActionDbTest {

@Test
public void testContingencies() {
void testContingencies() {
ActionDb actionDb = new ActionDb();
Contingency contingency = new Contingency("id");
actionDb.addContingency(contingency);
Expand All @@ -37,7 +37,7 @@ public void testContingencies() {
}

@Test
public void testDuplicateContingency() {
void testDuplicateContingency() {
ActionDb actionDb = new ActionDb();
Contingency c1 = new Contingency("c1");
actionDb.addContingency(c1);
Expand All @@ -48,7 +48,7 @@ public void testDuplicateContingency() {
}

@Test
public void testRules() {
void testRules() {
Rule rule = Mockito.mock(Rule.class);

ActionDb actionDb = new ActionDb();
Expand All @@ -57,7 +57,7 @@ public void testRules() {
}

@Test
public void testActions() {
void testActions() {
Action action = Mockito.mock(Action.class);
Mockito.when(action.getId()).thenReturn("id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import groovy.lang.GroovyCodeSource;
import groovy.lang.MissingMethodException;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatcher;

import java.util.Arrays;
Expand All @@ -26,30 +25,27 @@
import java.util.function.Function;
import java.util.function.Supplier;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
* @author Mathieu Bague <mathieu.bague at rte-france.com>
*/
public class ActionDslLoaderTest {

@org.junit.Rule
public final ExpectedException exception = ExpectedException.none();
class ActionDslLoaderTest {

private Network network;
private Supplier<ActionDslLoader> loaderSupplier1;
private Supplier<ActionDslLoader> loaderSupplier2;

@Before
public void setUp() {
@BeforeEach
void setUp() {
network = EurostagTutorialExample1Factory.create();
loaderSupplier1 = () -> new ActionDslLoader(new GroovyCodeSource(Objects.requireNonNull(ActionDslLoaderTest.class.getResource("/actions.groovy"))));
loaderSupplier2 = () -> new ActionDslLoader(new GroovyCodeSource(Objects.requireNonNull(ActionDslLoaderTest.class.getResource("/actions2.groovy"))));
}

@Test
public void test() {
void test() {
ActionDb actionDb = loaderSupplier1.get().load(network);

assertEquals(2, actionDb.getContingencies().size());
Expand All @@ -75,7 +71,7 @@ public void test() {
}

@Test
public void testBackwardCompatibility() {
void testBackwardCompatibility() {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action fixedTapAction = actionDb.getAction("backwardCompatibility");
assertNotNull(fixedTapAction);
Expand All @@ -91,16 +87,15 @@ public void testBackwardCompatibility() {
}

@Test
public void testDslExtension() {
void testDslExtension() {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action another = actionDb.getAction("anotherAction");
exception.expect(RuntimeException.class);
exception.expectMessage("Switch 'switchId' not found");
another.run(network);
RuntimeException e = assertThrows(RuntimeException.class, () -> another.run(network));
assertTrue(e.getMessage().contains("Switch 'switchId' not found"));
}

@Test
public void testFixTapDslExtension() {
void testFixTapDslExtension() {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action fixedTapAction = actionDb.getAction("fixedTap");
assertNotNull(fixedTapAction);
Expand Down Expand Up @@ -129,7 +124,7 @@ private static List<DeltaTapData> provideParams() {
}

@Test
public void testDeltaTapDslExtension() {
void testDeltaTapDslExtension() {
for (DeltaTapData data : provideParams()) {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action deltaTapAction = actionDb.getAction(data.getTestName());
Expand All @@ -148,42 +143,38 @@ public void testDeltaTapDslExtension() {
}

@Test
public void testInvalidTransformerId() {
void testInvalidTransformerId() {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action deltaTapAction = actionDb.getAction("InvalidTransformerId");
assertNotNull(deltaTapAction);
assertEquals(-10, ((PhaseShifterShiftTap) deltaTapAction.getModifications().get(0)).getTapDelta());
exception.expect(PowsyblException.class);
exception.expectMessage("Transformer 'NHV1_NHV2_1' not found");
deltaTapAction.run(network);
PowsyblException e = assertThrows(PowsyblException.class, () -> deltaTapAction.run(network));
assertTrue(e.getMessage().contains("Transformer 'NHV1_NHV2_1' not found"));
}

@Test
public void testTransformerWithoutPhaseShifter() {
void testTransformerWithoutPhaseShifter() {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action deltaTapAction = actionDb.getAction("TransformerWithoutPhaseShifter");
assertNotNull(deltaTapAction);
assertEquals(-10, ((PhaseShifterShiftTap) deltaTapAction.getModifications().get(0)).getTapDelta());
exception.expect(PowsyblException.class);
exception.expectMessage("Transformer 'NGEN_NHV1' is not a phase shifter");
deltaTapAction.run(network);
PowsyblException e = assertThrows(PowsyblException.class, () -> deltaTapAction.run(network));
assertTrue(e.getMessage().contains("Transformer 'NGEN_NHV1' is not a phase shifter"));
}

@Test
public void testUnvalidate() {
void testUnvalidate() {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action someAction = actionDb.getAction("someAction");
exception.expect(ActionDslException.class);
exception.expectMessage("Dsl extension task(closeSwitch) is forbidden in task script");
someAction.run(network);
ActionDslException e = assertThrows(ActionDslException.class, () -> someAction.run(network));
assertTrue(e.getMessage().contains("Dsl extension task(closeSwitch) is forbidden in task script"));
}

@Test
public void testUnKnownMethodInScript() {
void testUnKnownMethodInScript() {
ActionDb actionDb = loaderSupplier2.get().load(network);
Action someAction = actionDb.getAction("missingMethod");
exception.expect(MissingMethodException.class);
someAction.run(network);
assertThrows(MissingMethodException.class, () -> someAction.run(network));
}

private static <T> ArgumentMatcher<T> matches(Function<T, Boolean> predicate) {
Expand All @@ -196,7 +187,7 @@ public boolean matches(Object o) {
}

@Test
public void testHandler() {
void testHandler() {
ActionDslHandler handler = mock(ActionDslHandler.class);
loaderSupplier1.get().load(network, handler, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.modification.NetworkModification;
import com.powsybl.iidm.modification.tripping.GeneratorTripping;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Mathieu Bague <mathieu.bague at rte-france.com>
*/
public class ActionTest {
class ActionTest {

@Test
public void test() {
void test() {
NetworkModification mock = Mockito.mock(NetworkModification.class);
List<NetworkModification> modifications = new ArrayList<>();

Expand All @@ -44,7 +44,7 @@ public void test() {
}

@Test
public void testInvalid() {
void testInvalid() {
testInvalid(null, Collections.emptyList());
testInvalid("id", null);
}
Expand All @@ -58,7 +58,7 @@ private void testInvalid(String id, List<NetworkModification> modifications) {
}

@Test
public void testRun() {
void testRun() {
Network network = EurostagTutorialExample1Factory.create();
assertTrue(network.getGenerator("GEN").getTerminal().isConnected());

Expand Down
Loading

0 comments on commit f2b5397

Please sign in to comment.