diff --git a/pom.xml b/pom.xml
index 48eec2d..22157b1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -121,6 +121,8 @@
pom
import
+
+
@@ -181,24 +183,9 @@
powsybl-config-test
test
-
- junit
- junit
- test
-
-
- org.mockito
- mockito-core
- test
-
-
- org.springframework
- spring-test
- test
-
org.springframework.boot
- spring-boot-test-autoconfigure
+ spring-boot-starter-test
test
diff --git a/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java b/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java
index f22ba5c..c99e7fb 100644
--- a/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java
+++ b/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java
@@ -7,12 +7,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-import com.powsybl.iidm.network.*;
+import com.powsybl.iidm.network.Country;
import com.powsybl.network.store.client.NetworkStoreService;
import com.powsybl.sld.server.dto.Coordinate;
import com.powsybl.sld.server.dto.SubstationGeoData;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@@ -22,83 +22,29 @@
import java.util.List;
import java.util.UUID;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
-public class GeoDataServiceTest {
+class GeoDataServiceTest {
+ private static final String BASE_URI = "http://geo-data-server/";
- private static final String VARIANT_1_ID = "variant_1";
- private static final String VARIANT_2_ID = "variant_2";
- private final String baseUri = "http://geo-data-server/";
@Mock
private RestTemplate restTemplate;
+
@InjectMocks
private GeoDataService geoDataService;
+
@Mock
private NetworkStoreService networkStoreService;
- public static Network createNetwork() {
- Network network = Network.create("test", "test");
- Substation substationFr1 = network.newSubstation()
- .setId("subFr1")
- .setCountry(Country.FR)
- .setTso("RTE")
- .add();
- VoltageLevel voltageLevelFr1A = substationFr1.newVoltageLevel()
- .setId("vlFr1A")
- .setName("vlFr1A")
- .setNominalV(440.0)
- .setHighVoltageLimit(400.0)
- .setLowVoltageLimit(200.0)
- .setTopologyKind(TopologyKind.BUS_BREAKER)
- .add();
- voltageLevelFr1A.getBusBreakerView().newBus()
- .setId("busFr1A")
- .setName("busFr1A")
- .add();
- VoltageLevel voltageLevelFr1B = substationFr1.newVoltageLevel()
- .setId("vlFr1B").setName("vlFr1B")
- .setNominalV(200.0)
- .setHighVoltageLimit(400.0)
- .setLowVoltageLimit(200.0)
- .setTopologyKind(TopologyKind.BUS_BREAKER)
- .add();
- voltageLevelFr1B.getBusBreakerView().newBus()
- .setId("busFr1B")
- .setName("busFr1B")
- .add();
-
- Substation substationFr2 = network.newSubstation()
- .setId("subFr2")
- .setCountry(Country.FR)
- .setTso("RTE")
- .add();
- VoltageLevel voltageLevelFr2A = substationFr2.newVoltageLevel()
- .setId("vlFr2A")
- .setName("vlFr2A")
- .setNominalV(440.0)
- .setHighVoltageLimit(400.0)
- .setLowVoltageLimit(200.0)
- .setTopologyKind(TopologyKind.BUS_BREAKER)
- .add();
- voltageLevelFr2A.getBusBreakerView().newBus()
- .setId("busFr2A")
- .setName("busFr2A")
- .add();
- network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_1_ID);
- network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_2_ID);
-
- return network;
- }
-
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
MockitoAnnotations.initMocks(this);
- geoDataService.setGeoDataServerBaseUri(baseUri);
+ geoDataService.setGeoDataServerBaseUri(BASE_URI);
}
@Test
- public void testGetSubstationsGraphics() {
+ void testGetSubstationsGraphics() {
UUID networkUuid = UUID.randomUUID();
String variantId = "variant2";
List substationsIds = List.of("subFr1", "subFr2");
@@ -113,7 +59,7 @@ public void testGetSubstationsGraphics() {
}
@Test
- public void testGetSubstationsGraphicsWithoutVariantId() {
+ void testGetSubstationsGraphicsWithoutVariantId() {
UUID networkUuid = UUID.randomUUID();
List substationsIds = List.of("subFr1");
SubstationGeoData substationGeoData = new SubstationGeoData();
diff --git a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java
index cc300dc..714cf3b 100644
--- a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java
+++ b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java
@@ -33,27 +33,23 @@
import com.powsybl.sld.svg.FeederInfo;
import com.powsybl.sld.svg.SvgParameters;
import com.powsybl.sld.svg.styles.NominalVoltageStyleProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import java.io.IOException;
import java.io.StringWriter;
-import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
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;
@@ -61,7 +57,7 @@
import static com.powsybl.sld.library.ComponentTypeName.ARROW_ACTIVE;
import static com.powsybl.sld.library.ComponentTypeName.ARROW_REACTIVE;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
@@ -74,10 +70,9 @@
* @author Abdelsalem Hedhili
* @author Franck Lecuyer
*/
-@RunWith(SpringRunner.class)
@WebMvcTest(SingleLineDiagramController.class)
@ContextConfiguration(classes = {SingleLineDiagramApplication.class})
-public class SingleLineDiagramTest {
+class SingleLineDiagramTest {
@Autowired
private MockMvc mvc;
@@ -102,22 +97,21 @@ public class SingleLineDiagramTest {
private static final String VARIANT_2_ID = "variant_2";
private static final String VARIANT_NOT_FOUND_ID = "variant_notFound";
private FileSystem fileSystem;
- private Path tmpDir;
- @Before
- public void setUp() throws IOException {
+ @BeforeEach
+ void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
fileSystem = Jimfs.newFileSystem(Configuration.unix());
- tmpDir = Files.createDirectory(fileSystem.getPath("tmp"));
+ Files.createDirectory(fileSystem.getPath("tmp"));
}
- @After
- public void tearDown() throws IOException {
+ @AfterEach
+ void tearDown() throws Exception {
fileSystem.close();
}
@Test
- public void test() throws Exception {
+ void test() throws Exception {
UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
UUID notFoundNetworkId = UUID.fromString("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
@@ -200,7 +194,7 @@ public void test() throws Exception {
}
@Test
- public void testSubstations() throws Exception {
+ void testSubstations() throws Exception {
UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
UUID notFoundNetworkId = UUID.fromString("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
@@ -281,7 +275,7 @@ public void testSubstations() throws Exception {
}
@Test
- public void testComponentLibraries() throws Exception {
+ void testComponentLibraries() throws Exception {
MvcResult result = mvc.perform(get("/v1/svg-component-libraries"))
.andExpect(status().isOk())
.andReturn();
@@ -292,7 +286,7 @@ public void testComponentLibraries() throws Exception {
private static final String GEO_DATA_SUBSTATIONS = "/geo_data_substations.json";
@Test
- public void testAssignSubstationGeoData() throws Exception {
+ void testAssignSubstationGeoData() {
UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork());
Network network = networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION);
@@ -306,9 +300,8 @@ public void testAssignSubstationGeoData() throws Exception {
String faultSubstationGeoDataJson = "[{\"id\":\"subFr1\",\"coordinate\":{\"lat\":48.8588443,\"long\":2.2943506}}]";
given(geoDataService.getSubstationsGraphics(testNetworkId, VARIANT_1_ID, List.of("subFr1"))).willReturn(faultSubstationGeoDataJson);
- PowsyblException exception = assertThrows(PowsyblException.class, () -> {
- networkAreaDiagramService.assignGeoDataCoordinates(network, testNetworkId, VARIANT_1_ID, List.of(network.getVoltageLevel("vlFr1A")));
- });
+ PowsyblException exception = assertThrows(PowsyblException.class, () ->
+ networkAreaDiagramService.assignGeoDataCoordinates(network, testNetworkId, VARIANT_1_ID, List.of(network.getVoltageLevel("vlFr1A"))));
// Assert the exception message
assertEquals("Failed to parse JSON response", exception.getMessage());
@@ -316,7 +309,7 @@ public void testAssignSubstationGeoData() throws Exception {
}
@Test
- public void testNetworkAreaDiagram() throws Exception {
+ void testNetworkAreaDiagram() throws Exception {
UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
UUID notFoundNetworkId = UUID.fromString("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
@@ -349,7 +342,7 @@ public void testNetworkAreaDiagram() throws Exception {
.andExpect(status().isNotFound());
}
- public void testGenerateNadBasedOnGeoData(boolean withGeoData) {
+ private void testGenerateNadBasedOnGeoData(boolean withGeoData) throws Exception {
UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork());
given(geoDataService.getSubstationsGraphics(testNetworkId, VARIANT_2_ID, List.of("subFr1"))).willReturn(toString(GEO_DATA_SUBSTATIONS));
@@ -364,17 +357,17 @@ public void testGenerateNadBasedOnGeoData(boolean withGeoData) {
}
@Test
- public void testGenerateNadWithoutGeoData() {
+ void testGenerateNadWithoutGeoData() throws Exception {
testGenerateNadBasedOnGeoData(false);
}
@Test
- public void testGenerateNadWithGeoData() {
+ void testGenerateNadWithGeoData() throws Exception {
testGenerateNadBasedOnGeoData(true);
}
@Test
- public void testNetworkAreaDiagramAdditionalMetadata() {
+ void testNetworkAreaDiagramAdditionalMetadata() throws Exception {
UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork());
@@ -383,11 +376,9 @@ public void testNetworkAreaDiagramAdditionalMetadata() {
SvgAndMetadata svgAndMetadata = networkAreaDiagramService.generateNetworkAreaDiagramSvg(testNetworkId, VARIANT_2_ID, List.of("vlFr1A"), 2, true);
Object additionalMetadata = svgAndMetadata.getAdditionalMetadata();
assertNotNull(additionalMetadata);
- Map convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() {
- });
+ Map convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() { });
assertEquals(1, convertedMetadata.get("nbVoltageLevels"));
- List