Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests to JUnit5 #114

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@
</developers>

<properties>
<gridsuite-dependencies.version>33</gridsuite-dependencies.version>
<commons-lang3.version>3.9</commons-lang3.version>
<gridsuite-dependencies.version>34</gridsuite-dependencies.version>
<liquibase-hibernate-package>org.gridsuite.merge.orchestrator.server</liquibase-hibernate-package>
<groovy.version>4.0.21</groovy.version>
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
</properties>

<build>
Expand All @@ -72,6 +71,13 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->
<dependency><!-- To remove when integrate in next release of gridsuite-dependencies or powsybl-ws-dependencies -->
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-bom</artifactId>
<version>${mockwebserver3.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- imports -->
<dependency>
Expand All @@ -83,11 +89,6 @@
</dependency>

<!-- project specific dependencies -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -136,7 +137,6 @@
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down Expand Up @@ -195,16 +195,6 @@
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -217,7 +207,7 @@
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<artifactId>mockwebserver3-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ReplacingDate {

private String businessProcess;

@Override
public String toString() {
return "date:" + date + " " + "businessProcess:" + businessProcess;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@
*/
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;

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 <franck.lecuyer at rte-france.com>
*/
@RunWith(MockitoJUnitRunner.class)
public class BalancesAdjustmentServiceTest {
@ExtendWith(MockitoExtension.class)
class BalancesAdjustmentServiceTest {

@Mock
private RestTemplate balancesAdjustmentServerRest;
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <franck.lecuyer at rte-france.com>
*/
@RunWith(MockitoJUnitRunner.class)
public class CaseFetcherServiceTest {
@ExtendWith(MockitoExtension.class)
class CaseFetcherServiceTest {

@Mock
private RestTemplate caseServerRest;
Expand All @@ -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<>();
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <franck.lecuyer at rte-france.com>
*/
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,48 @@
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;

/**
* @author Etienne Homer <etienne.homer at rte-france.com>
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@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<Map<String, String>> response = new ArrayList<>(List.of(
Map.of("id", "id1", "filename", "name1", "boundary", "boundary1"),
Map.of("id", "id2", "filename", "name2", "boundary", "boundary2")
Expand All @@ -67,7 +71,7 @@ public void testLastBoundaries() {
}

@Test
public void testSpecificBoundaries() {
void testSpecificBoundaries() {
Map<String, String> response = Map.of("id", "id1", "filename", "name1", "boundary", "boundary1");

when(cgmesBoundaryServiceRest.exchange(eq("/v1/boundaries/id1"),
Expand All @@ -90,4 +94,3 @@ public void testSpecificBoundaries() {
assertFalse(res.isPresent());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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 <franck.lecuyer at rte-france.com>
*/
@RunWith(MockitoJUnitRunner.class)
public class IgmQualityCheckServiceTest {
@ExtendWith(MockitoExtension.class)
class IgmQualityCheckServiceTest {

@Mock
private RestTemplate caseValidationServerRest;
Expand All @@ -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(),
Expand Down
Loading
Loading