diff --git a/pom.xml b/pom.xml
index 029fb7e..d760d92 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,13 +17,11 @@
-
gridsuite-geo-data-server
1.0.0-SNAPSHOT
Geo data server
Geographical data server
-
http://www.gridsuite.org/
@@ -193,27 +191,11 @@
-
- junit
- junit
- test
-
-
- org.junit.vintage
- junit-vintage-engine
- test
-
org.springframework.boot
spring-boot-starter-test
test
-
- org.mockito
- mockito-core
- test
-
-
com.powsybl
powsybl-config-test
@@ -229,6 +211,5 @@
h2
test
-
diff --git a/src/main/java/org/gridsuite/geodata/server/repositories/LineRepository.java b/src/main/java/org/gridsuite/geodata/server/repositories/LineRepository.java
index d330780..b97931c 100644
--- a/src/main/java/org/gridsuite/geodata/server/repositories/LineRepository.java
+++ b/src/main/java/org/gridsuite/geodata/server/repositories/LineRepository.java
@@ -4,7 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-
package org.gridsuite.geodata.server.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java b/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java
index f24fc6e..68ac624 100644
--- a/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java
+++ b/src/test/java/org/gridsuite/geodata/server/GeoDataControllerTest.java
@@ -7,6 +7,7 @@
package org.gridsuite.geodata.server;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.io.ByteStreams;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
@@ -18,22 +19,17 @@
import org.gridsuite.geodata.server.dto.SubstationGeoData;
import org.gridsuite.geodata.server.repositories.LineRepository;
import org.gridsuite.geodata.server.repositories.SubstationRepository;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
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.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
-import com.google.common.io.ByteStreams;
import java.io.IOException;
-import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
-import java.util.Objects;
-
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Objects;
import java.util.UUID;
import static com.powsybl.network.store.model.NetworkStoreApi.VERSION;
@@ -48,9 +44,8 @@
/**
* @author Chamseddine Benhamed
*/
-@RunWith(SpringRunner.class)
@WebMvcTest(GeoDataController.class)
-public class GeoDataControllerTest {
+class GeoDataControllerTest {
@Autowired
private ObjectMapper objectMapper;
@@ -73,16 +68,12 @@ public class GeoDataControllerTest {
private static final String VARIANT_ID = "First_variant";
private static final String WRONG_VARIANT_ID = "Wrong_variant";
- public String toString(String resourceName) {
- try {
- return new String(ByteStreams.toByteArray(Objects.requireNonNull(getClass().getResourceAsStream(resourceName))), StandardCharsets.UTF_8);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
+ private static String toString(String resourceName) throws IOException {
+ return new String(ByteStreams.toByteArray(Objects.requireNonNull(GeoDataControllerTest.class.getResourceAsStream(resourceName))), StandardCharsets.UTF_8);
}
@Test
- public void test() throws Exception {
+ void test() throws Exception {
UUID networkUuid = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
Network testNetwork = EurostagTutorialExample1Factory.create();
@@ -185,7 +176,7 @@ public void test() throws Exception {
}
@Test
- public void testGetLinesError() throws Exception {
+ void testGetLinesError() throws Exception {
UUID networkUuid = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
Network testNetwork = EurostagTutorialExample1Factory.create();
given(service.getNetwork(networkUuid)).willReturn(testNetwork);
diff --git a/src/test/java/org/gridsuite/geodata/server/GeoDataServiceTest.java b/src/test/java/org/gridsuite/geodata/server/GeoDataServiceTest.java
index 2ff7709..df61aa8 100644
--- a/src/test/java/org/gridsuite/geodata/server/GeoDataServiceTest.java
+++ b/src/test/java/org/gridsuite/geodata/server/GeoDataServiceTest.java
@@ -6,36 +6,30 @@
*/
package org.gridsuite.geodata.server;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
-import com.powsybl.iidm.network.test.NoEquipmentNetworkFactory;
+import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.Coordinate;
+import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
+import com.powsybl.iidm.network.test.NoEquipmentNetworkFactory;
import org.gridsuite.geodata.server.dto.LineGeoData;
import org.gridsuite.geodata.server.dto.SubstationGeoData;
import org.gridsuite.geodata.server.repositories.*;
-import com.powsybl.iidm.network.*;
-import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
-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.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.boot.test.context.SpringBootTest;
import java.util.*;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Chamseddine Benhamed
*/
-@RunWith(SpringRunner.class)
-@ContextHierarchy({
- @ContextConfiguration(classes = GeoDataApplication.class)
- })
-public class GeoDataServiceTest {
+@SpringBootTest(classes = GeoDataApplication.class)
+class GeoDataServiceTest {
@Autowired
private ObjectMapper objectMapper;
@@ -47,15 +41,13 @@ public class GeoDataServiceTest {
private LineRepository lineRepository;
@Autowired
- GeoDataService geoDataService;
+ private GeoDataService geoDataService;
@Autowired
private DefaultSubstationGeoDataByCountry defaultSubstationsGeoData;
- @Before
- public void setUp() throws JsonProcessingException {
- lineRepository.deleteAll();
- substationRepository.deleteAll();
+ @BeforeEach
+ void setUp() throws Exception {
List substationEntities = new ArrayList<>();
substationEntities.add(SubstationEntity.builder()
@@ -125,14 +117,20 @@ public void setUp() throws JsonProcessingException {
lineRepository.saveAll(lineEntities);
}
- static LineGeoData getFromList(List list, String id) {
+ @AfterEach
+ void cleanDb() {
+ lineRepository.deleteAll();
+ substationRepository.deleteAll();
+ }
+
+ private static LineGeoData getFromList(List list, String id) {
Optional res = list.stream().filter(l -> l.getId().equals(id)).findAny();
assertTrue(res.isPresent());
return res.get();
}
@Test
- public void test() {
+ void test() {
Network network = createGeoDataNetwork();
List substationsGeoData = geoDataService.getSubstationsByCountries(network, new HashSet<>(Collections.singletonList(Country.FR)));
@@ -189,7 +187,7 @@ public void test() {
}
@Test
- public void testCgmesCase() {
+ void testCgmesCase() {
Network network = createCgmesGeoDataNetwork();
List substationsGeoData = geoDataService.getSubstationsByCountries(network, new HashSet<>(Collections.singletonList(Country.FR)));
@@ -202,7 +200,7 @@ public void testCgmesCase() {
}
@Test
- public void testNonExisting() {
+ void testNonExisting() {
Network network = EurostagTutorialExample1Factory.create();
Substation notexistsub1 = network.newSubstation()
.setId("NOTEXISTSUB1")
@@ -248,20 +246,20 @@ public void testNonExisting() {
.setB2(386E-6 / 2)
.add();
List substationsGeoData = geoDataService.getSubstationsByCountries(network, new HashSet<>(Collections.singletonList(Country.FR)));
- assertFalse("Must not contain nulls", substationsGeoData.stream().anyMatch(Objects::isNull));
- assertFalse("Must not contain unknown substation " + notexistsub1.getId(),
- substationsGeoData.stream().anyMatch(s -> notexistsub1.getId().equals(s.getId())));
- assertFalse("Must not contain unknown substation " + notexistsub2.getId(),
- substationsGeoData.stream().anyMatch(s -> notexistsub2.getId().equals(s.getId())));
+ assertFalse(substationsGeoData.stream().anyMatch(Objects::isNull), "Must not contain nulls");
+ assertFalse(substationsGeoData.stream().anyMatch(s -> notexistsub1.getId().equals(s.getId())),
+ "Must not contain unknown substation " + notexistsub1.getId());
+ assertFalse(substationsGeoData.stream().anyMatch(s -> notexistsub2.getId().equals(s.getId())),
+ "Must not contain unknown substation " + notexistsub2.getId());
List linesGeoData = geoDataService.getLinesByCountries(network, new HashSet<>(Collections.singletonList(Country.FR)));
- assertFalse("Must not contain nulls", linesGeoData.stream().anyMatch(Objects::isNull));
- assertFalse("Must not contain unknown lines " + notexistline.getId(),
- linesGeoData.stream().anyMatch(s -> notexistline.getId().equals(s.getId())));
+ assertFalse(linesGeoData.stream().anyMatch(Objects::isNull), "Must not contain nulls");
+ assertFalse(linesGeoData.stream().anyMatch(s -> notexistline.getId().equals(s.getId())),
+ "Must not contain unknown lines " + notexistline.getId());
}
@Test
- public void testSimilarNeighborhoodOffset() {
+ void testSimilarNeighborhoodOffset() {
Network network = EurostagTutorialExample1Factory.create();
Substation p4 = network.newSubstation()
.setId("P4")
@@ -363,7 +361,7 @@ public void testSimilarNeighborhoodOffset() {
}
@Test
- public void testCalculatedDefaultSubstations() {
+ void testCalculatedDefaultSubstations() {
Network network = EurostagTutorialExample1Factory.create();
Substation p4 = network.newSubstation()
.setId("P4")
@@ -514,7 +512,7 @@ public void testCalculatedDefaultSubstations() {
}
@Test
- public void testLineCoordinatesError() {
+ void testLineCoordinatesError() {
LineEntity lineEntity = LineEntity.create(LineGeoData.builder()
.id("idLine")
.country1(Country.FR)
@@ -527,7 +525,7 @@ public void testLineCoordinatesError() {
geoDataService.toDto(lineEntity));
}
- private Network createGeoDataNetwork() {
+ private static Network createGeoDataNetwork() {
Network network = EurostagTutorialExample1Factory.create();
Substation p3 = network.newSubstation()
@@ -846,7 +844,7 @@ private Network createGeoDataNetwork() {
return network;
}
- private Network createCgmesGeoDataNetwork() {
+ private static Network createCgmesGeoDataNetwork() {
Network network = NoEquipmentNetworkFactory.create();
Substation s1 = network.newSubstation()
@@ -903,7 +901,7 @@ private Network createCgmesGeoDataNetwork() {
}
@Test
- public void testGetSubstationsGeodataById() {
+ void testGetSubstationsGeodataById() {
Network network = createGeoDataNetwork();
List substationsGeoData = geoDataService.getSubstationsByIds(network, Set.of("P1", "P3"));
@@ -1018,7 +1016,7 @@ public void testGetSubstationsGeodataById() {
}
@Test
- public void testGetLinesGeodataById() {
+ void testGetLinesGeodataById() {
Network network = createGeoDataNetwork();
List linesGeoData = geoDataService.getLinesByIds(network, Set.of("NHV2_NHV5", "NHV1_NHV2_1"));
diff --git a/src/test/java/org/gridsuite/geodata/server/dto/LineGeoDataTest.java b/src/test/java/org/gridsuite/geodata/server/dto/LineGeoDataTest.java
index 9d871f3..74ef12d 100644
--- a/src/test/java/org/gridsuite/geodata/server/dto/LineGeoDataTest.java
+++ b/src/test/java/org/gridsuite/geodata/server/dto/LineGeoDataTest.java
@@ -8,21 +8,20 @@
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.extensions.Coordinate;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Chamseddine Benhamed
*/
-public class LineGeoDataTest {
-
+class LineGeoDataTest {
@Test
- public void test() {
+ void test() {
LineGeoData lineGeoData = new LineGeoData("l", Country.FR, Country.FR, "sub1", "sub2", new ArrayList<>());
assertEquals("l", lineGeoData.getId());
@@ -41,6 +40,5 @@ public void test() {
assertEquals("LineGeoData.LineGeoDataBuilder(id=testId, country1=FR, country2=FR, substationStart=sub1, substationEnd=sub2, coordinates=[Coordinate(lat=1.0, lon=2.0), Coordinate(lat=3.0, lon=4.0)])",
lineGeoDataBuilder.toString());
assertEquals("LineGeoData(id=testId, country1=FR, country2=FR, substationStart=sub1, substationEnd=sub2, coordinates=[Coordinate(lat=1.0, lon=2.0), Coordinate(lat=3.0, lon=4.0)])", lineGeoDataBuilder.build().toString());
-
}
}
diff --git a/src/test/java/org/gridsuite/geodata/server/dto/SubstationGeoDataTest.java b/src/test/java/org/gridsuite/geodata/server/dto/SubstationGeoDataTest.java
index 4bf891a..c5a8017 100644
--- a/src/test/java/org/gridsuite/geodata/server/dto/SubstationGeoDataTest.java
+++ b/src/test/java/org/gridsuite/geodata/server/dto/SubstationGeoDataTest.java
@@ -8,17 +8,16 @@
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.extensions.Coordinate;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Chamseddine Benhamed
*/
-public class SubstationGeoDataTest {
-
+class SubstationGeoDataTest {
@Test
- public void test() {
+ void test() {
SubstationGeoData substationGeoData = new SubstationGeoData("id", Country.FR, new Coordinate(1, 1));
assertEquals("id", substationGeoData.getId());
@@ -32,6 +31,5 @@ public void test() {
substationGeoDataBuilder.coordinate(new Coordinate(3, 4));
assertEquals("SubstationGeoData.SubstationGeoDataBuilder(id=testID, country=FR, coordinate=Coordinate(lat=3.0, lon=4.0))", substationGeoDataBuilder.toString());
assertEquals("SubstationGeoData(id=testID, country=FR, coordinate=Coordinate(lat=3.0, lon=4.0))", substationGeoDataBuilder.build().toString());
-
}
}
diff --git a/src/test/java/org/gridsuite/geodata/server/repositories/CoordinateEntityTest.java b/src/test/java/org/gridsuite/geodata/server/repositories/CoordinateEntityTest.java
index 24fa54a..5069a89 100644
--- a/src/test/java/org/gridsuite/geodata/server/repositories/CoordinateEntityTest.java
+++ b/src/test/java/org/gridsuite/geodata/server/repositories/CoordinateEntityTest.java
@@ -7,20 +7,19 @@
package org.gridsuite.geodata.server.repositories;
import com.powsybl.iidm.network.extensions.Coordinate;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Chamseddine Benhamed
*/
-public class CoordinateEntityTest {
-
+class CoordinateEntityTest {
@Test
- public void test() {
+ void test() {
List coordinateEntities = CoordinateEmbeddable.create(Arrays.asList(new Coordinate(1, 1), new Coordinate(2, 2)));
assertEquals(2, coordinateEntities.size(), 0);
diff --git a/src/test/java/org/gridsuite/geodata/server/repositories/LineRepositoryTest.java b/src/test/java/org/gridsuite/geodata/server/repositories/LineRepositoryTest.java
index 697d2b6..4fbbe37 100644
--- a/src/test/java/org/gridsuite/geodata/server/repositories/LineRepositoryTest.java
+++ b/src/test/java/org/gridsuite/geodata/server/repositories/LineRepositoryTest.java
@@ -10,30 +10,26 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.extensions.Coordinate;
-import org.gridsuite.geodata.server.GeoDataApplication;
import org.gridsuite.geodata.server.dto.LineGeoData;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.autoconfigure.json.AutoConfigureJson;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
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 Chamseddine Benhamed
*/
-@RunWith(SpringRunner.class)
-@ContextHierarchy({
- @ContextConfiguration(classes = {GeoDataApplication.class})
-})
-public class LineRepositoryTest {
+@DataJpaTest
+@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
+@AutoConfigureJson
+class LineRepositoryTest {
@Autowired
private ObjectMapper objectMapper;
@@ -41,13 +37,8 @@ public class LineRepositoryTest {
@Autowired
private LineRepository repository;
- @Before
- public void setUp() {
- repository.deleteAll();
- }
-
@Test
- public void test() throws JsonProcessingException {
+ void test() throws JsonProcessingException {
List coordinateEntities = new ArrayList<>();
coordinateEntities.add(new Coordinate(11, 12));
coordinateEntities.add(new Coordinate(13, 14.1));
@@ -80,6 +71,5 @@ public void test() throws JsonProcessingException {
assertEquals("Samy", le.getSubstationStart());
assertEquals("Scooby", le.getSubstationEnd());
assertTrue(le.isSide1());
-
}
}
diff --git a/src/test/java/org/gridsuite/geodata/server/repositories/SubstationRepositoryTest.java b/src/test/java/org/gridsuite/geodata/server/repositories/SubstationRepositoryTest.java
index 1ce6b21..20d96d3 100644
--- a/src/test/java/org/gridsuite/geodata/server/repositories/SubstationRepositoryTest.java
+++ b/src/test/java/org/gridsuite/geodata/server/repositories/SubstationRepositoryTest.java
@@ -6,39 +6,28 @@
*/
package org.gridsuite.geodata.server.repositories;
-import org.gridsuite.geodata.server.GeoDataApplication;
import org.gridsuite.geodata.server.dto.SubstationGeoData;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import java.util.List;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Chamseddine Benhamed
*/
-@RunWith(SpringRunner.class)
-@ContextHierarchy({
- @ContextConfiguration(classes = {GeoDataApplication.class})
- })
-public class SubstationRepositoryTest {
+@DataJpaTest
+@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
+class SubstationRepositoryTest {
@Autowired
private SubstationRepository repository;
- @Before
- public void setUp() {
- repository.deleteAll();
- }
-
@Test
- public void test() {
+ void test() {
SubstationEntity.SubstationEntityBuilder substationEntityBuilder = SubstationEntity.builder()
.country("FR")
.id("ID")