From aa34975d4683ab22e92637bb1b6d88312ec4f6dc Mon Sep 17 00:00:00 2001 From: Tristan Chuine Date: Thu, 10 Oct 2024 13:04:27 +0200 Subject: [PATCH 1/2] Migrate tests to JUnit5 --- pom.xml | 30 ++-- .../MergeOrchestratorConfigService.java | 2 - .../orchestrator/server/ReplacingDate.java | 1 + .../server/BalancesAdjustmentServiceTest.java | 24 ++- .../server/CaseFetcherServiceTest.java | 31 ++-- .../orchestrator/server/CaseInfosTest.java | 10 +- .../server/CgmesBoundaryServiceTest.java | 37 +++-- .../server/IgmQualityCheckServiceTest.java | 26 ++- .../server/IgmReplacingInfoTest.java | 10 +- .../server/LoadFlowServiceTest.java | 24 ++- ...eOrchestratorControllerReplaceIGMTest.java | 19 +-- .../MergeOrchestratorControllerTest.java | 41 ++--- .../server/MergeOrchestratorIT.java | 151 ++++++++---------- .../merge/orchestrator/server/MergeTest.java | 10 +- .../server/NetworkConversionServiceTest.java | 28 ++-- .../server/ProcessConfigControllerTest.java | 26 ++- .../server/ReplaceIGMGroovyTest.java | 23 +-- .../server/ReplacingDateTest.java | 10 +- .../server/SecuredZipInputStreamTest.java | 20 +-- .../orchestrator/server/utils/MatcherIgm.java | 3 +- .../server/utils/MatcherIgmEntity.java | 3 +- .../server/utils/MatcherMerge.java | 3 +- .../server/utils/MatcherMergeEntity.java | 3 +- .../server/utils/MatcherReport.java | 3 +- 24 files changed, 235 insertions(+), 303 deletions(-) diff --git a/pom.xml b/pom.xml index 5837f927..dc01bed3 100644 --- a/pom.xml +++ b/pom.xml @@ -42,10 +42,9 @@ - 33 - 3.9 + 34 org.gridsuite.merge.orchestrator.server - 4.0.21 + 5.0.0-alpha.14 @@ -72,6 +71,13 @@ + + com.squareup.okhttp3 + okhttp-bom + ${mockwebserver3.version} + pom + import + @@ -83,11 +89,6 @@ - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - @@ -136,7 +137,6 @@ org.apache.groovy groovy - ${groovy.version} com.powsybl @@ -195,16 +195,6 @@ h2 test - - junit - junit - test - - - org.junit.vintage - junit-vintage-engine - test - org.springframework.boot spring-boot-starter-test @@ -217,7 +207,7 @@ com.squareup.okhttp3 - mockwebserver + mockwebserver3-junit5 test diff --git a/src/main/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorConfigService.java b/src/main/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorConfigService.java index c2e5179d..7f932280 100644 --- a/src/main/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorConfigService.java +++ b/src/main/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorConfigService.java @@ -16,7 +16,6 @@ import org.gridsuite.merge.orchestrator.server.dto.BoundaryInfo; import org.gridsuite.merge.orchestrator.server.dto.ProcessConfig; import org.gridsuite.merge.orchestrator.server.repositories.*; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.HttpMethod; @@ -62,7 +61,6 @@ public class MergeOrchestratorConfigService { private RestTemplate reportRestClient; - @Autowired public MergeOrchestratorConfigService( @Value("${gridsuite.services.report-server.base-uri:https://report-server}") String reportServerBaseURI, ProcessConfigRepository processConfigRepository, diff --git a/src/main/java/org/gridsuite/merge/orchestrator/server/ReplacingDate.java b/src/main/java/org/gridsuite/merge/orchestrator/server/ReplacingDate.java index be26a8c1..652a2352 100644 --- a/src/main/java/org/gridsuite/merge/orchestrator/server/ReplacingDate.java +++ b/src/main/java/org/gridsuite/merge/orchestrator/server/ReplacingDate.java @@ -21,6 +21,7 @@ public class ReplacingDate { private String businessProcess; + @Override public String toString() { return "date:" + date + " " + "businessProcess:" + businessProcess; } diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/BalancesAdjustmentServiceTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/BalancesAdjustmentServiceTest.java index 13646105..bb1f23c7 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/BalancesAdjustmentServiceTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/BalancesAdjustmentServiceTest.java @@ -6,11 +6,11 @@ */ package org.gridsuite.merge.orchestrator.server; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; @@ -18,17 +18,15 @@ import java.util.Arrays; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; /** * @author Franck Lecuyer */ -@RunWith(MockitoJUnitRunner.class) -public class BalancesAdjustmentServiceTest { +@ExtendWith(MockitoExtension.class) +class BalancesAdjustmentServiceTest { @Mock private RestTemplate balancesAdjustmentServerRest; @@ -39,13 +37,13 @@ public class BalancesAdjustmentServiceTest { private UUID networkUuid2 = UUID.fromString("da47a173-22d2-47e8-8a84-aa66e2d0fafb"); private UUID networkUuid3 = UUID.fromString("4d6ac8c0-eaea-4b1c-8d28-a4297ad480b5"); - @Before - public void setUp() { + @BeforeEach + void setUp() { balancesAdjustmentService = new BalancesAdjustmentService(balancesAdjustmentServerRest); } @Test - public void test() { + void test() { when(balancesAdjustmentServerRest.exchange(anyString(), eq(HttpMethod.PUT), any(), diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/CaseFetcherServiceTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/CaseFetcherServiceTest.java index 608ea425..10980d8c 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/CaseFetcherServiceTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/CaseFetcherServiceTest.java @@ -9,34 +9,31 @@ import com.powsybl.network.store.client.NetworkStoreService; import org.gridsuite.merge.orchestrator.server.dto.CaseInfos; import org.gridsuite.merge.orchestrator.server.dto.FileInfos; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.*; import org.springframework.web.client.RestTemplate; import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; /** * @author Franck Lecuyer */ -@RunWith(MockitoJUnitRunner.class) -public class CaseFetcherServiceTest { +@ExtendWith(MockitoExtension.class) +class CaseFetcherServiceTest { @Mock private RestTemplate caseServerRest; @@ -52,8 +49,8 @@ public class CaseFetcherServiceTest { @Mock private NetworkStoreService networkStoreService; - @Before - public void setUp() { + @BeforeEach + void setUp() { caseFetcherService = new CaseFetcherService(caseServerRest); listCases = new ArrayList<>(); @@ -63,7 +60,7 @@ public void setUp() { } @Test - public void test() { + void test() { when(caseServerRest.exchange(eq("/v1/cases/search?q={q}"), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/CaseInfosTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/CaseInfosTest.java index 2712b718..0bb52386 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/CaseInfosTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/CaseInfosTest.java @@ -1,20 +1,20 @@ package org.gridsuite.merge.orchestrator.server; import org.gridsuite.merge.orchestrator.server.dto.CaseInfos; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Franck Lecuyer */ -public class CaseInfosTest { +class CaseInfosTest { @Test - public void test() { + void test() { UUID uuid = UUID.fromString("0e14e487-5182-470a-ba33-859a9d4a5061"); CaseInfos caseInfos = new CaseInfos("case", uuid, "XIIDM", "FR", "1D"); assertEquals("XIIDM", caseInfos.getFormat()); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/CgmesBoundaryServiceTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/CgmesBoundaryServiceTest.java index a2b5d8ab..edd72544 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/CgmesBoundaryServiceTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/CgmesBoundaryServiceTest.java @@ -7,22 +7,26 @@ package org.gridsuite.merge.orchestrator.server; import org.gridsuite.merge.orchestrator.server.dto.BoundaryContent; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.*; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -30,21 +34,21 @@ * @author Etienne Homer * @author Franck Lecuyer */ -@RunWith(MockitoJUnitRunner.class) -public class CgmesBoundaryServiceTest { +@ExtendWith(MockitoExtension.class) +class CgmesBoundaryServiceTest { @Mock private RestTemplate cgmesBoundaryServiceRest; private CgmesBoundaryService cgmesBoundaryService; - @Before - public void setUp() { + @BeforeEach + void setUp() { MockitoAnnotations.initMocks(this); cgmesBoundaryService = new CgmesBoundaryService(cgmesBoundaryServiceRest); } @Test - public void testLastBoundaries() { + void testLastBoundaries() { List> response = new ArrayList<>(List.of( Map.of("id", "id1", "filename", "name1", "boundary", "boundary1"), Map.of("id", "id2", "filename", "name2", "boundary", "boundary2") @@ -67,7 +71,7 @@ public void testLastBoundaries() { } @Test - public void testSpecificBoundaries() { + void testSpecificBoundaries() { Map response = Map.of("id", "id1", "filename", "name1", "boundary", "boundary1"); when(cgmesBoundaryServiceRest.exchange(eq("/v1/boundaries/id1"), @@ -90,4 +94,3 @@ public void testSpecificBoundaries() { assertFalse(res.isPresent()); } } - diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/IgmQualityCheckServiceTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/IgmQualityCheckServiceTest.java index a538c2a5..fb945aeb 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/IgmQualityCheckServiceTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/IgmQualityCheckServiceTest.java @@ -7,30 +7,26 @@ package org.gridsuite.merge.orchestrator.server; import com.powsybl.commons.PowsyblException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import java.util.UUID; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; /** * @author Franck Lecuyer */ -@RunWith(MockitoJUnitRunner.class) -public class IgmQualityCheckServiceTest { +@ExtendWith(MockitoExtension.class) +class IgmQualityCheckServiceTest { @Mock private RestTemplate caseValidationServerRest; @@ -42,13 +38,13 @@ public class IgmQualityCheckServiceTest { private UUID networkUuid3 = UUID.fromString("4d6ac8c0-eaea-4b1c-8d28-a4297ad480b5"); private UUID reportId = UUID.fromString("12345691-5478-7412-2589-a4297ad480b5"); - @Before - public void setUp() { + @BeforeEach + void setUp() { igmQualityCheckService = new IgmQualityCheckService(caseValidationServerRest); } @Test - public void test() { + void test() { when(caseValidationServerRest.exchange(anyString(), eq(HttpMethod.PUT), any(), diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/IgmReplacingInfoTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/IgmReplacingInfoTest.java index 92de3131..76db012e 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/IgmReplacingInfoTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/IgmReplacingInfoTest.java @@ -8,21 +8,21 @@ import org.gridsuite.merge.orchestrator.server.dto.IgmReplacingInfo; import org.gridsuite.merge.orchestrator.server.dto.IgmStatus; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.ZonedDateTime; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Franck Lecuyer */ -public class IgmReplacingInfoTest { +class IgmReplacingInfoTest { @Test - public void test() { + void test() { UUID networkUuid = UUID.fromString("47b85a5c-44ec-4afc-9f7e-29e63368e83d"); UUID caseUuid = UUID.fromString("4d6ac8c0-eaea-4b1c-8d28-a4297ad480b5"); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/LoadFlowServiceTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/LoadFlowServiceTest.java index b8b26e69..700de6e5 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/LoadFlowServiceTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/LoadFlowServiceTest.java @@ -11,12 +11,12 @@ import com.powsybl.loadflow.LoadFlowResultImpl; import com.powsybl.loadflow.json.JsonLoadFlowParameters; import org.gridsuite.merge.orchestrator.server.dto.MergeStatus; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatcher; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -28,17 +28,15 @@ import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; /** * @author Franck Lecuyer */ -@RunWith(MockitoJUnitRunner.class) -public class LoadFlowServiceTest { +@ExtendWith(MockitoExtension.class) +class LoadFlowServiceTest { @Mock private RestTemplate loadFlowServerRest; @@ -49,8 +47,8 @@ public class LoadFlowServiceTest { private UUID networkUuid2 = UUID.fromString("da47a173-22d2-47e8-8a84-aa66e2d0fafb"); private UUID networkUuid3 = UUID.fromString("4d6ac8c0-eaea-4b1c-8d28-a4297ad480b5"); - @Before - public void setUp() { + @BeforeEach + void setUp() { loadFlowService = new LoadFlowService(loadFlowServerRest); } @@ -70,7 +68,7 @@ private void addLoadFlowResultExpectation(UUID networkUuid, } @Test - public void test() { + void test() { List componentResultsOk = Collections.singletonList(new LoadFlowResultImpl.ComponentResultImpl(0, 0, LoadFlowResult.ComponentResult.Status.CONVERGED, 5, "slackBusId", 0, 0)); List componentResultsNok = Collections.singletonList(new LoadFlowResultImpl.ComponentResultImpl(0, 0, LoadFlowResult.ComponentResult.Status.FAILED, 20, "slackBusId", 0, 0)); List componentResultsEmpty = Collections.emptyList(); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerReplaceIGMTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerReplaceIGMTest.java index 8d744d0e..3ae73c79 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerReplaceIGMTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerReplaceIGMTest.java @@ -8,15 +8,12 @@ import org.gridsuite.merge.orchestrator.server.dto.IgmReplacingInfo; import org.gridsuite.merge.orchestrator.server.dto.IgmStatus; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -30,7 +27,7 @@ import java.util.UUID; import static com.powsybl.network.store.model.NetworkStoreApi.VERSION; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; @@ -41,10 +38,8 @@ /** * @author Franck Lecuyer */ -@RunWith(SpringRunner.class) @WebMvcTest(MergeOrchestratorController.class) -@ContextConfiguration(classes = {MergeOrchestratorApplication.class}) -public class MergeOrchestratorControllerReplaceIGMTest { +class MergeOrchestratorControllerReplaceIGMTest { @Autowired private MockMvc mvc; @@ -78,13 +73,13 @@ public class MergeOrchestratorControllerReplaceIGMTest { @MockBean private NotificationService notificationService; - @Before - public void setUp() { + @BeforeEach + void setUp() { MockitoAnnotations.initMocks(this); } @Test - public void testReplaceIGM() throws Exception { + void testReplaceIGM() throws Exception { UUID uuidCaseIdFr = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); UUID uuidNetworkIdFr = UUID.fromString("8928181c-7977-4592-ba19-88027e4254e4"); UUID uuidCaseIdEs = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e5"); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerTest.java index 7dca06c4..ca426dff 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorControllerTest.java @@ -10,12 +10,11 @@ import com.powsybl.iidm.network.NetworkFactory; import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; -import lombok.SneakyThrows; import org.gridsuite.merge.orchestrator.server.dto.*; import org.gridsuite.merge.orchestrator.server.repositories.*; -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.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; @@ -27,13 +26,12 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.ExpectedCount; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.test.web.servlet.MockMvc; import java.net.URI; +import java.net.URISyntaxException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.time.ZoneId; @@ -60,11 +58,9 @@ /** * @author Franck Lecuyer */ -@RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = {MergeOrchestratorApplication.class, TestChannelBinderConfiguration.class}) @AutoConfigureMockMvc -@ContextConfiguration(classes = {MergeOrchestratorApplication.class, TestChannelBinderConfiguration.class}) -public class MergeOrchestratorControllerTest { +class MergeOrchestratorControllerTest { private static final UUID UUID_NETWORK = UUID.fromString("db9b8260-0e8d-4e0c-aad4-56994c151925"); private static final UUID UUID_NETWORK_MERGE_1 = UUID.fromString("a7a38a4c-a733-4d5e-a38d-8c6ab121c497"); @@ -90,13 +86,13 @@ public class MergeOrchestratorControllerTest { private MockMvc mvc; @Autowired - MergeRepository mergeRepository; + private MergeRepository mergeRepository; @Autowired - IgmRepository igmRepository; + private IgmRepository igmRepository; @Autowired - ProcessConfigRepository processConfigRepository; + private ProcessConfigRepository processConfigRepository; @MockBean private NetworkStoreService networkStoreService; @@ -121,16 +117,17 @@ public class MergeOrchestratorControllerTest { private MockRestServiceServer mockReportServer; @Autowired - InputDestination input; + private InputDestination input; - private void cleanDB() { + @AfterEach + void cleanDB() { igmRepository.deleteAll(); mergeRepository.deleteAll(); processConfigRepository.deleteAll(); } - @Before - public void setUp() { + @BeforeEach + void setUp() { MockitoAnnotations.initMocks(this); mockReportServer = MockRestServiceServer.createServer(mergeConfigService.getReportRestClient()); @@ -152,12 +149,10 @@ public void setUp() { Mockito.when(loadFlowService.run(any(), any())) .thenReturn(MergeStatus.FIRST_LOADFLOW_SUCCEED); - - cleanDB(); } @Test - public void test() throws Exception { + void test() throws Exception { ZonedDateTime dateTime = ZonedDateTime.of(2020, 7, 20, 10, 0, 0, 0, ZoneId.of("UTC")); mergeRepository.save(new MergeEntity(new MergeEntityKey(SWE_1D_UUID, dateTime.toLocalDateTime()), MergeStatus.FIRST_LOADFLOW_SUCCEED.name())); igmRepository.save(new IgmEntity(new IgmEntityKey(SWE_1D_UUID, dateTime.toLocalDateTime(), "FR"), IgmStatus.VALIDATION_SUCCEED.name(), UUID_NETWORK, UUID_CASE, null, null, null, null)); @@ -235,14 +230,12 @@ public void test() throws Exception { .andExpect(content().contentTypeCompatibleWith(APPLICATION_OCTET_STREAM)); } - @SneakyThrows - private URI getReportServerURI(String uri) { + private URI getReportServerURI(String uri) throws URISyntaxException { return new URI(mergeConfigService.getReportServerURI() + uri); } - @SneakyThrows @Test - public void testReport() { + void testReport() throws Exception { mergeConfigService.addConfig(new ProcessConfig(FRES_2D_UUID, "FRES_2D", "2D", List.of("FR", "ES"), false, true, null, null)); ZonedDateTime dateTime = ZonedDateTime.of(2019, 5, 1, 10, 0, 0, 0, ZoneId.of("UTC")); String mergeDate = DATE_FORMATTER.format(dateTime); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java index 45818ae2..ad19ac2d 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java @@ -15,18 +15,18 @@ import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import lombok.SneakyThrows; +import mockwebserver3.Dispatcher; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; +import okhttp3.Headers; import okhttp3.HttpUrl; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; import org.gridsuite.merge.orchestrator.server.dto.*; import org.gridsuite.merge.orchestrator.server.repositories.*; import org.gridsuite.merge.orchestrator.server.utils.*; -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.Mockito; import org.mockito.MockitoAnnotations; import org.slf4j.Logger; @@ -38,13 +38,13 @@ import org.springframework.cloud.stream.binder.test.InputDestination; import org.springframework.cloud.stream.binder.test.OutputDestination; import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringRunner; import java.time.LocalDateTime; import java.time.ZoneId; @@ -58,8 +58,7 @@ import static org.gridsuite.merge.orchestrator.server.MergeOrchestratorException.Type.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -67,31 +66,29 @@ * @author Jon Harper * @author Franck Lecuyer httpRequest = null; try { - httpRequest = getRequestsDone(1); + httpRequest = getRequestsDone(mockWebServer, 1); } catch (NullPointerException e) { // Ignoring } - - // Shut down the server. Instances cannot be reused. - try { - mockServer.shutdown(); - } catch (Exception e) { - // Ignoring - } - - assertNull("Should not be any messages", output.receive(1000, "merge.destination")); - assertNull("Should not be any http requests", httpRequest); + assertNull(output.receive(1000, "merge.destination"), "Should not be any messages"); + assertNull(httpRequest, "Should not be any http requests"); } - @SneakyThrows - private void initMockServer() { - mockServer = new MockWebServer(); - + private void initMockServer(final MockWebServer mockServer) { // FIXME: remove lines when dicos will be used on the front side - mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new ReportNodeJsonModule()); - // Start the server. - mockServer.start(); - // Ask the server for its URL. You'll need this to make HTTP requests. HttpUrl baseHttpUrl = mockServer.url(""); String baseUrl = baseHttpUrl.toString().substring(0, baseHttpUrl.toString().length() - 1); @@ -271,35 +248,35 @@ public MockResponse dispatch(RecordedRequest request) { String path = Objects.requireNonNull(request.getPath()); //Buffer body = request.getBody(); if (path.matches("/v1/reports/" + reportUuid) && "GET".equals(request.getMethod())) { - return new MockResponse().setResponseCode(HttpStatus.OK.value()).setBody(mapper.writeValueAsString(REPORT_TEST)) - .addHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE); + return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), mapper.writeValueAsString(REPORT_TEST)); } else if (path.matches("/v1/reports/" + reportUuid) && "DELETE".equals(request.getMethod())) { - return new MockResponse().setResponseCode(HttpStatus.OK.value()); + return new MockResponse(HttpStatus.OK.value()); } else if (path.matches("/v1/reports/" + reportErrorUuid)) { - return new MockResponse().setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value()); + return new MockResponse(HttpStatus.INTERNAL_SERVER_ERROR.value()); } else { LOGGER.error("Path not supported: " + request.getPath()); - return new MockResponse().setResponseCode(HttpStatus.NOT_FOUND.value()); - + return new MockResponse(HttpStatus.NOT_FOUND.value()); } } }; mockServer.setDispatcher(dispatcher); } - private Set getRequestsDone(int n) { + private Set getRequestsDone(final MockWebServer mockServer, final int n) { return IntStream.range(0, n).mapToObj(i -> { try { return mockServer.takeRequest(0, TimeUnit.SECONDS).getPath(); } catch (InterruptedException e) { - LOGGER.error("Error while attempting to get the request done : ", e); + LOGGER.error("Error while attempting to get the request done :", e); + return null; + } catch (NullPointerException e) { + return "[error]getPath()"; } - return null; }).collect(Collectors.toSet()); } @Test - public void testSingleMerge() { + void testSingleMerge() { createProcessConfigs(); // send first tso FR with business process = 1D, expect only one AVAILABLE and one VALIDATION_SUCCEED message @@ -429,7 +406,7 @@ private void testErrorMessage(String errorMessage) { } @Test - public void testMergeWithSpecificBoundaries() { + void testMergeWithSpecificBoundaries() { createProcessConfigWithSpecificBoundaries(); // first specific boundary available @@ -553,7 +530,7 @@ public void testMergeWithSpecificBoundaries() { } @Test - public void testMultipleMerge() { + void testMultipleMerge(final MockWebServer mockWebServer) { createProcessConfigs(); // send first tso FR with business process = 2D, expect two AVAILABLE and two VALIDATION_SUCCEED message @@ -724,7 +701,7 @@ public void testMultipleMerge() { reportUuid = merges.get(0).getReportUUID(); mergeOrchestratorConfigService.deleteConfig(SWE_2D_UUID); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); assertEquals("[MergeEntity(key=MergeEntityKey(processUuid=" + FRES_2D_UUID + ", date=2019-05-01T09:00), status=FIRST_LOADFLOW_SUCCEED, reportUUID=" + reportFres2Duuid + ")]", mergeRepository.findAll().toString()); @@ -764,7 +741,7 @@ private void testMergeOk(Merge merge, List tsos) { } @Test - public void testDeleteMerge() { + void testDeleteMerge(final MockWebServer mockWebServer) { mergeOrchestratorConfigService.addConfig(new ProcessConfig(FRES_2D_UUID, "FRES_2D", "2D", List.of("FR", "ES"), false, true, null, null)); mergeOrchestratorConfigService.addConfig(new ProcessConfig(FRPT_2D_UUID, "FRPT_2D", "2D", List.of("FR", "PT"), false, true, null, null)); @@ -815,57 +792,57 @@ public void testDeleteMerge() { assertTrue(assertThrows(MergeOrchestratorException.class, () -> mergeOrchestratorConfigService.getReport(randomUuid)) .getMessage().contains(MERGE_REPORT_NOT_FOUND.name())); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", randomUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", randomUuid))); reportErrorUuid = UUID.randomUUID(); assertTrue(assertThrows(MergeOrchestratorException.class, () -> mergeOrchestratorConfigService.getReport(reportErrorUuid)) .getMessage().contains(MERGE_REPORT_ERROR.name())); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportErrorUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportErrorUuid))); reportUuid = merges.get(0).getReportUUID(); assertThat(mergeOrchestratorConfigService.getReport(reportUuid), new MatcherReport(REPORT_TEST)); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); reportUuid = merges.get(1).getReportUUID(); assertThat(mergeOrchestratorConfigService.getReport(reportUuid), new MatcherReport(REPORT_TEST)); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); assertTrue(assertThrows(MergeOrchestratorException.class, () -> mergeOrchestratorService.deleteReport(randomUuid, dateNow)) .getMessage().contains(MERGE_NOT_FOUND.name())); assertTrue(assertThrows(MergeOrchestratorException.class, () -> mergeOrchestratorConfigService.deleteReport(randomUuid)) .getMessage().contains(MERGE_REPORT_NOT_FOUND.name())); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", randomUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", randomUuid))); assertTrue(assertThrows(MergeOrchestratorException.class, () -> mergeOrchestratorConfigService.deleteReport(reportErrorUuid)) .getMessage().contains(MERGE_REPORT_ERROR.name())); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportErrorUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportErrorUuid))); reportUuid = merges.get(0).getReportUUID(); mergeOrchestratorService.deleteReport(FRES_2D_UUID, LocalDateTime.ofInstant(dateTime.toInstant(), ZoneOffset.UTC)); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); reportUuid = merges.get(1).getReportUUID(); mergeOrchestratorService.deleteReport(FRPT_2D_UUID, LocalDateTime.ofInstant(dateTime.toInstant(), ZoneOffset.UTC)); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); reportUuid = merges.get(0).getReportUUID(); mergeOrchestratorConfigService.deleteConfig(FRES_2D_UUID); assertEquals(1, mergeRepository.findAll().size()); assertEquals(2, igmRepository.findAll().size()); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); reportUuid = merges.get(1).getReportUUID(); mergeOrchestratorConfigService.deleteConfig(FRPT_2D_UUID); assertEquals(0, mergeRepository.findAll().size()); assertEquals(0, igmRepository.findAll().size()); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); assertNull(output.receive(1000, "merge.destination")); } @Test - public void testDeleteIgmMergeWithImportError() { + void testDeleteIgmMergeWithImportError(final MockWebServer mockWebServer) { mergeOrchestratorConfigService.addConfig(new ProcessConfig(FRES_2D_UUID, "FRES_2D", "2D", List.of("FR", "ES"), false, true, null, null)); Mockito.when(cgmesBoundaryService.getLastBoundaries()) @@ -902,13 +879,13 @@ public void testDeleteIgmMergeWithImportError() { assertEquals(0, mergeRepository.findAll().size()); assertEquals(0, igmRepository.findAll().size()); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); assertNull(output.receive(1000, "merge.destination")); } @Test - public void testDeleteIgmMergeWithValidationFailed() { + void testDeleteIgmMergeWithValidationFailed(final MockWebServer mockWebServer) { mergeOrchestratorConfigService.addConfig(new ProcessConfig(FRES_2D_UUID, "FRES_2D", "2D", List.of("FR", "ES"), false, true, null, null)); Mockito.when(cgmesBoundaryService.getLastBoundaries()) @@ -945,13 +922,13 @@ public void testDeleteIgmMergeWithValidationFailed() { assertEquals(0, mergeRepository.findAll().size()); assertEquals(0, igmRepository.findAll().size()); - assertTrue(getRequestsDone(1).contains(String.format("/v1/reports/%s", reportUuid))); + assertTrue(getRequestsDone(mockWebServer, 1).contains(String.format("/v1/reports/%s", reportUuid))); assertNull(output.receive(1000, "merge.destination")); } @Test - public void testImportIgmByOnlyMatchingConfigs() { + void testImportIgmByOnlyMatchingConfigs() { mergeOrchestratorConfigService.addConfig(new ProcessConfig(FRES_2D_UUID, "FRES_2D", "2D", List.of("FR", "ES"), false, true, null, null)); mergeOrchestratorConfigService.addConfig(new ProcessConfig(FRPT_2D_UUID, "FRPT_2D", "2D", List.of("FR", "PT"), false, true, null, null)); MergeStatus mergeStatusOk = runBalancesAdjustment ? MergeStatus.BALANCE_ADJUSTMENT_SUCCEED : MergeStatus.FIRST_LOADFLOW_SUCCEED; @@ -1081,7 +1058,7 @@ public void testImportIgmByOnlyMatchingConfigs() { } @Test - public void parametersRepositoryTest() { + void parametersRepositoryTest() { createProcessConfigs(); List configs = mergeOrchestratorConfigService.getConfigs(); assertEquals(3, configs.size()); @@ -1115,7 +1092,7 @@ public void parametersRepositoryTest() { } @Test - public void replacingIGMsTest() { + void replacingIGMsTest() { // process dateTime : 2019-05_01T09:30:00Z ZonedDateTime dateTime = ZonedDateTime.of(2019, 5, 1, 9, 30, 0, 0, ZoneId.of("UTC")); @@ -1267,7 +1244,7 @@ public void replacingIGMsTest() { } @Test - public void testGetMerges() { + void testGetMerges() { ZonedDateTime dateTime = ZonedDateTime.of(2020, 7, 20, 8, 30, 0, 0, ZoneId.of("UTC")); ZonedDateTime replacingTime1 = ZonedDateTime.of(2020, 7, 21, 5, 30, 0, 0, ZoneId.of("UTC")); ZonedDateTime replacingTime2 = ZonedDateTime.of(2020, 7, 22, 12, 30, 0, 0, ZoneId.of("UTC")); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeTest.java index e1ab0f10..339b673d 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeTest.java @@ -10,24 +10,24 @@ import org.gridsuite.merge.orchestrator.server.dto.IgmStatus; import org.gridsuite.merge.orchestrator.server.dto.Merge; import org.gridsuite.merge.orchestrator.server.dto.MergeStatus; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.ZonedDateTime; import java.util.Collections; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Franck Lecuyer * @author Franck Lecuyer */ -@RunWith(MockitoJUnitRunner.class) -public class NetworkConversionServiceTest { +@ExtendWith(MockitoExtension.class) +class NetworkConversionServiceTest { @Mock private RestTemplate networkConversionServerRest; @@ -63,14 +59,14 @@ public class NetworkConversionServiceTest { private UUID networkUuid3 = UUID.fromString("4d6ac8c0-eaea-4b1c-8d28-a4297ad480b5"); private byte[] response = "TestFileContent".getBytes(); - @Before - public void setUp() { + @BeforeEach + void setUp() { MockitoAnnotations.initMocks(this); networkConversionService = new NetworkConversionService(networkConversionServerRest, caseFetcherService); } @Test - public void testExportXiidm() { + void testExportXiidm() { HttpHeaders header = new HttpHeaders(); header.setContentDisposition(ContentDisposition.builder("attachment").filename("test_file.xiidm", StandardCharsets.UTF_8).build()); when(networkConversionServerRest.exchange(anyString(), @@ -86,7 +82,7 @@ public void testExportXiidm() { } @Test - public void testExportCgmes() throws IOException, URISyntaxException { + void testExportCgmes() throws Exception { byte[] fileContentBe = Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("MicroGridTestConfiguration_T4_BE_BB_Complete_v2.zip").toURI())); byte[] fileContentNl = Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("MicroGridTestConfiguration_T4_NL_BB_Complete_v2.zip").toURI())); @@ -152,7 +148,7 @@ public void testExportCgmes() throws IOException, URISyntaxException { } @Test - public void importCaseTest() { + void importCaseTest() { List boundaries = new ArrayList<>(); String boundary1Id = "idBoundary1"; String boundary1Filename = "boundary1.xml"; diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/ProcessConfigControllerTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/ProcessConfigControllerTest.java index b48e3179..bce8baea 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/ProcessConfigControllerTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/ProcessConfigControllerTest.java @@ -9,16 +9,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.gridsuite.merge.orchestrator.server.dto.BoundaryInfo; import org.gridsuite.merge.orchestrator.server.dto.ProcessConfig; -import org.gridsuite.merge.orchestrator.server.repositories.*; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.gridsuite.merge.orchestrator.server.repositories.BoundaryRepository; +import org.gridsuite.merge.orchestrator.server.repositories.IgmRepository; +import org.gridsuite.merge.orchestrator.server.repositories.MergeRepository; +import org.gridsuite.merge.orchestrator.server.repositories.ProcessConfigRepository; +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.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import java.time.LocalDateTime; @@ -27,7 +27,7 @@ import java.util.UUID; import static com.powsybl.network.store.model.NetworkStoreApi.VERSION; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @@ -37,11 +37,9 @@ * @author Chamseddine Benhamed * @author Franck Lecuyer */ -public class ReplaceIGMGroovyTest { +class ReplaceIGMGroovyTest { private static final Logger LOGGER = LoggerFactory.getLogger(ReplaceIGMGroovyTest.class); GroovyShell shell; Script replacingIGMScript; - @Before - public void setUp() { + @BeforeEach + void setUp() { shell = new GroovyShell(); try { replacingIGMScript = shell.parse(new InputStreamReader(new ClassPathResource("replaceIGM.groovy").getInputStream())); @@ -37,8 +38,8 @@ public void setUp() { } @Test - public void test() { - Assert.assertEquals("[date:2021-01-11T02:30:00Z businessProcess:1D, date:2021-01-11T04:30:00Z businessProcess:1D, " + + void test() { + assertEquals("[date:2021-01-11T02:30:00Z businessProcess:1D, date:2021-01-11T04:30:00Z businessProcess:1D, " + "date:2021-01-11T01:30:00Z businessProcess:1D, date:2021-01-11T05:30:00Z businessProcess:1D, " + "date:2021-01-11T00:30:00Z businessProcess:1D, date:2021-01-08T03:30:00Z businessProcess:1D, " + "date:2021-01-08T02:30:00Z businessProcess:1D, date:2021-01-08T04:30:00Z businessProcess:1D, " + @@ -55,7 +56,7 @@ public void test() { "date:2021-01-11T23:30:00Z businessProcess:1D]", MergeOrchestratorService.execReplaceGroovyScript(replacingIGMScript, "2021-01-11T03:30:00Z", "SWE_1D", "1D").toString()); - Assert.assertEquals("[date:2021-01-14T10:30:00Z businessProcess:2D, date:2021-01-14T08:30:00Z businessProcess:2D, " + + assertEquals("[date:2021-01-14T10:30:00Z businessProcess:2D, date:2021-01-14T08:30:00Z businessProcess:2D, " + "date:2021-01-14T11:30:00Z businessProcess:2D, date:2021-01-14T12:30:00Z businessProcess:2D, " + "date:2021-01-13T09:30:00Z businessProcess:2D, date:2021-01-13T10:30:00Z businessProcess:2D, " + "date:2021-01-13T08:30:00Z businessProcess:2D, date:2021-01-13T11:30:00Z businessProcess:2D, " + @@ -71,7 +72,7 @@ public void test() { "date:2021-01-14T22:30:00Z businessProcess:2D, date:2021-01-14T23:30:00Z businessProcess:2D]", MergeOrchestratorService.execReplaceGroovyScript(replacingIGMScript, "2021-01-14T09:30:00Z", "SWE_2D", "2D").toString()); - Assert.assertEquals("[date:2021-01-16T20:30:00Z businessProcess:SN, date:2021-01-16T22:30:00Z businessProcess:SN, " + + assertEquals("[date:2021-01-16T20:30:00Z businessProcess:SN, date:2021-01-16T22:30:00Z businessProcess:SN, " + "date:2021-01-16T19:30:00Z businessProcess:SN, date:2021-01-16T23:30:00Z businessProcess:SN, " + "date:2021-01-09T21:30:00Z businessProcess:SN, date:2021-01-09T20:30:00Z businessProcess:SN, " + "date:2021-01-09T22:30:00Z businessProcess:SN, date:2021-01-09T19:30:00Z businessProcess:SN, " + @@ -87,7 +88,7 @@ public void test() { "date:2021-01-16T17:30:00Z businessProcess:SN, date:2021-01-16T18:30:00Z businessProcess:SN]", MergeOrchestratorService.execReplaceGroovyScript(replacingIGMScript, "2021-01-16T21:30:00Z", "SWE_SN", "SN").toString()); - Assert.assertEquals("[date:2021-01-17T16:30:00Z businessProcess:2D, date:2021-01-17T17:30:00Z businessProcess:2D, " + + assertEquals("[date:2021-01-17T16:30:00Z businessProcess:2D, date:2021-01-17T17:30:00Z businessProcess:2D, " + "date:2021-01-17T14:30:00Z businessProcess:2D, date:2021-01-17T13:30:00Z businessProcess:2D, " + "date:2021-01-17T12:30:00Z businessProcess:2D, date:2021-01-10T15:30:00Z businessProcess:2D, " + "date:2021-01-10T16:30:00Z businessProcess:2D, date:2021-01-10T17:30:00Z businessProcess:2D, " + diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/ReplacingDateTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/ReplacingDateTest.java index 1ea231ef..cbf79ef9 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/ReplacingDateTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/ReplacingDateTest.java @@ -6,18 +6,18 @@ */ package org.gridsuite.merge.orchestrator.server; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Franck Lecuyer */ -public class ReplacingDateTest { +class ReplacingDateTest { @Test - public void test() { + void test() { ReplacingDate rDate = new ReplacingDate("2021-01-14T09:30:00Z", "1D"); assertEquals("2021-01-14T09:30:00Z", rDate.getDate()); assertEquals("1D", rDate.getBusinessProcess()); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/SecuredZipInputStreamTest.java b/src/test/java/org/gridsuite/merge/orchestrator/server/SecuredZipInputStreamTest.java index 597a4521..c6c6c21d 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/SecuredZipInputStreamTest.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/SecuredZipInputStreamTest.java @@ -1,38 +1,34 @@ package org.gridsuite.merge.orchestrator.server; import org.gridsuite.merge.orchestrator.server.utils.SecuredZipInputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -public class SecuredZipInputStreamTest { +class SecuredZipInputStreamTest { @Test - public void test() throws URISyntaxException, IOException { + void test() throws Exception { byte[] fileContent = Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("MicroGridTestConfiguration_T4_BE_BB_Complete_v2.zip").toURI())); SecuredZipInputStream tooManyEntriesSecuredZis = new SecuredZipInputStream(new ByteArrayInputStream(fileContent), 3, 1000000000); - assertThrows(IllegalStateException.class, () -> readZip(tooManyEntriesSecuredZis)) - .getMessage().contains("Zip has too many entries."); + assertThrows(IllegalStateException.class, () -> readZip(tooManyEntriesSecuredZis), "Zip has too many entries."); SecuredZipInputStream tooBigSecuredZis = new SecuredZipInputStream(new ByteArrayInputStream(fileContent), 1000, 15000); - assertThrows(IllegalStateException.class, () -> readZip(tooBigSecuredZis)) - .getMessage().contains("Zip size is too big."); + assertThrows(IllegalStateException.class, () -> readZip(tooBigSecuredZis), "Zip size is too big."); SecuredZipInputStream okSecuredZis = new SecuredZipInputStream(new ByteArrayInputStream(fileContent), 1000, 1000000000); ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(fileContent)); assertEquals(readZip(zis), readZip(okSecuredZis)); - } - public int readZip(ZipInputStream zis) throws IOException { + private static int readZip(ZipInputStream zis) throws IOException { ZipEntry entry = zis.getNextEntry(); int readBytes = 0; while (entry != null) { diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgm.java b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgm.java index b8696bbd..3e05c9af 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgm.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgm.java @@ -17,8 +17,7 @@ * @author Slimane Amar */ public class MatcherIgm extends TypeSafeMatcher { - - Igm reference; + private final Igm reference; public MatcherIgm(String tso, IgmStatus status) { this.reference = new Igm(tso, status, null, null); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgmEntity.java b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgmEntity.java index f0407254..cb609475 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgmEntity.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherIgmEntity.java @@ -19,8 +19,7 @@ * @author Slimane Amar */ public class MatcherIgmEntity extends TypeSafeMatcher { - - IgmEntity reference; + private final IgmEntity reference; public MatcherIgmEntity(UUID processUuid, LocalDateTime date, String tso, IgmStatus status, UUID networkUuid) { this.reference = new IgmEntity(new IgmEntityKey(processUuid, date, tso), status.name(), networkUuid, networkUuid, null, null, null, null); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMerge.java b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMerge.java index 808c1f57..1f223da0 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMerge.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMerge.java @@ -19,8 +19,7 @@ * @author Slimane Amar */ public class MatcherMerge extends TypeSafeMatcher { - - Merge reference; + private final Merge reference; public MatcherMerge(UUID processUuid, ZonedDateTime date, MergeStatus status) { this.reference = new Merge(processUuid, date, status, List.of()); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMergeEntity.java b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMergeEntity.java index 899f390d..0cce17d7 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMergeEntity.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherMergeEntity.java @@ -20,8 +20,7 @@ * @author Slimane Amar */ public class MatcherMergeEntity extends TypeSafeMatcher { - - MergeEntity reference; + private final MergeEntity reference; public MatcherMergeEntity(UUID processUuid, LocalDateTime date, MergeStatus status) { this.reference = new MergeEntity(new MergeEntityKey(processUuid, date), status == null ? null : status.name()); diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherReport.java b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherReport.java index ad3ebefc..809239e2 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherReport.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/utils/MatcherReport.java @@ -14,8 +14,7 @@ * @author Slimane Amar */ public class MatcherReport extends TypeSafeMatcher { - - ReportNode reference; + private final ReportNode reference; public MatcherReport(ReportNode report) { this.reference = report; From 3be26417cfcb4636ecd2f7bfb498e8d697ceb598 Mon Sep 17 00:00:00 2001 From: Tristan Chuine Date: Tue, 15 Oct 2024 19:49:56 +0200 Subject: [PATCH 2/2] fix error in test strange that *IT files aren't lunch by mvn cli --- .../orchestrator/server/MergeOrchestratorIT.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java index ad19ac2d..05cab2bf 100644 --- a/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java +++ b/src/test/java/org/gridsuite/merge/orchestrator/server/MergeOrchestratorIT.java @@ -19,14 +19,17 @@ import mockwebserver3.MockResponse; import mockwebserver3.MockWebServer; import mockwebserver3.RecordedRequest; +import mockwebserver3.junit5.internal.MockWebServerExtension; import okhttp3.Headers; import okhttp3.HttpUrl; import org.gridsuite.merge.orchestrator.server.dto.*; import org.gridsuite.merge.orchestrator.server.repositories.*; import org.gridsuite.merge.orchestrator.server.utils.*; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.slf4j.Logger; @@ -66,6 +69,7 @@ * @author Jon Harper * @author Franck Lecuyer getRequestsDone(final MockWebServer mockServer, final int n) LOGGER.error("Error while attempting to get the request done :", e); return null; } catch (NullPointerException e) { - return "[error]getPath()"; + return ERROR_TAKE_REQUEST; } }).collect(Collectors.toSet()); }