From 0e5f4b5f72e5af901db84f57993d086e8cd90bc8 Mon Sep 17 00:00:00 2001
From: Tristan <135599584+Tristan-WorkGH@users.noreply.github.com>
Date: Thu, 17 Oct 2024 16:12:52 +0200
Subject: [PATCH] Migrate tests to JUnit5 (#59)
---
.gitignore | 2 +-
pom.xml | 42 ++-----------------
.../server/service/NotificationService.java | 1 -
.../gridsuite/config/server/ConfigTest.java | 34 ++++++---------
4 files changed, 18 insertions(+), 61 deletions(-)
diff --git a/.gitignore b/.gitignore
index dd7fbc4..931d21c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,4 @@ target/
# IntelliJ
/.idea
*.iml
-?/
\ No newline at end of file
+?/
diff --git a/pom.xml b/pom.xml
index 0beac57..c52d388 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
-
+
@@ -74,6 +74,8 @@
pom
import
+
+
@@ -129,9 +131,7 @@
runtime
-
+
org.postgresql
postgresql
runtime
@@ -157,39 +157,6 @@
r2dbc-h2
test
-
-
- com.h2database
- h2
- test
-
-
- junit
- junit
- test
-
-
- org.junit.vintage
- junit-vintage-engine
- test
-
-
- org.mockito
- mockito-core
- test
-
-
- com.squareup.okhttp3
- okhttp
- test
-
-
- com.squareup.okhttp3
- mockwebserver
- test
-
org.springframework.boot
spring-boot-starter-test
@@ -201,5 +168,4 @@
test
-
diff --git a/src/main/java/org/gridsuite/config/server/service/NotificationService.java b/src/main/java/org/gridsuite/config/server/service/NotificationService.java
index 5d67e86..a89f07d 100644
--- a/src/main/java/org/gridsuite/config/server/service/NotificationService.java
+++ b/src/main/java/org/gridsuite/config/server/service/NotificationService.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.config.server.service;
import org.gridsuite.config.server.ConfigService;
diff --git a/src/test/java/org/gridsuite/config/server/ConfigTest.java b/src/test/java/org/gridsuite/config/server/ConfigTest.java
index bc30a02..65867a4 100644
--- a/src/test/java/org/gridsuite/config/server/ConfigTest.java
+++ b/src/test/java/org/gridsuite/config/server/ConfigTest.java
@@ -6,17 +6,12 @@
*/
package org.gridsuite.config.server;
-import java.util.List;
-
import org.gridsuite.config.server.dto.ParameterInfos;
import org.gridsuite.config.server.repository.ParametersRepository;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import org.junit.Test;
-import org.junit.Before;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
@@ -25,24 +20,22 @@
import org.springframework.http.MediaType;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.config.EnableWebFlux;
-import static org.gridsuite.config.server.service.NotificationService.HEADER_USER_ID;
-import static org.gridsuite.config.server.service.NotificationService.HEADER_APP_NAME;
-import static org.gridsuite.config.server.service.NotificationService.HEADER_PARAMETER_NAME;
+import java.util.List;
+
+import static org.gridsuite.config.server.service.NotificationService.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author Abdelsalem Hedhili
*/
-@RunWith(SpringRunner.class)
@AutoConfigureWebTestClient
@EnableWebFlux
-@SpringBootTest
-@ContextConfiguration(classes = {ConfigApplication.class, TestChannelBinderConfiguration.class})
-public class ConfigTest {
+@SpringBootTest(classes = {ConfigApplication.class, TestChannelBinderConfiguration.class})
+class ConfigTest {
@Autowired
private WebTestClient webTestClient;
@@ -53,13 +46,13 @@ public class ConfigTest {
@Autowired
private ParametersRepository parametersRepository;
- @Before
- public void setup() {
+ @AfterEach
+ void setup() {
parametersRepository.deleteAll().block();
}
@Test
- public void testCreateParameters() {
+ void testCreateParameters() {
//get all config parameters for 'foo' application -> expect empty list
webTestClient.get()
.uri("/v1/applications/foo/parameters")
@@ -158,7 +151,7 @@ public void testCreateParameters() {
}
@Test
- public void testGetParameters() {
+ void testGetParameters() {
//get all config parameters -> expect empty list
webTestClient.get()
.uri("/v1/parameters")
@@ -316,4 +309,3 @@ public void describeTo(Description description) {
}
}
}
-